Search in sources :

Example 36 with INodeConnector

use of org.talend.core.model.process.INodeConnector in project tdi-studio-se by Talend.

the class UpdateELTMapComponentCommandTest method before.

@Before
public void before() {
    Process process = new Process(createProperty());
    sourceNode = new Node(sourceComponent, process);
    INodeConnector connector = new NodeConnector(sourceNode);
    connector.setName("connector");
    connector.setDefaultConnectionType(EConnectionType.FLOW_MAIN);
    ArrayList<INodeConnector> connectors = new ArrayList<INodeConnector>();
    connectors.add(connector);
    sourceNode.setListConnector(connectors);
    targetNode = new Node(targetComponent, process);
    DbMapComponent component = new DbMapComponent();
    targetNode.setExternalNode(component);
    connection = new Connection(sourceNode, targetNode, EConnectionType.FLOW_MAIN, "connector", "meta", "oldTable", true);
    inputs = (List<ExternalDbMapTable>) targetNode.getExternalData().getInputTables();
    ExternalDbMapTable input = new ExternalDbMapTable();
    input.setName("oldTable");
    input.setTableName("oldTable");
    inputs.add(input);
    outputs = (List<ExternalDbMapTable>) targetNode.getExternalData().getOutputTables();
    ExternalDbMapTable output = new ExternalDbMapTable();
    ExternalDbMapEntry entry = new ExternalDbMapEntry("oldTable", "oldTable.column");
    output.setMetadataTableEntries(new ArrayList<ExternalDbMapEntry>());
    output.getMetadataTableEntries().add(entry);
    outputs.add(output);
}
Also used : DbMapComponent(org.talend.designer.dbmap.DbMapComponent) INodeConnector(org.talend.core.model.process.INodeConnector) NodeConnector(org.talend.designer.core.model.components.NodeConnector) ExternalDbMapTable(org.talend.designer.dbmap.external.data.ExternalDbMapTable) Node(org.talend.designer.core.ui.editor.nodes.Node) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) Connection(org.talend.designer.core.ui.editor.connections.Connection) Process(org.talend.designer.core.ui.editor.process.Process) INodeConnector(org.talend.core.model.process.INodeConnector) ExternalDbMapEntry(org.talend.designer.dbmap.external.data.ExternalDbMapEntry) Before(org.junit.Before)

Example 37 with INodeConnector

use of org.talend.core.model.process.INodeConnector in project tdi-studio-se by Talend.

the class NodeTest method testGetNodeConnectorsShowIf1FlowConnector.

@Test
public void testGetNodeConnectorsShowIf1FlowConnector() {
    Process process = new Process(new FakePropertyImpl());
    IComponent sourceCom = ComponentsFactoryProvider.getInstance().get("tMysqlInput", ComponentCategory.CATEGORY_4_DI.getName());
    Node node = new Node(sourceCom, process);
    // create node connector for test
    List<INodeConnector> listConnector = new ArrayList<>();
    NodeConnector connector = new NodeConnector(node);
    connector.setDefaultConnectionType(EConnectionType.FLOW_MAIN);
    connector.setName(EConnectionType.FLOW_MAIN.getName());
    connector.setMaxLinkOutput(1);
    connector.setShowIf("SHOW_FLOW_CONNECTOR == 'true'");
    listConnector.add(connector);
    node.setListConnector(listConnector);
    // create a test param with default value 'false'
    IElementParameter param = addShowIfParam(node);
    Assert.assertNull(node.getConnectorFromName(EConnectionType.FLOW_MAIN.getName()));
    Assert.assertNull(node.getConnectorFromType(EConnectionType.FLOW_MAIN));
    Assert.assertEquals(node.getConnectorsFromType(EConnectionType.FLOW_MAIN).size(), 0);
    // make connector show if to 'true'
    param.setValue(true);
    Assert.assertNotNull(node.getConnectorFromName(EConnectionType.FLOW_MAIN.getName()));
    Assert.assertNotNull(node.getConnectorFromType(EConnectionType.FLOW_MAIN));
    Assert.assertEquals(node.getConnectorsFromType(EConnectionType.FLOW_MAIN).size(), 1);
}
Also used : FakePropertyImpl(org.talend.core.model.repository.FakePropertyImpl) INodeConnector(org.talend.core.model.process.INodeConnector) NodeConnector(org.talend.designer.core.model.components.NodeConnector) IComponent(org.talend.core.model.components.IComponent) ArrayList(java.util.ArrayList) IElementParameter(org.talend.core.model.process.IElementParameter) Process(org.talend.designer.core.ui.editor.process.Process) INodeConnector(org.talend.core.model.process.INodeConnector) Test(org.junit.Test)

