Search in sources :

Example 26 with Context

use of com.alibaba.citrus.turbine.Context in project tis by qlangtech.

the class OperationLogInterceptor method doIntercept.

@Override
protected String doIntercept(ActionInvocation invocation) throws Exception {
    BasicModule action = (BasicModule) invocation.getAction();
    final Method method = action.getExecuteMethod();
    final String result = invocation.invoke();
    Func func = method.getAnnotation(Func.class);
    if (func != null && !func.sideEffect()) {
        return result;
    }
    AppDomainInfo appDomain = CheckAppDomainExistValve.getAppDomain(daoContext);
    OperationLog log = new OperationLog();
    log.setOpType(BasicModule.parseMehtodName());
    if (StringUtils.startsWith(log.getOpType(), "doGet")) {
        return result;
    }
    log.setCreateTime(new Date());
    if (!(appDomain instanceof Nullable)) {
        log.setAppName(appDomain.getAppName());
    }
    ActionProxy proxy = invocation.getProxy();
    // log.setOpType(proxy.getMethod());
    HttpServletRequest request = ServletActionContext.getRequest();
    if (StringUtils.indexOf(request.getClass().getSimpleName(), "Mock") > -1) {
        // 当前是测试流程的话就不需要记录日志了
        return result;
    }
    IUser user = UserUtils.getUser(request, daoContext);
    if (user == null) {
        throw new IllegalStateException("user can not be null");
    }
    StringBuffer jsonObject = new StringBuffer();
    JSONObject params = null;
    Map<String, String[]> paramsMap = null;
    String url = request.getRequestURL().toString();
    jsonObject.append("request:");
    jsonObject.append(url).append("\n");
    String requestBody = null;
    if (!ConfigFileContext.HTTPMethod.GET.name().equals(request.getMethod())) {
        paramsMap = request.getParameterMap();
        if (paramsMap.size() > 0) {
            params = new JSONObject();
            for (Map.Entry<String, String[]> entry : paramsMap.entrySet()) {
                if (entry.getValue().length == 1) {
                    params.put(entry.getKey(), entry.getValue()[0]);
                } else {
                    params.put(entry.getKey(), entry.getValue());
                }
            }
            jsonObject.append("params:").append("\n");
            jsonObject.append(params.toString(1)).append("\n");
        }
        try (ServletInputStream input = request.getInputStream()) {
            if (!input.isFinished()) {
                requestBody = IOUtils.toString(input, TisUTF8.get());
                jsonObject.append("body:").append("\n");
                jsonObject.append(requestBody).append("\n");
            }
        }
    }
    Context context = new MockContext();
    jsonObject.append("\n=================================");
    jsonObject.append("response:").append("\n");
    jsonObject.append(AjaxValve.buildResultStruct(context));
    log.setTabName(proxy.getActionName());
    log.setUsrId(user.getId());
    log.setUsrName(user.getName());
    log.setOpDesc(jsonObject.toString());
    operationLogDAO.insertSelective(log);
    return result;
}
Also used : Context(com.alibaba.citrus.turbine.Context) ServletActionContext(org.apache.struts2.ServletActionContext) ActionProxy(com.opensymphony.xwork2.ActionProxy) Func(com.qlangtech.tis.manage.spring.aop.Func) BasicModule(com.qlangtech.tis.runtime.module.action.BasicModule) OperationLog(com.qlangtech.tis.manage.biz.dal.pojo.OperationLog) Method(java.lang.reflect.Method) Date(java.util.Date) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletInputStream(javax.servlet.ServletInputStream) JSONObject(org.json.JSONObject) Map(java.util.Map) Nullable(com.qlangtech.tis.pubhook.common.Nullable)

Example 27 with Context

use of com.alibaba.citrus.turbine.Context in project tis by qlangtech.

the class SchemaAction method parseSchemaResultWithPluginCfg.

