Search in sources :

Example 6 with UIDatabaseConnection

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

the class ConnectionsControllerTest method testEditConnectionGetsWrongName.

private void testEditConnectionGetsWrongName(String wrongName) throws Exception {
    final String dbName = "name";
    List<UIDatabaseConnection> selectedConnection = createSelectedConnectionList(dbName);
    when(connectionsTable.<UIDatabaseConnection>getSelectedItems()).thenReturn(selectedConnection);
    when(repository.getDatabaseID(dbName)).thenReturn(new StringObjectId("existing"));
    when(databaseDialog.open()).thenReturn(wrongName);
    controller.editConnection();
    assertSaveWasNotInvoked();
}
Also used : UIDatabaseConnection(org.pentaho.di.ui.repository.repositoryexplorer.model.UIDatabaseConnection) StringObjectId(org.pentaho.di.repository.StringObjectId)

Example 7 with UIDatabaseConnection

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

the class ConnectionPermissionsController method applyOnObjectOnly.

/**
 * applyOnObjectOnly is called to save acl for a file object only
 *
 * @param roList
 * @param hideDialog
 */
private void applyOnObjectOnly(List<UIDatabaseConnection> roList, boolean hideDialog) {
    try {
        UIDatabaseConnection rd = roList.get(0);
        if (rd instanceof IAclObject) {
            ((IAclObject) rd).setAcls(viewAclsModel);
        } else {
            // $NON-NLS-1$
            throw new IllegalStateException(BaseMessages.getString(PKG, "PermissionsController.NoAclSupport"));
        }
        viewAclsModel.setModelDirty(false);
        // $NON-NLS-1$
        messageBox.setTitle(BaseMessages.getString(PKG, "Dialog.Success"));
        // $NON-NLS-1$
        messageBox.setAcceptLabel(BaseMessages.getString(PKG, "Dialog.Ok"));
        // $NON-NLS-1$
        messageBox.setMessage(BaseMessages.getString(PKG, "PermissionsController.PermissionAppliedSuccessfully"));
        messageBox.open();
    } 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(ade.getLocalizedMessage());
            messageBox.open();
        }
    }
}
Also used : AccessDeniedException(org.pentaho.di.ui.repository.repositoryexplorer.AccessDeniedException) UIDatabaseConnection(org.pentaho.di.ui.repository.repositoryexplorer.model.UIDatabaseConnection) IAclObject(org.pentaho.di.ui.repository.pur.repositoryexplorer.IAclObject)

Example 8 with UIDatabaseConnection

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

the class ConnectionsController method removeConnection.

