Skip to content

Commit

Permalink
add transformer for TIS,and upgrade fastjson version 2.0.51
Browse files Browse the repository at this point in the history
  • Loading branch information
baisui1981 committed Jun 12, 2024
1 parent 4eabfaf commit 026c2a0
Show file tree
Hide file tree
Showing 15 changed files with 121 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.qlangtech.tis.datax.IGroupChildTaskIterator;
import com.qlangtech.tis.datax.impl.DataxReader;
import com.qlangtech.tis.extension.IPropertyType;
import com.qlangtech.tis.extension.SubFormFilter;
import com.qlangtech.tis.lang.TisException;
import com.qlangtech.tis.plugin.KeyedPluginStore;
import com.qlangtech.tis.plugin.annotation.FormField;
Expand Down Expand Up @@ -239,7 +240,7 @@ protected boolean validateAll(IControlMsgHandler msgHandler, Context context, Po
}

@Override
public boolean validate(IFieldErrorHandler msgHandler, Optional<IPropertyType.SubFormFilter> subFormFilter,
public boolean validate(IFieldErrorHandler msgHandler, Optional<SubFormFilter> subFormFilter,
Context context, String fieldName, List<FormFieldType.SelectedItem> items) {

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static List<SelectedTab> createSelectedTabs(int count) {
}

public static <T extends SelectedTab> List<T> createSelectedTabs(int count, Class<T> clazz,
Optional<CMeta.ElementCreatorFactory> elementCreator, Consumer<T> postProcess) {
Optional<ElementCreatorFactory<CMeta>> elementCreator, Consumer<T> postProcess) {


try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package com.qlangtech.tis.plugin.datax;

import com.qlangtech.tis.datax.DataXCfgFile;
import com.qlangtech.tis.datax.IDataxReader;
import com.qlangtech.tis.datax.impl.DataXCfgGenerator;
import com.qlangtech.tis.manage.common.CenterResource;
Expand Down Expand Up @@ -68,9 +69,9 @@ public void testGenerateDataXCfgs() throws Exception {

DataXCfgGenerator.GenerateCfgs generateCfgs = gen.startGenerateCfg(dataxCfgDir);

List<DataXCfgGenerator.DataXCfgFile> cfgFiles = generateCfgs.getDataXCfgFiles();
List<DataXCfgFile> cfgFiles = generateCfgs.getDataXCfgFiles();
Assert.assertEquals(2, cfgFiles.size());
for (DataXCfgGenerator.DataXCfgFile f : cfgFiles) {
for (DataXCfgFile f : cfgFiles) {
File target = f.getFile();
Assert.assertTrue(target.getAbsolutePath(), target.exists());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.qlangtech.tis.datax.impl.DataxReader;
import com.qlangtech.tis.extension.Descriptor;
import com.qlangtech.tis.extension.IPropertyType;
import com.qlangtech.tis.extension.SubFormFilter;
import com.qlangtech.tis.fs.IPath;
import com.qlangtech.tis.manage.common.TisUTF8;
import com.qlangtech.tis.plugin.datax.common.PluginFieldValidators;
Expand Down Expand Up @@ -208,7 +209,7 @@ public FileFormat getFileFormat(Optional<String> entityName) {
public static final Pattern FTP_FILE_PATTERN
= Pattern.compile(".+?([^/]+)" + IOUtils.DIR_SEPARATOR + StringUtils.replace(FtpHelper.KEY_META_FILE, ".", "\\."));

public static List<String> getDFSFiles(IPropertyType.SubFormFilter filter) {
public static List<String> getDFSFiles(SubFormFilter filter) {
AbstractDFSReader reader = DataxReader.getDataxReader(filter);
return getFTPFiles(reader).stream().map((meta) -> meta.entityName).collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.qlangtech.tis.extension.Descriptor;
import com.qlangtech.tis.extension.IPropertyType;
import com.qlangtech.tis.extension.PluginFormProperties;
import com.qlangtech.tis.extension.SubFormFilter;
import com.qlangtech.tis.extension.util.OverwriteProps;
import com.qlangtech.tis.manage.common.Option;
import com.qlangtech.tis.plugin.annotation.FormField;
Expand Down Expand Up @@ -195,7 +196,7 @@ public BasicHudiKeyGeneratorDescriptor() {
}

@Override
public final PluginFormProperties getPluginFormPropertyTypes(Optional<IPropertyType.SubFormFilter> subFormFilter) {
public final PluginFormProperties getPluginFormPropertyTypes(Optional<SubFormFilter> subFormFilter) {
return super.getPluginFormPropertyTypes(Optional.empty());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.qlangtech.tis.extension.Descriptor;
import com.qlangtech.tis.extension.IPropertyType;
import com.qlangtech.tis.extension.PluginFormProperties;
import com.qlangtech.tis.extension.SubFormFilter;
import com.qlangtech.tis.plugin.datax.CreateTableSqlBuilder;
import com.qlangtech.tis.plugin.datax.hudi.IDataXHudiWriter;
import com.qlangtech.tis.runtime.module.misc.IControlMsgHandler;
Expand Down Expand Up @@ -115,7 +116,7 @@ public BaseDescriptor() {
}

@Override
public final PluginFormProperties getPluginFormPropertyTypes(Optional<IPropertyType.SubFormFilter> subFormFilter) {
public final PluginFormProperties getPluginFormPropertyTypes(Optional<SubFormFilter> subFormFilter) {
return super.getPluginFormPropertyTypes(Optional.empty());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.qlangtech.tis.extension.Descriptor;
import com.qlangtech.tis.extension.IPropertyType;
import com.qlangtech.tis.extension.PluginFormProperties;
import com.qlangtech.tis.extension.SubFormFilter;
import com.qlangtech.tis.extension.TISExtension;
import com.qlangtech.tis.manage.common.Option;
import com.qlangtech.tis.plugin.datax.CreateTableSqlBuilder;
Expand Down Expand Up @@ -82,7 +83,7 @@ public DefaultDescriptor() {
}

@Override
public PluginFormProperties getPluginFormPropertyTypes(Optional<IPropertyType.SubFormFilter> subFormFilter) {
public PluginFormProperties getPluginFormPropertyTypes(Optional<SubFormFilter> subFormFilter) {
return super.getPluginFormPropertyTypes(Optional.empty());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.alibaba.fastjson.JSONObject;
import com.qlangtech.tis.extension.Descriptor;
import com.qlangtech.tis.extension.IPropertyType;
import com.qlangtech.tis.extension.SubFormFilter;
import com.qlangtech.tis.extension.impl.IOUtils;
import com.qlangtech.tis.manage.common.TisUTF8;
import com.qlangtech.tis.runtime.module.misc.IControlMsgHandler;
Expand Down Expand Up @@ -86,7 +87,7 @@ public void testValidateForm() {
UploadPluginMeta pmeta = UploadPluginMeta.parse(
"dataxReader:require,targetDescriptorName_MySQL,targetDescriptorImpl_DataxMySQLReader,subFormFieldName_selectedTabs,dataxName_hudi");

Optional<IPropertyType.SubFormFilter> subFormFilter = pmeta.getSubFormFilter();
Optional<SubFormFilter> subFormFilter = pmeta.getSubFormFilter();
Assert.assertTrue(subFormFilter.isPresent());

EasyMock.replay(fieldErrorHandler, pluginContext, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.qlangtech.tis.annotation.Public;
import com.qlangtech.tis.extension.Descriptor;
import com.qlangtech.tis.extension.IPropertyType;
import com.qlangtech.tis.extension.SubFormFilter;
import com.qlangtech.tis.extension.TISExtension;
import com.qlangtech.tis.extension.impl.BaseSubFormProperties;
import com.qlangtech.tis.extension.impl.IOUtils;
Expand Down Expand Up @@ -256,9 +257,9 @@ public DefaultDescriptor() {

@Override
public SelectedTabExtend getCompanionPlugin(UploadPluginMeta pluginMeta) {
String tabName = pluginMeta.getExtraParam(IPropertyType.SubFormFilter.PLUGIN_META_SUBFORM_DETAIL_ID_VALUE);
String tabName = pluginMeta.getExtraParam(SubFormFilter.PLUGIN_META_SUBFORM_DETAIL_ID_VALUE);
if (StringUtils.isEmpty(tabName)) {
throw new IllegalArgumentException("param:" + IPropertyType.SubFormFilter.PLUGIN_META_SUBFORM_DETAIL_ID_VALUE + " is not exsit in pluginMeta");
throw new IllegalArgumentException("param:" + SubFormFilter.PLUGIN_META_SUBFORM_DETAIL_ID_VALUE + " is not exsit in pluginMeta");
}
return SelectedTabExtend.getBatchPluginStore(pluginMeta.getPluginContext(),
pluginMeta.getDataXName(true)).find(tabName, false);
Expand Down Expand Up @@ -289,7 +290,7 @@ public boolean validateInspectRowCount(IFieldErrorHandler msgHandler, Context co

@Override
public boolean validateSubFormItems(IControlMsgHandler msgHandler, Context context,
BaseSubFormProperties props, IPropertyType.SubFormFilter subFormFilter,
BaseSubFormProperties props, SubFormFilter subFormFilter,
AttrVals formData) {
// 校验一次提交的全部selectForm
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
package com.qlangtech.tis.plugin.datax.mongo;

import com.alibaba.citrus.turbine.Context;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.qlangtech.tis.extension.IPropertyType;
import com.qlangtech.tis.plugin.annotation.Validator;
import com.qlangtech.tis.plugin.datax.SelectedTab;
import com.qlangtech.tis.plugin.ds.CMeta;
import com.qlangtech.tis.plugin.ds.CMeta.ParsePostMCols;
import com.qlangtech.tis.plugin.ds.DataType;
import com.qlangtech.tis.plugin.ds.ElementCreatorFactory;
import com.qlangtech.tis.plugin.ds.IdlistElementCreatorFactory;
import com.qlangtech.tis.runtime.module.misc.IFieldErrorHandler;
import org.apache.commons.lang.StringUtils;
import org.bson.BsonType;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiConsumer;

Expand All @@ -17,10 +29,75 @@
* @author 百岁 ([email protected])
* @date 2023/9/3
*/
public class MongoCMetaCreatorFactory implements CMeta.ElementCreatorFactory {
public class MongoCMetaCreatorFactory extends IdlistElementCreatorFactory {
public static final String KEY_DOC_FIELD_SPLIT_METAS = "docFieldSplitMetas";
public static final String KEY_JSON_PATH = "jsonPath";

@Override
public ParsePostMCols<CMeta> parsePostMCols(IPropertyType propertyType, IFieldErrorHandler msgHandler, Context context, String keyColsMeta, JSONArray targetCols) {

if (targetCols == null) {
throw new IllegalArgumentException("param targetCols can not be null");
}
CMeta.ParsePostMCols postMCols = new CMeta.ParsePostMCols();
CMeta colMeta = null;


String targetColName = null;
DataType dataType = null;

Map<String, Integer> existCols = Maps.newHashMap();
Integer previousColIndex = null;
boolean pk;
for (int i = 0; i < targetCols.size(); i++) {
JSONObject targetCol = targetCols.getJSONObject(i);
int index = targetCol.getInteger("index") - 1;
pk = targetCol.getBooleanValue("pk");
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;
postMCols.validateFaild = true;
return postMCols;
}
if (!Validator.require.validate(msgHandler, context, keyColsMeta + "[" + index + "]", targetColName)) {
postMCols.validateFaild = true;
} else if (!Validator.db_col_name.validate(msgHandler, context, keyColsMeta + "[" + index + "]",
targetColName)) {
postMCols.validateFaild = true;
}


colMeta = this.create(targetCol, (propKey, errMsg) -> {
msgHandler.addFieldError(context
, IFieldErrorHandler.joinField(SelectedTab.KEY_FIELD_COLS, Collections.singletonList(index), propKey)
, errMsg);
postMCols.validateFaild = true;
});

if (pk) {
postMCols.pkHasSelected = true;
}

dataType = CMeta.parseType(targetCol, (propKey, errMsg) -> {
msgHandler.addFieldError(context
, IFieldErrorHandler.joinField(SelectedTab.KEY_FIELD_COLS, Collections.singletonList(index), propKey)
, errMsg);
postMCols.validateFaild = true;
});

if (dataType != null) {
colMeta.setType(dataType);
postMCols.writerCols.add(colMeta);
}
}

return postMCols;


}

/**
* example: cols[0].docFieldSplitMetas[0].jsonpath 等等
*
Expand Down Expand Up @@ -51,10 +128,13 @@ public CMeta createDefault() {
*/
@Override
public CMeta create(JSONObject targetCol, BiConsumer<String, String> errorProcess) {
if (targetCol == null) {
throw new IllegalArgumentException("param targetCol can not be null");
}
MongoCMeta cMeta = (MongoCMeta) createDefault();
MongoCMeta cMeta = (MongoCMeta) super.create(targetCol, errorProcess);
// String targetColName = targetCol.getString("name");
// boolean pk = targetCol.getBooleanValue("pk");
// cMeta.setDisable(targetCol.getBooleanValue("disable"));
// cMeta.setName(targetColName);
// cMeta.setPk(pk);

JSONArray fieldSplitterMetas = null;
JSONObject fieldSplit = null;
cMeta.setMongoFieldType(BsonType.valueOf(targetCol.getString("mongoFieldType")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.qlangtech.tis.plugin.ds.CMeta;
import com.qlangtech.tis.plugin.ds.ColumnMetaData;
import com.qlangtech.tis.plugin.ds.DataType;
import com.qlangtech.tis.plugin.ds.ElementCreatorFactory;
import com.qlangtech.tis.plugin.ds.JDBCTypes;
import com.qlangtech.tis.plugin.ds.mangodb.MangoDBDataSourceFactory;
import com.qlangtech.tis.plugin.ds.mangodb.TestMangoDBDataSourceFactory;
Expand Down Expand Up @@ -186,7 +187,7 @@ public void testValidateSubForm() {

public void testParseColsHtmlPost() {

Optional<CMeta.ElementCreatorFactory> mongoElementCreator = Optional.of(new MongoCMetaCreatorFactory());
ElementCreatorFactory mongoElementCreator = new MongoCMetaCreatorFactory();
IControlMsgHandler msgHandler = mock("msgHandler", IControlMsgHandler.class);
Context context = mock("context", Context.class);

Expand All @@ -198,8 +199,8 @@ public void testParseColsHtmlPost() {
, "mongo_reader_mulit_select_cols_with_docfield_split_metas_jsonpath_empty.json"));

this.replay();
CMeta.ParsePostMCols parsePostMCols
= PluginExtraProps.parsePostMCols(mongoElementCreator, msgHandler, context, MultiItemsViewType.keyColsMeta, colsJson);
CMeta.ParsePostMCols<CMeta> parsePostMCols
= mongoElementCreator.parsePostMCols(null , msgHandler, context, MultiItemsViewType.keyColsMeta, colsJson);
Assert.assertNotNull(parsePostMCols);
Assert.assertFalse(parsePostMCols.validateFaild);
Assert.assertEquals(5, parsePostMCols.writerCols.size());
Expand Down Expand Up @@ -244,11 +245,11 @@ public PropertyType visit(BaseSubFormProperties props) {

});

Optional<CMeta.ElementCreatorFactory> metaCreator = fieldProp.getCMetaCreator();
Assert.assertTrue(metaCreator.isPresent());
List<SelectedTab> tabs = TestSelectedTabs.createSelectedTabs(1, SelectedTab.class, metaCreator, (tab) -> {
ElementCreatorFactory metaCreator = fieldProp.getCMetaCreator();
// Assert.assertTrue(metaCreator.isPresent());
List<SelectedTab> tabs = TestSelectedTabs.createSelectedTabs(1, SelectedTab.class, Optional.of((ElementCreatorFactory<CMeta>)metaCreator) , (tab) -> {

MongoCMeta addCol = (MongoCMeta) CMeta.create(metaCreator, DOC_TYPE_FIELD, JDBCTypes.LONGNVARCHAR);
MongoCMeta addCol = (MongoCMeta) CMeta.create(Optional.of( metaCreator), DOC_TYPE_FIELD, JDBCTypes.LONGNVARCHAR);
addCol.setDisable(disableDocTypeField);
addCol.setMongoFieldType(BsonType.DOCUMENT);
List<MongoCMeta.MongoDocSplitCMeta> docFieldSplitMetas = Lists.newArrayList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.alibaba.datax.plugin.writer.hdfswriter.HdfsColMeta;
import com.google.common.collect.Lists;
import com.qlangtech.tis.datax.DataXCfgFile;
import com.qlangtech.tis.datax.IDataxProcessor;
import com.qlangtech.tis.datax.impl.DataxProcessor;
import com.qlangtech.tis.datax.impl.DataxWriter;
Expand Down Expand Up @@ -177,7 +178,7 @@ public void testRealDump() throws Exception {
OracleDSFactoryContainer.oracleDS.getDbConfig().vistDbURL(false, (a, b, url) -> {
jdbcUrl[0] = url;
});
DataXCfgJson wjson = DataXCfgJson.path("oracle_writer_real_dump.json");
DataXCfgJson wjson = DataXCfgJson.path(TestDataXOracleWriter.class,"oracle_writer_real_dump.json");
wjson.addCfgSetter((cfg) -> {
cfg.set("parameter.connection[0].jdbcUrl", jdbcUrl[0]);
return cfg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.common.collect.Lists;
import com.qlangtech.tis.common.utils.Assert;
import com.qlangtech.tis.extension.IPropertyType;
import com.qlangtech.tis.extension.SubFormFilter;
import com.qlangtech.tis.manage.common.Option;
import com.qlangtech.tis.offline.DataxUtils;

Expand All @@ -33,7 +34,7 @@
* @create: 2021-06-17 10:50
**/
public class DataxAction {
public static List<String> getTablesInDB(IPropertyType.SubFormFilter filter) {
public static List<String> getTablesInDB(SubFormFilter filter) {
String dataxName = filter.param(DataxUtils.DATAX_NAME);
Assert.assertEquals("dataxName must equal", "baisuitestTestcase", dataxName);
return Lists.newArrayList("table1", "table2", "table3");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.qlangtech.tis.extension.Descriptor;
import com.qlangtech.tis.extension.IPropertyType;
import com.qlangtech.tis.extension.PluginFormProperties;
import com.qlangtech.tis.extension.SubFormFilter;
import org.apache.commons.lang.StringUtils;

import java.util.Map;
Expand Down Expand Up @@ -72,7 +73,7 @@ public final String getDisplayName() {
return StringUtils.capitalize(writeMode.getMode());
}

public final PluginFormProperties getPluginFormPropertyTypes(Optional<IPropertyType.SubFormFilter> subFormFilter) {
public final PluginFormProperties getPluginFormPropertyTypes(Optional<SubFormFilter> subFormFilter) {
return super.getPluginFormPropertyTypes(Optional.empty());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ public ResultDTO<WorkflowInfoDTO> fetchWorkflow(Long workflowId) {
try {
String post = (String) postHAMethod.invoke(this, OpenAPIConstant.FETCH_WORKFLOW, body);
// String post = postHA(OpenAPIConstant.FETCH_WORKFLOW, body);
return JSON.parseObject(post, WF_TIS_RESULT_TYPE);
ResultDTO<TISWorkflowInfoDTO> resultDTO = JSON.parseObject(post, WF_TIS_RESULT_TYPE);
return resultDTO.isSuccess() ? ResultDTO.success(resultDTO.getData()) : ResultDTO.failed(resultDTO.getMessage());
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down

0 comments on commit 026c2a0

Please sign in to comment.