use of com.alibaba.citrus.turbine.Context in project tis by qlangtech.
the class OfflineDatasourceAction method doReflectTableCols.
/**
* 通过sql语句反射sql语句中的列
*/
@Func(value = PermissionConstant.PERMISSION_DATASOURCE_EDIT, sideEffect = false)
public void doReflectTableCols(Context context) throws Exception {
String topology = this.getString("topology");
if (StringUtils.isEmpty(topology)) {
throw new IllegalArgumentException("param topology can not be null");
}
SqlDataFlowTopology wfTopology = SqlTaskNodeMeta.getSqlDataFlowTopology(topology);
Map<String, DependencyNode> /**
* id
*/
dumpNodes = wfTopology.getDumpNodes().stream().collect(Collectors.toMap((d) -> d.getId(), (d) -> d));
com.alibaba.fastjson.JSONArray sqlAry = this.parseJsonArrayPost();
com.alibaba.fastjson.JSONObject j = null;
// String sql = null;
// List<RowMetaData> rowMetaData = null;
List<SqlCols> colsMeta = Lists.newArrayList();
SqlCols sqlCols = null;
DependencyNode dumpNode = null;
TISTable tabCfg = null;
// List<ColumnMetaData> reflectCols = null;
for (int i = 0; i < sqlAry.size(); i++) {
j = sqlAry.getJSONObject(i);
// sql = j.getString("sql");
sqlCols = new SqlCols();
sqlCols.setKey(j.getString("key"));
String dumpNodeId = sqlCols.getKey();
dumpNode = dumpNodes.get(dumpNodeId);
if (dumpNode == null) {
throw new IllegalStateException("key:" + dumpNodeId + " can not find relevant dump node in topplogy '" + topology + "'");
}
// tabCfg = GitUtils.$().getTableConfig(dumpNode.getDbName(), dumpNode.getName());
DataSourceFactoryPluginStore dbPlugin = TIS.getDataBasePluginStore(new PostedDSProp(dumpNode.getDbName()));
TISTable tisTable = dbPlugin.loadTableMeta(dumpNode.getName());
if (CollectionUtils.isEmpty(tisTable.getReflectCols())) {
throw new IllegalStateException("db:" + dumpNode.getDbName() + ",table:" + dumpNode.getName() + " relevant table col reflect cols can not be empty");
}
sqlCols.setCols(tisTable.getReflectCols());
colsMeta.add(sqlCols);
}
this.setBizResult(context, colsMeta);
}
use of com.alibaba.citrus.turbine.Context 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.alibaba.citrus.turbine.Context in project tis by qlangtech.
the class TestSchemaResult method testParseSchemaResultAlreadyContainFieldPlugin.
/**
* 在schema配置文件中已经添加了 <br/>
* <fieldType name="test" class="plugin:test" precisionStep="0" positionIncrementGap="0"/>
* 该类型也要能自动加入到傻瓜模式下,string类型的联动下拉框 <br/>
*
* @throws Exception
*/
public void testParseSchemaResultAlreadyContainFieldPlugin() throws Exception {
IMessageHandler msgHandler = EasyMock.createMock("msgHandler", IMessageHandler.class);
Context context = EasyMock.createMock("context", Context.class);
assertEquals(FieldTypeFactory.class, HeteroEnum.SOLR_FIELD_TYPE.extensionPoint);
IPluginStore<FieldTypeFactory> fieldTypePluginStore = TIS.getPluginStore(collection, FieldTypeFactory.class);
assertNotNull(fieldTypePluginStore);
final String testFieldTypeName = "test";
final List<FieldTypeFactory> plugins = fieldTypePluginStore.getPlugins();
assertTrue(plugins.size() > 0);
FieldTypeFactory fieldType = fieldTypePluginStore.find(testFieldTypeName);
assertNotNull("fieldType can not be null", fieldType);
try (InputStream schema = this.getClass().getResourceAsStream("s4totalpay-schema-already-contain-fieldtype-plugin.xml")) {
EasyMock.replay(msgHandler, context);
SchemaResult schemaResult = SchemaAction.parseSchemaResultWithPluginCfg(collection, msgHandler, context, IOUtils.toByteArray(schema));
Collection<SolrFieldsParser.SolrType> fieldTypes = ((ParseResult) schemaResult.getParseResult()).getFieldTypes();
assertEquals("fieldTypes size", 2, fieldTypes.size());
// String content = (com.alibaba.fastjson.JSON.toJSONString(schemaResult.toJSON()
// , SerializerFeature.DisableCircularReferenceDetect, SerializerFeature.PrettyFormat));
// try (InputStream assertSchemaResultInput = this.getClass().getResourceAsStream("s4totalpay-schema-already-contain-fieldtype-plugin-schema-result.json")) {
// assertNotNull(assertSchemaResultInput);
// FileUtils.write(new File("test.json"), content, TisUTF8.get());
// assertEquals(StringUtils.trim(IOUtils.toString(assertSchemaResultInput, TisUTF8.get())), content);
// }
JsonUtil.assertJSONEqual(this.getClass(), "s4totalpay-schema-already-contain-fieldtype-plugin-schema-result.json", schemaResult.toJSON(), (m, e, a) -> {
assertEquals(m, e, a);
});
}
EasyMock.verify(msgHandler, context);
}
use of com.alibaba.citrus.turbine.Context in project tis by qlangtech.
the class TestSchemaResult method testParseSchemaResult.
/**
* 模拟用户刚添加fieldtype plugin,则用户第一次家在schema中要自动加入 fieldtype
*
* @throws Exception
*/
public void testParseSchemaResult() throws Exception {
IMessageHandler msgHandler = EasyMock.createMock("msgHandler", IMessageHandler.class);
Context context = EasyMock.createMock("context", Context.class);
assertEquals(FieldTypeFactory.class, HeteroEnum.SOLR_FIELD_TYPE.extensionPoint);
final String collection = "search4totalpay";
IPluginStore<FieldTypeFactory> fieldTypePluginStore = TIS.getPluginStore(collection, FieldTypeFactory.class);
assertNotNull(fieldTypePluginStore);
final String testFieldTypeName = "test";
final List<FieldTypeFactory> plugins = fieldTypePluginStore.getPlugins();
assertTrue(plugins.size() > 0);
FieldTypeFactory fieldType = fieldTypePluginStore.find(testFieldTypeName);
assertNotNull("fieldType can not be null", fieldType);
try (InputStream schema = this.getClass().getResourceAsStream("s4totalpay-schema.xml")) {
EasyMock.replay(msgHandler, context);
SchemaResult schemaResult = SchemaAction.parseSchemaResultWithPluginCfg(collection, msgHandler, context, IOUtils.toByteArray(schema));
Collection<SolrFieldsParser.SolrType> fieldTypes = ((ParseResult) schemaResult.getParseResult()).getFieldTypes();
assertEquals("fieldTypes size", 16, fieldTypes.size());
// String content = (com.alibaba.fastjson.JSON.toJSONString(schemaResult.toJSON()
// , SerializerFeature.DisableCircularReferenceDetect, SerializerFeature.PrettyFormat));
//
// try (InputStream assertSchemaResultInput = this.getClass().getResourceAsStream("assertSchemaResult.json")) {
// assertNotNull(assertSchemaResultInput);
// assertEquals(IOUtils.toString(assertSchemaResultInput, TisUTF8.get()), content);
// }
JsonUtil.assertJSONEqual(this.getClass(), "assertSchemaResult.json", schemaResult.toJSON(), (m, e, a) -> {
assertEquals(m, e, a);
});
}
EasyMock.verify(msgHandler, context);
}
use of com.alibaba.citrus.turbine.Context 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);
}
Aggregations