public void removeConnection() {
    try {
        Collection<UIDatabaseConnection> connections = connectionsTable.getSelectedItems();
        if (connections != null && !connections.isEmpty()) {
            for (Object obj : connections) {
                if (obj != null && obj instanceof UIDatabaseConnection) {
                    UIDatabaseConnection connection = (UIDatabaseConnection) obj;
                    DatabaseMeta databaseMeta = connection.getDatabaseMeta();
                    // Make sure this connection already exists and store its id for updating
                    ObjectId idDatabase = repository.getDatabaseID(databaseMeta.getName());
                    if (idDatabase == null) {
                        MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
                        mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Connection.Delete.DoesNotExists.Message", databaseMeta.getName()));
                        mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Connection.Delete.Title"));
                        mb.open();
                    } else {
                        repository.deleteDatabaseMeta(databaseMeta.getName());
                        reloadLoadedJobsAndTransformations();
                    }
                }
            }
        } else {
            MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
            mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Connection.Edit.NoItemSelected.Message"));
            mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Connection.Delete.Title"));
            mb.open();
        }
    } catch (KettleException e) {
        if (mainController == null || !mainController.handleLostRepository(e)) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryExplorerDialog.Connection.Create.UnexpectedError.Title"), BaseMessages.getString(PKG, "RepositoryExplorerDialog.Connection.Remove.UnexpectedError.Message"), e);
        }
    } finally {
        refreshConnectionList();
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ObjectId(org.pentaho.di.repository.ObjectId) UIDatabaseConnection(org.pentaho.di.ui.repository.repositoryexplorer.model.UIDatabaseConnection) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 9 with UIDatabaseConnection

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

the class ConnectionsController method editConnection.

public void editConnection() {
    try {
        Collection<UIDatabaseConnection> connections = connectionsTable.getSelectedItems();
        if (connections != null && !connections.isEmpty()) {
            // Grab the first item in the list & send it to the database dialog
            DatabaseMeta databaseMeta = ((UIDatabaseConnection) connections.toArray()[0]).getDatabaseMeta();
            // Make sure this connection already exists and store its id for updating
            ObjectId idDatabase = repository.getDatabaseID(databaseMeta.getName());
            if (idDatabase == null) {
                MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
                mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Connection.Edit.DoesNotExists.Message"));
                mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Connection.Edit.DoesNotExists.Title"));
                mb.open();
            } else {
                getDatabaseDialog().setDatabaseMeta(databaseMeta);
                String dbName = getDatabaseDialog().open();
                if (dbName != null) {
                    dbName = dbName.trim();
                    databaseMeta.setName(dbName);
                    databaseMeta.setDisplayName(dbName);
                    if (!dbName.isEmpty()) {
                        ObjectId idRenamed = repository.getDatabaseID(dbName);
                        if (idRenamed == null || idRenamed.equals(idDatabase)) {
                            // renaming to non-existing name or updating the current
                            repository.insertLogEntry(BaseMessages.getString(PKG, "ConnectionsController.Message.UpdatingDatabase", databaseMeta.getName()));
                            repository.save(databaseMeta, Const.VERSION_COMMENT_EDIT_VERSION, null);
                            reloadLoadedJobsAndTransformations();
                        } else {
                            // trying to rename to an existing name - show error dialog
                            showAlreadyExistsMessage();
                        }
                    }
                }
            // We should be able to tell the difference between a cancel and an empty database name
            // 
            // else {
            // MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
            // mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Connection.Edit.MissingName.Message"));
            // mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Connection.Edit.MissingName.Title"));
            // mb.open();
            // }
            }
        } else {
            MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
            mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Connection.Edit.NoItemSelected.Message"));
            mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Connection.Edit.NoItemSelected.Title"));
            mb.open();
        }
    } catch (KettleException e) {
        if (mainController == null || !mainController.handleLostRepository(e)) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryExplorerDialog.Connection.Create.UnexpectedError.Title"), BaseMessages.getString(PKG, "RepositoryExplorerDialog.Connection.Edit.UnexpectedError.Message"), e);
        }
    } finally {
        refreshConnectionList();
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ObjectId(org.pentaho.di.repository.ObjectId) UIDatabaseConnection(org.pentaho.di.ui.repository.repositoryexplorer.model.UIDatabaseConnection) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 10 with UIDatabaseConnection

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

the class ConnectionPermissionsController method createBindings.

protected void createBindings() {
    super.createBindings();
    // $NON-NLS-1$
    connNameLabel = (XulLabel) document.getElementById("conn-name");
    bf.setBindingType(Binding.Type.ONE_WAY);
    BindingConvertor<List<UIDatabaseConnection>, List<UIRepositoryObjectAcl>> securityBindingConverter = new BindingConvertor<List<UIDatabaseConnection>, List<UIRepositoryObjectAcl>>() {

        @Override
        public List<UIRepositoryObjectAcl> sourceToTarget(List<UIDatabaseConnection> ro) {
            if (ro == null) {
                return null;
            }
            if (ro.size() <= 0) {
                return null;
            }
            setSelectedDatabaseConnections(ro);
            if (!hasManageAclAccess()) {
                applyAclButton.setDisabled(true);
                addAclButton.setDisabled(true);
                removeAclButton.setDisabled(true);
                manageAclCheckbox.setDisabled(true);
                deleteCheckbox.setDisabled(true);
                writeCheckbox.setDisabled(true);
                readCheckbox.setDisabled(true);
                viewAclsModel.setHasManageAclAccess(false);
            } else {
                applyAclButton.setDisabled(false);
                addAclButton.setDisabled(false);
                viewAclsModel.setHasManageAclAccess(true);
            }
            viewAclsModel.setRemoveEnabled(false);
            List<UIRepositoryObjectAcl> selectedAclList = Collections.emptyList();
            // we've moved to a connection; need to clear out what the model thinks is selected
            viewAclsModel.setSelectedAclList(selectedAclList);
            permissionsCheckboxHandler.setAllChecked(false);
            UIDatabaseConnection dbconnObject = ro.get(0);
            try {
                if (dbconnObject instanceof IAclObject) {
                    IAclObject aclObj = (IAclObject) dbconnObject;
                    // This is a special case for DB Connections, wipe out the isEnherting flag.
                    // This will cause the model to become "dirty", and prompt the user for changes the first time
                    // let's make sure the default creation behavior of connections is to be that inheritance is
                    // set to false, so this case never presents itself in the wild.
                    aclObj.getAcls(viewAclsModel);
                    if (viewAclsModel.isEntriesInheriting()) {
                        viewAclsModel.setEntriesInheriting(false);
                        aclObj.setAcls(viewAclsModel);
                        viewAclsModel.setModelDirty(false);
                    }
                } else {
                    // $NON-NLS-1$
                    throw new IllegalStateException(BaseMessages.getString(PKG, "PermissionsController.NoAclSupport"));
                }
                connNameLabel.setValue(BaseMessages.getString(PKG, "AclTab.ConnectionPermission", // $NON-NLS-1$
                dbconnObject.getDisplayName()));
                bf.setBindingType(Binding.Type.ONE_WAY);
                // $NON-NLS-1$ //$NON-NLS-2$
                bf.createBinding(viewAclsModel, "acls", userRoleList, "elements");
            } catch (AccessDeniedException 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", dbconnObject.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", dbconnObject.getName(), // $NON-NLS-1$
                    e.getLocalizedMessage()));
                    messageBox.open();
                }
            }
            return viewAclsModel.getAcls();
        }

        @Override
        public List<UIDatabaseConnection> targetToSource(List<UIRepositoryObjectAcl> elements) {
            // One way binding, nothing to do here
            return null;
        }
    };
    // Binding between the selected repository objects and the user role list for acls
    securityBinding = bf.createBinding(connectionsController, "repositoryConnections", userRoleList, "elements", // $NON-NLS-1$ //$NON-NLS-2$
    securityBindingConverter);
    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 : AccessDeniedException(org.pentaho.di.ui.repository.repositoryexplorer.AccessDeniedException) UIDatabaseConnection(org.pentaho.di.ui.repository.repositoryexplorer.model.UIDatabaseConnection) UIRepositoryObjectAcl(org.pentaho.di.ui.repository.pur.repositoryexplorer.model.UIRepositoryObjectAcl) ArrayList(java.util.ArrayList) List(java.util.List) IAclObject(org.pentaho.di.ui.repository.pur.repositoryexplorer.IAclObject) BindingConvertor(org.pentaho.ui.xul.binding.BindingConvertor) AccessDeniedException(org.pentaho.di.ui.repository.repositoryexplorer.AccessDeniedException) ControllerInitializationException(org.pentaho.di.ui.repository.repositoryexplorer.ControllerInitializationException)

