Search in sources :

Example 21 with ConnectionType

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

the class CamelFeatureUtil method addConnectionsSpecialFeatures.

private static void addConnectionsSpecialFeatures(Collection<FeatureModel> features, ProcessType processType) {
    EList<?> connections = processType.getConnection();
    Iterator<?> iterator = connections.iterator();
    while (iterator.hasNext()) {
        Object next = iterator.next();
        if (!(next instanceof ConnectionType)) {
            continue;
        }
        ConnectionType con = (ConnectionType) next;
        if (!EConnectionType.ROUTE_WHEN.getName().equals(con.getConnectorName())) {
            continue;
        }
        EList<?> elementParameters = con.getElementParameter();
        Iterator<?> paraIter = elementParameters.iterator();
        while (paraIter.hasNext()) {
            Object paraNext = paraIter.next();
            if (!(paraNext instanceof ElementParameterType)) {
                continue;
            }
            ElementParameterType ept = (ElementParameterType) paraNext;
            if (!EParameterName.ROUTETYPE.getName().equals(ept.getName())) {
                continue;
            }
            //	                    "python", "ruby", "simple", "spel", "sql", "xpath", "xquery" };
            if ("groovy".equals(ept.getValue())) {
                features.add(FEATURE_CAMEL_GROOVY);
            } else if ("javaScript".equals(ept.getValue())) {
                features.add(FEATURE_CAMEL_SCRIPT);
                features.add(FEATURE_CAMEL_SCRIPT_JAVASCRIPT);
            }
        }
    }
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) EConnectionType(org.talend.core.model.process.EConnectionType) ConnectionType(org.talend.designer.core.model.utils.emf.talendfile.ConnectionType) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject)

Example 22 with ConnectionType

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

the class ChangeModelForRoutineParameterMigrationTask2 method execute.

