Skip to content

Commit

Permalink
add transoformer support datax row
Browse files Browse the repository at this point in the history
  • Loading branch information
baisui1981 committed Jun 10, 2024
1 parent 46fb28b commit 96af12f
Show file tree
Hide file tree
Showing 46 changed files with 1,680 additions and 309 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,35 @@ public class DataTypeMeta {

private final DataType _type;

public interface IMultiItemsView {
public static IMultiItemsView unknow() {
return new IMultiItemsView() {
@Override
public List<String> getElementPropertyKeys() {
return Collections.emptyList();
}

@Override
public ViewContent getViewContent() {
return ViewContent.Unknow;
}
};
}

public List<String> getElementPropertyKeys();

public ViewContent getViewContent();

/**
* 向客户端传输的json内容中额外添加自动移属性
*
* @param biz
*/
default void appendExternalJsonProp(JSONObject biz) {

}
}

/**
* 接受的两种类型:
* <ol>
Expand All @@ -49,8 +78,10 @@ public class DataTypeMeta {
* @param tabMapper
* @return
*/
public static Map<String, Object> createViewBiz(List<String> elementGetKeys, Object tabMapper) {
public static Map<String, Object> createViewBiz(IMultiItemsView multiItemsView, Object tabMapper) {
List<String> elementGetKeys = Objects.requireNonNull(multiItemsView).getElementPropertyKeys();
JSONObject biz = new JSONObject();
biz.put("viewContentType", multiItemsView.getViewContent().getToken());
// Map<String, Object> biz = new HashMap<>();
if (elementGetKeys != null && !elementGetKeys.isEmpty()) {
biz.put("elementKeys", elementGetKeys);
Expand Down Expand Up @@ -111,6 +142,7 @@ public static Map<String, Object> createViewBiz(List<String> elementGetKeys, Obj
}

biz.put("colMetas", types);
multiItemsView.appendExternalJsonProp(biz);
return biz;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* <p>
* http:https://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.qlangtech.tis.plugin.ds;

/**
*
*/
public enum ViewContent {
TransformerRules("transformerRules"),
MongoCols("mongoCols"),
JdbcTypeProps("jdbcTypeProps"),
Unknow("unknow");
private String token;

private ViewContent(String token) {
this.token = token;
}

public String getToken() {
return this.token;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.qlangtech.tis.plugin.ds.DataTypeMeta.IMultiItemsView;
import org.apache.commons.io.IOUtils;
import org.junit.Assert;
import org.junit.Test;
Expand All @@ -44,7 +45,7 @@ public void testCreateViewBiz() throws Exception {
try (InputStream metaAssert = TestDataTypeMeta.class.getResourceAsStream("data_type_meta_assert.json")) {
Assert.assertEquals( //
json2String(IOUtils.toString(metaAssert, Charset.forName("utf-8"))) //
, json2String(DataTypeMeta.createViewBiz(Collections.emptyList(),cms)));
, json2String(DataTypeMeta.createViewBiz(IMultiItemsView.unknow(),cms)));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import com.qlangtech.tis.extension.DescriptorExtensionList;
import com.qlangtech.tis.extension.IPropertyType;
import com.qlangtech.tis.extension.util.MultiItemsViewType;
import com.qlangtech.tis.extension.util.PluginExtraProps;
import com.qlangtech.tis.fullbuild.IFullBuildContext;
import com.qlangtech.tis.lang.TisException;
import com.qlangtech.tis.manage.IAppSource;
Expand All @@ -84,8 +83,11 @@
import com.qlangtech.tis.plugin.ds.CMeta;
import com.qlangtech.tis.plugin.ds.ColumnMetaData;
import com.qlangtech.tis.plugin.ds.DataTypeMeta;
import com.qlangtech.tis.plugin.ds.DataTypeMeta.IMultiItemsView;
import com.qlangtech.tis.plugin.ds.DefaultTab;
import com.qlangtech.tis.plugin.ds.ElementCreatorFactory;
import com.qlangtech.tis.plugin.ds.ISelectedTab;
import com.qlangtech.tis.plugin.ds.IdlistElementCreatorFactory;
import com.qlangtech.tis.plugin.trigger.JobTrigger;
import com.qlangtech.tis.runtime.module.action.BasicModule;
import com.qlangtech.tis.runtime.module.action.CreateIndexConfirmModel;
Expand Down Expand Up @@ -181,7 +183,7 @@ public void doTriggerFullbuildTask(Context context) throws Exception {


Optional<JobTrigger> partialTrigger = JobTrigger.getPartialTriggerFromContext(context); // Optional.ofNullable((JobTrigger) context.get(JobTrigger.class.getName()));
DataXCfgGenerator.GenerateCfgs cfgFileNames = dataXProcessor.getDataxCfgFileNames(null,partialTrigger);
DataXCfgGenerator.GenerateCfgs cfgFileNames = dataXProcessor.getDataxCfgFileNames(null, partialTrigger);
if (!triggerType.validate(this, context, cfgFileNames.getDataXCfgFiles())) {
return;
}
Expand Down Expand Up @@ -1345,7 +1347,7 @@ public void doGetWriterColsMeta(Context context) {
}
}

this.setBizResult(context, DataTypeMeta.createViewBiz(Collections.emptyList(), tabMapper));
this.setBizResult(context, DataTypeMeta.createViewBiz(IMultiItemsView.unknow(), tabMapper));
}

@Func(value = PermissionConstant.APP_ADD)
Expand Down Expand Up @@ -1433,7 +1435,7 @@ public boolean validate(IFieldErrorHandler msgHandler, Context context, String f
return false;
}

CMeta.ParsePostMCols postMCols = PluginExtraProps.parsePostMCols(Optional.empty(), msgHandler,
CMeta.ParsePostMCols postMCols = (new IdlistElementCreatorFactory()).parsePostMCols(msgHandler,
context, MultiItemsViewType.keyColsMeta, targetCols);

// Map<String, Integer> existCols = Maps.newHashMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,8 @@ public void doSavePluginConfig(Context context) throws Exception {
JSONObject postData = this.parseJsonPost();
String[] forwardParams = getActionForwardParam(postData);

JSONArray pluginArray = Objects.requireNonNull(postData.getJSONArray("items"), "json prop items can not be null");
JSONArray pluginArray = Objects.requireNonNull(
postData.getJSONArray("items"), "json prop items can not be null");
UploadPluginMeta pluginMeta = null;

boolean faild = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,11 @@ public void setBizResult(Context context, Object value, boolean overwriteable) {

if ((previous = context.get(ACTION_BIZ_RESULT)) != null) {
if ((previous instanceof CanNotOverwriteableWrapper)) {
//context.put(ACTION_BIZ_RESULT, value);
return;
}
}

context.put(ACTION_BIZ_RESULT, value);
// if ((previous = context.put(ACTION_BIZ_RESULT, value)) != null) {
// if (previous instanceof CanNotOverwriteableWrapper) {
// throw new IllegalStateException("setBizResult relevant val can not be overwrite in apply context");
// }
// }
}

public static Object getBizResult(Context context) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* <p>
* http:https://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.qlangtech.tis.plugin;

import com.qlangtech.tis.plugin.ds.DataType;

/**
* @author: 百岁([email protected]
* @create: 2024-06-09 17:44
**/
public interface JDBCColumnProp {

public String getName();

public DataType getType();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.qlangtech.tis.plugin.IdentityName;
import com.qlangtech.tis.plugin.ValidatorCommons;
import org.apache.commons.lang.StringUtils;

import javax.management.Descriptor;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

/**
* Licensed to the Apache Software Foundation (ASF) under one
Expand All @@ -40,21 +36,33 @@
* <p>
* //@see com.qlangtech.tis.plugin.ds.ColumnMetaData
*/
public class CMeta implements Serializable, IColMetaGetter, IdentityName {
public class CMeta extends TypeBase implements Serializable, IColMetaGetter, IdentityName {


public static final String FIELD_NAME = "name";
public static final String KEY_COLUMN_SIZE = "columnSize";
public static final String KEY_DECIMAL_DIGITS = "decimalDigits";

private String name;

@Override
public String getName() {
return this.name;
}

public static DataType parseType(JSONObject targetCol, BiConsumer<String, String> errorProcess) {
boolean hasError = false;
JSONObject type = null;
type = Objects.requireNonNull(targetCol, "targetCol can not be null").getJSONObject("type");
if (type == null) {
errorProcess.accept(FIELD_NAME, ValidatorCommons.MSG_EMPTY_INPUT_ERROR);
return null;
}
Integer jdbcType = type.getInteger("type");

DataTypeMeta typeMeta = DataTypeMeta.getDataTypeMeta(JDBCTypes.parse(jdbcType));

boolean hasError = false;

Integer colSize = 0;
if ((colSize = type.getInteger(KEY_COLUMN_SIZE)) == null && typeMeta.isContainColSize()) {
errorProcess.accept(KEY_COLUMN_SIZE, ValidatorCommons.MSG_EMPTY_INPUT_ERROR);
Expand All @@ -76,25 +84,11 @@ public static DataType parseType(JSONObject targetCol, BiConsumer<String, String
}


public interface ElementCreatorFactory {


CMeta createDefault();

default CMeta create(JSONObject targetCol) {
return create(targetCol, (key, errMsg) -> {
throw new IllegalStateException("key:" + key + " ,errMsg:" + errMsg + " shall not occur");
});
}

CMeta create(JSONObject targetCol, BiConsumer<String, String> errorProcess);
}

public static CMeta create(String colName, JDBCTypes type) {
return create(Optional.empty(), colName, type);
}

public static CMeta create(Optional<ElementCreatorFactory> elementCreator, String colName, JDBCTypes type) {
public static CMeta create(Optional<ElementCreatorFactory<CMeta>> elementCreator, String colName, JDBCTypes type) {
CMeta cmeta = elementCreator.map((factory) -> {
return factory.createDefault();
}).orElse(new CMeta());// new CMeta();
Expand All @@ -105,8 +99,8 @@ public static CMeta create(Optional<ElementCreatorFactory> elementCreator, Strin

public static final String KEY_ELEMENT_CREATOR_FACTORY = "elementCreator";

private String name;
private DataType type;
// private String name;
// private DataType type;
private Boolean pk = false;

private String comment;
Expand Down Expand Up @@ -167,30 +161,18 @@ public void setPk(Boolean pk) {
this.pk = pk;
}

public String getName() {
return name;
}

public void setName(String name) {

if (StringUtils.indexOf(name, "{") > -1) {
throw new IllegalArgumentException("illegal param name:" + name);
}

this.name = name;
}

public DataType getType() {
return type;
}

public void setType(DataType type) {
this.type = type;
}

@Override
public String toString() {
return "{" + "name='" + name + '\'' + ", type=" + type + '}';
return "{" + "name='" + this.getName() + '\'' + ", type=" + this.getType() + '}';
}

@JSONField(serialize = false)
Expand All @@ -199,8 +181,8 @@ public Class<?> getDescribleClass() {
return IdentityName.super.getDescribleClass();
}

public static class ParsePostMCols {
public List<CMeta> writerCols = Lists.newArrayList();
public static class ParsePostMCols<T extends TypeBase> {
public List<T> writerCols = Lists.newArrayList();
public boolean validateFaild = false;
public boolean pkHasSelected = false;
}
Expand Down
Loading

0 comments on commit 96af12f

Please sign in to comment.