Search in sources :

Example 1 with ElementValueTypeImpl

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

the class AddPortForTCassandraConfigurationSpark 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 = { "tCassandraConfiguration" };
    IComponentConversion conversion = new IComponentConversion() {

        @Override
        public void transform(NodeType node) {
            if (node == null) {
                return;
            }
            //$NON-NLS-1$
            ElementParameterType parameter = ComponentUtilities.getNodeProperty(node, "PORT");
            List<Object> needRemovedList = new ArrayList<Object>();
            if (parameter == null) {
                // get the value of native port if the user defined it on the configuration table
                String portValue = null;
                //$NON-NLS-1$
                ElementParameterType configTable = ComponentUtilities.getNodeProperty(node, "CASSANDRA_CONFIGURATION");
                boolean findNative = false;
                boolean findRpc = false;
                for (Object e : configTable.getElementValue()) {
                    ElementValueTypeImpl el = (ElementValueTypeImpl) e;
                    if (findNative && "VALUE".equals(el.getElementRef())) {
                        //$NON-NLS-1$
                        portValue = el.getValue();
                        needRemovedList.add(e);
                        findNative = false;
                    }
                    if (findRpc && "VALUE".equals(el.getElementRef())) {
                        //$NON-NLS-1$
                        needRemovedList.add(e);
                        findRpc = false;
                    }
                    if ("KEY".equals(el.getElementRef())) {
                        //$NON-NLS-1$
                        if ("connection_native_port".equals(el.getValue())) {
                            //$NON-NLS-1$
                            findNative = true;
                            needRemovedList.add(e);
                        }
                        if ("connection_rpc_port".equals(el.getValue())) {
                            //$NON-NLS-1$
                            findRpc = true;
                            needRemovedList.add(e);
                        }
                    }
                }
                configTable.getElementValue().removeAll(needRemovedList);
                //$NON-NLS-1$ //$NON-NLS-2$
                ComponentUtilities.addNodeProperty(node, "PORT", "TEXT");
                //$NON-NLS-1$ //$NON-NLS-2$ 
                ComponentUtilities.setNodeValue(node, "PORT", portValue == null ? "\"9042\"" : portValue);
            }
        }
    };
    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 : IComponentFilter(org.talend.core.model.components.filters.IComponentFilter) ArrayList(java.util.ArrayList) 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) ElementValueTypeImpl(org.talend.designer.core.model.utils.emf.talendfile.impl.ElementValueTypeImpl) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) PersistenceException(org.talend.commons.exception.PersistenceException) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Example 2 with ElementValueTypeImpl

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

the class ChangeValueBug14780 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 (getProject().getLanguage() != ECodeLanguage.JAVA || processType == null) {
        return ExecutionResult.NOTHING_TO_DO;
    }
    String[] componentsName = new String[] { "tSchemaComplianceCheck" };
    try {
        for (int i = 0; i < componentsName.length; i++) {
            IComponentFilter filter = new NameComponentFilter(componentsName[i]);
            ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(new IComponentConversion() {

                public void transform(NodeType node) {
                    if (ComponentUtilities.getNodeProperty(node, "EMPTY_IS_NULL") != null) {
                        if (ComponentUtilities.getNodeProperty(node, "EMPTY_IS_NULL").getValue().equals("true")) {
                            ComponentUtilities.addNodeProperty(node, "ALL_EMPTY_ARE_NULL", "CHECK");
                            ComponentUtilities.getNodeProperty(node, "ALL_EMPTY_ARE_NULL").setValue("false");
                            ComponentUtilities.getNodeProperty(node, "EMPTY_IS_NULL").setValue("false");
                        } else {
                            for (Object obj : ComponentUtilities.getNodeProperty(node, "EMPTY_NULL_TABLE").getElementValue()) {
                                ElementValueTypeImpl evt = (ElementValueTypeImpl) obj;
                                if ("EMPTY_NULL".equals(evt.getElementRef())) {
                                    evt.setValue("false");
                                }
                            }
                            ComponentUtilities.addNodeProperty(node, "ALL_EMPTY_ARE_NULL", "CHECK");
                            ComponentUtilities.getNodeProperty(node, "ALL_EMPTY_ARE_NULL").setValue("false");
                        }
                    }
                }
            }));
        }
        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) ElementValueTypeImpl(org.talend.designer.core.model.utils.emf.talendfile.impl.ElementValueTypeImpl) 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 3 with ElementValueTypeImpl

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

the class MapNetsuiteOperatorValueTDI32245 method execute.

