Search in sources :

Example 1 with ContextParameterTypeImpl

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

the class ComponentChooseDialog method createContext.

private void createContext(List<Object> sourceList) {
    if (sourceList.size() == 0) {
        return;
    }
    boolean created = false;
    for (Object source : sourceList) {
        if (source instanceof RepositoryNode) {
            RepositoryNode sourceNode = (RepositoryNode) source;
            Item item = sourceNode.getObject().getProperty().getItem();
            if (item instanceof ContextItem) {
                ContextItem contextItem = (ContextItem) item;
                EList context = contextItem.getContext();
                Set<String> contextSet = new HashSet<String>();
                Iterator iterator = context.iterator();
                while (iterator.hasNext()) {
                    Object obj = iterator.next();
                    if (obj instanceof ContextTypeImpl) {
                        EList contextParameters = ((ContextTypeImpl) obj).getContextParameter();
                        Iterator contextParas = contextParameters.iterator();
                        while (contextParas.hasNext()) {
                            ContextParameterTypeImpl contextParameterType = (ContextParameterTypeImpl) contextParas.next();
                            String name = contextParameterType.getName();
                            contextSet.add(name);
                        }
                    }
                }
                IEditorInput editorInput = editor.getEditorInput();
                if (editorInput instanceof JobEditorInput) {
                    JobEditorInput jobInput = (JobEditorInput) editorInput;
                    IProcess2 process = jobInput.getLoadedProcess();
                    IContextManager contextManager = process.getContextManager();
                    List<IContext> listContext = contextManager.getListContext();
                    // context group will reflect absolutely if no context variable in contextViewer
                    // if (!ConnectionContextHelper.containsVariable(contextManager)) {
                    // for bug 15608
                    // ConnectionContextHelper.addContextVarForJob(process, contextItem, contextManager);
                    // ConnectionContextHelper.checkAndAddContextsVarDND(contextItem, contextManager);
                    Set<String> addedVars = ConnectionContextHelper.checkAndAddContextVariables(contextItem, contextSet, process.getContextManager(), false);
                    if (addedVars != null && !addedVars.isEmpty() && !ConnectionContextHelper.isAddContextVar(contextItem, contextManager, contextSet)) {
                        // show
                        Map<String, Set<String>> addedVarsMap = new HashMap<String, Set<String>>();
                        addedVarsMap.put(item.getProperty().getLabel(), contextSet);
                        if (ConnectionContextHelper.showContextdialog(process, contextItem, process.getContextManager(), addedVarsMap, contextSet)) {
                            created = true;
                        }
                    }
                // } else {
                // Set<String> addedContext = ConnectionContextHelper.checkAndAddContextVariables(contextItem,
                // contextSet, contextManager, false);
                // if (addedContext != null && addedContext.size() > 0) {
                // ConnectionContextHelper.addContextVarForJob(process, contextItem, contextSet);
                // created = true;
                // }
                // }
                }
            }
        }
    }
    if (created) {
        RepositoryPlugin.getDefault().getDesignerCoreService().switchToCurContextsView();
    }
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) IContext(org.talend.core.model.process.IContext) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ContextParameterTypeImpl(org.talend.designer.core.model.utils.emf.talendfile.impl.ContextParameterTypeImpl) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) JobEditorInput(org.talend.core.ui.editor.JobEditorInput) ValidationRulesConnectionItem(org.talend.core.model.properties.ValidationRulesConnectionItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) MDMConnectionItem(org.talend.core.model.properties.MDMConnectionItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ContextItem(org.talend.core.model.properties.ContextItem) Item(org.talend.core.model.properties.Item) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) EbcdicConnectionItem(org.talend.core.model.properties.EbcdicConnectionItem) RulesItem(org.talend.core.model.properties.RulesItem) HL7ConnectionItem(org.talend.core.model.properties.HL7ConnectionItem) FileItem(org.talend.core.model.properties.FileItem) EList(org.eclipse.emf.common.util.EList) Iterator(java.util.Iterator) IProcess2(org.talend.core.model.process.IProcess2) SAPFunctionRepositoryObject(org.talend.core.repository.model.repositoryObject.SAPFunctionRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) QueryRepositoryObject(org.talend.core.repository.model.repositoryObject.QueryRepositoryObject) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) SalesforceModuleRepositoryObject(org.talend.core.repository.model.repositoryObject.SalesforceModuleRepositoryObject) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) SAPIDocRepositoryObject(org.talend.core.repository.model.repositoryObject.SAPIDocRepositoryObject) ContextTypeImpl(org.talend.designer.core.model.utils.emf.talendfile.impl.ContextTypeImpl) IContextManager(org.talend.core.model.process.IContextManager) IEditorInput(org.eclipse.ui.IEditorInput) HashSet(java.util.HashSet)

