Search in sources :

Example 31 with IConnection

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

the class TableByRowController method init.

// when delete the input link should delete the data in the model
private void init(IElement elem, final IElementParameter param) {
    if (elem instanceof Node) {
        List<IConnection> listConnection = (List<IConnection>) ((Node) elem).getInputs();
        List<String> names = new ArrayList<String>();
        for (IConnection con : listConnection) {
            names.add(con.getName());
        }
        List<Map<String, Object>> tableValues = (List<Map<String, Object>>) param.getValue();
        for (Map<String, Object> map : tableValues) {
            Iterator it = map.keySet().iterator();
            while (it.hasNext()) {
                String key = (String) it.next();
                if (!names.contains(key)) {
                    it.remove();
                }
            }
        }
    }
}
Also used : Node(org.talend.designer.core.ui.editor.nodes.Node) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) Map(java.util.Map) HashMap(java.util.HashMap)

Example 32 with IConnection

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

the class HL7OutputManager method initModel.

public void initModel() {
    List<? extends IConnection> incomingConnections = NodeUtil.getIncomingConnections(hl7Component, IConnectionCategory.FLOW);
    // HL7Root root = new HL7Root("root");
    List<Map<String, String>> maps = (List<Map<String, String>>) ElementParameterParser.getObjectValue(hl7Component, //$NON-NLS-1$
    "__SCHEMAS__");
    List<String> schemaList = new ArrayList<String>();
    for (IMetadataTable table : hl7Component.getMetadataList()) {
        if (table.getLabel() != null) {
            schemaList.add(table.getLabel());
        }
    }
    List<Map<String, String>> rootTable = hl7Component.getTableList(HL7InputComponent.ROOT);
    Map<String, IMetadataTable> schemaNameToInputTable = new HashMap<String, IMetadataTable>();
    if (!maps.isEmpty()) {
        for (Map<String, String> map : maps) {
            String schemaName = map.get("SCHEMA");
            int first = schemaName.indexOf("_");
            int second = schemaName.lastIndexOf("_");
            if (first > 0 && first < second) {
                schemaName = schemaName.substring(first + 1, second);
            }
            IMetadataTable metadataTable = null;
            for (IConnection connection : incomingConnections) {
                if (connection.getUniqueName().equals(map.get("PARENT_ROW"))) {
                    metadataTable = connection.getMetadataTable();
                    metadataTable.setLabel(connection.getUniqueName());
                    schemaNameToInputTable.put(schemaName, metadataTable);
                    break;
                }
            }
        }
    } else {
        for (String schemaName : schemaList) {
            IMetadataTable metadataTable = null;
            for (IConnection connection : incomingConnections) {
                if (connection.getUniqueName().equals(schemaName)) {
                    metadataTable = connection.getMetadataTable();
                    metadataTable.setLabel(connection.getUniqueName());
                    schemaNameToInputTable.put(schemaName, metadataTable);
                }
            }
        }
    }
    Map<String, HL7TreeNode> mapNodes = new HashMap<String, HL7TreeNode>();
    treeData = new ArrayList<HL7TreeNode>();
    HL7TreeNode rootNode = null;
    HL7TreeNode current = null;
    HL7TreeNode temp = null;
    String currentPath = null;
    String defaultValue = null;
    int nodeOrder = 0;
    boolean haveOrder = true;
    // build root tree
    for (Map<String, String> rootMap : rootTable) {
        String newPath = rootMap.get(HL7InputComponent.PATH);
        String columnName = rootMap.get(HL7InputComponent.COLUMN);
        defaultValue = rootMap.get(HL7InputComponent.VALUE);
        String orderValue = rootMap.get(HL7InputComponent.ORDER);
        boolean repeatable = Boolean.valueOf(rootMap.get("REPEATABLE"));
        if (orderValue == null || "".equals(orderValue)) {
            haveOrder = false;
        }
        String rowName = columnName;
        if (columnName != null && columnName.contains(":")) {
            String[] names = columnName.split(":");
            rowName = names[0];
            columnName = names[1];
        } else {
            columnName = null;
        }
        temp = this.addElement(current, currentPath, newPath, defaultValue, mapNodes);
        if (temp == null) {
            // should not happen
            continue;
        }
        if (rootNode == null) {
            rootNode = temp;
        }
        if (rootMap.get(HL7InputComponent.ATTRIBUTE).equals("main")) {
            //$NON-NLS-1$
            temp.setMain(true);
        }
        current = temp;
        currentPath = newPath;
        temp.setRepetable(repeatable);
        if (haveOrder) {
            temp.setOrder(nodeOrder);
        }
        if (rowName != null && rowName.length() > 0) {
            temp.setRow(rowName);
        }
        if (columnName != null) {
            IMetadataTable metadataTable = schemaNameToInputTable.get(rowName);
            // group node can not get the metadata table
            if (metadataTable == null) {
                IMetadataTable metadataTableTemp = null;
                for (IConnection connection : incomingConnections) {
                    metadataTableTemp = connection.getMetadataTable();
                    String connectionName = metadataTableTemp.getLabel();
                    if (connectionName == null) {
                        connectionName = connection.getUniqueName();
                    }
                    if (columnName.startsWith(connectionName)) {
                        break;
                    }
                }
                temp.setColumnName(columnName);
                if (metadataTableTemp != null) {
                    temp.setColumn(metadataTableTemp.getColumn(columnName));
                    temp.setTable(metadataTableTemp);
                }
            } else {
                temp.setColumnName(columnName);
                temp.setColumn(metadataTable.getColumn(columnName));
                temp.setTable(metadataTable);
            }
        }
    }
    if (rootNode == null) {
        rootNode = new Element("rootTag");
    }
    if (haveOrder) {
        orderNode(rootNode);
    }
    // the root node should not set the ColumnLabel
    if (rootNode.getRow() != null) {
        rootNode.setRow(null);
    }
    treeData.add(rootNode);
    contents.put(rootNode.getColumnLabel(), treeData);
    initCurrentSchema();
}
Also used : HashMap(java.util.HashMap) Element(org.talend.designer.hl7.ui.data.Element) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) HL7TreeNode(org.talend.designer.hl7.ui.data.HL7TreeNode) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 33 with IConnection

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

