Search in sources :

Example 36 with ElementParameterType

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

the class EncryptPasswordInProjectSettingsMigrationTask 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 ElementParameterType) {
                ElementParameterType parameterType = (ElementParameterType) object;
                String name = parameterType.getName();
                // variable name used for Stat&Logs
                if ("PASS".equals(name)) {
                    //$NON-NLS-1$
                    try {
                        if (encryptValueIfNeeded(parameterType)) {
                            modified = true;
                        }
                    } catch (Exception e) {
                        ExceptionHandler.process(e);
                        return ExecutionResult.FAILURE;
                    }
                }
            }
        }
    }
    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) {
                ElementParameterType parameterType = (ElementParameterType) object;
                String name = parameterType.getName();
                // variable name used for implicit context
                if ("PASS_IMPLICIT_CONTEXT".equals(name)) {
                    //$NON-NLS-1$
                    try {
                        if (encryptValueIfNeeded(parameterType)) {
                            modified = true;
                        }
                    } catch (Exception e) {
                        ExceptionHandler.process(e);
                        return ExecutionResult.FAILURE;
                    }
                }
            }
        }
    }
    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 : PersistenceException(org.talend.commons.exception.PersistenceException) ImplicitContextSettings(org.talend.core.model.properties.ImplicitContextSettings) ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) StatAndLogsSettings(org.talend.core.model.properties.StatAndLogsSettings) PersistenceException(org.talend.commons.exception.PersistenceException) 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 37 with ElementParameterType

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

the class FileInputRegexContextVariableMigrationTask method addQuote.

private boolean addQuote(Item item) {
    ProcessType processType = getProcessType(item);
    if (processType == null) {
        return false;
    }
    ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    boolean modified = false;
    EList nodes = processType.getNode();
    for (Object n : nodes) {
        NodeType type = (NodeType) n;
        if (type.getComponentName().equals("tFileInputRegex")) {
            //$NON-NLS-1$
            EList elementParameterList = type.getElementParameter();
            for (Object elem : elementParameterList) {
                ElementParameterType elemType = (ElementParameterType) elem;
                if (//$NON-NLS-1$ //$NON-NLS-2$
                elemType.getName().equals("HEADER") || elemType.getName().equals("FOOTER") || elemType.getName().equals("LIMIT")) {
                    //$NON-NLS-1$
                    String oldV = elemType.getValue();
                    if (oldV == null || oldV.length() == 0) {
                        if (elemType.getName().equals("LIMIT")) {
                            //$NON-NLS-1$
                            //$NON-NLS-1$
                            oldV = "-1";
                        } else {
                            //$NON-NLS-1$
                            oldV = "0";
                        }
                    }
                    if (!oldV.contains("\"")) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$ //$NON-NLS-2$
                        elemType.setValue("\"" + oldV + "\"");
                    }
                    modified = true;
                }
            }
        }
    }
    return modified;
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) EList(org.eclipse.emf.common.util.EList) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType)

Example 38 with ElementParameterType

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

the class FileInputRegexContextVariableMigrationTaskForSave method removeQuote.

