Search in sources :

Example 1 with IPluginEnum

use of com.qlangtech.tis.IPluginEnum 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 2 with IPluginEnum

use of com.qlangtech.tis.IPluginEnum in project tis by qlangtech.

the class PluginAction method doGetDescriptor.

/**
 * @param context
 */
public void doGetDescriptor(Context context) {
    this.errorsPageShow(context);
    final String displayName = this.getString("name");
    if (StringUtils.isEmpty(displayName)) {
        throw new IllegalArgumentException("request param 'impl' can not be null");
    }
    IPluginEnum hetero = HeteroEnum.of(this.getString("hetero"));
    List<Descriptor<Describable>> descriptors = hetero.descriptors();
    for (Descriptor desc : descriptors) {
        if (StringUtils.equals(desc.getDisplayName(), displayName)) {
            this.setBizResult(context, new DescriptorsJSON(desc).getDescriptorsJSON());
            return;
        }
    }
    // throw new IllegalStateException("displayName:" + displayName + " relevant Descriptor can not be null");
    this.setBizResult(context, Collections.singletonMap("notFoundExtension", hetero.getExtensionPoint().getName()));
    this.addErrorMessage(context, "displayName:" + displayName + " relevant Descriptor can not be null");
}
Also used : IPluginEnum(com.qlangtech.tis.IPluginEnum)

Example 3 with IPluginEnum

use of com.qlangtech.tis.IPluginEnum in project tis by qlangtech.

the class PluginAction method doSubformDetailedClick.

/**
 * plugin form 的子表单的某条详细记录被点击
 *
 * @param context
 * @throws Exception
 */
public void doSubformDetailedClick(Context context) throws Exception {
    List<UploadPluginMeta> pluginsMeta = getPluginMeta();
    List<Describable> plugins = null;
    // Map<String, String> execContext = Maps.newHashMap();
    // execContext.put(SuFormProperties.SuFormGetterContext.FIELD_SUBFORM_ID
    // , this.getString(SuFormProperties.SuFormGetterContext.FIELD_SUBFORM_ID));
    IPluginEnum heteroEnum = null;
    HeteroList<?> hList = null;
    // com.alibaba.fastjson.JSONArray hlist = new com.alibaba.fastjson.JSONArray();
    for (UploadPluginMeta meta : pluginsMeta) {
        // meta.putExtraParams(IPropertyType.SubFormFilter.PLUGIN_META_SUBFORM_DETAIL_ID_VALUE
        // , this.getString(SuFormProperties.SuFormGetterContext.FIELD_SUBFORM_ID));
        heteroEnum = meta.getHeteroEnum();
        plugins = heteroEnum.getPlugins(this, meta);
        for (Describable plugin : plugins) {
            SuFormProperties.setSuFormGetterContext(plugin, meta, this.getString(SuFormProperties.SuFormGetterContext.FIELD_SUBFORM_ID));
            // SuFormProperties.SuFormGetterContext subFormContext = SuFormProperties.subFormGetterProcessThreadLocal.get();
            // subFormContext.plugin = plugin;
            // subFormContext.param = meta;
            hList = meta.getHeteroList(this);
            // hlist.add();
            // pluginDetail.put("plugins", hlist);
            this.setBizResult(context, hList.toJSON());
            return;
        // subFormFilter = meta.getSubFormFilter();
        // PluginFormProperties pluginFormPropertyTypes = plugin.getDescriptor().getPluginFormPropertyTypes(subFormFilter);
        // pluginFormPropertyTypes.accept(new DescriptorsJSON.SubFormFieldVisitor(subFormFilter) {
        // 
        // 
        // @Override
        // public Void visit(
        // //SuFormProperties.SuFormPropertiesBehaviorMeta behaviorMeta,
        // SuFormProperties props) {
        // SuFormProperties.SuFormPropertyGetterMeta fieldDataGetterMeta = null;
        // List<String> params = null;
        // Map<String, SuFormProperties.SuFormPropertyGetterMeta> onClickFillData = behaviorMeta.getOnClickFillData();
        // Objects.requireNonNull(onClickFillData, "onClickFillData can not be null");
        // Map<String, Object> fillFieldsData = Maps.newHashMap();
        // for (Map.Entry<String, SuFormProperties.SuFormPropertyGetterMeta> entry : onClickFillData.entrySet()) {
        // String fillField = entry.getKey();
        // 
        // fieldDataGetterMeta = entry.getValue();
        // Objects.requireNonNull(fieldDataGetterMeta, "fillField:" + fillField + " relevant behavier meta can not be null");
        // // String targetMethod = fieldDataGetterMeta.getString("method");
        // String targetMethod = fieldDataGetterMeta.getMethod();
        // //  params = fieldDataGetterMeta.getJSONArray("params");
        // params = fieldDataGetterMeta.getParams();
        // if (CollectionUtils.isEmpty(params)) {
        // throw new IllegalStateException("params can not be null");
        // }
        // 
        // Class<?>[] paramClass = new Class<?>[params.size()];
        // String[] paramsVals = new String[params.size()];
        // for (int index = 0; index < params.size(); index++) {
        // paramClass[index] = String.class;
        // paramsVals[index] = Objects.requireNonNull(execContext.get(params.get(index))
        // , "param:" + params.get(index) + " can not be null in context");
        // }
        // Method method = ReflectionUtils.findMethod(plugin.getClass(), targetMethod, paramClass);
        // Objects.requireNonNull(method, "target method '" + targetMethod + "' of " + plugin.getClass() + " can not be null");
        // fillFieldsData.put(fillField, ReflectionUtils.invokeMethod(method, plugin, paramsVals));
        // }
        // params 必须全为spring类型的
        // setBizResult(context, fillFieldsData);
        // return null;
        // }
        // });
        }
    }
    throw new IllegalStateException("have not set plugin meta");
}
Also used : IPluginEnum(com.qlangtech.tis.IPluginEnum)