the class UIManager method setTraceFilterParaMapper.

/**
     * DOC wzhang Comment method "setTraceFilterParaMapper".
     */
public void setTraceFilterParaMapper(Map<IConnection, Set<String>> preColumnSet, List<? extends AbstractInOutTable> curTables, Map<IConnection, Map<String, String>> changedColumnMap) {
    for (IConnection curConn : preColumnSet.keySet()) {
        Set<String> addedColumns = new HashSet<String>();
        Set<String> preColSet = preColumnSet.get(curConn);
        Map<String, String> changedColumns = changedColumnMap.get(curConn);
        for (AbstractInOutTable table : curTables) {
            String curTableName = table.getName();
            if (curTableName.equals(curConn.getUniqueName())) {
                if (changedColumns != null) {
                    for (String newName : changedColumns.keySet()) {
                        String oldName = changedColumns.get(newName);
                        if (preColSet.contains(oldName)) {
                            preColSet.remove(oldName);
                            preColSet.add(newName);
                        }
                    }
                }
                List<IMetadataColumn> curTableColumn = table.getMetadataTable().getListColumns();
                for (IMetadataColumn curColumn : curTableColumn) {
                    if (!(preColSet.contains(curColumn.getLabel()))) {
                        addedColumns.add(curColumn.getLabel());
                    }
                }
            }
        }
        CorePlugin.getDefault().getDesignerCoreService().updateTraceColumnValues(curConn, changedColumns, addedColumns);
    }
}
Also used : AbstractInOutTable(org.talend.designer.mapper.model.table.AbstractInOutTable) IConnection(org.talend.core.model.process.IConnection) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) HashSet(java.util.HashSet)

Example 34 with IConnection

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

the class MapDataHelper method rebuildModelInputs.

