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;
}
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;
}
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);
}
}
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);
}
}
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);
}
}
Aggregations