Commit b9143e5b authored by Raimbek Egemberdiev's avatar Raimbek Egemberdiev

dictionary delete and add

parent 1d957d44
...@@ -10,6 +10,7 @@ import kz.arta.synergy.api.dictionaries.annotations.DictionaryColumn; ...@@ -10,6 +10,7 @@ import kz.arta.synergy.api.dictionaries.annotations.DictionaryColumn;
import kz.arta.synergy.api.dictionaries.pojo.Dictionary; import kz.arta.synergy.api.dictionaries.pojo.Dictionary;
import kz.arta.synergy.api.dictionaries.pojo.DictionaryItem; import kz.arta.synergy.api.dictionaries.pojo.DictionaryItem;
import kz.arta.synergy.api.dictionaries.pojo.DictionaryItemValue; import kz.arta.synergy.api.dictionaries.pojo.DictionaryItemValue;
import kz.arta.synergy.api.dictionaries.pojo.DictionaryRecord;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
...@@ -42,6 +43,28 @@ public class DictionaryService { ...@@ -42,6 +43,28 @@ public class DictionaryService {
return JsonUtils.read(restHttpQuery.doQuery(query), Dictionary.class); return JsonUtils.read(restHttpQuery.doQuery(query), Dictionary.class);
} }
public String deleteDictionaryItem(final String code, final String itemId) throws IOException {
HashMap<String, String> data = new HashMap<String, String>() {{
put("dictCode", code);
put("itemID", itemId);
}};
Query query = Query.newInstance()
.methodPost()
.url("/rest/api/dictionary/record/remove")
.header("Content-Type", "application/json; charset=utf-8")
.body(JsonUtils.toJson(data));
return restHttpQuery.doQuery(query);
}
public String addRecord(DictionaryRecord dictionaryRecord) throws IOException {
Query query = Query.newInstance()
.methodPost()
.url("/rest/api/dictionary/record/add")
.header("Content-Type", "application/json; charset=utf-8")
.body(JsonUtils.toJson(dictionaryRecord));
return restHttpQuery.doQuery(query);
}
public <T> List<T> getDictionary(Class<T> dictionaryType) throws DictionaryConvertException { public <T> List<T> getDictionary(Class<T> dictionaryType) throws DictionaryConvertException {
try { try {
ArrayList<T> dictionaryList = new ArrayList<>(); ArrayList<T> dictionaryList = new ArrayList<>();
......
...@@ -3,6 +3,7 @@ package kz.arta.synergy.api.dictionaries.pojo; ...@@ -3,6 +3,7 @@ package kz.arta.synergy.api.dictionaries.pojo;
import kz.arta.synergy.api.asforms.utils.Strings; import kz.arta.synergy.api.asforms.utils.Strings;
import java.util.Collections;
import java.util.List; import java.util.List;
/** /**
...@@ -59,6 +60,15 @@ public class Dictionary { ...@@ -59,6 +60,15 @@ public class Dictionary {
return null; return null;
} }
public String findColumnCodeById(String columnID) {
for (DictionaryColumn column : columns) {
if (!Strings.isNullOrEmpty(column.getColumnID()) && column.getColumnID().equals(columnID)) {
return column.getCode();
}
}
return null;
}
public String findItemID(String columnID, String value) { public String findItemID(String columnID, String value) {
for (DictionaryItem item : getItems()) { for (DictionaryItem item : getItems()) {
for (DictionaryItemValue itemValue : item.getValues()) { for (DictionaryItemValue itemValue : item.getValues()) {
...@@ -83,4 +93,13 @@ public class Dictionary { ...@@ -83,4 +93,13 @@ public class Dictionary {
} }
return ""; return "";
} }
public DictionaryItem findItem(DictionaryItem srcDictItem) {
for (DictionaryItem dictionaryItem : getItems()) {
if (dictionaryItem.equals(srcDictItem)) {
return dictionaryItem;
}
}
return null;
}
} }
...@@ -26,4 +26,23 @@ public class DictionaryColumn { ...@@ -26,4 +26,23 @@ public class DictionaryColumn {
public void setCode(String code) { public void setCode(String code) {
this.code = code; this.code = code;
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
DictionaryColumn column = (DictionaryColumn) o;
if (columnID != null ? !columnID.equals(column.columnID) : column.columnID != null) return false;
return !(code != null ? !code.equals(column.code) : column.code != null);
}
@Override
public int hashCode() {
int result = columnID != null ? columnID.hashCode() : 0;
result = 31 * result + (code != null ? code.hashCode() : 0);
return result;
}
} }
...@@ -28,4 +28,20 @@ public class DictionaryItem { ...@@ -28,4 +28,20 @@ public class DictionaryItem {
public void setValues(List<DictionaryItemValue> values) { public void setValues(List<DictionaryItemValue> values) {
this.values = values; this.values = values;
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
DictionaryItem that = (DictionaryItem) o;
return !(values != null ? !values.equals(that.values) : that.values != null);
}
@Override
public int hashCode() {
return values != null ? values.hashCode() : 0;
}
} }
...@@ -4,7 +4,7 @@ package kz.arta.synergy.api.dictionaries.pojo; ...@@ -4,7 +4,7 @@ package kz.arta.synergy.api.dictionaries.pojo;
* @author raimbek * @author raimbek
* @since 26.04.2016 * @since 26.04.2016
*/ */
public class DictionaryItemValue { public class DictionaryItemValue implements Comparable<DictionaryItemValue> {
private String columnID; private String columnID;
private String value; private String value;
...@@ -26,4 +26,31 @@ public class DictionaryItemValue { ...@@ -26,4 +26,31 @@ public class DictionaryItemValue {
public void setValue(String value) { public void setValue(String value) {
this.value = value; this.value = value;
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
DictionaryItemValue itemValue = (DictionaryItemValue) o;
if (columnID != null ? !columnID.equals(itemValue.columnID) : itemValue.columnID != null) return false;
return !(value != null ? !value.equals(itemValue.value) : itemValue.value != null);
}
@Override
public int hashCode() {
int result = columnID != null ? columnID.hashCode() : 0;
result = 31 * result + (value != null ? value.hashCode() : 0);
return result;
}
@Override
public int compareTo(DictionaryItemValue o) {
if (o == null) {
return 0;
}
return o.getColumnID().compareTo(this.columnID);
}
} }
package kz.arta.synergy.api.dictionaries.pojo;
import java.util.ArrayList;
import java.util.List;
/**
* @author raimbek
* @since 17.02.2017
*/
public class DictionaryRecord {
private String dictCode;
private String itemID;
public static class Column {
public String code;
public String value;
public String valueKZ;
public String valueRU;
public String valueEN;
}
private List<Column> columns = new ArrayList<>();
public String getDictCode() {
return dictCode;
}
public void setDictCode(String dictCode) {
this.dictCode = dictCode;
}
public String getItemID() {
return itemID;
}
public void setItemID(String itemID) {
this.itemID = itemID;
}
public List<Column> getColumns() {
return columns;
}
public void setColumns(List<Column> columns) {
this.columns = columns;
}
public void addColumn(Column column) {
columns.add(column);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment