Search in sources :

Example 16 with ElementValueType

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

the class SetDefaultValue4tWriteJSONFieldGroupByOutput method execute.

@Override
public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    IComponentFilter filter = new NameComponentFilter("tWriteJSONField");
    try {
        ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(new IComponentConversion() {

            public void transform(NodeType node) {
                EList<ElementValueType> list = ComponentUtilities.getNodeProperty(node, "GROUPBYS").getElementValue();
                ElementValueType outputColumnPropertyElement = null;
                int size = list.size();
                if (list != null && size > 0) {
                    String outputFieldValue = ComponentUtilities.getNodeProperty(node, "JSONFIELD").getValue();
                    for (int i = 0, j = 0; i < size; i++) {
                        outputColumnPropertyElement = TalendFileFactory.eINSTANCE.createElementValueType();
                        //$NON-NLS-1$
                        outputColumnPropertyElement.setElementRef("OUTPUT_COLUMN");
                        outputColumnPropertyElement.setValue(outputFieldValue);
                        list.add(j, outputColumnPropertyElement);
                        j = j + 2;
                    }
                }
            }
        }));
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
    return ExecutionResult.SUCCESS_NO_ALERT;
}
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) PersistenceException(org.talend.commons.exception.PersistenceException) NameComponentFilter(org.talend.core.model.components.filters.NameComponentFilter) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Example 17 with ElementValueType

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

the class SetFilterTiemFromTotoFromPOPComponentsMigrationTask method execute.