@SuppressWarnings("unchecked")
@Override
public ExecutionResult execute(Item item) {
    try {
        List<String> possibleRoutines = new ArrayList<String>();
        List<String> routinesToAdd = new ArrayList<String>();
        String additionalString = LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA ? "." : "";
        IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
        List<IRepositoryViewObject> routines = factory.getAll(ProjectManager.getInstance().getCurrentProject(), ERepositoryObjectType.ROUTINES);
        // always add the system, others must be checked
        for (IRepositoryViewObject object : routines) {
            if (((RoutineItem) object.getProperty().getItem()).isBuiltIn()) {
                routinesToAdd.add(object.getLabel());
            } else {
                possibleRoutines.add(object.getLabel());
            }
        }
        for (Project project : ProjectManager.getInstance().getAllReferencedProjects()) {
            List<IRepositoryViewObject> refRoutines = factory.getAll(project, ERepositoryObjectType.ROUTINES);
            for (IRepositoryViewObject object : refRoutines) {
                if (!((RoutineItem) object.getProperty().getItem()).isBuiltIn()) {
                    if (!possibleRoutines.contains(object.getLabel())) {
                        possibleRoutines.add(object.getLabel());
                        routines.add(object);
                    }
                }
            }
        }
        List<RoutinesParameterType> oldList = Collections.EMPTY_LIST;
        ProcessType processType = getProcessType(item);
        if (null != processType) {
            if (processType.getParameters() != null && processType.getParameters().getRoutinesParameter() == null) {
                ParametersType parameterType = TalendFileFactory.eINSTANCE.createParametersType();
                processType.setParameters(parameterType);
                if (item instanceof ProcessItem) {
                    routinesToAdd.addAll(possibleRoutines);
                    possibleRoutines.clear();
                }
            } else {
                if (processType.getParameters() == null) {
                    processType.setParameters(TalendFileFactory.eINSTANCE.createParametersType());
                }
                oldList = new ArrayList<RoutinesParameterType>(processType.getParameters().getRoutinesParameter());
                if (oldList.isEmpty() && item instanceof ProcessItem) {
                    routinesToAdd.addAll(possibleRoutines);
                    possibleRoutines.clear();
                }
                processType.getParameters().getRoutinesParameter().clear();
            }
            if (processType.getRoutinesDependencies() != null && !processType.getRoutinesDependencies().isEmpty()) {
                processType.getRoutinesDependencies().clear();
            }
            List<RoutinesParameterType> routinesDependencies = (List<RoutinesParameterType>) processType.getParameters().getRoutinesParameter();
            if (!possibleRoutines.isEmpty()) {
                // check possible routines to setup in process
                for (ElementParameterType param : (List<ElementParameterType>) processType.getParameters().getElementParameter()) {
                    for (String routine : possibleRoutines) {
                        if (!routinesToAdd.contains(routine) && param.getValue() != null && param.getValue().contains(routine + additionalString)) {
                            routinesToAdd.add(routine);
                        }
                        for (ElementValueType elementValue : (List<ElementValueType>) param.getElementValue()) {
                            if (!routinesToAdd.contains(routine) && elementValue.getValue() != null && elementValue.getValue().contains(routine + additionalString)) {
                                routinesToAdd.add(routine);
                            }
                        }
                    }
                }
                // check possible routines to setup in nodes
                for (NodeType node : ((List<NodeType>) processType.getNode())) {
                    for (ElementParameterType param : (List<ElementParameterType>) node.getElementParameter()) {
                        for (String routine : possibleRoutines) {
                            if (!routinesToAdd.contains(routine) && param.getValue() != null && param.getValue().contains(routine + additionalString)) {
                                routinesToAdd.add(routine);
                            }
                            for (ElementValueType elementValue : (List<ElementValueType>) param.getElementValue()) {
                                if (!routinesToAdd.contains(routine) && elementValue.getValue() != null && elementValue.getValue().contains(routine + additionalString)) {
                                    routinesToAdd.add(routine);
                                }
                            }
                        }
                    }
                }
                // check possible routines to setup in connections
                for (ConnectionType connection : ((List<ConnectionType>) processType.getConnection())) {
                    for (ElementParameterType param : (List<ElementParameterType>) connection.getElementParameter()) {
                        for (String routine : possibleRoutines) {
                            if (!routinesToAdd.contains(routine) && param.getValue() != null && param.getValue().contains(routine + additionalString)) {
                                routinesToAdd.add(routine);
                            }
                            for (ElementValueType elementValue : (List<ElementValueType>) param.getElementValue()) {
                                if (!routinesToAdd.contains(routine) && elementValue.getValue() != null && elementValue.getValue().contains(routine + additionalString)) {
                                    routinesToAdd.add(routine);
                                }
                            }
                        }
                    }
                }
            }
            // just in case some routine dependencies exist before but are lost... (migration from 4.1.1 or 4.1.2)
            for (RoutinesParameterType routine : oldList) {
                if (!routinesToAdd.contains(routine.getName())) {
                    routinesDependencies.add(routine);
                }
            }
            for (IRepositoryViewObject object : routines) {
                if (routinesToAdd.contains(object.getLabel())) {
                    RoutinesParameterType routinesParameterType = TalendFileFactory.eINSTANCE.createRoutinesParameterType();
                    routinesParameterType.setId(object.getId());
                    routinesParameterType.setName(object.getLabel());
                    routinesDependencies.add(routinesParameterType);
                }
            }
            factory.save(item, true);
        }
        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) RoutinesParameterType(org.talend.designer.core.model.utils.emf.talendfile.RoutinesParameterType) ArrayList(java.util.ArrayList) RoutineItem(org.talend.core.model.properties.RoutineItem) ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) Project(org.talend.core.model.general.Project) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) ElementValueType(org.talend.designer.core.model.utils.emf.talendfile.ElementValueType) ProcessItem(org.talend.core.model.properties.ProcessItem) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ArrayList(java.util.ArrayList) List(java.util.List) ParametersType(org.talend.designer.core.model.utils.emf.talendfile.ParametersType) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 23 with ConnectionType

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

the class ChangeReturnTypeOfServerAliveResult method convertItem.

private boolean convertItem(Item item, ProcessType processType) throws PersistenceException {
    ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    boolean modified = false;
    ECodeLanguage language = getProject().getLanguage();
    EList node = processType.getNode();
    EList connections = processType.getConnection();
    for (Object n : node) {
        NodeType type = (NodeType) n;
        EList elementParameterList = type.getElementParameter();
        for (Object elem : elementParameterList) {
            ElementParameterType elemType = (ElementParameterType) elem;
            if (language.equals(ECodeLanguage.JAVA)) {
                if (elemType.getValue() != null && elemType.getValue().contains("tServerAlive")) {
                    //$NON-NLS-1$
                    Matcher match = PATTERN_GET.matcher(elemType.getValue());
                    String replace = getReplaceValue(match);
                    if (replace != null && replace.length() > 0) {
                        elemType.setValue(replace);
                        modified = true;
                    }
                }
            }
            // for table
            EList elemValue = elemType.getElementValue();
            for (Object elemV : elemValue) {
                ElementValueType elemVal = (ElementValueType) elemV;
                if (language.equals(ECodeLanguage.JAVA)) {
                    if (elemVal.getValue() != null && elemVal.getValue().contains("tServerAlive")) {
                        //$NON-NLS-1$
                        Matcher match = PATTERN_GET.matcher(elemVal.getValue());
                        String replace = getReplaceValue(match);
                        if (replace != null && replace.length() > 0) {
                            elemVal.setValue(replace);
                            modified = true;
                        }
                    }
                }
            }
        }
    }
    // the links
    for (Object n : connections) {
        ConnectionType type = (ConnectionType) n;
        EList elementParameterList = type.getElementParameter();
        for (Object elem : elementParameterList) {
            ElementParameterType elemType = (ElementParameterType) elem;
            if (language.equals(ECodeLanguage.JAVA)) {
                if (elemType.getValue() != null && elemType.getValue().contains("tServerAlive")) {
                    //$NON-NLS-1$
                    Matcher match = PATTERN_GET.matcher(elemType.getValue());
                    String replace = getReplaceValue(match);
                    if (replace != null && replace.length() > 0) {
                        elemType.setValue(replace);
                        modified = true;
                    }
                }
            }
        }
    }
    if (modified) {
        factory.save(item, true);
    }
    return modified;
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) EList(org.eclipse.emf.common.util.EList) ElementValueType(org.talend.designer.core.model.utils.emf.talendfile.ElementValueType) ConnectionType(org.talend.designer.core.model.utils.emf.talendfile.ConnectionType) Matcher(java.util.regex.Matcher) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) ECodeLanguage(org.talend.core.language.ECodeLanguage)

