Search in sources :

Example 11 with ConnectionType

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

the class RenameConnectionRunErrorToComponentErrorTask method renameConnections.

/**
     * yzhang Comment method "renameConnections".
     * 
     * @param item
     * @param processType 
     */
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_ERROR")) {
            //$NON-NLS-1$
            currentConnection.setConnectorName(EConnectionType.ON_COMPONENT_ERROR.getName());
            currentConnection.setLabel(EConnectionType.ON_COMPONENT_ERROR.getDefaultLinkName());
            currentConnection.setLineStyle(EConnectionType.ON_COMPONENT_ERROR.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 12 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 13 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 14 with ConnectionType

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

the class NewComponentFrameworkMigrationTask method execute.

@Override
public ExecutionResult execute(final Item item) {
    final ProcessType processType = getProcessType(item);
    ComponentCategory category = ComponentCategory.getComponentCategoryFromItem(item);
    Properties props = getPropertiesFromFile();
    IComponentConversion conversion = new IComponentConversion() {

        @Override
        public void transform(NodeType nodeType) {
            if (nodeType == null || props == null) {
                return;
            }
            boolean modified = false;
            Map<String, String> schemaParamMap = new HashMap<>();
            String currComponentName = nodeType.getComponentName();
            String newComponentName = props.getProperty(currComponentName);
            nodeType.setComponentName(newComponentName);
            IComponent component = ComponentsFactoryProvider.getInstance().get(newComponentName, category.getName());
            ComponentProperties compProperties = ComponentsUtils.getComponentProperties(newComponentName);
            FakeNode fNode = new FakeNode(component);
            for (IElementParameter param : fNode.getElementParameters()) {
                if (param instanceof GenericElementParameter) {
                    String paramName = param.getName();
                    NamedThing currNamedThing = ComponentsUtils.getGenericSchemaElement(compProperties, paramName);
                    String oldParamName = props.getProperty(currComponentName + IGenericConstants.EXP_SEPARATOR + paramName);
                    if (oldParamName != null && !(oldParamName = oldParamName.trim()).isEmpty()) {
                        if (currNamedThing instanceof Property && (GenericTypeUtils.isSchemaType((Property<?>) currNamedThing))) {
                            schemaParamMap.put(paramName, props.getProperty(currComponentName + IGenericConstants.EXP_SEPARATOR + paramName + IGenericConstants.EXP_SEPARATOR + "connector"));
                        }
                        ElementParameterType paramType = getParameterType(nodeType, oldParamName);
                        if (paramType != null) {
                            if (currNamedThing instanceof ComponentReferenceProperties) {
                                ComponentReferenceProperties refProps = (ComponentReferenceProperties) currNamedThing;
                                refProps.referenceType.setValue(ComponentReferenceProperties.ReferenceType.COMPONENT_INSTANCE);
                                refProps.componentInstanceId.setStoredValue(ParameterUtilTool.convertParameterValue(paramType));
                                refProps.componentInstanceId.setTaggedValue(IGenericConstants.ADD_QUOTES, true);
                            } else {
                                processMappedElementParameter(props, nodeType, (GenericElementParameter) param, paramType, currNamedThing);
                            }
                            ParameterUtilTool.removeParameterType(nodeType, paramType);
                            modified = true;
                        }
                        if (EParameterFieldType.SCHEMA_REFERENCE.equals(param.getFieldType())) {
                            //$NON-NLS-1$
                            String schemaTypeName = ":" + EParameterName.SCHEMA_TYPE.getName();
                            //$NON-NLS-1$
                            String repSchemaTypeName = ":" + EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
                            paramType = getParameterType(nodeType, oldParamName + schemaTypeName);
                            if (paramType != null) {
                                paramType.setName(param.getName() + schemaTypeName);
                            }
                            paramType = getParameterType(nodeType, oldParamName + repSchemaTypeName);
                            if (paramType != null) {
                                paramType.setName(param.getName() + repSchemaTypeName);
                            }
                        }
                    } else {
                        processUnmappedElementParameter(props, nodeType, (GenericElementParameter) param, currNamedThing);
                    }
                } else {
                    if (EParameterFieldType.SCHEMA_REFERENCE.equals(param.getFieldType())) {
                        String paramName = param.getName();
                        schemaParamMap.put(paramName, props.getProperty(currComponentName + IGenericConstants.EXP_SEPARATOR + paramName + IGenericConstants.EXP_SEPARATOR + "connector"));
                        String oldParamName = props.getProperty(currComponentName + IGenericConstants.EXP_SEPARATOR + paramName);
                        //$NON-NLS-1$
                        String schemaTypeName = ":" + EParameterName.SCHEMA_TYPE.getName();
                        //$NON-NLS-1$
                        String repSchemaTypeName = ":" + EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
                        ElementParameterType paramType = getParameterType(nodeType, oldParamName + schemaTypeName);
                        if (paramType != null) {
                            paramType.setName(param.getName() + schemaTypeName);
                        }
                        paramType = getParameterType(nodeType, oldParamName + repSchemaTypeName);
                        if (paramType != null) {
                            paramType.setName(param.getName() + repSchemaTypeName);
                        }
                    }
                }
            }
            // Migrate schemas
            Map<String, MetadataType> metadatasMap = new HashMap<>();
            EList<MetadataType> metadatas = nodeType.getMetadata();
            for (MetadataType metadataType : metadatas) {
                metadatasMap.put(metadataType.getConnector(), metadataType);
            }
            Iterator<Entry<String, String>> schemaParamIter = schemaParamMap.entrySet().iterator();
            //$NON-NLS-1$
            String uniqueName = ParameterUtilTool.getParameterValue(nodeType, "UNIQUE_NAME");
            while (schemaParamIter.hasNext()) {
                Entry<String, String> schemaParamEntry = schemaParamIter.next();
                String newParamName = schemaParamEntry.getKey();
                String connectorMapping = schemaParamEntry.getValue();
                //$NON-NLS-1$
                String oldConnector = connectorMapping.split("->")[0];
                //$NON-NLS-1$
                String newConnector = connectorMapping.split("->")[1];
                MetadataType metadataType = metadatasMap.get(oldConnector);
                if (metadataType != null) {
                    metadataType.setConnector(newConnector);
                    MetadataEmfFactory factory = new MetadataEmfFactory();
                    factory.setMetadataType(metadataType);
                    IMetadataTable metadataTable = factory.getMetadataTable();
                    Schema schema = SchemaUtils.convertTalendSchemaIntoComponentSchema(ConvertionHelper.convert(metadataTable));
                    compProperties.setValue(newParamName, schema);
                }
                if (!oldConnector.equals(newConnector)) {
                    // if connector was changed, we should update the connections
                    for (Object connectionObj : processType.getConnection()) {
                        if (connectionObj instanceof ConnectionType) {
                            ConnectionType connectionType = (ConnectionType) connectionObj;
                            if (connectionType.getSource().equals(uniqueName) && connectionType.getConnectorName().equals(oldConnector)) {
                                connectionType.setConnectorName(newConnector);
                            }
                        }
                    }
                }
            }
            for (Object connectionObj : processType.getConnection()) {
                ConnectionType connection = (ConnectionType) connectionObj;
                if (connection.getSource() != null && connection.getSource().equals(uniqueName)) {
                    if (EConnectionType.FLOW_MAIN.getName().equals(connection.getConnectorName())) {
                        connection.setConnectorName(Connector.MAIN_NAME);
                    }
                }
            }
            if (modified) {
                String serializedProperties = compProperties.toSerialized();
                if (serializedProperties != null) {
                    ElementParameterType pType = //$NON-NLS-1$
                    ParameterUtilTool.createParameterType(//$NON-NLS-1$
                    null, //$NON-NLS-1$
                    "PROPERTIES", serializedProperties);
                    nodeType.getElementParameter().add(pType);
                }
            }
        }
    };
    if (processType != null) {
        boolean modified = false;
        for (Object obj : processType.getNode()) {
            if (obj != null && obj instanceof NodeType) {
                String componentName = ((NodeType) obj).getComponentName();
                String newComponentName = props.getProperty(componentName);
                if (newComponentName == null) {
                    continue;
                }
                IComponentFilter filter = new NameComponentFilter(componentName);
                modified = ModifyComponentsAction.searchAndModify((NodeType) obj, filter, Arrays.<IComponentConversion>asList(conversion)) || modified;
            }
        }
        if (modified) {
            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 : MetadataEmfFactory(org.talend.designer.core.model.metadata.MetadataEmfFactory) ComponentProperties(org.talend.components.api.properties.ComponentProperties) HashMap(java.util.HashMap) IComponent(org.talend.core.model.components.IComponent) Schema(org.apache.avro.Schema) NameComponentFilter(org.talend.core.model.components.filters.NameComponentFilter) Properties(java.util.Properties) ComponentProperties(org.talend.components.api.properties.ComponentProperties) ComponentReferenceProperties(org.talend.components.api.properties.ComponentReferenceProperties) ComponentCategory(org.talend.core.model.components.ComponentCategory) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) Entry(java.util.Map.Entry) GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) IElementParameter(org.talend.core.model.process.IElementParameter) Property(org.talend.daikon.properties.property.Property) ConnectionType(org.talend.designer.core.model.utils.emf.talendfile.ConnectionType) EConnectionType(org.talend.core.model.process.EConnectionType) IComponentFilter(org.talend.core.model.components.filters.IComponentFilter) MetadataType(org.talend.designer.core.model.utils.emf.talendfile.MetadataType) NamedThing(org.talend.daikon.NamedThing) ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) PersistenceException(org.talend.commons.exception.PersistenceException) ComponentReferenceProperties(org.talend.components.api.properties.ComponentReferenceProperties) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Example 15 with ConnectionType

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

the class ConnectionAddUniqueNameMigrationTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    try {
        uniqueConnectionNameList.clear();
        ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
        ProcessType processType = getProcessType(item);
        boolean modified = false;
        if (processType != null) {
            for (Object o : processType.getConnection()) {
                ConnectionType currentConnection = (ConnectionType) o;
                ElementParameterType uniqueNameParam = null;
                for (Object paramObject : currentConnection.getElementParameter()) {
                    ElementParameterType paramType = (ElementParameterType) paramObject;
                    if (UNIQUE_NAME.equals(paramType.getName())) {
                        uniqueNameParam = paramType;
                    }
                }
                if (uniqueNameParam == null) {
                    uniqueNameParam = TalendFileFactory.eINSTANCE.createElementParameterType();
                    uniqueNameParam.setName("UNIQUE_NAME");
                    uniqueNameParam.setField(EParameterFieldType.TEXT.getName());
                    uniqueNameParam.setContextMode(false);
                    currentConnection.getElementParameter().add(uniqueNameParam);
                }
                String value = uniqueNameParam.getValue();
                String baseName = "";
                if (value == null || "".equals(value)) {
                    modified = true;
                    EConnectionType connectionType = EConnectionType.getTypeFromId(currentConnection.getLineStyle());
                    if (connectionType.hasConnectionCategory(IConnectionCategory.UNIQUE_NAME) && connectionType.hasConnectionCategory(IConnectionCategory.FLOW)) {
                        baseName = null;
                    } else if (connectionType.equals(EConnectionType.ITERATE)) {
                        baseName = "iterate";
                    } else if (connectionType.equals(EConnectionType.TABLE)) {
                        baseName = null;
                    } else if (connectionType.equals(EConnectionType.SYNCHRONIZE) || connectionType.equals(EConnectionType.PARALLELIZE)) {
                        baseName = null;
                    } else {
                        baseName = connectionType.getDefaultLinkName();
                    }
                    String uniqueName = "";
                    if (connectionType.equals(EConnectionType.TABLE)) {
                        uniqueName = currentConnection.getMetaname();
                    } else {
                        uniqueName = currentConnection.getLabel();
                    }
                    if (baseName != null && !"".equals(baseName)) {
                        uniqueName = generateUniqueConnectionName(baseName);
                    }
                    uniqueNameParam.setValue(uniqueName);
                    uniqueConnectionNameList.add(uniqueName);
                }
            }
        }
        if (modified) {
            factory.save(item, true);
            return ExecutionResult.SUCCESS_WITH_ALERT;
        } else {
            return ExecutionResult.SUCCESS_NO_ALERT;
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) 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) EConnectionType(org.talend.core.model.process.EConnectionType) EConnectionType(org.talend.core.model.process.EConnectionType) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException)

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