Search in sources :

Example 41 with NodeType

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

the class CorrectBatchModeForDBComponents 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("tOracleOutput");
    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");
            }
            //Use Existing Conn == true
            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("false")) {
                    elementParaType.setValue("true");
                    ComponentUtilities.getNodeProperty(node, "BATCH_SIZE").setValue("0");
                }
            }
        }
    };
    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 42 with NodeType

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

the class CorrectBatchModeForJDBCOutput 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;
    }
    //groupx
    List<String> filterList = Arrays.asList("tJDBCOutput");
    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 useBatchSizePara = ComponentUtilities.getNodeProperty(node, "USE_BATCH_SIZE");
            if (useBatchSizePara == null) {
                ComponentUtilities.addNodeProperty(node, "USE_BATCH_SIZE", "CHECK");
                ComponentUtilities.getNodeProperty(node, "USE_BATCH_SIZE").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");
            }
        }
    };
    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 43 with NodeType

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

the class CorrectBatchModeForTeradataOutput 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;
    }
    //groupx
    List<String> filterList = Arrays.asList("tTeradataOutput");
    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");
            }
            boolean useExistConn = ComponentUtilities.getNodeProperty(node, "USE_EXISTING_CONNECTION").getValue().equalsIgnoreCase("true");
            ElementParameterType useBatchSizePara = ComponentUtilities.getNodeProperty(node, "USE_BATCH_SIZE");
            if (useBatchSizePara == null) {
                ComponentUtilities.addNodeProperty(node, "USE_BATCH_SIZE", "CHECK");
                ComponentUtilities.getNodeProperty(node, "USE_BATCH_SIZE").setValue("false");
            }
            boolean useBatchExistAndCheckForPreviousVersion = useBatchSizePara != null && useBatchSizePara.getValue().equalsIgnoreCase("true");
            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(useBatchExistAndCheckForPreviousVersion ? "true" : "false");
            }
            boolean useBatchExistAndUncheckForPreviousVersion = useBatchSizePara != null && useBatchSizePara.getValue().equalsIgnoreCase("false");
            if (useExistConn) {
                if (useBatchExistAndUncheckForPreviousVersion) {
                    ComponentUtilities.getNodeProperty(node, "USE_BATCH_AND_USE_CONN").setValue("true");
                    ComponentUtilities.getNodeProperty(node, "BATCH_SIZE").setValue("0");
                }
            } else {
                if (useBatchExistAndUncheckForPreviousVersion) {
                    useBatchSizePara.setValue("true");
                    ComponentUtilities.getNodeProperty(node, "BATCH_SIZE").setValue("0");
                }
            }
        }
    };
    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 44 with NodeType

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

the class AbstractProcessAction method checkUnLoadedNodeForProcess.