public void rebuildModelInputs(List<? extends IConnection> inputConn, XmlMapData mapData) {
    // remove no used input tree
    if (mapData.getInputTrees().size() != inputConn.size()) {
        List treesToRemove = new ArrayList();
        for (InputXmlTree inputTree : mapData.getInputTrees()) {
            boolean found = false;
            for (IConnection connection : inputConn) {
                if (inputTree.getName().equals(connection.getName())) {
                    found = true;
                }
            }
            if (!found) {
                for (TreeNode treeNode : inputTree.getNodes()) {
                    XmlMapUtil.detachNodeConnections(treeNode, mapData, true);
                }
                treesToRemove.add(inputTree);
                XmlMapUtil.detachFilterSource(inputTree, mapData);
            }
        }
        mapData.getInputTrees().removeAll(treesToRemove);
    }
    for (IConnection inData : inputConn) {
        String name = inData.getName();
        InputXmlTree inputTree = null;
        for (InputXmlTree in : mapData.getInputTrees()) {
            if (in.getName() != null && in.getName().equals(name)) {
                inputTree = in;
                break;
            }
        }
        if (inputTree == null) {
            inputTree = XmlmapFactory.eINSTANCE.createInputXmlTree();
            inputTree.setName(name);
            inputTree.setLookup(EConnectionType.FLOW_MAIN != inData.getLineStyle());
            mapData.getInputTrees().add(inputTree.isLookup() ? mapData.getInputTrees().size() : 0, inputTree);
        } else {
            inputTree.setLookup(EConnectionType.FLOW_MAIN != inData.getLineStyle());
        }
        if (inputTree.getLookupMode() == null) {
            inputTree.setLookupMode(XML_MAP_LOOKUP_MODE.LOAD_ONCE.toString());
        }
        if (inputTree.getMatchingMode() == null) {
            inputTree.setMatchingMode(XML_MAP_MATCHING_MODE.ALL_ROWS.toString());
        }
        rebuildInputTree(inputTree, inData.getMetadataTable(), mapData);
    }
}
Also used : InputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) ArrayList(java.util.ArrayList) List(java.util.List) IConnection(org.talend.core.model.process.IConnection)

Example 35 with IConnection

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

the class ConnectionManager method canConnect.

