Commit e204aeb0 authored by Raimbek Egemberdiev's avatar Raimbek Egemberdiev

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

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