Search in sources :

Example 71 with NameComponentFilter

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

the class MoveExcelSheetnameToSheetlist method execute.

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

            public void transform(NodeType node) {
                //$NON-NLS-1$ //$NON-NLS-2$
                ComponentUtilities.addNodeProperty(node, "SHEETLIST", "TABLE");
                List<ElementValueType> values = new ArrayList<ElementValueType>();
                ElementValueType eValue = TalendFileFactory.eINSTANCE.createElementValueType();
                //$NON-NLS-1$
                eValue.setElementRef("SHEETNAME");
                //$NON-NLS-1$
                eValue.setValue(ComponentUtilities.getNodePropertyValue(node, "SHEETNAME"));
                values.add(eValue);
                //$NON-NLS-1$
                ComponentUtilities.setNodeProperty(node, "SHEETLIST", values);
            }
        };
        //$NON-NLS-1$
        IComponentConversion removeOldProperty = new RemovePropertyComponentConversion("SHEETNAME");
        ModifyComponentsAction.searchAndModify(item, processType, filter1, Arrays.<IComponentConversion>asList(addNewProperty, removeOldProperty));
        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) 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) ArrayList(java.util.ArrayList) RemovePropertyComponentConversion(org.talend.core.model.components.conversions.RemovePropertyComponentConversion) NameComponentFilter(org.talend.core.model.components.filters.NameComponentFilter) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Example 72 with NameComponentFilter

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

the class MoveExcelSheetnameToSheetlistForJava method execute.

@Override
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 filter1 = new NameComponentFilter("tFileInputExcel");
        IComponentConversion addNewProperty = new IComponentConversion() {

            public void transform(NodeType node) {
                //$NON-NLS-1$ //$NON-NLS-2$
                ComponentUtilities.addNodeProperty(node, "SHEETLIST", "TABLE");
                List<ElementValueType> values = new ArrayList<ElementValueType>();
                ElementValueType eValue = TalendFileFactory.eINSTANCE.createElementValueType();
                //$NON-NLS-1$
                eValue.setElementRef("SHEETNAME");
                //$NON-NLS-1$
                eValue.setValue(ComponentUtilities.getNodePropertyValue(node, "SHEETNAME"));
                values.add(eValue);
                //$NON-NLS-1$
                ComponentUtilities.setNodeProperty(node, "SHEETLIST", values);
            }
        };
        //$NON-NLS-1$
        IComponentConversion removeOldProperty = new RemovePropertyComponentConversion("SHEETNAME");
        ModifyComponentsAction.searchAndModify(item, processType, filter1, Arrays.<IComponentConversion>asList(addNewProperty, removeOldProperty));
        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) 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) ArrayList(java.util.ArrayList) RemovePropertyComponentConversion(org.talend.core.model.components.conversions.RemovePropertyComponentConversion) NameComponentFilter(org.talend.core.model.components.filters.NameComponentFilter) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Example 73 with NameComponentFilter

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

the class MoveFileListFilemaskToFilemaskListForJava method execute.

@Override
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 filter1 = new NameComponentFilter("tFileList");
        IComponentConversion addNewProperty = new IComponentConversion() {

            public void transform(NodeType node) {
                //$NON-NLS-1$ //$NON-NLS-2$
                ComponentUtilities.addNodeProperty(node, "FILES", "TABLE");
                List<ElementValueType> values = new ArrayList<ElementValueType>();
                ElementValueType eValue = TalendFileFactory.eINSTANCE.createElementValueType();
                //$NON-NLS-1$
                eValue.setElementRef("FILEMASK");
                //$NON-NLS-1$
                eValue.setValue(ComponentUtilities.getNodePropertyValue(node, "FILEMASK"));
                values.add(eValue);
                //$NON-NLS-1$
                ComponentUtilities.setNodeProperty(node, "FILES", values);
            }
        };
        ModifyComponentsAction.searchAndModify(item, processType, filter1, Arrays.<IComponentConversion>asList(addNewProperty));
        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) 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) ArrayList(java.util.ArrayList) NameComponentFilter(org.talend.core.model.components.filters.NameComponentFilter) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Example 74 with NameComponentFilter

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

the class RenametFor method execute.

