Search in sources :

Example 41 with ContextType

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

the class ReplaceJavaKeywordsNameForContextMigrationTask method getReplacedNamesAndReplaceContextVars.

/**
     * 
     * ggu Comment method "getReplacedNamesAndReplaceContextVars".
     * 
     * get the replaced names, and replace the context variables at the same time.
     */
@SuppressWarnings("unchecked")
private Map<String, Map<String, String>> getReplacedNamesAndReplaceContextVars() {
    // id to map(oldName to newName)
    Map<String, Map<String, String>> contextIdNamesMap = new HashMap<String, Map<String, String>>();
    List<ContextItem> allContextItem = ContextUtils.getAllContextItem();
    if (allContextItem != null) {
        for (ContextItem contextItem : allContextItem) {
            boolean changed = false;
            boolean first = true;
            Set<String> varNames = null;
            for (ContextType contextType : (List<ContextType>) contextItem.getContext()) {
                if (first) {
                    varNames = ContextUtils.getContextVarNames(contextType);
                }
                // oldName to newName
                Map<String, String> nameMap = new HashMap<String, String>();
                final String contextId = contextItem.getProperty().getId();
                for (ContextParameterType paramType : (List<ContextParameterType>) contextType.getContextParameter()) {
                    String oldName = paramType.getName();
                    if (first) {
                        if (ContextUtils.isJavaKeyWords(oldName)) {
                            // is java keywords
                            String newName = getNewName(varNames, oldName);
                            nameMap.put(newName, oldName);
                            paramType.setName(newName);
                            changed = true;
                        }
                    } else {
                        String newName = getContextNewNameFromMap(contextIdNamesMap, contextId, oldName);
                        if (newName != null) {
                            // is java keywords
                            paramType.setName(newName);
                            changed = true;
                        }
                    }
                }
                if (first && !nameMap.isEmpty()) {
                    contextIdNamesMap.put(contextId, nameMap);
                }
                first = false;
            }
            if (changed) {
                // save
                try {
                    factory.save(contextItem, true);
                } catch (PersistenceException e) {
                // 
                }
            }
        }
    }
    return contextIdNamesMap;
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) HashMap(java.util.HashMap) PersistenceException(org.talend.commons.exception.PersistenceException) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)

Example 42 with ContextType

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

the class ReplaceJavaKeywordsNameForContextMigrationTask method modifyJobContext.

/**
     * 
     * ggu Comment method "modifyJobContext".
     * 
     * this function will get the replaced variables map.
     */
@SuppressWarnings("unchecked")
private boolean modifyJobContext(Map<String, String> jobContextReplacedNamesMap, List<ContextType> contextTypeList) {
    if (contextTypeList == null || contextTypeList.isEmpty()) {
        return false;
    }
    boolean changed = false;
    boolean first = true;
    Set<String> varNames = null;
    for (ContextType contextType : (List<ContextType>) contextTypeList) {
        if (first) {
            varNames = ContextUtils.getContextVarNames(contextType);
        }
        for (ContextParameterType paramType : (List<ContextParameterType>) contextType.getContextParameter()) {
            final String oldName = paramType.getName();
            final String sourceId = paramType.getRepositoryContextId();
            if (first) {
                if (ContextUtils.isJavaKeyWords(oldName)) {
                    // is java keywords
                    String newName = getNewName(varNames, oldName);
                    String tmpName = getContextNewNameFromMap(contextReplacedNamesMap, sourceId, oldName);
                    if (tmpName != null) {
                        // from repository context
                        newName = tmpName;
                    }
                    jobContextReplacedNamesMap.put(newName, oldName);
                    paramType.setName(newName);
                    changed = true;
                }
            } else {
                String newName = getJobContextNewNameFromMap(jobContextReplacedNamesMap, oldName);
                if (newName != null) {
                    // is key words
                    paramType.setName(newName);
                    changed = true;
                }
            }
        }
    }
    return changed;
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) ArrayList(java.util.ArrayList) List(java.util.List) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)

Example 43 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType 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 44 with ContextType

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

the class FixUnevenItemContextParametersMigrationTaskTest method testChangeParamList.

@Test
public void testChangeParamList() {
    testItem.getProcess().setDefaultContext("Default");
    String[] paramNames = new String[] { "new4", "new2", "new3" };
    // default
    ContextType defaultGroup = createContextType("Default", paramNames);
    testItem.getProcess().getContext().add(defaultGroup);
    // group1
    paramNames = new String[] { "new5", "new2", "new1" };
    ContextType group1 = createContextType("group1", paramNames);
    testItem.getProcess().getContext().add(group1);
    FixUnevenItemContextParametersMigrationTask migration = new FixUnevenItemContextParametersMigrationTask();
    migration.execute(testItem);
    Assert.assertEquals(((ContextParameterType) defaultGroup.getContextParameter().get(0)).getName(), "new4");
    Assert.assertEquals(((ContextParameterType) defaultGroup.getContextParameter().get(1)).getName(), "new2");
    Assert.assertEquals(((ContextParameterType) defaultGroup.getContextParameter().get(2)).getName(), "new3");
    Assert.assertEquals(((ContextParameterType) defaultGroup.getContextParameter().get(3)).getName(), "new5");
    Assert.assertEquals(((ContextParameterType) defaultGroup.getContextParameter().get(4)).getName(), "new1");
    Assert.assertEquals(((ContextParameterType) group1.getContextParameter().get(0)).getName(), "new4");
    Assert.assertEquals(((ContextParameterType) group1.getContextParameter().get(1)).getName(), "new2");
    Assert.assertEquals(((ContextParameterType) group1.getContextParameter().get(2)).getName(), "new3");
    Assert.assertEquals(((ContextParameterType) group1.getContextParameter().get(3)).getName(), "new5");
    Assert.assertEquals(((ContextParameterType) group1.getContextParameter().get(4)).getName(), "new1");
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) Test(org.junit.Test)

Example 45 with ContextType

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

Aggregations

ContextType (org.talend.designer.core.model.utils.emf.talendfile.ContextType)58 ContextParameterType (org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)19 PersistenceException (org.talend.commons.exception.PersistenceException)16 ArrayList (java.util.ArrayList)15 File (java.io.File)13 ContextItem (org.talend.core.model.properties.ContextItem)9 ProcessItem (org.talend.core.model.properties.ProcessItem)9 IOException (java.io.IOException)7 FileNotFoundException (java.io.FileNotFoundException)6 FileOutputStream (java.io.FileOutputStream)6 List (java.util.List)6 EList (org.eclipse.emf.common.util.EList)6 HashMap (java.util.HashMap)5 Test (org.junit.Test)5 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)5 IProject (org.eclipse.core.resources.IProject)4 JobletProcessItem (org.talend.core.model.properties.JobletProcessItem)4 BufferedReader (java.io.BufferedReader)3 EOFException (java.io.EOFException)3 FileInputStream (java.io.FileInputStream)3