Search in sources :

Example 1 with IFieldErrorHandler

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

the class TestDefaultK8SImage method testHostAliasesValidate.

public void testHostAliasesValidate() {
    // https://blog.csdn.net/weixin_47729423/article/details/114288431
    DefaultK8SImage k8SImage = new DefaultK8SImage();
    DefaultK8SImage.DescriptorImpl descriptor = (DefaultK8SImage.DescriptorImpl) k8SImage.getDescriptor();
    assertNotNull("descriptor can not be null", descriptor);
    IFieldErrorHandler msgHandler = EasyMock.createMock("msgHandler", IFieldErrorHandler.class);
    Context context = EasyMock.createMock("context", Context.class);
    String fieldName = "hostAliases";
    EasyMock.replay(msgHandler, context);
    assertTrue(descriptor.validateHostAliases(msgHandler, context, fieldName, IOUtils.loadResourceFromClasspath(DefaultK8SImage.class, "DefaultK8SImage-hostaliases-content.yaml")));
    EasyMock.verify(msgHandler, context);
}
Also used : Context(com.alibaba.citrus.turbine.Context) IFieldErrorHandler(com.qlangtech.tis.runtime.module.misc.IFieldErrorHandler)

Example 2 with IFieldErrorHandler

use of com.qlangtech.tis.runtime.module.misc.IFieldErrorHandler 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 3 with IFieldErrorHandler

use of com.qlangtech.tis.runtime.module.misc.IFieldErrorHandler 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

Context (com.alibaba.citrus.turbine.Context)3 IFieldErrorHandler (com.qlangtech.tis.runtime.module.misc.IFieldErrorHandler)3 Func (com.qlangtech.tis.manage.spring.aop.Func)2 Validator (com.qlangtech.tis.plugin.annotation.Validator)2 IControlMsgHandler (com.qlangtech.tis.runtime.module.misc.IControlMsgHandler)2 DelegateControl4JsonPostMsgHandler (com.qlangtech.tis.runtime.module.misc.impl.DelegateControl4JsonPostMsgHandler)2 JSONArray (com.alibaba.fastjson.JSONArray)1 JSONObject (com.alibaba.fastjson.JSONObject)1 DescriptorExtensionList (com.qlangtech.tis.extension.DescriptorExtensionList)1 IFullBuildContext (com.qlangtech.tis.fullbuild.IFullBuildContext)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 Matcher (java.util.regex.Matcher)1 ServletActionContext (org.apache.struts2.ServletActionContext)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1