public static SchemaResult parseSchemaResultWithPluginCfg(String collection, IMessageHandler msgHandler, Context context, byte[] resContent) throws Exception {
    final Map<String, Boolean> pluginTypeAddedMap = Maps.newHashMap();
    ISchemaPluginContext schemaPlugin = createSchemaPlugin(collection);
    SchemaResult schemaResult = SchemaResult.parseSchemaResult(msgHandler, context, resContent, false, schemaPlugin, (cols, sResult) -> {
        boolean pluginTypeAdded;
        String identityNameVal = null;
        List<FieldTypeFactory> fieldTypeFactories = schemaPlugin.getFieldTypeFactories();
        for (FieldTypeFactory plugin : fieldTypeFactories) {
            identityNameVal = plugin.identityValue();
            if (!(pluginTypeAdded = sResult.containType(identityNameVal))) {
                sResult.addFieldType(identityNameVal, SolrFieldsParser.parseFieldType(identityNameVal, identityNameVal, plugin.forStringTokenizer()));
            }
            pluginTypeAddedMap.put(identityNameVal, pluginTypeAdded);
        }
    });
    schemaResult.content = XModifier.modifySchemaContent(schemaResult.content, (document2, modifier) -> {
        // FieldTypeFactory fieldTypeFactory = null;
        for (Map.Entry<String, Boolean> entry : pluginTypeAddedMap.entrySet()) {
            if (!entry.getValue()) {
                // fieldTypeFactory = fieldTypePluginStore.find(entry.getKey());
                // Objects.requireNonNull(fieldTypeFactory, "the name:" + entry.getKey() + " relevant fieldTypeFactory can not be null");
                // fieldTypeFactory.
                modifier.addModify(String.format("/types/fieldType[@name='%s']/@class", entry.getKey()), "plugin:" + entry.getKey());
                // precisionStep="0" positionIncrementGap="0"
                // modifier.addModify(String.format("/types/fieldType[@name='%s']/@precisionStep", entry.getKey()), "0");
                modifier.addModify(String.format("/types/fieldType[@name='%s']/@positionIncrementGap", entry.getKey()), "0");
            }
        }
    });
    return schemaResult;
}
Also used : WorkFlow(com.qlangtech.tis.workflow.pojo.WorkFlow) StringUtils(org.apache.commons.lang.StringUtils) PluginStore(com.qlangtech.tis.plugin.PluginStore) PSchemaField(com.qlangtech.tis.solrdao.pojo.PSchemaField) TIS(com.qlangtech.tis.TIS) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) WorkFlowCriteria(com.qlangtech.tis.workflow.pojo.WorkFlowCriteria) IServerGroupDAO(com.qlangtech.tis.manage.biz.dal.dao.IServerGroupDAO) SaveFileContentAction(com.qlangtech.tis.runtime.module.action.jarcontent.SaveFileContentAction) Document(org.jdom2.Document) com.qlangtech.tis.solrdao(com.qlangtech.tis.solrdao) ByteArrayInputStream(java.io.ByteArrayInputStream) PermissionConstant(com.qlangtech.tis.manage.PermissionConstant) IDataxProcessor(com.qlangtech.tis.datax.IDataxProcessor) IPluginStore(com.qlangtech.tis.plugin.IPluginStore) EntityResolver(org.xml.sax.EntityResolver) Savefilecontent(com.qlangtech.tis.manage.Savefilecontent) com.qlangtech.tis.manage.biz.dal.pojo(com.qlangtech.tis.manage.biz.dal.pojo) Validator(com.qlangtech.tis.plugin.annotation.Validator) ISolrAppSource(com.qlangtech.tis.manage.ISolrAppSource) JSONException(com.alibaba.fastjson.JSONException) com.qlangtech.tis.manage.common(com.qlangtech.tis.manage.common) Collectors(java.util.stream.Collectors) IOUtils(org.apache.commons.io.IOUtils) ISearchEngineTypeTransfer(com.qlangtech.tis.datax.ISearchEngineTypeTransfer) DataxReader(com.qlangtech.tis.datax.impl.DataxReader) SAXException(org.xml.sax.SAXException) RunEnvironment(com.qlangtech.tis.pubhook.common.RunEnvironment) JSONObject(com.alibaba.fastjson.JSONObject) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Pattern(java.util.regex.Pattern) UnsupportedEncodingException(java.io.UnsupportedEncodingException) LuceneVersion(com.qlangtech.tis.fullbuild.indexbuild.LuceneVersion) ParseResult(com.qlangtech.tis.solrdao.impl.ParseResult) java.util(java.util) BeanUtils(org.apache.commons.beanutils.BeanUtils) DocType(org.jdom2.DocType) Func(com.qlangtech.tis.manage.spring.aop.Func) ColumnMetaData(com.qlangtech.tis.plugin.ds.ColumnMetaData) SolrType(com.qlangtech.tis.solrdao.SolrFieldsParser.SolrType) Context(com.alibaba.citrus.turbine.Context) JsonUtil(com.qlangtech.tis.trigger.util.JsonUtil) JSONArray(com.alibaba.fastjson.JSONArray) com.qlangtech.tis.runtime.module.misc(com.qlangtech.tis.runtime.module.misc) DataxProcessor(com.qlangtech.tis.datax.impl.DataxProcessor) Charset(java.nio.charset.Charset) XModifier(com.yushu.tis.xmodifier.XModifier) DataxUtils(com.qlangtech.tis.offline.DataxUtils) InputSource(org.xml.sax.InputSource) ReflectSchemaFieldType(com.qlangtech.tis.plugin.ds.ReflectSchemaFieldType) FieldTypeFactory(com.qlangtech.tis.plugin.solr.schema.FieldTypeFactory) IOException(java.io.IOException) Maps(com.google.common.collect.Maps) JSON(com.alibaba.fastjson.JSON) StringReader(java.io.StringReader) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Assert(com.qlangtech.tis.common.utils.Assert) FieldTypeFactory(com.qlangtech.tis.plugin.solr.schema.FieldTypeFactory)

