Commit e204aeb0 authored by Raimbek Egemberdiev's avatar Raimbek Egemberdiev

рефакторинг импорта завершена

parent 10a8de6e
...@@ -34,12 +34,16 @@ public class Query { ...@@ -34,12 +34,16 @@ public class Query {
} }
public Query queryParam(String key, String value) { public Query queryParam(String key, String value) {
if (value != null) {
queryParams.put(key, value); queryParams.put(key, value);
}
return this; return this;
} }
public Query formParam(String key, String value) { public Query formParam(String key, String value) {
if (value != null) {
formParams.put(key, value); formParams.put(key, value);
}
return this; return this;
} }
......
...@@ -85,22 +85,24 @@ public class AsFormService { ...@@ -85,22 +85,24 @@ public class AsFormService {
)); ));
} }
public List<AdvancedSearchResult> advancedSearchOne(String formId, String key, String value) throws IOException { public AdvancedSearchResult advancedSearchOne(String formId, String key, String value) throws IOException, FormRecordNotFound, FoundTooManyRecords {
return advancedSearchOne(formId, key, value); return advancedSearchOne(AdvancedSearchParams.build(
String.format("where uuid='%s' and %s='%s'", formId, key, value), key
));
} }
public SearchIndexResult searchIndex(SearchIndexParamsBuilder builder) throws IOException { public SearchIndexResult searchIndex(SearchIndexParamsBuilder builder) throws IOException {
Query query = Query.newInstance().url("/rest/api/asforms/search_index?" + builder.build()); Query query = Query.newInstance().url("/rest/api/asforms/search_index?" + builder.build());
String responce = restHttpQuery.doQuery(query); String response = restHttpQuery.doQuery(query);
return JsonUtils.read(responce, SearchIndexResult.class); return JsonUtils.read(response, SearchIndexResult.class);
} }
public RegistryRecord searchIndexOne(SearchIndexParamsBuilder builder) throws IOException, FormRecordNotFound, FoundTooManyRecords { public RegistryRecord searchIndexOne(SearchIndexParamsBuilder builder) throws IOException, FormRecordNotFound, FoundTooManyRecords {
SearchIndexResult result = searchIndex(builder); SearchIndexResult result = searchIndex(builder);
if (result == null || result.getCount() == 0) { if (result == null || result.getCount() == 0) {
throw new FormRecordNotFound(); throw new FormRecordNotFound(builder.build());
} else if (result.getCount() > 1) { } else if (result.getCount() > 1) {
throw new FoundTooManyRecords(); throw new FoundTooManyRecords(builder.build());
} }
return result.getRecords().get(0); return result.getRecords().get(0);
} }
......
...@@ -30,6 +30,7 @@ public class DefaultAsFormConverter implements AsFormConverter { ...@@ -30,6 +30,7 @@ public class DefaultAsFormConverter implements AsFormConverter {
registerConverter(Entity.class, new EntityConverter()); registerConverter(Entity.class, new EntityConverter());
registerConverter(ListBox.class, new ListBoxConverter()); registerConverter(ListBox.class, new ListBoxConverter());
registerConverter(Table.class, new TableConverter(this)); registerConverter(Table.class, new TableConverter(this));
registerConverter(DateCmp.class, new DateConverter());
} }
@Override @Override
......
...@@ -48,34 +48,22 @@ public abstract class AbstractComponentConverter implements ComponentConverter { ...@@ -48,34 +48,22 @@ public abstract class AbstractComponentConverter implements ComponentConverter {
} else if (field.getType().isAssignableFrom(Integer.class)) { } else if (field.getType().isAssignableFrom(Integer.class)) {
// int // int
String value = getValueForClassField(field, asfData, cmpId); String value = getNumberValueForField(asfData, field, cmpId);
if (value == null) {
value = "0";
}
field.set(asFormObject, Integer.parseInt(value)); field.set(asFormObject, Integer.parseInt(value));
} else if (field.getType().isAssignableFrom(BigInteger.class)) { } else if (field.getType().isAssignableFrom(BigInteger.class)) {
// int // int
String value = getValueForClassField(field, asfData, cmpId); String value = getNumberValueForField(asfData, field, cmpId);
if (value == null) {
value = "0";
}
field.set(asFormObject, new BigInteger(value)); field.set(asFormObject, new BigInteger(value));
} else if (field.getType().isAssignableFrom(Double.class)) { } else if (field.getType().isAssignableFrom(Double.class)) {
// double // double
String value = getValueForClassField(field, asfData, cmpId); String value = getNumberValueForField(asfData, field, cmpId);
if (value == null) {
value = "0";
}
field.set(asFormObject, Double.parseDouble(value)); field.set(asFormObject, Double.parseDouble(value));
} else if (field.getType().isAssignableFrom(BigDecimal.class)) { } else if (field.getType().isAssignableFrom(BigDecimal.class)) {
// double // double
String value = getValueForClassField(field, asfData, cmpId); String value = getNumberValueForField(asfData, field, cmpId);
if (value == null) {
value = "0";
}
field.set(asFormObject, new BigDecimal(value)); field.set(asFormObject, new BigDecimal(value));
} else if (field.getType().isAssignableFrom(AsFormData.class)) { } else if (field.getType().isAssignableFrom(AsFormData.class)) {
...@@ -125,6 +113,14 @@ public abstract class AbstractComponentConverter implements ComponentConverter { ...@@ -125,6 +113,14 @@ public abstract class AbstractComponentConverter implements ComponentConverter {
return asfData.getValue(cmpId); return asfData.getValue(cmpId);
} }
private String getNumberValueForField(AsFormDataContainer asfData, Field field, String cmpId) {
String value = getValueForClassField(field, asfData, cmpId);
if (Strings.isNullOrEmpty(value)) {
value = "0";
}
return value.trim().replaceAll(" ", "");
}
protected boolean hasKeyValueAnnotation(Field field) { protected boolean hasKeyValueAnnotation(Field field) {
boolean fetchKey = false; boolean fetchKey = false;
Annotation[] declaredAnnotations = field.getDeclaredAnnotations(); Annotation[] declaredAnnotations = field.getDeclaredAnnotations();
......
...@@ -17,6 +17,7 @@ public class AdvancedSearchParams { ...@@ -17,6 +17,7 @@ public class AdvancedSearchParams {
private String query; private String query;
private List<String> parameters = new ArrayList<String>(); private List<String> parameters = new ArrayList<String>();
private boolean searchInRegistry = true; private boolean searchInRegistry = true;
private boolean showDeleted = false;
private int startRecord = 0; private int startRecord = 0;
private int recordsCount = 100; private int recordsCount = 100;
private List<List<String>> dynParams = new ArrayList<List<String>>(); private List<List<String>> dynParams = new ArrayList<List<String>>();
...@@ -78,4 +79,12 @@ public class AdvancedSearchParams { ...@@ -78,4 +79,12 @@ public class AdvancedSearchParams {
public void setDynParams(List<List<String>> dynParams) { public void setDynParams(List<List<String>> dynParams) {
this.dynParams = dynParams; this.dynParams = dynParams;
} }
public boolean isShowDeleted() {
return showDeleted;
}
public void setShowDeleted(boolean showDeleted) {
this.showDeleted = showDeleted;
}
} }
...@@ -15,6 +15,7 @@ public class AsForm { ...@@ -15,6 +15,7 @@ public class AsForm {
private String uuid; private String uuid;
private String form; private String form;
private String modified; private String modified;
private String documentId;
public AsForm() { public AsForm() {
} }
...@@ -50,4 +51,12 @@ public class AsForm { ...@@ -50,4 +51,12 @@ public class AsForm {
public void setModified(String modified) { public void setModified(String modified) {
this.modified = modified; this.modified = modified;
} }
public void setDocumentId(String documentId) {
this.documentId = documentId;
}
public String getDocumentId() {
return documentId;
}
} }
...@@ -122,4 +122,23 @@ public class AsFormData extends AsFormDataContainer { ...@@ -122,4 +122,23 @@ public class AsFormData extends AsFormDataContainer {
asFormData.setType(type); asFormData.setType(type);
return asFormData; return asFormData;
} }
public static AsFormData createOnlyWithValue(String value) {
AsFormData asFormData = new AsFormData();
asFormData.setValue(value);
return asFormData;
}
public static AsFormData createOnlyWithKey(String key) {
AsFormData asFormData = new AsFormData();
asFormData.setKey(key);
return asFormData;
}
public static AsFormData createByValueAndKey(String key, String value) {
AsFormData asFormData = new AsFormData();
asFormData.setKey(key);
asFormData.setValue(value);
return asFormData;
}
} }
package kz.arta.synergy.api.asforms.pojo; package kz.arta.synergy.api.asforms.pojo;
import org.codehaus.jackson.annotate.JsonIgnoreProperties; import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
import java.util.List; import java.util.List;
...@@ -8,6 +9,7 @@ import java.util.List; ...@@ -8,6 +9,7 @@ import java.util.List;
public class SearchIndexResult { public class SearchIndexResult {
private int count; private int count;
@JsonProperty("data")
private List<RegistryRecord> records; private List<RegistryRecord> records;
public SearchIndexResult() { public SearchIndexResult() {
......
...@@ -4,6 +4,7 @@ import kz.arta.synergy.api.JsonUtils; ...@@ -4,6 +4,7 @@ import kz.arta.synergy.api.JsonUtils;
import kz.arta.synergy.api.Query; import kz.arta.synergy.api.Query;
import kz.arta.synergy.api.QueryContext; import kz.arta.synergy.api.QueryContext;
import kz.arta.synergy.api.RestHttpQuery; import kz.arta.synergy.api.RestHttpQuery;
import kz.arta.synergy.api.asforms.pojo.RegistryRecord;
import java.io.IOException; import java.io.IOException;
...@@ -24,15 +25,18 @@ public class RegistryService { ...@@ -24,15 +25,18 @@ public class RegistryService {
return new RegistryService(context); return new RegistryService(context);
} }
public String createRegistryRecord(String registryID) throws IOException { public RegistryRecord createRegistryRecord(String registryID) throws IOException {
Query query = Query.newInstance() Query query = Query.newInstance()
.url("/rest/api/registry/create_doc") .url("/rest/api/registry/create_doc")
.queryParam("registryID", registryID); .queryParam("registryID", registryID);
String response = restHttpQuery.doQuery(query); String response = restHttpQuery.doQuery(query);
return JsonUtils.readTree(response).get("dataUUID").getTextValue(); return JsonUtils.read(response, RegistryRecord.class);
} }
public void activateRecord(String dataUUID) { public String activateRecord(String dataUUID) throws IOException {
Query query = Query.newInstance()
.url("/rest/api/registry/activate_doc")
.queryParam("dataUUID", dataUUID);
return restHttpQuery.doQuery(query);
} }
} }
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