Search in sources :

Example 1 with Describable

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

use of com.qlangtech.tis.extension.Describable in project plugins by qlangtech.

the class SelectedTab method getContextTableCols.

public static List<Option> getContextTableCols(Function<List<ColumnMetaData>, Stream<ColumnMetaData>> func) {
    SuFormProperties.SuFormGetterContext context = SuFormProperties.subFormGetterProcessThreadLocal.get();
    if (context == null || context.plugin == null) {
        return Collections.emptyList();
    }
    Describable plugin = Objects.requireNonNull(context.plugin, "context.plugin can not be null");
    if (!(plugin instanceof DataSourceMeta)) {
        throw new IllegalStateException("plugin must be type of " + DataSourceMeta.class.getName() + ", now type of " + plugin.getClass().getName());
    }
    DataSourceMeta dsMeta = (DataSourceMeta) plugin;
    List<ColumnMetaData> cols = context.getContextAttr(KEY_TABLE_COLS, (key) -> dsMeta.getTableMetadata(context.getSubFormIdentityField()));
    return func.apply(cols).map((c) -> c).collect(Collectors.toList());
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) DataSourceMeta(com.qlangtech.tis.plugin.ds.DataSourceMeta) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) LoggerFactory(org.slf4j.LoggerFactory) Option(com.qlangtech.tis.manage.common.Option) FormField(com.qlangtech.tis.plugin.annotation.FormField) ColumnMetaData(com.qlangtech.tis.plugin.ds.ColumnMetaData) Function(java.util.function.Function) Context(com.alibaba.citrus.turbine.Context) Lists(com.google.common.collect.Lists) CollectionUtils(org.apache.commons.collections.CollectionUtils) FormFieldType(com.qlangtech.tis.plugin.annotation.FormFieldType) Validator(com.qlangtech.tis.plugin.annotation.Validator) TISExtension(com.qlangtech.tis.extension.TISExtension) Logger(org.slf4j.Logger) Descriptor(com.qlangtech.tis.extension.Descriptor) IdentityName(com.qlangtech.tis.plugin.IdentityName) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) DataxReader(com.qlangtech.tis.datax.impl.DataxReader) Stream(java.util.stream.Stream) IControlMsgHandler(com.qlangtech.tis.runtime.module.misc.IControlMsgHandler) Optional(java.util.Optional) SuFormProperties(com.qlangtech.tis.extension.impl.SuFormProperties) Collections(java.util.Collections) Describable(com.qlangtech.tis.extension.Describable) Describable(com.qlangtech.tis.extension.Describable) SuFormProperties(com.qlangtech.tis.extension.impl.SuFormProperties) ColumnMetaData(com.qlangtech.tis.plugin.ds.ColumnMetaData) DataSourceMeta(com.qlangtech.tis.plugin.ds.DataSourceMeta)

Example 3 with Describable

use of com.qlangtech.tis.extension.Describable in project tis by qlangtech.

the class TaskStatusServlet method service.

protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    String extendPoint = null;
    try {
        if (StringUtils.isNotEmpty(extendPoint = req.getParameter(DescriptorsJSON.KEY_EXTEND_POINT))) {
            IPluginStore<Describable> pluginStore = TIS.getPluginStore((Class<Describable>) Class.forName(extendPoint));
            pluginStore.cleanPlugins();
            logger.info("key of '{}' pluginStore has been clean", extendPoint);
            return;
        }
    } catch (ClassNotFoundException e) {
        throw new ServletException("clean plugin store cache faild ", e);
    }
    if (Boolean.parseBoolean(req.getParameter(TIS.KEY_ACTION_CLEAN_TIS))) {
        TIS.clean();
        logger.info(" clean TIS cache", extendPoint);
        return;
    }
    int taskid = Integer.parseInt(req.getParameter(IParamContext.KEY_TASK_ID));
    // 是否要获取全部的日志信息,比如dump已經完成了,那麼只需要獲取dump之後的日志信息
    // boolean all = Boolean.parseBoolean(req.getParameter("all"));
    PhaseStatusCollection statusSet = TrackableExecuteInterceptor.getTaskPhaseReference(taskid);
    JSONObject result = new JSONObject();
    boolean success = false;
    if (statusSet != null) {
        result.put("status", statusSet);
        success = true;
    }
    result.put("success", success);
    IOUtils.write(JSON.toJSONString(result, true), res.getWriter());
}
Also used : ServletException(javax.servlet.ServletException) PhaseStatusCollection(com.qlangtech.tis.fullbuild.phasestatus.PhaseStatusCollection) JSONObject(com.alibaba.fastjson.JSONObject) Describable(com.qlangtech.tis.extension.Describable)

Example 4 with Describable

use of com.qlangtech.tis.extension.Describable 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)

Example 5 with Describable

use of com.qlangtech.tis.extension.Describable in project tis by qlangtech.

the class IdentityName method identityValue.

// /**
// * 相同类型的插件不能重名
// *
// * @return
// */
// String getName();
/**
 * 取得唯一ID
 *
 * @return
 */
default String identityValue() {
    Describable plugin = (Describable) this;
    Descriptor des = plugin.getDescriptor();
    Objects.requireNonNull(des, " Descriptor of Describable instance of " + plugin.getClass().getName());
    return des.getIdentityValue(plugin);
}
Also used : Describable(com.qlangtech.tis.extension.Describable) Descriptor(com.qlangtech.tis.extension.Descriptor)

Aggregations

Describable (com.qlangtech.tis.extension.Describable)7 Descriptor (com.qlangtech.tis.extension.Descriptor)6 Lists (com.google.common.collect.Lists)4 JSONObject (com.alibaba.fastjson.JSONObject)3 IPropertyType (com.qlangtech.tis.extension.IPropertyType)3 SuFormProperties (com.qlangtech.tis.extension.impl.SuFormProperties)3 java.util (java.util)3 Collectors (java.util.stream.Collectors)3 StringUtils (org.apache.commons.lang.StringUtils)3 Context (com.alibaba.citrus.turbine.Context)2 JSONArray (com.alibaba.fastjson.JSONArray)2 IPluginEnum (com.qlangtech.tis.IPluginEnum)2 TIS (com.qlangtech.tis.TIS)2 DataxReader (com.qlangtech.tis.datax.impl.DataxReader)2 PluginFormProperties (com.qlangtech.tis.extension.PluginFormProperties)2 PropertyType (com.qlangtech.tis.extension.impl.PropertyType)2 Option (com.qlangtech.tis.manage.common.Option)2 IdentityName (com.qlangtech.tis.plugin.IdentityName)2 FormFieldType (com.qlangtech.tis.plugin.annotation.FormFieldType)2 PostedDSProp (com.qlangtech.tis.plugin.ds.PostedDSProp)2