Example 28 with Context

use of com.alibaba.citrus.turbine.Context in project tis by qlangtech.

the class SchemaAction method doGetApp.

/**
 * 当一个索引创建之后又被删除了,又需要重新创建就需要需执行该流程了,过程中需要将之前的记录找回来
 *
 * @param context
 */
public void doGetApp(Context context) throws Exception {
    final String collectionName = this.getString("name");
    if (StringUtils.isEmpty(collectionName)) {
        throw new IllegalArgumentException("param name can not be null");
    }
    AddAppAction.ExtendApp app = new AddAppAction.ExtendApp();
    Application a = this.getApplicationDAO().selectByName(collectionName);
    BeanUtils.copyProperties(app, a);
    WorkFlow df = this.getWorkflowDAOFacade().getWorkFlowDAO().selectByPrimaryKey(a.getWorkFlowId());
    if (df == null) {
        this.addErrorMessage(context, "当前索引'" + collectionName + "'还未绑定数据流实例");
        return;
    }
    app.setWorkflow(df.getId() + ":" + df.getName());
    DepartmentCriteria dc = new DepartmentCriteria();
    dc.createCriteria();
    List<Department> dpts = this.getDepartmentDAO().selectByExample(dc);
    if (dpts.size() < 1) {
        this.addErrorMessage(context, "系统还未创建部门实例");
        return;
    }
    app.setSelectableDepartment(dpts.stream().map((r) -> new Option(r.getName(), String.valueOf(r.getDptId()))).collect(Collectors.toList()));
    Map<String, Object> result = Maps.newHashMap();
    result.put("app", app);
    if (!getStructSchema(context, app, (schema) -> {
        result.put("schema", schema);
    })) {
        return;
    }
    this.setBizResult(context, result);
}
Also used : WorkFlow(com.qlangtech.tis.workflow.pojo.WorkFlow) StringUtils(org.apache.commons.lang.StringUtils) PluginStore(com.qlangtech.tis.plugin.PluginStore) PSchemaField(com.qlangtech.tis.solrdao.pojo.PSchemaField) TIS(com.qlangtech.tis.TIS) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) WorkFlowCriteria(com.qlangtech.tis.workflow.pojo.WorkFlowCriteria) IServerGroupDAO(com.qlangtech.tis.manage.biz.dal.dao.IServerGroupDAO) SaveFileContentAction(com.qlangtech.tis.runtime.module.action.jarcontent.SaveFileContentAction) Document(org.jdom2.Document) com.qlangtech.tis.solrdao(com.qlangtech.tis.solrdao) ByteArrayInputStream(java.io.ByteArrayInputStream) PermissionConstant(com.qlangtech.tis.manage.PermissionConstant) IDataxProcessor(com.qlangtech.tis.datax.IDataxProcessor) IPluginStore(com.qlangtech.tis.plugin.IPluginStore) EntityResolver(org.xml.sax.EntityResolver) Savefilecontent(com.qlangtech.tis.manage.Savefilecontent) com.qlangtech.tis.manage.biz.dal.pojo(com.qlangtech.tis.manage.biz.dal.pojo) Validator(com.qlangtech.tis.plugin.annotation.Validator) ISolrAppSource(com.qlangtech.tis.manage.ISolrAppSource) JSONException(com.alibaba.fastjson.JSONException) com.qlangtech.tis.manage.common(com.qlangtech.tis.manage.common) Collectors(java.util.stream.Collectors) IOUtils(org.apache.commons.io.IOUtils) ISearchEngineTypeTransfer(com.qlangtech.tis.datax.ISearchEngineTypeTransfer) DataxReader(com.qlangtech.tis.datax.impl.DataxReader) SAXException(org.xml.sax.SAXException) RunEnvironment(com.qlangtech.tis.pubhook.common.RunEnvironment) JSONObject(com.alibaba.fastjson.JSONObject) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Pattern(java.util.regex.Pattern) UnsupportedEncodingException(java.io.UnsupportedEncodingException) LuceneVersion(com.qlangtech.tis.fullbuild.indexbuild.LuceneVersion) ParseResult(com.qlangtech.tis.solrdao.impl.ParseResult) java.util(java.util) BeanUtils(org.apache.commons.beanutils.BeanUtils) DocType(org.jdom2.DocType) Func(com.qlangtech.tis.manage.spring.aop.Func) ColumnMetaData(com.qlangtech.tis.plugin.ds.ColumnMetaData) SolrType(com.qlangtech.tis.solrdao.SolrFieldsParser.SolrType) Context(com.alibaba.citrus.turbine.Context) JsonUtil(com.qlangtech.tis.trigger.util.JsonUtil) JSONArray(com.alibaba.fastjson.JSONArray) com.qlangtech.tis.runtime.module.misc(com.qlangtech.tis.runtime.module.misc) DataxProcessor(com.qlangtech.tis.datax.impl.DataxProcessor) Charset(java.nio.charset.Charset) XModifier(com.yushu.tis.xmodifier.XModifier) DataxUtils(com.qlangtech.tis.offline.DataxUtils) InputSource(org.xml.sax.InputSource) ReflectSchemaFieldType(com.qlangtech.tis.plugin.ds.ReflectSchemaFieldType) FieldTypeFactory(com.qlangtech.tis.plugin.solr.schema.FieldTypeFactory) IOException(java.io.IOException) Maps(com.google.common.collect.Maps) JSON(com.alibaba.fastjson.JSON) StringReader(java.io.StringReader) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Assert(com.qlangtech.tis.common.utils.Assert) WorkFlow(com.qlangtech.tis.workflow.pojo.WorkFlow) JSONObject(com.alibaba.fastjson.JSONObject)

