use of com.qlangtech.tis.plugin.IdentityName in project tis by qlangtech.
the class Descriptor method getPluginFormPropertyTypes.
public PluginFormProperties getPluginFormPropertyTypes(Optional<IPropertyType.SubFormFilter> subFormFilter) {
IPropertyType.SubFormFilter filter = null;
if (subFormFilter.isPresent()) {
filter = subFormFilter.get();
if (filter.match(this)) {
SuFormProperties subPluginFormPropertyTypes = (SuFormProperties) getSubPluginFormPropertyTypes(filter.subFieldName);
try {
// 类似Hudi的Writer需要覆盖Reader的subFieldName的在Reader的表设置表单中需要设置Hudi相关的属性
// DataxWriter dataxWriter = DataxWriter.load(filter.uploadPluginMeta.getPluginContext(), dataXName);
Descriptor writerDescriptor = // dataxWriter.getClass();
IDataxProcessor.getWriterDescriptor(filter.uploadPluginMeta);
if (writerDescriptor instanceof DataxWriter.IRewriteSuFormProperties) {
subPluginFormPropertyTypes = Objects.requireNonNull(((DataxWriter.IRewriteSuFormProperties) writerDescriptor).overwriteSubPluginFormPropertyTypes(subPluginFormPropertyTypes), "result can not be null " + PluginFormProperties.class.getSimpleName());
}
// String overwriteSubField = IOUtils.loadResourceFromClasspath(
// writerClass, writerClass.getSimpleName() + "." + filter.subFieldName + ".json", false);
// if (overwriteSubField != null) {
// JSONObject subField = JSON.parseObject(overwriteSubField);
// Class<?> clazz = writerClass.getClassLoader().loadClass(subField.getString(SubForm.FIELD_DES_CLASS));
// return SuFormProperties.copy(filterFieldProp(buildPropertyTypes(this, clazz)), subPluginFormPropertyTypes);
// }
} catch (Exception e) {
throw new RuntimeException(e);
}
if (filter.subformDetailView) {
final String subformDetailId = filter.subformDetailId;
final SuFormProperties _subPluginFormPropertyTypes = subPluginFormPropertyTypes;
return new AdapterPluginFormProperties(subPluginFormPropertyTypes) {
@Override
public JSON getInstancePropsJson(Object instance) {
Collection<IdentityName> subFormPropVal = _subPluginFormPropertyTypes.getSubFormPropVal(instance);
for (IdentityName subProp : subFormPropVal) {
if (StringUtils.equals(subformDetailId, subProp.identityValue())) {
return (new RootFormProperties(_subPluginFormPropertyTypes.fieldsType)).getInstancePropsJson(subProp);
}
}
ISelectedTab subDetailed = _subPluginFormPropertyTypes.newSubDetailed();
_subPluginFormPropertyTypes.pkPropertyType.setVal(subDetailed, subformDetailId);
return (new RootFormProperties(_subPluginFormPropertyTypes.fieldsType)).getInstancePropsJson(subDetailed);
// throw new IllegalStateException("subformDetailId:" + subformDetailId + " has not find subForm instance");
}
};
} else {
return subPluginFormPropertyTypes;
}
}
}
return new RootFormProperties(filterFieldProp(getPropertyTypes()));
}
use of com.qlangtech.tis.plugin.IdentityName in project tis by qlangtech.
the class PluginAction method doSavePluginConfig.
/**
* 保存blugin配置
*
* @param context
*/
public void doSavePluginConfig(Context context) throws Exception {
if (this.getBoolean("errors_page_show")) {
this.errorsPageShow(context);
}
List<UploadPluginMeta> plugins = getPluginMeta();
JSONObject postData = this.parseJsonPost();
String serverForward = postData.getString("serverForward");
String[] forwardParams = null;
if (StringUtils.isNotEmpty(serverForward)) {
forwardParams = StringUtils.split(serverForward, ":");
if (forwardParams.length != 3) {
throw new IllegalArgumentException("illegal forward param:" + serverForward);
}
}
JSONArray pluginArray = Objects.requireNonNull(postData.getJSONArray("items"), "json prop items can not be null");
UploadPluginMeta pluginMeta = null;
// JSONObject itemObj = null;
boolean faild = false;
List<PluginItems> categoryPlugins = Lists.newArrayList();
// 是否进行业务逻辑校验?当正式提交表单时候不进行业务逻辑校验,用户可能先添加一个不存在的数据库配置
final boolean verify = this.getBoolean("verify");
PluginItemsParser pluginItemsParser = null;
for (int pluginIndex = 0; pluginIndex < plugins.size(); pluginIndex++) {
// items = Lists.newArrayList();
pluginMeta = plugins.get(pluginIndex);
// subFormFilter = pluginMeta.getSubFormFilter();
JSONArray itemsArray = pluginArray.getJSONArray(pluginIndex);
// hEnum = pluginMeta.getHeteroEnum();
pluginItemsParser = parsePluginItems(this, pluginMeta, context, pluginIndex, itemsArray, verify);
if (pluginItemsParser.faild) {
faild = true;
}
categoryPlugins.add(pluginItemsParser.pluginItems);
}
if (this.hasErrors(context) || verify) {
return;
}
if (faild) {
// 判断提交的plugin表单是否有错误?错误则退出
this.addErrorMessage(context, "提交表单内容有错误");
return;
}
List<Describable> describables = Lists.newArrayList();
for (PluginItems pi : categoryPlugins) {
describables.addAll(pi.save(context));
}
if (forwardParams != null) {
// getRundata().forwardTo(getCoredefine().namespace, "core_action", "create_incr_sync_channal");
getRundata().forwardTo(forwardParams[0], forwardParams[1], forwardParams[2]);
return;
}
addActionMessage(context, "配置保存成功");
// 成功保存的主键信息返回给客户端
if (context.get(IMessageHandler.ACTION_BIZ_RESULT) == null) {
this.setBizResult(context, describables.stream().filter((d) -> d instanceof IdentityName).map((d) -> ((IdentityName) d).identityValue()).collect(Collectors.toList()));
}
}
use of com.qlangtech.tis.plugin.IdentityName 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;
}
use of com.qlangtech.tis.plugin.IdentityName in project tis by qlangtech.
the class OfflineDatasourceAction method doGetDsTabsVals.
/**
* 批量设置用,初始化数据库表
*
* @param context
* @throws IOException
*/
public void doGetDsTabsVals(Context context) throws IOException {
com.alibaba.fastjson.JSONObject body = this.parseJsonPost();
com.alibaba.fastjson.JSONArray tabs = body.getJSONArray("tabs");
if (tabs == null) {
throw new IllegalArgumentException("initialize Tabs can not be null");
}
List<String> selectedTabs = tabs.stream().map((tab) -> (String) tab).collect(Collectors.toList());
String pluginName = body.getString("name");
boolean require = body.getBooleanValue("require");
String extraParam = body.getString("extraParam");
UploadPluginMeta pluginMeta = null;
List<UploadPluginMeta> pluginMetas = UploadPluginMeta.parse(new String[] { pluginName + ":" + (require ? "require" : StringUtils.EMPTY) + "," + extraParam });
for (UploadPluginMeta m : pluginMetas) {
pluginMeta = m;
}
Objects.requireNonNull(pluginMeta, "pluginMeta can not be null");
HeteroList<DataxReader> heteroList = pluginMeta.getHeteroList(this);
List<DataxReader> readers = heteroList.getItems();
Map<String, List<ColumnMetaData>> mapCols = null;
List<ISelectedTab> allNewTabs = Lists.newArrayList();
PluginFormProperties pluginFormPropertyTypes = null;
Map<String, Object> bizResult = Maps.newHashMap();
for (DataxReader reader : readers) {
mapCols = selectedTabs.stream().collect(Collectors.toMap((tab) -> tab, (tab) -> {
return reader.getTableMetadata(tab);
}));
if (MapUtils.isEmpty(mapCols)) {
throw new IllegalStateException("mapCols can not be empty");
}
pluginFormPropertyTypes = reader.getDescriptor().getPluginFormPropertyTypes(pluginMeta.getSubFormFilter());
for (Map.Entry<String, List<ColumnMetaData>> tab2cols : mapCols.entrySet()) {
SuFormProperties.setSuFormGetterContext(reader, pluginMeta, tab2cols.getKey());
allNewTabs.add(createNewSelectedTab(pluginFormPropertyTypes, tab2cols));
}
DescriptorsJSON desc2Json = new DescriptorsJSON(reader.getDescriptor());
bizResult.put("subformDescriptor", desc2Json.getDescriptorsJSON(pluginMeta.getSubFormFilter()));
break;
}
Objects.requireNonNull(pluginFormPropertyTypes, "pluginFormPropertyTypes can not be null");
if (allNewTabs.size() < 1) {
throw new IllegalStateException("allNewTabs size can not small than 1");
}
bizResult.put("tabVals", pluginFormPropertyTypes.accept(new PluginFormProperties.IVisitor() {
@Override
public com.alibaba.fastjson.JSONObject visit(SuFormProperties props) {
return props.createSubFormVals(allNewTabs.stream().map((t) -> (IdentityName) t).collect(Collectors.toList()));
}
}));
this.setBizResult(context, bizResult);
}
use of com.qlangtech.tis.plugin.IdentityName 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;
}
Aggregations