Search in sources :

Example 66 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule 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 67 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule in project tdi-studio-se by Talend.

the class BuildJobManager method buildJob.

public void buildJob(String destinationPath, ProcessItem itemToExport, String version, String context, Map<ExportChoice, Object> exportChoiceMap, JobExportType jobExportType, boolean checkCompilationError, IProgressMonitor monitor) throws Exception {
    IProgressMonitor pMonitor = new NullProgressMonitor();
    if (monitor != null) {
        pMonitor = monitor;
    }
    final boolean oldMeasureActived = TimeMeasure.measureActive;
    if (!oldMeasureActived) {
        // not active before.
        TimeMeasure.display = TimeMeasure.displaySteps = TimeMeasure.measureActive = CommonsPlugin.isDebugMode();
    }
    final String timeMeasureId = "Build job for " + itemToExport.getProperty().getLabel() + ' ' + version;
    TimeMeasure.begin(timeMeasureId);
    try {
        final int scale = 1000;
        int total = 4;
        //$NON-NLS-1$
        pMonitor.beginTask(Messages.getString("JobScriptsExportWizardPage.newExportJobScript", jobExportType), scale * total);
        ProcessItem processItem = itemToExport;
        // get correct version
        if (!RelationshipItemBuilder.LATEST_VERSION.equals(version) && version != null && !"".equals(version) && !version.equals(processItem.getProperty().getVersion())) {
            processItem = ItemCacheManager.getProcessItem(processItem.getProperty().getId(), version);
        }
        final String label = processItem.getProperty().getLabel();
        final IBuildJobHandler buildJobHandler = BuildJobFactory.createBuildJobHandler(processItem, context, version, exportChoiceMap, jobExportType);
        ProcessUtils.setJarWithContext(ProcessUtils.needsToHaveContextInsideJar(processItem));
        final IWorkspaceRunnable op = new IWorkspaceRunnable() {

            @Override
            public void run(IProgressMonitor wrMonitor) throws CoreException {
                try {
                    wrMonitor.beginTask(Messages.getString("JobScriptsExportWizardPage.newExportJobScript", jobExportType), scale * 3);
                    TimeMeasure.step(timeMeasureId, "prepare to build job");
                    buildJobHandler.generateItemFiles(true, new SubProgressMonitor(wrMonitor, scale));
                    wrMonitor.worked(scale);
                    TimeMeasure.step(timeMeasureId, "generateItemFiles");
                    buildJobHandler.generateJobFiles(new SubProgressMonitor(wrMonitor, scale));
                    wrMonitor.worked(scale);
                    TimeMeasure.step(timeMeasureId, "generateJobFiles");
                    buildJobHandler.build(new SubProgressMonitor(wrMonitor, scale));
                    TimeMeasure.step(timeMeasureId, "build and package");
                    wrMonitor.done();
                } catch (Exception e) {
                    throw new CoreException(new org.eclipse.core.runtime.Status(IStatus.ERROR, FrameworkUtil.getBundle(this.getClass()).getSymbolicName(), "Error", e));
                }
            }

            ;
        };
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        try {
            ISchedulingRule schedulingRule = workspace.getRoot();
            // the update the project files need to be done in the workspace runnable to avoid all
            // notification
            // of changes before the end of the modifications.
            workspace.run(op, schedulingRule, IWorkspace.AVOID_UPDATE, pMonitor);
        } catch (CoreException e) {
            Throwable cause = e.getCause();
            if (cause == null) {
                throw new PersistenceException(e);
            }
            throw new PersistenceException(cause);
        }
        ProcessUtils.setJarWithContext(false);
        IFile jobTargetFile = buildJobHandler.getJobTargetFile();
        if (jobTargetFile != null && jobTargetFile.exists()) {
            IPath jobZipLocation = jobTargetFile.getLocation();
            File jobZipFile = jobZipLocation.toFile();
            String jobZip = jobZipLocation.toString();
            if (needClasspathJar(exportChoiceMap)) {
                ExportJobUtil.deleteTempFiles();
                JavaJobExportReArchieveCreator creator = new JavaJobExportReArchieveCreator(jobZip, label);
                FilesUtils.unzip(jobZip, creator.getTmpFolder() + File.separator + label + "_" + version);
                creator.buildNewJar();
                ZipToFile.zipFile(creator.getTmpFolder(), jobZip);
                creator.deleteTempFiles();
                TimeMeasure.step(timeMeasureId, "Recreate job jar for classpath");
            }
            // TBD-2500
            Set<ProcessItem> processItems = new HashSet<ProcessItem>();
            processItems.add(processItem);
            // We get the father job childs.
            Set<JobInfo> infos = ProcessorUtilities.getChildrenJobInfo(processItem);
            Iterator<JobInfo> infoIterator = infos.iterator();
            while (infoIterator.hasNext()) {
                processItems.add(infoIterator.next().getProcessItem());
            }
            TimeMeasure.step(timeMeasureId, "getChildrenJobInfo");
            // We iterate over the job and its childs in order to re-archive them if needed.
            for (ProcessItem pi : processItems) {
                BDJobReArchieveCreator bdRecreator = new BDJobReArchieveCreator(pi, processItem);
                bdRecreator.create(jobZipFile);
            }
            TimeMeasure.step(timeMeasureId, "BDJobReArchieveCreator");
            File jobFileTarget = new File(destinationPath);
            if (jobFileTarget.isDirectory()) {
                jobFileTarget = new File(destinationPath, jobZipFile.getName());
            }
            FilesUtils.copyFile(jobZipFile, jobFileTarget);
            TimeMeasure.step(timeMeasureId, "Copy packaged file to target");
        } else if (jobTargetFile != null) {
            throw new Exception("Job was not built successfully, please check the logs for more details available on the workspace/.Java/lastGenerated.log");
        }
        if (checkCompilationError) {
            CorePlugin.getDefault().getRunProcessService().checkLastGenerationHasCompilationError(false);
        }
        pMonitor.worked(scale);
        pMonitor.done();
    } finally {
        TimeMeasure.end(timeMeasureId);
        // if active before, not disable and active still.
        if (!oldMeasureActived) {
            TimeMeasure.display = TimeMeasure.displaySteps = TimeMeasure.measureActive = false;
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) JobInfo(org.talend.core.model.process.JobInfo) JavaJobExportReArchieveCreator(org.talend.repository.ui.wizards.exportjob.JavaJobExportReArchieveCreator) HashSet(java.util.HashSet) IStatus(org.eclipse.core.runtime.IStatus) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IPath(org.eclipse.core.runtime.IPath) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) PersistenceException(org.talend.commons.exception.PersistenceException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProcessItem(org.talend.core.model.properties.ProcessItem) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IBuildJobHandler(org.talend.core.runtime.process.IBuildJobHandler) PersistenceException(org.talend.commons.exception.PersistenceException) ZipToFile(org.talend.repository.ui.utils.ZipToFile) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 68 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule in project tdi-studio-se by Talend.

the class ImportItemUtil method importItemRecords.

@SuppressWarnings("unchecked")
public List<ItemRecord> importItemRecords(final ResourcesManager manager, final List<ItemRecord> itemRecords, final IProgressMonitor monitor, final boolean overwrite, final IPath destinationPath, final String contentType) {
    TimeMeasure.display = CommonsPlugin.isDebugMode();
    TimeMeasure.displaySteps = CommonsPlugin.isDebugMode();
    TimeMeasure.measureActive = CommonsPlugin.isDebugMode();
    TimeMeasure.begin("importItemRecords");
    hasJoblets = false;
    statAndLogsSettingsReloaded = false;
    implicitSettingsReloaded = false;
    restoreFolder = new RestoreFolderUtil();
    Collections.sort(itemRecords, new Comparator<ItemRecord>() {

        @Override
        public int compare(ItemRecord o1, ItemRecord o2) {
            if (o1.getProperty().getItem() instanceof RoutineItem && o2.getProperty().getItem() instanceof RoutineItem) {
                return 0;
            } else if (!(o1.getProperty().getItem() instanceof RoutineItem) && !(o2.getProperty().getItem() instanceof RoutineItem)) {
                // TUP-2548 sort items by label
                String label = o1.getLabel();
                if (label == null) {
                    return -1;
                }
                final String label2 = o2.getLabel();
                if (label2 == null) {
                    return 1;
                }
                return label.compareTo(label2);
            } else if (o1.getProperty().getItem() instanceof RoutineItem) {
                return -1;
            } else {
                return 1;
            }
        }
    });
    //$NON-NLS-1$
    monitor.beginTask(Messages.getString("ImportItemWizardPage.ImportSelectedItems"), itemRecords.size() * 2 + 1);
    RepositoryWorkUnit repositoryWorkUnit = new //$NON-NLS-1$
    RepositoryWorkUnit(//$NON-NLS-1$
    "Import Items") {

        @Override
        public void run() throws PersistenceException {
            final IWorkspaceRunnable op = new IWorkspaceRunnable() {

                @Override
                public void run(IProgressMonitor monitor) throws CoreException {
                    final IProxyRepositoryFactory factory = CorePlugin.getDefault().getProxyRepositoryFactory();
                    // bug 10520
                    final Set<String> overwriteDeletedItems = new HashSet<String>();
                    final Set<String> idDeletedBeforeImport = new HashSet<String>();
                    Map<String, String> nameToIdMap = new HashMap<String, String>();
                    for (ItemRecord itemRecord : itemRecords) {
                        if (!monitor.isCanceled()) {
                            if (itemRecord.isValid()) {
                                if (itemRecord.getState() == State.ID_EXISTED) {
                                    String id = nameToIdMap.get(itemRecord.getProperty().getLabel() + ERepositoryObjectType.getItemType(itemRecord.getProperty().getItem()).toString());
                                    if (id == null) {
                                        /*
                                             * if id exsist then need to genrate new id for this job,in this case the
                                             * job won't override the old one
                                             */
                                        id = EcoreUtil.generateUUID();
                                        nameToIdMap.put(itemRecord.getProperty().getLabel() + ERepositoryObjectType.getItemType(itemRecord.getProperty().getItem()).toString(), id);
                                    }
                                    itemRecord.getProperty().setId(id);
                                }
                            }
                        }
                    }
                    for (ItemRecord itemRecord : itemRecords) {
                        if (!monitor.isCanceled()) {
                            if (itemRecord.isValid()) {
                                importItemRecord(manager, itemRecord, overwrite, destinationPath, overwriteDeletedItems, idDeletedBeforeImport, contentType, monitor);
                                IRepositoryViewObject object;
                                try {
                                    Property property = itemRecord.getProperty();
                                    if (property == null) {
                                        object = factory.getSpecificVersion(itemRecord.getItemId(), itemRecord.getItemVersion(), true);
                                        property = object.getProperty();
                                    }
                                    RelationshipItemBuilder.getInstance().addOrUpdateItem(property.getItem(), true);
                                    itemRecord.setProperty(null);
                                    ProxyRepositoryFactory.getInstance().unloadResources(property);
                                } catch (PersistenceException e) {
                                    ExceptionHandler.process(e);
                                }
                                statAndLogsSettingsReloaded = false;
                                implicitSettingsReloaded = false;
                                monitor.worked(1);
                            }
                        }
                    }
                    // deploy routines Jar
                    if (!getRoutineExtModulesMap().isEmpty()) {
                        Set<String> extRoutines = new HashSet<String>();
                        for (String id : getRoutineExtModulesMap().keySet()) {
                            Set<String> set = getRoutineExtModulesMap().get(id);
                            if (set != null) {
                                extRoutines.addAll(set);
                            }
                        }
                        if (manager instanceof ProviderManager || manager instanceof ZipFileManager) {
                            deployJarToDesForArchive(manager, extRoutines);
                        } else {
                            deployJarToDes(manager, extRoutines);
                        }
                    }
                    if (PluginChecker.isJobLetPluginLoaded()) {
                        IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
                        if (service != null) {
                            service.loadComponentsFromProviders();
                        }
                    }
                    checkDeletedFolders();
                    monitor.done();
                    TimeMeasure.step("importItemRecords", "before save");
                    if (RelationshipItemBuilder.getInstance().isNeedSaveRelations()) {
                        RelationshipItemBuilder.getInstance().saveRelations();
                        TimeMeasure.step("importItemRecords", "save relations");
                    } else {
                        // with relations
                        try {
                            factory.saveProject(ProjectManager.getInstance().getCurrentProject());
                        } catch (PersistenceException e) {
                            throw new CoreException(new Status(IStatus.ERROR, FrameworkUtil.getBundle(this.getClass()).getSymbolicName(), "Import errors", e));
                        }
                        TimeMeasure.step("importItemRecords", "save project");
                    }
                }
            };
            IWorkspace workspace = ResourcesPlugin.getWorkspace();
            try {
                ISchedulingRule schedulingRule = workspace.getRoot();
                // the update the project files need to be done in the workspace runnable to avoid all
                // notification
                // of changes before the end of the modifications.
                workspace.run(op, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
            } catch (CoreException e) {
            // ?
            }
        }
    };
    repositoryWorkUnit.setAvoidUnloadResources(true);
    repositoryWorkUnit.setUnloadResourcesAfterRun(true);
    ProxyRepositoryFactory.getInstance().executeRepositoryWorkUnit(repositoryWorkUnit);
    monitor.done();
    // for (ItemRecord itemRecord : itemRecords) {
    // itemRecord.clear();
    // }
    clearAllData();
    if (hasJoblets) {
        ComponentsFactoryProvider.getInstance().resetSpecificComponents();
    }
    TimeMeasure.end("importItemRecords");
    TimeMeasure.display = false;
    TimeMeasure.displaySteps = false;
    TimeMeasure.measureActive = false;
    return itemRecords;
}
Also used : Status(org.eclipse.core.runtime.Status) ERepositoryStatus(org.talend.commons.runtime.model.repository.ERepositoryStatus) IStatus(org.eclipse.core.runtime.IStatus) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) HashMap(java.util.HashMap) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) RoutineItem(org.talend.core.model.properties.RoutineItem) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IJobletProviderService(org.talend.core.ui.IJobletProviderService) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) RestoreFolderUtil(org.talend.core.repository.ui.actions.RestoreFolderUtil) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) HashSet(java.util.HashSet)

