Search in sources :

Example 6 with IContextManager

use of org.talend.core.model.process.IContextManager in project tdi-studio-se by Talend.

the class UpdateContextParameterCommand method doExecute.

private void doExecute() {
    if (result == null) {
        return;
    }
    Object job = result.getJob();
    if (job == null) {
        return;
    }
    if (job instanceof IProcess2) {
        IProcess2 process = (IProcess2) job;
        ContextParameterMap deleteParameters = new ContextParameterMap();
        Object updateObject = result.getUpdateObject();
        List<IContext> listContext = process.getContextManager().getListContext();
        if (updateObject instanceof Set) {
            Set<String> names = (Set<String>) updateObject;
            if (result.getResultType() == EUpdateResult.ADD && result.isChecked()) {
                // check parameters that have been added to repository context group
                checkNewRepositoryParameters(process, names);
                return;
            }
            for (IContext context : listContext) {
                for (IContextParameter param : context.getContextParameterList()) {
                    ContextItem item = null;
                    if (names != null && names.contains(param.getName())) {
                        switch(result.getResultType()) {
                            case DELETE:
                                item = (ContextItem) result.getParameter();
                                if (item != null && item.getProperty().getId().equals(param.getSource()) && result.isChecked()) {
                                    // delete it later
                                    deleteParameters.addParameter(context, param);
                                } else {
                                    param.setSource(IContextParameter.BUILT_IN);
                                }
                                break;
                            case UPDATE:
                                item = (ContextItem) result.getParameter();
                                if (item != null && item.getProperty().getId().equals(param.getSource()) && result.isChecked()) {
                                    ContextUtils.updateParameterFromRepository(item, param, context.getName());
                                } else {
                                    param.setSource(IContextParameter.BUILT_IN);
                                }
                                break;
                            case RENAME:
                                List<Object> parameter = (List<Object>) result.getParameter();
                                if (parameter.size() >= 3) {
                                    item = (ContextItem) parameter.get(0);
                                    String sourceId = item.getProperty().getId();
                                    String oldName = (String) parameter.get(1);
                                    String newName = (String) parameter.get(2);
                                    if (oldName.equals(param.getName()) && sourceId.equals(param.getSource())) {
                                        if (newName != null) {
                                            param.setName(newName);
                                            ContextUtils.updateParameterFromRepository(item, param, context.getName());
                                        }
                                    }
                                }
                                break;
                            // built-in
                            case BUIL_IN:
                            default:
                                param.setSource(IContextParameter.BUILT_IN);
                                break;
                        }
                    }
                }
            }
        }
        if (updateObject instanceof JobContext) {
            if (result.getResultType() == EUpdateResult.ADD && result.getUpdateType() == EUpdateItemType.CONTEXT_GROUP && result.isChecked()) {
                IContext context = (IContext) updateObject;
                String name = context.getName();
                if (!listContext.contains(context) && result.getParameter() instanceof ContextItem) {
                    ContextItem item = (ContextItem) result.getParameter();
                    JobContext newContext = new JobContext(name);
                    List<IContextParameter> newParamList = new ArrayList<IContextParameter>();
                    newContext.setContextParameterList(newParamList);
                    JobContextParameter param = null;
                    // add other context params to the new group
                    for (IContextParameter contextParam : process.getContextManager().getDefaultContext().getContextParameterList()) {
                        boolean exist = false;
                        for (IContextParameter existParam : context.getContextParameterList()) {
                            if (contextParam.getName().equals(existParam.getName())) {
                                exist = true;
                            }
                        }
                        if (exist) {
                            continue;
                        }
                        param = (JobContextParameter) contextParam.clone();
                        param.setContext(newContext);
                        newParamList.add(param);
                    }
                    // current context params for the new group
                    for (int i = 0; i < context.getContextParameterList().size(); i++) {
                        IContextParameter oldParam = context.getContextParameterList().get(i);
                        param = (JobContextParameter) oldParam.clone();
                        param.setSource(item.getProperty().getId());
                        param.setContext(newContext);
                        newParamList.add(param);
                    }
                    listContext.add(newContext);
                }
            } else if (result.getResultType() == EUpdateResult.DELETE && result.getUpdateType() == EUpdateItemType.CONTEXT_GROUP && result.isChecked()) {
                IContext context = (IContext) updateObject;
                if (result.getParameter() instanceof ContextItem) {
                    ContextItem item = (ContextItem) result.getParameter();
                    List<IContext> listC = new ArrayList<IContext>(listContext);
                    for (IContext con : listC) {
                        if (con.getName().equals(context.getName())) {
                            for (IContextParameter oldParam : con.getContextParameterList()) {
                                if (item.getProperty().getId().equals(oldParam.getSource())) {
                                    listContext.remove(con);
                                }
                            }
                        }
                    }
                }
                return;
            } else if (result.getResultType() == EUpdateResult.RENAME && result.getUpdateType() == EUpdateItemType.CONTEXT_GROUP && result.isChecked()) {
                IContext context = (IContext) updateObject;
                IContextManager contextManager = process.getContextManager();
                Map<IContext, String> renameGroupContext = ((JobContextManager) contextManager).getRenameGroupContext();
                String oldName = renameGroupContext.get(context);
                if (result.getParameter() instanceof ContextItem) {
                    ContextItem item = (ContextItem) result.getParameter();
                    for (IContext con : listContext) {
                        if (con.getName().equals(oldName)) {
                            for (IContextParameter oldParam : con.getContextParameterList()) {
                                if (item.getProperty().getId().equals(oldParam.getSource())) {
                                    con.setName(context.getName());
                                }
                            }
                        }
                    }
                }
            }
            return;
        }
        // delete parameters
        deleteParameters.removeFromContext();
        // update parameters
        if (result.getResultType() == EUpdateResult.RENAME) {
            List<Object> parameter = (List<Object>) result.getParameter();
            if (parameter.size() >= 3) {
                String oldName = (String) parameter.get(1);
                String newName = (String) parameter.get(2);
                UpdateContextVariablesHelper.updateProcessForRenamed(process, oldName, newName);
                // tRunJob parameters rename
                IEditorReference[] reference = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
                List<IProcess2> processes = RepositoryPlugin.getDefault().getDesignerCoreService().getOpenedProcess(reference);
                Map<String, String> renamedMap = new HashMap<String, String>();
                renamedMap.put(newName, oldName);
                UpdateRunJobComponentContextHelper.updateOpenedJobRunJobComponentReference(processes, renamedMap, process.getId(), null);
                try {
                    // perhaps, need optimize.
                    UpdateRunJobComponentContextHelper.updateItemRunJobComponentReference(DesignerPlugin.getDefault().getProxyRepositoryFactory(), renamedMap, process.getId(), null);
                } catch (PersistenceException e) {
                    ExceptionHandler.process(e);
                }
            }
        }
    }
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) IContext(org.talend.core.model.process.IContext) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IContextParameter(org.talend.core.model.process.IContextParameter) IEditorReference(org.eclipse.ui.IEditorReference) ArrayList(java.util.ArrayList) List(java.util.List) JobContext(org.talend.core.model.context.JobContext) IContextManager(org.talend.core.model.process.IContextManager) JobContextParameter(org.talend.core.model.context.JobContextParameter) IProcess2(org.talend.core.model.process.IProcess2) PersistenceException(org.talend.commons.exception.PersistenceException) JobContextManager(org.talend.core.model.context.JobContextManager)

