Search in sources :

Example 36 with ProcessType

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

the class UpdateCJMSProjectMigrationTask method updateJMSComponent.

/**
     * Update cJMS, add cMQConnectionFactory.
     * 
     * @param item
     * @throws PersistenceException
     */
@SuppressWarnings("unchecked")
private void updateJMSComponent(Item item) throws PersistenceException {
    ProcessType processType = getProcessType(item);
    if (processType == null) {
        return;
    }
    boolean modified = false;
    List<NodeType> nodes = new ArrayList<NodeType>();
    for (Object o : processType.getNode()) {
        if (o instanceof NodeType) {
            NodeType currentNode = (NodeType) o;
            if ("cJMS".equals(currentNode.getComponentName())) {
                modified = true;
                NodeType cfNode = createConnectionFactoryNode(currentNode);
                nodes.add(cfNode);
            }
        }
    }
    if (modified) {
        locateNodes(processType, nodes);
        processType.getNode().addAll(nodes);
        REPO_FACTORY.save(item, true);
    }
}
Also used : ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) ArrayList(java.util.ArrayList)

Example 37 with ProcessType

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

the class FixWrongDbTypesMigrationTask 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 (processType == null) {
        return ExecutionResult.NOTHING_TO_DO;
    }
    boolean modified = false;
    for (Object nodeTypeObject : processType.getNode()) {
        NodeType nodeType = (NodeType) nodeTypeObject;
        IComponent component = ComponentsFactoryProvider.getInstance().get(nodeType.getComponentName(), ComponentCategory.CATEGORY_4_DI.getName());
        if (component == null) {
            // in case original component doesn't exist here
            continue;
        }
        FakeNode fNode = new FakeNode(component);
        IElementParameter mappingParameter = fNode.getElementParameterFromField(EParameterFieldType.MAPPING_TYPE);
        if (mappingParameter != null && mappingParameter.getValue() != null) {
            String mappingParameterValue = (String) mappingParameter.getValue();
            MappingTypeRetriever mtr = MetadataTalendType.getMappingTypeRetriever(mappingParameterValue);
            if (mtr == null) {
                continue;
            }
            for (Object metadataObject : nodeType.getMetadata()) {
                MetadataType metadataType = (MetadataType) metadataObject;
                for (Object columnObject : metadataType.getColumn()) {
                    ColumnType columnType = (ColumnType) columnObject;
                    if (columnType.getSourceType() != null && !"".equals(columnType.getSourceType())) {
                        if (mtr.isAdvicedTalendToDbType(columnType.getType(), columnType.getSourceType())) {
                            // correct type already, no need to do anything
                            continue;
                        }
                        List<MappingType> advicedTalendToDbTypes = mtr.getAdvicedTalendToDbTypes(columnType.getType());
                        if (advicedTalendToDbTypes == null) {
                            continue;
                        }
                        String dbType = columnType.getSourceType();
                        for (MappingType type : advicedTalendToDbTypes) {
                            if (type.getDbType().equalsIgnoreCase(dbType)) {
                                columnType.setSourceType(type.getDbType());
                                modified = true;
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    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 : MappingType(org.talend.core.model.metadata.MappingType) ColumnType(org.talend.designer.core.model.utils.emf.talendfile.ColumnType) MappingTypeRetriever(org.talend.core.model.metadata.MappingTypeRetriever) IComponent(org.talend.core.model.components.IComponent) MetadataType(org.talend.designer.core.model.utils.emf.talendfile.MetadataType) 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) IElementParameter(org.talend.core.model.process.IElementParameter)

Example 38 with ProcessType

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

the class HandleOracleSchemaMigrationTask method execute.

@Override
public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    if (getProject().getLanguage() == ECodeLanguage.JAVA && processType != null) {
        NodeType tOracleConnection = null;
        for (Object nodeType : processType.getNode()) {
            NodeType tmpNodeType = (NodeType) nodeType;
            if (tmpNodeType.getComponentName().equals("tOracleConnection")) {
                //$NON-NLS-1$
                tOracleConnection = tmpNodeType;
                break;
            }
        }
        if (tOracleConnection != null) {
            if (ComponentUtilities.getNodeProperty(tOracleConnection, "SCHEMA_DB") == null) {
                //$NON-NLS-1$
                //$NON-NLS-1$ //$NON-NLS-2$
                ComponentUtilities.addNodeProperty(tOracleConnection, "SCHEMA_DB", "TEXT");
                //$NON-NLS-1$ //$NON-NLS-2$
                ComponentUtilities.setNodeValue(tOracleConnection, "SCHEMA_DB", "\"\"");
            } else {
                //$NON-NLS-1$
                ElementParameterType elementParameter = ComponentUtilities.getNodeProperty(tOracleConnection, "SCHEMA_DB");
                if (elementParameter.getValue().equals("ROOT")) {
                    //$NON-NLS-1$
                    //$NON-NLS-1$
                    elementParameter.setValue("\"\"");
                }
            }
        }
        return ExecutionResult.SUCCESS_WITH_ALERT;
    } else {
        return ExecutionResult.NOTHING_TO_DO;
    }
}
Also used : 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)

Example 39 with ProcessType

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

the class CorrectBatchSizeForDBComponents 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("tAmazonOracleOutput", "tInformixOutput");
    IComponentConversion correctBatchModeForDBComponents = new IComponentConversion() {

        public void transform(NodeType node) {
            ElementParameterType useExistingConnPara = ComponentUtilities.getNodeProperty(node, "USE_EXISTING_CONNECTION");
            if (useExistingConnPara == null) {
                ComponentUtilities.addNodeProperty(node, "USE_EXISTING_CONNECTION", "CHECK");
                ComponentUtilities.getNodeProperty(node, "USE_EXISTING_CONNECTION").setValue("false");
            }
            ElementParameterType useBatchAndUseConnPara = ComponentUtilities.getNodeProperty(node, "USE_BATCH_AND_USE_CONN");
            if (useBatchAndUseConnPara == null) {
                ComponentUtilities.addNodeProperty(node, "USE_BATCH_AND_USE_CONN", "CHECK");
                ComponentUtilities.getNodeProperty(node, "USE_BATCH_AND_USE_CONN").setValue("false");
            }
            boolean useExistConn = ComponentUtilities.getNodeProperty(node, "USE_EXISTING_CONNECTION").getValue().equalsIgnoreCase("true");
            ElementParameterType elementParaType = ComponentUtilities.getNodeProperty(node, "USE_BATCH_SIZE");
            if (elementParaType == null) {
                ComponentUtilities.addNodeProperty(node, "USE_BATCH_SIZE", "CHECK");
                ComponentUtilities.getNodeProperty(node, "USE_BATCH_SIZE").setValue("false");
            }
            if (!useExistConn) {
                if (elementParaType != null && elementParaType.getValue().equalsIgnoreCase("true")) {
                    String batchSizeInStr = ComponentUtilities.getNodeProperty(node, "BATCH_SIZE").getValue();
                    if (batchSizeInStr != null && !"".equals(batchSizeInStr)) {
                        int batchSize = Integer.valueOf(batchSizeInStr);
                        if (batchSize <= 0) {
                            ComponentUtilities.getNodeProperty(node, "BATCH_SIZE").setValue("1");
                        }
                    }
                }
            }
        }
    };
    for (String componentName : filterList) {
        IComponentFilter filter = new NameComponentFilter(componentName);
        try {
            ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(correctBatchModeForDBComponents));
        } 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) 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) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Example 40 with ProcessType

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

the class CorrectBatchSizeForDBComponentsMore 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("tAS400Output", "tNetezzaOutput", "tVerticaOutput", "tDB2Output", "tMSSqlOutput", "tPostgresqlOutput", "tSybaseOutput", "tVectorWiseOutput", "tAmazonMysqlOutput");
    IComponentConversion correctBatchModeForDBComponents = new IComponentConversion() {

        public void transform(NodeType node) {
            ElementParameterType useExistingConnPara = ComponentUtilities.getNodeProperty(node, "USE_EXISTING_CONNECTION");
            if (useExistingConnPara == null) {
                ComponentUtilities.addNodeProperty(node, "USE_EXISTING_CONNECTION", "CHECK");
                ComponentUtilities.getNodeProperty(node, "USE_EXISTING_CONNECTION").setValue("false");
            }
            ElementParameterType elementParaType = ComponentUtilities.getNodeProperty(node, "USE_BATCH_SIZE");
            if (elementParaType == null) {
                ComponentUtilities.addNodeProperty(node, "USE_BATCH_SIZE", "CHECK");
                ComponentUtilities.getNodeProperty(node, "USE_BATCH_SIZE").setValue("false");
            }
            if (elementParaType != null && elementParaType.getValue().equalsIgnoreCase("true")) {
                String batchSizeInStr = ComponentUtilities.getNodeProperty(node, "BATCH_SIZE").getValue();
                if (batchSizeInStr != null && !"".equals(batchSizeInStr)) {
                    if (batchSizeInStr.matches("\\d+")) {
                        //$NON-NLS-1$
                        int batchSize = Integer.valueOf(batchSizeInStr);
                        if (batchSize <= 0) {
                            ComponentUtilities.getNodeProperty(node, "BATCH_SIZE").setValue("1");
                        }
                    }
                }
            }
        }
    };
    for (String componentName : filterList) {
        IComponentFilter filter = new NameComponentFilter(componentName);
        try {
            ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(correctBatchModeForDBComponents));
        } 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) 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) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Aggregations

ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)237 IComponentConversion (org.talend.core.model.components.conversions.IComponentConversion)154 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)152 IComponentFilter (org.talend.core.model.components.filters.IComponentFilter)151 NameComponentFilter (org.talend.core.model.components.filters.NameComponentFilter)143 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)114 PersistenceException (org.talend.commons.exception.PersistenceException)107 ArrayList (java.util.ArrayList)24 ProcessItem (org.talend.core.model.properties.ProcessItem)24 EList (org.eclipse.emf.common.util.EList)23 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)22 List (java.util.List)18 ElementValueType (org.talend.designer.core.model.utils.emf.talendfile.ElementValueType)16 ConnectionType (org.talend.designer.core.model.utils.emf.talendfile.ConnectionType)14 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)14 RenameComponentConversion (org.talend.core.model.components.conversions.RenameComponentConversion)12 JobletProcessItem (org.talend.core.model.properties.JobletProcessItem)12 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)10 MetadataType (org.talend.designer.core.model.utils.emf.talendfile.MetadataType)10 ParametersType (org.talend.designer.core.model.utils.emf.talendfile.ParametersType)10