Search in sources :

Example 26 with ElementValueType

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

Example 27 with ElementValueType

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

the class CMessgingEndpointSwitchVersionTask method switchVersion.

private boolean switchVersion(NodeType currentNode) throws PersistenceException {
    boolean needSave = false;
    for (Object e : currentNode.getElementParameter()) {
        ElementParameterType p = (ElementParameterType) e;
        if ("HOTLIBS".equals(p.getName())) {
            EList<?> elementValue = p.getElementValue();
            for (Object pv : elementValue) {
                ElementValueType evt = (ElementValueType) pv;
                String evtValue = evt.getValue();
                String switchVersion = switchVersion(evtValue);
                if (switchVersion != null && !switchVersion.equals(evtValue)) {
                    evt.setValue(switchVersion);
                    needSave = true;
                }
            }
        }
    }
    return needSave;
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ElementValueType(org.talend.designer.core.model.utils.emf.talendfile.ElementValueType)

Example 28 with ElementValueType

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

the class SqlTemplateParameterRelationshipHandler method collect.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.relationship.AbstractParameterRelationshipHandler#collect(java.util.Map,
     * java.util.Map)
     */
@Override
protected Set<Relation> collect(Map<String, ElementParameterType> parametersMap, Map<?, ?> options) {
    Set<Relation> relationSet = new HashSet<Relation>();
    //$NON-NLS-1$
    ElementParameterType sqlpatternParamType = parametersMap.get("SQLPATTERN_VALUE");
    // only for SQL Patterns
    if (sqlpatternParamType != null) {
        for (Object o3 : sqlpatternParamType.getElementValue()) {
            if (o3 instanceof ElementValueType && "SQLPATTERNLIST".equals(((ElementValueType) o3).getElementRef())) {
                //$NON-NLS-1$
                Relation addedRelation = new Relation();
                addedRelation.setId(((ElementValueType) o3).getValue());
                addedRelation.setType(RelationshipItemBuilder.SQLPATTERN_RELATION);
                addedRelation.setVersion(RelationshipItemBuilder.LATEST_VERSION);
                relationSet.add(addedRelation);
            }
        }
    }
    return relationSet;
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) Relation(org.talend.core.model.relationship.Relation) ElementValueType(org.talend.designer.core.model.utils.emf.talendfile.ElementValueType) HashSet(java.util.HashSet)

Example 29 with ElementValueType

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

