Commit 8020154f authored by Raimbek Egemberdiev's avatar Raimbek Egemberdiev

рефакторинг импорта платежей

parent b4b09319
......@@ -87,7 +87,7 @@ public class AsFormService {
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
String.format("where uuid='%s' and %s='%s'", formId, key, value), key
));
}
......@@ -142,7 +142,8 @@ public class AsFormService {
}
public <T extends AsForm> String saveData(T asForm) throws IOException {
return saveData(asFormConverter.toAsfData(asForm));
AsFormWrapper asFormWrapper = asFormConverter.toAsfData(asForm);
return saveData(asFormWrapper);
}
public <T extends AsForm> AsFormWrapper toAsfData(T asForm) {
......
package kz.arta.synergy.api.asforms.annotations;
import kz.arta.synergy.api.asforms.pojo.DefaultListBoxDictionary;
import kz.arta.synergy.api.asforms.pojo.ListBoxDictionary;
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 Radio {
String id() default "";
Class<? extends ListBoxDictionary> dictionary() default DefaultListBoxDictionary.class;
}
......@@ -31,6 +31,7 @@ public class DefaultAsFormConverter implements AsFormConverter {
registerConverter(ListBox.class, new ListBoxConverter());
registerConverter(Table.class, new TableConverter(this));
registerConverter(DateCmp.class, new DateConverter());
registerConverter(Radio.class, new RadioConverter());
}
@Override
......
package kz.arta.synergy.api.asforms.converter.components;
import kz.arta.synergy.api.asforms.annotations.Radio;
import kz.arta.synergy.api.asforms.pojo.AsFormData;
import kz.arta.synergy.api.asforms.pojo.ComponentTypes;
import kz.arta.synergy.api.asforms.pojo.ListBoxDictionary;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
/**
* @author raimbek
* @since 11.11.2016
*/
public class RadioConverter extends AbstractComponentConverter {
@Override
public <T> AsFormData toAsfData(T asForm, Field field, Annotation annotation, String index) throws IllegalAccessException {
field.setAccessible(true);
String cmpId = getCmpId(field, annotation, index);
AsFormData asFormData = AsFormData.create(cmpId, getType(annotation));
Object valueObject = field.get(asForm);
if (valueObject instanceof AsFormData) {
AsFormData asFormDataObject = (AsFormData) valueObject;
asFormDataObject.setId(cmpId);
asFormDataObject.setType(getType(annotation));
return asFormDataObject;
} else {
String value = String.valueOf(valueObject);
try {
ListBoxDictionary listBoxDictionary = ((Radio) annotation).dictionary().newInstance();
if (hasKeyValueAnnotation(field)) {
asFormData.setKey(value);
asFormData.setValue(listBoxDictionary.getValue(value));
} else {
asFormData.setValue(value);
asFormData.setKey(listBoxDictionary.getValue(value));
}
} catch (InstantiationException e) {
e.printStackTrace();
}
}
return asFormData;
}
@Override
public String getType(Annotation annotation) {
return ComponentTypes.RADIO;
}
@Override
public String getCmpId(Annotation annotation) {
return ((Radio) annotation).id();
}
}
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