Commit f5ebfd9a authored by Raimbek Egemberdiev's avatar Raimbek Egemberdiev

as form utils

parent ca814402
group 'kz.arta.synergy.asforms' group 'kz.arta.synergy.api'
version '1.0' version '1.0'
apply plugin: 'java' apply plugin: 'java'
...@@ -10,6 +10,7 @@ repositories { ...@@ -10,6 +10,7 @@ repositories {
} }
dependencies { dependencies {
compile group: 'cglib', name: 'cglib', version: '3.2.4' // compile group: 'cglib', name: 'cglib', version: '3.2.4'
testCompile group: 'org.testng', name: 'testng', version: '6.9.13.6' testCompile group: 'org.testng', name: 'testng', version: '6.8'
testCompile group: 'org.mockito', name: 'mockito-all', version: '1.9.5'
} }
package kz.arta.synergy.api;
/**
* @author raimbek
* @since 10.11.2016
*/
public class ConfigProvider {
}
package kz.arta.synergy.api;
import kz.arta.synergy.api.asforms.exceptions.SynergyApiCallException;
import kz.arta.synergy.api.asforms.pojo.AsFormWrapper;
/**
* @author raimbek
* @since 09.11.2016
*/
public class SynergyApiProvider {
public AsFormWrapper getAsfData(String dataUUID) throws SynergyApiCallException {
return new AsFormWrapper();
}
public String saveData(AsFormWrapper asfData) {
return null;
}
}
package kz.arta.synergy.asforms; package kz.arta.synergy.api.asforms;
import kz.arta.synergy.asforms.annotations.*; import kz.arta.synergy.api.SynergyApiProvider;
import kz.arta.synergy.asforms.exceptions.CreateAsFormException; import kz.arta.synergy.api.asforms.annotations.*;
import kz.arta.synergy.asforms.exceptions.SynergyApiCallException; import kz.arta.synergy.api.asforms.exceptions.CreateAsFormException;
import kz.arta.synergy.asforms.exceptions.UnsupportedFieldTypeException; import kz.arta.synergy.api.asforms.exceptions.UnsupportedFieldTypeException;
import kz.arta.synergy.asforms.pojo.AsForm; import kz.arta.synergy.api.asforms.pojo.*;
import kz.arta.synergy.asforms.pojo.AsFormData;
import kz.arta.synergy.asforms.pojo.ComponentTypes;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set;
/** /**
* @author raimbek * @author raimbek
...@@ -22,63 +20,185 @@ public class AsFormProvider { ...@@ -22,63 +20,185 @@ public class AsFormProvider {
private SynergyApiProvider synergyApiProvider; private SynergyApiProvider synergyApiProvider;
public AsFormProvider() { private AsFormProvider() {
} }
public AsFormProvider(SynergyApiProvider synergyApiProvider) { public static AsFormProvider newInstance(SynergyApiProvider synergyApiProvider) {
this.synergyApiProvider = synergyApiProvider; AsFormProvider asFormProvider = new AsFormProvider();
asFormProvider.synergyApiProvider = synergyApiProvider;
return asFormProvider;
} }
public <T extends AsForm> public List<AdvancedSearchResult> advancedSearch(AdvancedSearchParams advancedSearchParams) {
List<AdvancedSearchResult<T>> return new ArrayList<AdvancedSearchResult>();
advancedSearch(Class<T> formClass, AdvancedSearchParams advancedSearchParams)
{
return new ArrayList<AdvancedSearchResult<T>>();
} }
public <T extends AsForm> public <T extends AsForm> T fetch(Class<T> formClass, String dataUUID) {
T AsFormWrapper asfData = synergyApiProvider.getAsfData(dataUUID);
fetchData(Class<T> formClass, String dataUUID) throws CreateAsFormException, SynergyApiCallException, UnsupportedFieldTypeException return create(formClass, asfData);
{
AsForm asfData = synergyApiProvider.getAsfData(dataUUID);
return createAsForm(formClass, asfData);
} }
public <T extends AsForm> public <T extends AsForm> T create(Class<T> asFormClass, AsFormWrapper asfData) {
T T asForm = createAsFormObject(asFormClass, asfData, null);
createAsForm(Class<T> asFormClass, AsForm asfData) throws CreateAsFormException, UnsupportedFieldTypeException { asForm.setForm(asfData.getForm());
asForm.setModified(asfData.getModified());
asForm.setNodeUUID(asfData.getNodeUUID());
asForm.setUuid(asfData.getUuid());
return asForm;
}
public <T extends AsForm> String save(T asForm) {
return synergyApiProvider.saveData(toAsfData(asForm));
}
public <T extends AsForm> AsFormWrapper toAsfData(T asForm) {
AsFormWrapper asFormWrapper = new AsFormWrapper();
asFormWrapper.setForm(asForm.getForm());
asFormWrapper.setModified(asForm.getModified());
asFormWrapper.setNodeUUID(asForm.getNodeUUID());
asFormWrapper.setUuid(asForm.getUuid());
asFormWrapper.setData(toAsfData(asForm, null).getData());
return asFormWrapper;
}
private <T> AsFormDataContainer toAsfData(T asForm, String index) {
AsFormDataContainer dataContainer = new AsFormDataContainer();
try {
Field[] allFields = asForm.getClass().getDeclaredFields();
for (Field field : allFields) {
Annotation[] declaredAnnotations = field.getDeclaredAnnotations();
for (Annotation annotation : declaredAnnotations) {
if (annotation instanceof TextInput) {
String cmpId = ((TextInput) annotation).value();
dataContainer.addData(toAsfData(asForm, field, cmpId, index, ComponentTypes.TEXT_BOX));
break;
}
if (annotation instanceof Cmp) {
Cmp cmpAnnotation = (Cmp) annotation;
dataContainer.addData(toAsfData(asForm, field, cmpAnnotation.id(), index, cmpAnnotation.type()));
break;
}
if (annotation instanceof NumericInput) {
String cmpId = ((NumericInput) annotation).value();
dataContainer.addData(toAsfData(asForm, field, cmpId, index, ComponentTypes.NUMERIC_INPUT));
break;
}
if (annotation instanceof Entity) {
String cmpId = ((Entity) annotation).value();
dataContainer.addData(toAsfData(asForm, field, cmpId, index, ComponentTypes.ENTITY));
break;
}
if (annotation instanceof ListBox) {
String cmpId = ((ListBox) annotation).value();
dataContainer.addData(toAsfData(asForm, field, cmpId, index, ComponentTypes.LISTBOX));
break;
}
if (annotation instanceof Table) {
Table tableAnnotation = (Table) annotation;
if (field.getType().isAssignableFrom(AsFormData.class)) {
dataContainer.addData(toAsfData(asForm, field, tableAnnotation.value(), index, ComponentTypes.TABLE));
} else if (field.getType().isAssignableFrom(List.class)) {
AsFormData tableData = listToAppendableTable(asForm, field, tableAnnotation.id());
dataContainer.addData(tableData);
} else {
throw new UnsupportedFieldTypeException();
}
break;
}
}
}
} catch (IllegalAccessException e) {
throw new CreateAsFormException("Form class should be accessible");
}
return dataContainer;
}
private <T> AsFormData toAsfData(T asForm, Field field, String cmpId, String index, String type) throws IllegalAccessException {
if (index != null) {
cmpId = cmpId + "-b" + index;
}
AsFormData asFormData = AsFormData.create(cmpId, type);
if (ComponentTypes.TABLE.equals(type)) {
AsFormData tableData = (AsFormData) field.get(asForm);
if (tableData != null && tableData.getData() != null) {
asFormData.setData(tableData.getData());
}
}
field.setAccessible(true);
Object valueObject = field.get(asForm);
if (valueObject instanceof AsFormData) {
AsFormData asFormDataObject = (AsFormData) valueObject;
asFormDataObject.setId(cmpId);
asFormDataObject.setType(type);
return asFormDataObject;
} else {
if (type.equals(ComponentTypes.NUMERIC_INPUT)) {
asFormData.setKey(String.valueOf(valueObject));
}
asFormData.setValue(String.valueOf(valueObject));
}
return asFormData;
}
private <T> AsFormData listToAppendableTable(T asForm, Field field, String id) throws IllegalAccessException {
AsFormData tableData = AsFormData.create(id, ComponentTypes.TABLE);
field.setAccessible(true);
List tableList = (List) field.get(asForm);
for (int bIndex = 1; bIndex <= tableList.size(); bIndex++) {
AsFormDataContainer asFormDataContainer = toAsfData(tableList.get(bIndex - 1), String.valueOf(bIndex));
for (AsFormData asFormData : asFormDataContainer.getData()) {
tableData.addData(asFormData);
}
}
return tableData;
}
private <T> T createAsFormObject(Class<T> asFormClass, AsFormDataContainer asfData, String index) {
try { try {
T asFormObject = asFormClass.newInstance(); T asFormObject = asFormClass.newInstance();
if (asfData == null || asfData.getData() == null || asfData.getData().isEmpty()) {
return asFormObject;
}
Field[] allFields = asFormClass.getDeclaredFields(); Field[] allFields = asFormClass.getDeclaredFields();
for (Field field : allFields) { for (Field field : allFields) {
Annotation[] declaredAnnotations = field.getDeclaredAnnotations(); Annotation[] declaredAnnotations = field.getDeclaredAnnotations();
for (Annotation annotation : declaredAnnotations) { for (Annotation annotation : declaredAnnotations) {
if (annotation instanceof TextInput) { if (annotation instanceof TextInput) {
String cmpId = ((TextInput) annotation).value(); String cmpId = ((TextInput) annotation).value();
setFieldValue(asfData, asFormObject, field, cmpId, ComponentTypes.TEXT_INPUT); setFieldValue(asfData, asFormObject, field, cmpId, index, ComponentTypes.TEXT_BOX);
break;
}
if (annotation instanceof Cmp) {
Cmp cmpAnnotation = (Cmp) annotation;
setFieldValue(asfData, asFormObject, field, cmpAnnotation.id(), index, cmpAnnotation.type());
break; break;
} }
if (annotation instanceof NumericInput) { if (annotation instanceof NumericInput) {
String cmpId = ((NumericInput) annotation).value(); String cmpId = ((NumericInput) annotation).value();
setFieldValue(asfData, asFormObject, field, cmpId, ComponentTypes.NUMERIC_INPUT); setFieldValue(asfData, asFormObject, field, cmpId, index, ComponentTypes.NUMERIC_INPUT);
break; break;
} }
if (annotation instanceof Entity) { if (annotation instanceof Entity) {
String cmpId = ((Entity) annotation).value(); String cmpId = ((Entity) annotation).value();
setFieldValue(asfData, asFormObject, field, cmpId, ComponentTypes.ENTITY); setFieldValue(asfData, asFormObject, field, cmpId, index, ComponentTypes.ENTITY);
break; break;
} }
if (annotation instanceof ListBox) { if (annotation instanceof ListBox) {
String cmpId = ((ListBox) annotation).value(); String cmpId = ((ListBox) annotation).value();
setFieldValue(asfData, asFormObject, field, cmpId, ComponentTypes.LISTBOX); setFieldValue(asfData, asFormObject, field, cmpId, index, ComponentTypes.LISTBOX);
break; break;
} }
if (annotation instanceof Table) { if (annotation instanceof Table) {
String cmpId = ((Table) annotation).value(); Table tableAnnotation = (Table) annotation;
if (field.getType().isAssignableFrom(AsFormData.class)) { if (field.getType().isAssignableFrom(AsFormData.class)) {
setFieldValue(asfData, asFormObject, field, cmpId, ComponentTypes.TABLE); setFieldValue(asfData, asFormObject, field, tableAnnotation.value(), index, ComponentTypes.TABLE);
} else if (field.getType().isAssignableFrom(List.class)) { } else if (field.getType().isAssignableFrom(List.class)) {
getList(asfData, field.getGenericType(), cmpId, ComponentTypes.TABLE); List list = tableToList(asfData, tableAnnotation.type(), tableAnnotation.id());
field.setAccessible(true);
field.set(asFormObject, list);
} else { } else {
throw new UnsupportedFieldTypeException(); throw new UnsupportedFieldTypeException();
} }
...@@ -95,27 +215,39 @@ public class AsFormProvider { ...@@ -95,27 +215,39 @@ public class AsFormProvider {
} }
} }
private void getList(AsForm asfData, Type genericType, String cmpId, String table) { private <T> void setFieldValue(
AsFormDataContainer asfData,
T asFormObject,
Field field,
String cmpId,
String index,
String cmpType
) throws IllegalAccessException {
field.setAccessible(true);
} if (index != null) {
cmpId = cmpId + "-b" + index;
}
private <T extends AsForm>
void
setFieldValue(AsForm asfData, T asFormObject, Field field, String cmpId, String cmpType) throws IllegalAccessException, UnsupportedFieldTypeException {
field.setAccessible(true);
if (field.getType().isAssignableFrom(String.class)) { if (field.getType().isAssignableFrom(String.class)) {
// string // string
String value = getValueForClassField(field, asfData, cmpId); String value = getValueForClassField(field, asfData, cmpId);
field.set(asFormObject, value); field.set(asFormObject, value);
} if (field.getType().isAssignableFrom(Integer.class)) { } else if (field.getType().isAssignableFrom(Integer.class)) {
// int // int
String value = getValueForClassField(field, asfData, cmpId); String value = getValueForClassField(field, asfData, cmpId);
if (value == null) {
value = "0";
}
field.set(asFormObject, Integer.parseInt(value)); field.set(asFormObject, Integer.parseInt(value));
} if (field.getType().isAssignableFrom(Double.class)) { } else if (field.getType().isAssignableFrom(Double.class)) {
// double // double
String value = getValueForClassField(field, asfData, cmpId); String value = getValueForClassField(field, asfData, cmpId);
if (value == null) {
value = "0";
}
field.set(asFormObject, Double.parseDouble(value)); field.set(asFormObject, Double.parseDouble(value));
} else if (field.getType().isAssignableFrom(AsFormData.class)) { } else if (field.getType().isAssignableFrom(AsFormData.class)) {
...@@ -142,17 +274,37 @@ public class AsFormProvider { ...@@ -142,17 +274,37 @@ public class AsFormProvider {
} }
} }
private String getValueForClassField(Field field, AsForm asfData, String cmpId) { @SuppressWarnings("unchecked")
private List tableToList(AsFormDataContainer asfData, Class genericType, String cmpId) {
AsFormData tableData = asfData.getData(cmpId);
if (tableData == null || tableData.getData() == null || tableData.getData().isEmpty()) {
return null;
}
List table = new ArrayList<>();
Set<String> indexes = AsfTableUtil.tableBIndexes(tableData);
for (String index : indexes) {
table.add(createAsFormObject(genericType, tableData, index));
}
return table;
}
private String getValueForClassField(Field field, AsFormDataContainer asfData, String cmpId) {
if (hasKeyValueAnnotation(field)) {
return asfData.getKey(cmpId);
}
return asfData.getValue(cmpId);
}
private boolean hasKeyValueAnnotation(Field field) {
boolean fetchKey = false; boolean fetchKey = false;
Annotation[] declaredAnnotations = field.getDeclaredAnnotations(); Annotation[] declaredAnnotations = field.getDeclaredAnnotations();
for (Annotation annotation : declaredAnnotations) { for (Annotation annotation : declaredAnnotations) {
if (annotation instanceof KeyValue) { if (annotation instanceof KeyValue) {
fetchKey = true; fetchKey = true;
break;
} }
} }
if (fetchKey) { return fetchKey;
return asfData.getKey(cmpId);
}
return asfData.getValue(cmpId);
} }
} }
package kz.arta.synergy.api.asforms;
import kz.arta.synergy.api.asforms.pojo.AsFormData;
import kz.arta.synergy.api.asforms.pojo.AsFormDataContainer;
import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* User: vsl
* Date: 3/18/15
* Time: 9:48 AM
*
* Утилиты для работы с данными форм
*/
public class AsfTableUtil {
private static final Pattern BLOCK_ID_PATTERN = Pattern.compile("(.*)-b([0-9]{1,})$");
/**
* Есть ли табличный индекс в id
*/
public static boolean hasBIndex(String id) {
return BLOCK_ID_PATTERN.matcher(id).matches();
}
/**
* Возвращает табличный индекс из id, если его нет - null
*/
public static String getBindex(String id) {
Matcher matcher = BLOCK_ID_PATTERN.matcher(id);
if (!matcher.matches()) {
return null;
} else {
return matcher.group(2);
}
}
/**
* Возвращает часть id без табличного индекса если он есть,
* если нет - просто возвращает id
*/
public static String getBlockComponentId(String id) {
Matcher matcher = BLOCK_ID_PATTERN.matcher(id);
if (!matcher.matches()) {
return id;
} else {
return matcher.group(1);
}
}
/**
* Возвращает табличный индекс из id, если его нет -1
*/
public static int getIntBindex(String id) {
String bIndex = getBindex(id);
if (bIndex == null || bIndex.isEmpty()) {
return -1;
}
try {
return Integer.parseInt(bIndex);
} catch (NumberFormatException e) {
return -1;
}
}
public static Set<String> tableBIndexes(AsFormDataContainer asFormDataContainer) {
Set<String> indexes = new TreeSet<>();
for (AsFormData data : asFormDataContainer.getData()) {
if (data == null || data.getId() == null || data.getId().isEmpty()) {
continue;
}
if (hasBIndex(data.getId())) {
indexes.add(getBindex(data.getId()));
}
}
return indexes;
}
}
package kz.arta.synergy.api.asforms.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @author raimbek
* @since 09.11.2016
*/
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Cmp {
String id();
String type();
}
package kz.arta.synergy.asforms.annotations; package kz.arta.synergy.api.asforms.annotations;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
...@@ -9,7 +9,7 @@ import java.lang.annotation.Target; ...@@ -9,7 +9,7 @@ import java.lang.annotation.Target;
* @author raimbek * @author raimbek
* @since 09.11.2016 * @since 09.11.2016
*/ */
@Target({ElementType.METHOD, ElementType.FIELD}) @Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface Entity { public @interface Entity {
......
package kz.arta.synergy.api.asforms.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @author raimbek
* @since 10.11.2016
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Form {
String id() default "";
String code() default "";
String config() default "";
}
package kz.arta.synergy.asforms.annotations; package kz.arta.synergy.api.asforms.annotations;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
...@@ -9,7 +9,7 @@ import java.lang.annotation.Target; ...@@ -9,7 +9,7 @@ import java.lang.annotation.Target;
* @author raimbek * @author raimbek
* @since 09.11.2016 * @since 09.11.2016
*/ */
@Target({ElementType.METHOD, ElementType.FIELD}) @Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface KeyValue { public @interface KeyValue {
......
package kz.arta.synergy.asforms.annotations; package kz.arta.synergy.api.asforms.annotations;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
...@@ -9,7 +9,7 @@ import java.lang.annotation.Target; ...@@ -9,7 +9,7 @@ import java.lang.annotation.Target;
* @author raimbek * @author raimbek
* @since 09.11.2016 * @since 09.11.2016
*/ */
@Target({ElementType.METHOD, ElementType.FIELD}) @Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface ListBox { public @interface ListBox {
......
package kz.arta.synergy.asforms.annotations; package kz.arta.synergy.api.asforms.annotations;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
...@@ -9,7 +9,7 @@ import java.lang.annotation.Target; ...@@ -9,7 +9,7 @@ import java.lang.annotation.Target;
* @author raimbek * @author raimbek
* @since 09.11.2016 * @since 09.11.2016
*/ */
@Target({ElementType.METHOD, ElementType.FIELD}) @Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface NumericInput { public @interface NumericInput {
......
package kz.arta.synergy.asforms.annotations; package kz.arta.synergy.api.asforms.annotations;
import kz.arta.synergy.api.asforms.pojo.AsFormData;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
...@@ -9,10 +11,13 @@ import java.lang.annotation.Target; ...@@ -9,10 +11,13 @@ import java.lang.annotation.Target;
* @author raimbek * @author raimbek
* @since 09.11.2016 * @since 09.11.2016
*/ */
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.TYPE}) @Target({ElementType.FIELD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface Table { public @interface Table {
String value(); String value() default "";
String id() default "";
Class type() default AsFormData.class;
} }
package kz.arta.synergy.asforms.annotations; package kz.arta.synergy.api.asforms.annotations;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
...@@ -9,7 +9,7 @@ import java.lang.annotation.Target; ...@@ -9,7 +9,7 @@ import java.lang.annotation.Target;
* @author raimbek * @author raimbek
* @since 09.11.2016 * @since 09.11.2016
*/ */
@Target({ElementType.METHOD, ElementType.FIELD}) @Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface TextInput { public @interface TextInput {
......
package kz.arta.synergy.asforms.exceptions; package kz.arta.synergy.api.asforms.exceptions;
/** /**
* @author raimbek * @author raimbek
* @since 09.11.2016 * @since 09.11.2016
*/ */
public class CreateAsFormException extends Exception { public class CreateAsFormException extends RuntimeException {
public CreateAsFormException(String message) { public CreateAsFormException(String message) {
super(message); super(message);
......
package kz.arta.synergy.asforms.exceptions; package kz.arta.synergy.api.asforms.exceptions;
/** /**
* @author raimbek * @author raimbek
* @since 09.11.2016 * @since 09.11.2016
*/ */
public class SynergyApiCallException extends Exception { public class SynergyApiCallException extends RuntimeException {
public SynergyApiCallException() { public SynergyApiCallException() {
} }
......
package kz.arta.synergy.asforms.exceptions; package kz.arta.synergy.api.asforms.exceptions;
/** /**
* @author raimbek * @author raimbek
* @since 09.11.2016 * @since 09.11.2016
*/ */
public class UnsupportedFieldTypeException extends Exception { public class UnsupportedFieldTypeException extends RuntimeException {
public UnsupportedFieldTypeException() { public UnsupportedFieldTypeException() {
} }
......
package kz.arta.synergy.asforms; package kz.arta.synergy.api.asforms.pojo;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
......
package kz.arta.synergy.asforms; package kz.arta.synergy.api.asforms.pojo;
/** /**
* @author raimbek * @author raimbek
* @since 02.11.2016 * @since 02.11.2016
*/ */
public class AdvancedSearchResult<T> { public class AdvancedSearchResult {
private String dataUUID; private String dataUUID;
private String documentID; private String documentID;
private String registryRecordStatus; private String registryRecordStatus;
......
package kz.arta.synergy.api.asforms.pojo;
/**
* @author raimbek
* @since 09.11.2016
*/
public class AsForm {
private String nodeUUID;
private String uuid;
private String form;
private String modified;
public AsForm() {
}
public String getNodeUUID() {
return nodeUUID;
}
public void setNodeUUID(String nodeUUID) {
this.nodeUUID = nodeUUID;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public String getForm() {
return form;
}
public void setForm(String form) {
this.form = form;
}
public String getModified() {
return modified;
}
public void setModified(String modified) {
this.modified = modified;
}
}
package kz.arta.synergy.asforms.pojo; package kz.arta.synergy.api.asforms.pojo;
import java.util.List; import java.util.List;
...@@ -6,7 +6,7 @@ import java.util.List; ...@@ -6,7 +6,7 @@ import java.util.List;
* @author raimbek * @author raimbek
* @since 09.11.2016 * @since 09.11.2016
*/ */
public class AsFormData { public class AsFormData extends AsFormDataContainer {
private String id; private String id;
private String type; private String type;
private String label; private String label;
...@@ -17,7 +17,6 @@ public class AsFormData { ...@@ -17,7 +17,6 @@ public class AsFormData {
private String userID; private String userID;
private List<String> values; private List<String> values;
private List<String> keys; private List<String> keys;
private List<AsFormData> data;
public String getId() { public String getId() {
return id; return id;
...@@ -99,11 +98,23 @@ public class AsFormData { ...@@ -99,11 +98,23 @@ public class AsFormData {
this.keys = keys; this.keys = keys;
} }
public List<AsFormData> getData() { public static AsFormData textbox(String cmpId, String value) {
return data; AsFormData asFormData = create(cmpId, ComponentTypes.TEXT_BOX);
asFormData.setValue(value);
return asFormData;
} }
public void setData(List<AsFormData> data) { public static AsFormData numericinput(String cmpId, String value, String key) {
this.data = data; AsFormData asFormData = create(cmpId, ComponentTypes.NUMERIC_INPUT);
asFormData.setValue(value);
asFormData.setKey(key);
return asFormData;
}
public static AsFormData create(String id, String type) {
AsFormData asFormData = new AsFormData();
asFormData.setId(id);
asFormData.setType(type);
return asFormData;
} }
} }
package kz.arta.synergy.asforms.pojo; package kz.arta.synergy.api.asforms.pojo;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* @author raimbek * @author raimbek
* @since 09.11.2016 * @since 10.11.2016
*/ */
public class AsForm { public class AsFormDataContainer {
private String nodeUUID;
private String uuid;
private String form;
private String modified;
private List<AsFormData> data; private List<AsFormData> data;
public AsForm() { public AsFormDataContainer() {
} }
public AsFormData getData(String cmpId) { public AsFormData getData(String cmpId) {
...@@ -45,38 +42,6 @@ public class AsForm { ...@@ -45,38 +42,6 @@ public class AsForm {
return null; return null;
} }
public String getNodeUUID() {
return nodeUUID;
}
public void setNodeUUID(String nodeUUID) {
this.nodeUUID = nodeUUID;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public String getForm() {
return form;
}
public void setForm(String form) {
this.form = form;
}
public String getModified() {
return modified;
}
public void setModified(String modified) {
this.modified = modified;
}
public List<AsFormData> getData() { public List<AsFormData> getData() {
return data; return data;
} }
...@@ -84,4 +49,11 @@ public class AsForm { ...@@ -84,4 +49,11 @@ public class AsForm {
public void setData(List<AsFormData> data) { public void setData(List<AsFormData> data) {
this.data = data; this.data = data;
} }
public void addData(AsFormData data) {
if (this.data == null) {
this.data = new ArrayList<>();
}
this.data.add(data);
}
} }
package kz.arta.synergy.api.asforms.pojo;
/**
* @author raimbek
* @since 09.11.2016
*/
public class AsFormWrapper extends AsFormDataContainer {
private String nodeUUID;
private String uuid;
private String form;
private String modified;
public AsFormWrapper() {
}
public String getNodeUUID() {
return nodeUUID;
}
public void setNodeUUID(String nodeUUID) {
this.nodeUUID = nodeUUID;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public String getForm() {
return form;
}
public void setForm(String form) {
this.form = form;
}
public String getModified() {
return modified;
}
public void setModified(String modified) {
this.modified = modified;
}
}
package kz.arta.synergy.asforms.pojo; package kz.arta.synergy.api.asforms.pojo;
/** /**
* @author raimbek * @author raimbek
* @since 09.11.2016 * @since 09.11.2016
*/ */
public class ComponentTypes { public class ComponentTypes {
public static final String TEXT_INPUT = "textinput"; public static final String TEXT_BOX = "textbox";
public static final String NUMERIC_INPUT = "numericinput"; public static final String NUMERIC_INPUT = "numericinput";
public static final String LISTBOX = "listbox"; public static final String LISTBOX = "listbox";
public static final String ENTITY = "entity"; public static final String ENTITY = "entity";
public static final String TABLE = "appendable_table"; public static final String TABLE = "appendable_table";
public static final String FILE = "file";
public static final String TEXTAREA = "textarea";
public static final String HTD = "htd";
public static final String DATE = "date";
public static final String CHECK = "check";
public static final String RADIO = "radio";
public static final String IMAGE = "image";
public static final String LINK = "link";
public static final String PROJECT_LINK = "projectlink";
public static final String FILE_LINK = "filelink";
public static final String REG_LINK = "reglink";
} }
package kz.arta.synergy.asforms;
import kz.arta.synergy.asforms.exceptions.SynergyApiCallException;
import kz.arta.synergy.asforms.pojo.AsForm;
/**
* @author raimbek
* @since 09.11.2016
*/
public class SynergyApiProvider {
public AsForm getAsfData(String dataUUID) throws SynergyApiCallException {
return new AsForm();
}
}
package kz.arta.synergy.api.asforms;
import kz.arta.synergy.api.SynergyApiProvider;
import kz.arta.synergy.api.asforms.pojo.AsFormData;
import kz.arta.synergy.api.asforms.pojo.AsFormWrapper;
import kz.arta.synergy.api.asforms.pojo.ComponentTypes;
import kz.arta.synergy.pojo.TableCmp;
import kz.arta.synergy.pojo.TestForm;
import org.mockito.Mockito;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.util.List;
/**
* @author raimbek
* @since 09.11.2016
*/
public class AsFormProviderTest {
String expectedTextInputValue = "value_1";
String expectedNumericInputValue = "value_2";
String expectedNumericInputKey = "key_1";
String expectedFileValue = "file_value";
String expectedFileKey = "file_key";
String expectedDoubleValue = "45.2";
String expectedIntegerValue = "456";
String expectedTableInputValueB1 = "table_input_b1";
String expectedTableInputValueB2 = "table_input_b2";
TestForm testForm;
AsFormProvider asFormProvider;
@BeforeClass
public void createAsfWrapper() {
AsFormWrapper asFormWrapper = new AsFormWrapper();
asFormWrapper.addData(AsFormData.textbox("text_input", expectedTextInputValue));
asFormWrapper.addData(AsFormData.textbox("double_input", expectedDoubleValue));
asFormWrapper.addData(AsFormData.textbox("integer_input", expectedIntegerValue));
asFormWrapper.addData(AsFormData.numericinput("numeric_input_key", expectedNumericInputValue, expectedNumericInputKey));
asFormWrapper.addData(AsFormData.numericinput("numeric_input_value", expectedNumericInputValue, expectedNumericInputKey));
asFormWrapper.addData(AsFormData.numericinput("file", expectedFileValue, expectedFileKey));
AsFormData tableData = new AsFormData();
tableData.setType(ComponentTypes.TABLE);
tableData.setId("table_cmp");
tableData.addData(AsFormData.textbox("table_input-b1", expectedTableInputValueB1));
tableData.addData(AsFormData.numericinput("table_input_2-b1", expectedTableInputValueB1, expectedTableInputValueB1));
tableData.addData(AsFormData.textbox("table_input-b2", expectedTableInputValueB2));
tableData.addData(AsFormData.numericinput("table_input_2-b2", expectedTableInputValueB2, expectedTableInputValueB2));
asFormWrapper.getData().add(tableData);
SynergyApiProvider synergyApiProviderMock = Mockito.mock(SynergyApiProvider.class);
Mockito.when(synergyApiProviderMock.getAsfData(Mockito.anyString())).thenReturn(asFormWrapper);
asFormProvider = AsFormProvider.newInstance(synergyApiProviderMock);
testForm = asFormProvider.fetch(TestForm.class, "123456");
}
@Test
public void testTextInputValue() {
Assert.assertEquals(testForm.getTextInput(), expectedTextInputValue);
}
@Test
public void testNumericInputValue() {
Assert.assertEquals(testForm.getNumericInputValue(), expectedNumericInputValue);
}
@Test
public void testNumericInputKey() {
Assert.assertEquals(testForm.getNumericInputKey(), expectedNumericInputKey);
}
@Test
public void testFile() {
AsFormData fileData = testForm.getFile();
Assert.assertEquals(fileData.getValue(), expectedFileValue);
Assert.assertEquals(fileData.getKey(), expectedFileKey);
}
@Test
public void testDoubleValue() {
Assert.assertEquals(testForm.getDoubleValue(), Double.parseDouble(expectedDoubleValue));
}
@Test
public void testIntegerValue() {
Assert.assertEquals(testForm.getIntegerValue(), Integer.parseInt(expectedIntegerValue));
}
@Test
public void testTableData() {
List<TableCmp> tableData = testForm.getTableData();
Assert.assertEquals(tableData.get(0).getTableInput(), expectedTableInputValueB1);
Assert.assertEquals(tableData.get(1).getTableInput(), expectedTableInputValueB2);
}
@Test
public void toAsfData() {
AsFormWrapper asFormWrapper = asFormProvider.toAsfData(testForm);
AsFormData textInput = asFormWrapper.getData("text_input");
Assert.assertEquals(textInput.getType(), ComponentTypes.TEXT_BOX);
Assert.assertEquals(textInput.getValue(), expectedTextInputValue);
AsFormData tableCmp = asFormWrapper.getData("table_cmp");
Assert.assertEquals(tableCmp.getData().size(), 2);
}
}
package kz.arta.synergy.asforms; package kz.arta.synergy.api.asforms;
import kz.arta.synergy.api.SynergyApiProvider;
import org.testng.annotations.Test; import org.testng.annotations.Test;
/** /**
......
package kz.arta.synergy.asforms;
import kz.arta.synergy.asforms.exceptions.CreateAsFormException;
import kz.arta.synergy.asforms.exceptions.SynergyApiCallException;
import kz.arta.synergy.pojo.TestForm;
/**
* @author raimbek
* @since 09.11.2016
*/
public class AsFormProviderTest {
public static void main(String[] args) throws SynergyApiCallException, CreateAsFormException {
SynergyApiProvider synergyApiProvider = new SynergyApiProvider();
AsFormProvider asFormProvider = new AsFormProvider(synergyApiProvider);
TestForm testForm = asFormProvider.fetchData(TestForm.class, "123456");
}
}
package kz.arta.synergy.pojo;
import kz.arta.synergy.api.asforms.annotations.KeyValue;
import kz.arta.synergy.api.asforms.annotations.NumericInput;
import kz.arta.synergy.api.asforms.annotations.TextInput;
/**
* @author raimbek
* @since 10.11.2016
*/
public class TableCmp {
@TextInput("table_input")
private String tableInput;
@KeyValue
@NumericInput("table_input_2")
private String textInputKeyValue;
public String getTableInput() {
return tableInput;
}
public void setTableInput(String tableInput) {
this.tableInput = tableInput;
}
public String getTextInputKeyValue() {
return textInputKeyValue;
}
public void setTextInputKeyValue(String textInputKeyValue) {
this.textInputKeyValue = textInputKeyValue;
}
}
package kz.arta.synergy.pojo; package kz.arta.synergy.pojo;
import kz.arta.synergy.asforms.annotations.KeyValue; import kz.arta.synergy.api.asforms.annotations.*;
import kz.arta.synergy.asforms.annotations.NumericInput; import kz.arta.synergy.api.asforms.pojo.AsForm;
import kz.arta.synergy.asforms.annotations.Table; import kz.arta.synergy.api.asforms.pojo.AsFormData;
import kz.arta.synergy.asforms.annotations.TextInput; import kz.arta.synergy.api.asforms.pojo.ComponentTypes;
import kz.arta.synergy.asforms.pojo.AsForm;
import kz.arta.synergy.asforms.pojo.AsFormData;
import java.util.List; import java.util.List;
...@@ -13,17 +11,27 @@ import java.util.List; ...@@ -13,17 +11,27 @@ import java.util.List;
* @author raimbek * @author raimbek
* @since 09.11.2016 * @since 09.11.2016
*/ */
@Form(config = "application_form")
public class TestForm extends AsForm { public class TestForm extends AsForm {
@TextInput("text_input") @TextInput("text_input")
private String textInput; private String textInput;
@KeyValue @KeyValue
@NumericInput("text_input_2") @NumericInput("numeric_input_key")
private String textInputKeyValue; private String numericInputKey;
@Table("table_cmp") @NumericInput("numeric_input_value")
private List<List<AsFormData>> tableData; private String numericInputValue;
@Cmp(id = "file", type = ComponentTypes.FILE)
private AsFormData file;
@TextInput("double_input")
private Double doubleValue;
@TextInput("integer_input")
private Integer integerValue;
public String getTextInput() { public String getTextInput() {
return textInput; return textInput;
...@@ -32,4 +40,55 @@ public class TestForm extends AsForm { ...@@ -32,4 +40,55 @@ public class TestForm extends AsForm {
public void setTextInput(String textInput) { public void setTextInput(String textInput) {
this.textInput = textInput; this.textInput = textInput;
} }
public String getNumericInputKey() {
return numericInputKey;
}
public void setNumericInputKey(String numericInputKey) {
this.numericInputKey = numericInputKey;
}
public String getNumericInputValue() {
return numericInputValue;
}
public void setNumericInputValue(String numericInputValue) {
this.numericInputValue = numericInputValue;
}
public AsFormData getFile() {
return file;
}
public void setFile(AsFormData file) {
this.file = file;
}
public Double getDoubleValue() {
return doubleValue;
}
public void setDoubleValue(Double doubleValue) {
this.doubleValue = doubleValue;
}
public int getIntegerValue() {
return integerValue;
}
public void setIntegerValue(Integer integerValue) {
this.integerValue = integerValue;
}
@Table(id = "table_cmp", type = TableCmp.class)
private List<TableCmp> tableData;
public List<TableCmp> getTableData() {
return tableData;
}
public void setTableData(List<TableCmp> tableData) {
this.tableData = tableData;
}
} }
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