Search in sources :

Example 1 with DuplicateDatasourceException

use of org.pentaho.platform.api.repository.datasource.DuplicateDatasourceException in project data-access by pentaho.

the class ConnectionServiceImpl method addConnection.

public boolean addConnection(IDatabaseConnection connection) throws ConnectionServiceException {
    ensureDataAccessPermission();
    try {
        if (connection.getAccessType() != null && connection.getAccessType().equals(DatabaseAccessType.JNDI)) {
            IPentahoConnection pentahoConnection = null;
            pentahoConnection = PentahoConnectionFactory.getConnection(IPentahoConnection.SQL_DATASOURCE, connection.getDatabaseName(), null, this);
            try {
                connection.setUsername((((SQLConnection) pentahoConnection).getNativeConnection().getMetaData().getUserName()));
            } catch (Exception e) {
                logger.warn("Unable to get username from datasource: " + connection.getName());
            }
        }
        datasourceMgmtSvc.createDatasource(connection);
        return true;
    } catch (DuplicateDatasourceException duplicateDatasourceException) {
        String message = Messages.getErrorString(// $NON-NLS-1$
        "ConnectionServiceImpl.ERROR_0004_UNABLE_TO_ADD_CONNECTION", connection.getName(), duplicateDatasourceException.getLocalizedMessage());
        logger.error(message);
        throw new ConnectionServiceException(Response.SC_CONFLICT, message, duplicateDatasourceException);
    } catch (Exception e) {
        String message = Messages.getErrorString(// $NON-NLS-1$
        "ConnectionServiceImpl.ERROR_0004_UNABLE_TO_ADD_CONNECTION", connection.getName(), e.getLocalizedMessage());
        logger.error(message);
        throw new ConnectionServiceException(message, e);
    }
}
Also used : IPentahoConnection(org.pentaho.commons.connection.IPentahoConnection) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) DuplicateDatasourceException(org.pentaho.platform.api.repository.datasource.DuplicateDatasourceException) SQLConnection(org.pentaho.platform.plugin.services.connections.sql.SQLConnection) DatabaseDialectException(org.pentaho.database.DatabaseDialectException) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) DuplicateDatasourceException(org.pentaho.platform.api.repository.datasource.DuplicateDatasourceException) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException) NonExistingDatasourceException(org.pentaho.platform.api.repository.datasource.NonExistingDatasourceException)

Example 2 with DuplicateDatasourceException

use of org.pentaho.platform.api.repository.datasource.DuplicateDatasourceException in project pentaho-platform by pentaho.

the class JcrBackedDatasourceMgmtService method createDatasource.

public String createDatasource(IDatabaseConnection databaseConnection) throws DuplicateDatasourceException, DatasourceMgmtServiceException {
    try {
        // IPasswordService passwordService = PentahoSystem.get(IPasswordService.class,
        // PentahoSessionHolder.getSession());
        // databaseMeta.setPassword(passwordService.encrypt(databaseMeta.getPassword()));
        RepositoryFile file = new RepositoryFile.Builder(RepositoryFilenameUtils.escape(databaseConnection.getName() + RepositoryObjectType.DATABASE.getExtension(), cachedReservedChars)).title(RepositoryFile.DEFAULT_LOCALE, databaseConnection.getName()).versioned(true).build();
        file = repository.createFile(getDatabaseParentFolderId(), file, new NodeRepositoryFileData(databaseHelper.databaseConnectionToDataNode(databaseConnection)), null);
        if (file != null && file.getId() != null) {
            return file.getId().toString();
        } else {
            return null;
        }
    // } catch(PasswordServiceException pse) {
    // throw new DatasourceMgmtServiceException(Messages.getInstance().getErrorString(
    // "DatasourceMgmtService.ERROR_0007_UNABLE_TO_ENCRYPT_PASSWORD"), pse ); //$NON-NLS-1$
    } catch (UnifiedRepositoryException ure) {
        if (ure.getCause().toString().contains("ItemExistsException")) {
            throw new DuplicateDatasourceException();
        }
        throw new DatasourceMgmtServiceException(Messages.getInstance().getErrorString("DatasourceMgmtService.ERROR_0001_UNABLE_TO_CREATE_DATASOURCE", databaseConnection.getName(), ure.getLocalizedMessage()), // $NON-NLS-1$
        ure);
    }
}
Also used : NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) DuplicateDatasourceException(org.pentaho.platform.api.repository.datasource.DuplicateDatasourceException) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)

Aggregations

DatasourceMgmtServiceException (org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)2 DuplicateDatasourceException (org.pentaho.platform.api.repository.datasource.DuplicateDatasourceException)2 IPentahoConnection (org.pentaho.commons.connection.IPentahoConnection)1 DatabaseDialectException (org.pentaho.database.DatabaseDialectException)1 NonExistingDatasourceException (org.pentaho.platform.api.repository.datasource.NonExistingDatasourceException)1 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)1 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)1 NodeRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)1 ConnectionServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException)1 SQLConnection (org.pentaho.platform.plugin.services.connections.sql.SQLConnection)1