Search in sources :

Example 1 with RepositoryWorkUnit

use of org.talend.repository.RepositoryWorkUnit in project tdi-studio-se by Talend.

the class BusinessDiagramEditor method doSave.

@Override
public void doSave(IProgressMonitor progressMonitor) {
    if (repositoryEditorInput != null) {
        final BusinessProcessItem businessProcessItem = (BusinessProcessItem) repositoryEditorInput.getItem();
        IRepositoryService service = CorePlugin.getDefault().getRepositoryService();
        IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
        try {
            repFactory.updateLockStatus();
            // For TDI-23825, if not lock by user try to lock again.
            boolean locked = repFactory.getStatus(businessProcessItem) == ERepositoryStatus.LOCK_BY_USER;
            if (!locked) {
                repFactory.lock(businessProcessItem);
            }
        } catch (Exception e) {
            ExceptionHandler.process(e);
        }
        ERepositoryStatus status = repFactory.getStatus(businessProcessItem);
        if (!status.equals(ERepositoryStatus.LOCK_BY_USER) && !repFactory.getRepositoryContext().isEditableAsReadOnly()) {
            MessageDialog.openWarning(getEditorSite().getShell(), //$NON-NLS-1$
            Messages.getString("BusinessDiagramEditor.canNotSaveTitle"), //$NON-NLS-1$
            Messages.getString("BusinessDiagramEditor.canNotSaveMessage"));
            return;
        }
        super.doSave(progressMonitor);
        DiagramResourceManager diagramResourceManager = new DiagramResourceManager();
        diagramResourceManager.updateFromResource(businessProcessItem, repositoryEditorInput.getFile());
        final IProxyRepositoryFactory factory = service.getProxyRepositoryFactory();
        RepositoryWorkUnit rwu = new RepositoryWorkUnit("save Business") {

            @Override
            protected void run() throws LoginException, PersistenceException {
                ProxyRepositoryFactory.getInstance().save(businessProcessItem);
            }
        };
        rwu.setAvoidUnloadResources(true);
        rwu.setAvoidSvnUpdate(true);
        factory.executeRepositoryWorkUnit(rwu);
        propertyIsDirty = false;
        firePropertyChange(IEditorPart.PROP_DIRTY);
    }
}
Also used : ERepositoryStatus(org.talend.commons.runtime.model.repository.ERepositoryStatus) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) DiagramResourceManager(org.talend.designer.business.diagram.custom.actions.DiagramResourceManager) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) PartInitException(org.eclipse.ui.PartInitException) LoginException(org.talend.commons.exception.LoginException) PersistenceException(org.talend.commons.exception.PersistenceException) IRepositoryService(org.talend.repository.model.IRepositoryService)

Example 2 with RepositoryWorkUnit

use of org.talend.repository.RepositoryWorkUnit in project tdi-studio-se by Talend.

the class ProjectSettingsPreferenceDialog method commiteProjectSettings.

private void commiteProjectSettings() {
    // excute a workUnit to do svn commite
    RepositoryWorkUnit repositoryWorkUnit = new //$NON-NLS-1$
    RepositoryWorkUnit(//$NON-NLS-1$
    ProjectManager.getInstance().getCurrentProject(), //$NON-NLS-1$
    "") {

        @Override
        public void run() throws PersistenceException {
        // do nothing
        }
    };
    repositoryWorkUnit.setAvoidUnloadResources(true);
    CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory().executeRepositoryWorkUnit(repositoryWorkUnit);
}
Also used : RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit)

Example 3 with RepositoryWorkUnit

use of org.talend.repository.RepositoryWorkUnit in project tdi-studio-se by Talend.

the class StandAloneTalendJavaEditor method doSave.

@Override
public void doSave(final IProgressMonitor monitor) {
    IRepositoryService service = CorePlugin.getDefault().getRepositoryService();
    final IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
    try {
        repFactory.lock(item);
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    ERepositoryStatus status = repFactory.getStatus(item);
    if (!status.equals(ERepositoryStatus.LOCK_BY_USER) && !repFactory.getRepositoryContext().isEditableAsReadOnly()) {
        MessageDialog.openWarning(getEditorSite().getShell(), Messages.getString("AbstractMultiPageTalendEditor.canNotSaveTitle"), Messages.getString("AbstractMultiPageTalendEditor.canNotSaveMessage.routine"));
        return;
    }
    EList adapters = item.getProperty().eAdapters();
    adapters.remove(dirtyListener);
    super.doSave(monitor);
    try {
        resetItem();
        ByteArray byteArray = item.getContent();
        byteArray.setInnerContentFromFile(((FileEditorInput) getEditorInput()).getFile());
        final IRunProcessService runProcessService = CorePlugin.getDefault().getRunProcessService();
        runProcessService.buildJavaProject();
        // check syntax error
        addProblems();
        //$NON-NLS-1$
        String name = "Save Routine";
        RepositoryWorkUnit<Object> repositoryWorkUnit = new RepositoryWorkUnit<Object>(name, this) {

            @Override
            protected void run() throws LoginException, PersistenceException {
                refreshJobAndSave(repFactory);
            }
        };
        repositoryWorkUnit.setAvoidSvnUpdate(true);
        repositoryWorkUnit.setAvoidUnloadResources(true);
        repFactory.executeRepositoryWorkUnit(repositoryWorkUnit);
        repositoryWorkUnit.throwPersistenceExceptionIfAny();
    // for bug 11930: Unable to save Routines.* in db project
    // repFactory.save(item);
    // startRefreshJob(repFactory);
    } catch (Exception e) {
        // e.printStackTrace();
        ExceptionHandler.process(e);
    }
}
Also used : ERepositoryStatus(org.talend.commons.runtime.model.repository.ERepositoryStatus) EList(org.eclipse.emf.common.util.EList) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) ByteArray(org.talend.core.model.properties.ByteArray) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) LoginException(org.talend.commons.exception.LoginException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException) IRepositoryService(org.talend.repository.model.IRepositoryService)

