Search in sources :

Example 41 with ProcessItem

use of org.talend.core.model.properties.ProcessItem in project tdi-studio-se by Talend.

the class FixUnevenItemContextParametersMigrationTask method execute.

@SuppressWarnings("unchecked")
@Override
public ExecutionResult execute(Item item) {
    EList<ContextType> contexts = null;
    String defualtGroupName = null;
    if (item instanceof ProcessItem) {
        // process, process_mr, process_storm, route, routelet.
        ProcessItem processItem = (ProcessItem) item;
        contexts = processItem.getProcess().getContext();
        defualtGroupName = processItem.getProcess().getDefaultContext();
    } else if (item instanceof JobletProcessItem) {
        JobletProcessItem jobletItem = (JobletProcessItem) item;
        contexts = jobletItem.getJobletProcess().getContext();
        defualtGroupName = jobletItem.getJobletProcess().getDefaultContext();
    } else if (item instanceof ContextItem) {
        ContextItem contextItem = (ContextItem) item;
        contexts = contextItem.getContext();
        defualtGroupName = contextItem.getDefaultContext();
    }
    try {
        ContextType defaultGroup = null;
        for (ContextType context : contexts) {
            if (context.getName().equals(defualtGroupName)) {
                defaultGroup = context;
                break;
            }
        }
        if (defaultGroup == null && contexts.size() > 0) {
            defaultGroup = contexts.get(0);
        }
        boolean contextChanged = false;
        if (defaultGroup != null) {
            Map<String, ContextParameterType> paramMap = new HashMap<String, ContextParameterType>();
            List<String> paramNameList = new ArrayList<String>();
            paramMap.putAll(collectDefaultGroupParams(defaultGroup, paramNameList));
            for (ContextType context : contexts) {
                if (context == defaultGroup) {
                    continue;
                }
                Map<String, ContextParameterType> otherGroupParam = collectDefaultGroupParams(context, paramNameList);
                for (String paramName : otherGroupParam.keySet()) {
                    if (!paramMap.containsKey(paramName)) {
                        paramMap.put(paramName, otherGroupParam.get(paramName));
                    }
                }
            }
            // make sure all groups have the same param list
            for (ContextType context : contexts) {
                EList<ContextParameterType> params = context.getContextParameter();
                List<String> paramNames = new ArrayList<String>(paramNameList);
                for (ContextParameterType param : params) {
                    if (paramNames.contains(param.getName())) {
                        paramNames.remove(param.getName());
                    }
                }
                if (!paramNames.isEmpty()) {
                    contextChanged = true;
                    for (String paramToAdd : paramNames) {
                        ContextParameterType toAdd = paramMap.get(paramToAdd);
                        context.getContextParameter().add(EcoreUtil.copy(toAdd));
                    }
                }
            }
            // change param order if needed
            for (ContextType context : contexts) {
                EList<ContextParameterType> params = context.getContextParameter();
                List<ContextParameterType> copyOfParam = new ArrayList<ContextParameterType>(params);
                for (int i = 0; i < copyOfParam.size(); i++) {
                    ContextParameterType param = copyOfParam.get(i);
                    int indexOf = paramNameList.indexOf(param.getName());
                    if (i != indexOf) {
                        contextChanged = true;
                        params.remove(param);
                        params.add(indexOf, param);
                    }
                }
            }
            // make sure params in different groups have the same repository id and type as default group
            for (ContextType context : contexts) {
                EList<ContextParameterType> params = context.getContextParameter();
                for (ContextParameterType param : params) {
                    ContextParameterType paramDefault = paramMap.get(param.getName());
                    if (!paramDefault.getType().equals(param.getType())) {
                        contextChanged = true;
                        param.setType(paramDefault.getType());
                    }
                    if (paramDefault.getRepositoryContextId() == null && param.getRepositoryContextId() != null || (paramDefault.getRepositoryContextId() != null && !paramDefault.getRepositoryContextId().equals(param.getRepositoryContextId()))) {
                        contextChanged = true;
                        param.setRepositoryContextId(paramDefault.getRepositoryContextId());
                    }
                }
            }
        }
        if (contextChanged) {
            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) HashMap(java.util.HashMap) 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 42 with ProcessItem

use of org.talend.core.model.properties.ProcessItem in project tdi-studio-se by Talend.

the class AbstractMultiPageTalendEditor method updateRunJobContext.

protected void updateRunJobContext() {
    final JobContextManager manager = (JobContextManager) getProcess().getContextManager();
    if (manager.isModified()) {
        final Map<String, String> nameMap = manager.getNameMap();
        // gcui:add a progressDialog.
        Shell shell = null;
        Display display = PlatformUI.getWorkbench().getDisplay();
        if (display != null) {
            shell = display.getActiveShell();
        }
        if (shell == null) {
            display = Display.getCurrent();
            if (display == null) {
                display = Display.getDefault();
            }
            if (display != null) {
                shell = display.getActiveShell();
            }
        }
        ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(shell);
        IRunnableWithProgress runnable = new IRunnableWithProgress() {

            @Override
            public void run(final IProgressMonitor monitor) {
                //$NON-NLS-1$
                monitor.beginTask(Messages.getString("AbstractMultiPageTalendEditor_pleaseWait"), IProgressMonitor.UNKNOWN);
                Display.getDefault().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        IProxyRepositoryFactory factory = CorePlugin.getDefault().getProxyRepositoryFactory();
                        factory.executeRepositoryWorkUnit(new //$NON-NLS-1$
                        RepositoryWorkUnit<Object>(//$NON-NLS-1$
                        "..", //$NON-NLS-1$
                        this) {

                            @Override
                            protected void run() throws LoginException, PersistenceException {
                                try {
                                    IProxyRepositoryFactory factory = CorePlugin.getDefault().getProxyRepositoryFactory();
                                    Set<String> curContextVars = getCurrentContextVariables(manager);
                                    IProcess2 process2 = getProcess();
                                    String jobId = process2.getProperty().getId();
                                    IEditorReference[] reference = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
                                    List<IProcess2> processes = CorePlugin.getDefault().getDesignerCoreService().getOpenedProcess(reference);
                                    // gcui:if nameMap is empty it do nothing.
                                    if (!nameMap.isEmpty()) {
                                        UpdateRunJobComponentContextHelper.updateItemRunJobComponentReference(factory, nameMap, jobId, curContextVars);
                                        UpdateRunJobComponentContextHelper.updateOpenedJobRunJobComponentReference(processes, nameMap, jobId, curContextVars);
                                    }
                                    // add for bug 9564
                                    List<IRepositoryViewObject> all = factory.getAll(ERepositoryObjectType.PROCESS, true);
                                    List<ProcessItem> allProcess = new ArrayList<ProcessItem>();
                                    for (IRepositoryViewObject repositoryObject : all) {
                                        Item item = repositoryObject.getProperty().getItem();
                                        if (item instanceof ProcessItem) {
                                            ProcessItem processItem = (ProcessItem) item;
                                            allProcess.add(processItem);
                                        }
                                    }
                                    UpdateRunJobComponentContextHelper.updateRefJobRunJobComponentContext(factory, allProcess, process2);
                                } catch (PersistenceException e) {
                                    // e.printStackTrace();
                                    ExceptionHandler.process(e);
                                }
                                manager.setModified(false);
                            }
                        });
                    }
                });
                monitor.done();
                if (monitor.isCanceled()) {
                    try {
                        //$NON-NLS-1$
                        throw new InterruptedException("Save Fail");
                    } catch (InterruptedException e) {
                        ExceptionHandler.process(e);
                    }
                }
            }
        };
        try {
            progressDialog.run(true, true, runnable);
        } catch (InvocationTargetException e1) {
            ExceptionHandler.process(e1);
        } catch (InterruptedException e1) {
            ExceptionHandler.process(e1);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) Shell(org.eclipse.swt.widgets.Shell) IEditorReference(org.eclipse.ui.IEditorReference) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) IProcess2(org.talend.core.model.process.IProcess2) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) JobContextManager(org.talend.core.model.context.JobContextManager) Display(org.eclipse.swt.widgets.Display)

