Search in sources :

Example 1 with IControlMsgHandler

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

the class DataXOssReader method verifyFormOSSRelative.

public static boolean verifyFormOSSRelative(IControlMsgHandler msgHandler, Context context, Descriptor.PostFormVals postFormVals) {
    String endpoint = postFormVals.getField(FIELD_ENDPOINT);
    String bucket = postFormVals.getField(FIELD_BUCKET);
    HttpEndpoint end = ParamsConfig.getItem(endpoint, HttpEndpoint.KEY_DISPLAY_NAME);
    try {
        OSS ossClient = new OSSClientBuilder().build(end.getEndpoint(), end.getAccessKeyId(), end.getAccessKeySecret());
        List<Bucket> buckets = ossClient.listBuckets();
        if (buckets.size() < 1) {
            msgHandler.addErrorMessage(context, "buckets不能为空");
            return false;
        }
        Optional<Bucket> bucketFind = buckets.stream().filter((b) -> StringUtils.equals(bucket, b.getName())).findFirst();
        if (!bucketFind.isPresent()) {
            // msgHandler.addErrorMessage(context, );
            msgHandler.addFieldError(context, FIELD_BUCKET, "还未创建bucket:" + bucket);
            return false;
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return true;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) ParamsConfig(com.qlangtech.tis.config.ParamsConfig) LoggerFactory(org.slf4j.LoggerFactory) FormField(com.qlangtech.tis.plugin.annotation.FormField) Context(com.alibaba.citrus.turbine.Context) IFieldErrorHandler(com.qlangtech.tis.runtime.module.misc.IFieldErrorHandler) Matcher(java.util.regex.Matcher) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DefaultContext(com.alibaba.citrus.turbine.impl.DefaultContext) IGroupChildTaskIterator(com.qlangtech.tis.datax.IGroupChildTaskIterator) HttpEndpoint(com.qlangtech.tis.plugin.aliyun.HttpEndpoint) IDataxReaderContext(com.qlangtech.tis.datax.IDataxReaderContext) FormFieldType(com.qlangtech.tis.plugin.annotation.FormFieldType) Validator(com.qlangtech.tis.plugin.annotation.Validator) TISExtension(com.qlangtech.tis.extension.TISExtension) Logger(org.slf4j.Logger) IHttpToken(com.qlangtech.tis.config.aliyun.IHttpToken) OSSClientBuilder(com.aliyun.oss.OSSClientBuilder) Descriptor(com.qlangtech.tis.extension.Descriptor) OSS(com.aliyun.oss.OSS) List(java.util.List) DataxReader(com.qlangtech.tis.datax.impl.DataxReader) IOUtils(com.qlangtech.tis.extension.impl.IOUtils) Public(com.qlangtech.tis.annotation.Public) IControlMsgHandler(com.qlangtech.tis.runtime.module.misc.IControlMsgHandler) PluginFieldValidators(com.qlangtech.tis.plugin.datax.common.PluginFieldValidators) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) Bucket(com.aliyun.oss.model.Bucket) Collections(java.util.Collections) StringEscapeUtils(org.apache.commons.lang.StringEscapeUtils) Bucket(com.aliyun.oss.model.Bucket) HttpEndpoint(com.qlangtech.tis.plugin.aliyun.HttpEndpoint) OSS(com.aliyun.oss.OSS) OSSClientBuilder(com.aliyun.oss.OSSClientBuilder)

Example 2 with IControlMsgHandler

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

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

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

the class TestPluginItems method validateSubFormSave.

private void validateSubFormSave() {
    IPluginContext pluginContext = EasyMock.createMock("pluginContext", IPluginContext.class);
    EasyMock.expect(pluginContext.isDataSourceAware()).andReturn(false);
    EasyMock.expect(pluginContext.isCollectionAware()).andReturn(false).anyTimes();
    EasyMock.expect(pluginContext.getRequestHeader(DataxReader.HEAD_KEY_REFERER)).andReturn("/x/" + dataXName + "/config").times(2);
    Context context = EasyMock.createMock("context", Context.class);
    // targetDescriptorName_MySQL,subFormFieldName_selectedTabs
    Optional<IPropertyType.SubFormFilter> subFormFilter = subFieldPluginMeta.getSubFormFilter();
    assertTrue("subFormFilter.isPresent():true", subFormFilter.isPresent());
    PluginItems pluginItems = new PluginItems(pluginContext, subFieldPluginMeta);
    IControlMsgHandler fieldErrorHandler = EasyMock.createMock("fieldErrorHandler", IControlMsgHandler.class);
    JSONArray jsonArray = IOUtils.loadResourceFromClasspath(TestPluginItems.class, "datax_reader_mysql_post_subfield_form.json", true, (input) -> {
        return JSON.parseArray(org.apache.commons.io.IOUtils.toString(input, TisUTF8.get()));
    });
    JSONArray itemsArray = jsonArray.getJSONArray(0);
    // Optional.empty();
    List<AttrValMap> items = AttrValMap.describableAttrValMapList(fieldErrorHandler, itemsArray, subFormFilter);
    pluginItems.items = items;
    EasyMock.replay(pluginContext, context, fieldErrorHandler);
    pluginItems.save(context);
    EasyMock.verify(pluginContext, context, fieldErrorHandler);
}
Also used : Context(com.alibaba.citrus.turbine.Context) JSONArray(com.alibaba.fastjson.JSONArray) IControlMsgHandler(com.qlangtech.tis.runtime.module.misc.IControlMsgHandler)

Example 5 with IControlMsgHandler

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

the class TestPluginItems method validateRootFormSave.

private void validateRootFormSave() {
    IPluginContext pluginContext = EasyMock.createMock("pluginContext", IPluginContext.class);
    EasyMock.expect(pluginContext.isDataSourceAware()).andReturn(false);
    EasyMock.expect(pluginContext.isCollectionAware()).andReturn(false).anyTimes();
    EasyMock.expect(pluginContext.getRequestHeader(DataxReader.HEAD_KEY_REFERER)).andReturn("/x/" + dataXName + "/config").anyTimes();
    Context context = EasyMock.createMock("context", Context.class);
    // targetDescriptorName_MySQL,subFormFieldName_selectedTabs
    UploadPluginMeta pluginMeta = UploadPluginMeta.parse("dataxReader:require,dataxName_" + dataXName);
    PluginItems pluginItems = new PluginItems(pluginContext, pluginMeta);
    IControlMsgHandler fieldErrorHandler = EasyMock.createMock("fieldErrorHandler", IControlMsgHandler.class);
    JSONArray jsonArray = IOUtils.loadResourceFromClasspath(TestPluginItems.class, "datax_reader_mysql_post.json", true, (input) -> {
        return JSON.parseArray(org.apache.commons.io.IOUtils.toString(input, TisUTF8.get()));
    });
    JSONArray itemsArray = jsonArray.getJSONArray(0);
    Optional<IPropertyType.SubFormFilter> subFormFilter = pluginMeta.getSubFormFilter();
    assertFalse("subFormFilter.isPresent():false", subFormFilter.isPresent());
    List<AttrValMap> items = AttrValMap.describableAttrValMapList(fieldErrorHandler, itemsArray, subFormFilter);
    pluginItems.items = items;
    EasyMock.replay(pluginContext, context, fieldErrorHandler);
    pluginItems.save(context);
    EasyMock.verify(pluginContext, context, fieldErrorHandler);
}
Also used : Context(com.alibaba.citrus.turbine.Context) JSONArray(com.alibaba.fastjson.JSONArray) IControlMsgHandler(com.qlangtech.tis.runtime.module.misc.IControlMsgHandler)

Aggregations

IControlMsgHandler (com.qlangtech.tis.runtime.module.misc.IControlMsgHandler)12 Context (com.alibaba.citrus.turbine.Context)8 Validator (com.qlangtech.tis.plugin.annotation.Validator)5 DefaultContext (com.alibaba.citrus.turbine.impl.DefaultContext)4 JSONArray (com.alibaba.fastjson.JSONArray)3 IFieldErrorHandler (com.qlangtech.tis.runtime.module.misc.IFieldErrorHandler)3 DelegateControl4JsonPostMsgHandler (com.qlangtech.tis.runtime.module.misc.impl.DelegateControl4JsonPostMsgHandler)3 JSONObject (com.alibaba.fastjson.JSONObject)2 IndexIncrStatus (com.qlangtech.tis.coredefine.module.action.IndexIncrStatus)2 Descriptor (com.qlangtech.tis.extension.Descriptor)2 Func (com.qlangtech.tis.manage.spring.aop.Func)2 Collections (java.util.Collections)2 List (java.util.List)2 Matcher (java.util.regex.Matcher)2 OSS (com.aliyun.oss.OSS)1 OSSClientBuilder (com.aliyun.oss.OSSClientBuilder)1 Bucket (com.aliyun.oss.model.Bucket)1 Lists (com.google.common.collect.Lists)1 KoubeiIbatorRunner (com.koubei.abator.KoubeiIbatorRunner)1 KoubeiProgressCallback (com.koubei.abator.KoubeiProgressCallback)1