Example 7 with IContextManager

use of org.talend.core.model.process.IContextManager 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 8 with IContextManager

use of org.talend.core.model.process.IContextManager in project tdi-studio-se by Talend.

the class RepositoryWebService method parseContextParameter.

private String parseContextParameter(String contextValue) {
    String url = "";
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    IContextManager contextManager = connector.getProcess().getContextManager();
    String currentDefaultName = contextManager.getDefaultContext().getName();
    List contextList = contextManager.getListContext();
    if (!contextList.isEmpty() && contextList.size() > 1) {
        currentDefaultName = ConnectionContextHelper.getContextTypeForJob(shell, contextManager, false);
    }
    // ContextSetsSelectionDialog cssd=new ContextSetsSelectionDialog(shell,,false);
    // ContextType contextType=ConnectionContextHelper.getContextTypeForContextMode(connector);
    IContext context = contextManager.getContext(currentDefaultName);
    url = ContextParameterUtils.parseScriptContextCode(contextValue, context);
    return url;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IContext(org.talend.core.model.process.IContext) List(java.util.List) ArrayList(java.util.ArrayList) IContextManager(org.talend.core.model.process.IContextManager)

Example 9 with IContextManager

use of org.talend.core.model.process.IContextManager 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

IContextManager (org.talend.core.model.process.IContextManager)9 IContext (org.talend.core.model.process.IContext)7 HashMap (java.util.HashMap)5 List (java.util.List)5 ArrayList (java.util.ArrayList)4 IProcess2 (org.talend.core.model.process.IProcess2)4 HashSet (java.util.HashSet)3 Set (java.util.Set)3 ContextItem (org.talend.core.model.properties.ContextItem)3 ProcessItem (org.talend.core.model.properties.ProcessItem)3 JobEditorInput (org.talend.core.ui.editor.JobEditorInput)3 Iterator (java.util.Iterator)2 Map (java.util.Map)2 EList (org.eclipse.emf.common.util.EList)2 Point (org.eclipse.swt.graphics.Point)2 IEditorInput (org.eclipse.ui.IEditorInput)2 IContextParameter (org.talend.core.model.process.IContextParameter)2 IElementParameter (org.talend.core.model.process.IElementParameter)2 Item (org.talend.core.model.properties.Item)2 ContextParameterTypeImpl (org.talend.designer.core.model.utils.emf.talendfile.impl.ContextParameterTypeImpl)2