Search in sources :

Example 56 with IMetadataTable

use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.

the class JobSettingsManager method getSchemaTablefromComponent.

private static IMetadataTable getSchemaTablefromComponent(final String componentName, final String tableName) {
    IComponent tmpComponent = ComponentsFactoryProvider.getInstance().get(componentName, ComponentCategory.CATEGORY_4_DI.getName());
    //$NON-NLS-1$
    DataNode tmpNode = new DataNode(tmpComponent, "tmp");
    for (int k = 0; k < tmpNode.getElementParameters().size(); k++) {
        IElementParameter currentParam = tmpNode.getElementParameters().get(k);
        if (currentParam.getFieldType().equals(EParameterFieldType.SCHEMA_TYPE) || currentParam.getFieldType().equals(EParameterFieldType.SCHEMA_REFERENCE)) {
            Object value = currentParam.getValue();
            if (value instanceof IMetadataTable) {
                IMetadataTable table = null;
                if (LanguageManager.getCurrentLanguage().equals(ECodeLanguage.JAVA)) {
                    table = ((IMetadataTable) value).clone(true);
                } else {
                    table = ((IMetadataTable) value).clone();
                }
                table.setTableName(tableName);
                table.setAttachedConnector(currentParam.getContext());
                // fix for TUP-3972: set defult value
                for (IMetadataColumn column : table.getListColumns()) {
                    column.setDefault("\"\"");
                }
                return table;
            }
        }
    }
    return null;
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IComponent(org.talend.core.model.components.IComponent) DataNode(org.talend.designer.core.model.process.DataNode) IElementParameter(org.talend.core.model.process.IElementParameter) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn)

Example 57 with IMetadataTable

use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.

the class NodesPasteCommand method createNodeContainerList.

@SuppressWarnings("unchecked")
private void createNodeContainerList() {
    int firstIndex = 0;
    int index = 0;
    nodeContainerList = new ArrayList<NodeContainer>();
    jobletNodeToExpand = 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>();
    ITestContainerGEFService testContainerService = null;
    Map<SubjobContainer, List<Node>> junitGroup = null;
    if (isJunitCreate()) {
        if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerGEFService.class)) {
            testContainerService = (ITestContainerGEFService) GlobalServiceRegister.getDefault().getService(ITestContainerGEFService.class);
            if (testContainerService != null) {
                junitGroup = testContainerService.caculateJunitGroup(nodeParts);
            }
        }
        if (nodeMap == null) {
            nodeMap = new HashMap<IGraphicalNode, IGraphicalNode>();
        }
    }
    // create the nodes
    for (NodePart copiedNodePart : nodeParts) {
        IGraphicalNode copiedNode = (IGraphicalNode) copiedNodePart.getModel();
        if (!containNodeInProcess(copiedNode)) {
            continue;
        }
        IComponent component = ComponentsFactoryProvider.getInstance().get(copiedNode.getComponent().getName(), process.getComponentsType());
        if (component == null) {
            boolean isJobletInOutComponent = false;
            if (PluginChecker.isJobLetPluginLoaded()) {
                IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
                if (service != null && service.isJobletInOutComponent(copiedNode)) {
                    isJobletInOutComponent = true;
                }
            }
            if (isJobletInOutComponent) {
                component = copiedNode.getComponent();
            } else {
                component = new DummyComponent(copiedNode.getComponent().getName());
            }
        }
        IGraphicalNode pastedNode = new Node(component, process);
        if (nodeMap != null) {
            nodeMap.put(copiedNode, pastedNode);
        }
        if (isJobletRefactor() || isJunitCreate()) {
            // keep original for joblet refactor.
            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 = copiedNode.getLocation();
        } else {
            location = getCursorLocation();
            index = nodeParts.indexOf(copiedNodePart);
        }
        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, copiedNode.getSize(), index, firstIndex, copiedNodePart));
        pastedNode.setSize(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 {
                    if (metaTable.getTableName().equals(copiedNode.getUniqueName())) {
                        newTable.setTableName(createNewConnectionName(pastedNode.getUniqueName(), null));
                    } 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);
        }
        // TDQ-10039 extract this code from above "else",aslo consider tMatchGroup.
        if (mainConnector.isMultiSchema() || copiedNode.getComponent().getName().startsWith("tMatchGroup")) {
            //$NON-NLS-1$
            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());
                }
                if (copiedNode.getExternalNode().getExternalEmfData() != null) {
                    externalNode.setExternalEmfData(EcoreUtil.copy(copiedNode.getExternalNode().getExternalEmfData()));
                }
                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 (elementParameter != null) {
                        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 (!oldMetaToNewMeta.isEmpty()) {
                                    boolean isSAPBapiInputSchema = //$NON-NLS-1$
                                    "MAPPING_INPUT".equals(param.getName()) && //$NON-NLS-1$
                                    "tSAPBapi".equals(copiedNode.getComponent().getName());
                                    if (EParameterName.SCHEMAS.name().equals(param.getName()) || isSAPBapiInputSchema) {
                                        String newSchemaName = oldMetaToNewMeta.get(pastedNode.getUniqueName() + ":" + map.get(EParameterName.SCHEMA.getName()));
                                        if (newSchemaName != null) {
                                            newMap.put(EParameterName.SCHEMA.getName(), newSchemaName);
                                        }
                                    }
                                }
                                newValues.add(newMap);
                            }
                            // fix for TDI-7988 paste tFixedFlowInput inline table
                            Object[] copiedListItem = param.getListItemsValue();
                            if (copiedListItem != null) {
                                Object[] pasetedListItem = elementParameter.getListItemsValue();
                                if (pasetedListItem == null || pasetedListItem.length != copiedListItem.length) {
                                    elementParameter.setListItemsValue(copiedListItem);
                                    elementParameter.setListItemsDisplayCodeName(param.getListItemsDisplayCodeName());
                                    elementParameter.setListItemsDisplayName(param.getListItemsDisplayName());
                                }
                            }
                            elementParameter.setValue(newValues);
                        } else {
                            if (param.getParentParameter() != null) {
                                String parentName = param.getParentParameter().getName();
                                //$NON-NLS-1$
                                pastedNode.setPropertyValue(parentName + ":" + param.getName(), param.getValue());
                            } else if (param.getName().equals("SOURCE_GENERATED_TDM_STRUCT_PATH") || param.getName().equals("TARGET_GENERATED_TDM_STRUCT_PATH") || param.getName().equals("SOURCE_TDM_STRUCT_INCARNATION") || param.getName().equals("TARGET_TDM_STRUCT_INCARNATION")) {
                                elementParameter.setReadOnly(param.getOriginalityReadOnly());
                                elementParameter.setRepositoryValueUsed(param.isRepositoryValueUsed());
                            } 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());
                            }
                        }
                    }
                }
            }
        }
        List<Node> pastedNodeList = null;
        if (junitGroup != null) {
            pastedNodeList = junitGroup.get(((Node) copiedNode).getNodeContainer().getSubjobContainer());
        }
        NodeContainer nc = ((Process) pastedNode.getProcess()).loadNodeContainer((Node) pastedNode, ((Node) copiedNode).isJunitStart() && isJunitCreate());
        if (pastedNodeList != null) {
            pastedNodeList.remove(copiedNode);
            pastedNodeList.add((Node) pastedNode);
        }
        nodeContainerList.add(nc);
        if (selectedExpandedJoblet != null && selectedExpandedJoblet.contains(copiedNodePart)) {
            jobletNodeToExpand.add(nc);
        }
    }
    ((Process) process).setCopyPasteSubjobMappings(mapping);
    Map<String, String> oldToNewConnVarMap = new HashMap<String, String>();
    // add the connections
    for (NodePart copiedNodePart : nodeParts) {
        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));
                    }
                }
            }
        }
    }
    if (isJunitCreate()) {
        if (testContainerService != null) {
            testContainerService.setTestNodes(nodeMap, junitGroup, nodeContainerList);
        }
    }
}
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) DummyComponent(org.talend.designer.core.model.components.DummyComponent) SubjobContainer(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainer) IElementParameter(org.talend.core.model.process.IElementParameter) ITestContainerGEFService(org.talend.designer.core.ITestContainerGEFService) List(java.util.List) ArrayList(java.util.ArrayList) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) 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) 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) NodePart(org.talend.designer.core.ui.editor.nodes.NodePart) Map(java.util.Map) HashMap(java.util.HashMap)

