Search in sources :

Example 86 with NameComponentFilter

use of org.talend.core.model.components.filters.NameComponentFilter in project tdi-studio-se by Talend.

the class SetDefaultValueForNewerEmailFirstOfTDI35976 method execute.

@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("tPOP");
    IComponentConversion correctBatchModeForDBComponents = new IComponentConversion() {

        public void transform(NodeType node) {
            ElementParameterType isNewEmailFirst = ComponentUtilities.getNodeProperty(node, "NEWER_EMAILS");
            if (isNewEmailFirst == null) {
                ComponentUtilities.addNodeProperty(node, "NEWER_EMAILS", "CHECK");
                ComponentUtilities.getNodeProperty(node, "NEWER_EMAILS").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 87 with NameComponentFilter

use of org.talend.core.model.components.filters.NameComponentFilter in project tdi-studio-se by Talend.

the class RenametFileInputCSVMigrationTask method execute.

public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    if (processType == null) {
        return ExecutionResult.NOTHING_TO_DO;
    }
    try {
        //$NON-NLS-1$
        IComponentFilter filter1 = new NameComponentFilter("tFileInputCSV");
        IComponentConversion addProperty = new AddPropertyCSVOptionConversion();
        //$NON-NLS-1$
        IComponentConversion renameComponent = new RenameComponentConversion("tFileInputDelimited");
        ModifyComponentsAction.searchAndModify(item, processType, filter1, Arrays.<IComponentConversion>asList(addProperty, renameComponent));
        return ExecutionResult.SUCCESS_WITH_ALERT;
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
}
Also used : ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) IComponentFilter(org.talend.core.model.components.filters.IComponentFilter) NameComponentFilter(org.talend.core.model.components.filters.NameComponentFilter) AddPropertyCSVOptionConversion(org.talend.core.model.components.conversions.AddPropertyCSVOptionConversion) RenameComponentConversion(org.talend.core.model.components.conversions.RenameComponentConversion) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Example 88 with NameComponentFilter

use of org.talend.core.model.components.filters.NameComponentFilter in project tdi-studio-se by Talend.

the class RenametFileOutputCSVMigrationTask method execute.

public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    if (processType == null) {
        return ExecutionResult.NOTHING_TO_DO;
    }
    try {
        //$NON-NLS-1$
        IComponentFilter filter1 = new NameComponentFilter("tFileOutputCSV");
        IComponentConversion addProperty = new AddPropertyCSVOptionConversion();
        //$NON-NLS-1$
        IComponentConversion renameComponent = new RenameComponentConversion("tFileOutputDelimited");
        ModifyComponentsAction.searchAndModify(item, processType, filter1, Arrays.<IComponentConversion>asList(addProperty, renameComponent));
        return ExecutionResult.SUCCESS_WITH_ALERT;
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
}
Also used : ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) IComponentFilter(org.talend.core.model.components.filters.IComponentFilter) NameComponentFilter(org.talend.core.model.components.filters.NameComponentFilter) AddPropertyCSVOptionConversion(org.talend.core.model.components.conversions.AddPropertyCSVOptionConversion) RenameComponentConversion(org.talend.core.model.components.conversions.RenameComponentConversion) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Example 89 with NameComponentFilter

use of org.talend.core.model.components.filters.NameComponentFilter in project tdi-studio-se by Talend.

the class ReplacetFileOutputXMLParameterMigrationTask method execute.

public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    if (getProject().getLanguage() != ECodeLanguage.JAVA || processType == null) {
        return ExecutionResult.NOTHING_TO_DO;
    }
    try {
        IComponentFilter filter = new NameComponentFilter("tFileOutputXML");
        IComponentConversion changeNodeValueConversion = new IComponentConversion() {

            public void transform(NodeType node) {
                ProcessType item = (ProcessType) node.eContainer();
                for (Object o : item.getNode()) {
                    NodeType nt = (NodeType) o;
                    for (Object o1 : nt.getElementParameter()) {
                        ElementParameterType t = (ElementParameterType) o1;
                        if ("TABLE".equals(t.getField()) && ("MAPPING".equals(t.getName()) || "GROUP_BY".equals(t.getName()))) {
                            for (ElementValueType type : (List<ElementValueType>) t.getElementValue()) {
                                if ("LABEL".equals(type.getElementRef())) {
                                    String value = type.getValue();
                                    if (value != null && (!value.trim().startsWith("\""))) {
                                        type.setValue("\"" + value.trim() + "\"");
                                    }
                                }
                            }
                        }
                    }
                }
            }
        };
        ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(changeNodeValueConversion));
        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) ElementValueType(org.talend.designer.core.model.utils.emf.talendfile.ElementValueType) IComponentFilter(org.talend.core.model.components.filters.IComponentFilter) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) NameComponentFilter(org.talend.core.model.components.filters.NameComponentFilter) List(java.util.List) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Example 90 with NameComponentFilter

