Commit ca814402 authored by Raimbek Egemberdiev's avatar Raimbek Egemberdiev

moved to new module

parents
group 'kz.arta.synergy.asforms'
version '1.0'
apply plugin: 'java'
sourceCompatibility = 1.7
repositories {
mavenCentral()
}
dependencies {
compile group: 'cglib', name: 'cglib', version: '3.2.4'
testCompile group: 'org.testng', name: 'testng', version: '6.9.13.6'
}
package kz.arta.synergy.asforms;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* @author raimbek
* @since 02.11.2016
*/
public class AdvancedSearchParams {
private String query;
private List<String> parameters = new ArrayList<String>();
private boolean searchInRegistry = true;
private int startRecord = 0;
private int recordsCount = 100;
private List<List<String>> dynParams = new ArrayList<List<String>>();
public AdvancedSearchParams() {
}
public static AdvancedSearchParams build(String query, String... parameters) {
AdvancedSearchParams advancedSearchParams = new AdvancedSearchParams();
advancedSearchParams.setQuery(query);
advancedSearchParams.setParameters(Arrays.asList(parameters));
return advancedSearchParams;
}
public String getQuery() {
return query;
}
public void setQuery(String query) {
this.query = query;
}
public List<String> getParameters() {
return parameters;
}
public void setParameters(List<String> parameters) {
this.parameters = parameters;
}
public boolean isSearchInRegistry() {
return searchInRegistry;
}
public void setSearchInRegistry(boolean searchInRegistry) {
this.searchInRegistry = searchInRegistry;
}
public int getStartRecord() {
return startRecord;
}
public void setStartRecord(int startRecord) {
this.startRecord = startRecord;
}
public int getRecordsCount() {
return recordsCount;
}
public void setRecordsCount(int recordsCount) {
this.recordsCount = recordsCount;
}
public List<List<String>> getDynParams() {
return dynParams;
}
public void setDynParams(List<List<String>> dynParams) {
this.dynParams = dynParams;
}
}
package kz.arta.synergy.asforms;
/**
* @author raimbek
* @since 02.11.2016
*/
public class AdvancedSearchResult<T> {
private String dataUUID;
private String documentID;
private String registryRecordStatus;
public AdvancedSearchResult() {
}
public String getDataUUID() {
return dataUUID;
}
public void setDataUUID(String dataUUID) {
this.dataUUID = dataUUID;
}
public String getDocumentID() {
return documentID;
}
public void setDocumentID(String documentID) {
this.documentID = documentID;
}
public String getRegistryRecordStatus() {
return registryRecordStatus;
}
public void setRegistryRecordStatus(String registryRecordStatus) {
this.registryRecordStatus = registryRecordStatus;
}
}
package kz.arta.synergy.asforms;
import kz.arta.synergy.asforms.annotations.*;
import kz.arta.synergy.asforms.exceptions.CreateAsFormException;
import kz.arta.synergy.asforms.exceptions.SynergyApiCallException;
import kz.arta.synergy.asforms.exceptions.UnsupportedFieldTypeException;
import kz.arta.synergy.asforms.pojo.AsForm;
import kz.arta.synergy.asforms.pojo.AsFormData;
import kz.arta.synergy.asforms.pojo.ComponentTypes;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
/**
* @author raimbek
* @since 09.11.2016
*/
public class AsFormProvider {
private SynergyApiProvider synergyApiProvider;
public AsFormProvider() {
}
public AsFormProvider(SynergyApiProvider synergyApiProvider) {
this.synergyApiProvider = synergyApiProvider;
}
public <T extends AsForm>
List<AdvancedSearchResult<T>>
advancedSearch(Class<T> formClass, AdvancedSearchParams advancedSearchParams)
{
return new ArrayList<AdvancedSearchResult<T>>();
}
public <T extends AsForm>
T
fetchData(Class<T> formClass, String dataUUID) throws CreateAsFormException, SynergyApiCallException, UnsupportedFieldTypeException
{
AsForm asfData = synergyApiProvider.getAsfData(dataUUID);
return createAsForm(formClass, asfData);
}
public <T extends AsForm>
T
createAsForm(Class<T> asFormClass, AsForm asfData) throws CreateAsFormException, UnsupportedFieldTypeException {
try {
T asFormObject = asFormClass.newInstance();
Field[] allFields = asFormClass.getDeclaredFields();
for (Field field : allFields) {
Annotation[] declaredAnnotations = field.getDeclaredAnnotations();
for (Annotation annotation : declaredAnnotations) {
if (annotation instanceof TextInput) {
String cmpId = ((TextInput) annotation).value();
setFieldValue(asfData, asFormObject, field, cmpId, ComponentTypes.TEXT_INPUT);
break;
}
if (annotation instanceof NumericInput) {
String cmpId = ((NumericInput) annotation).value();
setFieldValue(asfData, asFormObject, field, cmpId, ComponentTypes.NUMERIC_INPUT);
break;
}
if (annotation instanceof Entity) {
String cmpId = ((Entity) annotation).value();
setFieldValue(asfData, asFormObject, field, cmpId, ComponentTypes.ENTITY);
break;
}
if (annotation instanceof ListBox) {
String cmpId = ((ListBox) annotation).value();
setFieldValue(asfData, asFormObject, field, cmpId, ComponentTypes.LISTBOX);
break;
}
if (annotation instanceof Table) {
String cmpId = ((Table) annotation).value();
if (field.getType().isAssignableFrom(AsFormData.class)) {
setFieldValue(asfData, asFormObject, field, cmpId, ComponentTypes.TABLE);
} else if (field.getType().isAssignableFrom(List.class)) {
getList(asfData, field.getGenericType(), cmpId, ComponentTypes.TABLE);
} else {
throw new UnsupportedFieldTypeException();
}
break;
}
}
}
return asFormObject;
} catch (InstantiationException e) {
throw new CreateAsFormException("Form class should has accessible without params constructor");
} catch (IllegalAccessException e) {
throw new CreateAsFormException("Form class should be accessible");
}
}
private void getList(AsForm asfData, Type genericType, String cmpId, String table) {
}
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)) {
// string
String value = getValueForClassField(field, asfData, cmpId);
field.set(asFormObject, value);
} if (field.getType().isAssignableFrom(Integer.class)) {
// int
String value = getValueForClassField(field, asfData, cmpId);
field.set(asFormObject, Integer.parseInt(value));
} if (field.getType().isAssignableFrom(Double.class)) {
// double
String value = getValueForClassField(field, asfData, cmpId);
field.set(asFormObject, Double.parseDouble(value));
} else if (field.getType().isAssignableFrom(AsFormData.class)) {
// common type
AsFormData data = asfData.getData(cmpId);
if (data != null) {
AsFormData fieldAsFormData = new AsFormData();
fieldAsFormData.setId(cmpId);
fieldAsFormData.setType(cmpType);
fieldAsFormData.setValue(data.getValue());
fieldAsFormData.setKey(data.getKey());
fieldAsFormData.setKeys(data.getKeys());
fieldAsFormData.setValues(data.getValues());
fieldAsFormData.setUserID(data.getUserID());
fieldAsFormData.setValueID(data.getValueID());
fieldAsFormData.setLabel(data.getLabel());
fieldAsFormData.setUsername(data.getUsername());
fieldAsFormData.setData(data.getData());
field.set(asFormObject, fieldAsFormData);
}
} else {
throw new UnsupportedFieldTypeException("This type unsupported");
}
}
private String getValueForClassField(Field field, AsForm asfData, String cmpId) {
boolean fetchKey = false;
Annotation[] declaredAnnotations = field.getDeclaredAnnotations();
for (Annotation annotation : declaredAnnotations) {
if (annotation instanceof KeyValue) {
fetchKey = true;
}
}
if (fetchKey) {
return asfData.getKey(cmpId);
}
return asfData.getValue(cmpId);
}
}
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.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.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Entity {
String value();
}
package kz.arta.synergy.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.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface KeyValue {
}
package kz.arta.synergy.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.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface ListBox {
String value();
}
package kz.arta.synergy.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.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface NumericInput {
String value();
}
package kz.arta.synergy.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.METHOD, ElementType.FIELD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface Table {
String value();
}
package kz.arta.synergy.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.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface TextInput {
String value();
}
package kz.arta.synergy.asforms.exceptions;
/**
* @author raimbek
* @since 09.11.2016
*/
public class CreateAsFormException extends Exception {
public CreateAsFormException(String message) {
super(message);
}
}
package kz.arta.synergy.asforms.exceptions;
/**
* @author raimbek
* @since 09.11.2016
*/
public class SynergyApiCallException extends Exception {
public SynergyApiCallException() {
}
public SynergyApiCallException(String message) {
super(message);
}
}
package kz.arta.synergy.asforms.exceptions;
/**
* @author raimbek
* @since 09.11.2016
*/
public class UnsupportedFieldTypeException extends Exception {
public UnsupportedFieldTypeException() {
}
public UnsupportedFieldTypeException(String message) {
super(message);
}
}
package kz.arta.synergy.asforms.pojo;
import java.util.List;
/**
* @author raimbek
* @since 09.11.2016
*/
public class AsForm {
private String nodeUUID;
private String uuid;
private String form;
private String modified;
private List<AsFormData> data;
public AsForm() {
}
public AsFormData getData(String cmpId) {
if (getData() == null || getData().isEmpty()) {
return null;
}
for (AsFormData asFormData : getData()) {
if (asFormData.getId() != null && asFormData.getId().equalsIgnoreCase(cmpId)) {
return asFormData;
}
}
return null;
}
public String getValue(String cmpId) {
AsFormData data = getData(cmpId);
if (data != null) {
return data.getValue();
}
return null;
}
public String getKey(String cmpId) {
AsFormData data = getData(cmpId);
if (data != null) {
return data.getKey();
}
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() {
return data;
}
public void setData(List<AsFormData> data) {
this.data = data;
}
}
package kz.arta.synergy.asforms.pojo;
import java.util.List;
/**
* @author raimbek
* @since 09.11.2016
*/
public class AsFormData {
private String id;
private String type;
private String label;
private String value;
private String key;
private String valueID;
private String username;
private String userID;
private List<String> values;
private List<String> keys;
private List<AsFormData> data;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValueID() {
return valueID;
}
public void setValueID(String valueID) {
this.valueID = valueID;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getUserID() {
return userID;
}
public void setUserID(String userID) {
this.userID = userID;
}
public List<String> getValues() {
return values;
}
public void setValues(List<String> values) {
this.values = values;
}
public List<String> getKeys() {
return keys;
}
public void setKeys(List<String> keys) {
this.keys = keys;
}
public List<AsFormData> getData() {
return data;
}
public void setData(List<AsFormData> data) {
this.data = data;
}
}
package kz.arta.synergy.asforms.pojo;
/**
* @author raimbek
* @since 09.11.2016
*/
public class ComponentTypes {
public static final String TEXT_INPUT = "textinput";
public static final String NUMERIC_INPUT = "numericinput";
public static final String LISTBOX = "listbox";
public static final String ENTITY = "entity";
public static final String TABLE = "appendable_table";
}
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.asforms;
import org.testng.annotations.Test;
/**
* @author raimbek
* @since 09.11.2016
*/
public class AsFormTest {
private SynergyApiProvider synergyApiProvider;
@Test
public void createAsForm() {
}
}
package kz.arta.synergy.pojo;
import kz.arta.synergy.asforms.annotations.KeyValue;
import kz.arta.synergy.asforms.annotations.NumericInput;
import kz.arta.synergy.asforms.annotations.Table;
import kz.arta.synergy.asforms.annotations.TextInput;
import kz.arta.synergy.asforms.pojo.AsForm;
import kz.arta.synergy.asforms.pojo.AsFormData;
import java.util.List;
/**
* @author raimbek
* @since 09.11.2016
*/
public class TestForm extends AsForm {
@TextInput("text_input")
private String textInput;
@KeyValue
@NumericInput("text_input_2")
private String textInputKeyValue;
@Table("table_cmp")
private List<List<AsFormData>> tableData;
public String getTextInput() {
return textInput;
}
public void setTextInput(String textInput) {
this.textInput = textInput;
}
}
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