Search in sources :

Example 81 with IProcess2

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

the class JavaProcessorUtilities method sortClasspath.

// // see bug 3914, make the order of the jar files consistent with the
// command
// // line in run mode
private static void sortClasspath(Set<ModuleNeeded> jobModuleList, IProcess process, Set<ModuleNeeded> alreadyRetrievedModules) throws CoreException, ProcessorException {
    ITalendProcessJavaProject jProject = getTalendJavaProject();
    if (jProject == null) {
        return;
    }
    Set<ModuleNeeded> listModulesReallyNeeded = new HashSet<ModuleNeeded>();
    listModulesReallyNeeded.addAll(jobModuleList);
    Set<ModuleNeeded> optionalJarsOnlyForRoutines = new HashSet<ModuleNeeded>();
    // only for wizards or additional jars only to make the java project compile without any error.
    for (ModuleNeeded moduleNeeded : ModulesNeededProvider.getSystemRunningModules()) {
        optionalJarsOnlyForRoutines.add(moduleNeeded);
    }
    // list contains all routines linked to job as well as routines not used in the job
    // rebuild the list to have only the libs linked to routines "not used".
    optionalJarsOnlyForRoutines.removeAll(listModulesReallyNeeded);
    // only to be able to compile java project without error.
    for (ModuleNeeded jar : optionalJarsOnlyForRoutines) {
        listModulesReallyNeeded.add(jar);
    }
    addLog4jToModuleList(listModulesReallyNeeded);
    listModulesReallyNeeded.removeAll(alreadyRetrievedModules);
    alreadyRetrievedModules.addAll(listModulesReallyNeeded);
    String missingJars = null;
    Set<String> missingJarsForRoutinesOnly = new HashSet<String>();
    Set<String> missingJarsForProcessOnly = new HashSet<String>();
    File libDir = getJavaProjectLibFolder();
    ILibraryManagerService repositoryBundleService = CorePlugin.getDefault().getRepositoryBundleService();
    if ((libDir != null) && (libDir.isDirectory())) {
        Set<ModuleNeeded> jarsNeedRetrieve = new HashSet<ModuleNeeded>();
        for (ModuleNeeded moduleNeeded : listModulesReallyNeeded) {
            jarsNeedRetrieve.add(moduleNeeded);
        }
        if (!jarsNeedRetrieve.isEmpty()) {
            repositoryBundleService.retrieve(jarsNeedRetrieve, libDir.getAbsolutePath(), true);
            if (process instanceof IProcess2) {
                ((IProcess2) process).checkProcess();
            }
        }
        Set<ModuleNeeded> exist = new HashSet<ModuleNeeded>();
        for (File externalLib : libDir.listFiles(FilesUtils.getAcceptJARFilesFilter())) {
            for (ModuleNeeded module : jarsNeedRetrieve) {
                if (externalLib.getName().equals(module.getModuleName())) {
                    exist.add(module);
                }
            }
        }
        jarsNeedRetrieve.removeAll(exist);
        Set<String> jarStringListNeededByProcess = new HashSet<String>();
        for (ModuleNeeded moduleNeeded : jobModuleList) {
            jarStringListNeededByProcess.add(moduleNeeded.getModuleName());
        }
        for (ModuleNeeded jar : jarsNeedRetrieve) {
            if (jobModuleList.contains(jar)) {
                missingJarsForProcessOnly.add(jar.getModuleName());
            } else {
                missingJarsForRoutinesOnly.add(jar.getModuleName());
            }
            if (missingJars == null) {
                //$NON-NLS-1$
                missingJars = Messages.getString("JavaProcessorUtilities.msg.missingjar.forProcess") + jar;
            } else {
                //$NON-NLS-1$
                missingJars = missingJars + ", " + jar;
            }
        }
    }
    repositoryBundleService.deployModules(listModulesReallyNeeded, null);
    if (missingJars != null) {
        handleMissingJarsForProcess(missingJarsForRoutinesOnly, missingJarsForProcessOnly, missingJars);
    }
}
Also used : ILibraryManagerService(org.talend.core.ILibraryManagerService) IProcess2(org.talend.core.model.process.IProcess2) ModuleNeeded(org.talend.core.model.general.ModuleNeeded) File(java.io.File) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) HashSet(java.util.HashSet)

Example 82 with IProcess2

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

the class ProcessLayoutEditPolicy method getConnectionAndEndCommands.