Example 2 with ContextParameterTypeImpl

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

the class JSONConnectionContextHelper method setContextParameter.

public static void setContextParameter(ContextItem item, Set<String> addedVars, List<ContextParameterTypeImpl> list, JobContext jobContext) {
    for (ContextParameterTypeImpl contextImpl : list) {
        for (String var : addedVars) {
            if (var.equals(contextImpl.getName())) {
                JobContextParameter contextParam = new JobContextParameter();
                ContextUtils.updateParameter(contextImpl, contextParam);
                contextParam.setSource(item.getProperty().getId());
                contextParam.setContext(jobContext);
                jobContext.getContextParameterList().add(contextParam);
            }
        }
    }
}
Also used : JobContextParameter(org.talend.core.model.context.JobContextParameter) ContextParameterTypeImpl(org.talend.designer.core.model.utils.emf.talendfile.impl.ContextParameterTypeImpl)

Example 3 with ContextParameterTypeImpl

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

the class JSONConnectionContextHelper method checkAndAddContextVariables.

public static void checkAndAddContextVariables(ContextItem item, IContextManager contextManager, Set<String> addedVars, Set<String> contextGoupNameSet) {
    EList context = item.getContext();
    Map<String, List<ContextParameterTypeImpl>> map = new HashMap<String, List<ContextParameterTypeImpl>>();
    Iterator iterator = context.iterator();
    while (iterator.hasNext()) {
        Object obj = iterator.next();
        if (obj instanceof ContextTypeImpl) {
            ContextTypeImpl contextTypeImpl = (ContextTypeImpl) obj;
            String name = contextTypeImpl.getName();
            EList contextParameters = contextTypeImpl.getContextParameter();
            Iterator contextParas = contextParameters.iterator();
            List<ContextParameterTypeImpl> list = new ArrayList<ContextParameterTypeImpl>();
            while (contextParas.hasNext()) {
                ContextParameterTypeImpl contextParameterType = (ContextParameterTypeImpl) contextParas.next();
                list.add(contextParameterType);
            }
            map.put(name, list);
        }
    }
    if (map.isEmpty()) {
        return;
    }
    String defaultContextName = item.getDefaultContext();
    Set<String> existGroupNameSet = new HashSet<String>();
    for (IContext con : contextManager.getListContext()) {
        existGroupNameSet.add(con.getName());
    }
    if (contextGoupNameSet.isEmpty()) {
        contextGoupNameSet.add(defaultContextName);
    }
    Set<String> alreadyUpdateNameSet = new HashSet<String>();
    for (String key : map.keySet()) {
        for (String groupName : contextGoupNameSet) {
            boolean isExtraGroup = false;
            for (String existGroup : existGroupNameSet) {
                if (key.equals(existGroup)) {
                    isExtraGroup = true;
                    alreadyUpdateNameSet.add(existGroup);
                    break;
                }
            }
            if (key.equals(groupName) || isExtraGroup) {
                List<ContextParameterTypeImpl> list = map.get(key);
                JobContext jobContext = new JobContext(key);
                boolean isExistContext = false;
                if (isExtraGroup) {
                    for (IContext con : contextManager.getListContext()) {
                        if (key.equals(con.getName())) {
                            if (con instanceof JobContext) {
                                jobContext = (JobContext) con;
                                isExistContext = true;
                                break;
                            }
                        }
                    }
                }
                setContextParameter(item, addedVars, list, jobContext);
                if (!isExistContext) {
                    contextManager.getListContext().add(jobContext);
                }
                break;
            }
        }
    }
    // if job context group is not in current add's context,then update context group value to default group value
    existGroupNameSet.removeAll(alreadyUpdateNameSet);
    List<ContextParameterTypeImpl> list = map.get(defaultContextName);
    if (list == null) {
        return;
    }
}
Also used : IContext(org.talend.core.model.process.IContext) HashMap(java.util.HashMap) ContextParameterTypeImpl(org.talend.designer.core.model.utils.emf.talendfile.impl.ContextParameterTypeImpl) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ContextTypeImpl(org.talend.designer.core.model.utils.emf.talendfile.impl.ContextTypeImpl) JobContext(org.talend.core.model.context.JobContext) HashSet(java.util.HashSet)