Example 43 with ProcessItem

use of org.talend.core.model.properties.ProcessItem in project tdi-studio-se by Talend.

the class AbstractMultiPageTalendEditor method covertJobscriptOnPageChange.

private void covertJobscriptOnPageChange() {
    try {
        boolean isDirty = jobletEditor.isDirty();
        jobletEditor.doSave(null);
        IProcess2 oldProcess = getProcess();
        ICreateXtextProcessService n = CorePlugin.getDefault().getCreateXtextProcessService();
        Item item = oldProcess.getProperty().getItem();
        ProcessType processType = null;
        if (item instanceof ProcessItem) {
            processType = n.convertDesignerEditorInput(((IFile) jobletEditor.getEditorInput().getAdapter(IResource.class)).getLocation().toOSString(), oldProcess.getProperty());
        } else if (item instanceof JobletProcessItem) {
            processType = n.convertJobletDesignerEditorInput(((IFile) jobletEditor.getEditorInput().getAdapter(IResource.class)).getLocation().toOSString(), oldProcess.getProperty());
        }
        if (item instanceof ProcessItem) {
            ((Process) oldProcess).updateProcess(processType);
        } else if (item instanceof JobletProcessItem) {
            ((Process) oldProcess).updateProcess(processType);
        }
        oldProcess.getUpdateManager().updateAll();
        designerEditor.setDirty(isDirty);
        List<Node> nodes = (List<Node>) oldProcess.getGraphicalNodes();
        List<Node> newNodes = new ArrayList<Node>();
        newNodes.addAll(nodes);
        for (Node node : newNodes) {
            node.getProcess().checkStartNodes();
            node.checkAndRefreshNode();
            IElementParameter ep = node.getElementParameter("ACTIVATE");
            if (ep != null && ep.getValue().equals(Boolean.FALSE)) {
                node.setPropertyValue(EParameterName.ACTIVATE.getName(), true);
                node.setPropertyValue(EParameterName.ACTIVATE.getName(), false);
            } else if (ep != null && ep.getValue().equals(Boolean.TRUE)) {
                node.setPropertyValue(EParameterName.ACTIVATE.getName(), false);
                node.setPropertyValue(EParameterName.ACTIVATE.getName(), true);
            }
            for (IElementParameter param : node.getElementParameters()) {
                if (!param.getChildParameters().isEmpty()) {
                    if (param.getValue() != null && param.getValue() instanceof String && ((String) param.getValue()).contains(":")) {
                        String[] splited = ((String) param.getValue()).split(":");
                        String childNameNeeded = splited[0].trim();
                        String valueChild = TalendQuoteUtils.removeQuotes(splited[1].trim());
                        if (param.getChildParameters().containsKey(childNameNeeded)) {
                            param.getChildParameters().get(childNameNeeded).setValue(valueChild);
                        }
                    }
                }
            }
            if (node.getNodeContainer() instanceof JobletContainer) {
                JobletContainer jc = (JobletContainer) node.getNodeContainer();
                if (node.isMapReduceStart()) {
                    //$NON-NLS-1$
                    jc.updateState("UPDATE_STATUS", "", jc.getPercentMap(), jc.getPercentReduce());
                }
            }
        }
    } catch (PersistenceException e) {
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) AbstractJobletContainer(org.talend.designer.core.ui.editor.jobletcontainer.AbstractJobletContainer) JobletContainer(org.talend.designer.core.ui.editor.jobletcontainer.JobletContainer) INode(org.talend.core.model.process.INode) Node(org.talend.designer.core.ui.editor.nodes.Node) ArrayList(java.util.ArrayList) ICreateXtextProcessService(org.talend.core.services.ICreateXtextProcessService) Process(org.talend.designer.core.ui.editor.process.Process) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) IProcess2(org.talend.core.model.process.IProcess2) PersistenceException(org.talend.commons.exception.PersistenceException) IElementParameter(org.talend.core.model.process.IElementParameter) ArrayList(java.util.ArrayList) List(java.util.List) IResource(org.eclipse.core.resources.IResource)

