Search in sources :

Example 16 with ConnectionType

use of org.talend.designer.core.model.utils.emf.talendfile.ConnectionType in project tdi-studio-se by Talend.

the class RenametELTMigrationTask method execute.

public ExecutionResult execute(Item item) {
    final String[] source = { "tELT", "tELTAggregate", "tELTCommit", "tELTFilterColumns", "tELTFilterRows", "tELTMerge", "tELTRollback" };
    final String[] target = { "tSQLTemplate", "tSQLTemplateAggregate", "tSQLTemplateCommit", "tSQLTemplateFilterColumns", "tSQLTemplateFilterRows", "tSQLTemplateMerge", "tSQLTemplateRollback" };
    ProcessType processType = getProcessType(item);
    if (getProject().getLanguage() != ECodeLanguage.JAVA || processType == null) {
        return ExecutionResult.NOTHING_TO_DO;
    }
    try {
        for (int i = 0; i < source.length; i++) {
            final int j = i;
            IComponentFilter filter = new NameComponentFilter(source[i]);
            RenameComponentConversion renameConversion = new RenameComponentConversion(target[i]);
            IComponentConversion changeNodeNameConversion = new IComponentConversion() {

                public void transform(NodeType node) {
                    ProcessType item = (ProcessType) node.eContainer();
                    for (Object o : item.getConnection()) {
                        ConnectionType connection = (ConnectionType) o;
                        if ("RUN_IF".equals(connection.getConnectorName())) {
                            for (Object obj : connection.getElementParameter()) {
                                ElementParameterType type = (ElementParameterType) obj;
                                if ("CONDITION".equals(type.getName())) {
                                    if (type.getValue() != null && type.getValue().contains(source[j])) {
                                        String replaceAll = type.getValue().replaceAll(source[j], target[j]);
                                        type.setValue(replaceAll);
                                    }
                                    break;
                                }
                            }
                        }
                    }
                    for (Object o : item.getNode()) {
                        NodeType nt = (NodeType) o;
                        for (Object o1 : nt.getElementParameter()) {
                            ElementParameterType t = (ElementParameterType) o1;
                            String value = t.getValue();
                            if (value != null) {
                                if (value.contains(source[j])) {
                                    String replaceAll = value.replaceAll(source[j], target[j]);
                                    t.setValue(replaceAll);
                                }
                            }
                            if ("TABLE".equals(t.getField())) {
                                for (ElementValueType type : (List<ElementValueType>) t.getElementValue()) {
                                    if (type.getValue() != null && type.getValue().contains(source[j])) {
                                        String replaceAll = type.getValue().replaceAll(source[j], target[j]);
                                        type.setValue(replaceAll);
                                    }
                                }
                            }
                        }
                    }
                }
            };
            ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(renameConversion, changeNodeNameConversion));
        }
        return ExecutionResult.SUCCESS_NO_ALERT;
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
}
Also used : ConnectionType(org.talend.designer.core.model.utils.emf.talendfile.ConnectionType) IComponentFilter(org.talend.core.model.components.filters.IComponentFilter) NameComponentFilter(org.talend.core.model.components.filters.NameComponentFilter) RenameComponentConversion(org.talend.core.model.components.conversions.RenameComponentConversion) ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) ElementValueType(org.talend.designer.core.model.utils.emf.talendfile.ElementValueType) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) List(java.util.List) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Example 17 with ConnectionType

use of org.talend.designer.core.model.utils.emf.talendfile.ConnectionType in project tdi-studio-se by Talend.

the class ReplaceRunBeforeAfterWithThenRunMigrationTask method resetDirectionOfConnections.

/**
     * Reset driection of the connections.
     * 
     * yzhang Comment method "resetRunAfterConnections".
     * 
     * @param connectionMap
     */
private void resetDirectionOfConnections(Map<String, List> connectionMap) {
    if (connectionMap.isEmpty()) {
        return;
    }
    for (Iterator iter = connectionMap.keySet().iterator(); iter.hasNext(); ) {
        String sourceName = (String) iter.next();
        List<ConnectionType> connectionList = connectionMap.get(sourceName);
        ConnectionType oldConnection = null;
        for (ConnectionType connection : connectionList) {
            if (oldConnection != null) {
                oldConnection.setTarget(connection.getTarget());
            }
            connection.setSource(connection.getTarget());
            oldConnection = connection;
        }
        if (oldConnection != null) {
            oldConnection.setTarget(sourceName);
        }
    }
}
Also used : ConnectionType(org.talend.designer.core.model.utils.emf.talendfile.ConnectionType) EConnectionType(org.talend.core.model.process.EConnectionType) Iterator(java.util.Iterator)

