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