Search in sources :

Example 1 with UIRepositoryObject

use of org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject in project pentaho-kettle by pentaho.

the class RepositoryLockControllerTest method testBlockLock.

@Test
public void testBlockLock() throws Exception {
    RepositoryLockController repositoryLockController = new RepositoryLockController();
    List<UIRepositoryObject> selectedRepoObjects = new ArrayList<>();
    UIEETransformation lockObject = Mockito.mock(UIEETransformation.class);
    selectedRepoObjects.add(lockObject);
    Mockito.when(lockObject.isLocked()).thenReturn(true);
    ObjectId objectId = Mockito.mock(ObjectId.class);
    Mockito.when(lockObject.getObjectId()).thenReturn(objectId);
    XulMenuitem lockFileMenuItem = Mockito.mock(XulMenuitem.class);
    Field lockFileMenuItemField = repositoryLockController.getClass().getDeclaredField("lockFileMenuItem");
    lockFileMenuItemField.setAccessible(true);
    lockFileMenuItemField.set(repositoryLockController, lockFileMenuItem);
    XulMenuitem deleteFileMenuItem = Mockito.mock(XulMenuitem.class);
    Field deleteFileMenuItemField = repositoryLockController.getClass().getDeclaredField("deleteFileMenuItem");
    deleteFileMenuItemField.setAccessible(true);
    deleteFileMenuItemField.set(repositoryLockController, deleteFileMenuItem);
    XulMenuitem renameFileMenuItem = Mockito.mock(XulMenuitem.class);
    Field renameFileMenuItemField = repositoryLockController.getClass().getDeclaredField("renameFileMenuItem");
    renameFileMenuItemField.setAccessible(true);
    renameFileMenuItemField.set(repositoryLockController, renameFileMenuItem);
    Repository repository = Mockito.mock(Repository.class);
    PurRepositoryMeta repositoryMeta = Mockito.mock(PurRepositoryMeta.class);
    Mockito.when(repository.getRepositoryMeta()).thenReturn(repositoryMeta);
    Field repositoryField = repositoryLockController.getClass().getDeclaredField("repository");
    repositoryField.setAccessible(true);
    repositoryField.set(repositoryLockController, repository);
    ILockService service = Mockito.mock(ILockService.class);
    Mockito.when(service.canUnlockFileById(objectId)).thenReturn(true);
    Field serviceField = repositoryLockController.getClass().getDeclaredField("service");
    serviceField.setAccessible(true);
    serviceField.set(repositoryLockController, service);
    repositoryLockController.setMenuItemEnabledState(selectedRepoObjects);
    Assert.assertFalse(lockFileMenuItem.isDisabled());
    Mockito.verify(lockFileMenuItem).setDisabled(false);
}
Also used : UIRepositoryObject(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject) Field(java.lang.reflect.Field) Repository(org.pentaho.di.repository.Repository) ObjectId(org.pentaho.di.repository.ObjectId) XulMenuitem(org.pentaho.ui.xul.components.XulMenuitem) ILockService(org.pentaho.di.ui.repository.pur.services.ILockService) ArrayList(java.util.ArrayList) PurRepositoryMeta(org.pentaho.di.repository.pur.PurRepositoryMeta) UIEETransformation(org.pentaho.di.ui.repository.pur.repositoryexplorer.model.UIEETransformation) Test(org.junit.Test)

Example 2 with UIRepositoryObject

use of org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject in project pentaho-kettle by pentaho.

the class PermissionsController method createBindings.

