TUP-15848: tRowGenerator Not Saving DataMasking Parameters
This commit is contained in:
@@ -20,9 +20,13 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
import org.talend.commons.exception.ExceptionHandler;
|
||||
import org.talend.designer.rowgenerator.RowGeneratorComponent;
|
||||
import org.talend.designer.rowgenerator.managers.UIManager;
|
||||
import org.talend.designer.rowgenerator.ui.editor.MetadataColumnExt;
|
||||
import org.talend.utils.json.JSONArray;
|
||||
import org.talend.utils.json.JSONException;
|
||||
import org.talend.utils.json.JSONObject;
|
||||
|
||||
/**
|
||||
* class global comment. Detailled comment <br/>
|
||||
@@ -112,6 +116,35 @@ public class FunctionManagerExt extends FunctionManager {
|
||||
return arrayTalendFunctions2;
|
||||
}
|
||||
|
||||
public Function getFunctionFromColumn(MetadataColumnExt column) {
|
||||
Function function = null;
|
||||
String functionInfo = column.getFunctionInfo();
|
||||
if (functionInfo != null) {
|
||||
try {
|
||||
JSONObject functionObj = new JSONObject(functionInfo);
|
||||
String functionName = functionObj.getString(Function.NAME);
|
||||
int functionSize = 0;
|
||||
JSONArray parametersArray = functionObj.getJSONArray(Function.PARAMETERS);
|
||||
if (parametersArray != null) {
|
||||
functionSize = parametersArray.length();
|
||||
}
|
||||
List<Function> funcs = getFunctionsByType(column.getTalendType());
|
||||
for (Function func : funcs) {
|
||||
if (func.getName().equals(functionName) && func.getParameters().size() == functionSize) {
|
||||
function = func;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (function != null) {
|
||||
function = function.clone(parametersArray);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
ExceptionHandler.process(e);
|
||||
}
|
||||
}
|
||||
return function;
|
||||
}
|
||||
|
||||
public Function getFuntionFromArray(MetadataColumnExt bean, RowGeneratorComponent externalNode, int index) {
|
||||
String value = externalNode.getColumnValue(bean, index);
|
||||
List<Function> functions = getFunctionsByType(bean.getTalendType());
|
||||
|
||||
@@ -240,7 +240,11 @@ public class UIManager {
|
||||
List<Function> funs = functionManager.getFunctionsByType(ext.getTalendType());
|
||||
ext.setArrayFunctions(functionManager.getFunctionArrays(funs));
|
||||
if (!funs.isEmpty()) {
|
||||
ext.setFunction(functionManager.getFuntionFromArray(ext, externalNode, j));
|
||||
Function funtion = functionManager.getFunctionFromColumn(ext);
|
||||
if (funtion == null) {
|
||||
funtion = functionManager.getFuntionFromArray(ext, externalNode, j);
|
||||
}
|
||||
ext.setFunction(funtion);
|
||||
}
|
||||
exts.add(ext);
|
||||
}
|
||||
|
||||
@@ -14,10 +14,12 @@ package org.talend.designer.rowgenerator.ui.editor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.talend.commons.exception.ExceptionHandler;
|
||||
import org.talend.core.model.metadata.IMetadataColumn;
|
||||
import org.talend.core.model.metadata.MetadataColumn;
|
||||
import org.talend.designer.rowgenerator.data.Function;
|
||||
import org.talend.designer.rowgenerator.data.Parameter;
|
||||
import org.talend.utils.json.JSONException;
|
||||
|
||||
/**
|
||||
* qzhang class global comment. Detailled comment <br/>
|
||||
@@ -27,6 +29,8 @@ import org.talend.designer.rowgenerator.data.Parameter;
|
||||
*/
|
||||
public class MetadataColumnExt extends MetadataColumn {
|
||||
|
||||
public static final String FUNCTION_INFO = "FUNCTION_INFO"; //$NON-NLS-1$
|
||||
|
||||
private boolean isChanged;
|
||||
|
||||
/**
|
||||
@@ -51,9 +55,25 @@ public class MetadataColumnExt extends MetadataColumn {
|
||||
|
||||
public void setFunction(Function function) {
|
||||
this.function = function;
|
||||
updateFunctionInfo();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")//$NON-NLS-1$
|
||||
private void updateFunctionInfo() {
|
||||
if (function != null) {
|
||||
try {
|
||||
String serializedFunction = function.toSerialized();
|
||||
this.getAdditionalField().put(FUNCTION_INFO, serializedFunction);
|
||||
} catch (JSONException e) {
|
||||
ExceptionHandler.process(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getFunctionInfo() {
|
||||
return this.getAdditionalField().get(FUNCTION_INFO);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public String getParameter() {
|
||||
String currentPara = ""; //$NON-NLS-1$
|
||||
if (this.function != null) {
|
||||
|
||||
@@ -12,9 +12,8 @@
|
||||
// ============================================================================
|
||||
package org.talend.designer.rowgenerator.data;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
@@ -24,6 +23,8 @@ import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.talend.core.i18n.Messages;
|
||||
import org.talend.core.model.metadata.MetadataColumn;
|
||||
import org.talend.core.model.metadata.types.JavaTypesManager;
|
||||
import org.talend.designer.rowgenerator.ui.editor.MetadataColumnExt;
|
||||
|
||||
/**
|
||||
@@ -104,4 +105,21 @@ public class FunctionManagerExtTest {
|
||||
return function;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFuntionFromColumn() {
|
||||
FunctionManagerExt functionManagerExt = new FunctionManagerExt();
|
||||
MetadataColumn newColumn = new MetadataColumn();
|
||||
newColumn.setLabel("newColumn"); //$NON-NLS-1$
|
||||
newColumn.setTalendType(JavaTypesManager.STRING.getId());
|
||||
MetadataColumnExt columnExt = new MetadataColumnExt(newColumn);
|
||||
List<Function> funcs = functionManagerExt.getFunctionsByType(newColumn.getTalendType());
|
||||
if (funcs.size() > 0) {
|
||||
Function func = funcs.get(0);
|
||||
columnExt.setFunction(func);
|
||||
Function function = functionManagerExt.getFunctionFromColumn(columnExt);
|
||||
assertEquals(func.getName(), function.getName());
|
||||
assertEquals(func.getParameters().size(), function.getParameters().size());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
// ============================================================================
|
||||
//
|
||||
// Copyright (C) 2006-2015 Talend Inc. - www.talend.com
|
||||
//
|
||||
// This source code is available under agreement available at
|
||||
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
|
||||
//
|
||||
// You should have received a copy of the agreement
|
||||
// along with this program; if not, write to Talend SA
|
||||
// 9 rue Pages 92150 Suresnes, France
|
||||
//
|
||||
// ============================================================================
|
||||
package org.talend.designer.rowgenerator.ui.editor;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.talend.designer.rowgenerator.data.Function;
|
||||
|
||||
/**
|
||||
* created by ycbai on 2016年10月28日 Detailled comment
|
||||
*
|
||||
*/
|
||||
public class MetadataColumnExtTest {
|
||||
|
||||
@Test
|
||||
public void testSetFunction() {
|
||||
MetadataColumnExt column = new MetadataColumnExt();
|
||||
Function func = new Function();
|
||||
func.setName("testFunc"); //$NON-NLS-1$
|
||||
column.setFunction(func);
|
||||
assertNotNull(column.getAdditionalField().get(MetadataColumnExt.FUNCTION_INFO));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user