protected Command getConnectionAndEndCommands(CreateConnectionRequest request) {
    CompoundCommand cc = new CompoundCommand("CreateNodeCommand");
    ProcessPart processPart = (ProcessPart) this.getHost();
    final GraphicalViewer graphicalViewer = (GraphicalViewer) processPart.getViewer();
    final CommandStack commandStack = processPart.getViewer().getEditDomain().getCommandStack();
    final String categoryName = ComponentsFactoryProvider.getInstance().getComponentsHandler().extractComponentsCategory().getName();
    final IProcess2 process = (IProcess2) processPart.getModel();
    TalendEditorConnectionTargetAssist assist = new TalendEditorConnectionTargetAssist(categoryName, graphicalViewer, commandStack, process);
    char start = '*';
    assist.showComponentCreationAssist(start);
    ConnectionCreateCommand cmd = (ConnectionCreateCommand) request.getStartCommand();
    if (assist.getComponentName() == null) {
        assist.releaseText();
        return cmd;
    }
    IComponent component = TalendEditorComponentCreationUtil.getComponentsInCategory(categoryName).get(assist.getComponentName());
    if (component == null) {
        assist.releaseText();
        return cmd;
    }
    assist.releaseText();
    Node newNode = new Node(component);
    NodeContainer nodeContainer = ((Process) newNode.getProcess()).loadNodeContainer(newNode, false);
    CreateNodeContainerCommand command = new CreateNodeContainerCommand((org.talend.designer.core.ui.editor.process.Process) newNode.getProcess(), nodeContainer, request.getLocation());
    cc.add(command);
    cmd.setTarget(newNode);
    cc.add(cmd);
    return cc;
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) GraphicalViewer(org.eclipse.gef.GraphicalViewer) IComponent(org.talend.core.model.components.IComponent) Node(org.talend.designer.core.ui.editor.nodes.Node) IGraphicalNode(org.talend.core.ui.process.IGraphicalNode) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) CreateNodeContainerCommand(org.talend.designer.core.ui.editor.cmd.CreateNodeContainerCommand) ConnectionCreateCommand(org.talend.designer.core.ui.editor.cmd.ConnectionCreateCommand) IProcess2(org.talend.core.model.process.IProcess2) TalendEditorConnectionTargetAssist(org.talend.designer.core.assist.TalendEditorConnectionTargetAssist)

Example 83 with IProcess2

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

the class UpdateManagerUtils method checkandRefreshProcess.

/**
     * DOC hyWang Comment method "checkandRefreshProcess".
     * 
     * @param results
     */
private static void checkandRefreshProcess(final List<UpdateResult> results) {
    for (UpdateResult result : results) {
        if (result.isJoblet() && !result.isChecked()) {
            continue;
        }
        if (result.getJob() instanceof IProcess2) {
            IProcess2 process = (IProcess2) result.getJob();
            process.checkProcess();
        }
    }
}
Also used : IProcess2(org.talend.core.model.process.IProcess2) UpdateResult(org.talend.core.model.update.UpdateResult)

Example 84 with IProcess2

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

the class UpdateManagerUtils method doExecuteUpdates.