Example 18 with ConnectionType

use of org.talend.designer.core.model.utils.emf.talendfile.ConnectionType in project tdi-studio-se by Talend.

the class AddWebServiceOutputTableMigrationTask method addNewColumn.

private void addNewColumn(Item item) {
    // TODO Auto-generated method stub
    boolean isUpdate = false;
    MetadataType metadata;
    ProcessType processType = getProcessType(item);
    TalendFileFactory fileFact = TalendFileFactory.eINSTANCE;
    String webServiceComponentName = "";
    NodeType webServiceNode = null;
    for (Object o : processType.getNode()) {
        if (o instanceof NodeType) {
            NodeType currentNode = (NodeType) o;
            if ("tWebService".equals(currentNode.getComponentName())) {
                webServiceNode = currentNode;
                if (currentNode.getMetadata().size() == 1) {
                    isUpdate = true;
                    for (Object e : currentNode.getElementParameter()) {
                        ElementParameterType p = (ElementParameterType) e;
                        if ("UNIQUE_NAME".equals(p.getName())) {
                            webServiceComponentName = p.getValue();
                            MetadataType newMetadata = (MetadataType) currentNode.getMetadata().get(0);
                            newMetadata.getColumn().clear();
                        }
                    }
                }
            }
        }
    }
    if (isUpdate) {
        String name = "";
        String webSourceName = "";
        String webserviceOutNaame = "";
        for (Object o : processType.getConnection()) {
            if (o instanceof ConnectionType) {
                ConnectionType currentConnection = (ConnectionType) o;
                if ("FLOW".equals(currentConnection.getConnectorName()) && currentConnection.getTarget().equals(webServiceComponentName)) {
                    webSourceName = currentConnection.getSource();
                } else if ("FLOW".equals(currentConnection.getConnectorName()) && currentConnection.getSource().equals(webServiceComponentName)) {
                    webserviceOutNaame = currentConnection.getTarget();
                    currentConnection.setConnectorName("OUTPUT");
                    currentConnection.setMetaname("OUTPUT");
                }
            }
        }
        for (Object o : processType.getNode()) {
            if (o instanceof NodeType) {
                NodeType currentNode = (NodeType) o;
                for (Object e : currentNode.getElementParameter()) {
                    ElementParameterType p = (ElementParameterType) e;
                    if ("UNIQUE_NAME".equals(p.getName()) && webSourceName.equals(p.getValue())) {
                        MetadataType newMetadata = (MetadataType) currentNode.getMetadata().get(0);
                        metadata = ((MetadataType) webServiceNode.getMetadata().get(0));
                        EList<ColumnType> list = newMetadata.getColumn();
                        for (int i = 0; i < list.size(); i++) {
                            ColumnType in = (ColumnType) list.get(i);
                            ColumnType out = fileFact.createColumnType();
                            out.setComment(in.getComment());
                            out.setKey(in.isKey());
                            out.setNullable(in.isNullable());
                            if (String.valueOf(in.getLength()).equals("0")) {
                                out.unsetLength();
                            } else {
                                out.setLength(in.getLength());
                            }
                            out.setName(in.getName());
                            if (String.valueOf(in.getPrecision()).equals("0")) {
                                out.unsetPrecision();
                            } else {
                                out.setPrecision(in.getPrecision());
                            }
                            if (!in.getName().equals(in.getOriginalDbColumnName())) {
                                out.setOriginalDbColumnName(in.getOriginalDbColumnName());
                            }
                            out.setType(in.getType());
                            out.setSourceType(in.getSourceType());
                            out.setPattern(in.getPattern());
                            out.setDefaultValue(in.getDefaultValue());
                            metadata.getColumn().add(out);
                        }
                    } else if ("UNIQUE_NAME".equals(p.getName()) && webserviceOutNaame.equals(p.getValue())) {
                        MetadataType newMetadata = fileFact.createMetadataType();
                        metadata = ((MetadataType) currentNode.getMetadata().get(0));
                        name = metadata.getName();
                        EList<ColumnType> list = metadata.getColumn();
                        newMetadata.setName("OUTPUT");
                        newMetadata.setConnector("OUTPUT");
                        for (int i = 0; i < list.size(); i++) {
                            ColumnType in = (ColumnType) list.get(i);
                            ColumnType out = fileFact.createColumnType();
                            out.setComment(in.getComment());
                            out.setKey(in.isKey());
                            out.setNullable(in.isNullable());
                            if (String.valueOf(in.getLength()).equals("0")) {
                                out.unsetLength();
                            } else {
                                out.setLength(in.getLength());
                            }
                            out.setName(in.getName());
                            if (String.valueOf(in.getPrecision()).equals("0")) {
                                out.unsetPrecision();
                            } else {
                                out.setPrecision(in.getPrecision());
                            }
                            if (!in.getName().equals(in.getOriginalDbColumnName())) {
                                out.setOriginalDbColumnName(in.getOriginalDbColumnName());
                            }
                            out.setType(in.getType());
                            out.setSourceType(in.getSourceType());
                            out.setPattern(in.getPattern());
                            out.setDefaultValue(in.getDefaultValue());
                            newMetadata.getColumn().add(out);
                            webServiceNode.getMetadata().add(newMetadata);
                        }
                    }
                }
            }
        }
    }
    if (isUpdate) {
        try {
            FACTORY.save(item, true);
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
        }
    }
}
Also used : ColumnType(org.talend.designer.core.model.utils.emf.talendfile.ColumnType) ConnectionType(org.talend.designer.core.model.utils.emf.talendfile.ConnectionType) MetadataType(org.talend.designer.core.model.utils.emf.talendfile.MetadataType) ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) EList(org.eclipse.emf.common.util.EList) TalendFileFactory(org.talend.designer.core.model.utils.emf.talendfile.TalendFileFactory) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 19 with ConnectionType

