Search in sources :

Example 1 with UnifiedRepositoryLockService

use of org.pentaho.di.repository.pur.UnifiedRepositoryLockService in project pentaho-kettle by pentaho.

the class SpoonLockController method init.

protected void init() {
    try {
        if ((Spoon.getInstance().getRepository() != null) && (Spoon.getInstance().getRepository().hasService(IAbsSecurityProvider.class))) {
            IAbsSecurityProvider securityService = (IAbsSecurityProvider) Spoon.getInstance().getRepository().getService(IAbsSecurityProvider.class);
            setCreateAllowed(allowedActionsContains(securityService, IAbsSecurityProvider.CREATE_CONTENT_ACTION));
        }
        shell = (((Spoon) SpoonFactory.getInstance()).getShell());
        XulDomContainer container = getXulDomContainer();
        bindingFactory = new DefaultBindingFactory();
        bindingFactory.setDocument(container.getDocumentRoot());
        bindingFactory.setBindingType(Type.ONE_WAY);
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        bindingFactory.createBinding(this, "activeMetaUnlocked", "lock-context-locknotes", "disabled");
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        bindingFactory.createBinding(this, "lockingNotAllowed", "lock-context-lock", "disabled");
        // Try transformation
        if (container.getEventHandlers().containsKey("transgraph")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            workingMeta = ((TransGraph) container.getEventHandler("transgraph")).getMeta();
        } else if (container.getEventHandlers().containsKey("jobgraph")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            workingMeta = ((JobGraph) container.getEventHandler("jobgraph")).getMeta();
        }
        RepositoryLock repoLock = fetchRepositoryLock(workingMeta);
        if (repoLock != null) {
            // $NON-NLS-1$
            XulMenuitem lockMenuItem = (XulMenuitem) container.getDocumentRoot().getElementById("lock-context-lock");
            lockMenuItem.setSelected(true);
            // Permit locking/unlocking if the user owns the lock
            if (Spoon.getInstance().getRepository() instanceof PurRepository) {
                setLockingAllowed(new UnifiedRepositoryLockService(((PurRepository) Spoon.getInstance().getRepository()).getUnderlyingRepository()).canUnlockFileById(workingMeta.getObjectId()));
            } else {
                setLockingAllowed(repoLock.getLogin().equalsIgnoreCase(Spoon.getInstance().getRepository().getUserInfo().getLogin()));
            }
        } else {
            setLockingAllowed(true);
        }
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        firePropertyChange("activeMetaUnlocked", null, repoLock == null);
    } catch (Exception e) {
        // $NON-NLS-1$
        log.error(BaseMessages.getString(PKG, "LockController.NoLockingSupport"), e);
        new ErrorDialog(((Spoon) SpoonFactory.getInstance()).getShell(), BaseMessages.getString(PKG, "Dialog.Error"), e.getMessage(), // $NON-NLS-1$
        e);
    }
}
Also used : IAbsSecurityProvider(org.pentaho.di.ui.repository.pur.services.IAbsSecurityProvider) DefaultBindingFactory(org.pentaho.ui.xul.binding.DefaultBindingFactory) JobGraph(org.pentaho.di.ui.spoon.job.JobGraph) XulMenuitem(org.pentaho.ui.xul.components.XulMenuitem) PurRepository(org.pentaho.di.repository.pur.PurRepository) UnifiedRepositoryLockService(org.pentaho.di.repository.pur.UnifiedRepositoryLockService) Spoon(org.pentaho.di.ui.spoon.Spoon) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RepositoryLock(org.pentaho.di.repository.pur.model.RepositoryLock) XulDomContainer(org.pentaho.ui.xul.XulDomContainer) XulException(org.pentaho.ui.xul.XulException) KettleException(org.pentaho.di.core.exception.KettleException)

Aggregations

KettleException (org.pentaho.di.core.exception.KettleException)1 PurRepository (org.pentaho.di.repository.pur.PurRepository)1 UnifiedRepositoryLockService (org.pentaho.di.repository.pur.UnifiedRepositoryLockService)1 RepositoryLock (org.pentaho.di.repository.pur.model.RepositoryLock)1 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)1 IAbsSecurityProvider (org.pentaho.di.ui.repository.pur.services.IAbsSecurityProvider)1 Spoon (org.pentaho.di.ui.spoon.Spoon)1 JobGraph (org.pentaho.di.ui.spoon.job.JobGraph)1 XulDomContainer (org.pentaho.ui.xul.XulDomContainer)1 XulException (org.pentaho.ui.xul.XulException)1 DefaultBindingFactory (org.pentaho.ui.xul.binding.DefaultBindingFactory)1 XulMenuitem (org.pentaho.ui.xul.components.XulMenuitem)1