Search in sources :

Example 1 with PropertyType

use of com.qlangtech.tis.extension.impl.PropertyType in project plugins by qlangtech.

the class TestPlugin method testReceiceRequestFromClient.

public void testReceiceRequestFromClient() throws Exception {
    com.alibaba.fastjson.JSONArray jsonArray = null;
    com.alibaba.fastjson.JSONObject jsonObject = null;
    com.alibaba.fastjson.JSONObject valJ = null;
    String impl = null;
    PropertyType attrDesc = null;
    Descriptor descriptor = null;
    JSONArray vals = null;
    String attr = null;
    String attrVal = null;
    TIS tis = TIS.get();
    // IncrComponent incrComponent = tis.loadIncrComponent(collection);
    // incrComponent.setMqListenerFactory();
    Describable describable = null;
    try (InputStream input = TestPlugin.class.getResourceAsStream("RocketMQListenerFactory.json")) {
        assertNotNull(input);
        jsonArray = JSONArray.parseArray(IOUtils.toString(input, TisUTF8.getName()));
        for (int i = 0; i < jsonArray.size(); i++) {
            // 创建一个item
            jsonObject = jsonArray.getJSONObject(i);
            describable = (Describable) parseDescribable(jsonObject).instance;
        }
    }
    assertNotNull(describable);
    RocketMQListenerFactory mqListenerFactory = (RocketMQListenerFactory) describable;
    assertEquals(MQ_TOPIC, mqListenerFactory.getMqTopic());
    assertEquals(NamesrvAddr, mqListenerFactory.getNamesrvAddr());
    assertEquals(consumeId, mqListenerFactory.consumeName);
    assertNotNull(mqListenerFactory.getDeserialize());
}
Also used : Describable(com.qlangtech.tis.extension.Describable) InputStream(java.io.InputStream) JSONArray(com.alibaba.fastjson.JSONArray) PropertyType(com.qlangtech.tis.extension.impl.PropertyType) JSONArray(com.alibaba.fastjson.JSONArray) Descriptor(com.qlangtech.tis.extension.Descriptor) JSONObject(com.alibaba.fastjson.JSONObject) RocketMQListenerFactory(com.qlangtech.async.message.client.consumer.RocketMQListenerFactory) TIS(com.qlangtech.tis.TIS)

Example 2 with PropertyType

use of com.qlangtech.tis.extension.impl.PropertyType 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 PropertyType

use of com.qlangtech.tis.extension.impl.PropertyType in project plugins by qlangtech.

the class TestPlugin method parseDescribable.

private Descriptor.ParseDescribable parseDescribable(com.alibaba.fastjson.JSONObject jsonObject) {
    String impl;
    JSONArray vals;
    Descriptor descriptor;
    String attr;
    PropertyType attrDesc;
    com.alibaba.fastjson.JSONObject valJ;
    String attrVal;
    impl = jsonObject.getString("impl");
    vals = jsonObject.getJSONArray("vals");
    descriptor = TIS.get().getDescriptor(impl);
    assertNotNull("impl:" + impl, descriptor);
    Descriptor.ParseDescribable describable = descriptor.newInstance(null, Descriptor.parseAttrValMap(jsonObject.getJSONArray("vals")), Optional.empty());
    return describable;
}
Also used : JSONArray(com.alibaba.fastjson.JSONArray) Descriptor(com.qlangtech.tis.extension.Descriptor) JSONObject(com.alibaba.fastjson.JSONObject) PropertyType(com.qlangtech.tis.extension.impl.PropertyType)

Example 4 with PropertyType

use of com.qlangtech.tis.extension.impl.PropertyType in project tis by qlangtech.

the class OfflineDatasourceAction method createNewSelectedTab.

/**
 * 通过表名和列创建新tab实例,如果SelectedTab对象中有其他字段但是没有设置默认值,创建过程中就会出错
 *
 * @param pluginFormPropertyTypes
 * @param tab2cols
 * @return
 */