Example 29 with Context

use of com.alibaba.citrus.turbine.Context in project tis by qlangtech.

the class SchemaAction method mergeWfColsWithTplCollection.

/**
 * 通过解析workflow的最终导出的字段,来生成Schema配置
 *
 * @param module
 * @param context
 * @param appSource
 * @return
 * @throws Exception
 */
public static SchemaResult mergeWfColsWithTplCollection(BasicModule module, Context context, ISolrAppSource appSource, final ISchemaPluginContext schemaPlugin, SolrFieldsParser.ParseResultCallback... parseResultCallback) throws Exception {
    // 通过version取默认模板
    Application tplApp = getTemplateApp(module);
    SchemaResult tplSchema = getTemplateSchema(module, context, tplApp);
    if (!tplSchema.isSuccess()) {
        return null;
    }
    ParseResult parseResult = (ParseResult) tplSchema.getParseResult();
    SolrType strType = parseResult.getTisType(ReflectSchemaFieldType.STRING.literia);
    List<ColumnMetaData> cols = appSource.reflectCols();
    for (ColumnMetaData colName : cols) {
        PSchemaField f = new PSchemaField();
        f.setName(colName.getKey());
        f.setType(strType);
        f.setStored(true);
        f.setIndexed(false);
        f.setMltiValued(false);
        f.setDocValue(false);
        parseResult.dFields.add(f);
    }
    parseResult.setUniqueKey(null);
    for (SolrFieldsParser.ParseResultCallback c : parseResultCallback) {
        c.process(cols, parseResult);
    }
    parseResult.addReservedFields();
    tplSchema.content = XModifier.modifySchemaContent(tplSchema.content, (document2, modifier) -> {
        modifier.addModify("/fields/field(:delete)");
        modifier.addModify("/sharedKey(:delete)");
        modifier.deleteUniqueKey();
        updateSchemaXML(parseResult.types, schemaPlugin, parseResult, document2, modifier);
    });
    parseResultCallback4test.process(cols, parseResult);
    return tplSchema;
}
Also used : WorkFlow(com.qlangtech.tis.workflow.pojo.WorkFlow) StringUtils(org.apache.commons.lang.StringUtils) PluginStore(com.qlangtech.tis.plugin.PluginStore) PSchemaField(com.qlangtech.tis.solrdao.pojo.PSchemaField) TIS(com.qlangtech.tis.TIS) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) WorkFlowCriteria(com.qlangtech.tis.workflow.pojo.WorkFlowCriteria) IServerGroupDAO(com.qlangtech.tis.manage.biz.dal.dao.IServerGroupDAO) SaveFileContentAction(com.qlangtech.tis.runtime.module.action.jarcontent.SaveFileContentAction) Document(org.jdom2.Document) com.qlangtech.tis.solrdao(com.qlangtech.tis.solrdao) ByteArrayInputStream(java.io.ByteArrayInputStream) PermissionConstant(com.qlangtech.tis.manage.PermissionConstant) IDataxProcessor(com.qlangtech.tis.datax.IDataxProcessor) IPluginStore(com.qlangtech.tis.plugin.IPluginStore) EntityResolver(org.xml.sax.EntityResolver) Savefilecontent(com.qlangtech.tis.manage.Savefilecontent) com.qlangtech.tis.manage.biz.dal.pojo(com.qlangtech.tis.manage.biz.dal.pojo) Validator(com.qlangtech.tis.plugin.annotation.Validator) ISolrAppSource(com.qlangtech.tis.manage.ISolrAppSource) JSONException(com.alibaba.fastjson.JSONException) com.qlangtech.tis.manage.common(com.qlangtech.tis.manage.common) Collectors(java.util.stream.Collectors) IOUtils(org.apache.commons.io.IOUtils) ISearchEngineTypeTransfer(com.qlangtech.tis.datax.ISearchEngineTypeTransfer) DataxReader(com.qlangtech.tis.datax.impl.DataxReader) SAXException(org.xml.sax.SAXException) RunEnvironment(com.qlangtech.tis.pubhook.common.RunEnvironment) JSONObject(com.alibaba.fastjson.JSONObject) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Pattern(java.util.regex.Pattern) UnsupportedEncodingException(java.io.UnsupportedEncodingException) LuceneVersion(com.qlangtech.tis.fullbuild.indexbuild.LuceneVersion) ParseResult(com.qlangtech.tis.solrdao.impl.ParseResult) java.util(java.util) BeanUtils(org.apache.commons.beanutils.BeanUtils) DocType(org.jdom2.DocType) Func(com.qlangtech.tis.manage.spring.aop.Func) ColumnMetaData(com.qlangtech.tis.plugin.ds.ColumnMetaData) SolrType(com.qlangtech.tis.solrdao.SolrFieldsParser.SolrType) Context(com.alibaba.citrus.turbine.Context) JsonUtil(com.qlangtech.tis.trigger.util.JsonUtil) JSONArray(com.alibaba.fastjson.JSONArray) com.qlangtech.tis.runtime.module.misc(com.qlangtech.tis.runtime.module.misc) DataxProcessor(com.qlangtech.tis.datax.impl.DataxProcessor) Charset(java.nio.charset.Charset) XModifier(com.yushu.tis.xmodifier.XModifier) DataxUtils(com.qlangtech.tis.offline.DataxUtils) InputSource(org.xml.sax.InputSource) ReflectSchemaFieldType(com.qlangtech.tis.plugin.ds.ReflectSchemaFieldType) FieldTypeFactory(com.qlangtech.tis.plugin.solr.schema.FieldTypeFactory) IOException(java.io.IOException) Maps(com.google.common.collect.Maps) JSON(com.alibaba.fastjson.JSON) StringReader(java.io.StringReader) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Assert(com.qlangtech.tis.common.utils.Assert) SolrType(com.qlangtech.tis.solrdao.SolrFieldsParser.SolrType) ParseResult(com.qlangtech.tis.solrdao.impl.ParseResult) PSchemaField(com.qlangtech.tis.solrdao.pojo.PSchemaField) ColumnMetaData(com.qlangtech.tis.plugin.ds.ColumnMetaData)