@Override
public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    if (getProject().getLanguage() != ECodeLanguage.JAVA || processType == null) {
        return ExecutionResult.NOTHING_TO_DO;
    }
    IComponentConversion changeDeletEmptyFileValue = new IComponentConversion() {

        public void transform(NodeType node) {
            Map<String, String> operatorMap = new HashMap<String, String>();
            operatorMap.put("contains", "S-contains");
            operatorMap.put("doesNotContain", "S-doesNotContain");
            operatorMap.put("doesNotStartWith", "S-doesNotStartWith");
            operatorMap.put("emptyS", "S-empty");
            operatorMap.put("hasKeywords", "S-hasKeywords");
            operatorMap.put("is", "S-is");
            operatorMap.put("isNot", "S-isNot");
            operatorMap.put("notEmptyS", "S-notEmpty");
            operatorMap.put("startsWith", "S-startsWith");
            operatorMap.put("between", "N-between");
            operatorMap.put("notBetween", "N-notBetween");
            operatorMap.put("emptyN", "N-empty");
            operatorMap.put("equalTo", "N-equalTo");
            operatorMap.put("greaterThan", "N-greaterThan");
            operatorMap.put("greaterThanOrEqualTo", "N-greaterThanOrEqualTo");
            operatorMap.put("lessThan", "N-lessThan");
            operatorMap.put("lessThanOrEqualTo", "N-lessThanOrEqualTo");
            operatorMap.put("notEmptyN", "N-notEmpty");
            operatorMap.put("notEqualTo", "N-notEqualTo");
            operatorMap.put("notGreaterThan", "N-notGreaterThan");
            operatorMap.put("notGreaterThanOrEqualTo", "N-notGreaterThanOrEqualTo");
            operatorMap.put("notLessThan", "N-notLessThan");
            operatorMap.put("notLessThanOrEqualTo", "N-notLessThanOrEqualTo");
            operatorMap.put("anyOf", "L-anyOf");
            operatorMap.put("noneOf", "L-noneOf");
            operatorMap.put("after", "D-after");
            operatorMap.put("before", "D-before");
            operatorMap.put("emptyD", "D-empty");
            operatorMap.put("notAfter", "D-notAfter");
            operatorMap.put("notBefore", "D-notBefore");
            operatorMap.put("notEmptyD", "D-notEmpty");
            operatorMap.put("notOn", "D-notOn");
            operatorMap.put("notOnOrAfter", "D-notOnOrAfter");
            operatorMap.put("notOnOrBefore", "D-notOnOrBefore");
            operatorMap.put("notWithin", "D-notWithin");
            operatorMap.put("on", "D-on");
            operatorMap.put("onOrAfter", "D-onOrAfter");
            operatorMap.put("onOrBefore", "D-onOrBefore");
            operatorMap.put("within", "D-within");
            operatorMap.put("boolean", "B-boolean");
            ElementParameterType criteriaTable = ComponentUtilities.getNodeProperty(node, "CONDITIONS");
            if (criteriaTable != null) {
                for (Object o : criteriaTable.getElementValue()) {
                    ElementValueTypeImpl el = (ElementValueTypeImpl) o;
                    if (el.getElementRef().equals("OPERATOR")) {
                        String oldValue = el.getValue();
                        String newValue = operatorMap.get(oldValue);
                        el.setValue(newValue);
                    }
                }
            }
        }
    };
    //$NON-NLS-1$
    IComponentFilter filter = new NameComponentFilter("tNetsuiteInput");
    try {
        ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(changeDeletEmptyFileValue));
    } 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) HashMap(java.util.HashMap) ElementValueTypeImpl(org.talend.designer.core.model.utils.emf.talendfile.impl.ElementValueTypeImpl) 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 4 with ElementValueTypeImpl

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