Example 58 with IMetadataTable

use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.

the class ChangeValuesFromRepository method execute.

@SuppressWarnings("unchecked")
@Override
public void execute() {
    // Force redraw of Commponents propoerties
    elem.setPropertyValue(updataComponentParamName, new Boolean(true));
    boolean allowAutoSwitch = true;
    IElementParameter elemParam = elem.getElementParameter(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
    if (elemParam != null) {
        // add for TDI-8053
        elemParam.setValue(Boolean.FALSE);
        allowAutoSwitch = (Boolean) elemParam.getValue();
    }
    if (!allowAutoSwitch && (elem instanceof Node)) {
        // force the autoSwitch to true if the schema is empty and if the
        // query is not set.
        Node node = (Node) elem;
        boolean isSchemaEmpty = false;
        if (node.getMetadataList().size() > 0) {
            isSchemaEmpty = node.getMetadataList().get(0).getListColumns().size() == 0;
        } else {
            isSchemaEmpty = true;
        }
        for (IElementParameter curParam : node.getElementParameters()) {
            if (curParam.getFieldType().equals(EParameterFieldType.MEMO_SQL)) {
                if (curParam.getDefaultValues().size() > 0) {
                }
            }
        }
        if (isSchemaEmpty) {
            allowAutoSwitch = true;
        }
        if (((INode) elem).getComponent().getName().equals("tWebService")) {
            //$NON-NLS-1$
            allowAutoSwitch = true;
        }
    }
    if (propertyName.split(":")[1].equals(propertyTypeName)) {
        //$NON-NLS-1$
        elem.setPropertyValue(propertyName, value);
        if (allowAutoSwitch) {
            // Update spark mode to YARN_CLIENT if repository
            if (elem instanceof IProcess) {
                if (ComponentCategory.CATEGORY_4_SPARK.getName().equals(((IProcess) elem).getComponentsType()) || ComponentCategory.CATEGORY_4_SPARKSTREAMING.getName().equals(((IProcess) elem).getComponentsType())) {
                    if (EmfComponent.REPOSITORY.equals(value)) {
                        IElementParameter sparkLocalParam = ((IProcess) elem).getElementParameter(HadoopConstants.SPARK_LOCAL_MODE);
                        IElementParameter sparkParam = ((IProcess) elem).getElementParameter(HadoopConstants.SPARK_MODE);
                        if (sparkLocalParam != null && (Boolean) (sparkLocalParam.getValue())) {
                            sparkLocalParam.setValue(false);
                        }
                        if (sparkParam != null && !HadoopConstants.SPARK_MODE_YARN_CLIENT.equals(sparkParam.getValue())) {
                            sparkParam.setValue(HadoopConstants.SPARK_MODE_YARN_CLIENT);
                        }
                    }
                }
            }
            setOtherProperties();
        }
    } else {
        oldMetadata = (String) elem.getPropertyValue(propertyName);
        elem.setPropertyValue(propertyName, value);
        if (allowAutoSwitch) {
            setOtherProperties();
        }
    }
    String propertyParamName = null;
    if (elem.getElementParameter(propertyName).getParentParameter() != null) {
        IElementParameter param = elem.getElementParameter(propertyName).getParentParameter();
        if (param.getFieldType() == EParameterFieldType.PROPERTY_TYPE) {
            propertyParamName = param.getName();
        }
    }
    if (propertyName.split(":")[1].equals(propertyTypeName) && (EmfComponent.BUILTIN.equals(value))) {
        //$NON-NLS-1$
        for (IElementParameter param : elem.getElementParameters()) {
            if (param.getRepositoryProperty() != null && !param.getRepositoryProperty().equals(propertyParamName)) {
                continue;
            }
            boolean paramFlag = JobSettingsConstants.isExtraParameter(param.getName());
            //$NON-NLS-1$
            boolean extraFlag = JobSettingsConstants.isExtraParameter(propertyName.split(":")[0]);
            if (paramFlag == extraFlag) {
                // for memo sql
                if (param.getFieldType() == EParameterFieldType.MEMO_SQL) {
                    IElementParameter querystoreParam = elem.getElementParameterFromField(EParameterFieldType.QUERYSTORE_TYPE, param.getCategory());
                    if (querystoreParam != null) {
                        Map<String, IElementParameter> childParam = querystoreParam.getChildParameters();
                        if (childParam != null) {
                            IElementParameter queryTypeParam = childParam.get(EParameterName.QUERYSTORE_TYPE.getName());
                            if (queryTypeParam != null && EmfComponent.REPOSITORY.equals(queryTypeParam.getValue())) {
                                continue;
                            }
                        }
                    }
                }
                if (param.getRepositoryValue() != null) {
                    param.setReadOnly(false);
                    // for job settings extra.(feature 2710)
                    param.setRepositoryValueUsed(false);
                }
            }
        }
    } else {
        oldValues.clear();
        List<ComponentProperties> componentProperties = null;
        IGenericWizardService wizardService = null;
        if (GlobalServiceRegister.getDefault().isServiceRegistered(IGenericWizardService.class)) {
            wizardService = (IGenericWizardService) GlobalServiceRegister.getDefault().getService(IGenericWizardService.class);
        }
        if (wizardService != null && wizardService.isGenericConnection(connection)) {
            componentProperties = wizardService.getAllComponentProperties(connection, null);
        }
        IElementParameter propertyParam = elem.getElementParameter(propertyName);
        List<IElementParameter> elementParameters = new ArrayList<>(elem.getElementParameters());
        for (IElementParameter param : elementParameters) {
            String repositoryValue = param.getRepositoryValue();
            if (param.getFieldType() == EParameterFieldType.PROPERTY_TYPE) {
                continue;
            }
            boolean isGenericRepositoryValue = RepositoryToComponentProperty.isGenericRepositoryValue(connection, componentProperties, param.getName());
            if (repositoryValue == null && isGenericRepositoryValue) {
                repositoryValue = param.getName();
                param.setRepositoryValue(repositoryValue);
                param.setRepositoryValueUsed(true);
            }
            if (repositoryValue == null || param.getRepositoryProperty() != null && !param.getRepositoryProperty().equals(propertyParamName)) {
                continue;
            }
            String componentName = elem instanceof INode ? (((INode) elem).getComponent().getName()) : null;
            boolean b = elem instanceof INode && (//$NON-NLS-1$
            ((INode) elem).getComponent().getName().equals("tHL7Input") || //$NON-NLS-1$
            ((INode) elem).getComponent().getName().equals("tAdvancedFileOutputXML") || ((INode) elem).getComponent().getName().equals("tMDMOutput") || ((INode) elem).getComponent().getName().equals("tWebService") || ((INode) elem).getComponent().getName().equals("tCreateTable") || //$NON-NLS-1$
            ((INode) elem).getComponent().getName().equals("tWriteJSONField"));
            if ((//$NON-NLS-1$
            "TYPE".equals(repositoryValue) || (isGenericRepositoryValue || param.isShow(elem.getElementParameters())) || b) && (!param.getName().equals(propertyTypeName))) {
                if (param.getRepositoryProperty() != null && !param.getRepositoryProperty().equals(propertyParamName)) {
                    continue;
                }
                Object objectValue = null;
                if (connection instanceof XmlFileConnection && this.dragAndDropAction == true && repositoryValue.equals("FILE_PATH") && reOpenXSDBool == true) {
                    objectValue = RepositoryToComponentProperty.getXmlAndXSDFileValue((XmlFileConnection) connection, repositoryValue);
                } else if (connection instanceof SalesforceSchemaConnection && "MODULENAME".equals(repositoryValue)) {
                    //$NON-NLS-1$
                    if (this.moduleUnit != null) {
                        objectValue = moduleUnit.getModuleName();
                    } else {
                        objectValue = null;
                    }
                } else // module which was the last one be retrived
                if (connection instanceof SalesforceSchemaConnection && "CUSTOM_MODULE_NAME".equals(repositoryValue)) {
                    //$NON-NLS-1$
                    if (this.moduleUnit != null) {
                        objectValue = moduleUnit.getModuleName();
                    } else {
                        objectValue = null;
                    }
                } else if (connection instanceof MDMConnection) {
                    if (table == null) {
                        IMetadataTable metaTable = null;
                        if (((Node) elem).getMetadataList().size() > 0) {
                            metaTable = ((Node) elem).getMetadataList().get(0);
                        }
                        objectValue = RepositoryToComponentProperty.getValue(connection, repositoryValue, metaTable);
                    } else {
                        objectValue = RepositoryToComponentProperty.getValue(connection, repositoryValue, table);
                    }
                } else if (connection instanceof WSDLSchemaConnection && "USE_PROXY".equals(repositoryValue)) {
                    //$NON-NLS-1$
                    objectValue = ((WSDLSchemaConnection) connection).isUseProxy();
                } else {
                    IMetadataTable metaTable = table;
                    if (metaTable == null && elem instanceof Node) {
                        INodeConnector conn = ((Node) elem).getConnectorFromType(EConnectionType.FLOW_MAIN);
                        if (conn != null && conn.getMaxLinkOutput() == 1) {
                            metaTable = ((Node) elem).getMetadataFromConnector(conn.getName());
                        }
                    }
                    objectValue = RepositoryToComponentProperty.getValue(connection, repositoryValue, metaTable, componentName);
                }
                if (GlobalServiceRegister.getDefault().isServiceRegistered(IJsonFileService.class)) {
                    IJsonFileService jsonService = (IJsonFileService) GlobalServiceRegister.getDefault().getService(IJsonFileService.class);
                    boolean paramChanged = jsonService.changeFilePathFromRepository(connection, param, elem, objectValue);
                    if (paramChanged) {
                        continue;
                    }
                }
                if (objectValue != null) {
                    oldValues.put(param.getName(), param.getValue());
                    if (param.getFieldType().equals(EParameterFieldType.CLOSED_LIST) && param.getRepositoryValue().equals("TYPE")) {
                        //$NON-NLS-1$
                        String dbVersion = "";
                        if (connection instanceof DatabaseConnection) {
                            dbVersion = ((DatabaseConnection) connection).getDbVersionString();
                        }
                        boolean found = false;
                        String[] list = param.getListRepositoryItems();
                        for (int i = 0; (i < list.length) && (!found); i++) {
                            if (objectValue.equals(list[i])) {
                                found = true;
                                elem.setPropertyValue(param.getName(), param.getListItemsValue()[i]);
                            }
                        }
                        IElementParameter elementParameter = null;
                        IElementParameter elementParameter2 = null;
                        if (EParameterName.DB_TYPE.getName().equals(param.getName())) {
                            elementParameter = elem.getElementParameter(EParameterName.DB_VERSION.getName());
                            elementParameter2 = elem.getElementParameter(EParameterName.SCHEMA_DB.getName());
                        } else {
                            elementParameter = elem.getElementParameter(JobSettingsConstants.getExtraParameterName(EParameterName.DB_VERSION.getName()));
                            elementParameter2 = elem.getElementParameter(JobSettingsConstants.getExtraParameterName(EParameterName.SCHEMA_DB.getName()));
                        }
                        String dbType = "";
                        if (param.getValue() != null) {
                            int indexOfItemFromList = param.getIndexOfItemFromList(param.getValue().toString());
                            if (indexOfItemFromList != -1) {
                                dbType = param.getListItemsDisplayCodeName()[indexOfItemFromList];
                            }
                        }
                        // Some DB not need fill the schema parameter for the JobSetting View "Extra" ,"Stats&Logs"
                        if (elementParameter2 != null && !elementParameter2.isShow(elem.getElementParameters()) && !elementParameter2.getValue().equals("")) {
                            elementParameter2.setValue("");
                        }
                        if (StatsAndLogsConstants.JDBC.equals(dbType)) {
                            IElementParameter dbNameParm = elem.getElementParameter(EParameterName.DBNAME.getName());
                            if (dbNameParm != null) {
                                dbNameParm.setValue("");
                            }
                        } else {
                            IElementParameter rulParam = elem.getElementParameter(EParameterName.URL.getName());
                            if (rulParam != null) {
                                rulParam.setValue("");
                            }
                            IElementParameter classParam = elem.getElementParameter(EParameterName.DRIVER_CLASS.getName());
                            if (classParam != null) {
                                classParam.setValue("");
                            }
                            IElementParameter jarParam = elem.getElementParameter(EParameterName.DRIVER_JAR.getName());
                            if (jarParam != null) {
                                jarParam.setValue(new ArrayList<Map<String, Object>>());
                            }
                        }
                        JobSettingVersionUtil.setDbVersion(elementParameter, dbVersion, false);
                        DesignerUtilities.setSchemaDB(elementParameter2, param.getValue());
                    } else if (param.getFieldType().equals(EParameterFieldType.CLOSED_LIST) && param.getRepositoryValue().equals("FRAMEWORK_TYPE")) {
                        //$NON-NLS-1$
                        String[] list = param.getListItemsDisplayName();
                        for (int i = 0; i < list.length; i++) {
                            if (objectValue.equals(list[i])) {
                                elem.setPropertyValue(param.getName(), param.getListItemsValue()[i]);
                            }
                        }
                    } else if (param.getFieldType().equals(EParameterFieldType.CLOSED_LIST) && param.getRepositoryValue().equals("EDI_VERSION")) {
                        String[] list = param.getListItemsDisplayName();
                        for (String element : list) {
                            if (objectValue.toString().toUpperCase().equals(element)) {
                                elem.setPropertyValue(param.getName(), objectValue);
                            }
                        }
                    } else if (param.getFieldType().equals(EParameterFieldType.CLOSED_LIST) && param.getRepositoryValue().equals("DRIVER")) {
                        String[] list = param.getListItemsDisplayCodeName();
                        for (String element : list) {
                            if (objectValue.toString().toUpperCase().equals(element)) {
                                elem.setPropertyValue(param.getName(), objectValue);
                            }
                        }
                    } else if (param.getFieldType().equals(EParameterFieldType.CLOSED_LIST) && param.getRepositoryValue().equals("CONNECTION_MODE")) {
                        //$NON-NLS-1$
                        if (!objectValue.equals(param.getValue())) {
                            //$NON-NLS-1$
                            PropertyChangeCommand cmd = new PropertyChangeCommand(elem, "CONNECTION_MODE", objectValue);
                            cmd.execute();
                        }
                    } else {
                        if (repositoryValue.equals("ENCODING")) {
                            //$NON-NLS-1$
                            IElementParameter paramEncoding = param.getChildParameters().get(EParameterName.ENCODING_TYPE.getName());
                            if (connection instanceof FTPConnection) {
                                if (((FTPConnection) connection).getEcoding() != null) {
                                    paramEncoding.setValue(((FTPConnection) connection).getEcoding());
                                } else {
                                    paramEncoding.setValue(EmfComponent.ENCODING_TYPE_CUSTOM);
                                }
                            } else {
                                if (objectValue instanceof String) {
                                    String str = TalendTextUtils.removeQuotes((String) objectValue);
                                    if (str.equals(EmfComponent.ENCODING_TYPE_UTF_8)) {
                                        paramEncoding.setValue(EmfComponent.ENCODING_TYPE_UTF_8);
                                    } else if (str.equals(EmfComponent.ENCODING_TYPE_ISO_8859_15)) {
                                        paramEncoding.setValue(EmfComponent.ENCODING_TYPE_ISO_8859_15);
                                    } else {
                                        paramEncoding.setValue(EmfComponent.ENCODING_TYPE_CUSTOM);
                                    // paramEncoding.setRepositoryValueUsed(true);
                                    }
                                }
                            }
                        } else if (repositoryValue.equals("CSV_OPTION")) {
                            //$NON-NLS-1$
                            setOtherProperties();
                        }
                        if (repositoryValue.equals("MODULENAME")) {
                            //$NON-NLS-1$
                            List list = new ArrayList();
                            Object[] listItemsValue = elem.getElementParameter("MODULENAME").getListItemsValue();
                            for (Object element : listItemsValue) {
                                list.add(element);
                            }
                            if (list != null && !list.contains(objectValue)) {
                                //$NON-NLS-1$
                                objectValue = "CustomModule";
                            }
                        }
                        // hywang add for excel 2007
                        if (repositoryValue.equals(EParameterName.FILE_PATH.getName())) {
                            String filePath = "";
                            if (connection.isContextMode()) {
                                ContextItem contextItem = ContextUtils.getContextItemById2(connection.getContextId());
                                if (contextItem != null) {
                                    String selectedContext = contextItem.getDefaultContext();
                                    final ContextType contextTypeByName = ContextUtils.getContextTypeByName(contextItem, selectedContext, true);
                                    filePath = ConnectionContextHelper.getOriginalValue(contextTypeByName, objectValue.toString());
                                }
                            } else {
                                filePath = TalendTextUtils.removeQuotes(objectValue.toString());
                            }
                            boolean versionCheckFor2007 = false;
                            if (filePath != null && filePath.endsWith(".xlsx")) {
                                versionCheckFor2007 = true;
                            }
                            if (elem.getElementParameter("VERSION_2007") != null) {
                                elem.setPropertyValue("VERSION_2007", versionCheckFor2007);
                            }
                        }
                        if (param.getFieldType().equals(EParameterFieldType.FILE)) {
                            if (objectValue != null) {
                                objectValue = objectValue.toString().replace("\\", "/");
                            }
                        }
                        elem.setPropertyValue(param.getName(), objectValue);
                    }
                    param.setRepositoryValueUsed(true);
                } else if (param.getFieldType().equals(EParameterFieldType.TABLE) && param.getRepositoryValue().equals("XML_MAPPING")) {
                    //$NON-NLS-1$
                    List<Map<String, Object>> table = (List<Map<String, Object>>) elem.getPropertyValue(param.getName());
                    if (((Node) elem).getMetadataList().size() > 0) {
                        IMetadataTable metaTable = ((Node) elem).getMetadataList().get(0);
                        //$NON-NLS-1$
                        RepositoryToComponentProperty.getTableXmlFileValue(//$NON-NLS-1$
                        connection, //$NON-NLS-1$
                        "XML_MAPPING", //$NON-NLS-1$
                        param, table, metaTable);
                        param.setRepositoryValueUsed(true);
                    }
                } else if (param.getFieldType().equals(EParameterFieldType.TABLE) && param.getRepositoryValue().equals("WSDL_PARAMS") && connection != null) {
                    //$NON-NLS-1$
                    List<Map<String, Object>> table = (List<Map<String, Object>>) elem.getPropertyValue(param.getName());
                    table.clear();
                    ArrayList parameters = ((WSDLSchemaConnection) connection).getParameters();
                    if (parameters != null) {
                        for (Object object : parameters) {
                            Map<String, Object> map2 = new HashMap<String, Object>();
                            //$NON-NLS-1$
                            map2.put("VALUE", TalendTextUtils.addQuotes(object.toString()));
                            table.add(map2);
                        }
                    }
                    param.setRepositoryValueUsed(true);
                } else if (param.getFieldType().equals(EParameterFieldType.TEXT) && "XPATH_QUERY".equals(param.getRepositoryValue())) {
                    //$NON-NLS-1$
                    param.setRepositoryValueUsed(true);
                } else {
                    // For SAP
                    String paramName = param.getName();
                    if ("SAP_PROPERTIES".equals(paramName) || "MAPPING_INPUT".equals(paramName) || // INPUT_PARAMS should be MAPPING_INPUT,bug16426
                    "SAP_FUNCTION".equals(paramName) || "OUTPUT_PARAMS".equals(paramName) || "SAP_ITERATE_OUT_TYPE".equals(paramName) || "SAP_ITERATE_OUT_TABLENAME".equals(paramName)) {
                        SAPParametersUtils.retrieveSAPParams(elem, connection, param, getSapFunctionLabel());
                    }
                    if ("GATEWAYSERVICE".equals(paramName) || "PROGRAMID".equals(paramName) || "FORMAT_XML".equals(paramName) || "FILE_IDOC_XML".equals(paramName) || "FORMAT_HTML".equals(paramName) || "FILE_IDOC_HTML".equals(paramName)) {
                        SAPParametersUtils.getSAPIDocParams(elem, connection, param, getSapIDocLabel());
                    }
                }
                if (param.isRepositoryValueUsed()) {
                    if (("GENERATION_MODE").equals(param.getName())) {
                        param.setReadOnly(true);
                    } else {
                        param.setReadOnly(false);
                    }
                }
            }
        }
        // (bug 5198)
        IElementParameter parentParameter = propertyParam.getParentParameter();
        if (parentParameter != null) {
            IElementParameter param = parentParameter.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
            if (param != null && propertyParam == param) {
                // avoid to process twice.
                ConnectionItem connItem = UpdateRepositoryUtils.getConnectionItemByItemId((String) param.getValue());
                if (connItem != null) {
                    if (elem instanceof Node) {
                        ConnectionContextHelper.addContextForNodeParameter((Node) elem, connItem, ignoreContextMode);
                    } else if (elem instanceof Process) {
                        ConnectionContextHelper.addContextForProcessParameter((Process) elem, connItem, param.getCategory(), ignoreContextMode);
                    }
                }
            }
        }
    }
    toUpdate = false;
    // change AS400 value
    for (IElementParameter curParam : elem.getElementParameters()) {
        if (curParam.getFieldType().equals(EParameterFieldType.AS400_CHECK)) {
            setOtherProperties();
        }
        // change the HL7 Version
        if (connection instanceof HL7Connection) {
            if (curParam.getName().equals("HL7_VER")) {
                String hl7VersionString = connection.getVersion();
                if (hl7VersionString != null) {
                    hl7VersionString = hl7VersionString.replace(".", "");
                    curParam.setValue(hl7VersionString);
                }
            }
        }
        setDefaultValues(curParam, elem);
    }
    if (elem instanceof Node) {
        // Xstream Cdc Type Mode
        boolean isXstreamCdcTypeMode = false;
        if (connection != null && connection instanceof DatabaseConnection) {
            String cdcTypeMode = ((DatabaseConnection) connection).getCdcTypeMode();
            if (CDCTypeMode.XSTREAM_MODE == CDCTypeMode.indexOf(cdcTypeMode)) {
                isXstreamCdcTypeMode = true;
            }
        }
        if (isXstreamCdcTypeMode && ((Node) elem).getComponent().getName().equals("tOracleCDC")) {
            //$NON-NLS-1$
            IMetadataTable table = ((Node) elem).getMetadataList().get(0);
            IElementParameter schemaParam = elem.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
            schemaParam.setValueToDefault(elem.getElementParameters());
            table.setListColumns((((IMetadataTable) schemaParam.getValue()).clone(true)).getListColumns());
        }
        ((Process) ((Node) elem).getProcess()).checkProcess();
        // Added TDQ-11688 show regex when "built-in"
        ITDQPatternService service = null;
        if (GlobalServiceRegister.getDefault().isServiceRegistered(ITDQPatternService.class)) {
            service = (ITDQPatternService) GlobalServiceRegister.getDefault().getService(ITDQPatternService.class);
        }
        if (service != null && service.isSinglePatternNode(elem)) {
            IElementParameter regexParameter = ((Node) elem).getElementParameter("PATTERN_REGEX");
            if (regexParameter != null) {
                regexParameter.setShow(EmfComponent.BUILTIN.equals(this.value));
            }
        }
    }
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) INode(org.talend.core.model.process.INode) ComponentProperties(org.talend.components.api.properties.ComponentProperties) HashMap(java.util.HashMap) ConnectionItem(org.talend.core.model.properties.ConnectionItem) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) ArrayList(java.util.ArrayList) 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) IGenericWizardService(org.talend.core.runtime.services.IGenericWizardService) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) List(java.util.List) ArrayList(java.util.ArrayList) ITDQPatternService(org.talend.core.ITDQPatternService) IProcess(org.talend.core.model.process.IProcess) WSDLSchemaConnection(org.talend.core.model.metadata.builder.connection.WSDLSchemaConnection) ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) XmlFileConnection(org.talend.core.model.metadata.builder.connection.XmlFileConnection) FTPConnection(org.talend.core.model.metadata.builder.connection.FTPConnection) MDMConnection(org.talend.core.model.metadata.builder.connection.MDMConnection) IJsonFileService(org.talend.core.service.IJsonFileService) SalesforceSchemaConnection(org.talend.core.model.metadata.builder.connection.SalesforceSchemaConnection) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) Map(java.util.Map) HashMap(java.util.HashMap) HL7Connection(org.talend.core.model.metadata.builder.connection.HL7Connection)