private ISelectedTab createNewSelectedTab(PluginFormProperties pluginFormPropertyTypes, Map.Entry<String, List<ColumnMetaData>> tab2cols) {
    return pluginFormPropertyTypes.accept(new PluginFormProperties.IVisitor() {

        @Override
        public ISelectedTab visit(SuFormProperties props) {
            // try {
            // } catch (Exception e) {
            // throw new RuntimeException("create subform,table:" + tab2cols.getKey()
            // + ",cols size:" + tab2cols.getValue().size(), e);
            // }
            ISelectedTab subForm = props.newSubDetailed();
            PropertyType pp = null;
            ppDftValGetter: for (Map.Entry<String, PropertyType> pentry : props.getKVTuples()) {
                pp = pentry.getValue();
                if (pp.isIdentity()) {
                    pp.setVal(subForm, tab2cols.getKey());
                    continue;
                }
                if (pp.formField.type() == FormFieldType.MULTI_SELECTABLE) {
                    pp.setVal(subForm, tab2cols.getValue().stream().map((c) -> c.getName()).collect(Collectors.toList()));
                    continue ppDftValGetter;
                }
                if (pp.isInputRequired()) {
                    if (StringUtils.isNotEmpty(pp.dftVal())) {
                        if (pp.isDescribable()) {
                            List<? extends Descriptor> descriptors = pp.getApplicableDescriptors();
                            for (Descriptor desc : descriptors) {
                                if (StringUtils.equals(pp.dftVal(), desc.getDisplayName())) {
                                    // desc.getPluginFormPropertyTypes();
                                    pp.setVal(subForm, desc.newInstance(null, Collections.emptyMap(), Optional.empty()).instance);
                                    continue ppDftValGetter;
                                }
                            }
                        } else {
                            pp.setVal(subForm, pp.dftVal());
                            continue ppDftValGetter;
                        }
                    } else {
                        // pp.getEnumConstants()
                        FormFieldType fieldType = pp.formField.type();
                        if (fieldType == FormFieldType.SELECTABLE || fieldType == FormFieldType.ENUM) {
                            Object enumPp = pp.getExtraProps().get(Descriptor.KEY_ENUM_PROP);
                            com.alibaba.fastjson.JSONArray enums = null;
                            if (enumPp instanceof com.alibaba.fastjson.JSONArray) {
                                enums = (com.alibaba.fastjson.JSONArray) enumPp;
                            } else if (enumPp instanceof JsonUtil.UnCacheString) {
                                enums = ((JsonUtil.UnCacheString<com.alibaba.fastjson.JSONArray>) enumPp).getValue();
                            } else {
                                throw new IllegalStateException("unsupport type:" + pp.getClass().getName());
                            }
                            for (int i = 0; i < enums.size(); i++) {
                                com.alibaba.fastjson.JSONObject opt = enums.getJSONObject(i);
                                pp.setVal(subForm, opt.get(Option.KEY_VALUE));
                                continue ppDftValGetter;
                            }
                        }
                    }
                    throw new IllegalStateException("have not prepare for table:" + tab2cols.getKey() + " creating,prop name:'" + pentry.getKey() + "',subform class:" + subForm.getClass().getName());
                }
            }
            return subForm;
        }
    });
}
Also used : FormFieldType(com.qlangtech.tis.plugin.annotation.FormFieldType) JSONArray(org.json.JSONArray) PropertyType(com.qlangtech.tis.extension.impl.PropertyType) PluginFormProperties(com.qlangtech.tis.extension.PluginFormProperties) JsonUtil(com.qlangtech.tis.trigger.util.JsonUtil) Descriptor(com.qlangtech.tis.extension.Descriptor) JSONObject(org.json.JSONObject) SuFormProperties(com.qlangtech.tis.extension.impl.SuFormProperties)

Example 5 with PropertyType

use of com.qlangtech.tis.extension.impl.PropertyType in project tis by qlangtech.

the class DescriptorsJSON method getDescriptorsJSON.