public void checkUnLoadedNodeForProcess(JobEditorInput fileEditorInput) {
    if (fileEditorInput == null || fileEditorInput.getLoadedProcess() == null) {
        return;
    }
    IProcess2 loadedProcess = fileEditorInput.getLoadedProcess();
    List<NodeType> unloadedNode = loadedProcess.getUnloadedNode();
    if (unloadedNode != null && !unloadedNode.isEmpty()) {
        String message = "Some Component are not loaded:\n";
        for (int i = 0; i < unloadedNode.size(); i++) {
            message = message + unloadedNode.get(i).getComponentName() + "\n";
        }
        if (!CommonsPlugin.isHeadless() && PlatformUI.isWorkbenchRunning()) {
            Display display = Display.getCurrent();
            if (display == null) {
                display = Display.getDefault();
            }
            if (display != null) {
                final Display tmpDis = display;
                final String tmpMess = message;
                display.syncExec(new Runnable() {

                    public void run() {
                        Shell shell = null;
                        final IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
                        if (activeWorkbenchWindow != null) {
                            shell = activeWorkbenchWindow.getShell();
                        } else {
                            if (tmpDis != null) {
                                shell = tmpDis.getActiveShell();
                            } else {
                                shell = new Shell();
                            }
                        }
                        MessageDialog.openWarning(shell, "Warning", tmpMess);
                    }
                });
            }
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) Shell(org.eclipse.swt.widgets.Shell) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) IProcess2(org.talend.core.model.process.IProcess2) Display(org.eclipse.swt.widgets.Display)

Example 45 with NodeType

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

the class DBMapSplitTableConstraintFiltersMigrationTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    IProxyRepositoryFactory factory = CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory();
    ProcessType processType = getProcessType(item);
    boolean modified = false;
    if (processType != null) {
        for (Object obj : processType.getNode()) {
            NodeType nodeType = (NodeType) obj;
            AbstractExternalData externalData = nodeType.getNodeData();
            if (externalData instanceof DBMapData) {
                DBMapData mapperData = (DBMapData) externalData;
                for (OutputTable pTable : mapperData.getOutputTables()) {
                    int i = 0;
                    List<FilterEntry> needSplitFilters = new ArrayList<FilterEntry>();
                    List<FilterEntry> newFilters = new ArrayList<FilterEntry>();
                    for (FilterEntry pFilter : pTable.getFilterEntries()) {
                        String expression = pFilter.getExpression();
                        if (expression != null && !expression.trim().isEmpty()) {
                            if (!DbGenerationManager.containWith(expression, DbMapSqlConstants.GROUP_BY_PATTERN, false) && !DbGenerationManager.containWith(expression, DbMapSqlConstants.ORDER_BY_PATTERN, false)) {
                                continue;
                            } else {
                                // can not split the clause directly here, because clause like this(a = b GROUP BY
                                // c) will be put at
                                // the end of where clause
                                needSplitFilters.add(pFilter);
                            }
                        }
                    }
                    if (!needSplitFilters.isEmpty()) {
                        EList<FilterEntry> entryList = pTable.getFilterEntries();
                        for (FilterEntry pFilter : needSplitFilters) {
                            String expression = pFilter.getExpression().trim();
                            int splitIndex = firstIndexInString(expression, DbMapSqlConstants.GROUP_BY_PATTERN);
                            int orderIndex = firstIndexInString(expression, DbMapSqlConstants.ORDER_BY_PATTERN);
                            if (splitIndex < 0 || (0 <= orderIndex && orderIndex < splitIndex)) {
                                splitIndex = orderIndex;
                            }
                            if (splitIndex == 0) {
                                // keep the order of "GROUP BY" and "ORDER BY"
                                pFilter.setFilterKind(FilterTableEntry.OTHER_FILTER);
                                entryList.remove(pFilter);
                                newFilters.add(pFilter);
                            } else {
                                String whereClause = expression.substring(0, splitIndex);
                                if (//$NON-NLS-1$
                                !DbGenerationManager.containWith(expression, DbMapSqlConstants.OR + "\\b", true) && !DbGenerationManager.containWith(expression, DbMapSqlConstants.AND + "\\b", true)) {
                                    //$NON-NLS-1$ 
                                    //$NON-NLS-1$
                                    whereClause = DbMapSqlConstants.AND + " " + whereClause;
                                }
                                pFilter.setExpression(whereClause);
                                FilterEntry tFilter = DbmapFactory.eINSTANCE.createFilterEntry();
                                //$NON-NLS-1$
                                tFilter.setName("newFilterSplited" + ++i);
                                tFilter.setExpression(expression.substring(splitIndex).trim());
                                tFilter.setFilterKind(FilterTableEntry.OTHER_FILTER);
                                entryList.remove(pFilter);
                                entryList.add(pFilter);
                                newFilters.add(tFilter);
                            }
                            modified = true;
                        }
                        if (!newFilters.isEmpty()) {
                            pTable.getFilterEntries().addAll(newFilters);
                            modified = true;
                        }
                    }
                }
            }
        }
    }
    try {
        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 : AbstractExternalData(org.talend.designer.core.model.utils.emf.talendfile.AbstractExternalData) DBMapData(org.talend.designer.dbmap.model.emf.dbmap.DBMapData) ArrayList(java.util.ArrayList) OutputTable(org.talend.designer.dbmap.model.emf.dbmap.OutputTable) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) FilterEntry(org.talend.designer.dbmap.model.emf.dbmap.FilterEntry) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

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