Search in sources :

Example 1 with UploadPluginMeta

use of com.qlangtech.tis.util.UploadPluginMeta in project plugins by qlangtech.

the class TestDataxMySQLReader method testDescriptorsJSONGenerate.

public void testDescriptorsJSONGenerate() {
    DataxMySQLReader esWriter = new DataxMySQLReader();
    DescriptorsJSON descJson = new DescriptorsJSON(esWriter.getDescriptor());
    // System.out.println(descJson.getDescriptorsJSON().toJSONString());
    JsonUtil.assertJSONEqual(DataxMySQLReader.class, "mysql-datax-reader-descriptor.json", descJson.getDescriptorsJSON(), (m, e, a) -> {
        assertEquals(m, e, a);
    });
    UploadPluginMeta pluginMeta = UploadPluginMeta.parse("dataxReader:require,targetDescriptorName_MySQL,subFormFieldName_selectedTabs,dataxName_baisuitestTestcase");
    JSONObject subFormDescriptorsJSON = descJson.getDescriptorsJSON(pluginMeta.getSubFormFilter());
    JsonUtil.assertJSONEqual(DataxMySQLReader.class, "mysql-datax-reader-selected-tabs-subform-descriptor.json", subFormDescriptorsJSON, (m, e, a) -> {
        assertEquals(m, e, a);
    });
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) DescriptorsJSON(com.qlangtech.tis.util.DescriptorsJSON) UploadPluginMeta(com.qlangtech.tis.util.UploadPluginMeta)

Example 2 with UploadPluginMeta

use of com.qlangtech.tis.util.UploadPluginMeta in project plugins by qlangtech.

the class TestPlugin method testSerialize.

public void testSerialize() throws Exception {
    IPluginStore<MQListenerFactory> pluginStore = TIS.getPluginStore(collection, MQListenerFactory.class);
    // IncrComponent incrComponent = createIncrComponent();
    List<MQListenerFactory> mqListenerFactory = pluginStore.getPlugins();
    UploadPluginMeta meta = UploadPluginMeta.parse("mq");
    HeteroList<MQListenerFactory> hList = new HeteroList<>(meta);
    hList.setCaption("MQ消息监听");
    hList.setItems(mqListenerFactory);
    hList.setDescriptors(TIS.getPluginStore(MQListenerFactory.class).allDescriptor());
    assertEquals(1, hList.getDescriptors().size());
    PluginFormProperties propertyTypes;
    for (Descriptor<MQListenerFactory> f : hList.getDescriptors()) {
        System.out.println(f.getId());
        // getPropertyTypes();
        propertyTypes = f.getPluginFormPropertyTypes();
        for (Map.Entry<String, PropertyType> entry : propertyTypes.getKVTuples()) {
            System.out.println(entry.getKey() + ":" + entry.getValue());
        }
    }
    JSONObject j = hList.toJSON();
    System.out.println("==============================");
    System.out.println(j.toJSONString());
    System.out.println("==============================");
}
Also used : HeteroList(com.qlangtech.tis.util.HeteroList) UploadPluginMeta(com.qlangtech.tis.util.UploadPluginMeta) PropertyType(com.qlangtech.tis.extension.impl.PropertyType) PluginFormProperties(com.qlangtech.tis.extension.PluginFormProperties) JSONObject(com.alibaba.fastjson.JSONObject) RocketMQListenerFactory(com.qlangtech.async.message.client.consumer.RocketMQListenerFactory) MQListenerFactory(com.qlangtech.tis.async.message.client.consumer.impl.MQListenerFactory) Map(java.util.Map)

Example 3 with UploadPluginMeta

use of com.qlangtech.tis.util.UploadPluginMeta in project plugins by qlangtech.

the class TestDataXCassandraReader method testDescriptorsJSONGenerate.

public void testDescriptorsJSONGenerate() {
    DataXCassandraReader reader = new DataXCassandraReader();
    DescriptorsJSON descJson = new DescriptorsJSON(reader.getDescriptor());
    // System.out.println(descJson.getDescriptorsJSON().toJSONString());
    JsonUtil.assertJSONEqual(DataXCassandraReader.class, "cassandra-datax-reader-descriptor.json", descJson.getDescriptorsJSON(), (m, e, a) -> {
        assertEquals(m, e, a);
    });
    UploadPluginMeta pluginMeta = UploadPluginMeta.parse("dataxReader:require,targetDescriptorName_" + DataXCassandraReader.DATAX_NAME + ",subFormFieldName_selectedTabs,dataxName_baisuitestTestcase");
    JSONObject subFormDescriptorsJSON = descJson.getDescriptorsJSON(pluginMeta.getSubFormFilter());
    JsonUtil.assertJSONEqual(DataXCassandraReader.class, "cassandra-datax-reader-selected-tabs-subform-descriptor.json", subFormDescriptorsJSON, (m, e, a) -> {
        assertEquals(m, e, a);
    });
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) DescriptorsJSON(com.qlangtech.tis.util.DescriptorsJSON) UploadPluginMeta(com.qlangtech.tis.util.UploadPluginMeta)

Example 4 with UploadPluginMeta

use of com.qlangtech.tis.util.UploadPluginMeta in project tis by qlangtech.

the class OfflineDatasourceAction method doGetDsTabsVals.

/**
 * 批量设置用,初始化数据库表
 *
 * @param context
 * @throws IOException
 */
