Search in sources :

Example 1 with IdentityName

use of com.qlangtech.tis.plugin.IdentityName in project tis by qlangtech.

the class Descriptor method getPluginFormPropertyTypes.

public PluginFormProperties getPluginFormPropertyTypes(Optional<IPropertyType.SubFormFilter> subFormFilter) {
    IPropertyType.SubFormFilter filter = null;
    if (subFormFilter.isPresent()) {
        filter = subFormFilter.get();
        if (filter.match(this)) {
            SuFormProperties subPluginFormPropertyTypes = (SuFormProperties) getSubPluginFormPropertyTypes(filter.subFieldName);
            try {
                // 类似Hudi的Writer需要覆盖Reader的subFieldName的在Reader的表设置表单中需要设置Hudi相关的属性
                // DataxWriter dataxWriter = DataxWriter.load(filter.uploadPluginMeta.getPluginContext(), dataXName);
                Descriptor writerDescriptor = // dataxWriter.getClass();
                IDataxProcessor.getWriterDescriptor(filter.uploadPluginMeta);
                if (writerDescriptor instanceof DataxWriter.IRewriteSuFormProperties) {
                    subPluginFormPropertyTypes = Objects.requireNonNull(((DataxWriter.IRewriteSuFormProperties) writerDescriptor).overwriteSubPluginFormPropertyTypes(subPluginFormPropertyTypes), "result can not be null " + PluginFormProperties.class.getSimpleName());
                }
            // String overwriteSubField = IOUtils.loadResourceFromClasspath(
            // writerClass, writerClass.getSimpleName() + "." + filter.subFieldName + ".json", false);
            // if (overwriteSubField != null) {
            // JSONObject subField = JSON.parseObject(overwriteSubField);
            // Class<?> clazz = writerClass.getClassLoader().loadClass(subField.getString(SubForm.FIELD_DES_CLASS));
            // return SuFormProperties.copy(filterFieldProp(buildPropertyTypes(this, clazz)), subPluginFormPropertyTypes);
            // }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            if (filter.subformDetailView) {
                final String subformDetailId = filter.subformDetailId;
                final SuFormProperties _subPluginFormPropertyTypes = subPluginFormPropertyTypes;
                return new AdapterPluginFormProperties(subPluginFormPropertyTypes) {

                    @Override
                    public JSON getInstancePropsJson(Object instance) {
                        Collection<IdentityName> subFormPropVal = _subPluginFormPropertyTypes.getSubFormPropVal(instance);
                        for (IdentityName subProp : subFormPropVal) {
                            if (StringUtils.equals(subformDetailId, subProp.identityValue())) {
                                return (new RootFormProperties(_subPluginFormPropertyTypes.fieldsType)).getInstancePropsJson(subProp);
                            }
                        }
                        ISelectedTab subDetailed = _subPluginFormPropertyTypes.newSubDetailed();
                        _subPluginFormPropertyTypes.pkPropertyType.setVal(subDetailed, subformDetailId);
                        return (new RootFormProperties(_subPluginFormPropertyTypes.fieldsType)).getInstancePropsJson(subDetailed);
                    // throw new IllegalStateException("subformDetailId:" + subformDetailId + " has not find subForm instance");
                    }
                };
            } else {
                return subPluginFormPropertyTypes;
            }
        }
    }
    return new RootFormProperties(filterFieldProp(getPropertyTypes()));
}
Also used : ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) IOException(java.io.IOException) JSONObject(com.alibaba.fastjson.JSONObject) IdentityName(com.qlangtech.tis.plugin.IdentityName)

Example 2 with IdentityName

use of com.qlangtech.tis.plugin.IdentityName in project tis by qlangtech.

the class PluginAction method doSavePluginConfig.

/**
 * 保存blugin配置
 *
 * @param context
 */
