Search in sources :

Example 1 with LabelValueVO

use of com.ds.retl.rest.vo.LabelValueVO in project main by JohnPeng739.

the class TopologyManageResource method getSupported.

/**
 * 获取系统中相关的各种支持列表信息
 *
 * @return 支持信息列表
 */
@Path("topology/supported")
@GET
public DataVO<SupportedVO> getSupported() {
    SupportedVO supportedVO = new SupportedVO();
    // get JMS supported
    List<LabelValueVO> supportedJms = new ArrayList<>();
    for (JmsManager.Supported s : JmsManager.Supported.values()) {
        supportedJms.add(new LabelValueVO(s.name(), s.name()));
    }
    Collections.sort(supportedJms);
    supportedVO.setJmsTypes(supportedJms);
    // get validate types
    List<String> validateClasses = ClassUtils.scanPackage("com.ds.retl.validate");
    List<LabelValueVO> validateTypes = this.transform(validateClasses);
    Collections.sort(validateTypes);
    supportedVO.setValidateTypes(validateTypes);
    // get validate rule types
    TypeValidateFunc.ValueType[] types = TypeValidateFunc.ValueType.values();
    List<LabelValueVO> supportedValidateRules = new ArrayList<>();
    for (TypeValidateFunc.ValueType type : types) {
        switch(type) {
            case STRING:
                supportedValidateRules.add(new LabelValueVO("1. 字符串类型", type.name()));
                break;
            case DATE:
                supportedValidateRules.add(new LabelValueVO("2. 时间类型", type.name()));
                break;
            case INT:
                supportedValidateRules.add(new LabelValueVO("3. 整数", type.name()));
                break;
            case DECIMAL:
                supportedValidateRules.add(new LabelValueVO("4. 小数类型", type.name()));
                break;
            case BOOL:
                supportedValidateRules.add(new LabelValueVO("5. 布尔类型", type.name()));
                break;
            default:
                if (logger.isWarnEnabled()) {
                    logger.warn(String.format("Unsupported type: %s.", type));
                }
        }
    }
    Collections.sort(supportedValidateRules);
    supportedVO.setValidateRuleTypes(supportedValidateRules);
    // get transform types
    List<String> transformClasses = ClassUtils.scanPackage("com.ds.retl.transform");
    List<LabelValueVO> transformTypes = this.transform(transformClasses);
    Collections.sort(transformTypes);
    supportedVO.setTransformTypes(transformTypes);
    return new DataVO<>(supportedVO);
}
Also used : ArrayList(java.util.ArrayList) LabelValueVO(com.ds.retl.rest.vo.LabelValueVO) PaginationDataVO(org.mx.rest.vo.PaginationDataVO) DataVO(org.mx.rest.vo.DataVO) TypeValidateFunc(com.ds.retl.validate.TypeValidateFunc) JmsManager(com.ds.retl.jms.JmsManager) SupportedVO(com.ds.retl.rest.vo.topology.SupportedVO)

Example 2 with LabelValueVO

use of com.ds.retl.rest.vo.LabelValueVO in project main by JohnPeng739.

the class TopologyManageResource method transform.

/**
 * 将符合条件的类信息转换为Label-Value值对象
 *
 * @param classes 类名列表
 * @return 成功返回Label-Value值对象列表,否则返回空列表。
 */
private List<LabelValueVO> transform(List<String> classes) {
    List<LabelValueVO> supported = new ArrayList<>();
    if (classes != null && !classes.isEmpty()) {
        classes.forEach(className -> {
            try {
                Class<?> clazz = Class.forName(className);
                Field codeField = clazz.getDeclaredField("CODE");
                Field nameField = clazz.getDeclaredField("NAME");
                String code = null, name = null;
                if (codeField != null) {
                    code = (String) codeField.get(clazz);
                }
                if (nameField != null) {
                    name = (String) nameField.get(clazz);
                }
                if (!StringUtils.isBlank(code) && !StringUtils.isBlank(name)) {
                    supported.add(new LabelValueVO(name, code));
                }
            } catch (Exception ex) {
                if (logger.isInfoEnabled()) {
                    logger.info(String.format("Fetch class[%s] info fail.", className));
                }
            }
        });
    }
    return supported;
}
Also used : LabelValueVO(com.ds.retl.rest.vo.LabelValueVO) Field(java.lang.reflect.Field) ArrayList(java.util.ArrayList) EntityAccessException(org.mx.dal.exception.EntityAccessException) UserInterfaceErrorException(com.ds.retl.exception.UserInterfaceErrorException)

Aggregations

LabelValueVO (com.ds.retl.rest.vo.LabelValueVO)2 ArrayList (java.util.ArrayList)2 UserInterfaceErrorException (com.ds.retl.exception.UserInterfaceErrorException)1 JmsManager (com.ds.retl.jms.JmsManager)1 SupportedVO (com.ds.retl.rest.vo.topology.SupportedVO)1 TypeValidateFunc (com.ds.retl.validate.TypeValidateFunc)1 Field (java.lang.reflect.Field)1 EntityAccessException (org.mx.dal.exception.EntityAccessException)1 DataVO (org.mx.rest.vo.DataVO)1 PaginationDataVO (org.mx.rest.vo.PaginationDataVO)1