Search in sources :

Example 1 with ConnectionServiceException

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

the class DataSourceWizardServiceTest method testRemoveDSWError.

@Test
public void testRemoveDSWError() throws Exception {
    Domain mockDomain = mock(Domain.class);
    IPentahoSession mockIPentahoSession = mock(IPentahoSession.class);
    ModelerWorkspace mockModelerWorkspace = mock(ModelerWorkspace.class);
    LogicalModel mockLogicalModel = mock(LogicalModel.class);
    String mockObject = "not null";
    String dswId = "dswId";
    // Test 1
    ConnectionServiceException cse = new ConnectionServiceException();
    doThrow(cse).when(dataSourceWizardService).ensureDataAccessPermissionCheck();
    try {
        dataSourceWizardService.removeDSW("dswId");
        fail();
    } catch (PentahoAccessControlException pace) {
    // expected
    }
    // Test 2
    DatasourceServiceException mockDatasourceServiceException = mock(DatasourceServiceException.class);
    doNothing().when(dataSourceWizardService).ensureDataAccessPermissionCheck();
    doReturn(dswId).when(dataSourceWizardService).parseMondrianSchemaNameWrapper(dswId);
    doReturn(mockDomain).when(dataSourceWizardService.metadataDomainRepository).getDomain(dswId);
    doReturn(mockModelerWorkspace).when(dataSourceWizardService).createModelerWorkspace();
    doReturn(null).when(mockModelerWorkspace).getLogicalModel(ModelerPerspective.ANALYSIS);
    doReturn(mockLogicalModel).when(mockModelerWorkspace).getLogicalModel(ModelerPerspective.REPORTING);
    doReturn(mockObject).when(mockLogicalModel).getProperty("MondrianCatalogRef");
    doReturn(mockIPentahoSession).when(dataSourceWizardService).getSession();
    doNothing().when(dataSourceWizardService.mondrianCatalogService).removeCatalog("not null", mockIPentahoSession);
    doThrow(mockDatasourceServiceException).when(dataSourceWizardService.dswService).deleteLogicalModel(null, null);
    dataSourceWizardService.removeDSW("dswId");
    verify(dataSourceWizardService, times(2)).removeDSW("dswId");
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Matchers.anyString(org.mockito.Matchers.anyString) Domain(org.pentaho.metadata.model.Domain) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) ModelerWorkspace(org.pentaho.agilebi.modeler.ModelerWorkspace) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException) Test(org.junit.Test)

Example 2 with ConnectionServiceException

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

the class MultitableDatasourceService method retrieveSchemas.

public List<String> retrieveSchemas(IDatabaseConnection connection) throws DatasourceServiceException {
    List<String> schemas = new ArrayList<String>();
    try {
        DatabaseMeta databaseMeta = this.getDatabaseMeta(connection);
        Database database = new Database(null, databaseMeta);
        database.connect();
        Map<String, Collection<String>> tableMap = database.getTableMap(null, this.isDataServicesConnection(connection) ? new HashMap<String, String>() {

            {
                put("STREAMING", "N");
            }
        } : null);
        // database.getSchemas()
        Set<String> schemaNames = tableMap.keySet();
        schemas.addAll(schemaNames);
        database.disconnect();
    } catch (KettleDatabaseException e) {
        logger.error("Error creating database object", e);
        throw new DatasourceServiceException(e);
    } catch (ConnectionServiceException e) {
        logger.error("Error getting database meta", e);
        throw new DatasourceServiceException(e);
    }
    return schemas;
}
Also used : ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) HashMap(java.util.HashMap) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) ArrayList(java.util.ArrayList) Database(org.pentaho.di.core.database.Database) Collection(java.util.Collection) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)

Example 3 with ConnectionServiceException

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

the class DatasourceInMemoryServiceHelper method getConnection.

public static SQLConnection getConnection(String connectionName) throws DatasourceServiceException {
    IDatabaseConnection connection = null;
    try {
        ConnectionServiceImpl service = new ConnectionServiceImpl();
        connection = service.getConnectionByName(connectionName);
        DatabaseDialectService dialectService = new DatabaseDialectService();
        IDatabaseDialect dialect = dialectService.getDialect(connection);
        String driverClass = null;
        if (connection.getDatabaseType().getShortName().equals("GENERIC")) {
            driverClass = connection.getAttributes().get(GenericDatabaseDialect.ATTRIBUTE_CUSTOM_DRIVER_CLASS);
        } else {
            driverClass = dialect.getNativeDriver();
        }
        return new SQLConnection(driverClass, dialect.getURLWithExtraOptions(connection), connection.getUsername(), connection.getPassword(), null);
    } catch (ConnectionServiceException e1) {
        return null;
    } catch (DatabaseDialectException e) {
        return null;
    }
}
Also used : ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) ConnectionServiceImpl(org.pentaho.platform.dataaccess.datasource.wizard.service.impl.ConnectionServiceImpl) DatabaseDialectException(org.pentaho.database.DatabaseDialectException) SQLConnection(org.pentaho.platform.plugin.services.connections.sql.SQLConnection) DatabaseDialectService(org.pentaho.database.service.DatabaseDialectService) IDatabaseDialect(org.pentaho.database.IDatabaseDialect) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection)

