Search in sources :

Example 6 with Context

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);
}
Also used : WorkFlow(com.qlangtech.tis.workflow.pojo.WorkFlow) StringUtils(org.apache.commons.lang.StringUtils) ERRules.$(com.qlangtech.tis.sql.parser.er.ERRules.$) SqlTaskNode(com.qlangtech.tis.sql.parser.SqlTaskNode) JoinRule(com.qlangtech.tis.git.GitUtils.JoinRule) TIS(com.qlangtech.tis.TIS) WorkFlowCriteria(com.qlangtech.tis.workflow.pojo.WorkFlowCriteria) Autowired(org.springframework.beans.factory.annotation.Autowired) Option(com.qlangtech.tis.manage.common.Option) DbScope(com.qlangtech.tis.offline.DbScope) DescriptorsJSON(com.qlangtech.tis.util.DescriptorsJSON) IFieldErrorHandler(com.qlangtech.tis.runtime.module.misc.IFieldErrorHandler) JSONObject(org.json.JSONObject) Matcher(java.util.regex.Matcher) DescriptorExtensionList(com.qlangtech.tis.extension.DescriptorExtensionList) PermissionConstant(com.qlangtech.tis.manage.PermissionConstant) FullbuildPhase(com.qlangtech.tis.assemble.FullbuildPhase) IPluginStore(com.qlangtech.tis.plugin.IPluginStore) PluginFormProperties(com.qlangtech.tis.extension.PluginFormProperties) PostParam(com.qlangtech.tis.manage.common.HttpUtils.PostParam) Validator(com.qlangtech.tis.plugin.annotation.Validator) GitRepositoryCommitPojo(com.qlangtech.tis.offline.pojo.GitRepositoryCommitPojo) DelegateControl4JsonPostMsgHandler(com.qlangtech.tis.runtime.module.misc.impl.DelegateControl4JsonPostMsgHandler) HeteroList(com.qlangtech.tis.util.HeteroList) Descriptor(com.qlangtech.tis.extension.Descriptor) TabCardinality(com.qlangtech.tis.sql.parser.er.TabCardinality) Collectors(java.util.stream.Collectors) name.fraser.neil.plaintext.diff_match_patch(name.fraser.neil.plaintext.diff_match_patch) IFullBuildContext(com.qlangtech.tis.fullbuild.IFullBuildContext) IOUtils(org.apache.commons.io.IOUtils) DataxReader(com.qlangtech.tis.datax.impl.DataxReader) IWorkFlowDAO(com.qlangtech.tis.workflow.dao.IWorkFlowDAO) IControlMsgHandler(com.qlangtech.tis.runtime.module.misc.IControlMsgHandler) TableRelation(com.qlangtech.tis.sql.parser.er.TableRelation) DataxAction(com.qlangtech.tis.coredefine.module.action.DataxAction) SqlDataFlowTopology(com.qlangtech.tis.sql.parser.SqlTaskNodeMeta.SqlDataFlowTopology) DBConfigSuit(com.qlangtech.tis.db.parser.DBConfigSuit) Pattern(java.util.regex.Pattern) SuFormProperties(com.qlangtech.tis.extension.impl.SuFormProperties) Types(java.sql.Types) Pager(com.koubei.web.tag.pager.Pager) java.util(java.util) Func(com.qlangtech.tis.manage.spring.aop.Func) UploadPluginMeta(com.qlangtech.tis.util.UploadPluginMeta) Context(com.alibaba.citrus.turbine.Context) TISDb(com.qlangtech.tis.offline.pojo.TISDb) JsonUtil(com.qlangtech.tis.trigger.util.JsonUtil) Lists(com.google.common.collect.Lists) PropertyType(com.qlangtech.tis.extension.impl.PropertyType) DatasourceTable(com.qlangtech.tis.workflow.pojo.DatasourceTable) CollectionUtils(org.apache.commons.collections.CollectionUtils) GitUtils(com.qlangtech.tis.git.GitUtils) OfflineManager(com.qlangtech.tis.offline.module.manager.impl.OfflineManager) FormFieldType(com.qlangtech.tis.plugin.annotation.FormFieldType) com.qlangtech.tis.sql.parser.meta(com.qlangtech.tis.sql.parser.meta) WorkflowPojo(com.qlangtech.tis.offline.pojo.WorkflowPojo) IWorkflowDAOFacade(com.qlangtech.tis.workflow.dao.IWorkflowDAOFacade) MapUtils(org.apache.commons.collections.MapUtils) IdentityName(com.qlangtech.tis.plugin.IdentityName) JSONTokener(org.json.JSONTokener) com.qlangtech.tis.plugin.ds(com.qlangtech.tis.plugin.ds) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) Maps(com.google.common.collect.Maps) File(java.io.File) TisSqlFormatException(com.qlangtech.tis.sql.parser.exception.TisSqlFormatException) JSON(com.alibaba.fastjson.JSON) ERRules(com.qlangtech.tis.sql.parser.er.ERRules) BasicModule(com.qlangtech.tis.runtime.module.action.BasicModule) AppDomainInfo(com.qlangtech.tis.manage.common.AppDomainInfo) CoreAction(com.qlangtech.tis.coredefine.module.action.CoreAction) Assert(com.qlangtech.tis.common.utils.Assert) SqlTaskNodeMeta(com.qlangtech.tis.sql.parser.SqlTaskNodeMeta) IUser(com.qlangtech.tis.manage.common.IUser) PrimaryTableMeta(com.qlangtech.tis.sql.parser.er.PrimaryTableMeta) JSONArray(org.json.JSONArray) PluginDescMeta(com.qlangtech.tis.coredefine.module.action.PluginDescMeta) SqlDataFlowTopology(com.qlangtech.tis.sql.parser.SqlTaskNodeMeta.SqlDataFlowTopology) Func(com.qlangtech.tis.manage.spring.aop.Func)