Example 69 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule in project tesb-studio-se by Talend.

the class OpenAnotherVersionResrouceWizard method performFinish.

@Override
public boolean performFinish() {
    if (mainPage.isCreateNewVersionJob()) {
        IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

            public void run(final IProgressMonitor monitor) throws CoreException {
                if (!alreadyEditedByUser) {
                    getProperty().setVersion(mainPage.getNewVersion());
                    refreshNewJob();
                    try {
                        ProxyRepositoryFactory.getInstance().saveProject(ProjectManager.getInstance().getCurrentProject());
                    } catch (PersistenceException e) {
                        ExceptionHandler.process(e);
                    }
                }
                try {
                    ProxyRepositoryFactory.getInstance().lock(repoObject);
                } catch (PersistenceException | LoginException e) {
                    ExceptionHandler.process(e);
                }
                //					boolean locked = repoObject.getRepositoryStatus().equals(
                //							ERepositoryStatus.LOCK_BY_USER);
                openAnotherVersion((IRepositoryNode) repoObject.getRepositoryNode());
                try {
                    ProxyRepositoryFactory.getInstance().saveProject(ProjectManager.getInstance().getCurrentProject());
                } catch (PersistenceException e) {
                    ExceptionHandler.process(e);
                }
            }
        };
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        try {
            ISchedulingRule schedulingRule = workspace.getRoot();
            // the update the project files need to be done in the workspace
            // runnable to avoid all notification
            // of changes before the end of the modifications.
            workspace.run(runnable, schedulingRule, IWorkspace.AVOID_UPDATE, null);
        } catch (CoreException e) {
            MessageBoxExceptionHandler.process(e);
        }
    } else {
        StructuredSelection selection = (StructuredSelection) mainPage.getSelection();
        IRepositoryNode node = (IRepositoryNode) selection.getFirstElement();
        boolean lastVersion = node.getObject().getVersion().equals(repoObject.getVersion());
        repoObject.getProperty().setVersion(originalVersion);
        if (lastVersion) {
            lockObject(repoObject);
        }
        //			ERepositoryStatus status = node.getObject().getRepositoryStatus();
        //			boolean isLocked = false;
        //			if (status == ERepositoryStatus.LOCK_BY_USER) {
        //				isLocked = true;
        //			}
        // Only latest version can be editted
        openAnotherVersion(node);
    }
    return true;
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IRepositoryNode(org.talend.repository.model.IRepositoryNode) IWorkspace(org.eclipse.core.resources.IWorkspace) PersistenceException(org.talend.commons.exception.PersistenceException) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) LoginException(org.talend.commons.exception.LoginException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 70 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule in project tdi-studio-se by Talend.

the class OpenExistVersionProcessWizard method performFinish.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.wizard.Wizard#performFinish()
     */
@Override
public boolean performFinish() {
    if (mainPage.isCreateNewVersionJob()) {
        try {
            ProxyRepositoryFactory.getInstance().updateLockStatus();
        } catch (PersistenceException e1) {
            ExceptionHandler.process(e1);
        }
        ERepositoryStatus repositoryStatus = ProxyRepositoryFactory.getInstance().getStatus(processObject);
        if ((repositoryStatus.equals(ERepositoryStatus.READ_ONLY)) || repositoryStatus == ERepositoryStatus.LOCK_BY_OTHER || repositoryStatus.equals(ERepositoryStatus.LOCK_BY_USER)) {
            Display.getDefault().syncExec(new Runnable() {

                @Override
                public void run() {
                    MessageDialog.openWarning(getShell(), "Warning", Messages.getString("OpenExistVersionProcessWizard.labelContent"));
                }
            });
            return false;
        } else {
            IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

                @Override
                public void run(final IProgressMonitor monitor) throws CoreException {
                    if (!alreadyEditedByUser) {
                        refreshNewJob();
                        RelationshipItemBuilder.getInstance().addOrUpdateItem(processObject.getProperty().getItem());
                        try {
                            ProxyRepositoryFactory.getInstance().saveProject(ProjectManager.getInstance().getCurrentProject());
                        } catch (Exception e) {
                            ExceptionHandler.process(e);
                        }
                    }
                    try {
                        Item newCreated = null;
                        if (processObject.getProperty() != null && processObject.getProperty().getItem() != null) {
                            newCreated = processObject.getProperty().getItem();
                        }
                        if (!(newCreated instanceof BusinessProcessItem)) {
                            ProxyRepositoryFactory.getInstance().lock(processObject);
                        }
                    } catch (PersistenceException e) {
                        ExceptionHandler.process(e);
                    } catch (LoginException e) {
                        ExceptionHandler.process(e);
                    }
                    boolean locked = processObject.getRepositoryStatus().equals(ERepositoryStatus.LOCK_BY_USER);
                    openAnotherVersion((RepositoryNode) processObject.getRepositoryNode(), !locked);
                    try {
                        ProxyRepositoryFactory.getInstance().saveProject(ProjectManager.getInstance().getCurrentProject());
                    } catch (Exception e) {
                        ExceptionHandler.process(e);
                    }
                }
            };
            IWorkspace workspace = ResourcesPlugin.getWorkspace();
            try {
                ISchedulingRule schedulingRule = workspace.getRoot();
                // the update the project files need to be done in the workspace
                // runnable to avoid all notification
                // of changes before the end of the modifications.
                workspace.run(runnable, schedulingRule, IWorkspace.AVOID_UPDATE, null);
            } catch (CoreException e) {
                MessageBoxExceptionHandler.process(e);
            }
        }
    } else {
        StructuredSelection selection = (StructuredSelection) mainPage.getSelection();
        RepositoryNode node = (RepositoryNode) selection.getFirstElement();
        boolean lastVersion = node.getObject().getVersion().equals(processObject.getVersion());
        // processObject.getProperty().setVersion(originalVersion);
        if (lastVersion) {
            lockObject(processObject);
        }
        ERepositoryStatus status = node.getObject().getRepositoryStatus();
        boolean isLocked = false;
        if (status == ERepositoryStatus.LOCK_BY_USER) {
            isLocked = true;
        }
        // Only latest version can be editted
        openAnotherVersion(node, !lastVersion || !isLocked);
    }
    return true;
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ERepositoryStatus(org.talend.commons.runtime.model.repository.ERepositoryStatus) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) RepositoryNode(org.talend.repository.model.RepositoryNode) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) LoginException(org.talend.commons.exception.LoginException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SystemException(org.talend.commons.exception.SystemException) BusinessException(org.talend.commons.exception.BusinessException) PersistenceException(org.talend.commons.exception.PersistenceException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) Item(org.talend.core.model.properties.Item) JobScriptItem(org.talend.core.model.properties.JobScriptItem) RoutineItem(org.talend.core.model.properties.RoutineItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IWorkspace(org.eclipse.core.resources.IWorkspace) PersistenceException(org.talend.commons.exception.PersistenceException) LoginException(org.talend.commons.exception.LoginException)

Aggregations

ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)116 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)41 CoreException (org.eclipse.core.runtime.CoreException)40 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)32 IWorkspace (org.eclipse.core.resources.IWorkspace)30 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)22 PersistenceException (org.talend.commons.exception.PersistenceException)19 InvocationTargetException (java.lang.reflect.InvocationTargetException)17 IStatus (org.eclipse.core.runtime.IStatus)17 Status (org.eclipse.core.runtime.Status)15 IResource (org.eclipse.core.resources.IResource)14 MultiRule (org.eclipse.core.runtime.jobs.MultiRule)14 ArrayList (java.util.ArrayList)13 IResourceRuleFactory (org.eclipse.core.resources.IResourceRuleFactory)12 Job (org.eclipse.core.runtime.jobs.Job)12 IFile (org.eclipse.core.resources.IFile)11 HashSet (java.util.HashSet)10 IPath (org.eclipse.core.runtime.IPath)10 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)10 RepositoryWorkUnit (org.talend.repository.RepositoryWorkUnit)10