Example 4 with IPluginEnum

use of com.qlangtech.tis.IPluginEnum in project tis by qlangtech.

the class UploadPluginMeta method getHeteroList.

public <T extends Describable<T>> HeteroList<T> getHeteroList(IPluginContext pluginContext) {
    IPluginEnum hEnum = getHeteroEnum();
    HeteroList<T> hList = new HeteroList<>(this);
    hList.setCaption(hEnum.getCaption());
    hList.setIdentityId(hEnum.getIdentity());
    hList.setExtensionPoint(hEnum.getExtensionPoint());
    List<T> items = hEnum.getPlugins(pluginContext, this);
    hList.setItems(items);
    List<Descriptor<T>> descriptors = hEnum.descriptors();
    if (StringUtils.isNotEmpty(this.getTargetPluginDesc())) {
        descriptors = descriptors.stream().filter((desc) -> this.getTargetPluginDesc().equals(desc.getDisplayName())).collect(Collectors.toList());
    }
    String targetDesc = this.getExtraParam(IPropertyType.SubFormFilter.PLUGIN_META_TARGET_DESCRIPTOR_NAME);
    boolean justGetItemRelevant = Boolean.parseBoolean(this.getExtraParam(KEY_JUST_GET_ITEM_RELEVANT));
    if (justGetItemRelevant) {
        Set<String> itemRelevantDescNames = items.stream().map((i) -> i.getDescriptor().getDisplayName()).collect(Collectors.toSet());
        descriptors = descriptors.stream().filter((d) -> itemRelevantDescNames.contains(d.getDisplayName())).collect(Collectors.toList());
    } else if (StringUtils.isNotEmpty(targetDesc)) {
        descriptors = descriptors.stream().filter((d) -> targetDesc.equals(d.getDisplayName())).collect(Collectors.toList());
    }
    hList.setDescriptors(descriptors);
    hList.setSelectable(hEnum.getSelectable());
    return hList;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) java.util(java.util) Lists(com.google.common.collect.Lists) Matcher(java.util.regex.Matcher) Descriptor(com.qlangtech.tis.extension.Descriptor) PostedDSProp(com.qlangtech.tis.plugin.ds.PostedDSProp) Pattern(java.util.regex.Pattern) IPluginEnum(com.qlangtech.tis.IPluginEnum) IPropertyType(com.qlangtech.tis.extension.IPropertyType) Collectors(java.util.stream.Collectors) Describable(com.qlangtech.tis.extension.Describable) Descriptor(com.qlangtech.tis.extension.Descriptor) IPluginEnum(com.qlangtech.tis.IPluginEnum)

Aggregations

IPluginEnum (com.qlangtech.tis.IPluginEnum)4 Lists (com.google.common.collect.Lists)1 Describable (com.qlangtech.tis.extension.Describable)1 Descriptor (com.qlangtech.tis.extension.Descriptor)1 IPropertyType (com.qlangtech.tis.extension.IPropertyType)1 IdentityName (com.qlangtech.tis.plugin.IdentityName)1 PostedDSProp (com.qlangtech.tis.plugin.ds.PostedDSProp)1 java.util (java.util)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang.StringUtils)1