Example 38 with INodeConnector

use of org.talend.core.model.process.INodeConnector in project tdi-studio-se by Talend.

the class NodeTest method testGetNodeConnectorsShowIf2FlowConnector.

@Test
public void testGetNodeConnectorsShowIf2FlowConnector() {
    Process process = new Process(new FakePropertyImpl());
    IComponent sourceCom = ComponentsFactoryProvider.getInstance().get("tMysqlInput", ComponentCategory.CATEGORY_4_DI.getName());
    Node node = new Node(sourceCom, process);
    // create node connector for test
    List<INodeConnector> listConnector = new ArrayList<>();
    NodeConnector connector1 = new NodeConnector(node);
    connector1.setDefaultConnectionType(EConnectionType.FLOW_MAIN);
    connector1.setName(EConnectionType.FLOW_MAIN.getName());
    connector1.setMaxLinkOutput(1);
    listConnector.add(connector1);
    connector1.setShowIf("SHOW_FLOW_CONNECTOR == 'true'");
    NodeConnector connector2 = new NodeConnector(node);
    connector2.setDefaultConnectionType(EConnectionType.FLOW_MAIN);
    connector2.setName(EConnectionType.FLOW_MAIN.getName());
    connector2.setMaxLinkInput(-1);
    connector2.setMaxLinkOutput(-1);
    connector2.setShowIf("SHOW_FLOW_CONNECTOR == 'false'");
    listConnector.add(connector2);
    node.setListConnector(listConnector);
    // create a test param with default value 'false'
    IElementParameter param = addShowIfParam(node);
    Assert.assertTrue(node.getConnectorFromName(EConnectionType.FLOW_MAIN.getName()) == connector2);
    Assert.assertTrue(node.getConnectorFromType(EConnectionType.FLOW_MAIN) == connector2);
    Assert.assertEquals(node.getConnectorsFromType(EConnectionType.FLOW_MAIN).size(), 1);
    // make connector show if to 'true'
    param.setValue(true);
    Assert.assertTrue(node.getConnectorFromName(EConnectionType.FLOW_MAIN.getName()) == connector1);
    Assert.assertTrue(node.getConnectorFromType(EConnectionType.FLOW_MAIN) == connector1);
    Assert.assertEquals(node.getConnectorsFromType(EConnectionType.FLOW_MAIN).size(), 1);
    // connector with same name should have the same current input/output
    connector1.setCurLinkNbInput(10);
    connector1.setCurLinkNbOutput(100);
    Assert.assertEquals(connector1.getCurLinkNbInput(), 10);
    Assert.assertEquals(connector1.getCurLinkNbOutput(), 100);
    Assert.assertEquals(connector2.getCurLinkNbInput(), 10);
    Assert.assertEquals(connector2.getCurLinkNbOutput(), 100);
}
Also used : FakePropertyImpl(org.talend.core.model.repository.FakePropertyImpl) INodeConnector(org.talend.core.model.process.INodeConnector) NodeConnector(org.talend.designer.core.model.components.NodeConnector) IComponent(org.talend.core.model.components.IComponent) ArrayList(java.util.ArrayList) IElementParameter(org.talend.core.model.process.IElementParameter) Process(org.talend.designer.core.ui.editor.process.Process) INodeConnector(org.talend.core.model.process.INodeConnector) Test(org.junit.Test)

Example 39 with INodeConnector

use of org.talend.core.model.process.INodeConnector in project tdi-studio-se by Talend.

the class ChangeMetadataCommand method propagateDatas.

