Search in sources :

Example 1 with DelegateControl4JsonPostMsgHandler

use of com.qlangtech.tis.runtime.module.misc.impl.DelegateControl4JsonPostMsgHandler in project plugins by qlangtech.

the class TestRockMqPluginValidate method validatePluginPostForm.

private void validatePluginPostForm(String jsonPath, Context context) throws IOException {
    // DefaultFieldErrorHandler fieldErrorHandler = new DefaultFieldErrorHandler();
    DelegateControl4JsonPostMsgHandler fieldErrorHandler = null;
    List<AttrValMap> attrValMaps = null;
    try {
        try (InputStream reader = this.getClass().getResourceAsStream(jsonPath)) {
            JSONArray itemsArray = JSONArray.parseArray(IOUtils.toString(reader, TisUTF8.get()));
            attrValMaps = AttrValMap.describableAttrValMapList(fieldErrorHandler, itemsArray, Optional.empty());
        }
    } catch (Exception e) {
        throw new IllegalStateException("jsonPath:" + jsonPath, e);
    }
    assertNotNull(attrValMaps);
    assertEquals(1, attrValMaps.size());
    AttrValMap attrValMap = attrValMaps.get(0);
    Descriptor.PluginValidateResult validateResult = attrValMap.validate(context, true);
    assertFalse("validate false", validateResult.isValid());
}
Also used : DelegateControl4JsonPostMsgHandler(com.qlangtech.tis.runtime.module.misc.impl.DelegateControl4JsonPostMsgHandler) InputStream(java.io.InputStream) JSONArray(com.alibaba.fastjson.JSONArray) Descriptor(com.qlangtech.tis.extension.Descriptor) AttrValMap(com.qlangtech.tis.util.AttrValMap) IOException(java.io.IOException)

Example 2 with DelegateControl4JsonPostMsgHandler

use of com.qlangtech.tis.runtime.module.misc.impl.DelegateControl4JsonPostMsgHandler in project tis by qlangtech.

the class DepartmentAction method processDepartment.

private boolean processDepartment(Context context, Department dpt, IDepartmentProcess dptProcess, Object... validateRuleParams) {
    // 
    Map<String, Validator.FieldValidators> validateRule = // 
    Validator.fieldsValidator(// 
    "name", new Validator.FieldValidators(Validator.require) {

        @Override
        public void setFieldVal(String val) {
            dpt.setName(val);
        }
    }, // 
    "parentId", new Validator.FieldValidators(Validator.require, Validator.integer) {

        @Override
        public void setFieldVal(String val) {
            dpt.setParentId(Integer.parseInt(val));
        }
    }, validateRuleParams);
    // //////////////////
    IControlMsgHandler handler = new DelegateControl4JsonPostMsgHandler(this, this.parseJsonPost());
    if (!Validator.validate(handler, context, validateRule)) {
        return false;
    }
    Department parentDpt = this.getDepartmentDAO().selectByPrimaryKey(dpt.getParentId());
    dpt.setFullName("/" + parentDpt.getName() + "/" + dpt.getName());
    dpt.setGmtCreate(new Date());
    dpt.setGmtModified(new Date());
    dpt.setLeaf(true);
    dptProcess.process(dpt);
    this.setBizResult(context, dpt);
    return true;
}
Also used : Department(com.qlangtech.tis.manage.biz.dal.pojo.Department) DelegateControl4JsonPostMsgHandler(com.qlangtech.tis.runtime.module.misc.impl.DelegateControl4JsonPostMsgHandler) IControlMsgHandler(com.qlangtech.tis.runtime.module.misc.IControlMsgHandler) Validator(com.qlangtech.tis.plugin.annotation.Validator) Date(java.util.Date)

Example 3 with DelegateControl4JsonPostMsgHandler

use of com.qlangtech.tis.runtime.module.misc.impl.DelegateControl4JsonPostMsgHandler in project tis by qlangtech.

the class OfflineDatasourceAction method doValidateWorkflowAddJoinComponentForm.

/**
 * WorkflowAddJoinComponent 点击保存按钮进行,服务端进行校验
 *
 * @param context
 * @throws Exception
 */