/*
	 * (non-Javadoc)
	 * 
	 * @seeorg.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;
    }
    try {
        IComponentFilter filter = new NameComponentFilter("tPOP");
        ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(new IComponentConversion() {

            public void transform(NodeType node) {
                ElementParameterType p = ComponentUtilities.getNodeProperty(node, "ADVANCED_FILTER");
                EList<ElementValueType> es = p.getElementValue();
                for (int j = 0; j < es.size(); j++) {
                    if (es.get(j) != null && "To".equals(es.get(j).getValue())) {
                        es.get(j).setValue("From");
                    }
                }
            }
        }));
        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) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Example 18 with ElementValueType

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

the class NewNetsuiteMigrationTask method processSearchConditionsTable.

private void processSearchConditionsTable(GenericElementParameter param, ElementParameterType paramType, NamedThing target) {
    ComponentProperties searchQueryProps = (ComponentProperties) target;
    List<ElementValueType> columns = paramType.getElementValue();
    if (!(columns != null && columns.size() > 0)) {
        return;
    }
    Map<String, String> columnMapping = new HashMap<String, String>();
    columnMapping.put("INPUT_COLUMN", "field");
    columnMapping.put("OPERATOR", "operator");
    columnMapping.put("RVALUE", "value1");
    columnMapping.put("RVALUE2", "value2");
    List<String> fieldPropPossibleValues = new ArrayList<String>();
    List<Map<String, Object>> tableEntries = new ArrayList<Map<String, Object>>();
    Map<String, Object> tableEntry = null;
    for (ElementValueType column : columns) {
        String sourceName = column.getElementRef();
        if ("INPUT_COLUMN".equals(sourceName)) {
            if (tableEntry != null) {
                tableEntries.add(tableEntry);
            }
            tableEntry = new HashMap<String, Object>();
        }
        String targetName = columnMapping.get(sourceName);
        Object targetValue = column.getValue();
        if ("field".equals(targetName)) {
            String mappedFieldName = toInitialLower(targetValue.toString());
            targetValue = mappedFieldName;
            fieldPropPossibleValues.add(mappedFieldName);
        } else if ("operator".equals(targetName)) {
            String mappedOperatorName = searchOperatorMapping.get(targetValue.toString());
            if (mappedOperatorName != null) {
                targetValue = mappedOperatorName;
            }
        }
        tableEntry.put(targetName, targetValue);
    }
    tableEntries.add(tableEntry);
    GenericTableUtils.setTableValues(searchQueryProps, tableEntries, param);
    Property<String> fieldProp = (Property<String>) searchQueryProps.getProperty("field");
    fieldProp.setPossibleValues(Arrays.asList("type"));
    Property<String> operatorProp = (Property<String>) searchQueryProps.getProperty("operator");
    List<String> operatorPropPossibleValues = new ArrayList<String>(searchOperatorMapping.values());
    Collections.sort(operatorPropPossibleValues);
    operatorProp.setPossibleValues(operatorPropPossibleValues);
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ElementValueType(org.talend.designer.core.model.utils.emf.talendfile.ElementValueType) HashMap(java.util.HashMap) Map(java.util.Map) Property(org.talend.daikon.properties.property.Property)

Example 19 with ElementValueType

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

the class ChangeModelForRoutineParameterMigrationTask2 method execute.

@SuppressWarnings("unchecked")
@Override
public ExecutionResult execute(Item item) {
    try {
        List<String> possibleRoutines = new ArrayList<String>();
        List<String> routinesToAdd = new ArrayList<String>();
        String additionalString = LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA ? "." : "";
        IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
        List<IRepositoryViewObject> routines = factory.getAll(ProjectManager.getInstance().getCurrentProject(), ERepositoryObjectType.ROUTINES);
        // always add the system, others must be checked
        for (IRepositoryViewObject object : routines) {
            if (((RoutineItem) object.getProperty().getItem()).isBuiltIn()) {
                routinesToAdd.add(object.getLabel());
            } else {
                possibleRoutines.add(object.getLabel());
            }
        }
        for (Project project : ProjectManager.getInstance().getAllReferencedProjects()) {
            List<IRepositoryViewObject> refRoutines = factory.getAll(project, ERepositoryObjectType.ROUTINES);
            for (IRepositoryViewObject object : refRoutines) {
                if (!((RoutineItem) object.getProperty().getItem()).isBuiltIn()) {
                    if (!possibleRoutines.contains(object.getLabel())) {
                        possibleRoutines.add(object.getLabel());
                        routines.add(object);
                    }
                }
            }
        }
        List<RoutinesParameterType> oldList = Collections.EMPTY_LIST;
        ProcessType processType = getProcessType(item);
        if (null != processType) {
            if (processType.getParameters() != null && processType.getParameters().getRoutinesParameter() == null) {
                ParametersType parameterType = TalendFileFactory.eINSTANCE.createParametersType();
                processType.setParameters(parameterType);
                if (item instanceof ProcessItem) {
                    routinesToAdd.addAll(possibleRoutines);
                    possibleRoutines.clear();
                }
            } else {
                if (processType.getParameters() == null) {
                    processType.setParameters(TalendFileFactory.eINSTANCE.createParametersType());
                }
                oldList = new ArrayList<RoutinesParameterType>(processType.getParameters().getRoutinesParameter());
                if (oldList.isEmpty() && item instanceof ProcessItem) {
                    routinesToAdd.addAll(possibleRoutines);
                    possibleRoutines.clear();
                }
                processType.getParameters().getRoutinesParameter().clear();
            }
            if (processType.getRoutinesDependencies() != null && !processType.getRoutinesDependencies().isEmpty()) {
                processType.getRoutinesDependencies().clear();
            }
            List<RoutinesParameterType> routinesDependencies = (List<RoutinesParameterType>) processType.getParameters().getRoutinesParameter();
            if (!possibleRoutines.isEmpty()) {
                // check possible routines to setup in process
                for (ElementParameterType param : (List<ElementParameterType>) processType.getParameters().getElementParameter()) {
                    for (String routine : possibleRoutines) {
                        if (!routinesToAdd.contains(routine) && param.getValue() != null && param.getValue().contains(routine + additionalString)) {
                            routinesToAdd.add(routine);
                        }
                        for (ElementValueType elementValue : (List<ElementValueType>) param.getElementValue()) {
                            if (!routinesToAdd.contains(routine) && elementValue.getValue() != null && elementValue.getValue().contains(routine + additionalString)) {
                                routinesToAdd.add(routine);
                            }
                        }
                    }
                }
                // check possible routines to setup in nodes
                for (NodeType node : ((List<NodeType>) processType.getNode())) {
                    for (ElementParameterType param : (List<ElementParameterType>) node.getElementParameter()) {
                        for (String routine : possibleRoutines) {
                            if (!routinesToAdd.contains(routine) && param.getValue() != null && param.getValue().contains(routine + additionalString)) {
                                routinesToAdd.add(routine);
                            }
                            for (ElementValueType elementValue : (List<ElementValueType>) param.getElementValue()) {
                                if (!routinesToAdd.contains(routine) && elementValue.getValue() != null && elementValue.getValue().contains(routine + additionalString)) {
                                    routinesToAdd.add(routine);
                                }
                            }
                        }
                    }
                }
                // check possible routines to setup in connections
                for (ConnectionType connection : ((List<ConnectionType>) processType.getConnection())) {
                    for (ElementParameterType param : (List<ElementParameterType>) connection.getElementParameter()) {
                        for (String routine : possibleRoutines) {
                            if (!routinesToAdd.contains(routine) && param.getValue() != null && param.getValue().contains(routine + additionalString)) {
                                routinesToAdd.add(routine);
                            }
                            for (ElementValueType elementValue : (List<ElementValueType>) param.getElementValue()) {
                                if (!routinesToAdd.contains(routine) && elementValue.getValue() != null && elementValue.getValue().contains(routine + additionalString)) {
                                    routinesToAdd.add(routine);
                                }
                            }
                        }
                    }
                }
            }
            // just in case some routine dependencies exist before but are lost... (migration from 4.1.1 or 4.1.2)
            for (RoutinesParameterType routine : oldList) {
                if (!routinesToAdd.contains(routine.getName())) {
                    routinesDependencies.add(routine);
                }
            }
            for (IRepositoryViewObject object : routines) {
                if (routinesToAdd.contains(object.getLabel())) {
                    RoutinesParameterType routinesParameterType = TalendFileFactory.eINSTANCE.createRoutinesParameterType();
                    routinesParameterType.setId(object.getId());
                    routinesParameterType.setName(object.getLabel());
                    routinesDependencies.add(routinesParameterType);
                }
            }
            factory.save(item, true);
        }
        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) RoutinesParameterType(org.talend.designer.core.model.utils.emf.talendfile.RoutinesParameterType) ArrayList(java.util.ArrayList) RoutineItem(org.talend.core.model.properties.RoutineItem) ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) Project(org.talend.core.model.general.Project) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) ElementValueType(org.talend.designer.core.model.utils.emf.talendfile.ElementValueType) ProcessItem(org.talend.core.model.properties.ProcessItem) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ArrayList(java.util.ArrayList) List(java.util.List) ParametersType(org.talend.designer.core.model.utils.emf.talendfile.ParametersType) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 20 with ElementValueType

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

the class ChangeReturnTypeOfServerAliveResult 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();
    EList connections = processType.getConnection();
    for (Object n : node) {
        NodeType type = (NodeType) n;
        EList elementParameterList = type.getElementParameter();
        for (Object elem : elementParameterList) {
            ElementParameterType elemType = (ElementParameterType) elem;
            if (language.equals(ECodeLanguage.JAVA)) {
                if (elemType.getValue() != null && elemType.getValue().contains("tServerAlive")) {
                    //$NON-NLS-1$
                    Matcher match = PATTERN_GET.matcher(elemType.getValue());
                    String replace = getReplaceValue(match);
                    if (replace != null && replace.length() > 0) {
                        elemType.setValue(replace);
                        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("tServerAlive")) {
                        //$NON-NLS-1$
                        Matcher match = PATTERN_GET.matcher(elemVal.getValue());
                        String replace = getReplaceValue(match);
                        if (replace != null && replace.length() > 0) {
                            elemVal.setValue(replace);
                            modified = true;
                        }
                    }
                }
            }
        }
    }
    // the links
    for (Object n : connections) {
        ConnectionType type = (ConnectionType) n;
        EList elementParameterList = type.getElementParameter();
        for (Object elem : elementParameterList) {
            ElementParameterType elemType = (ElementParameterType) elem;
            if (language.equals(ECodeLanguage.JAVA)) {
                if (elemType.getValue() != null && elemType.getValue().contains("tServerAlive")) {
                    //$NON-NLS-1$
                    Matcher match = PATTERN_GET.matcher(elemType.getValue());
                    String replace = getReplaceValue(match);
                    if (replace != null && replace.length() > 0) {
                        elemType.setValue(replace);
                        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) ConnectionType(org.talend.designer.core.model.utils.emf.talendfile.ConnectionType) Matcher(java.util.regex.Matcher) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) ECodeLanguage(org.talend.core.language.ECodeLanguage)

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