protected void createBindings() {
    super.createBindings();
    // $NON-NLS-1$
    fileFolderLabel = (XulLabel) document.getElementById("file-folder-name");
    // $NON-NLS-1$
    aclDeck = (XulDeck) document.getElementById("acl-deck");
    // $NON-NLS-1$
    inheritParentPermissionCheckbox = (XulCheckbox) document.getElementById("inherit-from-parent-permission-checkbox");
    bf.setBindingType(Binding.Type.ONE_WAY);
    BindingConvertor<List<UIRepositoryObject>, List<UIRepositoryObjectAcl>> securityBindingConverter = new BindingConvertor<List<UIRepositoryObject>, List<UIRepositoryObjectAcl>>() {

        @Override
        public List<UIRepositoryObjectAcl> sourceToTarget(List<UIRepositoryObject> ro) {
            if (ro == null) {
                return null;
            }
            if (ro.size() <= 0) {
                return null;
            }
            setSelectedRepositoryObject(ro);
            if (!hasManageAclAccess()) {
                // disable everything
                applyAclButton.setDisabled(true);
                addAclButton.setDisabled(true);
                removeAclButton.setDisabled(true);
                inheritParentPermissionCheckbox.setDisabled(true);
                manageAclCheckbox.setDisabled(true);
                deleteCheckbox.setDisabled(true);
                writeCheckbox.setDisabled(true);
                readCheckbox.setDisabled(true);
                viewAclsModel.setHasManageAclAccess(false);
            } else {
                applyAclButton.setDisabled(false);
                inheritParentPermissionCheckbox.setDisabled(false);
                viewAclsModel.setHasManageAclAccess(true);
            }
            viewAclsModel.setRemoveEnabled(false);
            List<UIRepositoryObjectAcl> selectedAclList = Collections.emptyList();
            // we've moved to a new file/folder; need to clear out what the model thinks is selected
            viewAclsModel.setSelectedAclList(selectedAclList);
            permissionsCheckboxHandler.updateCheckboxes(EnumSet.noneOf(RepositoryFilePermission.class));
            UIRepositoryObject repoObject = ro.get(0);
            try {
                if (repoObject instanceof IAclObject) {
                    ((IAclObject) repoObject).getAcls(viewAclsModel);
                } else {
                    // $NON-NLS-1$
                    throw new IllegalStateException(BaseMessages.getString(PKG, "PermissionsController.NoAclSupport"));
                }
                fileFolderLabel.setValue(// $NON-NLS-1$
                BaseMessages.getString(PKG, "AclTab.UserRolePermission", repoObject.getName()));
                bf.setBindingType(Binding.Type.ONE_WAY);
                // $NON-NLS-1$ //$NON-NLS-2$
                bf.createBinding(viewAclsModel, "acls", userRoleList, "elements");
                updateInheritFromParentPermission();
            } catch (AccessDeniedException ade) {
                if (mainController == null || !mainController.handleLostRepository(ade)) {
                    // $NON-NLS-1$
                    messageBox.setTitle(BaseMessages.getString(PKG, "Dialog.Error"));
                    // $NON-NLS-1$
                    messageBox.setAcceptLabel(BaseMessages.getString(PKG, "Dialog.Ok"));
                    messageBox.setMessage(BaseMessages.getString(PKG, "PermissionsController.UnableToGetAcls", repoObject.getName(), // $NON-NLS-1$
                    ade.getLocalizedMessage()));
                    messageBox.open();
                }
            } catch (Exception e) {
                if (mainController == null || !mainController.handleLostRepository(e)) {
                    // $NON-NLS-1$
                    messageBox.setTitle(BaseMessages.getString(PKG, "Dialog.Error"));
                    // $NON-NLS-1$
                    messageBox.setAcceptLabel(BaseMessages.getString(PKG, "Dialog.Ok"));
                    messageBox.setMessage(BaseMessages.getString(PKG, "PermissionsController.UnableToGetAcls", repoObject.getName(), // $NON-NLS-1$
                    e.getLocalizedMessage()));
                    messageBox.open();
                }
            }
            aclDeck.setSelectedIndex(ACL);
            return viewAclsModel.getAcls();
        }

        @Override
        public List<UIRepositoryObject> targetToSource(List<UIRepositoryObjectAcl> elements) {
            return null;
        }
    };
    // Binding between the selected repository objects and the user role list for acls
    securityBinding = // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(browseController, "repositoryObjects", userRoleList, "elements", securityBindingConverter);
    securityBinding = // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(browseController, "repositoryDirectories", userRoleList, "elements", securityBindingConverter);
    bf.setBindingType(Binding.Type.BI_DIRECTIONAL);
    // Binding Add Remove button to the inherit check box. If the checkbox is checked that disable add remove
    // $NON-NLS-1$  //$NON-NLS-2$
    bf.createBinding(viewAclsModel, "entriesInheriting", inheritParentPermissionCheckbox, "checked");
    // Setting the default Deck to show no permission
    aclDeck.setSelectedIndex(NO_ACL);
    try {
        if (securityBinding != null) {
            securityBinding.fireSourceChanged();
        }
    } catch (Exception e) {
        if (mainController == null || !mainController.handleLostRepository(e)) {
            // convert to runtime exception so it bubbles up through the UI
            throw new RuntimeException(e);
        }
    }
}
Also used : UIRepositoryObject(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject) AccessDeniedException(org.pentaho.di.ui.repository.repositoryexplorer.AccessDeniedException) UIRepositoryObjectAcl(org.pentaho.di.ui.repository.pur.repositoryexplorer.model.UIRepositoryObjectAcl) RepositoryFilePermission(org.pentaho.platform.api.repository2.unified.RepositoryFilePermission) ArrayList(java.util.ArrayList) List(java.util.List) IAclObject(org.pentaho.di.ui.repository.pur.repositoryexplorer.IAclObject) BindingConvertor(org.pentaho.ui.xul.binding.BindingConvertor) KettleException(org.pentaho.di.core.exception.KettleException) AccessDeniedException(org.pentaho.di.ui.repository.repositoryexplorer.AccessDeniedException) ControllerInitializationException(org.pentaho.di.ui.repository.repositoryexplorer.ControllerInitializationException)

