Search in sources :

Example 26 with ContextType

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

the class ProcessContextComposite method checkIsSameContextParameter.

/*
     * check same ContextParameter or not.
     */
private boolean checkIsSameContextParameter() {
    List<ContextItem> allContextItem = ContextUtils.getAllContextItem();
    for (IContext context : process.getContextManager().getListContext()) {
        for (IContextParameter param : context.getContextParameterList()) {
            if (allContextItem != null) {
                ContextItem contextItem = ContextUtils.getContextItemById(allContextItem, param.getSource());
                ContextType contextType = ContextUtils.getContextTypeByName(contextItem, context.getName(), true);
                ContextParameterType contextParameterType = ContextUtils.getContextParameterTypeByName(contextType, param.getName());
                if (!ContextUtils.samePropertiesForContextParameter(param, contextParameterType)) {
                    return false;
                }
                // if don't open the job to run it(not use the "Detect and update all jobs"), will show
                // UpdateDetectionDialog to update the context ,after updated the item, the contextComboViewer still
                // set the old one , so need refresh.
                IContext runJobViewContext = getSelectedContext();
                if (runJobViewContext != null) {
                    for (IContextParameter tempContext : runJobViewContext.getContextParameterList()) {
                        if (tempContext.getName().equals(contextParameterType.getName()) && !ContextUtils.samePropertiesForContextParameter(tempContext, contextParameterType)) {
                            return false;
                        }
                    }
                }
            }
        }
    }
    return true;
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) IContext(org.talend.core.model.process.IContext) IContextParameter(org.talend.core.model.process.IContextParameter) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)

Example 27 with ContextType

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

the class AddContextCommentValueMigrationTask method execute.

@SuppressWarnings("unchecked")
@Override
public ExecutionResult execute(Item item) {
    EList<ContextType> contexts = null;
    if (item instanceof ProcessItem) {
        // process, process_mr, process_storm, route, routelet.
        ProcessItem processItem = (ProcessItem) item;
        contexts = processItem.getProcess().getContext();
    } else if (item instanceof JobletProcessItem) {
        JobletProcessItem jobletItem = (JobletProcessItem) item;
        contexts = jobletItem.getJobletProcess().getContext();
    } else if (item instanceof ContextItem) {
        ContextItem contextItem = (ContextItem) item;
        contexts = contextItem.getContext();
    }
    // 2 kinds of situation should be excluded before doing migration to the old context:
    // 1.has null, 2.all same comment values;
    // 1 is from 6.1.0 release and 5.6.2 patched TPS-1109, all null comment value will set to "".
    // for repository context in job, won't change anything because the repository context has been fixed
    // the update action will execute when opening job.
    boolean hasNull = false, isSame = true;
    if (contexts != null && contexts.size() > 1) {
        List<String> firstComments = new ArrayList<String>();
        for (int x = 0; x < contexts.size(); x++) {
            List<ContextParameterType> contextParams = contexts.get(x).getContextParameter();
            for (int y = 0; y < contextParams.size(); y++) {
                ContextParameterType param = contextParams.get(y);
                boolean isBuiltin = param.getRepositoryContextId() == null;
                String comment = param.getComment();
                if (comment == null) {
                    if (isBuiltin) {
                        //$NON-NLS-1$
                        param.setComment("");
                        hasNull = true;
                    }
                    continue;
                }
                // comments to show in old item before 5.6.1 are always in the first group.
                if (x == 0) {
                    if (!isBuiltin) {
                        //$NON-NLS-1$
                        firstComments.add("NOT_BUILTIN");
                    } else {
                        firstComments.add(comment);
                    }
                    continue;
                }
                if (isBuiltin && !comment.equals(firstComments.get(y))) {
                    isSame = false;
                }
            }
        }
        try {
            if (hasNull) {
                ProxyRepositoryFactory.getInstance().save(item, true);
                return ExecutionResult.SUCCESS_NO_ALERT;
            }
            if (!isSame) {
                for (int x = 1; x < contexts.size(); x++) {
                    List<ContextParameterType> contextParams = contexts.get(x).getContextParameter();
                    for (int y = 0; y < contextParams.size(); y++) {
                        ContextParameterType param = contextParams.get(y);
                        String comment = param.getComment();
                        if (param.getRepositoryContextId() == null && !firstComments.get(y).equals(comment)) {
                            if (!firstComments.get(y).equals("NOT_BUILTIN")) {
                                //$NON-NLS-1$
                                param.setComment(firstComments.get(y));
                            }
                        }
                    }
                }
                ProxyRepositoryFactory.getInstance().save(item, true);
                return ExecutionResult.SUCCESS_NO_ALERT;
            }
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) ContextItem(org.talend.core.model.properties.ContextItem) ArrayList(java.util.ArrayList) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) PersistenceException(org.talend.commons.exception.PersistenceException) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)