Example 44 with ProcessItem

use of org.talend.core.model.properties.ProcessItem in project tdi-studio-se by Talend.

the class AbstractMultiPageTalendEditor method codeSync.

private void codeSync() {
    IProcess2 process = getProcess();
    if (!(process.getProperty().getItem() instanceof ProcessItem)) {
        // shouldn't work for joblet
        return;
    }
    if (jobletEditor == getEditor(oldPageIndex)) {
        // added for routines code generated switch editor 0 to 3.
        ProcessItem processItem = (ProcessItem) process.getProperty().getItem();
        covertJobscriptOnPageChange();
        ParametersType parameters = processItem.getProcess().getParameters();
        if (parameters != null && parameters.getRoutinesParameter() != null && parameters.getRoutinesParameter().size() == 0) {
            try {
                List<RoutinesParameterType> dependenciesInPreference = RoutinesUtil.createDependenciesInPreference();
                parameters.getRoutinesParameter().addAll(dependenciesInPreference);
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
            }
        }
    }
    // if some code has been generated already, for the editor we should need only the main job, not the childs.
    try {
        boolean lastGeneratedWithStats = ProcessorUtilities.getLastGeneratedWithStats(process.getId());
        boolean lastGeneratedWithTrace = ProcessorUtilities.getLastGeneratedWithTrace(process.getId());
        if (processor.isCodeGenerated()) {
            ProcessorUtilities.generateCode(process, process.getContextManager().getDefaultContext(), lastGeneratedWithStats, lastGeneratedWithTrace, true, ProcessorUtilities.GENERATE_MAIN_ONLY);
        } else {
            ProcessorUtilities.generateCode(process, process.getContextManager().getDefaultContext(), lastGeneratedWithStats, lastGeneratedWithTrace, true, ProcessorUtilities.GENERATE_WITH_FIRST_CHILD);
        }
    } catch (ProcessorException e) {
        ExceptionHandler.process(e);
    }
}
Also used : ProcessorException(org.talend.designer.runprocess.ProcessorException) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) RoutinesParameterType(org.talend.designer.core.model.utils.emf.talendfile.RoutinesParameterType) IProcess2(org.talend.core.model.process.IProcess2) PersistenceException(org.talend.commons.exception.PersistenceException) ParametersType(org.talend.designer.core.model.utils.emf.talendfile.ParametersType)

