use of com.alibaba.citrus.turbine.Context in project tis by qlangtech.
the class DataxAction method doSaveWriterColsMeta.
/**
* @param context
*/
@Func(value = PermissionConstant.DATAX_MANAGE)
public void doSaveWriterColsMeta(Context context) {
String dataxName = this.getString(PARAM_KEY_DATAX_NAME);
DataxProcessor.DataXCreateProcessMeta processMeta = DataxProcessor.getDataXCreateProcessMeta(this, dataxName);
if ((processMeta.isReaderRDBMS())) {
throw new IllegalStateException("can not process the flow with:" + processMeta.toString());
}
List<ISelectedTab.ColMeta> writerCols = Lists.newArrayList();
IDataxProcessor.TableMap tableMapper = new IDataxProcessor.TableMap(new ISelectedTab() {
@Override
public List<ColMeta> getCols() {
return writerCols;
}
});
// tableMapper.setSourceCols(writerCols);
// //////////////////
final String keyColsMeta = "colsMeta";
IControlMsgHandler handler = new DelegateControl4JsonPostMsgHandler(this, this.parseJsonPost());
if (!Validator.validate(handler, context, //
Validator.fieldsValidator(//
"writerTargetTabName", new Validator.FieldValidators(Validator.require, Validator.db_col_name) {
@Override
public void setFieldVal(String val) {
tableMapper.setTo(val);
}
}, "writerFromTabName", new Validator.FieldValidators(Validator.require, Validator.db_col_name) {
@Override
public void setFieldVal(String val) {
tableMapper.setFrom(val);
}
}, //
keyColsMeta, new Validator.FieldValidators(Validator.require) {
@Override
public void setFieldVal(String val) {
}
}, new Validator.IFieldValidator() {
@Override
public boolean validate(IFieldErrorHandler msgHandler, Context context, String fieldKey, String fieldData) {
ISelectedTab.ColMeta colMeta = null;
JSONArray targetCols = JSON.parseArray(fieldData);
JSONObject targetCol = null;
int index;
String targetColName = null;
if (targetCols.size() < 1) {
msgHandler.addFieldError(context, fieldKey, "Writer目标表列不能为空");
return false;
}
Map<String, Integer> existCols = Maps.newHashMap();
boolean validateFaild = false;
Integer previousColIndex = null;
for (int i = 0; i < targetCols.size(); i++) {
targetCol = targetCols.getJSONObject(i);
index = targetCol.getInteger("index");
targetColName = targetCol.getString("name");
if (StringUtils.isNotBlank(targetColName) && (previousColIndex = existCols.put(targetColName, index)) != null) {
msgHandler.addFieldError(context, keyColsMeta + "[" + previousColIndex + "]", "内容不能与第" + index + "行重复");
msgHandler.addFieldError(context, keyColsMeta + "[" + index + "]", "内容不能与第" + previousColIndex + "行重复");
return false;
}
if (!Validator.require.validate(DataxAction.this, context, keyColsMeta + "[" + index + "]", targetColName)) {
validateFaild = true;
} else if (!Validator.db_col_name.validate(DataxAction.this, context, keyColsMeta + "[" + index + "]", targetColName)) {
validateFaild = true;
}
colMeta = new ISelectedTab.ColMeta();
colMeta.setName(targetColName);
DataType dataType = targetCol.getObject("type", DataType.class);
// colMeta.setType(ISelectedTab.DataXReaderColType.parse(targetCol.getString("type")));
colMeta.setType(dataType);
writerCols.add(colMeta);
}
return !validateFaild;
}
}))) {
return;
}
this.saveTableMapper(this, dataxName, Collections.singletonList(tableMapper));
}
use of com.alibaba.citrus.turbine.Context 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.alibaba.citrus.turbine.Context 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.alibaba.citrus.turbine.Context in project tis by qlangtech.
the class OfflineDatasourceAction method doGetDsRelevantReaderDesc.
@Func(value = PermissionConstant.PERMISSION_DATASOURCE_EDIT, sideEffect = false)
public void doGetDsRelevantReaderDesc(Context context) {
com.alibaba.fastjson.JSONObject form = this.parseJsonPost();
Integer dbId = form.getInteger("dbId");
if (dbId == null) {
throw new IllegalStateException("dbId can not be null");
}
com.qlangtech.tis.workflow.pojo.DatasourceDb db = this.offlineDAOFacade.getDatasourceDbDAO().selectByPrimaryKey(dbId);
// IPluginStore<DataSourceFactory> dbPlugin = TIS.getDataBasePluginStore(new PostedDSProp(db.getName(), DbScope.DETAILED));
// DataSourceFactory.BaseDataSourceFactoryDescriptor descriptor = (DataSourceFactory.BaseDataSourceFactoryDescriptor) dbPlugin.getPlugin().getDescriptor();
OfflineManager.DBDataXReaderDescName defaultDataXReaderDescName = offlineManager.getDBDataXReaderDescName(db.getName());
Map<String, Object> result = Maps.newHashMap();
if (!defaultDataXReaderDescName.readerDescName.isPresent()) {
// throw new IllegalStateException("datasource:" + db.getName() + " desc:" + descriptor.getDisplayName() + " has not relevant DataXReader defined");
// result.put(KEY_DATA_READER_SETTED + "NotSupport", descriptor.getId());
this.addErrorMessage(context, "插件:" + defaultDataXReaderDescName.dsDescriptor.getId() + " 不支持表导入");
return;
}
DataxReader dataxReader = OfflineManager.getDBDataxReader(this, db.getName());
if (dataxReader != null) {
result.put(KEY_DATA_READER_SETTED, true);
// this.setBizResult(context, result);
// return;
}
DescriptorExtensionList<DataxReader, Descriptor<DataxReader>> descriptorList = TIS.get().getDescriptorList(DataxReader.class);
Optional<DataxReader.BaseDataxReaderDescriptor> dataXReaderDesc = descriptorList.stream().filter((de) -> {
return defaultDataXReaderDescName.getReaderDescName().equals(de.getDisplayName());
}).map((d) -> (DataxReader.BaseDataxReaderDescriptor) d).findFirst();
if (!dataXReaderDesc.isPresent()) {
throw new IllegalStateException("DataXReaderDescName:" + defaultDataXReaderDescName.getReaderDescName() + " can not find relevant DataXReader Descriptor");
}
result.put("readerDesc", new DescriptorsJSON(dataXReaderDesc.get()).getDescriptorsJSON());
result.put("processMeta", DataxAction.getDataXBasicProcessMetaByReader(dataXReaderDesc.get()));
this.setBizResult(context, result);
}
use of com.alibaba.citrus.turbine.Context in project tis by qlangtech.
the class OfflineDatasourceAction method doGetErRule.
/**
* 取得ER关系规则
*
* @param context
* @throws Exception
*/
public void doGetErRule(Context context) throws Exception {
String topology = this.getString("topology");
// 强制同步,时间长了,toplolog上会新加一些数据表,导致ER规则和现有topology不同步,需要同步一下
boolean forceSync = this.getBoolean("sync");
if (StringUtils.isEmpty(topology)) {
throw new IllegalArgumentException("param 'topology' can not be null");
}
ERRules erRule = null;
if (!ERRules.ruleExist(topology)) {
// 还没有创建ER规则
erRule = new ERRules();
for (DependencyNode node : getDumpNodesFromTopology(topology)) {
erRule.addDumpNode(node);
}
} else {
erRule = ERRules.getErRule(topology).get();
final List<DependencyNode> oldErRules = erRule.getDumpNodes();
if (forceSync) {
List<DependencyNode> dumpNodes = getDumpNodesFromTopology(topology);
/**
* *************************************
* 需要添加的节点
* ***************************************
*/
List<DependencyNode> shallBeAdd = dumpNodes.stream().filter((n) -> !oldErRules.stream().filter((old) -> StringUtils.equals(n.getTabid(), old.getTabid())).findAny().isPresent()).collect(Collectors.toList());
/**
* *************************************
* 需要删除的节点
* ***************************************
*/
Iterator<DependencyNode> it = oldErRules.iterator();
while (it.hasNext()) {
DependencyNode old = it.next();
if (!dumpNodes.stream().filter((n) -> StringUtils.equals(n.getTabid(), old.getTabid())).findAny().isPresent()) {
it.remove();
}
}
oldErRules.addAll(shallBeAdd);
}
}
this.setBizResult(context, erRule);
}
Aggregations