Search in sources :

Example 1 with IRepositoryService

use of org.talend.repository.model.IRepositoryService 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 IRepositoryService

use of org.talend.repository.model.IRepositoryService 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 3 with IRepositoryService

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

the class ContextRepositoryReviewDialog method okPressed.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.repository.ui.dialog.RepositoryReviewDialog#okPressed()
     */
@SuppressWarnings("unchecked")
@Override
protected void okPressed() {
    if (params == null || params.isEmpty()) {
        super.okPressed();
    }
    ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    if (createNewButton.getSelection()) {
        if (nameInvalid(contextNameText)) {
            //$NON-NLS-1$
            MessageDialog.openError(getShell(), "Context", msg);
            return;
        } else {
            item = PropertiesFactory.eINSTANCE.createContextItem();
            if (item == null) {
                return;
            }
            Property createProperty = PropertiesFactory.eINSTANCE.createProperty();
            createProperty.setAuthor(((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getUser());
            createProperty.setVersion(VersionUtils.DEFAULT_VERSION);
            //$NON-NLS-1$
            createProperty.setStatusCode("");
            try {
                String nextId = factory.getNextId();
                createProperty.setId(nextId);
                item.setProperty(createProperty);
                for (IContext context : contextManager.getListContext()) {
                    ContextType contextType = TalendFileFactory.eINSTANCE.createContextType();
                    contextType.setName(context.getName());
                    item.getContext().add(contextType);
                }
                item.setDefaultContext(contextManager.getDefaultContext().getName());
                item.getProperty().setLabel(contextNameText.getText().trim());
                IRepositoryService service = (IRepositoryService) GlobalServiceRegister.getDefault().getService(IRepositoryService.class);
                IProxyRepositoryFactory repositoryFactory = service.getProxyRepositoryFactory();
                try {
                    boolean nameAvaliabe = repositoryFactory.isNameAvailable(createProperty.getItem(), contextNameText.getText());
                    if (!nameAvaliabe) {
                        MessageDialog.openError(getShell(), "Context", //$NON-NLS-1$
                        Messages.getString(//$NON-NLS-1$
                        "PropertiesWizardPage.ItemExistsError"));
                        return;
                    }
                } catch (PersistenceException e) {
                    ExceptionHandler.process(e);
                    super.okPressed();
                }
                //$NON-NLS-1$
                factory.create(item, new Path(""));
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
                super.okPressed();
            }
        }
    } else {
        IStructuredSelection selection = (IStructuredSelection) getRepositoryTreeViewer().getSelection();
        RepositoryNode context = (RepositoryNode) selection.getFirstElement();
        try {
            // get the item from file
            IRepositoryViewObject contextObj = factory.getLastVersion(context.getObject().getProperty().getId());
            item = (ContextItem) contextObj.getProperty().getItem();
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
            super.okPressed();
        }
    }
    super.okPressed();
}
Also used : Path(org.eclipse.core.runtime.Path) ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) IContext(org.talend.core.model.process.IContext) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryService(org.talend.repository.model.IRepositoryService) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) PersistenceException(org.talend.commons.exception.PersistenceException) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 4 with IRepositoryService

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

the class StandAloneTalendJavaEditor method doSetInput.

@Override
public void doSetInput(IEditorInput input) throws CoreException {
    // Lock the process :
    IRepositoryService service = DesignerPlugin.getDefault().getRepositoryService();
    IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
    if (input instanceof RepositoryEditorInput) {
        rEditorInput = (RepositoryEditorInput) input;
    } else {
        FileEditorInput fileInput = (FileEditorInput) input;
        rEditorInput = new RepositoryEditorInput(fileInput.getFile(), rEditorInput.getItem());
    }
    if (rEditorInput.getRepositoryNode() == null) {
        // retrieve node
        rEditorInput.setRepositoryNode(null);
    }
    try {
        // see bug 1321
        item = (FileItem) rEditorInput.getItem();
        if (!rEditorInput.isReadOnly()) {
            if (getRepositoryFactory().getStatus(item).isPotentiallyEditable()) {
                item.getProperty().eAdapters().add(dirtyListener);
                repFactory.lock(item);
            }
        } else {
            rEditorInput.getFile().setReadOnly(true);
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    rEditorInput.getFile().refreshLocal(IResource.DEPTH_ONE, null);
    super.doSetInput(rEditorInput);
    setName();
    // only for sql template
    if (item instanceof SQLPatternItem) {
        Workspace ws = (Workspace) ResourcesPlugin.getWorkspace();
        ws.broadcastBuildEvent(item, IResourceChangeEvent.POST_CHANGE, 1);
    }
}
Also used : RepositoryEditorInput(org.talend.core.repository.ui.editor.RepositoryEditorInput) FileEditorInput(org.eclipse.ui.part.FileEditorInput) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) 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) Workspace(org.eclipse.core.internal.resources.Workspace) IWorkspace(org.eclipse.core.resources.IWorkspace)

Example 5 with IRepositoryService

use of org.talend.repository.model.IRepositoryService 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)

Aggregations

IRepositoryService (org.talend.repository.model.IRepositoryService)27 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)21 PersistenceException (org.talend.commons.exception.PersistenceException)19 Item (org.talend.core.model.properties.Item)11 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)9 PartInitException (org.eclipse.ui.PartInitException)8 CoreException (org.eclipse.core.runtime.CoreException)7 Property (org.talend.core.model.properties.Property)7 LoginException (org.talend.commons.exception.LoginException)6 ProcessItem (org.talend.core.model.properties.ProcessItem)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 IPath (org.eclipse.core.runtime.IPath)5 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 ERepositoryStatus (org.talend.commons.runtime.model.repository.ERepositoryStatus)5 ITalendProcessJavaProject (org.talend.core.runtime.process.ITalendProcessJavaProject)5 IFile (org.eclipse.core.resources.IFile)4 JobletProcessItem (org.talend.core.model.properties.JobletProcessItem)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 IProject (org.eclipse.core.resources.IProject)3