Search in sources :

Example 31 with NodeType

use of org.talend.designer.core.model.utils.emf.talendfile.NodeType 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 32 with NodeType

use of org.talend.designer.core.model.utils.emf.talendfile.NodeType 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)

Example 33 with NodeType

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

the class CorrectTeradataTPTExecInserterOperatorToLoad method execute.

@Override
public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    IComponentFilter filter = new NameComponentFilter("tTeradataTPTExec");
    IComponentFilter filterTTeradataTPTUtility = new NameComponentFilter("tTeradataTPTUtility");
    try {
        ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(new IComponentConversion() {

            @Override
            public void transform(NodeType node) {
                if (ComponentUtilities.getNodeProperty(node, "ACTION").getValue().equalsIgnoreCase("Insert")) {
                    //$NON-NLS-1$ //$NON-NLS-2$
                    //$NON-NLS-1$
                    ComponentUtilities.getNodeProperty(node, "ACTION").setValue("Load");
                    if (ComponentUtilities.getNodeProperty(node, "SCRIPT_PARAMETER") == null) {
                        ComponentUtilities.addNodeProperty(node, "SCRIPT_PARAMETER", "CHECK");
                        ComponentUtilities.getNodeProperty(node, "SCRIPT_PARAMETER").setValue("true");
                    }
                }
            }
        }));
        ModifyComponentsAction.searchAndModify(item, processType, filterTTeradataTPTUtility, Arrays.<IComponentConversion>asList(new IComponentConversion() {

            @Override
            public void transform(NodeType node) {
                if (ComponentUtilities.getNodeProperty(node, "ACTION").getValue().equalsIgnoreCase("Insert")) {
                    //$NON-NLS-1$ //$NON-NLS-2$
                    //$NON-NLS-1$
                    ComponentUtilities.getNodeProperty(node, "ACTION").setValue("Load");
                    if (ComponentUtilities.getNodeProperty(node, "SCRIPT_PARAMETER") == null) {
                        ComponentUtilities.addNodeProperty(node, "SCRIPT_PARAMETER", "CHECK");
                        ComponentUtilities.getNodeProperty(node, "SCRIPT_PARAMETER").setValue("true");
                    }
                }
            }
        }));
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
    return ExecutionResult.SUCCESS_NO_ALERT;
}
Also used : ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) IComponentFilter(org.talend.core.model.components.filters.IComponentFilter) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) PersistenceException(org.talend.commons.exception.PersistenceException) NameComponentFilter(org.talend.core.model.components.filters.NameComponentFilter) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Example 34 with NodeType

use of org.talend.designer.core.model.utils.emf.talendfile.NodeType 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 35 with NodeType

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

the class FileInputRegexContextVariableMigrationTask method addQuote.

private boolean addQuote(Item item) {
    ProcessType processType = getProcessType(item);
    if (processType == null) {
        return false;
    }
    ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    boolean modified = false;
    EList nodes = processType.getNode();
    for (Object n : nodes) {
        NodeType type = (NodeType) n;
        if (type.getComponentName().equals("tFileInputRegex")) {
            //$NON-NLS-1$
            EList elementParameterList = type.getElementParameter();
            for (Object elem : elementParameterList) {
                ElementParameterType elemType = (ElementParameterType) elem;
                if (//$NON-NLS-1$ //$NON-NLS-2$
                elemType.getName().equals("HEADER") || elemType.getName().equals("FOOTER") || elemType.getName().equals("LIMIT")) {
                    //$NON-NLS-1$
                    String oldV = elemType.getValue();
                    if (oldV == null || oldV.length() == 0) {
                        if (elemType.getName().equals("LIMIT")) {
                            //$NON-NLS-1$
                            //$NON-NLS-1$
                            oldV = "-1";
                        } else {
                            //$NON-NLS-1$
                            oldV = "0";
                        }
                    }
                    if (!oldV.contains("\"")) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$ //$NON-NLS-2$
                        elemType.setValue("\"" + oldV + "\"");
                    }
                    modified = true;
                }
            }
        }
    }
    return modified;
}
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) EList(org.eclipse.emf.common.util.EList) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType)

Aggregations

NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)190 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)152 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)126 IComponentConversion (org.talend.core.model.components.conversions.IComponentConversion)111 IComponentFilter (org.talend.core.model.components.filters.IComponentFilter)109 NameComponentFilter (org.talend.core.model.components.filters.NameComponentFilter)108 PersistenceException (org.talend.commons.exception.PersistenceException)91 ArrayList (java.util.ArrayList)24 EList (org.eclipse.emf.common.util.EList)23 ProcessItem (org.talend.core.model.properties.ProcessItem)21 ElementValueType (org.talend.designer.core.model.utils.emf.talendfile.ElementValueType)21 List (java.util.List)20 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)18 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)17 ConnectionType (org.talend.designer.core.model.utils.emf.talendfile.ConnectionType)13 MetadataType (org.talend.designer.core.model.utils.emf.talendfile.MetadataType)13 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)13 ColumnType (org.talend.designer.core.model.utils.emf.talendfile.ColumnType)9 JobletProcessItem (org.talend.core.model.properties.JobletProcessItem)8 IOException (java.io.IOException)7