Search in sources :

Example 1 with DatasourceServiceException

use of org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException 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 DatasourceServiceException

use of org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException 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 DatasourceServiceException

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

the class MultitableDatasourceService method deSerializeModelState.

public MultiTableDatasourceDTO deSerializeModelState(String dtoStr) throws DatasourceServiceException {
    try {
        XStream xs = new XStream();
        xs.registerConverter(new LegacyDatasourceConverter());
        return (MultiTableDatasourceDTO) xs.fromXML(dtoStr);
    } catch (Exception e) {
        logger.error(e);
        throw new DatasourceServiceException(e);
    }
}
Also used : XStream(com.thoughtworks.xstream.XStream) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) LegacyDatasourceConverter(org.pentaho.platform.dataaccess.datasource.wizard.service.impl.utils.LegacyDatasourceConverter) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)

Example 4 with DatasourceServiceException

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

the class MultitableDatasourceService method serializeJoins.

public IDatasourceSummary serializeJoins(MultiTableDatasourceDTO dto, IDatabaseConnection connection) throws DatasourceServiceException {
    try {
        ModelerService modelerService = new ModelerService();
        modelerService.initKettle();
        DSWDatasourceServiceImpl datasourceService = new DSWDatasourceServiceImpl();
        GeoContext geoContext = datasourceService.getGeoContext();
        DatabaseMeta databaseMeta = this.getDatabaseMeta(connection);
        MultiTableModelerSource multiTable = new MultiTableModelerSource(databaseMeta, dto.getSchemaModel(), dto.getDatasourceName(), dto.getSelectedTables(), geoContext);
        Domain domain = multiTable.generateDomain(dto.isDoOlap());
        String modelState = serializeModelState(dto);
        for (LogicalModel lm : domain.getLogicalModels()) {
            lm.setProperty("datasourceModel", modelState);
            lm.setProperty("DatasourceType", "MULTI-TABLE-DS");
            // BISERVER-6450 - add security settings to the logical model
            applySecurity(lm);
        }
        modelerService.serializeModels(domain, dto.getDatasourceName(), dto.isDoOlap());
        QueryDatasourceSummary summary = new QueryDatasourceSummary();
        summary.setDomain(domain);
        return summary;
    } catch (Exception e) {
        logger.error("Error serializing joins", e);
        throw new DatasourceServiceException(e);
    }
}
Also used : MultiTableModelerSource(org.pentaho.agilebi.modeler.util.MultiTableModelerSource) LogicalModel(org.pentaho.metadata.model.LogicalModel) QueryDatasourceSummary(org.pentaho.platform.dataaccess.datasource.wizard.sources.query.QueryDatasourceSummary) Domain(org.pentaho.metadata.model.Domain) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) GeoContext(org.pentaho.agilebi.modeler.geo.GeoContext) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)

Example 5 with DatasourceServiceException

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

the class DatasourceInMemoryServiceHelper method getSerializeableResultSet.

public static SerializedResultSet getSerializeableResultSet(String connectionName, String query, int rowLimit, IPentahoSession session) throws DatasourceServiceException {
    SerializedResultSet serializedResultSet = null;
    SQLConnection sqlConnection = null;
    try {
        sqlConnection = getConnection(connectionName);
        sqlConnection.setMaxRows(rowLimit);
        sqlConnection.setReadOnly(true);
        IPentahoResultSet resultSet = sqlConnection.executeQuery(query);
        MarshallableResultSet marshallableResultSet = new MarshallableResultSet();
        marshallableResultSet.setResultSet(resultSet);
        IPentahoMetaData ipmd = resultSet.getMetaData();
        if (ipmd instanceof SQLMetaData) {
            // Hack warning - get JDBC column types
            // TODO: Need to generalize this amongst all IPentahoResultSets
            SQLMetaData smd = (SQLMetaData) ipmd;
            int[] columnTypes = smd.getJDBCColumnTypes();
            List<List<String>> data = new ArrayList<List<String>>();
            for (MarshallableRow row : marshallableResultSet.getRows()) {
                String[] rowData = row.getCell();
                List<String> rowDataList = new ArrayList<String>(rowData.length);
                for (int j = 0; j < rowData.length; j++) {
                    rowDataList.add(rowData[j]);
                }
                data.add(rowDataList);
            }
            serializedResultSet = new SerializedResultSet(columnTypes, marshallableResultSet.getColumnNames().getColumnName(), data);
        }
    } catch (Exception e) {
        logger.error(Messages.getErrorString("DatasourceInMemoryServiceHelper.ERROR_0005_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
        e);
        throw new DatasourceServiceException(Messages.getErrorString("DatasourceInMemoryServiceHelper.ERROR_0005_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
        e);
    } finally {
        if (sqlConnection != null) {
            sqlConnection.close();
        }
    }
    return serializedResultSet;
}
Also used : MarshallableResultSet(org.pentaho.commons.connection.marshal.MarshallableResultSet) SQLConnection(org.pentaho.platform.plugin.services.connections.sql.SQLConnection) ArrayList(java.util.ArrayList) SerializedResultSet(org.pentaho.platform.dataaccess.datasource.beans.SerializedResultSet) IPentahoMetaData(org.pentaho.commons.connection.IPentahoMetaData) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException) SQLException(java.sql.SQLException) DatabaseDialectException(org.pentaho.database.DatabaseDialectException) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SQLMetaData(org.pentaho.platform.plugin.services.connections.sql.SQLMetaData) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) MarshallableRow(org.pentaho.commons.connection.marshal.MarshallableRow) ArrayList(java.util.ArrayList) List(java.util.List) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)

Aggregations

DatasourceServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)26 ConnectionServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException)12 SQLException (java.sql.SQLException)10 ModelerException (org.pentaho.agilebi.modeler.ModelerException)10 Domain (org.pentaho.metadata.model.Domain)10 SerializedResultSet (org.pentaho.platform.dataaccess.datasource.beans.SerializedResultSet)10 MondrianCatalogServiceException (org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogServiceException)9 DomainIdNullException (org.pentaho.metadata.repository.DomainIdNullException)8 DomainStorageException (org.pentaho.metadata.repository.DomainStorageException)8 SqlQueriesNotSupportedException (org.pentaho.platform.dataaccess.datasource.wizard.service.SqlQueriesNotSupportedException)8 DomainAlreadyExistsException (org.pentaho.metadata.repository.DomainAlreadyExistsException)7 QueryValidationException (org.pentaho.platform.dataaccess.datasource.wizard.service.QueryValidationException)7 IOException (java.io.IOException)6 ModelerWorkspace (org.pentaho.agilebi.modeler.ModelerWorkspace)6 ArrayList (java.util.ArrayList)5 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)5 LogicalModel (org.pentaho.metadata.model.LogicalModel)5 SQLModelGeneratorException (org.pentaho.metadata.util.SQLModelGeneratorException)5 FileNotFoundException (java.io.FileNotFoundException)4 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)4