Search in sources :

Example 31 with ContextType

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

the class JobContextUtils method getContextsMap.

public static Map<String, Map<String, String>> getContextsMap(ProcessItem processItem) {
    Map<String, Map<String, String>> contextValues = new HashMap<String, Map<String, String>>();
    ProcessType process = processItem.getProcess();
    if (process != null) {
        EList<?> context = process.getContext();
        if (context != null) {
            for (Object next : context) {
                ContextType ct = (ContextType) next;
                Map<String, String> contextParams = getContextParametersMapByGroup(processItem, ct.getName());
                contextValues.put(ct.getName(), contextParams);
            }
        }
    }
    return contextValues;
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 32 with ContextType

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

the class AddContextCommentValueMigrationTaskTest method testAddContextCommentValue.

@Test
public void testAddContextCommentValue() {
    testItem.setDefaultContext("Default");
    String[] paramNames = new String[] { "p1", "p2", "p3" };
    String[] comments = new String[] { "c1", "c2", "c3" };
    // context item before 5.6.1
    // comments always in the first group of context no matter it's default group or not.
    testItem.getContext().add(createContextType("DEV", paramNames, comments));
    testItem.getContext().add(createContextType("PROD", paramNames, null));
    testItem.getContext().add(createContextType("Default", paramNames, null));
    AddContextCommentValueMigrationTask task = new AddContextCommentValueMigrationTask();
    task.execute(testItem);
    List<ContextType> contexts = testItem.getContext();
    for (ContextType context : contexts) {
        List<ContextParameterType> params = context.getContextParameter();
        for (ContextParameterType param : params) {
            if (param.getName().equals("p1")) {
                assertEquals("c1", param.getComment());
            } else if (param.getName().equals("p2")) {
                assertEquals("c2", param.getComment());
            } else if (param.getName().equals("p3")) {
                assertEquals("c3", param.getComment());
            }
        }
    }
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType) Test(org.junit.Test)

Example 33 with ContextType

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

the class AddContextCommentValueMigrationTaskTest method createContextType.

private ContextType createContextType(String contextName, String[] paramNames, String[] comments) {
    ContextType context = TalendFileFactory.eINSTANCE.createContextType();
    context.setName(contextName);
    for (int i = 0; i < paramNames.length; i++) {
        ContextParameterType param = TalendFileFactory.eINSTANCE.createContextParameterType();
        param.setName(paramNames[i]);
        param.setType("id_String");
        if (comments != null) {
            param.setComment(comments[i]);
        } else {
            param.setComment("");
        }
        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 34 with ContextType

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

the class FixUnevenItemContextParametersMigrationTaskTest method testChangeParamOrder.

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

Example 35 with ContextType

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

the class FixUnevenItemContextParametersMigrationTaskTest method testChangeType.

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

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