Aggregations

UIDatabaseConnection (org.pentaho.di.ui.repository.repositoryexplorer.model.UIDatabaseConnection)11 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)5 StringObjectId (org.pentaho.di.repository.StringObjectId)5 Test (org.junit.Test)4 KettleException (org.pentaho.di.core.exception.KettleException)3 ObjectId (org.pentaho.di.repository.ObjectId)3 ArrayList (java.util.ArrayList)2 MessageBox (org.eclipse.swt.widgets.MessageBox)2 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)2 IAclObject (org.pentaho.di.ui.repository.pur.repositoryexplorer.IAclObject)2 AccessDeniedException (org.pentaho.di.ui.repository.repositoryexplorer.AccessDeniedException)2 List (java.util.List)1 RepositoryElementMetaInterface (org.pentaho.di.repository.RepositoryElementMetaInterface)1 UIRepositoryObjectAcl (org.pentaho.di.ui.repository.pur.repositoryexplorer.model.UIRepositoryObjectAcl)1 ControllerInitializationException (org.pentaho.di.ui.repository.repositoryexplorer.ControllerInitializationException)1 UIObjectCreationException (org.pentaho.di.ui.repository.repositoryexplorer.model.UIObjectCreationException)1 BindingConvertor (org.pentaho.ui.xul.binding.BindingConvertor)1