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