Example 3 with UIRepositoryObject

use of org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject in project pentaho-kettle by pentaho.

the class PermissionsController method updateInheritFromParentPermission.

/*
   * public void closeApplyAclConfirmationDialog() { applyAclConfirmationDialog.hide(); }
   */
/*
   * If the user check or unchecks the inherit from parent checkbox, this method is called.
   */
public void updateInheritFromParentPermission() throws AccessDeniedException {
    viewAclsModel.setEntriesInheriting(inheritParentPermissionCheckbox.isChecked());
    if (inheritParentPermissionCheckbox.isChecked()) {
        addAclButton.setDisabled(true);
        UIRepositoryObject ro = repoObject.get(0);
        if (ro instanceof IAclObject) {
            // force inherit to true to get effective ACLs before apply...
            ((IAclObject) ro).clearAcl();
            ((IAclObject) ro).getAcls(viewAclsModel, true);
        }
        permissionsCheckboxHandler.updateCheckboxes(EnumSet.noneOf(RepositoryFilePermission.class));
    } else {
        addAclButton.setDisabled(!hasManageAclAccess());
        permissionsCheckboxHandler.processCheckboxes();
    }
}
Also used : UIRepositoryObject(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject) RepositoryFilePermission(org.pentaho.platform.api.repository2.unified.RepositoryFilePermission) IAclObject(org.pentaho.di.ui.repository.pur.repositoryexplorer.IAclObject)

Example 4 with UIRepositoryObject

use of org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject in project pentaho-kettle by pentaho.

the class RepositoryLockController method viewLockNote.

public void viewLockNote() throws Exception {
    List<UIRepositoryObject> selectedRepoObjects = browseController.getSelectedFileItems();
    if (selectedRepoObjects.size() > 0 && selectedRepoObjects.get(0) instanceof UIRepositoryContent) {
        final UIRepositoryContent contentToLock = (UIRepositoryContent) selectedRepoObjects.get(0);
        // $NON-NLS-1$
        XulMessageBox msgBox = (XulMessageBox) document.createElement("messagebox");
        // $NON-NLS-1$
        msgBox.setTitle(BaseMessages.getString(PKG, "PurRepository.LockNote.Title"));
        msgBox.setMessage(((ILockObject) contentToLock).getLockMessage());
        msgBox.open();
    }
}
Also used : UIRepositoryObject(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject) XulMessageBox(org.pentaho.ui.xul.components.XulMessageBox) UIRepositoryContent(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryContent)

