Search in sources :

Example 6 with ConnectionType

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

the class RenameConnectionRunIfOkToOnComponentOkTask method renameConnections.

/**
     * yzhang Comment method "renameConnections".
     * 
     * @param item
     * @param processType 
     * @throws PersistenceException
     */
private void renameConnections(Item item, ProcessType processType) throws PersistenceException {
    ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    boolean modified = false;
    for (Object o : processType.getConnection()) {
        ConnectionType currentConnection = (ConnectionType) o;
        if (currentConnection.getConnectorName().equals("RUN_OK")) {
            //$NON-NLS-1$
            currentConnection.setConnectorName(EConnectionType.ON_COMPONENT_OK.getName());
            currentConnection.setLabel(EConnectionType.ON_COMPONENT_OK.getDefaultLinkName());
            currentConnection.setLineStyle(EConnectionType.ON_COMPONENT_OK.getId());
            modified = true;
        }
    }
    if (modified) {
        factory.save(item, true);
    }
}
Also used : ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) ConnectionType(org.talend.designer.core.model.utils.emf.talendfile.ConnectionType) EConnectionType(org.talend.core.model.process.EConnectionType)

Example 7 with ConnectionType

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

the class RouteJavaScriptOSGIForESBManager method collectRouteInfo.

private Map<String, Object> collectRouteInfo(ProcessItem processItem, IProcess process) {
    Map<String, Object> routeInfo = new HashMap<String, Object>();
    // route name and class name
    //$NON-NLS-1$
    routeInfo.put("name", processItem.getProperty().getLabel());
    String className = getClassName(processItem);
    String idName = className;
    String suffix = getOsgiServiceIdSuffix();
    if (suffix != null && suffix.length() > 0) {
        idName += suffix;
    }
    //$NON-NLS-1$
    routeInfo.put("className", className);
    //$NON-NLS-2$
    routeInfo.put("idName", idName);
    boolean useSAM = false;
    boolean hasCXFUsernameToken = false;
    boolean hasCXFSamlConsumer = false;
    boolean hasCXFSamlProvider = false;
    boolean hasCXFRSSamlProviderAuthz = false;
    Collection<NodeType> cSOAPs = EmfModelUtils.getComponentsByName(processItem, "cSOAP");
    boolean hasCXFComponent = !cSOAPs.isEmpty();
    cSOAPs.addAll(EmfModelUtils.getComponentsByName(processItem, "cREST"));
    if (!cSOAPs.isEmpty()) {
        Set<String> consumerNodes = new HashSet<String>();
        @SuppressWarnings("unchecked") List<ConnectionType> connections = processItem.getProcess().getConnection();
        for (ConnectionType conn : connections) {
            consumerNodes.add(conn.getTarget());
        }
        boolean isEEVersion = isStudioEEVersion();
        for (NodeType node : cSOAPs) {
            boolean nodeUseSAM = false;
            boolean nodeUseSaml = false;
            boolean nodeUseAuthz = false;
            boolean nodeUseRegistry = false;
            // http://jira.talendforge.org/browse/TESB-3850
            //$NON-NLS-1$
            String format = EmfModelUtils.computeTextElementValue("DATAFORMAT", node);
            if (!useSAM && !"RAW".equals(format)) {
                //$NON-NLS-1$
                nodeUseSAM = //$NON-NLS-1$
                EmfModelUtils.computeCheckElementValue("ENABLE_SAM", node) || //$NON-NLS-1$
                EmfModelUtils.computeCheckElementValue("SERVICE_ACTIVITY_MONITOR", node);
            }
            // security is disable in case CXF_MESSAGE or RAW dataFormat
            if (!"CXF_MESSAGE".equals(format) && !"RAW".equals(format)) {
                //$NON-NLS-1$  //$NON-NLS-2$
                if (isEEVersion && EmfModelUtils.computeCheckElementValue("ENABLE_REGISTRY", node)) {
                    //$NON-NLS-1$
                    nodeUseRegistry = true;
                    // https://jira.talendforge.org/browse/TESB-10725
                    nodeUseSAM = false;
                } else if (EmfModelUtils.computeCheckElementValue("ENABLE_SECURITY", node)) {
                    //$NON-NLS-1$
                    //$NON-NLS-1$
                    String securityType = EmfModelUtils.computeTextElementValue("SECURITY_TYPE", node);
                    if ("USER".equals(securityType)) {
                        //$NON-NLS-1$
                        hasCXFUsernameToken = true;
                    } else if ("SAML".equals(securityType)) {
                        //$NON-NLS-1$
                        nodeUseSaml = true;
                        nodeUseAuthz = isEEVersion && EmfModelUtils.computeCheckElementValue("USE_AUTHORIZATION", node);
                    }
                }
            }
            useSAM |= nodeUseSAM;
            if (consumerNodes.contains(ElementParameterParser.getUNIQUENAME(node))) {
                hasCXFSamlConsumer |= nodeUseSaml | nodeUseRegistry;
            } else {
                hasCXFSamlProvider |= nodeUseSaml | nodeUseRegistry;
                hasCXFRSSamlProviderAuthz |= nodeUseAuthz;
            }
        }
    }
    //$NON-NLS-1$
    routeInfo.put("useSAM", useSAM);
    //$NON-NLS-1$
    routeInfo.put("hasCXFUsernameToken", hasCXFUsernameToken);
    //$NON-NLS-1$
    routeInfo.put("hasCXFSamlConsumer", hasCXFSamlConsumer);
    //$NON-NLS-1$
    routeInfo.put("hasCXFSamlProvider", hasCXFSamlProvider);
    //$NON-NLS-1$
    routeInfo.put("hasCXFRSSamlProviderAuthz", hasCXFRSSamlProviderAuthz && !hasCXFComponent);
    //$NON-NLS-1$
    routeInfo.put("hasCXFComponent", hasCXFComponent);
    // route OSGi DataSources
    //$NON-NLS-1$
    routeInfo.put("dataSources", DataSourceConfig.getAliases(process));
    //$NON-NLS-1$
    routeInfo.put("routelets", routelets);
    return routeInfo;
}
Also used : ConnectionType(org.talend.designer.core.model.utils.emf.talendfile.ConnectionType) HashMap(java.util.HashMap) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) HashSet(java.util.HashSet)