Example 59 with IMetadataTable

use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.

the class DeleteNodeContainerCommand method execute.

@Override
@SuppressWarnings("unchecked")
public void execute() {
    connectionDeletedInfosMap = new MultiKeyMap();
    process.setActivate(false);
    List uniqueNameList = new ArrayList();
    for (INode node : nodeList) {
        if (node.getJobletNode() != null) {
            continue;
        }
        uniqueNameList.add(node.getUniqueName());
        NodeContainer nodeContainer = ((Node) node).getNodeContainer();
        ((Process) process).removeNodeContainer(nodeContainer);
        List<IConnection> inputList = (List<IConnection>) node.getIncomingConnections();
        List<IConnection> outputList = (List<IConnection>) node.getOutgoingConnections();
        boolean builtIn = node.getConnectorFromType(EConnectionType.FLOW_MAIN).isMultiSchema() | node.getConnectorFromType(EConnectionType.TABLE).isMultiSchema();
        for (IConnection connection : inputList) {
            // see bug 0002633: "rejects" link disappears at times.
            if (connection != null && connection.getSourceNodeConnector() != null) {
                connection.getSourceNodeConnector().setCurLinkNbOutput(connection.getSourceNodeConnector().getCurLinkNbOutput() - 1);
            }
            INode prevNode = connection.getSource();
            if ((prevNode instanceof Node) && ((Node) prevNode).getJobletNode() != null) {
                Node jobletnode = (Node) prevNode.getJobletNode();
                ((AbstractJobletContainer) jobletnode.getNodeContainer()).getOutputs().remove(connection);
                if (!nodeList.contains(jobletnode)) {
                    boolean builtInJobletNode = jobletnode.getConnectorFromType(EConnectionType.FLOW_MAIN).isMultiSchema() | node.getConnectorFromType(EConnectionType.TABLE).isMultiSchema();
                    storeMetadata(connection, jobletnode, true);
                    jobletnode.removeOutput(connection);
                    if (!builtInJobletNode) {
                        process.removeUniqueConnectionName(connection.getUniqueName());
                    }
                }
            }
            if (!nodeList.contains(prevNode)) {
                boolean builtInPrevNode = prevNode.getConnectorFromType(EConnectionType.FLOW_MAIN).isMultiSchema() | node.getConnectorFromType(EConnectionType.TABLE).isMultiSchema();
                boolean remove = true;
                if ((prevNode instanceof Node) && ((Node) prevNode).isELTMapComponent()) {
                    remove = false;
                }
                storeMetadata(connection, prevNode, remove);
                prevNode.removeOutput(connection);
                if (!builtInPrevNode && remove) {
                    process.removeUniqueConnectionName(connection.getUniqueName());
                }
            }
        }
        for (IConnection connection : outputList) {
            INode nextNode = connection.getTarget();
            if ((nextNode instanceof Node) && ((Node) nextNode).getJobletNode() != null) {
                Node jobletnode = (Node) nextNode.getJobletNode();
                ((AbstractJobletContainer) jobletnode.getNodeContainer()).getInputs().remove(connection);
                if (!nodeList.contains(jobletnode)) {
                    jobletnode.removeInput(connection);
                    boolean builtInJobletNode = jobletnode.getConnectorFromType(EConnectionType.FLOW_MAIN).isMultiSchema() | node.getConnectorFromType(EConnectionType.TABLE).isMultiSchema();
                    if (!builtInJobletNode) {
                        process.removeUniqueConnectionName(connection.getUniqueName());
                    }
                }
            }
            if (!nodeList.contains(nextNode)) {
                INodeConnector nodeConnector = nextNode.getConnectorFromType(connection.getLineStyle());
                nodeConnector.setCurLinkNbInput(nodeConnector.getCurLinkNbInput() - 1);
                nextNode.removeInput(connection);
                if (nextNode != null) {
                    for (int i = 0; i < nextNode.getIncomingConnections().size(); i++) {
                        Connection nextNodeConnection = (Connection) nextNode.getIncomingConnections().get(i);
                        nextNodeConnection.updateName();
                    }
                }
                if (nextNode.getExternalNode() instanceof AbstractNode) {
                    ((AbstractNode) nextNode.getExternalNode()).removeInput(connection);
                }
            }
            if (!builtIn) {
                process.removeUniqueConnectionName(connection.getUniqueName());
            }
        }
        if (builtIn) {
            for (IMetadataTable meta : node.getMetadataList()) {
                String metaName = meta.getTableName();
                process.removeUniqueConnectionName(metaName);
            }
            // for tmap remove join table names
            final List<String> names = CorePlugin.getDefault().getMapperService().getJoinTableNames(node.getExternalData());
            if (!names.isEmpty()) {
                joinTableNames.addAll(names);
                for (String name : joinTableNames) {
                    process.removeUniqueConnectionName(name);
                }
            }
        }
    }
    process.setActivate(true);
    process.checkStartNodes();
    process.checkProcess();
}
Also used : INode(org.talend.core.model.process.INode) MultiKeyMap(org.apache.commons.collections.map.MultiKeyMap) AbstractNode(org.talend.core.model.process.AbstractNode) INode(org.talend.core.model.process.INode) Node(org.talend.designer.core.ui.editor.nodes.Node) AbstractNode(org.talend.core.model.process.AbstractNode) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) Connection(org.talend.designer.core.ui.editor.connections.Connection) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) Process(org.talend.designer.core.ui.editor.process.Process) IConnection(org.talend.core.model.process.IConnection) INodeConnector(org.talend.core.model.process.INodeConnector) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) ArrayList(java.util.ArrayList) List(java.util.List)