the class UpgradeAttributestFilterRow 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 (getProject().getLanguage() == ECodeLanguage.PERL || processType == null) {
        return ExecutionResult.NOTHING_TO_DO;
    } else {
        //$NON-NLS-1$
        String functionName = "FUNCTION";
        //$NON-NLS-1$
        String operatorName = "OPERATOR";
        String[][] replaceFuntions = new String[][] { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        { "S_VALUE_OF", "" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        { "N_VALUE_OF_FLOAT", "" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        { "N_VALUE_OF_INTEGER", "" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        { "ABS_VALUE_FLOAT", "Math.abs($source) $operator $target" }, //$NON-NLS-1$ //$NON-NLS-2$
        { "ABS_VALUE_INTEGER", "Math.abs($source) $operator $target" }, //$NON-NLS-1$ //$NON-NLS-2$
        { "LC", "$source == null? false : $source.toLowerCase().compareTo($target) $operator 0" }, //$NON-NLS-1$ //$NON-NLS-2$
        { "UC", "$source == null? false : $source.toUpperCase().compareTo($target) $operator 0" }, //$NON-NLS-1$ //$NON-NLS-2$
        { "LCFIRST", "$source == null? false : $source.toLowerCase().charAt(0).compareTo($target) $operator 0" }, //$NON-NLS-1$ //$NON-NLS-2$
        { "UCFIRST", "$source == null? false : $source.toUpperCase().charAt(0).compareTo($target) $operator 0" }, //$NON-NLS-1$ //$NON-NLS-2$
        { "LENGTH", "$source == null? false : $source.length() $operator $target" } };
        String[][] replaceOperator = new String[][] { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
        { "EQ", "==" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
        { "NE", "!=" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
        { "GT", ">" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
        { "LT", "<" }, { "GE", ">=" }, { "LE", "<=" }, { "MATCH", "==" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
        { "NMATCH", "!=" } };
        boolean isModified = false;
        NodeType tFilterRow = null;
        for (Object oNodeType : processType.getNode()) {
            NodeType nodeType = (NodeType) oNodeType;
            if (nodeType.getComponentName().equals("tFilterRow")) {
                //$NON-NLS-1$
                tFilterRow = nodeType;
                break;
            }
        }
        if (tFilterRow != null) {
            EList elementParameter = tFilterRow.getElementParameter();
            for (Object object : elementParameter) {
                ElementParameterTypeImpl parameter = (ElementParameterTypeImpl) object;
                if (parameter.getName().equals("CONDITIONS")) {
                    //$NON-NLS-1$
                    EList elementValue = parameter.getElementValue();
                    ElementValueTypeImpl lastFunctionForMatch = null;
                    for (Object object2 : elementValue) {
                        ElementValueTypeImpl tableElement = (ElementValueTypeImpl) object2;
                        if (tableElement.getElementRef().equals(functionName)) {
                            for (String[] element : replaceFuntions) {
                                if (element[0].equals(tableElement.getValue())) {
                                    tableElement.setValue(element[1]);
                                    lastFunctionForMatch = tableElement;
                                    isModified = true;
                                }
                            }
                        } else if (tableElement.getElementRef().equals(operatorName)) {
                            for (String[] element : replaceOperator) {
                                // list"
                                if ("MATCH".equals(tableElement.getValue()) || "NMATCH".equals(tableElement.getValue())) {
                                    //$NON-NLS-1$ //$NON-NLS-2$
                                    if (lastFunctionForMatch != null) {
                                        lastFunctionForMatch.setValue(//$NON-NLS-1$
                                        "$source == null? false : $source.matches($target) $operator true");
                                        isModified = true;
                                    }
                                }
                                if (element[0].equals(tableElement.getValue())) {
                                    tableElement.setValue(element[1]);
                                    isModified = true;
                                }
                            }
                        }
                    }
                } else if (parameter.getName().equals("LOGICAL_OP")) {
                    //$NON-NLS-1$
                    if (parameter.getValue().equals("AND")) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$
                        parameter.setValue("&&");
                        isModified = true;
                    } else if (parameter.getValue().equals("OR")) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$
                        parameter.setValue("||");
                        isModified = true;
                    }
                }
            }
        }
        if (isModified) {
            IRepositoryService service = (IRepositoryService) GlobalServiceRegister.getDefault().getService(IRepositoryService.class);
            IProxyRepositoryFactory factory = service.getProxyRepositoryFactory();
            try {
                factory.save(item, true);
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
                return ExecutionResult.FAILURE;
            }
        }
        return ExecutionResult.SUCCESS_NO_ALERT;
    }
}
Also used : IRepositoryService(org.talend.repository.model.IRepositoryService) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) EList(org.eclipse.emf.common.util.EList) ElementValueTypeImpl(org.talend.designer.core.model.utils.emf.talendfile.impl.ElementValueTypeImpl) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) PersistenceException(org.talend.commons.exception.PersistenceException) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) ElementParameterTypeImpl(org.talend.designer.core.model.utils.emf.talendfile.impl.ElementParameterTypeImpl)

Aggregations

NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)4 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)4 ElementValueTypeImpl (org.talend.designer.core.model.utils.emf.talendfile.impl.ElementValueTypeImpl)4 PersistenceException (org.talend.commons.exception.PersistenceException)3 IComponentConversion (org.talend.core.model.components.conversions.IComponentConversion)3 IComponentFilter (org.talend.core.model.components.filters.IComponentFilter)3 NameComponentFilter (org.talend.core.model.components.filters.NameComponentFilter)3 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 EList (org.eclipse.emf.common.util.EList)1 ElementParameterTypeImpl (org.talend.designer.core.model.utils.emf.talendfile.impl.ElementParameterTypeImpl)1 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)1 IRepositoryService (org.talend.repository.model.IRepositoryService)1