Search in sources :

Example 6 with ERepositoryStatus

use of org.talend.commons.runtime.model.repository.ERepositoryStatus in project tdi-studio-se by Talend.

the class SetupProcessDependenciesRoutinesAction method doRun.

@Override
protected void doRun() {
    ISelection selection = getSelection();
    Object obj = ((IStructuredSelection) selection).getFirstElement();
    if (obj == null) {
        return;
    }
    RepositoryNode node = (RepositoryNode) obj;
    boolean readonly = false;
    IRepositoryService service = DesignerPlugin.getDefault().getRepositoryService();
    IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
    ERepositoryStatus status = repFactory.getStatus(node.getObject());
    if (!repFactory.isPotentiallyEditable(node.getObject()) || status == ERepositoryStatus.LOCK_BY_OTHER || status == ERepositoryStatus.LOCK_BY_USER) {
        readonly = true;
    }
    Item item = node.getObject().getProperty().getItem();
    if (item instanceof ProcessItem) {
        ProcessItem processItem = (ProcessItem) item;
        ProcessType process = processItem.getProcess();
        SetupProcessDependenciesRoutinesDialog dialog = new SetupProcessDependenciesRoutinesDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), process, readonly);
        if (dialog.open() == Window.OK && !readonly) {
            process.getParameters().getRoutinesParameter().clear();
            createRoutinesDependencies(process, dialog.getSystemRoutines());
            createRoutinesDependencies(process, dialog.getUserRoutines());
            try {
                CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory().save(processItem);
                RelationshipItemBuilder.getInstance().addOrUpdateItem(processItem);
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
            }
        }
    } else if (item instanceof JobletProcessItem) {
        JobletProcessItem jobProcessItem = (JobletProcessItem) item;
        ProcessType process = jobProcessItem.getJobletProcess();
        SetupProcessDependenciesRoutinesDialog dialog = new SetupProcessDependenciesRoutinesDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), process, readonly);
        if (dialog.open() == Window.OK && !readonly) {
            process.getParameters().getRoutinesParameter().clear();
            createRoutinesDependencies(process, dialog.getSystemRoutines());
            createRoutinesDependencies(process, dialog.getUserRoutines());
            try {
                CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory().save(jobProcessItem);
                IJobletProviderService jobletService = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
                if (jobletService != null) {
                    jobletService.loadComponentsFromProviders();
                }
                RelationshipItemBuilder.getInstance().addOrUpdateItem(jobProcessItem);
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
            }
        }
    }
}
Also used : ERepositoryStatus(org.talend.commons.runtime.model.repository.ERepositoryStatus) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryService(org.talend.repository.model.IRepositoryService) IJobletProviderService(org.talend.core.ui.IJobletProviderService) ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) SetupProcessDependenciesRoutinesDialog(org.talend.designer.core.ui.routine.SetupProcessDependenciesRoutinesDialog) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ISelection(org.eclipse.jface.viewers.ISelection) PersistenceException(org.talend.commons.exception.PersistenceException) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 7 with ERepositoryStatus

use of org.talend.commons.runtime.model.repository.ERepositoryStatus in project tdi-studio-se by Talend.

the class JobletUtil method needReadOnlyJoblet.

public boolean needReadOnlyJoblet(JobletProcessItem jobletItem) {
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IEditorPart[] editors = page.getEditors();
    for (IEditorPart editor : editors) {
        if (editor instanceof AbstractMultiPageTalendEditor) {
            List<? extends INode> nodeList = ((AbstractMultiPageTalendEditor) editor).getProcess().getGraphicalNodes();
            for (INode node : nodeList) {
                if (((Node) node).isJoblet() && jobletItem.getProperty() != null) {
                    if (jobletItem.getProperty().getId().equals(node.getComponent().getProcess().getId())) {
                        boolean haveLock = jobletItem.getState().isLocked();
                        boolean isSvn = false;
                        ISVNProviderService service = null;
                        if (PluginChecker.isSVNProviderPluginLoaded()) {
                            service = (ISVNProviderService) GlobalServiceRegister.getDefault().getService(ISVNProviderService.class);
                        }
                        if (service != null && service.isProjectInSvnMode()) {
                            isSvn = service.isProjectInSvnMode();
                        }
                        if (isSvn) {
                            IProxyRepositoryService proxyService = (IProxyRepositoryService) GlobalServiceRegister.getDefault().getService(IProxyRepositoryService.class);
                            IProxyRepositoryFactory factory = proxyService.getProxyRepositoryFactory();
                            ERepositoryStatus repositoryStatus = factory.getStatus(jobletItem);
                            if (repositoryStatus == ERepositoryStatus.LOCK_BY_USER) {
                                haveLock = true;
                            }
                        }
                        if (haveLock) {
                            return true;
                        }
                    }
                }
            }
        }
    }
    return false;
}
Also used : INode(org.talend.core.model.process.INode) ERepositoryStatus(org.talend.commons.runtime.model.repository.ERepositoryStatus) AbstractMultiPageTalendEditor(org.talend.designer.core.ui.AbstractMultiPageTalendEditor) IProxyRepositoryService(org.talend.repository.model.IProxyRepositoryService) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ISVNProviderService(org.talend.core.services.ISVNProviderService) IEditorPart(org.eclipse.ui.IEditorPart) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 8 with ERepositoryStatus

use of org.talend.commons.runtime.model.repository.ERepositoryStatus 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 9 with ERepositoryStatus

use of org.talend.commons.runtime.model.repository.ERepositoryStatus 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 10 with ERepositoryStatus

use of org.talend.commons.runtime.model.repository.ERepositoryStatus in project tmdm-studio-se by Talend.

the class RepositoryResourceUtil method isLockedAndEdited.

public static boolean isLockedAndEdited(IRepositoryViewObject viewObj) {
    IProxyRepositoryFactory factory = CoreRuntimePlugin.getInstance().getProxyRepositoryFactory();
    ERepositoryStatus status = factory.getStatus(viewObj);
    if (status == ERepositoryStatus.LOCK_BY_OTHER) {
        return true;
    } else if (status == ERepositoryStatus.LOCK_BY_USER) {
        IEditorReference openRef = RepositoryResourceUtil.isOpenedInEditor(viewObj);
        return openRef != null;
    }
    return false;
}
Also used : ERepositoryStatus(org.talend.commons.runtime.model.repository.ERepositoryStatus) IEditorReference(org.eclipse.ui.IEditorReference) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Aggregations

ERepositoryStatus (org.talend.commons.runtime.model.repository.ERepositoryStatus)34 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)21 PersistenceException (org.talend.commons.exception.PersistenceException)14 Item (org.talend.core.model.properties.Item)12 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)7 CoreException (org.eclipse.core.runtime.CoreException)7 LoginException (org.talend.commons.exception.LoginException)7 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)7 RepositoryNode (org.talend.repository.model.RepositoryNode)7 JobletProcessItem (org.talend.core.model.properties.JobletProcessItem)6 ProcessItem (org.talend.core.model.properties.ProcessItem)6 IOException (java.io.IOException)5 PartInitException (org.eclipse.ui.PartInitException)5 IRepositoryService (org.talend.repository.model.IRepositoryService)5 ArrayList (java.util.ArrayList)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 IProcess2 (org.talend.core.model.process.IProcess2)3