use of org.talend.core.model.components.filters.NameComponentFilter in project tdi-studio-se by Talend.

the class RenametELTMigrationTask method execute.

public ExecutionResult execute(Item item) {
    final String[] source = { "tELT", "tELTAggregate", "tELTCommit", "tELTFilterColumns", "tELTFilterRows", "tELTMerge", "tELTRollback" };
    final String[] target = { "tSQLTemplate", "tSQLTemplateAggregate", "tSQLTemplateCommit", "tSQLTemplateFilterColumns", "tSQLTemplateFilterRows", "tSQLTemplateMerge", "tSQLTemplateRollback" };
    ProcessType processType = getProcessType(item);
    if (getProject().getLanguage() != ECodeLanguage.JAVA || processType == null) {
        return ExecutionResult.NOTHING_TO_DO;
    }
    try {
        for (int i = 0; i < source.length; i++) {
            final int j = i;
            IComponentFilter filter = new NameComponentFilter(source[i]);
            RenameComponentConversion renameConversion = new RenameComponentConversion(target[i]);
            IComponentConversion changeNodeNameConversion = new IComponentConversion() {

                public void transform(NodeType node) {
                    ProcessType item = (ProcessType) node.eContainer();
                    for (Object o : item.getConnection()) {
                        ConnectionType connection = (ConnectionType) o;
                        if ("RUN_IF".equals(connection.getConnectorName())) {
                            for (Object obj : connection.getElementParameter()) {
                                ElementParameterType type = (ElementParameterType) obj;
                                if ("CONDITION".equals(type.getName())) {
                                    if (type.getValue() != null && type.getValue().contains(source[j])) {
                                        String replaceAll = type.getValue().replaceAll(source[j], target[j]);
                                        type.setValue(replaceAll);
                                    }
                                    break;
                                }
                            }
                        }
                    }
                    for (Object o : item.getNode()) {
                        NodeType nt = (NodeType) o;
                        for (Object o1 : nt.getElementParameter()) {
                            ElementParameterType t = (ElementParameterType) o1;
                            String value = t.getValue();
                            if (value != null) {
                                if (value.contains(source[j])) {
                                    String replaceAll = value.replaceAll(source[j], target[j]);
                                    t.setValue(replaceAll);
                                }
                            }
                            if ("TABLE".equals(t.getField())) {
                                for (ElementValueType type : (List<ElementValueType>) t.getElementValue()) {
                                    if (type.getValue() != null && type.getValue().contains(source[j])) {
                                        String replaceAll = type.getValue().replaceAll(source[j], target[j]);
                                        type.setValue(replaceAll);
                                    }
                                }
                            }
                        }
                    }
                }
            };
            ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(renameConversion, changeNodeNameConversion));
        }
        return ExecutionResult.SUCCESS_NO_ALERT;
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
}
Also used : ConnectionType(org.talend.designer.core.model.utils.emf.talendfile.ConnectionType) IComponentFilter(org.talend.core.model.components.filters.IComponentFilter) NameComponentFilter(org.talend.core.model.components.filters.NameComponentFilter) RenameComponentConversion(org.talend.core.model.components.conversions.RenameComponentConversion) ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) ElementValueType(org.talend.designer.core.model.utils.emf.talendfile.ElementValueType) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) List(java.util.List) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Aggregations

NameComponentFilter (org.talend.core.model.components.filters.NameComponentFilter)145 IComponentFilter (org.talend.core.model.components.filters.IComponentFilter)143 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)143 IComponentConversion (org.talend.core.model.components.conversions.IComponentConversion)142 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)108 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)83 PersistenceException (org.talend.commons.exception.PersistenceException)75 ElementValueType (org.talend.designer.core.model.utils.emf.talendfile.ElementValueType)13 ArrayList (java.util.ArrayList)8 RenameComponentConversion (org.talend.core.model.components.conversions.RenameComponentConversion)6 List (java.util.List)5 ConnectionType (org.talend.designer.core.model.utils.emf.talendfile.ConnectionType)4 RemovePropertyComponentConversion (org.talend.core.model.components.conversions.RemovePropertyComponentConversion)3 MetadataType (org.talend.designer.core.model.utils.emf.talendfile.MetadataType)3 HashMap (java.util.HashMap)2 ComponentProperties (org.talend.components.api.properties.ComponentProperties)2 AddPropertyCSVOptionConversion (org.talend.core.model.components.conversions.AddPropertyCSVOptionConversion)2 AddPropertyLoopTypeConversion (org.talend.core.model.components.conversions.AddPropertyLoopTypeConversion)2 AddQuotesInPropertyComponentConversion (org.talend.core.model.components.conversions.AddQuotesInPropertyComponentConversion)2 EConnectionType (org.talend.core.model.process.EConnectionType)2