Search in sources :

Example 6 with ConnectionServiceException

use of org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException in project data-access by pentaho.

the class ConnectionService method getConnectionIdByNameWithResponse.

/**
 * Returns a response with id of a database connection
 *
 * @param name
 *          String representing the name of the database to search
 * @return Response based on the string value of the connection id
 *
 * @throws ConnectionServiceException
 */
@GET
@Path("/getid")
@Produces({ APPLICATION_JSON })
@Facet(name = "Unsupported")
public Response getConnectionIdByNameWithResponse(@QueryParam("name") String name) throws ConnectionServiceException {
    IDatabaseConnection conn = null;
    Response response;
    try {
        conn = connectionService.getConnectionByName(name);
        if (conn != null) {
            response = Response.ok().entity(conn.getId()).build();
        } else {
            response = Response.notModified().build();
        }
    } catch (Exception ex) {
        response = Response.serverError().entity(ex.getMessage()).build();
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Facet(org.codehaus.enunciate.Facet)

Example 7 with ConnectionServiceException

use of org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException in project data-access by pentaho.

the class ConnectionService method getConnectionByNameWithResponse.

/**
 * this is a method to return a response object with an error message use getEntity(Connection.class) and getStatus()
 * to determine success
 */
@GET
@Path("/getresponse")
@Produces({ APPLICATION_JSON })
@Facet(name = "Unsupported")
public Response getConnectionByNameWithResponse(@QueryParam("name") String name) throws ConnectionServiceException {
    IDatabaseConnection conn = null;
    Response response;
    try {
        conn = connectionService.getConnectionByName(name);
        sanitizer.unsanitizeConnectionParameters(conn);
        hidePassword(conn);
        response = Response.ok().entity(conn).build();
    } catch (Exception ex) {
        response = Response.serverError().entity(ex.getMessage()).build();
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Facet(org.codehaus.enunciate.Facet)

Example 8 with ConnectionServiceException

use of org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException in project data-access by pentaho.

the class ConnectionServiceImpl method deleteConnection.

public boolean deleteConnection(String name) throws ConnectionServiceException {
    ensureDataAccessPermission();
    name = sanitizer.safeEscapeHtml(name);
    try {
        datasourceMgmtSvc.deleteDatasourceByName(name);
        clearDatasource(name);
        return true;
    } catch (NonExistingDatasourceException nonExistingDatasourceException) {
        String message = // $NON-NLS-1$
        Messages.getErrorString(// $NON-NLS-1$
        "ConnectionServiceImpl.ERROR_0006_UNABLE_TO_DELETE_CONNECTION", name, nonExistingDatasourceException.getLocalizedMessage());
        throw new ConnectionServiceException(Response.SC_NOT_FOUND, message, nonExistingDatasourceException);
    } catch (Exception e) {
        String message = // $NON-NLS-1$
        Messages.getErrorString(// $NON-NLS-1$
        "ConnectionServiceImpl.ERROR_0006_UNABLE_TO_DELETE_CONNECTION", name, e.getLocalizedMessage());
        logger.error(message);
        throw new ConnectionServiceException(message, e);
    }
}
Also used : NonExistingDatasourceException(org.pentaho.platform.api.repository.datasource.NonExistingDatasourceException) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) 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 9 with ConnectionServiceException

use of org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException in project data-access by pentaho.

the class ConnectionServiceImpl method updateConnection.

public boolean updateConnection(IDatabaseConnection connection) throws ConnectionServiceException {
    ensureDataAccessPermission();
    try {
        connection.setPassword(getConnectionPassword(connection.getName(), connection.getPassword()));
        datasourceMgmtSvc.updateDatasourceByName(connection.getName(), connection);
        clearDatasource(connection.getName());
        return true;
    } catch (NonExistingDatasourceException nonExistingDatasourceException) {
        String message = Messages.getErrorString(// $NON-NLS-1$
        "ConnectionServiceImpl.ERROR_0005_UNABLE_TO_UPDATE_CONNECTION", connection.getName(), nonExistingDatasourceException.getLocalizedMessage());
        throw new ConnectionServiceException(Response.SC_NOT_FOUND, message, nonExistingDatasourceException);
    } catch (Exception e) {
        String message = Messages.getErrorString(// $NON-NLS-1$
        "ConnectionServiceImpl.ERROR_0005_UNABLE_TO_UPDATE_CONNECTION", connection.getName(), e.getLocalizedMessage());
        logger.error(message);
        throw new ConnectionServiceException(message, e);
    }
}
Also used : NonExistingDatasourceException(org.pentaho.platform.api.repository.datasource.NonExistingDatasourceException) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) 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 10 with ConnectionServiceException

use of org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException 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)

Aggregations

ConnectionServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException)26 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)9 Test (org.junit.Test)8 DatabaseDialectException (org.pentaho.database.DatabaseDialectException)8 DatasourceMgmtServiceException (org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)8 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)6 DatasourceServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)6 Path (javax.ws.rs.Path)4 IDatabaseDialect (org.pentaho.database.IDatabaseDialect)4 DuplicateDatasourceException (org.pentaho.platform.api.repository.datasource.DuplicateDatasourceException)4 NonExistingDatasourceException (org.pentaho.platform.api.repository.datasource.NonExistingDatasourceException)4 ArrayList (java.util.ArrayList)3 GET (javax.ws.rs.GET)3 Produces (javax.ws.rs.Produces)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 Response (javax.ws.rs.core.Response)3 DatabaseDialectService (org.pentaho.database.service.DatabaseDialectService)3 Database (org.pentaho.di.core.database.Database)3 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)3 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)3