group.rober.dataform.util.DataFormUtils Maven / Gradle / Ivy
package group.rober.dataform.util;
import group.rober.dataform.exception.DataFormException;
import group.rober.dataform.exception.ValidatorException;
import group.rober.dataform.mapper.impl.po.DataFormElementPO;
import group.rober.dataform.mapper.impl.po.FormElementValidatorPO;
import group.rober.dataform.model.DataForm;
import group.rober.dataform.model.DataFormElement;
import group.rober.dataform.model.types.ElementValidatorMode;
import group.rober.dataform.model.types.ElementValidatorRunAt;
import group.rober.dataform.model.types.FormDataModelType;
import group.rober.dataform.validator.ValidateRecord;
import group.rober.dataform.validator.ValidateResult;
import group.rober.runtime.holder.MessageHolder;
import group.rober.runtime.kit.BeanKit;
import group.rober.runtime.kit.ClassKit;
import group.rober.runtime.kit.StringKit;
import group.rober.runtime.lang.MapData;
import group.rober.runtime.lang.PairBond;
import group.rober.runtime.lang.ValueObject;
import group.rober.sql.core.DataAccessor;
import group.rober.sql.core.PaginationData;
import group.rober.sql.core.PaginationQuery;
import group.rober.sql.dialect.SqlDialectType;
import group.rober.sql.kit.SQLInjector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.LinkedCaseInsensitiveMap;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
* Created by luyu on 2017/12/26.
*/
public abstract class DataFormUtils {
protected static Logger logger = LoggerFactory.getLogger(DataFormUtils.class);
public static DataFormElementPO convertElementPO(DataFormElement dataFormElement) {
DataFormElement.FormElementUIHint hint = dataFormElement.getElementUIHint();
DataFormElementPO elementPO = new DataFormElementPO();
BeanKit.copyProperties(dataFormElement, elementPO);
BeanKit.copyProperties(dataFormElement.getElementUIHint(), elementPO);
elementPO.setPrimaryKey(dataFormElement.getPrimaryKey() ? "Y" : "N");
elementPO.setUpdateable(dataFormElement.getUpdateable() ? "Y" : "N");
elementPO.setPersist(dataFormElement.getPersist() ? "Y" : "N");
elementPO.setSortable(dataFormElement.getSortable() ? "Y" : "N");
elementPO.setEnabled(dataFormElement.getEnabled() ? "Y" : "N");
elementPO.setReadonly(hint.getReadonly() ? "Y" : "N");
elementPO.setRequired(hint.getRequired() ? "Y" : "N");
elementPO.setVisible(hint.getVisible() ? "Y" : "N");
elementPO.setDictCodeLazy(hint.getDictCodeLazy() ? "Y" : "N");
elementPO.setDictCodeTreeLeafOnly(hint.getDictCodeTreeLeafOnly() ? "Y" : "N");
elementPO.setDictCodeTreeFull(hint.getDictCodeTreeFull() ? "Y" : "N");
return elementPO;
}
public static List convertValidatorPO(DataFormElement element, String dataformId) {
List validatorPOs = element.getValidatorList().stream()
.map(formElementValidator -> getFormElementValidatorPO(formElementValidator, element.getCode(), dataformId))
.collect(Collectors.toList());
return validatorPOs;
}
private static FormElementValidatorPO getFormElementValidatorPO(
DataFormElement.FormElementValidator formElementValidator, String code, String dataformId) {
FormElementValidatorPO validatorPO = new FormElementValidatorPO();
BeanKit.copyProperties(formElementValidator, validatorPO);
validatorPO.setElementCode(code);
validatorPO.setDataformId(dataformId);
validatorPO.setMessage(formElementValidator.getDefaultMessage());
validatorPO.setMessageI18nCode(formElementValidator.getDefaultMessageI18nCode());
return validatorPO;
}
public static Class> getDataFormClass(DataForm dataForm) {
FormDataModelType dataModelType = dataForm.getDataModelType();
String id = dataForm.getId();
Class> clazz = null;
try {
clazz = Class.forName(dataForm.getDataModel());
} catch (ClassNotFoundException e) {
String error = "DataModel配置错误,formId={0},DataModelType={1},模型类:{2}不存在";
throw new DataFormException(error, id, dataModelType, dataForm.getDataModel());
}
return clazz;
}
public static List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy