use of com.qlangtech.tis.extension.PluginFormProperties 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.PluginFormProperties 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;
}
use of com.qlangtech.tis.extension.PluginFormProperties 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;
}
use of com.qlangtech.tis.extension.PluginFormProperties in project tis by qlangtech.
the class PluginItems method save.
public List<Describable> save(Context context) {
Objects.requireNonNull(this.pluginContext, "pluginContext can not be null");
if (items == null) {
throw new IllegalStateException("prop items can not be null");
}
Descriptor.ParseDescribable describable = null;
AttrValMap attrValMap = null;
List<Descriptor.ParseDescribable<?>> dlist = Lists.newArrayList();
List<Describable> describableList = Lists.newArrayList();
if (this.pluginMeta.isAppend()) {
IPluginStore pluginStore = heteroEnum.getPluginStore(this.pluginContext, this.pluginMeta);
if (pluginStore != null) {
List<Describable> plugins = pluginStore.getPlugins();
boolean firstSkip = false;
for (Describable p : plugins) {
if (!firstSkip) {
firstSkip = true;
Descriptor.ParseDescribable describablesWithMeta = PluginStore.getDescribablesWithMeta(pluginStore, p);
dlist.add(describablesWithMeta);
} else {
dlist.add(new Descriptor.ParseDescribable(p));
}
}
}
}
for (int i = 0; i < this.items.size(); i++) {
attrValMap = this.items.get(i);
/**
*====================================================
* 将客户端post数据包装
* ======================================================
*/
describable = attrValMap.createDescribable(pluginContext);
dlist.add(describable);
describableList.add((Describable) describable.instance);
}
IPluginStoreSave<?> store = null;
if (heteroEnum == HeteroEnum.APP_SOURCE) {
for (Descriptor.ParseDescribable<?> d : dlist) {
if (d.instance instanceof IdentityName) {
store = IAppSource.getPluginStore(pluginContext, ((IdentityName) d.instance).identityValue());
break;
}
}
Objects.requireNonNull(store, "plugin type:" + heteroEnum.getIdentity() + " can not find relevant Store");
} else if (this.pluginContext.isDataSourceAware()) {
store = new IPluginStoreSave<DataSourceFactory>() {
@Override
public boolean setPlugins(IPluginContext pluginContext, Optional<Context> context, List<Descriptor.ParseDescribable<DataSourceFactory>> dlist, boolean update) {
for (Descriptor.ParseDescribable<DataSourceFactory> plugin : dlist) {
PostedDSProp dbExtraProps = PostedDSProp.parse(pluginMeta);
if (DbScope.DETAILED == dbExtraProps.getDbType()) {
dbExtraProps.setDbname(plugin.instance.identityValue());
}
boolean success = TIS.getDataBasePluginStore(dbExtraProps).setPlugins(pluginContext, context, Collections.singletonList(plugin), dbExtraProps.isUpdate());
if (!success) {
return false;
}
}
return true;
}
};
} else if (heteroEnum == HeteroEnum.DATAX_WRITER || heteroEnum == HeteroEnum.DATAX_READER) {
// final String dataxName = pluginMeta.getExtraParam(DataxUtils.DATAX_NAME);
// if (StringUtils.isEmpty(dataxName)) {
// String saveDbName = pluginMeta.getExtraParam(DataxUtils.DATAX_DB_NAME);
// if (StringUtils.isNotBlank(saveDbName)) {
// store = DataxReader.getPluginStore(this.pluginContext, true, saveDbName);
// } else {
// throw new IllegalArgumentException("plugin extra param " + DataxUtils.DATAX_NAME + " can not be null");
// }
// } else {
// KeyedPluginStore<?> keyStore = (heteroEnum == HeteroEnum.DATAX_READER)
// ? DataxReader.getPluginStore(this.pluginContext, dataxName) : DataxWriter.getPluginStore(this.pluginContext, dataxName);
// store = keyStore;
// }
// if ((heteroEnum == HeteroEnum.DATAX_READER)) {
// for (Descriptor.ParseDescribable<?> dataXReader : dlist) {
// DataSourceMeta sourceMeta = (DataSourceMeta) dataXReader.instance;
// pluginContext.setBizResult(context, sourceMeta.getTablesInDB());
// }
// }
store = HeteroEnum.getDataXReaderAndWriterStore(this.pluginContext, this.heteroEnum == HeteroEnum.DATAX_READER, this.pluginMeta);
Optional<IPropertyType.SubFormFilter> subFormFilter = pluginMeta.getSubFormFilter();
if (subFormFilter.isPresent()) {
IPropertyType.SubFormFilter filter = subFormFilter.get();
Optional<Descriptor> firstDesc = heteroEnum.descriptors().stream().filter((des) -> filter.match((Descriptor) des)).map((des) -> (Descriptor) des).findFirst();
if (!firstDesc.isPresent()) {
throw new IllegalStateException("can not find relevant descriptor:" + filter.uploadPluginMeta.toString());
}
// Describable p = keyStore.getPlugin();
// Descriptor des = p.getDescriptor();
PluginFormProperties pluginProps = firstDesc.get().getPluginFormPropertyTypes(subFormFilter);
store = pluginProps.accept(new PluginFormProperties.IVisitor() {
@Override
public IPluginStoreSave<?> visit(SuFormProperties props) {
// 为了在更新插件时候不把plugin上的@SubForm标记的属性覆盖掉,需要先将老的plugin上的值覆盖到新http post过来的反序列化之后的plugin上
// IPluginContext pluginContext, String appname, SuFormProperties subfieldForm, Class<TT> clazz
Class<Describable> clazz = (Class<Describable>) heteroEnum.getExtensionPoint();
// DataxReader.SubFieldFormAppKey<Describable> key
// = new DataxReader.SubFieldFormAppKey<>(pluginContext, dataxName, props, clazz);
//
DataxReader.SubFieldFormAppKey<Describable> key = HeteroEnum.createDataXReaderAndWriterRelevant(pluginContext, pluginMeta, new HeteroEnum.DataXReaderAndWriterRelevantCreator<DataxReader.SubFieldFormAppKey<Describable>>() {
@Override
public DataxReader.SubFieldFormAppKey<Describable> dbRelevant(IPluginContext pluginContext, String saveDbName) {
return new DataxReader.SubFieldFormAppKey<>(pluginContext, true, saveDbName, props, clazz);
}
@Override
public DataxReader.SubFieldFormAppKey<Describable> appRelevant(IPluginContext pluginContext, String dataxName) {
return new DataxReader.SubFieldFormAppKey<>(pluginContext, false, dataxName, props, clazz);
}
});
return KeyedPluginStore.getPluginStore(key);
}
});
}
} else if (heteroEnum == HeteroEnum.PARAMS_CONFIG) {
store = new ParamsConfigPluginStore(this.pluginMeta);
} else if (heteroEnum == HeteroEnum.DATAX_WORKER) {
if (!this.pluginContext.isCollectionAware()) {
throw new IllegalStateException("must be collection aware");
}
store = DataXJobWorker.getJobWorkerStore(new TargetResName(this.pluginContext.getCollectionName()));
// } else if (this.pluginContext.isCollectionAware()) {
// store = TIS.getPluginStore(this.pluginContext.getCollectionName(), heteroEnum.getExtensionPoint());
} else {
if (heteroEnum.isAppNameAware()) {
if (!this.pluginContext.isCollectionAware()) {
throw new IllegalStateException(heteroEnum.getExtensionPoint().getName() + " must be collection aware");
}
store = TIS.getPluginStore(this.pluginContext.getCollectionName(), heteroEnum.getExtensionPoint());
} else {
store = TIS.getPluginStore(heteroEnum.getExtensionPoint());
}
// if (heteroEnum.isAppNameAware()) {
// throw new IllegalStateException(heteroEnum.getExtensionPoint().getName() + " must be app name aware");
// }
}
// dlist
if (!store.setPlugins(pluginContext, Optional.of(context), convert(dlist))) {
return Collections.emptyList();
}
observable.notifyObservers(new PluginItemsSaveEvent(this.pluginContext, this.heteroEnum, describableList));
return describableList;
}
use of com.qlangtech.tis.extension.PluginFormProperties in project tis by qlangtech.
the class TestSuFormProperties method testVisitSubForm.
public void testVisitSubForm() {
SubFieldContainPlugin plugin = new SubFieldContainPlugin();
String pluginName = "test_plugin";
// dataxName_" + dataXName
UploadPluginMeta pluginMeta = UploadPluginMeta.parse(pluginName + ":require," + DataxUtils.DATAX_NAME + "_" + dataXName);
IPropertyType.SubFormFilter subFormFilter = new IPropertyType.SubFormFilter(pluginMeta, SubFieldContainPlugin.PLUGIN_NAME, SubFieldContainPlugin.SUB_PROP_FIELD_NAME);
Descriptor<SubFieldContainPlugin> descriptor = plugin.getDescriptor();
assertNotNull("descriptor can not be null", descriptor);
PluginFormProperties pluginFormPropertyTypes = descriptor.getPluginFormPropertyTypes(Optional.of(subFormFilter));
assertNotNull("pluginFormPropertyTypes can not be null", pluginFormPropertyTypes);
// AtomicBoolean hasExecVisitSubForm = new AtomicBoolean(false);
boolean hasExecVisitSubForm = pluginFormPropertyTypes.accept(new DescriptorsJSON.SubFormFieldVisitor(Optional.of(subFormFilter)) {
@Override
public // SuFormProperties.SuFormPropertiesBehaviorMeta behaviorMeta,
Boolean visit(SuFormProperties props) {
// assertNotNull("behaviorMeta can not be null", behaviorMeta);
assertNotNull("prop can not be null", props);
// assertEquals("设置", behaviorMeta.getClickBtnLabel());
// Map<String, SuFormProperties.SuFormPropertyGetterMeta>
// onClickFillData = behaviorMeta.getOnClickFillData();
// assertEquals("onClickFillData.size() > 0", 2, onClickFillData.size());
// SuFormProperties.SuFormPropertyGetterMeta getterMeta = onClickFillData.get("cols");
// assertNotNull(getterMeta);
// assertEquals("getTableMetadata", getterMeta.getMethod());
// assertTrue("getParams equal"
// , CollectionUtils.isEqualCollection(Collections.singleton("id"), getterMeta.getParams()));
//
//
// getterMeta = onClickFillData.get("recordField");
// assertNotNull(getterMeta);
// assertEquals("getPrimaryKeys", getterMeta.getMethod());
// assertTrue("getParams equal"
// , CollectionUtils.isEqualCollection(Collections.singleton("id"), getterMeta.getParams()));
// ===============================================
Set<Map.Entry<String, PropertyType>> kvTuples = props.getKVTuples();
assertEquals(3, kvTuples.size());
assertTrue(CollectionUtils.isEqualCollection(Lists.newArrayList("name", "subProp1", "subProp2"), kvTuples.stream().map((kv) -> kv.getKey()).collect(Collectors.toList())));
Object subField = props.newSubDetailed();
assertTrue("subField must be type of " + SubFieldExtend.class.getSimpleName(), subField instanceof SubFieldExtend);
return true;
}
});
assertTrue("hasExecVisitSubForm must has execute", hasExecVisitSubForm);
}
Aggregations