public JSONObject getDescriptorsJSON(Optional<IPropertyType.SubFormFilter> subFormFilter) {
    JSONArray attrs;
    String key;
    PropertyType val;
    JSONObject extraProps = null;
    // FormField fieldAnnot;
    JSONObject attrVal;
    JSONObject descriptors = new JSONObject();
    Map<String, Object> extractProps;
    // IPropertyType.SubFormFilter subFilter = null;
    PluginFormProperties pluginFormPropertyTypes;
    for (Descriptor<T> d : this.descriptors) {
        pluginFormPropertyTypes = d.getPluginFormPropertyTypes(subFormFilter);
        JSONObject des = new JSONObject();
        pluginFormPropertyTypes.accept(new SubFormFieldVisitor(subFormFilter) {

            @Override
            public Void visit(SuFormProperties props) {
                JSONObject subForm = new JSONObject();
                subForm.put("fieldName", props.getSubFormFieldName());
                if (subFormFilter.isPresent()) {
                    IPropertyType.SubFormFilter filter = subFormFilter.get();
                    if (!filter.subformDetailView) {
                        des.put("subForm", true);
                        subForm.put("idList", props.getSubFormIdListGetter().build(filter));
                    }
                }
                des.put("subFormMeta", subForm);
                return null;
            }
        });
        des.put(KEY_EXTEND_POINT, d.getT().getName());
        this.setDescInfo(d, des);
        des.put("veriflable", d.overWriteValidateMethod);
        if (IdentityName.class.isAssignableFrom(d.clazz)) {
            des.put("pkField", d.getIdentityField().displayName);
        }
        extractProps = d.getExtractProps();
        if (!extractProps.isEmpty()) {
            des.put("extractProps", extractProps);
        }
        attrs = new JSONArray();
        ArrayList<Map.Entry<String, PropertyType>> entries = Lists.newArrayList(pluginFormPropertyTypes.getKVTuples());
        entries.sort(((o1, o2) -> o1.getValue().ordinal() - o2.getValue().ordinal()));
        for (Map.Entry<String, PropertyType> pp : entries) {
            key = pp.getKey();
            val = pp.getValue();
            // fieldAnnot = val.getFormField();
            attrVal = new JSONObject();
            attrVal.put("key", key);
            // 是否是主键
            attrVal.put("pk", val.isIdentity());
            attrVal.put("describable", val.isDescribable());
            attrVal.put("type", val.typeIdentity());
            attrVal.put("required", val.isInputRequired());
            attrVal.put("ord", val.ordinal());
            extraProps = val.getExtraProps();
            if (extraProps != null) {
                // 额外属性
                attrVal.put("eprops", extraProps);
            }
            if (val.typeIdentity() == FormFieldType.SELECTABLE.getIdentity()) {
                attrVal.put("options", getSelectOptions(d, val, key));
            }
            if (val.isDescribable()) {
                DescriptorsJSON des2Json = new DescriptorsJSON(val.getApplicableDescriptors());
                attrVal.put("descriptors", des2Json.getDescriptorsJSON());
            }
            // attrs.put(attrVal);
            attrs.add(attrVal);
        }
        // 对象拥有的属性
        des.put("attrs", attrs);
        // processor.process(attrs.keySet(), d);
        descriptors.put(d.getId(), des);
    }
    return descriptors;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) java.util(java.util) Descriptor(com.qlangtech.tis.extension.Descriptor) IdentityName(com.qlangtech.tis.plugin.IdentityName) JSONArray(com.alibaba.fastjson.JSONArray) Config(com.qlangtech.tis.manage.common.Config) Lists(com.google.common.collect.Lists) PropertyType(com.qlangtech.tis.extension.impl.PropertyType) JSONObject(com.alibaba.fastjson.JSONObject) IPropertyType(com.qlangtech.tis.extension.IPropertyType) SuFormProperties(com.qlangtech.tis.extension.impl.SuFormProperties) Describable(com.qlangtech.tis.extension.Describable) PluginFormProperties(com.qlangtech.tis.extension.PluginFormProperties) FormFieldType(com.qlangtech.tis.plugin.annotation.FormFieldType) JSONArray(com.alibaba.fastjson.JSONArray) PropertyType(com.qlangtech.tis.extension.impl.PropertyType) IPropertyType(com.qlangtech.tis.extension.IPropertyType) PluginFormProperties(com.qlangtech.tis.extension.PluginFormProperties) JSONObject(com.alibaba.fastjson.JSONObject) JSONObject(com.alibaba.fastjson.JSONObject) SuFormProperties(com.qlangtech.tis.extension.impl.SuFormProperties)

Aggregations

PropertyType (com.qlangtech.tis.extension.impl.PropertyType)7 JSONObject (com.alibaba.fastjson.JSONObject)4 Descriptor (com.qlangtech.tis.extension.Descriptor)4 PluginFormProperties (com.qlangtech.tis.extension.PluginFormProperties)4 JSONArray (com.alibaba.fastjson.JSONArray)3 IPropertyType (com.qlangtech.tis.extension.IPropertyType)3 SuFormProperties (com.qlangtech.tis.extension.impl.SuFormProperties)3 RocketMQListenerFactory (com.qlangtech.async.message.client.consumer.RocketMQListenerFactory)2 Describable (com.qlangtech.tis.extension.Describable)2 FormFieldType (com.qlangtech.tis.plugin.annotation.FormFieldType)2 Lists (com.google.common.collect.Lists)1 TIS (com.qlangtech.tis.TIS)1 MQListenerFactory (com.qlangtech.tis.async.message.client.consumer.impl.MQListenerFactory)1 DataxReader (com.qlangtech.tis.datax.impl.DataxReader)1 RootFormProperties (com.qlangtech.tis.extension.impl.RootFormProperties)1 Config (com.qlangtech.tis.manage.common.Config)1 IdentityName (com.qlangtech.tis.plugin.IdentityName)1 ISelectedTab (com.qlangtech.tis.plugin.ds.ISelectedTab)1 JsonUtil (com.qlangtech.tis.trigger.util.JsonUtil)1 HeteroList (com.qlangtech.tis.util.HeteroList)1