Search in sources :

Example 91 with NameComponentFilter

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

the class RenametForForPerl method execute.

public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    if (processType == null) {
        return ExecutionResult.NOTHING_TO_DO;
    }
    try {
        if (getProject().getLanguage().equals(ECodeLanguage.PERL)) {
            //$NON-NLS-1$
            IComponentFilter filter1 = new NameComponentFilter("tFor");
            IComponentConversion addProperty = new AddPropertyLoopTypeConversion();
            //$NON-NLS-1$
            IComponentConversion renameComponent = new RenameComponentConversion("tLoop");
            ModifyComponentsAction.searchAndModify(item, processType, filter1, Arrays.<IComponentConversion>asList(addProperty, renameComponent));
            return ExecutionResult.SUCCESS_WITH_ALERT;
        } else {
            // do nothing
            return ExecutionResult.NOTHING_TO_DO;
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
}
Also used : AddPropertyLoopTypeConversion(org.talend.core.model.components.conversions.AddPropertyLoopTypeConversion) 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) RenameComponentConversion(org.talend.core.model.components.conversions.RenameComponentConversion) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Example 92 with NameComponentFilter

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

the class SetDefineRegisterJarToTrueForPigLoadMigrationTask method setDefineRegisterJar.

private void setDefineRegisterJar(Item item) throws Exception {
    ProcessType processType = getProcessType(item);
    java.util.List<IComponentFilter> filters = new java.util.ArrayList<IComponentFilter>();
    filters.add(new NameComponentFilter("tPigLoad"));
    filters.add(new NameComponentFilter("tPigStoreResult"));
    IComponentConversion addOption = new AddDefineJarOption();
    java.util.Iterator<IComponentFilter> iter = filters.iterator();
    while (iter.hasNext()) {
        IComponentFilter filter = (IComponentFilter) iter.next();
        ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(addOption));
    }
}
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) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Example 93 with NameComponentFilter

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

the class AddNewFieldsForTDQHadoopComponentsTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractJobMigrationTask#executeOnProcess(org.talend.core.model.properties.
     * ProcessItem)
     */