private static boolean canConnect(INode source, INode target, EConnectionType connType, String connectionName, boolean refactorJoblet) {
    if (source.equals(target)) {
        return false;
    }
    if (!refactorJoblet && (!target.isActivate() || !source.isActivate())) {
        return false;
    }
    boolean skipSameProcessTest = false;
    if (newlineStyle.equals(EConnectionType.FLOW_MAIN)) {
        int nbMain = 0;
        for (IConnection connec : target.getIncomingConnections()) {
            if (connec.getLineStyle().equals(EConnectionType.FLOW_MAIN)) {
                nbMain++;
            }
        }
        int maxFlowInput = 0;
        if (target.getConnectorFromName(EConnectionType.FLOW_MAIN.getName()) != null) {
            maxFlowInput = target.getConnectorFromName(EConnectionType.FLOW_MAIN.getName()).getMaxLinkInput();
        }
        if (maxFlowInput > 1 && nbMain >= 1 && (nbMain <= maxFlowInput || maxFlowInput == -1)) {
            // if the component accept several connections on the input, all inputs must come from the same process
            boolean isExtensionComponent = false;
            AbstractProcessProvider findProcessProviderFromPID = AbstractProcessProvider.findProcessProviderFromPID(IComponent.JOBLET_PID);
            if (findProcessProviderFromPID != null) {
                isExtensionComponent = findProcessProviderFromPID.isExtensionComponent(target);
            }
            if (!isExtensionComponent && !source.sameProcessAs(target, false)) {
                return false;
            }
            skipSameProcessTest = true;
        }
    }
    if (!skipSameProcessTest && source.sameProcessAs(target, false)) {
        return false;
    }
    // limit the use of the tUnite, avoid a conflict in case source link is in a merge part, and target use merge.
    if (!source.getLinkedMergeInfo().isEmpty() && (!target.getLinkedMergeInfo().isEmpty() || target.getComponent().useMerge())) {
        return false;
    }
    // Check existing connections to avoid to have more than one link
    // no matter the type of the connection and the direction
    List<Connection> connections = new ArrayList<Connection>((List<Connection>) source.getOutgoingConnections());
    connections.removeAll(source.getOutgoingConnections(EConnectionType.FLOW_MAIN));
    // connections = source.getOutgoingConnections();
    for (int i = 0; i < connections.size(); i++) {
        if ((connections.get(i)).getTarget().equals(target)) {
            return false;
        }
    }
    connections = new ArrayList<Connection>((List<Connection>) source.getIncomingConnections());
    connections.removeAll(source.getIncomingConnections(EConnectionType.FLOW_MAIN));
    // connections = source.getIncomingConnections();
    for (int i = 0; i < connections.size(); i++) {
        if ((connections.get(i)).getSource().equals(target)) {
            return false;
        }
    }
    if (connType.hasConnectionCategory(IConnectionCategory.DEPENDENCY)) {
        if (!(Boolean) target.getPropertyValue(EParameterName.STARTABLE.getName())) {
            return false;
        }
        boolean isJoblet = false;
        if (PluginChecker.isJobLetPluginLoaded()) {
            IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
            if (service != null) {
                if (service.isJobletComponent(target) && !connType.hasConnectionCategory(IConnectionCategory.FLOW)) {
                    List<INodeConnector> freeTriggerBuiltConnectors = service.getFreeTriggerBuiltConnectors(target, connType, true);
                    if (freeTriggerBuiltConnectors.isEmpty()) {
                        return false;
                    }
                    isJoblet = true;
                }
                // for bug 10973
                if (service.isTriggerNode(target) && target.getIncomingConnections() != null && target.getIncomingConnections().size() >= 1) {
                    return false;
                }
            }
        }
        if (!isJoblet && !target.isELTComponent() && !target.isSubProcessStart()) {
            return false;
        }
    }
    connections = (List<Connection>) target.getIncomingConnections();
    for (int i = 0; i < connections.size(); i++) {
        if (connType == EConnectionType.TABLE || connType == EConnectionType.TABLE_REF) {
            if ((connections.get(i)).isActivate()) {
                if ((connections.get(i)).getName().equals(connectionName)) {
                    return false;
                }
            }
        }
    }
    boolean targetHasHashLinks = ((Process) target.getProcess()).isThereLinkWithHash(target) | newlineStyle.hasConnectionCategory(IConnectionCategory.USE_HASH);
    if (connType.hasConnectionCategory(IConnectionCategory.CONDITION)) {
        if (targetHasHashLinks) {
            return false;
        }
    }
    if (targetHasHashLinks && source.hasRunIfLink()) {
        return false;
    }
    return true;
}
Also used : IJobletProviderService(org.talend.core.ui.IJobletProviderService) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) Connection(org.talend.designer.core.ui.editor.connections.Connection) IConnection(org.talend.core.model.process.IConnection) ArrayList(java.util.ArrayList) List(java.util.List) INodeConnector(org.talend.core.model.process.INodeConnector)

Aggregations

IConnection (org.talend.core.model.process.IConnection)149 ArrayList (java.util.ArrayList)79 INode (org.talend.core.model.process.INode)63 List (java.util.List)60 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)57 Node (org.talend.designer.core.ui.editor.nodes.Node)47 HashMap (java.util.HashMap)36 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)33 IElementParameter (org.talend.core.model.process.IElementParameter)31 Map (java.util.Map)25 Connection (org.talend.designer.core.ui.editor.connections.Connection)25 INodeConnector (org.talend.core.model.process.INodeConnector)24 Point (org.eclipse.swt.graphics.Point)13 Process (org.talend.designer.core.ui.editor.process.Process)13 IJobletProviderService (org.talend.core.ui.IJobletProviderService)12 HashSet (java.util.HashSet)11 MetadataTable (org.talend.core.model.metadata.MetadataTable)10 IProcess (org.talend.core.model.process.IProcess)10 ChangeMetadataCommand (org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand)9 IExternalNode (org.talend.core.model.process.IExternalNode)8