@Func(value = PermissionConstant.DATAFLOW_MANAGE, sideEffect = false)
public void doValidateWorkflowAddJoinComponentForm(Context context) throws Exception {
    com.alibaba.fastjson.JSONObject form = this.parseJsonPost();
    IControlMsgHandler handler = new DelegateControl4JsonPostMsgHandler(this, form);
    String sql = form.getString("sql");
    String exportName = form.getString("exportName");
    com.alibaba.fastjson.JSONArray dependenceNodes = form.getJSONArray("dependencies");
    final List<String> dependencyNodes = Lists.newArrayList();
    final String validateRuleDependency = "dependencies";
    // 
    Map<String, Validator.FieldValidators> validateRule = // 
    Validator.fieldsValidator(// 
    "sql", new Validator.FieldValidators(Validator.require) {
    }.addDependency(// 
    validateRuleDependency), new Validator.IFieldValidator() {

        @Override
        public boolean validate(IFieldErrorHandler msgHandler, Context context, String fieldKey, String fieldData) {
            Optional<TisSqlFormatException> sqlErr = SqlTaskNodeMeta.validateSql(fieldData, dependencyNodes);
            if (sqlErr.isPresent()) {
                msgHandler.addFieldError(context, fieldKey, sqlErr.get().summary());
                return false;
            }
            return true;
        }
    }, // 
    "exportName", new Validator.FieldValidators(Validator.require, Validator.identity) {
    }, new Validator.IFieldValidator() {

        @Override
        public boolean validate(IFieldErrorHandler msgHandler, Context context, String fieldKey, String fieldData) {
            Matcher m = pattern_table_name.matcher(fieldData);
            if (!m.matches()) {
                msgHandler.addFieldError(context, fieldKey, "必须符合规则:" + pattern_table_name);
                return false;
            }
            return true;
        }
    }, // 
    validateRuleDependency, new Validator.FieldValidators(Validator.require) {

        @Override
        public void setFieldVal(String val) {
            com.alibaba.fastjson.JSONArray dpts = JSON.parseArray(val);
            com.alibaba.fastjson.JSONObject o = null;
            for (int index = 0; index < dpts.size(); index++) {
                o = dpts.getJSONObject(index);
                dependencyNodes.add(o.getString("label"));
            }
        }
    }, new Validator.IFieldValidator() {

        @Override
        public boolean validate(IFieldErrorHandler msgHandler, Context context, String fieldKey, String fieldData) {
            com.alibaba.fastjson.JSONArray dpts = JSON.parseArray(fieldData);
            if (dpts.size() < 1) {
                msgHandler.addFieldError(context, fieldKey, "请选择依赖表节点");
                return false;
            }
            return true;
        }
    });
    if (!Validator.validate(handler, context, validateRule)) {
    // return;
    }
}
Also used : IFullBuildContext(com.qlangtech.tis.fullbuild.IFullBuildContext) Context(com.alibaba.citrus.turbine.Context) DelegateControl4JsonPostMsgHandler(com.qlangtech.tis.runtime.module.misc.impl.DelegateControl4JsonPostMsgHandler) Matcher(java.util.regex.Matcher) IFieldErrorHandler(com.qlangtech.tis.runtime.module.misc.IFieldErrorHandler) JSONArray(org.json.JSONArray) JSONObject(org.json.JSONObject) IControlMsgHandler(com.qlangtech.tis.runtime.module.misc.IControlMsgHandler) Validator(com.qlangtech.tis.plugin.annotation.Validator) Func(com.qlangtech.tis.manage.spring.aop.Func)

Example 4 with DelegateControl4JsonPostMsgHandler

use of com.qlangtech.tis.runtime.module.misc.impl.DelegateControl4JsonPostMsgHandler in project tis by qlangtech.

the class DataxAction method doSaveWriterColsMeta.

/**
 * @param context
 */