public void doSavePluginConfig(Context context) throws Exception {
    if (this.getBoolean("errors_page_show")) {
        this.errorsPageShow(context);
    }
    List<UploadPluginMeta> plugins = getPluginMeta();
    JSONObject postData = this.parseJsonPost();
    String serverForward = postData.getString("serverForward");
    String[] forwardParams = null;
    if (StringUtils.isNotEmpty(serverForward)) {
        forwardParams = StringUtils.split(serverForward, ":");
        if (forwardParams.length != 3) {
            throw new IllegalArgumentException("illegal forward param:" + serverForward);
        }
    }
    JSONArray pluginArray = Objects.requireNonNull(postData.getJSONArray("items"), "json prop items can not be null");
    UploadPluginMeta pluginMeta = null;
    // JSONObject itemObj = null;
    boolean faild = false;
    List<PluginItems> categoryPlugins = Lists.newArrayList();
    // 是否进行业务逻辑校验?当正式提交表单时候不进行业务逻辑校验,用户可能先添加一个不存在的数据库配置
    final boolean verify = this.getBoolean("verify");
    PluginItemsParser pluginItemsParser = null;
    for (int pluginIndex = 0; pluginIndex < plugins.size(); pluginIndex++) {
        // items = Lists.newArrayList();
        pluginMeta = plugins.get(pluginIndex);
        // subFormFilter = pluginMeta.getSubFormFilter();
        JSONArray itemsArray = pluginArray.getJSONArray(pluginIndex);
        // hEnum = pluginMeta.getHeteroEnum();
        pluginItemsParser = parsePluginItems(this, pluginMeta, context, pluginIndex, itemsArray, verify);
        if (pluginItemsParser.faild) {
            faild = true;
        }
        categoryPlugins.add(pluginItemsParser.pluginItems);
    }
    if (this.hasErrors(context) || verify) {
        return;
    }
    if (faild) {
        // 判断提交的plugin表单是否有错误?错误则退出
        this.addErrorMessage(context, "提交表单内容有错误");
        return;
    }
    List<Describable> describables = Lists.newArrayList();
    for (PluginItems pi : categoryPlugins) {
        describables.addAll(pi.save(context));
    }
    if (forwardParams != null) {
        // getRundata().forwardTo(getCoredefine().namespace, "core_action", "create_incr_sync_channal");
        getRundata().forwardTo(forwardParams[0], forwardParams[1], forwardParams[2]);
        return;
    }
    addActionMessage(context, "配置保存成功");
    // 成功保存的主键信息返回给客户端
    if (context.get(IMessageHandler.ACTION_BIZ_RESULT) == null) {
        this.setBizResult(context, describables.stream().filter((d) -> d instanceof IdentityName).map((d) -> ((IdentityName) d).identityValue()).collect(Collectors.toList()));
    }
}
Also used : Pager(com.koubei.web.tag.pager.Pager) java.util(java.util) InstallState(com.qlangtech.tis.install.InstallState) URL(java.net.URL) TIS(com.qlangtech.tis.TIS) DatasourceDbCriteria(com.qlangtech.tis.workflow.pojo.DatasourceDbCriteria) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Option(com.qlangtech.tis.manage.common.Option) InterceptorRef(org.apache.struts2.convention.annotation.InterceptorRef) StringUtils(org.apache.commons.lang3.StringUtils) Context(com.alibaba.citrus.turbine.Context) JSONArray(com.alibaba.fastjson.JSONArray) Config(com.qlangtech.tis.manage.common.Config) Future(java.util.concurrent.Future) Lists(com.google.common.collect.Lists) PropertyType(com.qlangtech.tis.extension.impl.PropertyType) CollectionUtils(org.apache.commons.collections.CollectionUtils) com.qlangtech.tis.util(com.qlangtech.tis.util) RootFormProperties(com.qlangtech.tis.extension.impl.RootFormProperties) OfflineManager(com.qlangtech.tis.offline.module.manager.impl.OfflineManager) DataSourceFactory(com.qlangtech.tis.plugin.ds.DataSourceFactory) InterceptorRefs(org.apache.struts2.convention.annotation.InterceptorRefs) FormFieldType(com.qlangtech.tis.plugin.annotation.FormFieldType) PluginExtraProps(com.qlangtech.tis.extension.util.PluginExtraProps) Logger(org.slf4j.Logger) IdentityName(com.qlangtech.tis.plugin.IdentityName) InstallUtil(com.qlangtech.tis.install.InstallUtil) IPluginEnum(com.qlangtech.tis.IPluginEnum) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) UpdateCenter(com.qlangtech.tis.extension.model.UpdateCenter) DatasourceDb(com.qlangtech.tis.workflow.pojo.DatasourceDb) UpdateSite(com.qlangtech.tis.extension.model.UpdateSite) BasicModule(com.qlangtech.tis.runtime.module.action.BasicModule) HttpUtils(com.qlangtech.tis.manage.common.HttpUtils) JSONObject(com.alibaba.fastjson.JSONObject) com.qlangtech.tis.extension(com.qlangtech.tis.extension) SuFormProperties(com.qlangtech.tis.extension.impl.SuFormProperties) IMessageHandler(com.qlangtech.tis.runtime.module.misc.IMessageHandler) ConfigFileContext(com.qlangtech.tis.manage.common.ConfigFileContext) InputStream(java.io.InputStream) JSONArray(com.alibaba.fastjson.JSONArray) JSONObject(com.alibaba.fastjson.JSONObject) IdentityName(com.qlangtech.tis.plugin.IdentityName)

Example 3 with IdentityName

use of com.qlangtech.tis.plugin.IdentityName in project tis by qlangtech.

the class PluginAction method parsePluginItems.