Example 4 with ConnectionServiceException

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

the class DataSourceWizardService method removeDSW.

public void removeDSW(String dswId) throws PentahoAccessControlException {
    try {
        ensureDataAccessPermissionCheck();
    } catch (ConnectionServiceException e) {
        throw new PentahoAccessControlException();
    }
    Domain domain = metadataDomainRepository.getDomain(dswId);
    ModelerWorkspace model = createModelerWorkspace();
    model.setDomain(domain);
    LogicalModel logicalModel = model.getLogicalModel(ModelerPerspective.ANALYSIS);
    if (logicalModel == null) {
        logicalModel = model.getLogicalModel(ModelerPerspective.REPORTING);
    }
    if (logicalModel.getProperty(MONDRIAN_CATALOG_REF) != null) {
        String catalogRef = (String) logicalModel.getProperty(MONDRIAN_CATALOG_REF);
        try {
            mondrianCatalogService.removeCatalog(catalogRef, getSession());
        } catch (MondrianCatalogServiceException e) {
            logger.warn("Failed to remove mondrian catalog", e);
        }
    }
    try {
        dswService.deleteLogicalModel(domain.getId(), logicalModel.getId());
    } catch (DatasourceServiceException ex) {
        logger.warn("Failed to remove logical model", ex);
    }
    metadataDomainRepository.removeDomain(dswId);
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) MondrianCatalogServiceException(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogServiceException) Domain(org.pentaho.metadata.model.Domain) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) ModelerWorkspace(org.pentaho.agilebi.modeler.ModelerWorkspace) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)

Example 5 with ConnectionServiceException

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

the class JDBCDatasourceResource method getConnectionIDs.

/**
 * Get a list of JDBC datasource IDs.
 *
 * <p><b>Example Request:</b><br />
 *    GET pentaho/plugin/data-access/api/datasource/jdbc/connection
 * </p>
 *
 * @return A list of JDBC datasource IDs.
 *
 * <p><b>Example Response:</b></p>
 *    <pre function="syntax.xml">
 *      {
 *        "Item": [
 *          {
 *            "@type": "xs:string",
 *            "$": "AgileBI"
 *          },
 *          {
 *            "@type": "xs:string",
 *            "$": "Audit"
 *          },
 *          {
 *            "@type": "xs:string",
 *            "$": "SampleData"
 *          },
 *          {
 *            "@type": "xs:string",
 *            "$": "TestDataSourceResource"
 *          },
 *          {
 *            "@type": "xs:string",
 *            "$": "baseball connection"
 *          },
 *          {
 *            "@type": "xs:string",
 *            "$": "baseball connection"
 *          },
 *          {
 *            "@type": "xs:string",
 *            "$": "live_logging_info"
 *          },
 *          {
 *            "@type": "xs:string",
 *            "$": "pentaho_operations_mart"
 *          }
 *        ]
 *      }
 *    </pre>
 */
@GET
@Path("/")
@Produces({ APPLICATION_JSON, APPLICATION_XML })
@StatusCodes({ @ResponseCode(code = 200, condition = "Successfully retrieved the list of JDBC datasource IDs"), @ResponseCode(code = 500, condition = "Internal error retrieving JDBC datasource IDs") })
public JaxbList<String> getConnectionIDs() {
    List<String> connStrList = new ArrayList<String>();
    try {
        List<IDatabaseConnection> conns = service.getConnections();
        for (IDatabaseConnection conn : conns) {
            conn.setPassword(null);
            connStrList.add(conn.getName());
        }
    } catch (ConnectionServiceException e) {
        logger.error("Error " + e.getMessage());
        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    }
    JaxbList<String> connections = new JaxbList<String>(connStrList);
    return connections;
}
Also used : ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) JaxbList(org.pentaho.platform.web.http.api.resources.JaxbList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) StatusCodes(org.codehaus.enunciate.jaxrs.StatusCodes)

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