Search in sources :

Example 1 with PersistenceException

use of org.talend.commons.exception.PersistenceException in project tdi-studio-se by Talend.

the class GenericConnWizardPage method setVisible.

@Override
public void setVisible(boolean visible) {
    super.setVisible(visible);
    if (visible) {
        dynamicComposite.resetParameters();
        dynamicComposite.refresh();
        dynamicComposite.setMinHeight(dynamicComposite.getMinHeight());
        updateContextFields();
        if (getNameParameter() != null) {
            Job job = new //$NON-NLS-1$
            Job(//$NON-NLS-1$
            "") {

                @Override
                protected IStatus run(IProgressMonitor monitor) {
                    try {
                        listExistingObjects = loadRepositoryViewObjectList();
                    } catch (PersistenceException e) {
                        return new org.eclipse.core.runtime.Status(IStatus.ERROR, "org.talend.metadata.management.ui", 1, "", //$NON-NLS-1$ //$NON-NLS-2$
                        e);
                    }
                    retrieveNameFinished = true;
                    // force the refresh of the text field, no matter successfull retrieve of not.
                    Display d = DisplayUtils.getDisplay();
                    if (d != null) {
                        d.syncExec(new Runnable() {

                            @Override
                            public void run() {
                                evaluateTextField();
                            }
                        });
                    }
                    return Status.OK_STATUS;
                }
            };
            job.setUser(false);
            job.setPriority(Job.BUILD);
            // start as soon as possible
            job.schedule();
        }
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) PersistenceException(org.talend.commons.exception.PersistenceException) Status(org.eclipse.core.runtime.Status) Job(org.eclipse.core.runtime.jobs.Job) Display(org.eclipse.swt.widgets.Display)

Example 2 with PersistenceException

use of org.talend.commons.exception.PersistenceException in project tdi-studio-se by Talend.

the class ImportItemUtil method importItemRecord.

private void importItemRecord(ResourcesManager manager, ItemRecord itemRecord, boolean overwrite, IPath destinationPath, final Set<String> overwriteDeletedItems, final Set<String> idDeletedBeforeImport, String contentType, final IProgressMonitor monitor) {
    //$NON-NLS-1$
    monitor.subTask(Messages.getString("ImportItemWizardPage.Importing") + itemRecord.getItemName());
    resolveItem(manager, itemRecord);
    if (!itemRecord.isValid()) {
        return;
    }
    int num = 0;
    for (Object obj : itemRecord.getResourceSet().getResources()) {
        if (!(obj instanceof PropertiesProjectResourceImpl)) {
            if (obj instanceof XMIResourceImpl) {
                num++;
                if (num > 2) {
                    // 2 so that metadata migration for 4.1 works
                    try {
                        throw new InvocationTargetException(new PersistenceException("The source file of " + itemRecord.getLabel() + " has error,Please check it!"));
                    } catch (InvocationTargetException e) {
                        ExceptionHandler.process(e);
                    }
                    return;
                }
            }
        }
    }
    final Item item = itemRecord.getItem();
    if (item != null) {
        ProxyRepositoryFactory repFactory = ProxyRepositoryFactory.getInstance();
        ERepositoryObjectType itemType = ERepositoryObjectType.getItemType(item);
        IPath path = new Path(item.getState().getPath());
        if (destinationPath != null && itemType.name().equals(contentType)) {
            path = destinationPath.append(path);
        }
        try {
            FolderItem folderItem = repFactory.getFolderItem(ProjectManager.getInstance().getCurrentProject(), itemType, path);
            if (folderItem == null) {
                // if this folder does not exists (and it's parents), it will check if the folder was originally
                // deleted in source project.
                // if yes, it will set back the delete status to the folder, to keep the same as the original
                // project when import.
                // Without this code, deleted folders of items imported will not be in the recycle bin after import.
                // delete status is set finally in the function checkDeletedFolders
                IPath curPath = path;
                EList deletedFoldersFromOriginalProject = itemRecord.getItemProject().getDeletedFolders();
                while (folderItem == null && !curPath.isEmpty() && !curPath.isRoot()) {
                    if (deletedFoldersFromOriginalProject.contains(new Path(itemType.getFolder()).append(curPath.toPortableString()).toPortableString())) {
                        if (!foldersCreated.containsKey(itemType)) {
                            foldersCreated.put(itemType, new HashSet<String>());
                        }
                        foldersCreated.get(itemType).add(curPath.toPortableString());
                    }
                    if (curPath.segments().length > 0) {
                        curPath = curPath.removeLastSegments(1);
                        folderItem = repFactory.getFolderItem(ProjectManager.getInstance().getCurrentProject(), itemType, curPath);
                    }
                }
            }
            repFactory.createParentFoldersRecursively(ProjectManager.getInstance().getCurrentProject(), itemType, path, true);
        } catch (Exception e) {
            logError(e);
            //$NON-NLS-1$
            path = new Path("");
        }
        try {
            Item tmpItem = item;
            // delete existing items before importing, this should be done
            // once for a different id
            String id = itemRecord.getProperty().getId();
            IRepositoryViewObject lastVersion = itemRecord.getExistingItemWithSameId();
            if (lastVersion != null && overwrite && !itemRecord.isLocked() && (itemRecord.getState() == State.ID_EXISTED || itemRecord.getState() == State.NAME_EXISTED || itemRecord.getState() == State.NAME_AND_ID_EXISTED) && !deletedItems.contains(id)) {
                if (!overwriteDeletedItems.contains(id)) {
                    // bug 10520.
                    ERepositoryStatus status = repFactory.getStatus(lastVersion);
                    if (status == ERepositoryStatus.DELETED) {
                        // restore first.
                        repFactory.restoreObject(lastVersion, path);
                    }
                    overwriteDeletedItems.add(id);
                }
                /* only delete when name exsit rather than id exist */
                if (itemRecord.getState().equals(ItemRecord.State.NAME_EXISTED) || itemRecord.getState().equals(ItemRecord.State.NAME_AND_ID_EXISTED)) {
                    if (!idDeletedBeforeImport.contains(id)) {
                        // TDI-19535 (check if exists, delete all items with same id)
                        List<IRepositoryViewObject> allVersionToDelete = repFactory.getAllVersion(ProjectManager.getInstance().getCurrentProject(), lastVersion.getId(), false);
                        String importingLabel = itemRecord.getProperty().getLabel();
                        String existLabel = lastVersion.getProperty().getLabel();
                        for (IRepositoryViewObject currentVersion : allVersionToDelete) {
                            repFactory.forceDeleteObjectPhysical(lastVersion, currentVersion.getVersion(), isNeedDeleteOnRemote(importingLabel, existLabel));
                        }
                        idDeletedBeforeImport.add(id);
                    }
                }
                lastVersion = null;
            // List<IRepositoryObject> list = cache.findObjectsByItem(itemRecord);
            // if (!list.isEmpty()) {
            // // this code will delete all version of item with same
            // // id
            // repFactory.forceDeleteObjectPhysical(list.get(0));
            // deletedItems.add(id);
            // }
            }
            User author = itemRecord.getProperty().getAuthor();
            if (author != null) {
                if (!repFactory.setAuthorByLogin(tmpItem, author.getLogin())) {
                    // author will be
                    tmpItem.getProperty().setAuthor(null);
                // the logged
                // user in
                // create method
                }
            }
            if (item instanceof JobletProcessItem) {
                hasJoblets = true;
            }
            if (tmpItem instanceof ProcessItem && !statAndLogsSettingsReloaded && !implicitSettingsReloaded) {
                ProcessItem processItem = (ProcessItem) tmpItem;
                ParametersType paType = processItem.getProcess().getParameters();
                boolean statsPSettingRemoved = false;
                // for commanline import project setting
                if (itemRecord.isRemoveProjectStatslog()) {
                    if (paType != null) {
                        String paramName = "STATANDLOG_USE_PROJECT_SETTINGS";
                        EList listParamType = paType.getElementParameter();
                        for (int j = 0; j < listParamType.size(); j++) {
                            ElementParameterType pType = (ElementParameterType) listParamType.get(j);
                            if (pType != null && paramName.equals(pType.getName())) {
                                pType.setValue(Boolean.FALSE.toString());
                                statsPSettingRemoved = true;
                                break;
                            }
                        }
                    }
                }
                // 14446: item apply project setting param if use project setting
                String statslogUsePSetting = null;
                String implicitUsePSetting = null;
                if (paType != null) {
                    EList listParamType = paType.getElementParameter();
                    for (int j = 0; j < listParamType.size(); j++) {
                        ElementParameterType pType = (ElementParameterType) listParamType.get(j);
                        if (pType != null) {
                            if (!statsPSettingRemoved && "STATANDLOG_USE_PROJECT_SETTINGS".equals(pType.getName())) {
                                statslogUsePSetting = pType.getValue();
                            }
                            if ("IMPLICITCONTEXT_USE_PROJECT_SETTINGS".equals(pType.getName())) {
                                implicitUsePSetting = pType.getValue();
                            }
                            if (statsPSettingRemoved && implicitUsePSetting != null || !statsPSettingRemoved && implicitUsePSetting != null && statslogUsePSetting != null) {
                                break;
                            }
                        }
                    }
                }
                if (statslogUsePSetting != null && Boolean.parseBoolean(statslogUsePSetting) && !statAndLogsSettingsReloaded) {
                    CorePlugin.getDefault().getDesignerCoreService().reloadParamFromProjectSettings(paType, "STATANDLOG_USE_PROJECT_SETTINGS");
                    statAndLogsSettingsReloaded = true;
                }
                if (implicitUsePSetting != null && Boolean.parseBoolean(implicitUsePSetting) && !implicitSettingsReloaded) {
                    CorePlugin.getDefault().getDesignerCoreService().reloadParamFromProjectSettings(paType, "IMPLICITCONTEXT_USE_PROJECT_SETTINGS");
                    implicitSettingsReloaded = true;
                }
            }
            if (lastVersion == null || itemRecord.getState().equals(ItemRecord.State.ID_EXISTED)) {
                // import has not been developed to cope with migration in mind
                // so some model may not be able to load like the ConnectionItems
                // in that case items needs to be copied before migration
                // here we check that the loading of the item failed before calling the create method
                boolean isConnectionEmptyBeforeMigration = tmpItem instanceof ConnectionItem && ((ConnectionItem) tmpItem).getConnection().eResource() == null && !itemRecord.getMigrationTasksToApply().isEmpty();
                repFactory.create(tmpItem, path, true);
                if (isConnectionEmptyBeforeMigration) {
                    // copy the file before migration, this is bad because it
                    // should not refer to Filesytem
                    // but this is a quick hack and anyway the migration task only works on files
                    // IPath itemPath = itemRecord.getPath().removeFileExtension().addFileExtension(
                    // FileConstants.ITEM_EXTENSION);
                    InputStream is = manager.getStream(itemRecord.getPath().removeFileExtension().addFileExtension(FileConstants.ITEM_EXTENSION));
                    try {
                        URI propertyResourceURI = EcoreUtil.getURI(((ConnectionItem) tmpItem).getProperty());
                        URI relativePlateformDestUri = propertyResourceURI.trimFileExtension().appendFileExtension(FileConstants.ITEM_EXTENSION);
                        URL fileURL = FileLocator.toFileURL(new java.net.URL(//$NON-NLS-1$
                        "platform:/resource" + relativePlateformDestUri.toPlatformString(true)));
                        OutputStream os = new FileOutputStream(fileURL.getFile());
                        try {
                            FileCopyUtils.copyStreams(is, os);
                        } finally {
                            os.close();
                        }
                    } finally {
                        is.close();
                    }
                    repFactory.unloadResources(tmpItem.getProperty());
                } else {
                    // connections from migrations (from 4.0.x or previous version) doesn't support reference or
                    // screenshots
                    // so no need to call this code.
                    // It's needed to avoid to call the save method mainly just before or after the copy of the old
                    // connection since it will
                    copyScreenshotFile(manager, itemRecord);
                    boolean haveRef = copyReferenceFiles(manager, tmpItem, itemRecord.getPath());
                    if (haveRef) {
                        repFactory.save(tmpItem, true);
                    }
                }
                itemRecord.setImportPath(path.toPortableString());
                itemRecord.setRepositoryType(itemType);
                itemRecord.setItemId(itemRecord.getProperty().getId());
                itemRecord.setItemVersion(itemRecord.getProperty().getVersion());
                itemRecord.setImported(true);
                cache.addToCache(tmpItem);
            } else if (VersionUtils.compareTo(lastVersion.getProperty().getVersion(), tmpItem.getProperty().getVersion()) < 0) {
                repFactory.forceCreate(tmpItem, path);
                itemRecord.setImportPath(path.toPortableString());
                itemRecord.setItemId(itemRecord.getProperty().getId());
                itemRecord.setRepositoryType(itemType);
                itemRecord.setItemVersion(itemRecord.getProperty().getVersion());
                itemRecord.setImported(true);
                cache.addToCache(tmpItem);
            } else {
                PersistenceException e = new PersistenceException(Messages.getString("ImportItemUtil.persistenceException", //$NON-NLS-1$
                tmpItem.getProperty()));
                itemRecord.addError(e.getMessage());
                logError(e);
            }
            if (tmpItem != null) {
                // RelationshipItemBuilder.getInstance().addOrUpdateItem(tmpItem, true);
                if (tmpItem.getState() != null) {
                    if (itemType != null) {
                        final Set<String> folders = restoreFolder.getFolders(itemType);
                        if (folders != null) {
                            for (String folderPath : folders) {
                                if (folderPath != null && folderPath.equals(path.toString())) {
                                    FolderItem folderItem = repFactory.getFolderItem(ProjectManager.getInstance().getCurrentProject(), itemType, path);
                                    if (folderItem != null) {
                                        folderItem.getState().setDeleted(false);
                                        while (!(folderItem.getParent() instanceof Project)) {
                                            folderItem = (FolderItem) folderItem.getParent();
                                            if (folderItem.getType() == FolderType.SYSTEM_FOLDER_LITERAL) {
                                                break;
                                            }
                                            folderItem.getState().setDeleted(false);
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            itemRecord.addError(e.getMessage());
            logError(e);
        }
    }
    String label = itemRecord.getLabel();
    EList<Resource> resources = itemRecord.getResourceSet().getResources();
    Iterator<Resource> iterator = resources.iterator();
    while (iterator.hasNext()) {
        Resource res = iterator.next();
        // it can't be unloaded just after create the item.
        if (res != null && !(res instanceof ByteArrayResource)) {
            res.unload();
            iterator.remove();
        }
    }
    TimeMeasure.step("importItemRecords", "Import item: " + label);
    applyMigrationTasks(itemRecord, monitor);
    TimeMeasure.step("importItemRecords", "applyMigrationTasks: " + label);
}
Also used : ERepositoryStatus(org.talend.commons.runtime.model.repository.ERepositoryStatus) User(org.talend.core.model.properties.User) ConnectionItem(org.talend.core.model.properties.ConnectionItem) URL(java.net.URL) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileOutputStream(java.io.FileOutputStream) OutputStream(java.io.OutputStream) URI(org.eclipse.emf.common.util.URI) PropertiesProjectResourceImpl(org.talend.core.repository.model.PropertiesProjectResourceImpl) URL(java.net.URL) ReferenceFileItem(org.talend.core.model.properties.ReferenceFileItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ContextItem(org.talend.core.model.properties.ContextItem) SnippetItem(org.talend.core.model.properties.SnippetItem) Item(org.talend.core.model.properties.Item) LinkDocumentationItem(org.talend.core.model.properties.LinkDocumentationItem) FolderItem(org.talend.core.model.properties.FolderItem) RoutineItem(org.talend.core.model.properties.RoutineItem) TDQItem(org.talend.core.model.properties.TDQItem) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) FileItem(org.talend.core.model.properties.FileItem) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IPath(org.eclipse.core.runtime.IPath) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CwmResource(org.talend.model.emf.CwmResource) TalendXMIResource(org.talend.commons.runtime.model.emf.TalendXMIResource) ByteArrayResource(org.talend.core.model.properties.helper.ByteArrayResource) Resource(org.eclipse.emf.ecore.resource.Resource) ByteArrayResource(org.talend.core.model.properties.helper.ByteArrayResource) InvocationTargetException(java.lang.reflect.InvocationTargetException) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) MalformedURLException(java.net.MalformedURLException) PersistenceException(org.talend.commons.exception.PersistenceException) ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) Project(org.talend.core.model.properties.Project) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) FolderItem(org.talend.core.model.properties.FolderItem) EList(org.eclipse.emf.common.util.EList) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) FileOutputStream(java.io.FileOutputStream) PersistenceException(org.talend.commons.exception.PersistenceException) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) RepositoryViewObject(org.talend.core.model.repository.RepositoryViewObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) EObject(org.eclipse.emf.ecore.EObject) ParametersType(org.talend.designer.core.model.utils.emf.talendfile.ParametersType) XMIResourceImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl)

Example 3 with PersistenceException

use of org.talend.commons.exception.PersistenceException in project tdi-studio-se by Talend.

the class ImportItemWizardPage method performFinish.

public boolean performFinish() {
    final List<ItemRecord> itemRecords = new ArrayList<ItemRecord>();
    final List<ItemRecord> checkedItemRecords = getCheckedElements();
    itemRecords.addAll(checkedItemRecords);
    itemRecords.addAll(getHadoopSubrecords(itemRecords));
    for (ItemRecord itemRecord : itemRecords) {
        Item item = itemRecord.getProperty().getItem();
        if (item instanceof JobletProcessItem) {
            needToRefreshPalette = true;
        }
        IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
        if (item.getState().isLocked()) {
            try {
                factory.unlock(item);
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
            } catch (LoginException e) {
                ExceptionHandler.process(e);
            }
        }
        ERepositoryStatus status = factory.getStatus(item);
        if (status != null && status == ERepositoryStatus.LOCK_BY_USER) {
            try {
                factory.unlock(item);
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
            } catch (LoginException e) {
                ExceptionHandler.process(e);
            }
        }
    }
    try {
        IRunnableWithProgress iRunnableWithProgress = new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                IPath destinationPath = null;
                String contentType = "";
                if (rNode != null && rNode.getType().equals(ENodeType.SIMPLE_FOLDER)) {
                    destinationPath = RepositoryNodeUtilities.getPath(rNode);
                    contentType = rNode.getContentType().name();
                }
                repositoryUtil.setErrors(false);
                repositoryUtil.clear();
                repositoryUtil.importItemRecords(manager, itemRecords, monitor, overwrite, destinationPath, contentType);
                if (repositoryUtil.hasErrors()) {
                    throw new InvocationTargetException(new CoreException(new Status(IStatus.ERROR, FrameworkUtil.getBundle(this.getClass()).getSymbolicName(), //$NON-NLS-1$
                    "Import errors")));
                }
            }
        };
        new ProgressMonitorDialog(getShell()).run(true, true, iRunnableWithProgress);
    } catch (InvocationTargetException e) {
        Throwable targetException = e.getTargetException();
        if (repositoryUtil.getRoutineExtModulesMap().isEmpty()) {
            if (targetException instanceof CoreException) {
                //$NON-NLS-1$
                MessageDialog.openWarning(//$NON-NLS-1$
                getShell(), //$NON-NLS-1$
                Messages.getString("ImportItemWizardPage.ImportSelectedItems"), //$NON-NLS-1$
                Messages.getString("ImportItemWizardPage.ErrorsOccured"));
            }
        }
    } catch (InterruptedException e) {
    //
    }
    ResourcesManager curManager = this.manager;
    if (curManager instanceof ProviderManager) {
        curManager.closeResource();
    }
    selectedItems = null;
    itemRecords.clear();
    return true;
}
Also used : ERepositoryStatus(org.talend.commons.runtime.model.repository.ERepositoryStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ERepositoryStatus(org.talend.commons.runtime.model.repository.ERepositoryStatus) IPath(org.eclipse.core.runtime.IPath) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) JobletDocumentationItem(org.talend.core.model.properties.JobletDocumentationItem) JobDocumentationItem(org.talend.core.model.properties.JobDocumentationItem) Item(org.talend.core.model.properties.Item) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) TreeItem(org.eclipse.swt.widgets.TreeItem) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) CoreException(org.eclipse.core.runtime.CoreException) PersistenceException(org.talend.commons.exception.PersistenceException) LoginException(org.talend.commons.exception.LoginException) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 4 with PersistenceException

