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;
}
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;
}
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;
}
}
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);
}
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);
}
Aggregations