use of org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException in project pentaho-platform by pentaho.
the class JcrBackedDatasourceMgmtService method deleteDatasourceById.
public void deleteDatasourceById(String id) throws NonExistingDatasourceException, DatasourceMgmtServiceException {
RepositoryFile fileToDelete = null;
try {
fileToDelete = repository.getFileById(id);
} catch (UnifiedRepositoryException ure) {
throw new DatasourceMgmtServiceException(Messages.getInstance().getErrorString("DatasourceMgmtService.ERROR_0002_UNABLE_TO_DELETE_DATASOURCE", fileToDelete.getName(), ure.getLocalizedMessage()), // $NON-NLS-1$
ure);
}
deleteDatasource(fileToDelete);
}
use of org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException in project pentaho-platform by pentaho.
the class JcrBackedDatasourceMgmtService method getDatasource.
private IDatabaseConnection getDatasource(RepositoryFile file) throws DatasourceMgmtServiceException {
try {
if (file != null) {
NodeRepositoryFileData data = repository.getDataForRead(file.getId(), NodeRepositoryFileData.class);
IDatabaseConnection databaseConnection = databaseHelper.dataNodeToDatabaseConnection(file.getId(), file.getTitle(), data.getNode());
// databaseMeta.setPassword(passwordService.decrypt(databaseMeta.getPassword()));
return databaseConnection;
} else {
throw new DatasourceMgmtServiceException(Messages.getInstance().getErrorString("DatasourceMgmtService.ERROR_0004_UNABLE_TO_RETRIEVE_DATASOURCE", "", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
""));
}
// } catch(PasswordServiceException pse) {
// throw new DatasourceMgmtServiceException(Messages.getInstance()
// .getErrorString("DatasourceMgmtService.ERROR_0008_UNABLE_TO_DECRYPT_PASSWORD"), pse ); //$NON-NLS-1$
} catch (UnifiedRepositoryException ure) {
throw new DatasourceMgmtServiceException(Messages.getInstance().getErrorString("DatasourceMgmtService.ERROR_0004_UNABLE_TO_RETRIEVE_DATASOURCE", file.getName(), ure.getLocalizedMessage()), // $NON-NLS-1$
ure);
}
}
use of org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException in project data-access by pentaho.
the class ConnectionServiceImplTest method testGetConnectionByIdError.
@Test
public void testGetConnectionByIdError() throws Exception {
doNothing().when(connectionServiceImpl).ensureDataAccessPermission();
DatasourceMgmtServiceException dmsException = mock(DatasourceMgmtServiceException.class);
doThrow(dmsException).when(connectionServiceImpl.datasourceMgmtSvc).getDatasourceById(CONN_ID);
try {
connectionServiceImpl.getConnectionById(CONN_ID);
// This line should never be reached
fail();
} catch (ConnectionServiceException e) {
// Expected exception
}
}
use of org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException in project data-access by pentaho.
the class ConnectionServiceHelperTest method setUp.
@Before
public void setUp() throws Exception {
when(service.getDatasourceByName(anyString())).thenAnswer(new Answer<IDatabaseConnection>() {
@Override
public IDatabaseConnection answer(InvocationOnMock invocation) throws Throwable {
if (invocation.getArguments()[0].equals(VALID_CONNECTION)) {
return connection;
}
if (invocation.getArguments()[0].equals(INVALID_CONNECTION)) {
return null;
}
// throw exception for check if we get exception from getting connection
throw new DatasourceMgmtServiceException();
}
});
pentahoObjectFactory = mock(IPentahoObjectFactory.class);
when(pentahoObjectFactory.objectDefined(anyString())).thenReturn(true);
when(pentahoObjectFactory.get(this.anyClass(), anyString(), any(IPentahoSession.class))).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
if (invocation.getArguments()[0].equals(IDatasourceMgmtService.class)) {
return service;
}
return null;
}
});
PentahoSystem.registerObjectFactory(pentahoObjectFactory);
}
use of org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException in project pentaho-platform by pentaho.
the class NonPooledDatasourceService method retrieve.
@Override
protected DataSource retrieve(String dsName) throws DBDatasourceServiceException {
DataSource ds = null;
try {
IDatasourceMgmtService datasourceMgmtSvc = getDatasourceMgmtService();
IDatabaseConnection databaseConnection = datasourceMgmtSvc.getDatasourceByName(dsName);
if (databaseConnection != null) {
ds = resolveDatabaseConnection(databaseConnection);
if (ds != null) {
cacheManager.putInRegionCache(IDBDatasourceService.JDBC_DATASOURCE, dsName, ds);
}
} else {
throw new DBDatasourceServiceException(Messages.getInstance().getErrorString(// $NON-NLS-1$
"DatasourceService.ERROR_0002_UNABLE_TO_GET_DATASOURCE"));
}
} catch (DatasourceMgmtServiceException daoe) {
throw new DBDatasourceServiceException(Messages.getInstance().getErrorString("DatasourceService.ERROR_0002_UNABLE_TO_GET_DATASOURCE"), // $NON-NLS-1$
daoe);
}
return ds;
}
Aggregations