Search in sources :

Example 6 with DatasourceMgmtServiceException

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);
}
Also used : UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)

Example 7 with DatasourceMgmtServiceException

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);
    }
}
Also used : NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)

Example 8 with DatasourceMgmtServiceException

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
    }
}
Also used : ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException) Test(org.junit.Test)

Example 9 with DatasourceMgmtServiceException

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);
}
Also used : IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException) IDatasourceMgmtService(org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService) Before(org.junit.Before)

Example 10 with DatasourceMgmtServiceException

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;
}
Also used : DBDatasourceServiceException(org.pentaho.platform.api.data.DBDatasourceServiceException) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DataSource(javax.sql.DataSource) IDatasourceMgmtService(org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)

Aggregations

DatasourceMgmtServiceException (org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)19 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)11 IDatasourceMgmtService (org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService)7 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)7 DataSource (javax.sql.DataSource)6 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)6 Before (org.junit.Before)5 DBDatasourceServiceException (org.pentaho.platform.api.data.DBDatasourceServiceException)5 NodeRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)4 ConnectionServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException)4 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 IPentahoObjectFactory (org.pentaho.platform.api.engine.IPentahoObjectFactory)2 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)2 URL (java.net.URL)1 Connection (java.sql.Connection)1 HashMap (java.util.HashMap)1 Matchers.anyString (org.mockito.Matchers.anyString)1 IAuthorizationPolicy (org.pentaho.platform.api.engine.IAuthorizationPolicy)1