Example 8 with ConnectionType

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

the class DisableUseBatchWhenRejectLineExists method execute.

/*
     * (non-Javadoc)
     *
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    if (getProject().getLanguage() != ECodeLanguage.JAVA || processType == null) {
        return ExecutionResult.NOTHING_TO_DO;
    }
    List<String> filterList = Arrays.asList("tFirebirdOutput", "tGreenplumOutput", "tIngresOutput", "tInterbaseOutput", "tParAccelOutput", "tPostgresPlusOutput", "tSQLiteOutput", "tRedshiftOutput");
    List<String> filterListMore = Arrays.asList("tTeradataOutput", "tOracleOutput");
    IComponentConversion disableUseBatchWhenRejectLineExists = new IComponentConversion() {

        public void transform(NodeType node) {
            ElementParameterType useBatch = ComponentUtilities.getNodeProperty(node, "USE_BATCH");
            List<ConnectionType> list = ComponentUtilities.getNodeOutputConnections(node);
            for (ConnectionType connType : list) {
                EConnectionType eConnType = EConnectionType.getTypeFromId(connType.getLineStyle());
                if (eConnType == EConnectionType.FLOW_MAIN && connType.getConnectorName().equals("REJECT")) {
                    if (useBatch == null) {
                        ComponentUtilities.addNodeProperty(node, "USE_BATCH", "CHECK");
                    }
                    ComponentUtilities.getNodeProperty(node, "USE_BATCH").setValue("false");
                    break;
                }
            }
        }
    };
    IComponentConversion disableUseBatchWhenRejectLineExistsMore = new IComponentConversion() {

        public void transform(NodeType node) {
            ElementParameterType useBatch = ComponentUtilities.getNodeProperty(node, "USE_BATCH_SIZE");
            ElementParameterType useBatchAndUseExistingConn = ComponentUtilities.getNodeProperty(node, "USE_BATCH_AND_USE_CONN");
            List<ConnectionType> list = ComponentUtilities.getNodeOutputConnections(node);
            for (ConnectionType connType : list) {
                EConnectionType eConnType = EConnectionType.getTypeFromId(connType.getLineStyle());
                if (eConnType == EConnectionType.FLOW_MAIN && connType.getConnectorName().equals("REJECT")) {
                    if (useBatch == null) {
                        ComponentUtilities.addNodeProperty(node, "USE_BATCH_SIZE", "CHECK");
                    }
                    if (useBatchAndUseExistingConn == null) {
                        ComponentUtilities.addNodeProperty(node, "USE_BATCH_AND_USE_CONN", "CHECK");
                    }
                    ComponentUtilities.getNodeProperty(node, "USE_BATCH_SIZE").setValue("false");
                    ComponentUtilities.getNodeProperty(node, "USE_BATCH_AND_USE_CONN").setValue("false");
                    break;
                }
            }
        }
    };
    for (String componentName : filterList) {
        IComponentFilter filter = new NameComponentFilter(componentName);
        try {
            ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(disableUseBatchWhenRejectLineExists));
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
    }
    for (String componentName : filterListMore) {
        IComponentFilter filter = new NameComponentFilter(componentName);
        try {
            ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(disableUseBatchWhenRejectLineExistsMore));
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
    }
    return ExecutionResult.SUCCESS_NO_ALERT;
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) ConnectionType(org.talend.designer.core.model.utils.emf.talendfile.ConnectionType) EConnectionType(org.talend.core.model.process.EConnectionType) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) IComponentFilter(org.talend.core.model.components.filters.IComponentFilter) PersistenceException(org.talend.commons.exception.PersistenceException) NameComponentFilter(org.talend.core.model.components.filters.NameComponentFilter) EConnectionType(org.talend.core.model.process.EConnectionType) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Example 9 with ConnectionType

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

the class ReplaceRunBeforeAfterWithThenRunMigrationTask method isMultiJob.

/**
     * To see whether the job with sub jobs.
     * 
     * yzhang Comment method "isMulitiJob".
     * 
     * @return
     */
