use of org.talend.designer.core.model.components.ElementParameter in project tdi-studio-se by Talend.
the class GenericTableUtilsTest method testGetTableValues.
@Test
public void testGetTableValues() {
MyTestTable tableProperties = new MyTestTable("tableProp");
List<String> columnValues = new ArrayList<String>();
columnValues.add("Text1");
columnValues.add("Text2");
tableProperties.column1.setValue(columnValues);
columnValues = new ArrayList<String>();
columnValues.add("true");
columnValues.add("false");
tableProperties.column2.setValue(columnValues);
columnValues = new ArrayList<String>();
columnValues.add("Value1");
columnValues.add("Value3");
tableProperties.column3.setValue(columnValues);
IElement elem = new FakeElement("test");
IElementParameter tableParam = new ElementParameter(elem);
tableParam.setName("myTable");
IElementParameter column1 = new ElementParameter(elem);
column1.setName("column1");
column1.setFieldType(EParameterFieldType.TEXT);
IElementParameter column2 = new ElementParameter(elem);
column2.setName("column2");
column2.setFieldType(EParameterFieldType.CHECK);
IElementParameter column3 = new ElementParameter(elem);
column3.setName("column3");
column3.setFieldType(EParameterFieldType.CLOSED_LIST);
List<String> values = new ArrayList<>();
values.add("Value1");
values.add("Value2");
values.add("Value3");
column3.setListItemsValue(values.toArray());
List<String> codeNames = new ArrayList<>();
codeNames.add("column1");
codeNames.add("column2");
codeNames.add("column3");
tableParam.setListItemsDisplayCodeName(codeNames.toArray(new String[0]));
List<IElementParameter> childParams = new ArrayList<>();
childParams.add(column1);
childParams.add(column2);
childParams.add(column3);
tableParam.setListItemsValue(childParams.toArray());
List<Map<String, Object>> table = GenericTableUtils.getTableValues(tableProperties, tableParam);
assertEquals(2, table.size());
Map<String, Object> line1 = table.get(0);
Map<String, Object> line2 = table.get(1);
assertEquals("Text1", line1.get("column1"));
assertEquals(Boolean.TRUE, line1.get("column2"));
assertEquals("Value1", line1.get("column3"));
assertEquals("Text2", line2.get("column1"));
assertEquals(Boolean.FALSE, line2.get("column2"));
assertEquals("Value3", line2.get("column3"));
}
use of org.talend.designer.core.model.components.ElementParameter in project tdi-studio-se by Talend.
the class NodesMoveCommond method createNodeContainerList.
@SuppressWarnings("unchecked")
private void createNodeContainerList() {
int firstIndex = 0;
int index = 0;
nodeContainerList = new ArrayList<NodeContainer>();
connections = new ArrayList<IConnection>();
createdNames = new ArrayList<String>();
Map<String, String> oldNameTonewNameMap = new HashMap<String, String>();
Map<String, String> oldMetaToNewMeta = new HashMap<String, String>();
// see bug 0004882: Subjob title is not copied when copying/pasting subjobs from one job to another
Map<INode, SubjobContainer> mapping = new HashMap<INode, SubjobContainer>();
IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
// create the nodes
for (INode copiedNode : nodes) {
// IGraphicalNode copiedNode = (IGraphicalNode) copiedNodePart.getModel();
if (!containNodeInProcess(copiedNode)) {
continue;
}
IComponent component = ComponentsFactoryProvider.getInstance().get(copiedNode.getComponent().getName(), copiedNode.getProcess().getComponentsType());
if (component == null) {
component = copiedNode.getComponent();
}
IGraphicalNode pastedNode = new Node(component, process);
if (isJobletRefactor()) {
// keep original for joblet refactor.
process.removeUniqueNodeName(pastedNode.getUniqueName());
pastedNode.setPropertyValue(EParameterName.UNIQUE_NAME.getName(), copiedNode.getUniqueName());
process.addUniqueNodeName(copiedNode.getUniqueName());
}
if (service != null) {
if (service.isJobletInOutComponent(pastedNode)) {
process.removeUniqueNodeName(pastedNode.getUniqueName());
pastedNode.setPropertyValue(EParameterName.UNIQUE_NAME.getName(), copiedNode.getUniqueName());
process.addUniqueNodeName(copiedNode.getUniqueName());
}
}
// for bug 0004882: Subjob title is not copied when copying/pasting subjobs from one job to another
makeCopyNodeAndSubjobMapping(copiedNode, pastedNode, mapping);
Point location = null;
if (getCursorLocation() == null) {
location = (Point) ((Node) copiedNode).getLocation();
} else {
location = getCursorLocation();
index = nodes.indexOf(copiedNode);
}
if (process.isGridEnabled()) {
// replace the component to set it on the grid if it's enabled
int tempVar = location.x / TalendEditor.GRID_SIZE;
location.x = tempVar * TalendEditor.GRID_SIZE;
tempVar = location.y / TalendEditor.GRID_SIZE;
location.y = tempVar * TalendEditor.GRID_SIZE;
}
pastedNode.setLocation(findLocationForNode(location, (Dimension) ((Node) copiedNode).getSize(), index, firstIndex, ((Node) copiedNode)));
pastedNode.setSize(((Node) copiedNode).getSize());
INodeConnector mainConnector;
if (pastedNode.isELTComponent()) {
mainConnector = pastedNode.getConnectorFromType(EConnectionType.TABLE);
} else {
mainConnector = pastedNode.getConnectorFromType(EConnectionType.FLOW_MAIN);
}
if (!mainConnector.isMultiSchema()) {
if (copiedNode.getMetadataList().size() != 0) {
pastedNode.getMetadataList().clear();
for (IMetadataTable metaTable : copiedNode.getMetadataList()) {
IMetadataTable newMetaTable = metaTable.clone();
if (metaTable.getTableName().equals(copiedNode.getUniqueName())) {
newMetaTable.setTableName(pastedNode.getUniqueName());
}
for (IMetadataColumn column : metaTable.getListColumns()) {
if (column.isCustom()) {
IMetadataColumn newColumn = newMetaTable.getColumn(column.getLabel());
newColumn.setReadOnly(column.isReadOnly());
newColumn.setCustom(column.isCustom());
}
}
pastedNode.getMetadataList().add(newMetaTable);
}
}
} else {
List<IMetadataTable> copyOfMetadataList = new ArrayList<IMetadataTable>();
for (IMetadataTable metaTable : copiedNode.getMetadataList()) {
IMetadataTable newTable = metaTable.clone();
if (copiedNode.isELTComponent()) {
newTable.setTableName(createNewConnectionName(metaTable.getTableName(), IProcess.DEFAULT_TABLE_CONNECTION_NAME));
} else {
newTable.setTableName(createNewConnectionName(metaTable.getTableName(), null));
}
//$NON-NLS-1$
oldMetaToNewMeta.put(pastedNode.getUniqueName() + ":" + metaTable.getTableName(), newTable.getTableName());
for (IMetadataColumn column : metaTable.getListColumns()) {
if (column.isCustom()) {
IMetadataColumn newColumn = newTable.getColumn(column.getLabel());
newColumn.setReadOnly(column.isReadOnly());
newColumn.setCustom(column.isCustom());
}
}
newTable.sortCustomColumns();
copyOfMetadataList.add(newTable);
}
pastedNode.setMetadataList(copyOfMetadataList);
IExternalNode externalNode = pastedNode.getExternalNode();
if (externalNode != null) {
if (copiedNode.getExternalData() != null) {
try {
externalNode.setExternalData(copiedNode.getExternalData().clone());
} catch (CloneNotSupportedException e) {
ExceptionHandler.process(e);
}
((Node) pastedNode).setExternalData(externalNode.getExternalData());
}
for (IMetadataTable metaTable : copiedNode.getMetadataList()) {
String oldName = metaTable.getTableName();
//$NON-NLS-1$
String newName = oldMetaToNewMeta.get(pastedNode.getUniqueName() + ":" + metaTable.getTableName());
externalNode.renameOutputConnection(oldName, newName);
CorePlugin.getDefault().getMapperService().renameJoinTable(process, externalNode.getExternalData(), createdNames);
}
// when copy a external node, should also copy screeshot
if (copiedNode.getExternalNode() != null) {
ImageDescriptor screenshot = copiedNode.getExternalNode().getScreenshot();
if (screenshot != null) {
externalNode.setScreenshot(screenshot);
}
}
}
}
((Node) pastedNode).getNodeLabel().setOffset(new Point(((Node) copiedNode).getNodeLabel().getOffset()));
oldNameTonewNameMap.put(copiedNode.getUniqueName(), pastedNode.getUniqueName());
if (copiedNode.getElementParametersWithChildrens() != null) {
for (ElementParameter param : (List<ElementParameter>) copiedNode.getElementParametersWithChildrens()) {
if (!EParameterName.UNIQUE_NAME.getName().equals(param.getName())) {
IElementParameter elementParameter = pastedNode.getElementParameter(param.getName());
if (param.getFieldType() == EParameterFieldType.TABLE) {
List<Map<String, Object>> tableValues = (List<Map<String, Object>>) param.getValue();
ArrayList newValues = new ArrayList();
for (Map<String, Object> map : tableValues) {
Map<String, Object> newMap = new HashMap<String, Object>();
newMap.putAll(map);
// rename schemas
if (EParameterName.SCHEMAS.name().equals(param.getName()) && !oldMetaToNewMeta.isEmpty()) {
String newSchemaName = oldMetaToNewMeta.get(pastedNode.getUniqueName() + ":" + map.get(EParameterName.SCHEMA.getName()));
if (newSchemaName != null) {
newMap.put(EParameterName.SCHEMA.getName(), newSchemaName);
}
}
newValues.add(newMap);
}
elementParameter.setValue(newValues);
} else {
if (param.getParentParameter() != null) {
String parentName = param.getParentParameter().getName();
//$NON-NLS-1$
pastedNode.setPropertyValue(parentName + ":" + param.getName(), param.getValue());
} else {
pastedNode.setPropertyValue(param.getName(), param.getValue());
// See Bug 0005722: the pasted component don't keep the same read-only mode and didn;t
// hide
// the password.
elementParameter.setReadOnly(param.getOriginalityReadOnly());
elementParameter.setRepositoryValueUsed(param.isRepositoryValueUsed());
}
}
}
}
}
NodeContainer nc = ((Process) pastedNode.getProcess()).loadNodeContainer((Node) pastedNode, false);
;
nodeContainerList.add(nc);
}
((Process) process).setCopyPasteSubjobMappings(mapping);
Map<String, String> oldToNewConnVarMap = new HashMap<String, String>();
// add the connections
for (INode copiedNode : nodes) {
// INode copiedNode = (INode) copiedNodePart.getModel();
for (IConnection connection : (List<IConnection>) copiedNode.getOutgoingConnections()) {
INode pastedTargetNode = null, pastedSourceNode = null;
String nodeSource = oldNameTonewNameMap.get(copiedNode.getUniqueName());
for (NodeContainer nodeContainer : nodeContainerList) {
INode node = nodeContainer.getNode();
if (node.getUniqueName().equals(nodeSource)) {
pastedSourceNode = node;
}
}
INode targetNode = connection.getTarget();
// test if the target is in the nodes to paste to add the
// connection
// if the targeted node is not in the nodes to paste, then the
// string will be null
String nodeToConnect = oldNameTonewNameMap.get(targetNode.getUniqueName());
if (nodeToConnect != null) {
for (NodeContainer nodeContainer : nodeContainerList) {
INode node = nodeContainer.getNode();
if (node.getUniqueName().equals(nodeToConnect)) {
pastedTargetNode = node;
}
}
}
if ((pastedSourceNode != null) && (pastedTargetNode != null)) {
String newConnectionName;
String metaTableName;
if (connection.getLineStyle().hasConnectionCategory(IConnectionCategory.UNIQUE_NAME) && connection.getLineStyle().hasConnectionCategory(IConnectionCategory.FLOW)) {
String newNameBuiltIn = oldMetaToNewMeta.get(//$NON-NLS-1$
pastedSourceNode.getUniqueName() + ":" + connection.getMetaName());
if (newNameBuiltIn == null) {
IElementParameter formatParam = pastedSourceNode.getElementParameter(EParameterName.CONNECTION_FORMAT.getName());
String baseName = IProcess.DEFAULT_ROW_CONNECTION_NAME;
if (formatParam != null) {
String value = (String) formatParam.getValue();
if (value != null && !"".equals(value)) {
//$NON-NLS-1$
baseName = value;
}
}
if (process.checkValidConnectionName(connection.getName(), true)) {
// keep the name, bug 5086
baseName = null;
}
newConnectionName = createNewConnectionName(connection.getName(), baseName);
} else {
newConnectionName = newNameBuiltIn;
}
} else {
newConnectionName = connection.getName();
}
//$NON-NLS-1$
String meta = oldMetaToNewMeta.get(pastedSourceNode.getUniqueName() + ":" + connection.getMetaName());
if (meta != null) {
if (pastedSourceNode.getConnectorFromType(connection.getLineStyle()).isMultiSchema() && !connection.getLineStyle().equals(EConnectionType.TABLE)) {
newConnectionName = meta;
}
metaTableName = meta;
} else {
if (pastedSourceNode.getConnectorFromType(connection.getLineStyle()).isMultiSchema()) {
metaTableName = pastedSourceNode.getMetadataList().get(0).getTableName();
} else {
// connection.getMetaName();
metaTableName = pastedSourceNode.getUniqueName();
}
}
IConnection pastedConnection;
if (!pastedTargetNode.isELTComponent()) {
pastedConnection = new Connection(pastedSourceNode, pastedTargetNode, connection.getLineStyle(), connection.getConnectorName(), metaTableName, newConnectionName, connection.isMonitorConnection());
} else {
pastedConnection = new Connection(pastedSourceNode, pastedTargetNode, connection.getLineStyle(), connection.getConnectorName(), metaTableName, newConnectionName, metaTableName, connection.isMonitorConnection());
}
connections.add(pastedConnection);
oldNameTonewNameMap.put(connection.getUniqueName(), pastedConnection.getUniqueName());
// pastedConnection.setActivate(pastedSourceNode.isActivate());
for (ElementParameter param : (List<ElementParameter>) connection.getElementParameters()) {
// pastedConnection.getElementParameter(param.getName())
// .setValue(param.getValue());
pastedConnection.setPropertyValue(param.getName(), param.getValue());
}
// reset unique name param
IElementParameter uniqueNameParam = pastedConnection.getElementParameter(EParameterName.UNIQUE_NAME.getName());
String newName = oldNameTonewNameMap.get(connection.getUniqueName());
if (uniqueNameParam != null && newName != null) {
if (!newName.equals(uniqueNameParam.getValue())) {
pastedConnection.setPropertyValue(EParameterName.UNIQUE_NAME.getName(), newName);
}
}
// // keep the label (bug 3778)
// if (pastedConnection != null) {
// if (pastedConnection.getSourceNodeConnector().isBuiltIn()
// && pastedConnection.getLineStyle().hasConnectionCategory(EConnectionType.FLOW)) {
// pastedConnection.setPropertyValue(EParameterName.LABEL.getName(), connection.getName());
// } else {
// pastedConnection.setPropertyValue(EParameterName.LABEL.getName(), newConnectionName);
// }
// }
((Connection) pastedConnection).getConnectionLabel().setOffset(new Point(((Connection) connection).getConnectionLabel().getOffset()));
INodeConnector connector = pastedConnection.getSourceNodeConnector();
connector.setCurLinkNbOutput(connector.getCurLinkNbOutput() + 1);
connector = pastedConnection.getTargetNodeConnector();
connector.setCurLinkNbInput(connector.getCurLinkNbInput() + 1);
IExternalNode externalNode = pastedTargetNode.getExternalNode();
if (externalNode != null) {
externalNode.renameInputConnection(connection.getName(), newConnectionName);
}
// (feature 2962)
if (pastedConnection.getMetadataTable() == null) {
continue;
}
for (IMetadataColumn column : pastedConnection.getMetadataTable().getListColumns()) {
//$NON-NLS-1$
String oldConnVar = connection.getName() + "." + column.getLabel();
//$NON-NLS-1$
String newConnVar = newConnectionName + "." + column.getLabel();
// String newConnVar = newConnectionName;
if (!oldToNewConnVarMap.containsKey(oldConnVar)) {
oldToNewConnVarMap.put(oldConnVar, newConnVar);
}
}
}
}
}
// rename the connection data for node parameters. (feature 2962)
for (NodeContainer nodeContainer : nodeContainerList) {
Node node = nodeContainer.getNode();
for (String oldConnVar : oldToNewConnVarMap.keySet()) {
String newConnVar = oldToNewConnVarMap.get(oldConnVar);
if (newConnVar != null) {
node.renameData(oldConnVar, newConnVar);
}
}
}
// check if the new components use the old components name.
Map<String, Set<String>> usedDataMap = new HashMap<String, Set<String>>();
for (NodeContainer nodeContainer : nodeContainerList) {
Node currentNode = nodeContainer.getNode();
String uniqueName = currentNode.getUniqueName();
for (String oldName : oldNameTonewNameMap.keySet()) {
if (!oldName.equals(oldNameTonewNameMap.get(oldName)) && currentNode.useData(oldName)) {
Set<String> oldNameSet = usedDataMap.get(uniqueName);
if (oldNameSet == null) {
oldNameSet = new HashSet<String>();
usedDataMap.put(uniqueName, oldNameSet);
}
oldNameSet.add(oldName);
}
}
}
// check if the new connections use the old components name.
Map<String, Set<String>> usedDataMapForConnections = new HashMap<String, Set<String>>();
for (IConnection connection : connections) {
String uniqueName = connection.getUniqueName();
for (String oldName : oldNameTonewNameMap.keySet()) {
if (oldName != null && !oldName.equals(oldNameTonewNameMap.get(oldName)) && UpgradeElementHelper.isUseData(connection, oldName)) {
Set<String> oldNameSet = usedDataMapForConnections.get(uniqueName);
if (oldNameSet == null) {
oldNameSet = new HashSet<String>();
usedDataMapForConnections.put(uniqueName, oldNameSet);
}
oldNameSet.add(oldName);
}
}
}
if (!usedDataMap.isEmpty() || !usedDataMapForConnections.isEmpty()) {
MessageBox msgBox = new MessageBox(PlatformUI.getWorkbench().getDisplay().getActiveShell(), SWT.YES | SWT.NO | SWT.ICON_WARNING);
//$NON-NLS-1$
msgBox.setMessage(Messages.getString("NodesPasteCommand.renameMessages"));
if (msgBox.open() == SWT.YES) {
for (NodeContainer nodeContainer : nodeContainerList) {
Node currentNode = nodeContainer.getNode();
Set<String> oldNameSet = usedDataMap.get(currentNode.getUniqueName());
if (oldNameSet != null && !oldNameSet.isEmpty()) {
for (String oldName : oldNameSet) {
currentNode.renameData(oldName, oldNameTonewNameMap.get(oldName));
}
}
}
// Rename connections
for (IConnection connection : connections) {
Set<String> oldNameSet = usedDataMapForConnections.get(connection.getUniqueName());
if (oldNameSet != null && !oldNameSet.isEmpty()) {
for (String oldName : oldNameSet) {
UpgradeElementHelper.renameData(connection, oldName, oldNameTonewNameMap.get(oldName));
}
}
}
}
}
}
use of org.talend.designer.core.model.components.ElementParameter in project tdi-studio-se by Talend.
the class ColumnListController method updateColumnsOnElement.
private static void updateColumnsOnElement(IElement element, List<ColumnNameChanged> columnsChanged, boolean synWidthWithMetadataColumn, String[] prevColumnNameList, String[] curColumnNameList, String[] curColumnValueList, List<String> refColumnListNamesTmpWithSourceName, List<String> refColumnListValuesTmp, String[] refColumnListNames, String[] refColumnListValues, boolean isSCDComponent, boolean isEdifactComponent, Map<String, Boolean> customColMap) {
List<String> columnList;
String[] columnNameList;
String edifactId = null;
if (isEdifactComponent) {
for (IElementParameter par : element.getElementParametersWithChildrens()) {
if (par.getName().equals("REPOSITORY_PROPERTY_TYPE")) {
edifactId = par.getValue().toString();
break;
}
}
}
for (int i = 0; i < element.getElementParameters().size(); i++) {
IElementParameter param = element.getElementParameters().get(i);
columnList = getColumnList(element, param.getContext(), null);
columnNameList = columnList.toArray(new String[0]);
if (param.getFieldType() == EParameterFieldType.COLUMN_LIST && !isSCDComponent) {
curColumnNameList = columnNameList;
curColumnValueList = columnNameList;
}
if (param.getFieldType() == EParameterFieldType.PREV_COLUMN_LIST) {
curColumnNameList = prevColumnNameList;
curColumnValueList = prevColumnNameList;
}
if (param.getFieldType() == EParameterFieldType.LOOKUP_COLUMN_LIST) {
curColumnNameList = refColumnListNames;
curColumnValueList = refColumnListValues;
}
if ((param.getFieldType() == EParameterFieldType.COLUMN_LIST && !isSCDComponent) || param.getFieldType() == EParameterFieldType.PREV_COLUMN_LIST || param.getFieldType() == EParameterFieldType.LOOKUP_COLUMN_LIST) {
param.setListItemsDisplayName(curColumnNameList);
param.setListItemsValue(curColumnValueList);
// for bug 10945
// 10155
boolean currentColumnStillExist = ArrayUtils.contains(curColumnValueList, param.getValue());
if (!currentColumnStillExist) {
for (int j = 0; j < refColumnListNamesTmpWithSourceName.size(); j++) {
if (param.getValue().equals(refColumnListNamesTmpWithSourceName.get(j))) {
param.setValue(refColumnListValuesTmp.get(j));
break;
}
}
currentColumnStillExist = ArrayUtils.contains(curColumnValueList, param.getValue());
}
if (curColumnNameList.length > 0 && !currentColumnStillExist) {
param.setValue(curColumnValueList[0]);
} else if (!currentColumnStillExist) {
//$NON-NLS-1$
param.setValue("");
}
syncNodePropertiesColumns(param, columnsChanged, curColumnNameList);
}
if (param.getFieldType() == EParameterFieldType.TABLE) {
Object[] itemsValue = param.getListItemsValue();
for (Object element2 : itemsValue) {
if (element2 instanceof IElementParameter) {
IElementParameter tmpParam = (IElementParameter) element2;
columnList = getColumnList(element, tmpParam.getContext(), customColMap);
String[] tableColumnNameList = columnList.toArray(new String[0]);
if (tmpParam.getFieldType() == EParameterFieldType.COLUMN_LIST) {
curColumnNameList = tableColumnNameList;
curColumnValueList = tableColumnNameList;
}
if (tmpParam.getFieldType() == EParameterFieldType.PREV_COLUMN_LIST && element instanceof INode) {
curColumnNameList = prevColumnNameList;
curColumnValueList = prevColumnNameList;
}
// needed for traces with breakpoint, feature:
if (tmpParam.getFieldType() == EParameterFieldType.PREV_COLUMN_LIST && element instanceof IConnection) {
curColumnNameList = tableColumnNameList;
curColumnValueList = tableColumnNameList;
}
if (tmpParam.getFieldType() == EParameterFieldType.LOOKUP_COLUMN_LIST) {
curColumnNameList = refColumnListNames;
curColumnValueList = refColumnListValues;
}
if (tmpParam.getFieldType() == EParameterFieldType.COLUMN_LIST || tmpParam.getFieldType() == EParameterFieldType.PREV_COLUMN_LIST || tmpParam.getFieldType() == EParameterFieldType.LOOKUP_COLUMN_LIST) {
List<String[]> filterColumns = filterColumns(tmpParam, curColumnNameList, curColumnValueList, customColMap);
curColumnNameList = filterColumns.get(0);
curColumnValueList = filterColumns.get(1);
tmpParam.setListItemsDisplayCodeName(curColumnNameList);
tmpParam.setListItemsDisplayName(curColumnNameList);
tmpParam.setListItemsValue(curColumnValueList);
if (curColumnValueList.length > 0) {
tmpParam.setDefaultClosedListValue(curColumnValueList[0]);
} else {
//$NON-NLS-1$
tmpParam.setDefaultClosedListValue("");
}
syncNodePropertiesTableColumns(param, columnsChanged, curColumnNameList, tmpParam);
}
}
}
}
if (param.isBasedOnSchema()) {
List<Map<String, Object>> paramValues = (List<Map<String, Object>>) param.getValue();
List<Map<String, Object>> newParamValues = new ArrayList<Map<String, Object>>();
for (int j = 0; j < columnNameList.length; j++) {
String columnName = columnNameList[j];
String[] codes = param.getListItemsDisplayCodeName();
Map<String, Object> newLine = null;
boolean found = false;
ColumnNameChanged colChanged = null;
if (columnsChanged != null) {
for (int k = 0; k < columnsChanged.size() && !found; k++) {
colChanged = columnsChanged.get(k);
if (colChanged.getNewName().equals(columnName)) {
found = true;
}
}
}
if (found) {
found = false;
for (int k = 0; k < paramValues.size() && !found; k++) {
Map<String, Object> currentLine = paramValues.get(k);
if (currentLine.get(codes[0]).equals(colChanged.getOldName())) {
currentLine.put(codes[0], colChanged.getNewName());
found = true;
}
}
}
found = false;
for (int k = 0; k < paramValues.size() && !found; k++) {
Map<String, Object> currentLine = paramValues.get(k);
if (currentLine.get(codes[0]) == null) {
currentLine.put(codes[0], columnName);
}
if (currentLine.get(codes[0]).equals(columnName)) {
found = true;
newLine = currentLine;
}
}
if (!found) {
newLine = TableController.createNewLine(param);
newLine.put(codes[0], columnName);
reUsedColumnFunctionArrayCheck(newLine, element, codes);
if (!StringUtils.isEmpty(edifactId)) {
org.talend.core.model.metadata.builder.connection.Connection connection = MetadataToolHelper.getConnectionFromRepository(edifactId);
if (connection != null && connection instanceof EDIFACTConnection) {
List<org.talend.core.model.metadata.builder.connection.MetadataTable> tables = ConnectionHelper.getTablesWithOrders(connection);
for (MetadataColumn col : tables.get(0).getColumns()) {
if (col.getLabel().equals(columnName)) {
if (col instanceof EDIFACTColumn) {
EDIFACTColumn edicolumn = (EDIFACTColumn) col;
String ediXpath = edicolumn.getEDIXpath();
newLine.put(codes[0], columnName);
newLine.put(codes[1], ediXpath);
break;
}
}
}
}
}
if (element instanceof Node) {
Node node = (Node) element;
String familyName = node.getComponent().getOriginalFamilyName();
/** need add second parameter for hbase input/output component **/
if (familyName != null && familyName.equals("Databases/HBase")) {
for (IElementParameter par : node.getElementParametersWithChildrens()) {
if (par.getName().equals("REPOSITORY_PROPERTY_TYPE")) {
String hbaseConnectionId = par.getValue().toString();
String columnFamily = null;
org.talend.core.model.metadata.builder.connection.Connection connection = MetadataToolHelper.getConnectionFromRepository(hbaseConnectionId);
if (connection != null && connection instanceof DatabaseConnection) {
/* use imetadataconnection because maybe it's in context model */
IMetadataConnection metadataConnection = ConvertionHelper.convert(connection);
List<org.talend.core.model.metadata.builder.connection.MetadataTable> tables = ConnectionHelper.getTablesWithOrders(connection);
boolean find = false;
for (org.talend.core.model.metadata.builder.connection.MetadataTable table : tables) {
for (MetadataColumn column : table.getColumns()) {
if (column.getLabel() != null && column.getLabel().equals(columnName)) {
for (TaggedValue tv : column.getTaggedValue()) {
String tag = tv.getTag();
if (tag != null && tag.equals("COLUMN FAMILY")) {
String value = tv.getValue();
if (value != null) {
columnFamily = value;
break;
}
}
}
}
if (find) {
break;
}
}
if (find) {
break;
}
}
}
if (columnFamily != null) {
newLine.put(codes[1], TalendTextUtils.addQuotes(columnFamily));
break;
}
}
}
}
}
/* should put other attribute for edi mapping */
}
if (synWidthWithMetadataColumn) {
setColumnSize(newLine, element, codes, param);
}
newParamValues.add(j, newLine);
}
paramValues.clear();
paramValues.addAll(newParamValues);
} else if (param.isColumnsBasedOnSchema()) {
List<Map<String, Object>> paramValues = (List<Map<String, Object>>) param.getValue();
List<Map<String, Object>> newParamValues = new ArrayList<Map<String, Object>>();
String[] listRepositoryItem = new String[columnNameList.length];
String[] listItemsDisplayValue = new String[columnNameList.length];
String[] listItemsDisplayCodeValue = new String[columnNameList.length];
Object[] listItemsValue = new Object[columnNameList.length];
String[] listItemsShowIf = new String[columnNameList.length];
String[] listItemsNotShowIf = new String[columnNameList.length];
ElementParameter newParam;
for (int j = 0; j < columnNameList.length; j++) {
String columnName = columnNameList[j];
listItemsDisplayCodeValue[j] = columnName;
listItemsDisplayValue[j] = columnName;
//$NON-NLS-1$
listRepositoryItem[j] = "";
listItemsShowIf[j] = null;
listItemsNotShowIf[j] = null;
newParam = new ElementParameter(element);
newParam.setName(columnName);
//$NON-NLS-1$
newParam.setDisplayName("");
newParam.setFieldType(EParameterFieldType.TEXT);
//$NON-NLS-1$
newParam.setValue("");
listItemsValue[j] = newParam;
boolean found = false;
ColumnNameChanged colChanged = null;
if (columnsChanged != null) {
for (int k = 0; k < columnsChanged.size() && !found; k++) {
colChanged = columnsChanged.get(k);
if (colChanged.getNewName().equals(columnName)) {
found = true;
}
}
}
for (int k = 0; k < paramValues.size(); k++) {
Map<String, Object> line = paramValues.get(k);
Map<String, Object> newline = new HashMap<String, Object>();
if (found) {
Object object = line.get(colChanged.getOldName());
if (object != null) {
newline.put(colChanged.getNewName(), object);
line.remove(colChanged.getOldName());
line.putAll(newline);
}
}
}
}
param.setListItemsDisplayName(listItemsDisplayValue);
param.setListItemsDisplayCodeName(listItemsDisplayCodeValue);
param.setListItemsValue(listItemsValue);
param.setListRepositoryItems(listRepositoryItem);
param.setListItemsShowIf(listItemsShowIf);
param.setListItemsNotShowIf(listItemsNotShowIf);
}
}
}
use of org.talend.designer.core.model.components.ElementParameter in project tdi-studio-se by Talend.
the class JobSettingsManager method getExtraOnFileParameters.
private static List<IElementParameter> getExtraOnFileParameters(IProcess process) {
ElementParameter param;
List<IElementParameter> paramList = new ArrayList<IElementParameter>();
// set Implicit tContextLoad file
//$NON-NLS-1$
String fileName = ElementParameterParser.parse(process, "__COMP_DEFAULT_FILE_DIR__/in.csv");
IPath path = Path.fromOSString(fileName);
fileName = TalendTextUtils.addQuotes(path.toPortableString());
param = new ElementParameter(process);
param.setName(EParameterName.IMPLICIT_TCONTEXTLOAD_FILE.getName());
param.setValue(fileName);
param.setDisplayName(EParameterName.IMPLICIT_TCONTEXTLOAD_FILE.getDisplayName());
param.setFieldType(EParameterFieldType.FILE);
param.setCategory(EComponentCategory.EXTRA);
param.setGroup(IMPLICIT_GROUP);
param.setNumRow(31);
String condition = JobSettingsConstants.addBrackets(CONTEXTLOAD_CONDITION) + //$NON-NLS-1$
" and " + JobSettingsConstants.addBrackets(JobSettingsConstants.getExtraParameterName(EParameterName.FROM_FILE_FLAG.getName()) + //$NON-NLS-1$
" == 'true'");
param.setShowIf(condition);
paramList.add(param);
param = new ElementParameter(process);
param.setName(EParameterName.FIELDSEPARATOR.getName());
//$NON-NLS-1$
String value = ";";
value = TalendTextUtils.addQuotes(value);
param.setValue(value);
param.setDisplayName(EParameterName.FIELDSEPARATOR.getDisplayName());
param.setFieldType(EParameterFieldType.TEXT);
param.setCategory(EComponentCategory.EXTRA);
param.setGroup(IMPLICIT_GROUP);
param.setNumRow(32);
condition = JobSettingsConstants.addBrackets(CONTEXTLOAD_CONDITION) + //$NON-NLS-1$
" and " + JobSettingsConstants.addBrackets(JobSettingsConstants.getExtraParameterName(EParameterName.FROM_FILE_FLAG.getName()) + //$NON-NLS-1$
" == 'true'");
param.setShowIf(condition);
paramList.add(param);
return paramList;
}
use of org.talend.designer.core.model.components.ElementParameter in project tdi-studio-se by Talend.
the class JobSettingsManager method getHeaderFooterParameters.
private static List<IElementParameter> getHeaderFooterParameters(IProcess process) {
// for headerFooter Code
ElementParameter param;
List<IElementParameter> paramList = new ArrayList<IElementParameter>();
param = new ElementParameter(process);
param.setName(EParameterName.HEADERFOOTER_HEADERID.getName());
param.setValue("");
param.setDisplayName(EParameterName.FOOTER_ENABLED.getDisplayName());
param.setFieldType(EParameterFieldType.TEXT);
param.setCategory(EComponentCategory.HEADERFOOTER);
param.setNumRow(2);
param.setShow(false);
paramList.add(param);
param = new ElementParameter(process);
param.setName(EParameterName.HEADER_ENABLED.getName());
param.setValue(Boolean.FALSE);
param.setDisplayName(EParameterName.HEADER_ENABLED.getDisplayName());
param.setFieldType(EParameterFieldType.CHECK);
param.setCategory(EComponentCategory.HEADERFOOTER);
param.setNumRow(2);
param.setShow(false);
paramList.add(param);
param = new ElementParameter(process);
param.setName(EParameterName.HEADER_LIBRARY.getName());
param.setValue("");
param.setDisplayName(EParameterName.HEADER_LIBRARY.getDisplayName());
param.setFieldType(EParameterFieldType.TEXT);
param.setCategory(EComponentCategory.HEADERFOOTER);
param.setNumRow(3);
param.setShow(false);
paramList.add(param);
param = new ElementParameter(process);
param.setName(EParameterName.HEADER_CODE.getName());
param.setValue("");
param.setDisplayName(EParameterName.HEADER_CODE.getDisplayName());
param.setFieldType(EParameterFieldType.TEXT);
param.setCategory(EComponentCategory.HEADERFOOTER);
param.setNumRow(4);
param.setShow(false);
paramList.add(param);
param = new ElementParameter(process);
param.setName(EParameterName.HEADER_IMPORT.getName());
param.setValue("");
param.setDisplayName(EParameterName.HEADER_IMPORT.getDisplayName());
param.setFieldType(EParameterFieldType.TEXT);
param.setCategory(EComponentCategory.HEADERFOOTER);
param.setNumRow(4);
param.setShow(false);
paramList.add(param);
param = new ElementParameter(process);
param.setName(EParameterName.HEADERFOOTER_FOOTERID.getName());
param.setValue("");
param.setDisplayName(EParameterName.FOOTER_ENABLED.getDisplayName());
param.setFieldType(EParameterFieldType.TEXT);
param.setCategory(EComponentCategory.HEADERFOOTER);
param.setNumRow(2);
param.setShow(false);
paramList.add(param);
param = new ElementParameter(process);
param.setName(EParameterName.FOOTER_ENABLED.getName());
param.setValue(Boolean.FALSE);
param.setDisplayName(EParameterName.FOOTER_ENABLED.getDisplayName());
param.setFieldType(EParameterFieldType.CHECK);
param.setCategory(EComponentCategory.HEADERFOOTER);
param.setNumRow(5);
param.setShow(false);
paramList.add(param);
param = new ElementParameter(process);
param.setName(EParameterName.FOOTER_LIBRARY.getName());
param.setValue("");
param.setDisplayName(EParameterName.FOOTER_LIBRARY.getDisplayName());
param.setFieldType(EParameterFieldType.TEXT);
param.setCategory(EComponentCategory.HEADERFOOTER);
param.setNumRow(6);
param.setShow(false);
paramList.add(param);
param = new ElementParameter(process);
param.setName(EParameterName.FOOTER_CODE.getName());
param.setValue("");
param.setDisplayName(EParameterName.FOOTER_CODE.getDisplayName());
param.setFieldType(EParameterFieldType.TEXT);
param.setCategory(EComponentCategory.HEADERFOOTER);
param.setNumRow(7);
param.setShow(false);
paramList.add(param);
param = new ElementParameter(process);
param.setName(EParameterName.FOOTER_IMPORT.getName());
param.setValue("");
param.setDisplayName(EParameterName.FOOTER_IMPORT.getDisplayName());
param.setFieldType(EParameterFieldType.TEXT);
param.setCategory(EComponentCategory.HEADERFOOTER);
param.setNumRow(4);
param.setShow(false);
paramList.add(param);
return paramList;
}
Aggregations