Commit 27e0f42b authored by Raimbek Egemberdiev's avatar Raimbek Egemberdiev

advanced search one

parent c4a7691e
...@@ -4,8 +4,8 @@ import kz.arta.synergy.api.JsonUtils; ...@@ -4,8 +4,8 @@ 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.converter.AsfFormConverter; import kz.arta.synergy.api.asforms.converter.AsFormConverter;
import kz.arta.synergy.api.asforms.converter.DefaultAsfFormConverter; import kz.arta.synergy.api.asforms.converter.DefaultAsFormConverter;
import kz.arta.synergy.api.asforms.pojo.AdvancedSearchParams; import kz.arta.synergy.api.asforms.pojo.AdvancedSearchParams;
import kz.arta.synergy.api.asforms.pojo.AdvancedSearchResult; import kz.arta.synergy.api.asforms.pojo.AdvancedSearchResult;
import kz.arta.synergy.api.asforms.pojo.AsForm; import kz.arta.synergy.api.asforms.pojo.AsForm;
...@@ -22,7 +22,7 @@ import java.util.List; ...@@ -22,7 +22,7 @@ import java.util.List;
public class AsFormService { public class AsFormService {
private RestHttpQuery restHttpQuery; private RestHttpQuery restHttpQuery;
private AsfFormConverter asfFormConverter; private AsFormConverter asFormConverter;
private AsFormService(QueryContext context) { private AsFormService(QueryContext context) {
this.restHttpQuery = new RestHttpQuery(context); this.restHttpQuery = new RestHttpQuery(context);
...@@ -30,10 +30,24 @@ public class AsFormService { ...@@ -30,10 +30,24 @@ public class AsFormService {
public static AsFormService newInstance(QueryContext context) { public static AsFormService newInstance(QueryContext context) {
AsFormService asFormService = new AsFormService(context); AsFormService asFormService = new AsFormService(context);
asFormService.asfFormConverter = new DefaultAsfFormConverter(); asFormService.asFormConverter = new DefaultAsFormConverter();
return asFormService; return asFormService;
} }
public RestHttpQuery getRestHttpQuery() {
return restHttpQuery;
}
public AsFormService setRestHttpQuery(RestHttpQuery restHttpQuery) {
this.restHttpQuery = restHttpQuery;
return this;
}
public AsFormService setFormConverter(AsFormConverter converter) {
this.asFormConverter = converter;
return this;
}
public List<AdvancedSearchResult> advancedSearch(AdvancedSearchParams searchParams) throws IOException { public List<AdvancedSearchResult> advancedSearch(AdvancedSearchParams searchParams) throws IOException {
Query query = Query.newInstance() Query query = Query.newInstance()
.methodPost() .methodPost()
...@@ -47,38 +61,35 @@ public class AsFormService { ...@@ -47,38 +61,35 @@ public class AsFormService {
public List<AdvancedSearchResult> advancedSearch(String formId, String key, String value) throws IOException { public List<AdvancedSearchResult> advancedSearch(String formId, String key, String value) throws IOException {
return advancedSearch(AdvancedSearchParams.build( return advancedSearch(AdvancedSearchParams.build(
String.format("where uuid='%s' and %s='%s'", formId, key, value), key String.format("where uuid='%s' and %s='%s'", formId, key, value), key
)); ));
} }
public <T extends AsForm> T fetch(Class<T> formClass, String dataUUID) throws IOException { public <T extends AsForm> T getData(Class<T> formClass, String dataUUID) throws IOException {
String data = restHttpQuery.doQuery(Query.newInstance().url("/rest/api/asforms/data/" + dataUUID)); return asFormConverter.toAsForm(formClass, getData(dataUUID));
return asfFormConverter.toAsForm(formClass, JsonUtils.read(data, AsFormWrapper.class));
} }
public <T extends AsForm> String save(T asForm) throws IOException { public AsFormWrapper getData(String dataUUID) throws IOException {
AsFormWrapper asFormWrapper = asfFormConverter.toAsfData(asForm); String data = restHttpQuery.doQuery(Query.newInstance().url("/rest/api/asforms/data/" + dataUUID));
return JsonUtils.read(data, AsFormWrapper.class);
}
public String saveData(AsFormWrapper asFormWrapper) throws IOException {
Query query = Query.newInstance() Query query = Query.newInstance()
.methodPost() .methodPost()
.url("/rest/api/asforms/data/save") .url("/rest/api/asforms/data/save")
.formParam("formUUID", asForm.getForm()) .formParam("formUUID", asFormWrapper.getForm())
.formParam("uuid", asForm.getUuid()) .formParam("uuid", asFormWrapper.getUuid())
.formParam("data", "\"data\":" + JsonUtils.toJson(asFormWrapper.getData())); .formParam("data", "\"data\":" + JsonUtils.toJson(asFormWrapper.getData()));
return restHttpQuery.doQuery(query); return restHttpQuery.doQuery(query);
} }
public <T extends AsForm> AsFormWrapper toAsfData(T asForm) { public <T extends AsForm> String saveData(T asForm) throws IOException {
return asfFormConverter.toAsfData(asForm); return saveData(asFormConverter.toAsfData(asForm));
}
public RestHttpQuery getRestHttpQuery() {
return restHttpQuery;
} }
public AsFormService setRestHttpQuery(RestHttpQuery restHttpQuery) { public <T extends AsForm> AsFormWrapper toAsfData(T asForm) {
this.restHttpQuery = restHttpQuery; return asFormConverter.toAsfData(asForm);
return this;
} }
} }
...@@ -11,7 +11,7 @@ import java.lang.annotation.Annotation; ...@@ -11,7 +11,7 @@ import java.lang.annotation.Annotation;
* @author raimbek * @author raimbek
* @since 11.11.2016 * @since 11.11.2016
*/ */
public interface AsfFormConverter { public interface AsFormConverter {
<T extends AsForm> AsFormWrapper toAsfData(T asForm); <T extends AsForm> AsFormWrapper toAsfData(T asForm);
......
...@@ -17,11 +17,11 @@ import java.util.Map; ...@@ -17,11 +17,11 @@ import java.util.Map;
* @author raimbek * @author raimbek
* @since 11.11.2016 * @since 11.11.2016
*/ */
public class DefaultAsfFormConverter implements AsfFormConverter { public class DefaultAsFormConverter implements AsFormConverter {
Map<Class<? extends Annotation>, ComponentConverter> componentConverters = new HashMap<>(); Map<Class<? extends Annotation>, ComponentConverter> componentConverters = new HashMap<>();
public DefaultAsfFormConverter() { public DefaultAsFormConverter() {
registerConverter(Cmp.class, new CommonConverter()); registerConverter(Cmp.class, new CommonConverter());
registerConverter(TextBox.class, new TextBoxConverter()); registerConverter(TextBox.class, new TextBoxConverter());
registerConverter(NumericInput.class, new NumericInputConverter()); registerConverter(NumericInput.class, new NumericInputConverter());
......
...@@ -2,7 +2,7 @@ package kz.arta.synergy.api.asforms.converter.components; ...@@ -2,7 +2,7 @@ package kz.arta.synergy.api.asforms.converter.components;
import kz.arta.synergy.api.asforms.AsfTableUtil; import kz.arta.synergy.api.asforms.AsfTableUtil;
import kz.arta.synergy.api.asforms.annotations.Table; import kz.arta.synergy.api.asforms.annotations.Table;
import kz.arta.synergy.api.asforms.converter.AsfFormConverter; import kz.arta.synergy.api.asforms.converter.AsFormConverter;
import kz.arta.synergy.api.asforms.exceptions.UnsupportedFieldTypeException; import kz.arta.synergy.api.asforms.exceptions.UnsupportedFieldTypeException;
import kz.arta.synergy.api.asforms.pojo.AsFormData; import kz.arta.synergy.api.asforms.pojo.AsFormData;
import kz.arta.synergy.api.asforms.pojo.AsFormDataContainer; import kz.arta.synergy.api.asforms.pojo.AsFormDataContainer;
...@@ -20,10 +20,10 @@ import java.util.Set; ...@@ -20,10 +20,10 @@ import java.util.Set;
*/ */
public class TableConverter extends AbstractComponentConverter { public class TableConverter extends AbstractComponentConverter {
private AsfFormConverter asfFormConverter; private AsFormConverter asFormConverter;
public TableConverter(AsfFormConverter asfFormConverter) { public TableConverter(AsFormConverter asFormConverter) {
this.asfFormConverter = asfFormConverter; this.asFormConverter = asFormConverter;
} }
@Override @Override
...@@ -72,7 +72,7 @@ public class TableConverter extends AbstractComponentConverter { ...@@ -72,7 +72,7 @@ public class TableConverter extends AbstractComponentConverter {
field.setAccessible(true); field.setAccessible(true);
List tableList = (List) field.get(asForm); List tableList = (List) field.get(asForm);
for (int bIndex = 1; bIndex <= tableList.size(); bIndex++) { for (int bIndex = 1; bIndex <= tableList.size(); bIndex++) {
AsFormDataContainer asFormDataContainer = asfFormConverter.toAsfData(tableList.get(bIndex - 1), String.valueOf(bIndex)); AsFormDataContainer asFormDataContainer = asFormConverter.toAsfData(tableList.get(bIndex - 1), String.valueOf(bIndex));
for (AsFormData asFormData : asFormDataContainer.getData()) { for (AsFormData asFormData : asFormDataContainer.getData()) {
tableData.addData(asFormData); tableData.addData(asFormData);
} }
...@@ -90,7 +90,7 @@ public class TableConverter extends AbstractComponentConverter { ...@@ -90,7 +90,7 @@ public class TableConverter extends AbstractComponentConverter {
List table = new ArrayList<>(); List table = new ArrayList<>();
Set<String> indexes = AsfTableUtil.tableBIndexes(tableData); Set<String> indexes = AsfTableUtil.tableBIndexes(tableData);
for (String index : indexes) { for (String index : indexes) {
table.add(asfFormConverter.toAsForm(genericType, tableData, index)); table.add(asFormConverter.toAsForm(genericType, tableData, index));
} }
return table; return table;
} }
......
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