Example 30 with Context

use of com.alibaba.citrus.turbine.Context in project tis by qlangtech.

the class PluginItems method save.

public List<Describable> save(Context context) {
    Objects.requireNonNull(this.pluginContext, "pluginContext can not be null");
    if (items == null) {
        throw new IllegalStateException("prop items can not be null");
    }
    Descriptor.ParseDescribable describable = null;
    AttrValMap attrValMap = null;
    List<Descriptor.ParseDescribable<?>> dlist = Lists.newArrayList();
    List<Describable> describableList = Lists.newArrayList();
    if (this.pluginMeta.isAppend()) {
        IPluginStore pluginStore = heteroEnum.getPluginStore(this.pluginContext, this.pluginMeta);
        if (pluginStore != null) {
            List<Describable> plugins = pluginStore.getPlugins();
            boolean firstSkip = false;
            for (Describable p : plugins) {
                if (!firstSkip) {
                    firstSkip = true;
                    Descriptor.ParseDescribable describablesWithMeta = PluginStore.getDescribablesWithMeta(pluginStore, p);
                    dlist.add(describablesWithMeta);
                } else {
                    dlist.add(new Descriptor.ParseDescribable(p));
                }
            }
        }
    }
    for (int i = 0; i < this.items.size(); i++) {
        attrValMap = this.items.get(i);
        /**
         *====================================================
         * 将客户端post数据包装
         *       ======================================================
         */
        describable = attrValMap.createDescribable(pluginContext);
        dlist.add(describable);
        describableList.add((Describable) describable.instance);
    }
    IPluginStoreSave<?> store = null;
    if (heteroEnum == HeteroEnum.APP_SOURCE) {
        for (Descriptor.ParseDescribable<?> d : dlist) {
            if (d.instance instanceof IdentityName) {
                store = IAppSource.getPluginStore(pluginContext, ((IdentityName) d.instance).identityValue());
                break;
            }
        }
        Objects.requireNonNull(store, "plugin type:" + heteroEnum.getIdentity() + " can not find relevant Store");
    } else if (this.pluginContext.isDataSourceAware()) {
        store = new IPluginStoreSave<DataSourceFactory>() {

            @Override
            public boolean setPlugins(IPluginContext pluginContext, Optional<Context> context, List<Descriptor.ParseDescribable<DataSourceFactory>> dlist, boolean update) {
                for (Descriptor.ParseDescribable<DataSourceFactory> plugin : dlist) {
                    PostedDSProp dbExtraProps = PostedDSProp.parse(pluginMeta);
                    if (DbScope.DETAILED == dbExtraProps.getDbType()) {
                        dbExtraProps.setDbname(plugin.instance.identityValue());
                    }
                    boolean success = TIS.getDataBasePluginStore(dbExtraProps).setPlugins(pluginContext, context, Collections.singletonList(plugin), dbExtraProps.isUpdate());
                    if (!success) {
                        return false;
                    }
                }
                return true;
            }
        };
    } else if (heteroEnum == HeteroEnum.DATAX_WRITER || heteroEnum == HeteroEnum.DATAX_READER) {
        // final String dataxName = pluginMeta.getExtraParam(DataxUtils.DATAX_NAME);
        // if (StringUtils.isEmpty(dataxName)) {
        // String saveDbName = pluginMeta.getExtraParam(DataxUtils.DATAX_DB_NAME);
        // if (StringUtils.isNotBlank(saveDbName)) {
        // store = DataxReader.getPluginStore(this.pluginContext, true, saveDbName);
        // } else {
        // throw new IllegalArgumentException("plugin extra param " + DataxUtils.DATAX_NAME + " can not be null");
        // }
        // } else {
        // KeyedPluginStore<?> keyStore = (heteroEnum == HeteroEnum.DATAX_READER)
        // ? DataxReader.getPluginStore(this.pluginContext, dataxName) : DataxWriter.getPluginStore(this.pluginContext, dataxName);
        // store = keyStore;
        // }
        // if ((heteroEnum == HeteroEnum.DATAX_READER)) {
        // for (Descriptor.ParseDescribable<?> dataXReader : dlist) {
        // DataSourceMeta sourceMeta = (DataSourceMeta) dataXReader.instance;
        // pluginContext.setBizResult(context, sourceMeta.getTablesInDB());
        // }
        // }
        store = HeteroEnum.getDataXReaderAndWriterStore(this.pluginContext, this.heteroEnum == HeteroEnum.DATAX_READER, this.pluginMeta);
        Optional<IPropertyType.SubFormFilter> subFormFilter = pluginMeta.getSubFormFilter();
        if (subFormFilter.isPresent()) {
            IPropertyType.SubFormFilter filter = subFormFilter.get();
            Optional<Descriptor> firstDesc = heteroEnum.descriptors().stream().filter((des) -> filter.match((Descriptor) des)).map((des) -> (Descriptor) des).findFirst();
            if (!firstDesc.isPresent()) {
                throw new IllegalStateException("can not find relevant descriptor:" + filter.uploadPluginMeta.toString());
            }
            // Describable p = keyStore.getPlugin();
            // Descriptor des = p.getDescriptor();
            PluginFormProperties pluginProps = firstDesc.get().getPluginFormPropertyTypes(subFormFilter);
            store = pluginProps.accept(new PluginFormProperties.IVisitor() {

                @Override
                public IPluginStoreSave<?> visit(SuFormProperties props) {
                    // 为了在更新插件时候不把plugin上的@SubForm标记的属性覆盖掉,需要先将老的plugin上的值覆盖到新http post过来的反序列化之后的plugin上
                    // IPluginContext pluginContext, String appname, SuFormProperties subfieldForm, Class<TT> clazz
                    Class<Describable> clazz = (Class<Describable>) heteroEnum.getExtensionPoint();
                    // DataxReader.SubFieldFormAppKey<Describable> key
                    // = new DataxReader.SubFieldFormAppKey<>(pluginContext, dataxName, props, clazz);
                    // 
                    DataxReader.SubFieldFormAppKey<Describable> key = HeteroEnum.createDataXReaderAndWriterRelevant(pluginContext, pluginMeta, new HeteroEnum.DataXReaderAndWriterRelevantCreator<DataxReader.SubFieldFormAppKey<Describable>>() {

                        @Override
                        public DataxReader.SubFieldFormAppKey<Describable> dbRelevant(IPluginContext pluginContext, String saveDbName) {
                            return new DataxReader.SubFieldFormAppKey<>(pluginContext, true, saveDbName, props, clazz);
                        }

                        @Override
                        public DataxReader.SubFieldFormAppKey<Describable> appRelevant(IPluginContext pluginContext, String dataxName) {
                            return new DataxReader.SubFieldFormAppKey<>(pluginContext, false, dataxName, props, clazz);
                        }
                    });
                    return KeyedPluginStore.getPluginStore(key);
                }
            });
        }
    } else if (heteroEnum == HeteroEnum.PARAMS_CONFIG) {
        store = new ParamsConfigPluginStore(this.pluginMeta);
    } else if (heteroEnum == HeteroEnum.DATAX_WORKER) {
        if (!this.pluginContext.isCollectionAware()) {
            throw new IllegalStateException("must be collection aware");
        }
        store = DataXJobWorker.getJobWorkerStore(new TargetResName(this.pluginContext.getCollectionName()));
    // } else if (this.pluginContext.isCollectionAware()) {
    // store = TIS.getPluginStore(this.pluginContext.getCollectionName(), heteroEnum.getExtensionPoint());
    } else {
        if (heteroEnum.isAppNameAware()) {
            if (!this.pluginContext.isCollectionAware()) {
                throw new IllegalStateException(heteroEnum.getExtensionPoint().getName() + " must be collection aware");
            }
            store = TIS.getPluginStore(this.pluginContext.getCollectionName(), heteroEnum.getExtensionPoint());
        } else {
            store = TIS.getPluginStore(heteroEnum.getExtensionPoint());
        }
    // if (heteroEnum.isAppNameAware()) {
    // throw new IllegalStateException(heteroEnum.getExtensionPoint().getName() + " must be app name aware");
    // }
    }
    // dlist
    if (!store.setPlugins(pluginContext, Optional.of(context), convert(dlist))) {
        return Collections.emptyList();
    }
    observable.notifyObservers(new PluginItemsSaveEvent(this.pluginContext, this.heteroEnum, describableList));
    return describableList;
}
Also used : OfflineDatasourceAction(com.qlangtech.tis.offline.module.action.OfflineDatasourceAction) java.util(java.util) TargetResName(com.qlangtech.tis.coredefine.module.action.TargetResName) IAppSource(com.qlangtech.tis.manage.IAppSource) TIS(com.qlangtech.tis.TIS) DatasourceDbCriteria(com.qlangtech.tis.workflow.pojo.DatasourceDbCriteria) Option(com.qlangtech.tis.manage.common.Option) PostedDSProp(com.qlangtech.tis.plugin.ds.PostedDSProp) DbScope(com.qlangtech.tis.offline.DbScope) StringUtils(org.apache.commons.lang3.StringUtils) Context(com.alibaba.citrus.turbine.Context) ParamsConfigPluginStore(com.qlangtech.tis.plugin.credentials.ParamsConfigPluginStore) DataXJobWorker(com.qlangtech.tis.datax.job.DataXJobWorker) BasicServlet(com.qlangtech.tis.manage.servlet.BasicServlet) Lists(com.google.common.collect.Lists) IPropertyType(com.qlangtech.tis.extension.IPropertyType) PluginFormProperties(com.qlangtech.tis.extension.PluginFormProperties) DataSourceFactory(com.qlangtech.tis.plugin.ds.DataSourceFactory) GroovyShellEvaluate(com.qlangtech.tis.extension.util.GroovyShellEvaluate) IWorkflowDAOFacade(com.qlangtech.tis.workflow.dao.IWorkflowDAOFacade) com.qlangtech.tis.plugin(com.qlangtech.tis.plugin) Descriptor(com.qlangtech.tis.extension.Descriptor) IPluginEnum(com.qlangtech.tis.IPluginEnum) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ServletActionContext(org.apache.struts2.ServletActionContext) DataxReader(com.qlangtech.tis.datax.impl.DataxReader) SuFormProperties(com.qlangtech.tis.extension.impl.SuFormProperties) Describable(com.qlangtech.tis.extension.Describable) DataSourceFactory(com.qlangtech.tis.plugin.ds.DataSourceFactory) Describable(com.qlangtech.tis.extension.Describable) PostedDSProp(com.qlangtech.tis.plugin.ds.PostedDSProp) TargetResName(com.qlangtech.tis.coredefine.module.action.TargetResName) SuFormProperties(com.qlangtech.tis.extension.impl.SuFormProperties) DataxReader(com.qlangtech.tis.datax.impl.DataxReader) PluginFormProperties(com.qlangtech.tis.extension.PluginFormProperties) Descriptor(com.qlangtech.tis.extension.Descriptor) IPropertyType(com.qlangtech.tis.extension.IPropertyType) ParamsConfigPluginStore(com.qlangtech.tis.plugin.credentials.ParamsConfigPluginStore)

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