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());
}
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("==============================");
}
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;
}
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;
}
});
}
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;
}
Aggregations