Example 7 with Context

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;
    }
}
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 8 with Context

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);
}
Also used : Context(com.alibaba.citrus.turbine.Context) ParseResult(com.qlangtech.tis.solrdao.impl.ParseResult) IMessageHandler(com.qlangtech.tis.runtime.module.misc.IMessageHandler) InputStream(java.io.InputStream) FieldTypeFactory(com.qlangtech.tis.plugin.solr.schema.FieldTypeFactory)

Example 9 with 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);
}
Also used : Context(com.alibaba.citrus.turbine.Context) ParseResult(com.qlangtech.tis.solrdao.impl.ParseResult) IMessageHandler(com.qlangtech.tis.runtime.module.misc.IMessageHandler) InputStream(java.io.InputStream) FieldTypeFactory(com.qlangtech.tis.plugin.solr.schema.FieldTypeFactory)

Example 10 with 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);
}
Also used : Context(com.alibaba.citrus.turbine.Context) JSONArray(com.alibaba.fastjson.JSONArray) IControlMsgHandler(com.qlangtech.tis.runtime.module.misc.IControlMsgHandler)

Aggregations

Context (com.alibaba.citrus.turbine.Context)30 Collectors (java.util.stream.Collectors)15 Descriptor (com.qlangtech.tis.extension.Descriptor)14 IControlMsgHandler (com.qlangtech.tis.runtime.module.misc.IControlMsgHandler)13 TIS (com.qlangtech.tis.TIS)12 IOException (java.io.IOException)12 DataxReader (com.qlangtech.tis.datax.impl.DataxReader)11 Func (com.qlangtech.tis.manage.spring.aop.Func)11 Validator (com.qlangtech.tis.plugin.annotation.Validator)11 java.util (java.util)11 StringUtils (org.apache.commons.lang.StringUtils)11 JSONArray (com.alibaba.fastjson.JSONArray)10 Lists (com.google.common.collect.Lists)10 Maps (com.google.common.collect.Maps)10 IPluginStore (com.qlangtech.tis.plugin.IPluginStore)10 IFieldErrorHandler (com.qlangtech.tis.runtime.module.misc.IFieldErrorHandler)10 Pattern (java.util.regex.Pattern)9 JSON (com.alibaba.fastjson.JSON)8 DelegateControl4JsonPostMsgHandler (com.qlangtech.tis.runtime.module.misc.impl.DelegateControl4JsonPostMsgHandler)8 JSONObject (com.alibaba.fastjson.JSONObject)7