private static boolean doExecuteUpdates(final List<UpdateResult> results, final boolean updateAllJobs) {
    if (results == null || results.isEmpty()) {
        return false;
    }
    try {
        IWorkspaceRunnable op = new IWorkspaceRunnable() {

            @Override
            public void run(IProgressMonitor monitor) throws CoreException {
                monitor.setCanceled(false);
                int size = (results.size() * 2 + 1) * UpdatesConstants.SCALE;
                //$NON-NLS-1$
                monitor.beginTask(Messages.getString("UpdateManagerUtils.Update"), size);
                ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                // first list by job we need to update
                Map<String, Set<String>> jobIdToVersion = new HashMap<String, Set<String>>();
                Map<String, Boolean> jobIdClosed = new HashMap<String, Boolean>();
                for (UpdateResult result : results) {
                    // if (!result.isChecked()) {
                    // continue;
                    // }
                    String id = result.getObjectId();
                    String version = result.getObjectVersion();
                    if (id == null) {
                        if (result.getJob() != null && result.getJob() instanceof IProcess) {
                            IProcess process = (IProcess) result.getJob();
                            if (process instanceof IProcess2 && ERepositoryStatus.LOCK_BY_OTHER.equals(factory.getStatus(((IProcess2) process).getProperty().getItem()))) {
                                // file.
                                continue;
                            }
                            id = process.getId();
                            version = process.getVersion();
                            result.setObjectId(id);
                            result.setObjectVersion(version);
                        } else {
                            continue;
                        }
                    }
                    Set<String> versionList;
                    if (!jobIdToVersion.containsKey(id)) {
                        versionList = new HashSet<String>();
                        jobIdToVersion.put(id, versionList);
                    } else {
                        versionList = jobIdToVersion.get(id);
                    }
                    versionList.add(version);
                    //$NON-NLS-1$
                    jobIdClosed.put(id + " - " + version, result.isFromItem());
                }
                // now will execute updates only for the job selected depends this list.
                for (String currentId : jobIdToVersion.keySet()) {
                    for (String version : jobIdToVersion.get(currentId)) {
                        IRepositoryViewObject currentObj = null;
                        //$NON-NLS-1$
                        boolean closedItem = jobIdClosed.get(currentId + " - " + version);
                        IProcess process = null;
                        Item item = null;
                        if (closedItem) {
                            // if item is closed, then just load it.
                            boolean checkOnlyLastVersion = Boolean.parseBoolean(DesignerPlugin.getDefault().getPreferenceStore().getString(//$NON-NLS-1$
                            "checkOnlyLastVersion"));
                            try {
                                if (checkOnlyLastVersion || version == null) {
                                    currentObj = factory.getLastVersion(currentId);
                                } else {
                                    List<IRepositoryViewObject> allVersion = factory.getAllVersion(currentId);
                                    for (IRepositoryViewObject obj : allVersion) {
                                        if (obj.getVersion().equals(version)) {
                                            currentObj = obj;
                                        }
                                    }
                                }
                            } catch (PersistenceException e) {
                                ExceptionHandler.process(e);
                            }
                            if (currentObj == null) {
                                // item not found, don't do anything
                                continue;
                            }
                            item = currentObj.getProperty().getItem();
                            IDesignerCoreService designerCoreService = CorePlugin.getDefault().getDesignerCoreService();
                            if (item instanceof ProcessItem) {
                                process = designerCoreService.getProcessFromProcessItem((ProcessItem) item);
                            } else if (item instanceof JobletProcessItem) {
                                process = designerCoreService.getProcessFromJobletProcessItem((JobletProcessItem) item);
                            }
                        }
                        for (UpdateResult result : results) {
                            // }
                            if (!StringUtils.equals(currentId, result.getObjectId())) {
                                // not the current job we need to update
                                continue;
                            }
                            if (closedItem) {
                                if (result.getJob() == null) {
                                    result.setJob(process);
                                } else {
                                    process = (IProcess) result.getJob();
                                }
                                IUpdateItemType jobletContextType = UpdateManagerProviderDetector.INSTANCE.getUpdateItemType(UpdateManagerHelper.TYPE_JOBLET_CONTEXT);
                                if (process != null && jobletContextType != null && (jobletContextType.equals(result.getUpdateType()))) {
                                    if ((result.getParameter() instanceof List) && process.getContextManager() != null) {
                                        process.getContextManager().setListContext((List<IContext>) result.getParameter());
                                    }
                                }
                            }
                            // execute
                            executeUpdate(result, monitor, updateAllJobs);
                            if (closedItem) {
                                result.setJob(null);
                            }
                        }
                        boolean isTestContainer = false;
                        ITestContainerProviderService testContainerService = null;
                        if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
                            testContainerService = (ITestContainerProviderService) GlobalServiceRegister.getDefault().getService(ITestContainerProviderService.class);
                            if (testContainerService != null) {
                                isTestContainer = testContainerService.isTestContainerItem(item);
                            }
                        }
                        if (closedItem && process instanceof IProcess2) {
                            IProcess2 process2 = (IProcess2) process;
                            ProcessType processType;
                            try {
                                processType = process2.saveXmlFile(false);
                                if (isTestContainer) {
                                    testContainerService.setTestContainerProcess(processType, item);
                                } else if (item instanceof JobletProcessItem) {
                                    ((JobletProcessItem) item).setJobletProcess((JobletProcess) processType);
                                } else {
                                    ((ProcessItem) item).setProcess(processType);
                                }
                                factory.save(item);
                            } catch (IOException e) {
                                ExceptionHandler.process(e);
                            } catch (PersistenceException e) {
                                ExceptionHandler.process(e);
                            }
                        }
                        if (closedItem && !ERepositoryStatus.LOCK_BY_USER.equals(factory.getStatus(item))) {
                            // unload item from memory, but only if this one is not locked by current user.
                            try {
                                factory.unloadResources(item.getProperty());
                            } catch (PersistenceException e) {
                                ExceptionHandler.process(e);
                            }
                        }
                    }
                }
                UpdateManagerProviderDetector.INSTANCE.postUpdate(results);
                // update joblet reference
                upadateJobletReferenceInfor();
                final List<UpdateResult> tempResults = new ArrayList<UpdateResult>(results);
                // refresh
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        refreshRelatedViewers(tempResults);
                        // hyWang add method checkandRefreshProcess for bug7248
                        checkandRefreshProcess(tempResults);
                    }
                });
                monitor.worked(1 * UpdatesConstants.SCALE);
                monitor.done();
            }
        };
        IRunnableWithProgress iRunnableWithProgress = new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                IWorkspace workspace = ResourcesPlugin.getWorkspace();
                try {
                    ISchedulingRule schedulingRule = workspace.getRoot();
                    workspace.run(op, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
            }
        };
        try {
            new ProgressMonitorDialog(null).run(false, false, iRunnableWithProgress);
        } catch (InvocationTargetException e) {
            ExceptionHandler.process(e);
        } catch (InterruptedException e) {
        }
        return !results.isEmpty();
    } finally {
        results.clear();
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) IContext(org.talend.core.model.process.IContext) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JobletProcess(org.talend.designer.joblet.model.JobletProcess) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Item(org.talend.core.model.properties.Item) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) IUpdateItemType(org.talend.core.model.update.IUpdateItemType) List(java.util.List) ArrayList(java.util.ArrayList) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcess(org.talend.core.model.process.IProcess) UpdateResult(org.talend.core.model.update.UpdateResult) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IOException(java.io.IOException) ITestContainerProviderService(org.talend.core.ui.ITestContainerProviderService) InvocationTargetException(java.lang.reflect.InvocationTargetException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) CoreException(org.eclipse.core.runtime.CoreException) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IWorkspace(org.eclipse.core.resources.IWorkspace) IProcess2(org.talend.core.model.process.IProcess2) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 85 with IProcess2

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