Example 4 with ContextParameterTypeImpl

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

the class JSONConnectionContextHelper method checkAndAddContextsVarDND.

/**
     * 
     * wzhang Comment method "checkAndAddContextsVarDND".
     * 
     * @param item
     * @param contextManager
     */
public static void checkAndAddContextsVarDND(ContextItem item, IContextManager contextManager) {
    EList context = item.getContext();
    Map<String, List<ContextParameterTypeImpl>> map = new HashMap<String, List<ContextParameterTypeImpl>>();
    Iterator iterator = context.iterator();
    while (iterator.hasNext()) {
        Object obj = iterator.next();
        if (obj instanceof ContextTypeImpl) {
            ContextTypeImpl contextTypeImpl = (ContextTypeImpl) obj;
            String name = contextTypeImpl.getName();
            EList contextParameters = contextTypeImpl.getContextParameter();
            Iterator contextParas = contextParameters.iterator();
            List<ContextParameterTypeImpl> list = new ArrayList<ContextParameterTypeImpl>();
            while (contextParas.hasNext()) {
                ContextParameterTypeImpl contextParameterType = (ContextParameterTypeImpl) contextParas.next();
                list.add(contextParameterType);
            }
            map.put(name, list);
        }
    }
    if (map.isEmpty()) {
        return;
    }
    contextManager.getListContext().clear();
    String defaultContextName = item.getDefaultContext();
    for (String key : map.keySet()) {
        List<ContextParameterTypeImpl> list = map.get(key);
        JobContext jobContext = new JobContext(key);
        for (ContextParameterTypeImpl contextImpl : list) {
            JobContextParameter contextParam = new JobContextParameter();
            ContextUtils.updateParameter(contextImpl, contextParam);
            contextParam.setSource(item.getProperty().getId());
            contextParam.setContext(jobContext);
            jobContext.getContextParameterList().add(contextParam);
        }
        contextManager.getListContext().add(jobContext);
        if (key.equals(defaultContextName)) {
            contextManager.setDefaultContext(jobContext);
        }
    }
}
Also used : HashMap(java.util.HashMap) ContextParameterTypeImpl(org.talend.designer.core.model.utils.emf.talendfile.impl.ContextParameterTypeImpl) ArrayList(java.util.ArrayList) JobContextParameter(org.talend.core.model.context.JobContextParameter) EList(org.eclipse.emf.common.util.EList) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ContextTypeImpl(org.talend.designer.core.model.utils.emf.talendfile.impl.ContextTypeImpl) JobContext(org.talend.core.model.context.JobContext)

Example 5 with ContextParameterTypeImpl

use of org.talend.designer.core.model.utils.emf.talendfile.impl.ContextParameterTypeImpl in project tesb-studio-se by Talend.

the class CamelEditorDropTargetListener method createContext.