public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    try {
        if (getProject().getLanguage().equals(ECodeLanguage.JAVA) && processType != null) {
            //$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 75 with NameComponentFilter

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

the class Salesforce620Migration 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;
    }
    String[] componentsName = new String[] { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    "tSalesforceConnection", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    "tSalesforceBulkExec", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    "tSalesforceGetDeleted", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    "tSalesforceGetUpdated", "tSalesforceInput", "tSalesforceOutput", "tSalesforceOutputBulk", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    "tSalesforceOutputBulkExec" };
    IComponentConversion changeJDBCDriverJarType = new IComponentConversion() {

        @Override
        public void transform(NodeType node) {
            ElementParameterType elemParamType = ComponentUtilities.getNodeProperty(node, "PROPERTIES");
            String propertiesString = elemParamType.getValue();
            SerializerDeserializer.Deserialized<ComponentProperties> fromSerialized = Properties.Helper.fromSerializedPersistent(propertiesString, ComponentProperties.class, new PostDeserializeSetup() {

                @Override
                public void setup(Object properties) {
                    ((Properties) properties).setValueEvaluator(new PropertyValueEvaluator() {

                        @Override
                        public Object evaluate(Property property, Object storedValue) {
                            if (storedValue instanceof String) {
                                if (GenericTypeUtils.isEnumType(property)) {
                                    ComponentProperties newProperties = ComponentsUtils.getComponentProperties(node.getComponentName());
                                    Property newProperty = (Property) newProperties.getProperty(property.getName());
                                    if (newProperty == null) {
                                        newProperty = (Property) newProperties.getProperty("connection.loginType");
                                    }
                                    if (newProperty != null) {
                                        List<?> propertyPossibleValues = ((Property<?>) newProperty).getPossibleValues();
                                        if (propertyPossibleValues != null) {
                                            for (Object possibleValue : propertyPossibleValues) {
                                                if (possibleValue.toString().equals(storedValue)) {
                                                    property.setStoredValue(possibleValue);
                                                    return possibleValue;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            return storedValue;
                        }
                    });
                }
            });
            ComponentProperties newProperties = ComponentsUtils.getComponentProperties(node.getComponentName());
            updateSubProperties(fromSerialized.object, newProperties);
            newProperties.copyValuesFrom(fromSerialized.object, true, false);
            NamedThing nt = newProperties.getProperty("module.moduleName");
            if (nt != null && nt instanceof Property) {
                Property moduleNameProperty = (Property) nt;
                String moduleName = (String) moduleNameProperty.getValue();
                if (ContextParameterUtils.isContainContextParam(moduleName)) {
                    moduleName = TalendQuoteUtils.removeQuotes(moduleName);
                } else {
                    moduleName = TalendQuoteUtils.addPairQuotesIfNotExist(moduleName);
                }
                moduleNameProperty.setStoredValue(moduleName);
            }
            nt = newProperties.getProperty("upsertRelationTable.columnName");
            if (nt != null && nt instanceof Property) {
                Property moduleNameProperty = (Property) nt;
                if (moduleNameProperty.getPossibleValues() == null || moduleNameProperty.getPossibleValues().isEmpty()) {
                    List<String> columns = new ArrayList<String>();
                    if (moduleNameProperty.getValue() instanceof String) {
                        String column = (String) moduleNameProperty.getValue();
                        columns.add(column);
                    } else if (moduleNameProperty.getValue() instanceof List) {
                        columns.addAll((Collection<? extends String>) moduleNameProperty.getValue());
                    }
                    moduleNameProperty.setPossibleValues(columns);
                }
            }
            elemParamType.setValue(newProperties.toSerialized());
        }
    };
    boolean modified = false;
    for (Object obj : processType.getNode()) {
        if (obj != null && obj instanceof NodeType) {
            String componentName = ((NodeType) obj).getComponentName();
            if (ArrayUtils.contains(componentsName, componentName)) {
                IComponentFilter filter = new NameComponentFilter(componentName);
                modified = ModifyComponentsAction.searchAndModify((NodeType) obj, filter, Arrays.<IComponentConversion>asList(changeJDBCDriverJarType)) || modified;
            }
        }
    }
    if (modified) {
        try {
            ProxyRepositoryFactory.getInstance().save(item, true);
            return ExecutionResult.SUCCESS_NO_ALERT;
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
    }
    return ExecutionResult.SUCCESS_WITH_ALERT;
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) IComponentFilter(org.talend.core.model.components.filters.IComponentFilter) ArrayList(java.util.ArrayList) PropertyValueEvaluator(org.talend.daikon.properties.property.PropertyValueEvaluator) NameComponentFilter(org.talend.core.model.components.filters.NameComponentFilter) NamedThing(org.talend.daikon.NamedThing) 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) PersistenceException(org.talend.commons.exception.PersistenceException) SerializerDeserializer(org.talend.daikon.serialize.SerializerDeserializer) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) Property(org.talend.daikon.properties.property.Property) EnumProperty(org.talend.daikon.properties.property.EnumProperty) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion) PostDeserializeSetup(org.talend.daikon.serialize.PostDeserializeSetup)

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