Example 28 with ContextType

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

the class RemoveDuplicatedContextGroupMigrationTask method execute.

@Override
public ExecutionResult execute(Item item) {
    List<?> contexts = null;
    if (item instanceof ProcessItem) {
        // process, process_mr, process_storm, route, routelet.
        ProcessItem processItem = (ProcessItem) item;
        contexts = processItem.getProcess().getContext();
    } else if (item instanceof JobletProcessItem) {
        JobletProcessItem jobletItem = (JobletProcessItem) item;
        contexts = jobletItem.getJobletProcess().getContext();
    }
    Set<String> nameSet = new HashSet<String>();
    Iterator<?> iterator = contexts.listIterator();
    int count = 0;
    while (iterator.hasNext()) {
        Object obj = iterator.next();
        if (obj instanceof ContextType) {
            ContextType context = (ContextType) obj;
            if (nameSet.contains(context.getName())) {
                iterator.remove();
                count++;
            } else {
                nameSet.add(context.getName());
            }
        }
    }
    if (count > 0) {
        try {
            ProxyRepositoryFactory.getInstance().save(item, true);
            return ExecutionResult.SUCCESS_NO_ALERT;
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
    } else {
        return ExecutionResult.NOTHING_TO_DO;
    }
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) PersistenceException(org.talend.commons.exception.PersistenceException) HashSet(java.util.HashSet)

Example 29 with ContextType

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

the class ExportJobUtil method getJobContexts.

/**
     * 
     * Gets the set of current job's context.
     * 
     * @return a List of context names.
     * 
     */
public static List<String> getJobContexts(ProcessItem processItem) {
    List<String> contextNameList = new ArrayList<String>();
    for (Object o : ((ProcessTypeImpl) processItem.getProcess()).getContext()) {
        if (o instanceof ContextType) {
            ContextType context = (ContextType) o;
            if (contextNameList.contains(context.getName())) {
                continue;
            }
            contextNameList.add(context.getName());
        }
    }
    return contextNameList;
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) ArrayList(java.util.ArrayList) ProcessTypeImpl(org.talend.designer.core.model.utils.emf.talendfile.impl.ProcessTypeImpl)

Example 30 with ContextType

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

the class JobContextUtils method getContextParametersMapByGroup.

private static Map<String, String> getContextParametersMapByGroup(ProcessItem processItem, String contextGroup) {
    ProcessType process = processItem.getProcess();
    if (process != null && contextGroup != null) {
        EList<?> context = process.getContext();
        if (context != null) {
            for (Object next : context) {
                ContextType ct = (ContextType) next;
                if (ct.getName().equals(contextGroup)) {
                    Map<String, String> contextParams = new HashMap<String, String>();
                    EList<ContextParameterType> params = ct.getContextParameter();
                    for (ContextParameterType param : params) {
                        contextParams.put(param.getName(), param.getRawValue());
                    }
                    return contextParams;
                }
            }
        }
    }
    return Collections.emptyMap();
}
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) 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