public void doGetDsTabsVals(Context context) throws IOException {
    com.alibaba.fastjson.JSONObject body = this.parseJsonPost();
    com.alibaba.fastjson.JSONArray tabs = body.getJSONArray("tabs");
    if (tabs == null) {
        throw new IllegalArgumentException("initialize Tabs can not be null");
    }
    List<String> selectedTabs = tabs.stream().map((tab) -> (String) tab).collect(Collectors.toList());
    String pluginName = body.getString("name");
    boolean require = body.getBooleanValue("require");
    String extraParam = body.getString("extraParam");
    UploadPluginMeta pluginMeta = null;
    List<UploadPluginMeta> pluginMetas = UploadPluginMeta.parse(new String[] { pluginName + ":" + (require ? "require" : StringUtils.EMPTY) + "," + extraParam });
    for (UploadPluginMeta m : pluginMetas) {
        pluginMeta = m;
    }
    Objects.requireNonNull(pluginMeta, "pluginMeta can not be null");
    HeteroList<DataxReader> heteroList = pluginMeta.getHeteroList(this);
    List<DataxReader> readers = heteroList.getItems();
    Map<String, List<ColumnMetaData>> mapCols = null;
    List<ISelectedTab> allNewTabs = Lists.newArrayList();
    PluginFormProperties pluginFormPropertyTypes = null;
    Map<String, Object> bizResult = Maps.newHashMap();
    for (DataxReader reader : readers) {
        mapCols = selectedTabs.stream().collect(Collectors.toMap((tab) -> tab, (tab) -> {
            return reader.getTableMetadata(tab);
        }));
        if (MapUtils.isEmpty(mapCols)) {
            throw new IllegalStateException("mapCols can not be empty");
        }
        pluginFormPropertyTypes = reader.getDescriptor().getPluginFormPropertyTypes(pluginMeta.getSubFormFilter());
        for (Map.Entry<String, List<ColumnMetaData>> tab2cols : mapCols.entrySet()) {
            SuFormProperties.setSuFormGetterContext(reader, pluginMeta, tab2cols.getKey());
            allNewTabs.add(createNewSelectedTab(pluginFormPropertyTypes, tab2cols));
        }
        DescriptorsJSON desc2Json = new DescriptorsJSON(reader.getDescriptor());
        bizResult.put("subformDescriptor", desc2Json.getDescriptorsJSON(pluginMeta.getSubFormFilter()));
        break;
    }
    Objects.requireNonNull(pluginFormPropertyTypes, "pluginFormPropertyTypes can not be null");
    if (allNewTabs.size() < 1) {
        throw new IllegalStateException("allNewTabs size can not small than 1");
    }
    bizResult.put("tabVals", pluginFormPropertyTypes.accept(new PluginFormProperties.IVisitor() {

        @Override
        public com.alibaba.fastjson.JSONObject visit(SuFormProperties props) {
            return props.createSubFormVals(allNewTabs.stream().map((t) -> (IdentityName) t).collect(Collectors.toList()));
        }
    }));
    this.setBizResult(context, bizResult);
}
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) DescriptorExtensionList(com.qlangtech.tis.extension.DescriptorExtensionList) HeteroList(com.qlangtech.tis.util.HeteroList) SuFormProperties(com.qlangtech.tis.extension.impl.SuFormProperties) UploadPluginMeta(com.qlangtech.tis.util.UploadPluginMeta) DataxReader(com.qlangtech.tis.datax.impl.DataxReader) PluginFormProperties(com.qlangtech.tis.extension.PluginFormProperties) DescriptorsJSON(com.qlangtech.tis.util.DescriptorsJSON) JSONObject(org.json.JSONObject)

Example 5 with UploadPluginMeta

use of com.qlangtech.tis.util.UploadPluginMeta in project tis by qlangtech.

the class GroovyShellEvaluate method scriptEval.

public static Object scriptEval(String script, Function<Object, Object>... process) {
    try {
        UploadPluginMeta meta = UploadPluginMeta.parse(script);
        boolean unCache = meta.getBoolean(UploadPluginMeta.KEY_UNCACHE);
        Callable<Object> valGetter = () -> {
            for (Function<Object, Object> f : process) {
                return f.apply(eval(meta.getName()));
            }
            return eval(meta.getName());
        };
        return unCache ? new JsonUtil.UnCacheString(valGetter) : valGetter.call();
    } catch (Exception e) {
        throw new RuntimeException("script:" + script, e);
    }
}
Also used : Function(java.util.function.Function) UploadPluginMeta(com.qlangtech.tis.util.UploadPluginMeta) JsonUtil(com.qlangtech.tis.trigger.util.JsonUtil)

Aggregations

UploadPluginMeta (com.qlangtech.tis.util.UploadPluginMeta)7 DescriptorsJSON (com.qlangtech.tis.util.DescriptorsJSON)4 JSONObject (com.alibaba.fastjson.JSONObject)3 PluginFormProperties (com.qlangtech.tis.extension.PluginFormProperties)3 Descriptor (com.qlangtech.tis.extension.Descriptor)2 PropertyType (com.qlangtech.tis.extension.impl.PropertyType)2 JsonUtil (com.qlangtech.tis.trigger.util.JsonUtil)2 Context (com.alibaba.citrus.turbine.Context)1 JSON (com.alibaba.fastjson.JSON)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Pager (com.koubei.web.tag.pager.Pager)1 RocketMQListenerFactory (com.qlangtech.async.message.client.consumer.RocketMQListenerFactory)1 TIS (com.qlangtech.tis.TIS)1 FullbuildPhase (com.qlangtech.tis.assemble.FullbuildPhase)1 MQListenerFactory (com.qlangtech.tis.async.message.client.consumer.impl.MQListenerFactory)1 Assert (com.qlangtech.tis.common.utils.Assert)1 ParamsConfig (com.qlangtech.tis.config.ParamsConfig)1 CoreAction (com.qlangtech.tis.coredefine.module.action.CoreAction)1 DataxAction (com.qlangtech.tis.coredefine.module.action.DataxAction)1