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