private boolean isMultiJob(List<ConnectionType> connections) {
    Map<String, Integer> map = new HashMap<String, Integer>();
    for (ConnectionType conn : connections) {
        if (conn.getLabel().equals(Messages.getString("ReplaceRunBeforeAfterWithThenRunMigrationTask.RunAfter")) || conn.getLabel().equals(Messages.getString("ReplaceRunBeforeAfterWithThenRunMigrationTask.RunBefore"))) {
            //$NON-NLS-1$ //$NON-NLS-2$
            if (map.containsKey(conn.getTarget())) {
                int i = map.get(conn.getTarget());
                map.put(conn.getTarget(), ++i);
            } else {
                map.put(conn.getTarget(), 1);
            }
        }
    }
    for (Integer flag : map.values()) {
        if (flag > 1) {
            return true;
        }
    }
    return false;
}
Also used : ConnectionType(org.talend.designer.core.model.utils.emf.talendfile.ConnectionType) EConnectionType(org.talend.core.model.process.EConnectionType) HashMap(java.util.HashMap)

Example 10 with ConnectionType

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

the class ReplaceRunBeforeAfterWithThenRunMigrationTask method replaceConnections.

/**
	 * Replace run before and after connection with then run.
	 * 
	 * yzhang Comment method "replaceConnections".
	 * 
	 * @param processType
	 * 
	 * @throws PersistenceException
	 */
public void replaceConnections(Item item, ProcessType processType) throws PersistenceException {
    ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    boolean modified = false;
    Map<String, List> runAfterMap = new TreeMap<String, List>();
    if (isMultiJob(processType.getConnection())) {
    // TODO: if it's a job with muliti sub jobs an error mark need to be added in repository.
    }
    for (Object o : processType.getConnection()) {
        ConnectionType currentConnection = (ConnectionType) o;
        if (currentConnection.getLabel().equals(Messages.getString("ReplaceRunBeforeAfterWithThenRunMigrationTask.RunAfter"))) {
            //$NON-NLS-1$
            //$NON-NLS-1$
            currentConnection.setLabel(Messages.getString("ReplaceRunBeforeAfterWithThenRunMigrationTask.ThenRun"));
            currentConnection.setLineStyle(EConnectionType.ON_SUBJOB_OK.getId());
            String sourceKey = currentConnection.getSource();
            if (!runAfterMap.containsKey(sourceKey)) {
                List<ConnectionType> connectionList = new ArrayList<ConnectionType>();
                connectionList.add(currentConnection);
                runAfterMap.put(sourceKey, connectionList);
            } else {
                runAfterMap.get(sourceKey).add(currentConnection);
            }
            modified = true;
        } else if (currentConnection.getLabel().equals(Messages.getString("ReplaceRunBeforeAfterWithThenRunMigrationTask.RunBefore"))) {
            //$NON-NLS-1$
            //$NON-NLS-1$
            currentConnection.setLabel(Messages.getString("ReplaceRunBeforeAfterWithThenRunMigrationTask.ThenRun"));
            String target = currentConnection.getTarget();
            currentConnection.setTarget(currentConnection.getSource());
            currentConnection.setSource(target);
            String sourceKey = currentConnection.getSource();
            if (!runAfterMap.containsKey(sourceKey)) {
                List<ConnectionType> connectionList = new ArrayList<ConnectionType>();
                connectionList.add(currentConnection);
                runAfterMap.put(sourceKey, connectionList);
            } else {
                runAfterMap.get(sourceKey).add(currentConnection);
            }
            modified = true;
        }
    }
    if (modified) {
        resetDirectionOfConnections(runAfterMap);
        factory.save(item);
    }
}
Also used : ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) ConnectionType(org.talend.designer.core.model.utils.emf.talendfile.ConnectionType) EConnectionType(org.talend.core.model.process.EConnectionType) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TreeMap(java.util.TreeMap)

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