private boolean removeQuote(Item item, ProcessType processType) throws PersistenceException {
    ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    boolean modified = false;
    EList nodes = processType.getNode();
    for (Object n : nodes) {
        NodeType type = (NodeType) n;
        if (type.getComponentName().equals("tFileInputRegex")) {
            //$NON-NLS-1$
            EList elementParameterList = type.getElementParameter();
            for (Object elem : elementParameterList) {
                ElementParameterType elemType = (ElementParameterType) elem;
                if (//$NON-NLS-1$ //$NON-NLS-2$
                elemType.getName().equals("HEADER") || elemType.getName().equals("FOOTER") || elemType.getName().equals("LIMIT")) {
                    //$NON-NLS-1$
                    String oldV = elemType.getValue();
                    if (oldV != null && oldV.startsWith("\"") && oldV.endsWith("\"")) {
                        //$NON-NLS-1$ //$NON-NLS-2$
                        elemType.setValue(oldV.substring(1, oldV.length() - 1));
                        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) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType)

Example 39 with ElementParameterType

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

the class MigrationTaskForIssue10862 method execute.

@Override
public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    if (getProject().getLanguage() != ECodeLanguage.JAVA || processType == null) {
        return ExecutionResult.NOTHING_TO_DO;
    }
    //$NON-NLS-1$ //$NON-NLS-2$
    String[] componentsName = new String[] { "tPatternCheck", "tPatternExtract" };
    for (String name : componentsName) {
        IComponentFilter filter = new NameComponentFilter(name);
        try {
            ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(new IComponentConversion() {

                public void transform(NodeType node) {
                    //$NON-NLS-1$
                    ElementParameterType patternList = ComponentUtilities.getNodeProperty(node, "PATTERN_LIST");
                    if (ComponentUtilities.getNodeProperty(node, "CUSTOM_PATTERN") == null) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$ //$NON-NLS-2$
                        ComponentUtilities.addNodeProperty(node, "CUSTOM_PATTERN", "CHECK");
                    }
                    //$NON-NLS-1$
                    ElementParameterType customPattern = ComponentUtilities.getNodeProperty(node, "CUSTOM_PATTERN");
                    if (patternList != null && patternList.getValue().equals("\"CUSTOM2\"")) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$
                        customPattern.setValue("true");
                    } else {
                        //$NON-NLS-1$
                        customPattern.setValue("false");
                    }
                }
            }));
        } 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) 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 40 with ElementParameterType

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

the class MigrationTaskForIssue11632 method execute.

@Override
public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    if (getProject().getLanguage() != ECodeLanguage.JAVA || processType == null) {
        return ExecutionResult.NOTHING_TO_DO;
    }
    IComponentFilter filter = new NameComponentFilter("tLDAPOutput");
    try {
        ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(new IComponentConversion() {

            public void transform(NodeType node) {
                if (ComponentUtilities.getNodeProperty(node, "USE_ATTRIBUTE_OPTIONS") == null) {
                    //$NON-NLS-1$
                    //$NON-NLS-1$ //$NON-NLS-2$
                    ComponentUtilities.addNodeProperty(node, "USE_ATTRIBUTE_OPTIONS", "CHECK");
                }
                ElementParameterType useAttributeOptions = ComponentUtilities.getNodeProperty(node, //$NON-NLS-1$
                "USE_ATTRIBUTE_OPTIONS");
                //$NON-NLS-1$
                ElementParameterType attributeOptions = ComponentUtilities.getNodeProperty(node, "ATTRIBUTE_OPTIONS");
                if (attributeOptions == null) {
                    //$NON-NLS-1$
                    useAttributeOptions.setValue("false");
                } else {
                    if (attributeOptions.getElementValue().size() == 0) {
                        //$NON-NLS-1$
                        useAttributeOptions.setValue("false");
                    } else {
                        //$NON-NLS-1$
                        useAttributeOptions.setValue("true");
                    }
                }
            }
        }));
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
    return ExecutionResult.SUCCESS_NO_ALERT;
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) 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)

Aggregations

ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)197 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)126 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)114 PersistenceException (org.talend.commons.exception.PersistenceException)86 IComponentConversion (org.talend.core.model.components.conversions.IComponentConversion)85 IComponentFilter (org.talend.core.model.components.filters.IComponentFilter)83 NameComponentFilter (org.talend.core.model.components.filters.NameComponentFilter)83 EList (org.eclipse.emf.common.util.EList)40 ElementValueType (org.talend.designer.core.model.utils.emf.talendfile.ElementValueType)28 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)25 List (java.util.List)22 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)19 ArrayList (java.util.ArrayList)16 ProcessItem (org.talend.core.model.properties.ProcessItem)16 ParametersType (org.talend.designer.core.model.utils.emf.talendfile.ParametersType)15 ConnectionType (org.talend.designer.core.model.utils.emf.talendfile.ConnectionType)13 JobletProcessItem (org.talend.core.model.properties.JobletProcessItem)9 HashMap (java.util.HashMap)7 IOException (java.io.IOException)6 IElementParameter (org.talend.core.model.process.IElementParameter)6