Example 60 with IMetadataTable

use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.

the class DeleteNodeContainerCommand method undo.

@Override
@SuppressWarnings("unchecked")
public void undo() {
    process.setActivate(false);
    for (INode node : nodeList) {
        if (node.getJobletNode() != null) {
            continue;
        }
        NodeContainer nodeContainer = ((Node) node).getNodeContainer();
        this.process.addUniqueNodeName(node.getUniqueName());
        ((Process) process).addNodeContainer(nodeContainer);
        List<Connection> inputList = (List<Connection>) node.getIncomingConnections();
        List<Connection> outputList = (List<Connection>) node.getOutgoingConnections();
        boolean builtIn = node.getConnectorFromType(EConnectionType.FLOW_MAIN).isMultiSchema() | node.getConnectorFromType(EConnectionType.TABLE).isMultiSchema();
        for (Connection connection : inputList) {
            // see bug 0004514: need to undo for 0002633
            if (connection != null && connection.getSourceNodeConnector() != null) {
                connection.getSourceNodeConnector().setCurLinkNbOutput(connection.getSourceNodeConnector().getCurLinkNbOutput() + 1);
            }
            INode prevNode = connection.getSource();
            if ((prevNode instanceof Node) && ((Node) prevNode).getJobletNode() != null) {
                Node jobletnode = (Node) prevNode.getJobletNode();
                ((AbstractJobletContainer) jobletnode.getNodeContainer()).getOutputs().add(connection);
                restoreMetadata(connection, jobletnode);
            }
            if (!nodeList.contains(prevNode)) {
                if (!prevNode.getOutgoingConnections().contains(connection)) {
                    prevNode.addOutput(connection);
                }
                restoreMetadata(connection, prevNode);
                connection.reconnect();
                connection.updateAllId();
                boolean builtInPrevNode = prevNode.getConnectorFromType(EConnectionType.FLOW_MAIN).isMultiSchema() | node.getConnectorFromType(EConnectionType.TABLE).isMultiSchema();
                if (connection.getLineStyle().hasConnectionCategory(IConnectionCategory.UNIQUE_NAME) && !builtInPrevNode) {
                    // for bug 10024
                    // see 10583
                    String name = connection.getUniqueName();
                    if (connection.getConnectorName().startsWith("TRIGGER_OUTPUT")) {
                        if (process.checkValidConnectionName(name)) {
                            process.addUniqueConnectionName(name);
                        }
                    } else {
                        process.addUniqueConnectionName(name);
                    }
                }
            }
        }
        for (IConnection connection : outputList) {
            INode nextNode = connection.getTarget();
            if ((nextNode instanceof Node) && ((Node) nextNode).getJobletNode() != null) {
                Node jobletnode = (Node) nextNode.getJobletNode();
                ((AbstractJobletContainer) jobletnode.getNodeContainer()).getInputs().add(connection);
            }
            if (!nodeList.contains(nextNode)) {
                if (!nextNode.getIncomingConnections().contains(connection)) {
                    nextNode.addInput(connection);
                }
                INodeConnector nodeConnector = nextNode.getConnectorFromType(connection.getLineStyle());
                nodeConnector.setCurLinkNbInput(nodeConnector.getCurLinkNbInput() + 1);
                connection.reconnect();
                if (nextNode.getExternalNode() instanceof AbstractNode) {
                    ((AbstractNode) nextNode.getExternalNode()).addInput(connection);
                }
            }
            if (!builtIn) {
                if (connection.getLineStyle().hasConnectionCategory(IConnectionCategory.UNIQUE_NAME)) {
                    // for bug 10024
                    // see 10583
                    String name = connection.getUniqueName();
                    // name = process.generateUniqueConnectionName(name);
                    process.addUniqueConnectionName(name);
                }
            }
        }
        if (builtIn) {
            for (IMetadataTable meta : node.getMetadataList()) {
                String metaName = meta.getTableName();
                process.addUniqueConnectionName(metaName);
            }
            // tmap join table
            for (String name : joinTableNames) {
                process.addUniqueConnectionName(name);
            }
        }
    }
    process.setActivate(true);
    process.checkStartNodes();
    process.checkProcess();
}
Also used : INode(org.talend.core.model.process.INode) AbstractNode(org.talend.core.model.process.AbstractNode) INode(org.talend.core.model.process.INode) Node(org.talend.designer.core.ui.editor.nodes.Node) AbstractNode(org.talend.core.model.process.AbstractNode) IConnection(org.talend.core.model.process.IConnection) Connection(org.talend.designer.core.ui.editor.connections.Connection) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) Process(org.talend.designer.core.ui.editor.process.Process) IConnection(org.talend.core.model.process.IConnection) INodeConnector(org.talend.core.model.process.INodeConnector) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

IMetadataTable (org.talend.core.model.metadata.IMetadataTable)212 ArrayList (java.util.ArrayList)102 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)81 IElementParameter (org.talend.core.model.process.IElementParameter)67 IConnection (org.talend.core.model.process.IConnection)66 List (java.util.List)56 INode (org.talend.core.model.process.INode)54 Node (org.talend.designer.core.ui.editor.nodes.Node)50 HashMap (java.util.HashMap)48 Map (java.util.Map)39 MetadataTable (org.talend.core.model.metadata.MetadataTable)34 INodeConnector (org.talend.core.model.process.INodeConnector)32 Connection (org.talend.designer.core.ui.editor.connections.Connection)28 Process (org.talend.designer.core.ui.editor.process.Process)25 IComponent (org.talend.core.model.components.IComponent)22 ConnectionItem (org.talend.core.model.properties.ConnectionItem)20 MetadataColumn (org.talend.core.model.metadata.MetadataColumn)18 ChangeMetadataCommand (org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand)17 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)16 Point (org.eclipse.swt.graphics.Point)15