Example 45 with ProcessItem

use of org.talend.core.model.properties.ProcessItem in project tdi-studio-se by Talend.

the class AbstractMultiPageTalendEditor method generateCode.

/**
     * DOC bqian Comment method "generateCode".
     */
protected void generateCode() {
    final IProcess2 process = getProcess();
    if (!(process.getProperty().getItem() instanceof ProcessItem)) {
        // shouldn't work for joblet
        return;
    }
    if (process.getGeneratingNodes().size() != 0) {
        Job job = new //$NON-NLS-1$
        AccessingEmfJob(//$NON-NLS-1$
        "Generating code") {

            @Override
            protected IStatus doRun(IProgressMonitor monitor) {
                try {
                    ProcessorUtilities.generateCode(process, process.getContextManager().getDefaultContext(), false, false, true, ProcessorUtilities.GENERATE_WITH_FIRST_CHILD);
                } catch (ProcessorException e) {
                    ExceptionHandler.process(e);
                }
                return Status.OK_STATUS;
            }
        };
        job.setUser(true);
        job.setPriority(Job.BUILD);
        // start as soon as possible
        job.schedule();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProcessorException(org.talend.designer.runprocess.ProcessorException) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) AccessingEmfJob(org.talend.core.model.utils.AccessingEmfJob) IProcess2(org.talend.core.model.process.IProcess2) AccessingEmfJob(org.talend.core.model.utils.AccessingEmfJob) Job(org.eclipse.core.runtime.jobs.Job)

Aggregations

ProcessItem (org.talend.core.model.properties.ProcessItem)191 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)58 PersistenceException (org.talend.commons.exception.PersistenceException)56 ArrayList (java.util.ArrayList)45 Item (org.talend.core.model.properties.Item)43 Property (org.talend.core.model.properties.Property)43 JobletProcessItem (org.talend.core.model.properties.JobletProcessItem)37 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)29 IProcess2 (org.talend.core.model.process.IProcess2)25 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)25 IProcess (org.talend.core.model.process.IProcess)24 ExportFileResource (org.talend.repository.documentation.ExportFileResource)24 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)24 File (java.io.File)23 INode (org.talend.core.model.process.INode)23 IDesignerCoreService (org.talend.designer.core.IDesignerCoreService)22 IOException (java.io.IOException)21 IFile (org.eclipse.core.resources.IFile)20 List (java.util.List)19 EList (org.eclipse.emf.common.util.EList)19