the class UpdateViewerHelper method checkItemResultState.

private void checkItemResultState(Item item, boolean state) {
    if (item == null) {
        return;
    }
    List<IProcess2> openedProcesses = UpdateManagerUtils.getOpenedProcess();
    boolean isOpened = openedProcesses.contains(item.getResultObject().getJob());
    boolean jobletUpdate = false;
    boolean jobletContext = false;
    if (item.getParent() != null && item.getParent().getNode() != null && (item.getParent().getNode() instanceof Node) && ((Node) item.getParent().getNode()).isJoblet()) {
        jobletUpdate = true;
    }
    IUpdateItemType jobletContextType = UpdateManagerProviderDetector.INSTANCE.getUpdateItemType(UpdateManagerHelper.TYPE_JOBLET_CONTEXT);
    if (jobletContextType != null && item.getParent() != null && jobletContextType.equals(item.getParent().getType())) {
        jobletContext = true;
    }
    // not checked
    if (!state && !item.getResultObject().isReadOnly()) {
        EUpdateResult resultType = item.getResultObject().getResultType();
        if (resultType == EUpdateResult.UPDATE || resultType == EUpdateResult.ADD || resultType == EUpdateResult.DELETE) {
            item.setChecked(false);
        } else if ((jobletUpdate || jobletContext) && !isOpened && (resultType == EUpdateResult.JOBLET_UPDATE || resultType == EUpdateResult.RELOAD)) {
            item.setChecked(state);
        }
    } else if (item.getResultObject().isReadOnly() && jobletUpdate) {
        return;
    } else {
        // keep the checked
        item.setChecked(true);
    }
}
Also used : EUpdateResult(org.talend.core.model.update.EUpdateResult) Node(org.talend.designer.core.ui.editor.nodes.Node) IProcess2(org.talend.core.model.process.IProcess2) IUpdateItemType(org.talend.core.model.update.IUpdateItemType)

Aggregations

IProcess2 (org.talend.core.model.process.IProcess2)115 INode (org.talend.core.model.process.INode)31 Node (org.talend.designer.core.ui.editor.nodes.Node)31 ArrayList (java.util.ArrayList)30 ProcessItem (org.talend.core.model.properties.ProcessItem)30 Item (org.talend.core.model.properties.Item)28 IProcess (org.talend.core.model.process.IProcess)24 PersistenceException (org.talend.commons.exception.PersistenceException)22 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)21 JobletProcessItem (org.talend.core.model.properties.JobletProcessItem)19 List (java.util.List)17 IElementParameter (org.talend.core.model.process.IElementParameter)15 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)14 Property (org.talend.core.model.properties.Property)14 CoreException (org.eclipse.core.runtime.CoreException)12 IConnection (org.talend.core.model.process.IConnection)11 HashSet (java.util.HashSet)10 IEditorReference (org.eclipse.ui.IEditorReference)10 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)10 InvocationTargetException (java.lang.reflect.InvocationTargetException)7