@Override
public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    if (processType == null) {
        return ExecutionResult.NOTHING_TO_DO;
    }
    IComponentConversion changeNamenodeURIValue = new IComponentConversion() {

        public void transform(NodeType node) {
            if (node == null) {
                return;
            }
            //$NON-NLS-1$
            ElementParameterType namenodeURI = ComponentUtilities.getNodeProperty(node, "FS_DEFAULT_NAME");
            if (namenodeURI == null) {
                //$NON-NLS-1$
                ElementParameterType host = ComponentUtilities.getNodeProperty(node, "HOST");
                //$NON-NLS-1$
                ElementParameterType port = ComponentUtilities.getNodeProperty(node, "PORT");
                //$NON-NLS-1$ //$NON-NLS-2$
                ComponentUtilities.addNodeProperty(node, "FS_DEFAULT_NAME", "TEXT");
                ComponentUtilities.setNodeValue(node, "FS_DEFAULT_NAME", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                "\"hdfs://\" + " + host.getValue() + " + \":\" + " + port.getValue() + " + \"/\"");
            }
            //$NON-NLS-1$
            ElementParameterType distribution = ComponentUtilities.getNodeProperty(node, "DISTRIBUTION");
            if (distribution == null) {
                //$NON-NLS-1$
                ElementParameterType dbVersion = ComponentUtilities.getNodeProperty(node, "DB_VERSION");
                //$NON-NLS-1$ //$NON-NLS-2$
                ComponentUtilities.addNodeProperty(node, "DISTRIBUTION", "TEXT");
                String dbVersionValue = dbVersion.getValue();
                if (dbVersionValue.endsWith("_EMR")) {
                    //$NON-NLS-1$
                    //$NON-NLS-1$ //$NON-NLS-2$ 
                    ComponentUtilities.setNodeValue(node, "DISTRIBUTION", "AMAZON_EMR");
                } else if (dbVersionValue.startsWith("HDP_")) {
                    //$NON-NLS-1$
                    //$NON-NLS-1$ //$NON-NLS-2$ 
                    ComponentUtilities.setNodeValue(node, "DISTRIBUTION", "HORTONWORKS");
                } else if (dbVersionValue.startsWith("Cloudera_")) {
                    //$NON-NLS-1$
                    //$NON-NLS-1$ //$NON-NLS-2$ 
                    ComponentUtilities.setNodeValue(node, "DISTRIBUTION", "CLOUDERA");
                } else if (dbVersionValue.startsWith("MAPR")) {
                    //$NON-NLS-1$
                    //$NON-NLS-1$ //$NON-NLS-2$ 
                    ComponentUtilities.setNodeValue(node, "DISTRIBUTION", "MAPR");
                } else if (dbVersionValue.startsWith("APACHE_")) {
                    //$NON-NLS-1$
                    //$NON-NLS-1$ //$NON-NLS-2$ 
                    ComponentUtilities.setNodeValue(node, "DISTRIBUTION", "APACHE");
                }
            }
        }
    };
    try {
        List<IComponentFilter> filters = new ArrayList<IComponentFilter>();
        filters.add(new NameComponentFilter("tGenKeyHadoop"));
        filters.add(new NameComponentFilter("tMatchGroupHadoop"));
        Iterator<IComponentFilter> iter = filters.iterator();
        while (iter.hasNext()) {
            IComponentFilter filter = (IComponentFilter) iter.next();
            ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(changeNamenodeURIValue));
        }
        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) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) IComponentFilter(org.talend.core.model.components.filters.IComponentFilter) ArrayList(java.util.ArrayList) NameComponentFilter(org.talend.core.model.components.filters.NameComponentFilter) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Example 94 with NameComponentFilter

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

the class AddTableActionForUpdateCassandraDatastax method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    final ProcessType processType = getProcessType(item);
    //$NON-NLS-1$ 
    String[] compNames = { "tCassandraOutput" };
    IComponentConversion conversion = new IComponentConversion() {

        @Override
        public void transform(NodeType node) {
            if (node == null) {
                return;
            }
            //$NON-NLS-1$
            ElementParameterType dataAction = ComponentUtilities.getNodeProperty(node, "DATA_ACTION");
            if (dataAction != null && "UPDATA".equals(dataAction.getValue())) {
                //$NON-NLS-1$
                //$NON-NLS-1$ //$NON-NLS-2$
                ComponentUtilities.setNodeValue(node, "TABLE_ACTION", "NONE");
            }
        }
    };
    for (String name : compNames) {
        IComponentFilter filter = new NameComponentFilter(name);
        try {
            ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(conversion));
        } catch (PersistenceException e) {
            // TODO Auto-generated catch block
            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 95 with NameComponentFilter

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

the class AddTransmitOriginalContextFortRunJobMigrationTask method execute.

public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    if (getProject().getLanguage() == ECodeLanguage.PERL || processType == null) {
        return ExecutionResult.NOTHING_TO_DO;
    }
    try {
        //$NON-NLS-1$
        IComponentFilter filter = new NameComponentFilter("tRunJob");
        IComponentConversion addNewProperty = new IComponentConversion() {

            public void transform(NodeType node) {
                //$NON-NLS-1$ //$NON-NLS-2$
                ComponentUtilities.addNodeProperty(node, "TRANSMIT_ORIGINAL_CONTEXT", "CHECK");
                //$NON-NLS-1$ //$NON-NLS-2$
                ComponentUtilities.setNodeValue(node, "TRANSMIT_ORIGINAL_CONTEXT", "false");
            }
        };
        ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(addNewProperty));
        return ExecutionResult.SUCCESS_NO_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) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) NameComponentFilter(org.talend.core.model.components.filters.NameComponentFilter) 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