public static PluginItemsParser parsePluginItems(BasicModule module, UploadPluginMeta pluginMeta, Context context, int pluginIndex, JSONArray itemsArray, boolean verify) {
    context.put(UploadPluginMeta.KEY_PLUGIN_META, pluginMeta);
    PluginItemsParser parseResult = new PluginItemsParser();
    List<Descriptor.PluginValidateResult> items = Lists.newArrayList();
    Optional<IPropertyType.SubFormFilter> subFormFilter = pluginMeta.getSubFormFilter();
    Descriptor.PluginValidateResult validateResult = null;
    IPluginEnum hEnum = pluginMeta.getHeteroEnum();
    // context.put(KEY_VALIDATE_PLUGIN_INDEX, new Integer(pluginIndex));
    PluginItems pluginItems = new PluginItems(module, pluginMeta);
    List<AttrValMap> describableAttrValMapList = AttrValMap.describableAttrValMapList(module, itemsArray, subFormFilter);
    if (pluginMeta.isRequired() && describableAttrValMapList.size() < 1) {
        module.addErrorMessage(context, "请设置'" + hEnum.getCaption() + "'表单内容");
    }
    pluginItems.items = describableAttrValMapList;
    parseResult.pluginItems = pluginItems;
    // categoryPlugins.add(pluginItems);
    AttrValMap attrValMap = null;
    for (int itemIndex = 0; itemIndex < describableAttrValMapList.size(); itemIndex++) {
        attrValMap = describableAttrValMapList.get(itemIndex);
        Descriptor.PluginValidateResult.setValidateItemPos(context, pluginIndex, itemIndex);
        if (!(validateResult = attrValMap.validate(context, verify)).isValid()) {
            parseResult.faild = true;
        } else {
            validateResult.setDescriptor(attrValMap.descriptor);
            items.add(validateResult);
        }
    }
    /**
     *===============================================
     * 校验Item字段的identity字段不能重复,不然就报错
     *     ===============================================
     */
    Map<String, Descriptor.PluginValidateResult> identityUniqueMap = Maps.newHashMap();
    Descriptor.PluginValidateResult previous = null;
    if (!parseResult.faild && hEnum.isIdentityUnique() && hEnum.getSelectable() == Selectable.Multi && (items.size() > 1 || pluginMeta.isAppend())) {
        if (pluginMeta.isAppend()) {
            List<IdentityName> plugins = hEnum.getPlugins(module, pluginMeta);
            for (IdentityName p : plugins) {
                Descriptor.PluginValidateResult r = new Descriptor.PluginValidateResult(new Descriptor.PostFormVals(Collections.emptyMap()), 0, 0);
                r.setDescriptor(((Describable) p).getDescriptor());
                identityUniqueMap.put(p.identityValue(), r);
            }
        }
        for (Descriptor.PluginValidateResult i : items) {
            if ((previous = identityUniqueMap.put(i.getIdentityFieldValue(), i)) != null) {
                previous.addIdentityFieldValueDuplicateError(module, context);
                i.addIdentityFieldValueDuplicateError(module, context);
                return parseResult;
            }
        }
    }
    return parseResult;
}
Also used : IPluginEnum(com.qlangtech.tis.IPluginEnum) IdentityName(com.qlangtech.tis.plugin.IdentityName)

Example 4 with IdentityName

use of com.qlangtech.tis.plugin.IdentityName 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 IdentityName

use of com.qlangtech.tis.plugin.IdentityName in project tis by qlangtech.

the class DescribableJSON method getItemJson.

public JSONObject getItemJson(Optional<IPropertyType.SubFormFilter> subFormFilter) throws Exception {
    JSONObject item = new JSONObject();
    // item.put(DescriptorsJSON.KEY_IMPL, descriptor.getId());
    // item.put(DescriptorsJSON.KEY_IMPL_URL, Config.TIS_PUB_PLUGINS_DOC_URL + StringUtils.lowerCase(descriptor.clazz.getSimpleName()));
    // item.put(DescriptorsJSON.KEY_DISPLAY_NAME, descriptor.getDisplayName());
    DescriptorsJSON.setDescInfo(descriptor, item);
    PluginFormProperties pluginFormPropertyTypes = descriptor.getPluginFormPropertyTypes(subFormFilter);
    JSON vals = pluginFormPropertyTypes.getInstancePropsJson(this.instance);
    item.put("vals", vals);
    if (instance instanceof IdentityName) {
        item.put("identityName", ((IdentityName) instance).identityValue());
    }
    return item;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSON(com.alibaba.fastjson.JSON) PluginFormProperties(com.qlangtech.tis.extension.PluginFormProperties) IdentityName(com.qlangtech.tis.plugin.IdentityName)

Aggregations

IdentityName (com.qlangtech.tis.plugin.IdentityName)5 JSONObject (com.alibaba.fastjson.JSONObject)3 Context (com.alibaba.citrus.turbine.Context)2 JSON (com.alibaba.fastjson.JSON)2 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2 Pager (com.koubei.web.tag.pager.Pager)2 IPluginEnum (com.qlangtech.tis.IPluginEnum)2 TIS (com.qlangtech.tis.TIS)2 PluginFormProperties (com.qlangtech.tis.extension.PluginFormProperties)2 PropertyType (com.qlangtech.tis.extension.impl.PropertyType)2 SuFormProperties (com.qlangtech.tis.extension.impl.SuFormProperties)2 Option (com.qlangtech.tis.manage.common.Option)2 OfflineManager (com.qlangtech.tis.offline.module.manager.impl.OfflineManager)2 FormFieldType (com.qlangtech.tis.plugin.annotation.FormFieldType)2 BasicModule (com.qlangtech.tis.runtime.module.action.BasicModule)2 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 CollectionUtils (org.apache.commons.collections.CollectionUtils)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2