the class UpgradetDenormalizeMigrationTask method execute.

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("tDenormalize");
        IComponentConversion conversion = new IComponentConversion() {

            public void transform(NodeType node) {
                List<ElementValueType> values = new ArrayList<ElementValueType>();
                TalendFileFactory fileFact = TalendFileFactory.eINSTANCE;
                MetadataType object = (MetadataType) node.getMetadata().get(0);
                //$NON-NLS-1$
                String delimiterValue = ComponentUtilities.getNodePropertyValue(node, "DELIMITER");
                //$NON-NLS-1$
                String mergeValue = ComponentUtilities.getNodePropertyValue(node, "MERGE");
                //$NON-NLS-1$
                ElementParameterType p = ComponentUtilities.getNodeProperty(node, "GROUPS");
                if (p != null) {
                    EList<ElementValueType> es = p.getElementValue();
                    List<String> groups = new ArrayList<String>();
                    for (ElementValueType e : es) {
                        if (e.getElementRef().equals("INPUT_COLUMN")) {
                            //$NON-NLS-1$
                            groups.add(e.getValue());
                        }
                    }
                    for (Object o : object.getColumn()) {
                        ColumnType tagada = (ColumnType) o;
                        if (groups.contains(tagada.getName())) {
                            continue;
                        }
                        ElementValueType elementValue = fileFact.createElementValueType();
                        //$NON-NLS-1$
                        elementValue.setElementRef("INPUT_COLUMN");
                        elementValue.setValue(tagada.getName());
                        values.add(elementValue);
                        ElementValueType elementValue2 = fileFact.createElementValueType();
                        //$NON-NLS-1$
                        elementValue2.setElementRef("DELIMITER");
                        elementValue2.setValue(delimiterValue);
                        values.add(elementValue2);
                        ElementValueType elementValue3 = fileFact.createElementValueType();
                        //$NON-NLS-1$
                        elementValue3.setElementRef("MERGE");
                        elementValue3.setValue(mergeValue);
                        values.add(elementValue3);
                    }
                    //$NON-NLS-1$ //$NON-NLS-2$
                    ComponentUtilities.addNodeProperty(node, "DENORMALIZE_COLUMNS", "TABLE");
                    //$NON-NLS-1$
                    ComponentUtilities.setNodeProperty(node, "DENORMALIZE_COLUMNS", values);
                    //$NON-NLS-1$
                    ComponentUtilities.removeNodeProperty(node, "DELIMITER");
                    //$NON-NLS-1$
                    ComponentUtilities.removeNodeProperty(node, "MERGE");
                    //$NON-NLS-1$
                    ComponentUtilities.removeNodeProperty(node, "GROUPS");
                }
            }
        };
        ModifyComponentsAction.searchAndModify(item, processType, filter1, Arrays.<IComponentConversion>asList(conversion));
        return ExecutionResult.SUCCESS_NO_ALERT;
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
}
Also used : ColumnType(org.talend.designer.core.model.utils.emf.talendfile.ColumnType) IComponentFilter(org.talend.core.model.components.filters.IComponentFilter) ArrayList(java.util.ArrayList) MetadataType(org.talend.designer.core.model.utils.emf.talendfile.MetadataType) NameComponentFilter(org.talend.core.model.components.filters.NameComponentFilter) 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) TalendFileFactory(org.talend.designer.core.model.utils.emf.talendfile.TalendFileFactory) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Example 30 with ElementValueType

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

the class SubstituteRemovedMDMOperatorMigrationTask method execute.

@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[] { "tMDMInput", "tMDMDelete", "tMDMViewSearch" };
    IComponentConversion substituteRemovedOperatorsFromJobItem = new IComponentConversion() {

        public void transform(NodeType node) {
            ElementParameterType operations = ComponentUtilities.getNodeProperty(node, "OPERATIONS");
            if (operations != null && operations.getElementValue().size() > 0) {
                for (ElementValueType elementValue : (List<ElementValueType>) operations.getElementValue()) {
                    if ("STRICTCONTAINS".equals(elementValue.getValue()) && "FUNCTION".equals(elementValue.getElementRef())) {
                        elementValue.setValue("CONTAINS");
                    }
                }
            }
        }
    };
    for (String name : componentsName) {
        //$NON-NLS-1$
        IComponentFilter filter = new NameComponentFilter(name);
        try {
            ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(substituteRemovedOperatorsFromJobItem));
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
    }
    return ExecutionResult.SUCCESS_WITH_ALERT;
}
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) 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) List(java.util.List) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Aggregations

ElementValueType (org.talend.designer.core.model.utils.emf.talendfile.ElementValueType)35 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)28 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)21 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)16 IComponentConversion (org.talend.core.model.components.conversions.IComponentConversion)15 IComponentFilter (org.talend.core.model.components.filters.IComponentFilter)15 NameComponentFilter (org.talend.core.model.components.filters.NameComponentFilter)13 ArrayList (java.util.ArrayList)12 List (java.util.List)11 EList (org.eclipse.emf.common.util.EList)8 HashMap (java.util.HashMap)7 Map (java.util.Map)6 PersistenceException (org.talend.commons.exception.PersistenceException)6 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)5 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)4 ConnectionType (org.talend.designer.core.model.utils.emf.talendfile.ConnectionType)4 HashSet (java.util.HashSet)2 EObject (org.eclipse.emf.ecore.EObject)2 ECodeLanguage (org.talend.core.language.ECodeLanguage)2 RemovePropertyComponentConversion (org.talend.core.model.components.conversions.RemovePropertyComponentConversion)2