Search in sources :

Example 31 with ElementValueType

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

the class RenametForCurrentIterationMigrationTask method convertItem.

private boolean convertItem(Item item, ProcessType processType) throws PersistenceException {
    ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    boolean modified = false;
    ECodeLanguage language = getProject().getLanguage();
    EList node = processType.getNode();
    for (Object n : node) {
        NodeType type = (NodeType) n;
        EList elementParameterList = type.getElementParameter();
        for (Object elem : elementParameterList) {
            ElementParameterType elemType = (ElementParameterType) elem;
            if (!elemType.getField().equals("CHECK")) {
                //$NON-NLS-1$
                if (language.equals(ECodeLanguage.JAVA)) {
                    if (elemType.getValue() != null && elemType.getValue().contains(TFOR) && elemType.getValue().contains(CURRENT_ITER)) {
                        elemType.setValue(elemType.getValue().replaceAll(CURRENT_ITER, CURRENT_VALUE));
                    }
                }
                if (elemType.getValue() != null && elemType.getValue().contains(TFOR)) {
                    elemType.setValue(elemType.getValue().replaceAll(TFOR, TLOOP));
                    modified = true;
                }
                // for table
                EList elemValue = elemType.getElementValue();
                for (Object elemV : elemValue) {
                    ElementValueType elemVal = (ElementValueType) elemV;
                    if (language.equals(ECodeLanguage.JAVA)) {
                        if (elemVal.getValue() != null && elemVal.getValue().contains(TFOR) && elemVal.getValue().contains(CURRENT_ITER)) {
                            elemVal.setValue(elemVal.getValue().replaceAll(CURRENT_ITER, CURRENT_VALUE));
                        }
                    }
                    if (elemVal.getValue() != null && elemVal.getValue().contains(TFOR)) {
                        elemVal.setValue(elemVal.getValue().replaceAll(TFOR, TLOOP));
                        modified = true;
                    }
                }
            }
        }
    }
    if (modified) {
        factory.save(item, true);
    }
    return modified;
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) EList(org.eclipse.emf.common.util.EList) ElementValueType(org.talend.designer.core.model.utils.emf.talendfile.ElementValueType) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) ECodeLanguage(org.talend.core.language.ECodeLanguage)

Example 32 with ElementValueType

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

the class ReplaceVarcharArrayWithVarcharIssueTDI35719 method execute.

@Override
public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    final List<String> componentNames = Arrays.asList("tTeradataTPTUtility", "tTeradataTPTExec");
    final String tableToCheck = "TPT_COOA_FOR_UPDATE";
    final List<String> fieldNames = Arrays.asList("ERRORTABLE1", "ERRORTABLE2", "WORKTABLE");
    IComponentFilter filter = new IComponentFilter() {

        @Override
        public boolean accept(NodeType node) {
            return componentNames.contains(node.getComponentName());
        }
    };
    try {
        ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(new IComponentConversion() {

            @Override
            public void transform(NodeType node) {
                String openBrStr = "['";
                String closeBrStr = "']";
                String openBrPattern = Pattern.quote(openBrStr);
                String closeBrPattern = Pattern.quote(closeBrStr);
                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()) && tableToCheck.equals(t.getName())) {
                            List<ElementValueType> elementValues = (List<ElementValueType>) t.getElementValue();
                            for (int i = 0; i < elementValues.size() - 1; i++) {
                                ElementValueType nameCol = elementValues.get(i);
                                String nameValue = nameCol.getValue();
                                if (nameCol.getElementRef().equals("OPTIONAL_ATTRIBUTES_NAME") && nameValue != null && fieldNames.contains(nameValue)) {
                                    ElementValueType valueCol = elementValues.get(++i);
                                    String value = valueCol != null ? valueCol.getValue().trim() : null;
                                    if (value != null && value.contains(openBrStr) || value.contains(closeBrStr)) {
                                        String newValue = value.replaceFirst(openBrPattern, "").replaceFirst(closeBrPattern, "");
                                        if (!value.equals(newValue)) {
                                            valueCol.setValue(newValue);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }));
        return ExecutionResult.SUCCESS_NO_ALERT;
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
}
Also used : IComponentFilter(org.talend.core.model.components.filters.IComponentFilter) 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) PersistenceException(org.talend.commons.exception.PersistenceException) List(java.util.List) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Example 33 with ElementValueType

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

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