use of org.talend.designer.core.model.utils.emf.talendfile.ConnectionType in project tdi-studio-se by Talend.

the class ChangeBagName4tPigCode method execute.

@Override
public ExecutionResult execute(Item item) {
    final ProcessType processType = getProcessType(item);
    //$NON-NLS-1$
    String[] compNames = { "tPigCode" };
    IComponentConversion changeBagName4tPigCode = new IComponentConversion() {

        public void transform(NodeType node) {
            if (node == null) {
                return;
            }
            //$NON-NLS-1$
            ElementParameterType pigScript = ComponentUtilities.getNodeProperty(node, "SCRIPT_CODE");
            if (pigScript != null) {
                String content = pigScript.getValue();
                if (content == null) {
                    return;
                }
                //$NON-NLS-1$
                Pattern pattern = Pattern.compile("tPig[a-zA-Z]+_\\d+_RESULT");
                //$NON-NLS-1$
                String end = "_RESULT";
                Matcher matcher = pattern.matcher(content);
                boolean matches = matcher.find();
                if (matches) {
                    //replace the pigscript
                    StringBuffer sb = new StringBuffer();
                    do {
                        String group = matcher.group();
                        String uniqueNameOfComponent = group.substring(0, group.lastIndexOf(end));
                        String outputConnectionName = null;
                        if (processType != null) {
                            List connections = processType.getConnection();
                            if (connections != null) {
                                for (Object connection : connections) {
                                    ConnectionType currentConnection = (ConnectionType) connection;
                                    String source = currentConnection.getSource();
                                    if (uniqueNameOfComponent != null && uniqueNameOfComponent.equals(source)) {
                                        //find the unique output connection
                                        for (Object paramObject : currentConnection.getElementParameter()) {
                                            ElementParameterType paramType = (ElementParameterType) paramObject;
                                            if ("UNIQUE_NAME".equals(paramType.getName())) {
                                                //$NON-NLS-1$
                                                outputConnectionName = paramType.getValue();
                                            }
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                        if (outputConnectionName == null) {
                            //not find
                            matcher.appendReplacement(sb, group);
                        } else {
                            //$NON-NLS-1$
                            matcher.appendReplacement(sb, uniqueNameOfComponent + "_" + outputConnectionName + end);
                        }
                        matches = matcher.find();
                    } while (matches);
                    matcher.appendTail(sb);
                    pigScript.setValue(sb.toString());
                }
            }
        }
    };
    for (String name : compNames) {
        IComponentFilter filter = new NameComponentFilter(name);
        try {
            ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(changeBagName4tPigCode));
        } catch (PersistenceException e) {
            // TODO Auto-generated catch block
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
    }
    return ExecutionResult.SUCCESS_NO_ALERT;
}
Also used : Pattern(java.util.regex.Pattern) ConnectionType(org.talend.designer.core.model.utils.emf.talendfile.ConnectionType) Matcher(java.util.regex.Matcher) IComponentFilter(org.talend.core.model.components.filters.IComponentFilter) NameComponentFilter(org.talend.core.model.components.filters.NameComponentFilter) ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) PersistenceException(org.talend.commons.exception.PersistenceException) List(java.util.List) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Example 20 with ConnectionType

use of org.talend.designer.core.model.utils.emf.talendfile.ConnectionType in project tdi-studio-se by Talend.

the class UpdateELTComponentMigrationTask method execute.

@Override
public ExecutionResult execute(Item item) {
    boolean isModified = false;
    ProcessType processType = getProcessType(item);
    List nodes = processType.getNode();
    List<ConnectionType> connections = processType.getConnection();
    for (ConnectionType connection : connections) {
        String sourceNodeName = connection.getSource();
        String targetNodeName = connection.getTarget();
        if (sourceNodeName.matches("tELT.+Input.+") && targetNodeName.matches("tELT.+Map.+")) {
            //$NON-NLS-1$ //$NON-NLS-2$
            NodeType eltInputNode = getNodeTypeByUniqueName(nodes, sourceNodeName);
            //$NON-NLS-1$
            String orginalTableName = getPropertyValue(eltInputNode, "ELT_TABLE_NAME");
            //$NON-NLS-1$
            String orginalSchemaName = getPropertyValue(eltInputNode, "ELT_SCHEMA_NAME");
            if (orginalSchemaName == null) {
                continue;
            }
            String tableName = TalendQuoteUtils.removeQuotes(orginalTableName);
            String schemaName = TalendQuoteUtils.removeQuotes(orginalSchemaName);
            String connectionName;
            if (schemaName.trim().equals("")) {
                //$NON-NLS-1$
                connectionName = tableName;
            } else {
                //$NON-NLS-1$
                connectionName = schemaName + "." + tableName;
            }
            if (connection.getLabel().equals(tableName)) {
                connection.setLabel(connectionName);
                isModified = true;
            }
            List<MetadataTypeImpl> tables = eltInputNode.getMetadata();
            for (MetadataTypeImpl table : tables) {
                if (table.getLabel().equals(tableName)) {
                    table.setLabel(connectionName);
                    isModified = true;
                }
            }
            NodeType eltMapNode = getNodeTypeByUniqueName(nodes, targetNodeName);
            if (GlobalServiceRegister.getDefault().isServiceRegistered(IDbMapService.class)) {
                IDbMapService service = (IDbMapService) GlobalServiceRegister.getDefault().getService(IDbMapService.class);
                service.updateEMFDBMapData(eltMapNode, tableName, connectionName);
                isModified = true;
            }
        }
    }
    if (isModified) {
        try {
            ProxyRepositoryFactory.getInstance().save(item, true);
            return ExecutionResult.SUCCESS_NO_ALERT;
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) ConnectionType(org.talend.designer.core.model.utils.emf.talendfile.ConnectionType) MetadataTypeImpl(org.talend.designer.core.model.utils.emf.talendfile.impl.MetadataTypeImpl) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) PersistenceException(org.talend.commons.exception.PersistenceException) List(java.util.List) IDbMapService(org.talend.core.service.IDbMapService)

Aggregations

ConnectionType (org.talend.designer.core.model.utils.emf.talendfile.ConnectionType)29 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)14 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)13 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)13 EConnectionType (org.talend.core.model.process.EConnectionType)12 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)11 List (java.util.List)7 ArrayList (java.util.ArrayList)6 PersistenceException (org.talend.commons.exception.PersistenceException)5 IComponentConversion (org.talend.core.model.components.conversions.IComponentConversion)5 IComponentFilter (org.talend.core.model.components.filters.IComponentFilter)5 HashMap (java.util.HashMap)4 Point (org.eclipse.draw2d.geometry.Point)4 NameComponentFilter (org.talend.core.model.components.filters.NameComponentFilter)4 ElementValueType (org.talend.designer.core.model.utils.emf.talendfile.ElementValueType)4 EList (org.eclipse.emf.common.util.EList)3 MetadataType (org.talend.designer.core.model.utils.emf.talendfile.MetadataType)3 Matcher (java.util.regex.Matcher)2 MalformedPatternException (org.apache.oro.text.regex.MalformedPatternException)2 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)2