Search in sources :

Example 16 with ContextParameterType

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

the class GenericContextUtilTest method createContextParameterType.

private ContextParameterType createContextParameterType(String paramName, String paramValue) {
    ContextParameterType contextParameter = TalendFileFactoryImpl.eINSTANCE.createContextParameterType();
    contextParameter.setName(paramName);
    contextParameter.setRawValue(paramValue);
    return contextParameter;
}
Also used : ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)

Example 17 with ContextParameterType

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

the class FixUnevenItemContextParametersMigrationTaskTest method createContextType.

private ContextType createContextType(String contextName, String[] paramNames) {
    ContextType context = TalendFileFactory.eINSTANCE.createContextType();
    context.setName(contextName);
    for (String paramName : paramNames) {
        ContextParameterType param = TalendFileFactory.eINSTANCE.createContextParameterType();
        param.setName(paramName);
        param.setType("id_String");
        context.getContextParameter().add(param);
    }
    return context;
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)

Example 18 with ContextParameterType

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

the class UnifyPasswordEncryption4ParametersInJobMigrationTask method checkContext.

/**
     * 
     * same as UnifyPasswordEncryption4ContextMigrationTask to change the encryption.
     */
@SuppressWarnings("deprecation")
protected boolean checkContext(Item item, ProcessType processType) throws Exception {
    boolean modified = false;
    // context
    EList contextList = processType.getContext();
    for (Object o : contextList) {
        if (o instanceof ContextType) {
            List<ContextParameterType> paramTypes = ((ContextType) o).getContextParameter();
            if (paramTypes != null) {
                for (ContextParameterType param : paramTypes) {
                    String value = param.getValue();
                    if (value != null && (PasswordEncryptUtil.isPasswordType(param.getType()) || PasswordEncryptUtil.isPasswordField(param.getName()))) {
                        try {
                            String rawPassword = PasswordEncryptUtil.decryptPassword(value);
                            param.setRawValue(rawPassword);
                        } catch (Exception e) {
                            param.setRawValue(value);
                        }
                        modified = true;
                    }
                }
            }
        }
    }
    return modified;
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) EList(org.eclipse.emf.common.util.EList) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)

Example 19 with ContextParameterType

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

the class UpdateJobletContextInJobMigrationTask method execute.

@Override
public ExecutionResult execute(Item item) {
    if (item instanceof ProcessItem) {
        ProcessItem processItem = (ProcessItem) item;
        List<ContextType> contexts = processItem.getProcess().getContext();
        if (contexts.size() > 1) {
            boolean isModified = false;
            for (ContextType context1 : contexts) {
                List<ContextParameterType> params1 = context1.getContextParameter();
                for (ContextParameterType param1 : params1) {
                    String id = param1.getRepositoryContextId();
                    if (id != null) {
                        for (ContextType context2 : contexts) {
                            if (context2 != context1) {
                                List<ContextParameterType> params2 = context2.getContextParameter();
                                for (ContextParameterType param2 : params2) {
                                    if (param2.getName().equals(param1.getName()) && param2.getRepositoryContextId() == null) {
                                        param2.setRepositoryContextId(id);
                                        isModified = true;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (isModified) {
                try {
                    ProxyRepositoryFactory.getInstance().save(item, true);
                } catch (PersistenceException e) {
                    ExceptionHandler.process(e);
                    return ExecutionResult.FAILURE;
                }
                return ExecutionResult.SUCCESS_NO_ALERT;
            }
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) ProcessItem(org.talend.core.model.properties.ProcessItem) PersistenceException(org.talend.commons.exception.PersistenceException) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)

Example 20 with ContextParameterType

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

the class UnifyPasswordEncryption4ContextMigrationTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org .talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    if (item instanceof ContextItem) {
        List<ContextType> contextTypeList = ((ContextItem) item).getContext();
        boolean modify = false;
        if (contextTypeList != null) {
            for (ContextType type : contextTypeList) {
                List<ContextParameterType> paramTypes = type.getContextParameter();
                if (paramTypes != null) {
                    for (ContextParameterType param : paramTypes) {
                        try {
                            String value = param.getValue();
                            if (value != null && PasswordEncryptUtil.isPasswordType(param.getType())) {
                                String rawPassword = PasswordEncryptUtil.decryptPassword(value);
                                param.setRawValue(rawPassword);
                                modify = true;
                            }
                        } catch (Exception e) {
                            ExceptionHandler.process(e);
                            return ExecutionResult.FAILURE;
                        }
                    }
                }
            }
        }
        if (modify) {
            try {
                factory.save(item, true);
                return ExecutionResult.SUCCESS_NO_ALERT;
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
                return ExecutionResult.FAILURE;
            }
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) PersistenceException(org.talend.commons.exception.PersistenceException) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType) PersistenceException(org.talend.commons.exception.PersistenceException)

Aggregations

ContextParameterType (org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)25 ContextType (org.talend.designer.core.model.utils.emf.talendfile.ContextType)19 ContextItem (org.talend.core.model.properties.ContextItem)8 PersistenceException (org.talend.commons.exception.PersistenceException)7 ArrayList (java.util.ArrayList)6 ProcessItem (org.talend.core.model.properties.ProcessItem)5 HashMap (java.util.HashMap)4 EList (org.eclipse.emf.common.util.EList)4 List (java.util.List)3 JobletProcessItem (org.talend.core.model.properties.JobletProcessItem)3 File (java.io.File)2 Test (org.junit.Test)2 IContext (org.talend.core.model.process.IContext)2 IContextParameter (org.talend.core.model.process.IContextParameter)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Map (java.util.Map)1 Properties (java.util.Properties)1 Element (org.dom4j.Element)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1