-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add transformer for TIS,and upgrade fastjson version 2.0.51
- Loading branch information
1 parent
4eabfaf
commit 026c2a0
Showing
15 changed files
with
121 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
|
@@ -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 等等 | ||
* | ||
|
@@ -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"))); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters