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