Example 24 with ConnectionType

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

the class ChangeUniqRowLinksMigrationTask method replaceConnections.

public boolean replaceConnections(Item item) throws PersistenceException {
    ProcessType processType = getProcessType(item);
    if (processType == null) {
        return false;
    }
    ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    boolean replaceDone = false;
    boolean modified = false;
    for (Object o : processType.getConnection()) {
        ConnectionType currentConnection = (ConnectionType) o;
        // output of the tUniqRow, set the connector name to UNIQUE.
        if (((currentConnection.getConnectorName() == null) || STANDARD_CONNECTOR_NAME.equals(currentConnection.getConnectorName())) && sourceComeFromtUniqRow(processType, currentConnection.getSource())) {
            currentConnection.setConnectorName(NEW_CONNECTOR_NAME);
            modified = true;
        }
    }
    if (modified) {
        factory.save(item, true);
        replaceDone = true;
    }
    return replaceDone;
}
Also used : ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) ConnectionType(org.talend.designer.core.model.utils.emf.talendfile.ConnectionType)

Example 25 with ConnectionType

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

the class DisconnectErroHandlerMigrationTask method disconnectErrorHandler.

private void disconnectErrorHandler(CamelProcessItem item) throws PersistenceException {
    ProcessType processType = item.getProcess();
    /*
		 * find all cErrorHandler components first
		 * and if none, then return
		 */
    List<String> errorHandlerIds = findAllErrorHandlerIds(processType);
    if (errorHandlerIds == null || errorHandlerIds.size() == 0) {
        return;
    }
    /*
		 *  if a cErrorHandler has output connection but no input connection, 
		 *  then the output connection should be removed.
		 */
    /*
		 * store all connections whose target is a cErrorHandler
		 */
    Map<String, ConnectionType> inputMap = new HashMap<String, ConnectionType>();
    /*
		 * store all connections whose source is a cErrorHandler
		 */
    Map<String, ConnectionType> outputMap = new HashMap<String, ConnectionType>();
    EList connection = processType.getConnection();
    for (Object o : connection) {
        if (!(o instanceof ConnectionType)) {
            continue;
        }
        ConnectionType ct = (ConnectionType) o;
        String source = ct.getSource();
        String target = ct.getTarget();
        for (String id : errorHandlerIds) {
            /*
				 * if source of connection is a cErrorHandler
				 */
            if (id.equals(source)) {
                ConnectionType connectionType = inputMap.get(id);
                /*
					 * if the cErrorHandler doesn't find an Incoming connection yet
					 * then store it.
					 */
                if (connectionType == null) {
                    outputMap.put(id, ct);
                } else /*
					 * if find an Incoming connection
					 * then remove it from input map
					 */
                {
                    inputMap.remove(id);
                }
            } else /*
				 * if target of connection is a cErrorHandler
				 */
            if (id.equals(target)) {
                ConnectionType connectionType = outputMap.get(id);
                /*
					 * if the cErrorHandler doesn't find an Outgoing connection yet
					 * then store it.
					 */
                if (connectionType == null) {
                    inputMap.put(id, ct);
                } else {
                    /*
						 * if find an outgoing connection
						 * then remove it from output map
						 */
                    outputMap.remove(id);
                }
            }
        }
    }
    /*
		 * if outgoing map is not empty, then the connection should be
		 * removed
		 */
    if (!outputMap.isEmpty()) {
        Set<String> keySet = outputMap.keySet();
        Iterator<String> iterator = keySet.iterator();
        while (iterator.hasNext()) {
            String next = iterator.next();
            ConnectionType connectionType = outputMap.get(next);
            connection.remove(connectionType);
        }
        FACTORY.save(item, true);
    }
}
Also used : ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) EList(org.eclipse.emf.common.util.EList) ConnectionType(org.talend.designer.core.model.utils.emf.talendfile.ConnectionType) HashMap(java.util.HashMap)

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