Example 5 with UIRepositoryObject

use of org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject in project pentaho-kettle by pentaho.

the class RepositoryLockController method onDragFromLocalTable.

// Object being dragged from the file listing table
public void onDragFromLocalTable(DropEvent event) {
    try {
        Collection<Object> selectedRepoObjects = fileTable.getSelectedItems();
        if (selectedRepoObjects.size() > 0) {
            for (Object ro : selectedRepoObjects) {
                if (ro instanceof UIRepositoryObject && ro instanceof ILockObject) {
                    final UIRepositoryContent contentToLock = (UIRepositoryContent) ro;
                    if (((ILockObject) contentToLock).isLocked()) {
                        // Content is locked, not allowed to move
                        event.setAccepted(false);
                        // $NON-NLS-1$
                        messageBox.setTitle(BaseMessages.getString(PKG, "Dialog.Error"));
                        // $NON-NLS-1$
                        messageBox.setAcceptLabel(BaseMessages.getString(PKG, "Dialog.Ok"));
                        // $NON-NLS-1$
                        messageBox.setMessage(BaseMessages.getString(PKG, "BrowseController.MoveNotAllowed"));
                        messageBox.open();
                        break;
                    } else {
                        // Content is not locked, check default permissions
                        browseController.onDragFromLocalTable(event);
                    }
                } else if (ro instanceof UIRepositoryDirectory && repositoryDirectoryHasLockedObject(event, (UIRepositoryDirectory) ro)) {
                    // locked content nested in this directory. move not allowed.
                    event.setAccepted(false);
                    break;
                }
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : UIRepositoryObject(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject) UIRepositoryDirectory(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryDirectory) ILockObject(org.pentaho.di.ui.repository.pur.repositoryexplorer.ILockObject) UIRepositoryContent(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryContent) ILockObject(org.pentaho.di.ui.repository.pur.repositoryexplorer.ILockObject) UIRepositoryObject(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject) XulException(org.pentaho.ui.xul.XulException) KettleException(org.pentaho.di.core.exception.KettleException) ControllerInitializationException(org.pentaho.di.ui.repository.repositoryexplorer.ControllerInitializationException)

Aggregations

UIRepositoryObject (org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject)16 KettleException (org.pentaho.di.core.exception.KettleException)8 ControllerInitializationException (org.pentaho.di.ui.repository.repositoryexplorer.ControllerInitializationException)8 UIRepositoryDirectory (org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryDirectory)8 ArrayList (java.util.ArrayList)7 UIRepositoryContent (org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryContent)7 XulException (org.pentaho.ui.xul.XulException)7 List (java.util.List)4 ILockObject (org.pentaho.di.ui.repository.pur.repositoryexplorer.ILockObject)4 XulComponent (org.pentaho.ui.xul.XulComponent)3 BindingConvertor (org.pentaho.ui.xul.binding.BindingConvertor)3 Repository (org.pentaho.di.repository.Repository)2 IAclObject (org.pentaho.di.ui.repository.pur.repositoryexplorer.IAclObject)2 IRevisionObject (org.pentaho.di.ui.repository.pur.repositoryexplorer.IRevisionObject)2 UIObjectCreationException (org.pentaho.di.ui.repository.repositoryexplorer.model.UIObjectCreationException)2 RepositoryFilePermission (org.pentaho.platform.api.repository2.unified.RepositoryFilePermission)2 XulMenuitem (org.pentaho.ui.xul.components.XulMenuitem)2 XulPromptBox (org.pentaho.ui.xul.components.XulPromptBox)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1