private void propagateDatas(boolean isExecute) {
    // update currentConnector when flow main type
    if (schemaParam != null && (schemaParam.getFieldType().equals(EParameterFieldType.SCHEMA_TYPE) || schemaParam.getFieldType().equals(EParameterFieldType.SCHEMA_REFERENCE)) && EConnectionType.FLOW_MAIN.getDefaultMenuName().toUpperCase().equals(schemaParam.getContext())) {
        currentConnector = EConnectionType.FLOW_MAIN.getName();
    }
    String baseConnectorForCurrentNode = node.getConnectorFromName(currentConnector).getBaseSchema();
    // Propagate :
    if (outputdataContainer != null && (!outputdataContainer.getInputs().isEmpty() || !outputdataContainer.getOuputs().isEmpty())) {
        for (IODataComponent currentIO : outputdataContainer.getInputs()) {
            INode sourceNode = currentIO.getSource();
            if (currentIO.hasChanged() && (sourceNode.getConnectorFromName(currentIO.getConnection().getConnectorName()).getBaseSchema().equals(baseConnectorForCurrentNode))) {
                sourceNode.metadataOutputChanged(currentIO, currentIO.getName());
                if (isExecute) {
                    currentIO.setTable(oldInputMetadata);
                    currentIO.setColumnNameChanged(null);
                } else {
                    currentIO.setTable(newInputMetadata);
                    currentIO.setColumnNameChanged(null);
                }
            }
        }
        for (IODataComponent currentIO : outputdataContainer.getOuputs()) {
            INodeConnector nodeConnector = null;
            String baseConnector = null;
            Node sourceNode = (Node) currentIO.getSource();
            nodeConnector = sourceNode.getConnectorFromName(currentIO.getConnection().getConnectorName());
            baseConnector = nodeConnector.getBaseSchema();
            INode targetNode = currentIO.getTarget();
            boolean sourceIsBuiltIn = ((Node) currentIO.getSource()).getConnectorFromType(currentIO.getConnection().getLineStyle()).isMultiSchema();
            boolean targetIsBuiltIn = ((Node) targetNode).getConnectorFromType(currentIO.getConnection().getLineStyle()).isMultiSchema();
            boolean isJoblet = ((Node) targetNode).isJoblet();
            if (!isJoblet && baseConnector.equals(baseConnectorForCurrentNode) && (targetIsBuiltIn || (targetNode.getMetadataFromConnector(baseConnector) != null && !targetNode.getMetadataFromConnector(baseConnector).sameMetadataAs(newOutputMetadata)))) {
                targetNode.metadataInputChanged(currentIO, currentIO.getUniqueName());
                if (isExecute) {
                    if (targetNode instanceof Node) {
                        if (((Node) targetNode).getComponent().isSchemaAutoPropagated() && getPropagate() && targetNode.getMetadataList().size() > 0) {
                            IMetadataTable tmpClone;
                            if (sourceIsBuiltIn) {
                                IMetadataTable tab = node.getMetadataTable(currentIO.getConnection().getMetadataTable().getTableName());
                                if (tab == null && node.getJobletNode() != null) {
                                    tab = node.getJobletNode().getMetadataTable(currentIO.getConnection().getMetadataTable().getTableName());
                                }
                                tmpClone = tab.clone(true);
                            } else {
                                IMetadataTable tab = node.getMetadataFromConnector(currentIO.getConnection().getConnectorName());
                                if (tab == null && node.getJobletNode() != null) {
                                    tab = node.getJobletNode().getMetadataFromConnector(currentIO.getConnection().getConnectorName());
                                }
                                tmpClone = tab.clone(true);
                            }
                            IMetadataTable toCopy = newOutputMetadata.clone();
                            // wzhang modify to add feature 7611
                            String dbmsId = null;
                            IMetadataTable copy;
                            if (((Node) targetNode).getMetadataFromConnector(baseConnector) != null) {
                                dbmsId = targetNode.getMetadataFromConnector(baseConnector).getDbms();
                                MetadataToolHelper.copyTable(dbmsId, toCopy, tmpClone);
                                toCopy = tmpClone;
                                // only if the target node have exactly the same connector
                                copy = ((Node) targetNode).getMetadataFromConnector(baseConnector).clone(true);
                            } else {
                                // can only be FLOW right now for this case. //$NON-NLS-1$
                                final String mainConnector = "FLOW";
                                dbmsId = targetNode.getMetadataFromConnector(mainConnector).getDbms();
                                MetadataToolHelper.copyTable(dbmsId, toCopy, tmpClone);
                                toCopy = tmpClone;
                                // if don't have the same connector, take the main connector of the component.
                                copy = ((Node) targetNode).getMetadataFromConnector(mainConnector).clone(true);
                            }
                            // MetadataTool.copyTable(toCopy, copy);
                            // wzhang modify to add feature 7611
                            MetadataToolHelper.copyTable(dbmsId, toCopy, copy);
                            ChangeMetadataCommand cmd = new ChangeMetadataCommand(targetNode, null, null, copy, inputSchemaParam);
                            if (outputdataContainer.getOuputs().size() > 0) {
                                List<ColumnNameChanged> columnNameChanged = outputdataContainer.getOuputs().get(0).getColumnNameChanged();
                                for (IODataComponent dataComp : cmd.outputdataContainer.getOuputs()) {
                                    dataComp.setColumnNameChanged(columnNameChanged);
                                }
                            }
                            cmd.setRepositoryMode(repositoryMode);
                            cmd.execute(true);
                            propagatedChange.add(cmd);
                        }
                    }
                    currentIO.setTable(oldOutputMetadata);
                    currentIO.setColumnNameChanged(null);
                } else {
                    if (targetNode instanceof Node) {
                        if (!targetIsBuiltIn && getPropagate()) {
                            if (((Node) targetNode).getComponent().isSchemaAutoPropagated()) {
                                if (outputdataContainer.getOuputs().size() > 0) {
                                    List<ColumnNameChanged> columnNameChanged = outputdataContainer.getOuputs().get(0).getColumnNameChanged();
                                    for (ChangeMetadataCommand cmd : propagatedChange) {
                                        for (IODataComponent dataComp : cmd.outputdataContainer.getOuputs()) {
                                            dataComp.setColumnNameChanged(columnNameChanged);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    currentIO.setTable(newOutputMetadata);
                    currentIO.setColumnNameChanged(null);
                }
            }
        }
    } else if (dataComponent != null) {
        for (IConnection outgoingConnection : node.getOutgoingConnections()) {
            if (outgoingConnection.getConnectorName().equals(currentConnector)) {
                outgoingConnection.getTarget().metadataInputChanged(dataComponent, outgoingConnection.getName());
            }
        }
    } else {
        if (!node.getOutgoingConnections().isEmpty()) {
            IMetadataTable relativeOldOutputMetadata = null;
            IMetadataTable relativeNewOutputMetadata = null;
            if (isExecute) {
                relativeOldOutputMetadata = oldOutputMetadata;
                relativeNewOutputMetadata = newOutputMetadata;
            } else {
                relativeOldOutputMetadata = newOutputMetadata;
                relativeNewOutputMetadata = oldOutputMetadata;
            }
            for (IConnection outgoingConnection : node.getOutgoingConnections()) {
                if (!outgoingConnection.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
                    continue;
                }
                final Node target = (Node) outgoingConnection.getTarget();
                if (target != null && target.getExternalNode() != null) {
                    List<IMetadataColumn> oldListColumns = relativeOldOutputMetadata.getListColumns();
                    List<IMetadataColumn> newListColumns = relativeNewOutputMetadata.getListColumns();
                    List<ColumnNameChanged> columnNameChanges = new ArrayList<ColumnNameChanged>();
                    int size = oldListColumns.size();
                    int newSize = newListColumns.size();
                    if (newSize < size) {
                        size = newSize;
                    }
                    IODataComponent output = new IODataComponent(outgoingConnection, relativeNewOutputMetadata);
                    if (newListColumns != null) {
                        List<ColumnNameChanged> newColumnsList = output.getNewMetadataColumns();
                        // new added columns list
                        Set<String> newAddedColumns = new HashSet<String>();
                        // newest columns after user changed
                        Set<String> newestColumns = new HashSet<String>();
                        // init
                        if (newColumnsList != null) {
                            for (ColumnNameChanged columnChanged : newColumnsList) {
                                newAddedColumns.add(columnChanged.getNewName());
                            }
                        }
                        for (IMetadataColumn metadataColumn : newListColumns) {
                            newestColumns.add(metadataColumn.getLabel());
                        }
                        // check
                        for (int i = 0; i < size; i++) {
                            IMetadataColumn oldMetadataColumn = oldListColumns.get(i);
                            String columnName = oldMetadataColumn.getLabel();
                            // been removed
                            if (!newestColumns.contains(columnName)) {
                                IMetadataColumn newMetadataColumn = newListColumns.get(i);
                                String newColumnNameAtThisIndex = newMetadataColumn.getLabel();
                                // column, so we suppose the more possible truth is that it is a renamed column
                                if (newAddedColumns.contains(newColumnNameAtThisIndex)) {
                                    columnNameChanges.add(new ColumnNameChanged(columnName, newColumnNameAtThisIndex));
                                }
                            }
                        }
                    }
                    output.setColumnNameChanged(columnNameChanges);
                    target.metadataInputChanged(output, outgoingConnection.getName());
                }
            }
        }
    }
    if (inputdataContainer != null) {
        for (IODataComponent currentIO : inputdataContainer.getOuputs()) {
            if (currentIO.hasChanged() && (currentIO.getSource().getConnectorFromName(currentIO.getConnection().getConnectorName()).getBaseSchema().equals(currentConnector))) {
                INode targetNode = currentIO.getTarget();
                targetNode.metadataInputChanged(currentIO, currentIO.getUniqueName());
                if (isExecute) {
                    currentIO.setTable(oldInputMetadata);
                    currentIO.setColumnNameChanged(null);
                } else {
                    currentIO.setTable(newInputMetadata);
                    currentIO.setColumnNameChanged(null);
                }
            }
        }
    }
// End propagate
}
Also used : INode(org.talend.core.model.process.INode) HashSet(java.util.HashSet) Set(java.util.Set) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) IConnection(org.talend.core.model.process.IConnection) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) INodeConnector(org.talend.core.model.process.INodeConnector) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) ColumnNameChanged(org.talend.core.model.metadata.ColumnNameChanged) ArrayList(java.util.ArrayList) List(java.util.List) IODataComponent(org.talend.core.model.components.IODataComponent)

Example 40 with INodeConnector

use of org.talend.core.model.process.INodeConnector 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));
                    }
                }
            }
        }
    }
}
Also used : INode(org.talend.core.model.process.INode) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) IComponent(org.talend.core.model.components.IComponent) Node(org.talend.designer.core.ui.editor.nodes.Node) IExternalNode(org.talend.core.model.process.IExternalNode) INode(org.talend.core.model.process.INode) IGraphicalNode(org.talend.core.ui.process.IGraphicalNode) ArrayList(java.util.ArrayList) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) IConnection(org.talend.core.model.process.IConnection) IProcess(org.talend.core.model.process.IProcess) Process(org.talend.designer.core.ui.editor.process.Process) INodeConnector(org.talend.core.model.process.INodeConnector) IElementParameter(org.talend.core.model.process.IElementParameter) ElementParameter(org.talend.designer.core.model.components.ElementParameter) SubjobContainer(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainer) IElementParameter(org.talend.core.model.process.IElementParameter) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) List(java.util.List) ArrayList(java.util.ArrayList) IExternalNode(org.talend.core.model.process.IExternalNode) IGraphicalNode(org.talend.core.ui.process.IGraphicalNode) Connection(org.talend.designer.core.ui.editor.connections.Connection) IConnection(org.talend.core.model.process.IConnection) Point(org.eclipse.draw2d.geometry.Point) Dimension(org.eclipse.draw2d.geometry.Dimension) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) Point(org.eclipse.draw2d.geometry.Point) MessageBox(org.eclipse.swt.widgets.MessageBox) IJobletProviderService(org.talend.core.ui.IJobletProviderService) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

INodeConnector (org.talend.core.model.process.INodeConnector)76 ArrayList (java.util.ArrayList)37 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)31 INode (org.talend.core.model.process.INode)31 Node (org.talend.designer.core.ui.editor.nodes.Node)31 IConnection (org.talend.core.model.process.IConnection)27 IElementParameter (org.talend.core.model.process.IElementParameter)22 Process (org.talend.designer.core.ui.editor.process.Process)21 List (java.util.List)20 Connection (org.talend.designer.core.ui.editor.connections.Connection)17 IJobletProviderService (org.talend.core.ui.IJobletProviderService)14 HashMap (java.util.HashMap)11 NodeConnector (org.talend.designer.core.model.components.NodeConnector)11 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)9 EConnectionType (org.talend.core.model.process.EConnectionType)9 Map (java.util.Map)8 IExternalNode (org.talend.core.model.process.IExternalNode)7 IProcess (org.talend.core.model.process.IProcess)7 RepositoryNode (org.talend.repository.model.RepositoryNode)7 Point (org.eclipse.draw2d.geometry.Point)6