private void createContext() {
    if (selectSourceList.size() == 0) {
        return;
    }
    boolean created = false;
    for (Object source : selectSourceList) {
        if (source instanceof RepositoryNode) {
            RepositoryNode sourceNode = (RepositoryNode) source;
            Item item = sourceNode.getObject().getProperty().getItem();
            if (item instanceof ContextItem) {
                ContextItem contextItem = (ContextItem) item;
                EList context = contextItem.getContext();
                Set<String> contextSet = new HashSet<String>();
                Iterator iterator = context.iterator();
                while (iterator.hasNext()) {
                    Object obj = iterator.next();
                    if (obj instanceof ContextTypeImpl) {
                        EList contextParameters = ((ContextTypeImpl) obj).getContextParameter();
                        Iterator contextParas = contextParameters.iterator();
                        while (contextParas.hasNext()) {
                            ContextParameterTypeImpl contextParameterType = (ContextParameterTypeImpl) contextParas.next();
                            String name = contextParameterType.getName();
                            contextSet.add(name);
                        }
                    }
                }
                IEditorInput editorInput = editor.getEditorInput();
                if (editorInput instanceof JobEditorInput) {
                    JobEditorInput jobInput = (JobEditorInput) editorInput;
                    IProcess2 process = jobInput.getLoadedProcess();
                    IContextManager contextManager = process.getContextManager();
                    List<IContext> listContext = contextManager.getListContext();
                    Set<String> addedVars = ConnectionContextHelper.checkAndAddContextVariables(contextItem, contextSet, process.getContextManager(), false);
                    if (addedVars != null && !addedVars.isEmpty() && !ConnectionContextHelper.isAddContextVar(contextItem, contextManager, contextSet)) {
                        // show
                        Map<String, Set<String>> addedVarsMap = new HashMap<String, Set<String>>();
                        addedVarsMap.put(item.getProperty().getLabel(), contextSet);
                        if (ConnectionContextHelper.showContextdialog(process, contextItem, process.getContextManager(), addedVarsMap, contextSet)) {
                            created = true;
                        }
                    } else {
                        //$NON-NLS-1$
                        MessageDialog.openInformation(//$NON-NLS-1$
                        editor.getEditorSite().getShell(), //$NON-NLS-1$
                        "Adding Context", //$NON-NLS-1$
                        "Context \"" + contextItem.getProperty().getDisplayName() + "\" already exist.");
                    }
                }
            }
        }
    }
    if (created) {
        RepositoryPlugin.getDefault().getDesignerCoreService().switchToCurContextsView();
    }
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) IContext(org.talend.core.model.process.IContext) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ContextParameterTypeImpl(org.talend.designer.core.model.utils.emf.talendfile.impl.ContextParameterTypeImpl) RepositoryNode(org.talend.repository.model.RepositoryNode) JobEditorInput(org.talend.core.ui.editor.JobEditorInput) ContextItem(org.talend.core.model.properties.ContextItem) Item(org.talend.core.model.properties.Item) ProcessItem(org.talend.core.model.properties.ProcessItem) EList(org.eclipse.emf.common.util.EList) Iterator(java.util.Iterator) IProcess2(org.talend.core.model.process.IProcess2) ContextTypeImpl(org.talend.designer.core.model.utils.emf.talendfile.impl.ContextTypeImpl) IContextManager(org.talend.core.model.process.IContextManager) IEditorInput(org.eclipse.ui.IEditorInput) HashSet(java.util.HashSet)

Aggregations

ContextParameterTypeImpl (org.talend.designer.core.model.utils.emf.talendfile.impl.ContextParameterTypeImpl)5 HashMap (java.util.HashMap)4 Iterator (java.util.Iterator)4 EList (org.eclipse.emf.common.util.EList)4 ContextTypeImpl (org.talend.designer.core.model.utils.emf.talendfile.impl.ContextTypeImpl)4 HashSet (java.util.HashSet)3 IContext (org.talend.core.model.process.IContext)3 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Set (java.util.Set)2 IEditorInput (org.eclipse.ui.IEditorInput)2 JobContext (org.talend.core.model.context.JobContext)2 JobContextParameter (org.talend.core.model.context.JobContextParameter)2 IContextManager (org.talend.core.model.process.IContextManager)2 IProcess2 (org.talend.core.model.process.IProcess2)2 ContextItem (org.talend.core.model.properties.ContextItem)2 Item (org.talend.core.model.properties.Item)2 ProcessItem (org.talend.core.model.properties.ProcessItem)2 JobEditorInput (org.talend.core.ui.editor.JobEditorInput)2