use of org.talend.commons.exception.PersistenceException in project tdi-studio-se by Talend.

the class MavenVersionManagementProjectSettingPage method updateItemsVersion.

protected void updateItemsVersion() {
    List<ItemVersionObject> JobsOpenedInEditor = new ArrayList<ItemVersionObject>();
    List<ItemVersionObject> closedJobs = new ArrayList<ItemVersionObject>();
    boolean hasJobOpenedInEditor = false;
    StringBuilder builder = new StringBuilder();
    for (ItemVersionObject object : checkedObjects) {
        if (RepositoryManager.isOpenedItemInEditor(object.getRepositoryNode().getObject())) {
            hasJobOpenedInEditor = true;
            JobsOpenedInEditor.add(object);
            //$NON-NLS-1$
            builder.append(object.getRepositoryNode().getObject().getLabel() + ", ");
        } else {
            closedJobs.add(object);
        }
    }
    if (builder.length() > 0) {
        builder.delete(builder.length() - 2, builder.length());
    }
    if (hasJobOpenedInEditor) {
        MessageDialog.openWarning(Display.getCurrent().getActiveShell(), //$NON-NLS-1$
        Messages.getString("VersionManagementDialog.WarningTitle2"), //$NON-NLS-1$
        Messages.getString("VersionManagementDialog.openedInEditorMessage", builder.toString()));
        IWorkbenchWindow workBench = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        if (workBench != null) {
            IWorkbenchPage page = workBench.getActivePage();
            IEditorReference[] editorRefs = page.getEditorReferences();
            if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerCoreUIService.class)) {
                IDesignerCoreUIService service = (IDesignerCoreUIService) GlobalServiceRegister.getDefault().getService(IDesignerCoreUIService.class);
                if (service != null) {
                    for (IEditorReference editorRef : editorRefs) {
                        IEditorPart editor = editorRef.getEditor(false);
                        if (editor instanceof IMultiPageTalendEditor) {
                            IProcess2 process = ((IMultiPageTalendEditor) editor).getProcess();
                            String version = null;
                            for (ItemVersionObject object : JobsOpenedInEditor) {
                                if (object.getItem().getProperty().getId().equals(process.getId())) {
                                    version = object.getNewVersion();
                                    break;
                                }
                            }
                            if (version != null) {
                                String jobDefaultVersion = MavenVersionUtils.getDefaultVersion(process.getProperty().getVersion());
                                if (version.equals(jobDefaultVersion)) {
                                    // if default, set null to remove key from property.
                                    version = null;
                                }
                                Command command = service.crateMavenDeploymentValueChangeCommand(process, MavenConstants.NAME_USER_VERSION, version);
                                if (process instanceof IGEFProcess) {
                                    service.executeCommand((IGEFProcess) process, command);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    final IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

        @Override
        public void run(final IProgressMonitor monitor) throws CoreException {
            RepositoryWorkUnit<Object> rwu = new //$NON-NLS-1$
            RepositoryWorkUnit<Object>(//$NON-NLS-1$
            project, //$NON-NLS-1$
            "Update items Maven version") {

                @Override
                protected void run() throws LoginException, PersistenceException {
                    //$NON-NLS-1$
                    monitor.beginTask("Update items Maven version", closedJobs.size());
                    for (ItemVersionObject object : closedJobs) {
                        final Item item = object.getItem();
                        Property itemProperty = item.getProperty();
                        MavenVersionUtils.setItemMavenVersion(itemProperty, object.getNewVersion());
                        monitor.subTask(itemProperty.getLabel());
                        FACTORY.save(project, itemProperty);
                        monitor.worked(1);
                    }
                    try {
                        FACTORY.saveProject(project);
                    } catch (PersistenceException e) {
                        ExceptionHandler.process(e);
                    }
                }
            };
            rwu.setAvoidUnloadResources(true);
            rwu.executeRun();
            monitor.done();
        }
    };
    IRunnableWithProgress iRunnableWithProgress = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            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, monitor);
            } catch (CoreException e) {
                ExceptionHandler.process(e);
            }
        }
    };
    final ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
    try {
        dialog.run(false, false, iRunnableWithProgress);
    } catch (InvocationTargetException | InterruptedException e) {
        ExceptionHandler.process(e);
    }
}
Also used : ArrayList(java.util.ArrayList) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IMultiPageTalendEditor(org.talend.designer.core.IMultiPageTalendEditor) Item(org.talend.core.model.properties.Item) TableItem(org.eclipse.swt.widgets.TableItem) IEditorReference(org.eclipse.ui.IEditorReference) Property(org.talend.core.model.properties.Property) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IDesignerCoreUIService(org.talend.core.ui.services.IDesignerCoreUIService) IEditorPart(org.eclipse.ui.IEditorPart) InvocationTargetException(java.lang.reflect.InvocationTargetException) IGEFProcess(org.talend.core.ui.process.IGEFProcess) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) Command(org.eclipse.gef.commands.Command) IWorkspace(org.eclipse.core.resources.IWorkspace) IProcess2(org.talend.core.model.process.IProcess2) PersistenceException(org.talend.commons.exception.PersistenceException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ItemVersionObject(org.talend.repository.model.ItemVersionObject) ItemVersionObject(org.talend.repository.model.ItemVersionObject)

Example 5 with PersistenceException

use of org.talend.commons.exception.PersistenceException in project tdi-studio-se by Talend.

the class AbstractVersionManagementProjectSettingPage method selectSubjob.

protected void selectSubjob() {
    List<ItemVersionObject> jobList = new ArrayList<ItemVersionObject>();
    for (ItemVersionObject object : checkedObjects) {
        if (MavenVersionUtils.isHasSubjobType(ERepositoryObjectType.getItemType(object.getItem()))) {
            jobList.add(object);
        }
    }
    for (ItemVersionObject object : jobList) {
        if (object.getRepositoryNode() != null) {
            List<Relation> relations = builder.getItemsJobRelatedTo(object.getRepositoryNode().getId(), object.getItem().getProperty().getVersion(), RelationshipItemBuilder.JOB_RELATION);
            for (Relation relation : relations) {
                try {
                    IRepositoryViewObject obj = FACTORY.getLastVersion(relation.getId());
                    if (obj != null) {
                        for (ItemVersionObject obj2 : versionObjects) {
                            if (obj2.getItem() == obj.getProperty().getItem()) {
                                ItemVersionObject relat = obj2;
                                if (!checkedObjects.contains(relat)) {
                                    checkedObjects.add(relat);
                                    checkAllVerSionLatest(checkedObjects, relat);
                                }
                                break;
                            }
                        }
                    }
                } catch (PersistenceException et) {
                    ExceptionHandler.process(et);
                }
            }
        }
    }
    refreshTableItems();
    refreshCheckedTreeView();
}
Also used : Relation(org.talend.core.model.relationship.Relation) ArrayList(java.util.ArrayList) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) ItemVersionObject(org.talend.repository.model.ItemVersionObject)

Aggregations

PersistenceException (org.talend.commons.exception.PersistenceException)571 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)202 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)151 Property (org.talend.core.model.properties.Property)106 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)106 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)91 Item (org.talend.core.model.properties.Item)90 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)85 ArrayList (java.util.ArrayList)80 IComponentConversion (org.talend.core.model.components.conversions.IComponentConversion)78 IComponentFilter (org.talend.core.model.components.filters.IComponentFilter)78 NameComponentFilter (org.talend.core.model.components.filters.NameComponentFilter)77 Project (org.talend.core.model.general.Project)68 ConnectionItem (org.talend.core.model.properties.ConnectionItem)61 ProcessItem (org.talend.core.model.properties.ProcessItem)60 IPath (org.eclipse.core.runtime.IPath)58 IProject (org.eclipse.core.resources.IProject)54 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)52 CoreException (org.eclipse.core.runtime.CoreException)50 Path (org.eclipse.core.runtime.Path)50