Example 4 with RepositoryWorkUnit

use of org.talend.repository.RepositoryWorkUnit in project tdi-studio-se by Talend.

the class NodePart method performRequest.

@Override
public void performRequest(Request req) {
    Node node = (Node) getModel();
    IExternalData oldExternalData = node.getExternalData();
    if (req.getType().equals(RequestConstants.REQ_OPEN)) {
        IExternalNode externalNode = null;
        if (node.isExternalNode()) {
            IElementParameter externalParam = node.getElementParameterFromField(EParameterFieldType.EXTERNAL);
            if (externalParam != null && externalParam.isShow(node.getElementParameters())) {
                externalNode = ExternalUtilities.getExternalNodeReadyToOpen(node);
            }
        }
        IWorkbenchPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
        if (externalNode != null && (part instanceof AbstractMultiPageTalendEditor)) {
            boolean isOriginalNode = false;
            ITestContainerProviderService testContainerService = null;
            if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
                testContainerService = (ITestContainerProviderService) GlobalServiceRegister.getDefault().getService(ITestContainerProviderService.class);
                if (testContainerService != null) {
                    isOriginalNode = testContainerService.isOriginalNode(node);
                    if (isOriginalNode) {
                        testContainerService.renameConnection(node, true);
                    }
                }
            }
            int returnValue = externalNode.open(getViewer().getControl().getShell());
            if (!node.isReadOnly()) {
                if (returnValue == SWT.OK) {
                    Command cmd = new ExternalNodeChangeCommand(node, externalNode, oldExternalData);
                    CommandStack cmdStack = (CommandStack) part.getAdapter(CommandStack.class);
                    cmdStack.execute(cmd);
                } else {
                    externalNode.setExternalData(oldExternalData);
                }
            }
            if (isOriginalNode && (testContainerService != null)) {
                testContainerService.renameConnection(node, false);
            }
        } else {
            // add for feature 13361
            boolean isJoblet = false;
            if (PluginChecker.isJobLetPluginLoaded()) {
                AbstractProcessProvider jobletProcessProvider = AbstractProcessProvider.findProcessProviderFromPID(IComponent.JOBLET_PID);
                final IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
                boolean isAvoidShowJobletAfterDoubleClick = false;
                if (GlobalServiceRegister.getDefault().isServiceRegistered(IComponentsLocalProviderService.class)) {
                    IComponentsLocalProviderService componentService = (IComponentsLocalProviderService) GlobalServiceRegister.getDefault().getService(IComponentsLocalProviderService.class);
                    if (componentService != null) {
                        isAvoidShowJobletAfterDoubleClick = componentService.isAvoidToShowJobletAfterDoubleClick();
                    }
                }
                if (service != null && service.isJobletComponent(node) && !isAvoidShowJobletAfterDoubleClick) {
                    isJoblet = true;
                    String version = (String) node.getPropertyValue(EParameterName.PROCESS_TYPE_VERSION.getName());
                    final Item jobletItem = jobletProcessProvider.getJobletItem(node, version);
                    RepositoryWorkUnit<Object> repositoryWorkUnit = new RepositoryWorkUnit<Object>("", this) {

                        @Override
                        protected void run() throws LoginException, PersistenceException {
                            if (jobletItem != null) {
                                service.openJobletItem((JobletProcessItem) jobletItem);
                            }
                        }
                    };
                    repositoryWorkUnit.setAvoidUnloadResources(true);
                    CoreRuntimePlugin.getInstance().getProxyRepositoryFactory().executeRepositoryWorkUnit(repositoryWorkUnit);
                }
            }
            if (!isJoblet) {
                IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                String processName = (String) node.getPropertyValue(EParameterName.PROCESS_TYPE_PROCESS.getName());
                String version = (String) node.getPropertyValue(EParameterName.PROCESS_TYPE_VERSION.getName());
                boolean isAvoidShowJobAfterDoubleClick = false;
                if (GlobalServiceRegister.getDefault().isServiceRegistered(IComponentsLocalProviderService.class)) {
                    IComponentsLocalProviderService service = (IComponentsLocalProviderService) GlobalServiceRegister.getDefault().getService(IComponentsLocalProviderService.class);
                    if (service != null) {
                        isAvoidShowJobAfterDoubleClick = service.isAvoidToShowJobAfterDoubleClick();
                    }
                }
                // bug 20796
                boolean isSelectUseDynamic = false;
                Object useDynamicJobValue = node.getPropertyValue(EParameterName.USE_DYNAMIC_JOB.getName());
                if (useDynamicJobValue != null && useDynamicJobValue instanceof Boolean) {
                    isSelectUseDynamic = (Boolean) useDynamicJobValue;
                }
                if (processName != null && !"".equals(processName) && !isAvoidShowJobAfterDoubleClick && !isSelectUseDynamic) {
                    //$NON-NLS-1$
                    ItemCacheManager.clearCache();
                    ProcessItem processItem = ItemCacheManager.getProcessItem(processName, version);
                    if (processItem == null) {
                        return;
                    }
                    Property updatedProperty = null;
                    try {
                        updatedProperty = ProxyRepositoryFactory.getInstance().getLastVersion(new Project(ProjectManager.getInstance().getProject(processItem)), processName).getProperty();
                    } catch (PersistenceException e) {
                        CommonExceptionHandler.process(e);
                    }
                    // update the property of the node repository object
                    // node.getObject().setProperty(updatedProperty);
                    processItem = (ProcessItem) updatedProperty.getItem();
                    final ProcessItem item = processItem;
                    RepositoryWorkUnit<Object> repositoryWorkUnit = new RepositoryWorkUnit<Object>("", this) {

                        @Override
                        protected void run() throws LoginException, PersistenceException {
                            try {
                                if (item != null) {
                                    ERepositoryObjectType repObjType = ERepositoryObjectType.getItemType(item);
                                    IJobEditorHandler editorInputFactory = JobEditorHandlerManager.getInstance().extractEditorInputFactory(repObjType.getType());
                                    editorInputFactory.openJobEditor(editorInputFactory.createJobEditorInput(item, true));
                                }
                            } catch (PartInitException e) {
                                MessageBoxExceptionHandler.process(e);
                            }
                        }
                    };
                    repositoryWorkUnit.setAvoidUnloadResources(true);
                    CoreRuntimePlugin.getInstance().getProxyRepositoryFactory().executeRepositoryWorkUnit(repositoryWorkUnit);
                } else {
                    try {
                        // modified for feature 2454.
                        page.showView(ComponentSettingsView.ID);
                    } catch (PartInitException e) {
                        CommonExceptionHandler.process(e);
                    }
                }
            }
        }
    }
    super.performRequest(req);
}
Also used : IExternalNode(org.talend.core.model.process.IExternalNode) INode(org.talend.core.model.process.INode) IGraphicalNode(org.talend.core.ui.process.IGraphicalNode) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) AbstractProcessProvider(org.talend.designer.core.model.process.AbstractProcessProvider) IComponentsLocalProviderService(org.talend.core.ui.services.IComponentsLocalProviderService) Item(org.talend.core.model.properties.Item) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IElementParameter(org.talend.core.model.process.IElementParameter) PartInitException(org.eclipse.ui.PartInitException) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) Property(org.talend.core.model.properties.Property) IExternalNode(org.talend.core.model.process.IExternalNode) CommandStack(org.eclipse.gef.commands.CommandStack) AbstractMultiPageTalendEditor(org.talend.designer.core.ui.AbstractMultiPageTalendEditor) IJobEditorHandler(org.talend.core.ui.editor.IJobEditorHandler) ITestContainerProviderService(org.talend.core.ui.ITestContainerProviderService) Point(org.eclipse.draw2d.geometry.Point) ExternalNodeChangeCommand(org.talend.designer.core.ui.editor.cmd.ExternalNodeChangeCommand) IJobletProviderService(org.talend.core.ui.IJobletProviderService) Project(org.talend.core.model.general.Project) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ExternalNodeChangeCommand(org.talend.designer.core.ui.editor.cmd.ExternalNodeChangeCommand) Command(org.eclipse.gef.commands.Command) PersistenceException(org.talend.commons.exception.PersistenceException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IExternalData(org.talend.core.model.process.IExternalData)

Example 5 with RepositoryWorkUnit

use of org.talend.repository.RepositoryWorkUnit in project tdi-studio-se by Talend.

the class AbstractMultiPageTalendEditor method updateRunJobContext.

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

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

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

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

Aggregations

RepositoryWorkUnit (org.talend.repository.RepositoryWorkUnit)18 PersistenceException (org.talend.commons.exception.PersistenceException)14 CoreException (org.eclipse.core.runtime.CoreException)12 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)9 IWorkspace (org.eclipse.core.resources.IWorkspace)8 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)8 ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)7 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 ArrayList (java.util.ArrayList)6 LoginException (org.talend.commons.exception.LoginException)6 Item (org.talend.core.model.properties.Item)5 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)5 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)4 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)4 Property (org.talend.core.model.properties.Property)4 HashMap (java.util.HashMap)3 List (java.util.List)3 Path (org.eclipse.core.runtime.Path)3 PartInitException (org.eclipse.ui.PartInitException)3