Search in sources :

Example 11 with ElementParameterTypeImpl

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

the class UpdateJobSettingsForPostgresMigrationTask method updateJarValue.

private boolean updateJarValue(EList elementParameter) {
    for (int i = 0; i < elementParameter.size(); i++) {
        final Object object = elementParameter.get(i);
        if (object instanceof ElementParameterTypeImpl) {
            ElementParameterTypeImpl parameterType = (ElementParameterTypeImpl) object;
            String name = parameterType.getName();
            if ("DB_VERSION".equals(name)) {
                String value = parameterType.getValue();
                if (value.equals(EDatabaseVersion4Drivers.PSQL_PRIOR_TO_V9.getVersionValue()) || value.equals(EDatabaseVersion4Drivers.PSQL_V9_X.getVersionValue())) {
                // do nothing
                } else {
                    parameterType.setValue(EDatabaseVersion4Drivers.PSQL_PRIOR_TO_V9.getVersionValue());
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : ElementParameterTypeImpl(org.talend.designer.core.model.utils.emf.talendfile.impl.ElementParameterTypeImpl)

Example 12 with ElementParameterTypeImpl

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

Example 13 with ElementParameterTypeImpl

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

the class ChangePostgresDbVersionForProjectSetting method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.migration.IProjectMigrationTask#execute(org.talend.core.model.general.Project)
     */
@Override
public ExecutionResult execute(Project project) {
    org.talend.core.model.properties.Project emfProject = project.getEmfProject();
    StatAndLogsSettings statAndLogs = emfProject.getStatAndLogsSettings();
    boolean modified = false;
    if (statAndLogs != null && statAndLogs.getParameters() != null) {
        ParametersType parameters = statAndLogs.getParameters();
        List elementParameter = parameters.getElementParameter();
        for (int i = 0; i < elementParameter.size(); i++) {
            final Object object = elementParameter.get(i);
            if (object instanceof ElementParameterTypeImpl) {
                ElementParameterTypeImpl parameterType = (ElementParameterTypeImpl) object;
                String name = parameterType.getName();
                if ("ON_DATABASE_FLAG".equals(name) && !Boolean.valueOf(parameterType.getValue())) {
                    //$NON-NLS-1$
                    break;
                }
                if ("DB_TYPE".equals(name) && parameterType.getValue().startsWith("tPostgresql")) {
                    //$NON-NLS-1$
                    modified = updateJarValue(elementParameter) || modified;
                }
            }
        }
    }
    ImplicitContextSettings implicitContext = emfProject.getImplicitContextSettings();
    if (implicitContext != null && implicitContext.getParameters() != null) {
        ParametersType parameters = implicitContext.getParameters();
        List elementParameter = parameters.getElementParameter();
        for (int i = 0; i < elementParameter.size(); i++) {
            final Object object = elementParameter.get(i);
            if (object instanceof ElementParameterTypeImpl) {
                ElementParameterTypeImpl parameterType = (ElementParameterTypeImpl) object;
                String name = parameterType.getName();
                if ("FROM_DATABASE_FLAG_IMPLICIT_CONTEXT".equals(name) && !Boolean.valueOf(parameterType.getValue())) {
                    //$NON-NLS-1$
                    break;
                }
                if ("DB_TYPE_IMPLICIT_CONTEXT".equals(name) && parameterType.getValue().startsWith("tPostgresql")) {
                    //$NON-NLS-1$
                    modified = updateJarValueForImplici(elementParameter) || modified;
                }
            }
        }
    }
    if (modified) {
        try {
            IProxyRepositoryFactory prf = CorePlugin.getDefault().getProxyRepositoryFactory();
            prf.saveProject(project);
            return ExecutionResult.SUCCESS_NO_ALERT;
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : ImplicitContextSettings(org.talend.core.model.properties.ImplicitContextSettings) StatAndLogsSettings(org.talend.core.model.properties.StatAndLogsSettings) PersistenceException(org.talend.commons.exception.PersistenceException) EList(org.eclipse.emf.common.util.EList) List(java.util.List) ParametersType(org.talend.designer.core.model.utils.emf.talendfile.ParametersType) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) ElementParameterTypeImpl(org.talend.designer.core.model.utils.emf.talendfile.impl.ElementParameterTypeImpl)

Example 14 with ElementParameterTypeImpl

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

the class ChangePostgresDbVersionForProjectSetting method updateJarValue.

private boolean updateJarValue(List elementParameter) {
    for (int i = 0; i < elementParameter.size(); i++) {
        final Object object = elementParameter.get(i);
        if (object instanceof ElementParameterTypeImpl) {
            ElementParameterTypeImpl parameterType = (ElementParameterTypeImpl) object;
            String name = parameterType.getName();
            if ("DB_VERSION".equals(name)) {
                String value = parameterType.getValue();
                if (value.equals(EDatabaseVersion4Drivers.PSQL_PRIOR_TO_V9.getVersionValue()) || value.equals(EDatabaseVersion4Drivers.PSQL_V9_X.getVersionValue())) {
                // do nothing
                } else {
                    parameterType.setValue(EDatabaseVersion4Drivers.PSQL_PRIOR_TO_V9.getVersionValue());
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : ElementParameterTypeImpl(org.talend.designer.core.model.utils.emf.talendfile.impl.ElementParameterTypeImpl)

Example 15 with ElementParameterTypeImpl

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

the class ChangePostgresDbVersionForProjectSetting method updateJarValueForImplici.

private boolean updateJarValueForImplici(List elementParameter) {
    for (int i = 0; i < elementParameter.size(); i++) {
        final Object object = elementParameter.get(i);
        if (object instanceof ElementParameterTypeImpl) {
            ElementParameterTypeImpl parameterType = (ElementParameterTypeImpl) object;
            String name = parameterType.getName();
            if ("DB_VERSION_IMPLICIT_CONTEXT".equals(name)) {
                String value = parameterType.getValue();
                if (value.equals(EDatabaseVersion4Drivers.PSQL_PRIOR_TO_V9.getVersionValue()) || value.equals(EDatabaseVersion4Drivers.PSQL_V9_X.getVersionValue())) {
                // do nothing
                } else {
                    parameterType.setValue(EDatabaseVersion4Drivers.PSQL_PRIOR_TO_V9.getVersionValue());
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : ElementParameterTypeImpl(org.talend.designer.core.model.utils.emf.talendfile.impl.ElementParameterTypeImpl)

Aggregations

ElementParameterTypeImpl (org.talend.designer.core.model.utils.emf.talendfile.impl.ElementParameterTypeImpl)16 PersistenceException (org.talend.commons.exception.PersistenceException)11 EList (org.eclipse.emf.common.util.EList)7 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)6 List (java.util.List)5 ImplicitContextSettings (org.talend.core.model.properties.ImplicitContextSettings)5 StatAndLogsSettings (org.talend.core.model.properties.StatAndLogsSettings)5 ParametersType (org.talend.designer.core.model.utils.emf.talendfile.ParametersType)5 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)5 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)2 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)1 ElementValueTypeImpl (org.talend.designer.core.model.utils.emf.talendfile.impl.ElementValueTypeImpl)1 IRepositoryService (org.talend.repository.model.IRepositoryService)1