@Func(value = PermissionConstant.DATAX_MANAGE)
public void doSaveWriterColsMeta(Context context) {
    String dataxName = this.getString(PARAM_KEY_DATAX_NAME);
    DataxProcessor.DataXCreateProcessMeta processMeta = DataxProcessor.getDataXCreateProcessMeta(this, dataxName);
    if ((processMeta.isReaderRDBMS())) {
        throw new IllegalStateException("can not process the flow with:" + processMeta.toString());
    }
    List<ISelectedTab.ColMeta> writerCols = Lists.newArrayList();
    IDataxProcessor.TableMap tableMapper = new IDataxProcessor.TableMap(new ISelectedTab() {

        @Override
        public List<ColMeta> getCols() {
            return writerCols;
        }
    });
    // tableMapper.setSourceCols(writerCols);
    // //////////////////
    final String keyColsMeta = "colsMeta";
    IControlMsgHandler handler = new DelegateControl4JsonPostMsgHandler(this, this.parseJsonPost());
    if (!Validator.validate(handler, context, // 
    Validator.fieldsValidator(// 
    "writerTargetTabName", new Validator.FieldValidators(Validator.require, Validator.db_col_name) {

        @Override
        public void setFieldVal(String val) {
            tableMapper.setTo(val);
        }
    }, "writerFromTabName", new Validator.FieldValidators(Validator.require, Validator.db_col_name) {

        @Override
        public void setFieldVal(String val) {
            tableMapper.setFrom(val);
        }
    }, // 
    keyColsMeta, new Validator.FieldValidators(Validator.require) {

        @Override
        public void setFieldVal(String val) {
        }
    }, new Validator.IFieldValidator() {

        @Override
        public boolean validate(IFieldErrorHandler msgHandler, Context context, String fieldKey, String fieldData) {
            ISelectedTab.ColMeta colMeta = null;
            JSONArray targetCols = JSON.parseArray(fieldData);
            JSONObject targetCol = null;
            int index;
            String targetColName = null;
            if (targetCols.size() < 1) {
                msgHandler.addFieldError(context, fieldKey, "Writer目标表列不能为空");
                return false;
            }
            Map<String, Integer> existCols = Maps.newHashMap();
            boolean validateFaild = false;
            Integer previousColIndex = null;
            for (int i = 0; i < targetCols.size(); i++) {
                targetCol = targetCols.getJSONObject(i);
                index = targetCol.getInteger("index");
                targetColName = targetCol.getString("name");
                if (StringUtils.isNotBlank(targetColName) && (previousColIndex = existCols.put(targetColName, index)) != null) {
                    msgHandler.addFieldError(context, keyColsMeta + "[" + previousColIndex + "]", "内容不能与第" + index + "行重复");
                    msgHandler.addFieldError(context, keyColsMeta + "[" + index + "]", "内容不能与第" + previousColIndex + "行重复");
                    return false;
                }
                if (!Validator.require.validate(DataxAction.this, context, keyColsMeta + "[" + index + "]", targetColName)) {
                    validateFaild = true;
                } else if (!Validator.db_col_name.validate(DataxAction.this, context, keyColsMeta + "[" + index + "]", targetColName)) {
                    validateFaild = true;
                }
                colMeta = new ISelectedTab.ColMeta();
                colMeta.setName(targetColName);
                DataType dataType = targetCol.getObject("type", DataType.class);
                // colMeta.setType(ISelectedTab.DataXReaderColType.parse(targetCol.getString("type")));
                colMeta.setType(dataType);
                writerCols.add(colMeta);
            }
            return !validateFaild;
        }
    }))) {
        return;
    }
    this.saveTableMapper(this, dataxName, Collections.singletonList(tableMapper));
}
Also used : ServletActionContext(org.apache.struts2.ServletActionContext) Context(com.alibaba.citrus.turbine.Context) IParamContext(com.qlangtech.tis.order.center.IParamContext) DelegateControl4JsonPostMsgHandler(com.qlangtech.tis.runtime.module.misc.impl.DelegateControl4JsonPostMsgHandler) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) IFieldErrorHandler(com.qlangtech.tis.runtime.module.misc.IFieldErrorHandler) JSONArray(com.alibaba.fastjson.JSONArray) JSONObject(com.alibaba.fastjson.JSONObject) DataType(com.qlangtech.tis.plugin.ds.DataType) DescriptorExtensionList(com.qlangtech.tis.extension.DescriptorExtensionList) IControlMsgHandler(com.qlangtech.tis.runtime.module.misc.IControlMsgHandler) Validator(com.qlangtech.tis.plugin.annotation.Validator) Func(com.qlangtech.tis.manage.spring.aop.Func)

Aggregations

DelegateControl4JsonPostMsgHandler (com.qlangtech.tis.runtime.module.misc.impl.DelegateControl4JsonPostMsgHandler)4 Validator (com.qlangtech.tis.plugin.annotation.Validator)3 IControlMsgHandler (com.qlangtech.tis.runtime.module.misc.IControlMsgHandler)3 Context (com.alibaba.citrus.turbine.Context)2 JSONArray (com.alibaba.fastjson.JSONArray)2 Func (com.qlangtech.tis.manage.spring.aop.Func)2 IFieldErrorHandler (com.qlangtech.tis.runtime.module.misc.IFieldErrorHandler)2 JSONObject (com.alibaba.fastjson.JSONObject)1 Descriptor (com.qlangtech.tis.extension.Descriptor)1 DescriptorExtensionList (com.qlangtech.tis.extension.DescriptorExtensionList)1 IFullBuildContext (com.qlangtech.tis.fullbuild.IFullBuildContext)1 Department (com.qlangtech.tis.manage.biz.dal.pojo.Department)1 IParamContext (com.qlangtech.tis.order.center.IParamContext)1 DataType (com.qlangtech.tis.plugin.ds.DataType)1 ISelectedTab (com.qlangtech.tis.plugin.ds.ISelectedTab)1 AttrValMap (com.qlangtech.tis.util.AttrValMap)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Date (java.util.Date)1 Matcher (java.util.regex.Matcher)1