Search in sources :

Example 11 with DatasourceServiceException

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

the class DSWDatasourceServiceImpl method getLogicalModels.

public List<LogicalModelSummary> getLogicalModels(String context) throws DatasourceServiceException {
    if (!hasDataAccessViewPermission()) {
        // $NON-NLS-1$
        logger.error(Messages.getErrorString("DatasourceServiceImpl.ERROR_0001_PERMISSION_DENIED"));
        throw new DatasourceServiceException(Messages.getErrorString(// $NON-NLS-1$
        "DatasourceServiceImpl.ERROR_0001_PERMISSION_DENIED"));
    }
    List<LogicalModelSummary> logicalModelSummaries = new ArrayList<LogicalModelSummary>();
    for (String domainId : getMetadataDomainRepository().getDomainIds()) {
        Domain domain;
        try {
            domain = getMetadataDomainRepository().getDomain(domainId);
        } catch (Exception e) {
            logger.error(Messages.getErrorString("DatasourceServiceImpl.ERROR_0022_UNABLE_TO_PROCESS_LOGICAL_MODEL", domainId), e);
            continue;
        }
        String locale = LocaleHelper.getLocale().toString();
        String[] locales = new String[domain.getLocales().size()];
        for (int i = 0; i < domain.getLocales().size(); i++) {
            locales[i] = domain.getLocales().get(i).getCode();
        }
        locale = LocaleHelper.getClosestLocale(locale, locales);
        for (LogicalModel model : domain.getLogicalModels()) {
            String vis = (String) model.getProperty(LM_PROP_VISIBLE);
            if (vis != null) {
                String[] visibleContexts = vis.split(",");
                boolean visibleToContext = false;
                for (String c : visibleContexts) {
                    if (StringUtils.isNotEmpty(c.trim()) && c.trim().equals(context)) {
                        visibleToContext = true;
                        break;
                    }
                }
                if (!visibleToContext) {
                    continue;
                }
            }
            logicalModelSummaries.add(new LogicalModelSummary(domainId, model.getId(), model.getName(locale)));
        }
    }
    return logicalModelSummaries;
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) LogicalModelSummary(org.pentaho.platform.dataaccess.datasource.beans.LogicalModelSummary) ArrayList(java.util.ArrayList) Domain(org.pentaho.metadata.model.Domain) ModelerException(org.pentaho.agilebi.modeler.ModelerException) QueryValidationException(org.pentaho.platform.dataaccess.datasource.wizard.service.QueryValidationException) SQLModelGeneratorException(org.pentaho.metadata.util.SQLModelGeneratorException) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) SQLException(java.sql.SQLException) SqlQueriesNotSupportedException(org.pentaho.platform.dataaccess.datasource.wizard.service.SqlQueriesNotSupportedException) MondrianCatalogServiceException(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogServiceException) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) IOException(java.io.IOException) CsvTransformGeneratorException(org.pentaho.platform.dataaccess.datasource.wizard.models.CsvTransformGeneratorException) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)

Example 12 with DatasourceServiceException

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

the class InMemoryDSWDatasourceServiceImpl method doPreview.

public SerializedResultSet doPreview(String connectionName, String query, String previewLimit) throws DatasourceServiceException {
    SerializedResultSet returnResultSet;
    try {
        executeQuery(connectionName, query, previewLimit);
        returnResultSet = DatasourceInMemoryServiceHelper.getSerializeableResultSet(connectionName, query, Integer.parseInt(previewLimit), null);
    } catch (QueryValidationException e) {
        logger.error(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0009_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
        e);
        throw new DatasourceServiceException(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0009_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
        e);
    }
    return returnResultSet;
}
Also used : QueryValidationException(org.pentaho.platform.dataaccess.datasource.wizard.service.QueryValidationException) SerializedResultSet(org.pentaho.platform.dataaccess.datasource.beans.SerializedResultSet) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)

Example 13 with DatasourceServiceException

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

the class InMemoryDSWDatasourceServiceImpl method generateQueryDomain.

@Override
public QueryDatasourceSummary generateQueryDomain(String name, String query, DatabaseConnection connection, DatasourceDTO datasourceDTO) throws DatasourceServiceException {
    ModelerWorkspace modelerWorkspace = new ModelerWorkspace(new GwtModelerWorkspaceHelper(), getGeoContext());
    ModelerService modelerService = new ModelerService();
    modelerWorkspace.setModelName(name);
    try {
        Boolean securityEnabled = (getPermittedRoleList() != null && getPermittedRoleList().size() > 0) || (getPermittedUserList() != null && getPermittedUserList().size() > 0);
        SerializedResultSet resultSet = DatasourceInMemoryServiceHelper.getSerializeableResultSet(connection.getName(), query, Integer.parseInt("10"), null);
        SQLModelGenerator sqlModelGenerator = new SQLModelGenerator(name, connection.getName(), connection.getDatabaseType().getShortName(), resultSet.getColumnTypes(), resultSet.getColumns(), query, securityEnabled, getPermittedRoleList(), getPermittedUserList(), getDefaultAcls(), "joe");
        Domain domain = sqlModelGenerator.generate();
        modelerWorkspace.setDomain(domain);
        modelerWorkspace.getWorkspaceHelper().autoModelFlat(modelerWorkspace);
        modelerWorkspace.setModelName(datasourceDTO.getDatasourceName());
        modelerWorkspace.getWorkspaceHelper().populateDomain(modelerWorkspace);
        domain.getLogicalModels().get(0).setProperty("datasourceModel", serializeModelState(datasourceDTO));
        domain.getLogicalModels().get(0).setProperty("DatasourceType", "SQL-DS");
        QueryDatasourceSummary summary = new QueryDatasourceSummary();
        modelerService.serializeModels(domain, modelerWorkspace.getModelName());
        summary.setDomain(domain);
        return summary;
    } catch (SQLModelGeneratorException smge) {
        logger.error(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0016_UNABLE_TO_GENERATE_MODEL", smge.getLocalizedMessage()), smge);
        throw new DatasourceServiceException(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0015_UNABLE_TO_GENERATE_MODEL"), // $NON-NLS-1$
        smge);
    } catch (QueryValidationException e) {
        logger.error(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0009_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
        e);
        throw new DatasourceServiceException(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0009_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
        e);
    } catch (ModelerException e) {
        logger.error(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0016_UNABLE_TO_GENERATE_MODEL", e.getLocalizedMessage()), e);
        throw new DatasourceServiceException(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0015_UNABLE_TO_GENERATE_MODEL"), // $NON-NLS-1$
        e);
    } catch (Exception e) {
        logger.error(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0016_UNABLE_TO_GENERATE_MODEL", e.getLocalizedMessage()), e);
        throw new DatasourceServiceException(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0015_UNABLE_TO_GENERATE_MODEL"), // $NON-NLS-1$
        e);
    }
}
Also used : SQLModelGeneratorException(org.pentaho.metadata.util.SQLModelGeneratorException) ModelerException(org.pentaho.agilebi.modeler.ModelerException) SerializedResultSet(org.pentaho.platform.dataaccess.datasource.beans.SerializedResultSet) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) ModelerException(org.pentaho.agilebi.modeler.ModelerException) SQLException(java.sql.SQLException) QueryValidationException(org.pentaho.platform.dataaccess.datasource.wizard.service.QueryValidationException) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SQLModelGeneratorException(org.pentaho.metadata.util.SQLModelGeneratorException) GwtModelerWorkspaceHelper(org.pentaho.agilebi.modeler.gwt.GwtModelerWorkspaceHelper) QueryDatasourceSummary(org.pentaho.platform.dataaccess.datasource.wizard.sources.query.QueryDatasourceSummary) SQLModelGenerator(org.pentaho.metadata.util.SQLModelGenerator) QueryValidationException(org.pentaho.platform.dataaccess.datasource.wizard.service.QueryValidationException) Domain(org.pentaho.metadata.model.Domain) ModelerWorkspace(org.pentaho.agilebi.modeler.ModelerWorkspace) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)

Example 14 with DatasourceServiceException

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

the class DSWDatasourceServiceImplTest method testDoPreview_NullQuery.

@Test(expected = DatasourceServiceException.class)
public void testDoPreview_NullQuery() throws DatasourceServiceException {
    doReturn(true).when(dswService).hasDataAccessPermission();
    SerializedResultSet result = dswService.doPreview(CONNECTION_NAME, null, PREVIEW_LIMIT);
    try {
        verify(dswService).executeQuery("[connection &#25509;&#32154; &lt;;&gt;!@#$%^&amp;*()_-=+.,]", VALID_QUERY, PREVIEW_LIMIT);
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertNotNull(result);
    assertArrayEquals(columns, result.getColumns());
    assertArrayEquals(columnTypes, result.getColumnTypes());
}
Also used : SerializedResultSet(org.pentaho.platform.dataaccess.datasource.beans.SerializedResultSet) ModelerException(org.pentaho.agilebi.modeler.ModelerException) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) SQLException(java.sql.SQLException) SqlQueriesNotSupportedException(org.pentaho.platform.dataaccess.datasource.wizard.service.SqlQueriesNotSupportedException) MondrianCatalogServiceException(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogServiceException) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) Test(org.junit.Test)

Example 15 with DatasourceServiceException

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

the class DSWDatasourceServiceImplTest method testGenerateQueryDomain.

private void testGenerateQueryDomain(String modelName, String query, List<String> roleList, List<String> userList) throws DatasourceServiceException {
    ModelInfo modelInfo = mock(ModelInfo.class);
    when(modelInfo.getFileInfo()).thenReturn(mock(CsvFileInfo.class));
    DatasourceDTO datasourceDTO = new DatasourceDTO();
    datasourceDTO.setConnectionName(CONNECTION_NAME);
    datasourceDTO.setDatasourceName(CONNECTION_NAME);
    datasourceDTO.setCsvModelInfo(modelInfo);
    DatabaseConnection connectionSpy = spy(new DatabaseConnection());
    connectionSpy.setName(CONNECTION_NAME);
    connectionSpy.setDatabaseName("[database name 接続 <;>!@#$%^&*()_-=+.,]");
    connectionSpy.setDatabasePort("123456");
    connectionSpy.setHostname("[hostname 接続 <;>!@#$%^&*()_-=+.,]");
    connectionSpy.setPassword("[password 接続 <;>!@#$%^&*()_-=+.,]");
    connectionSpy.setUsername("[username 接続 <;>!@#$%^&*()_-=+.,]");
    connectionSpy.setDatabaseType(mock(IDatabaseType.class));
    doReturn(modelerService).when(dswService).createModelerService();
    doReturn(true).when(dswService).hasDataAccessPermission();
    doReturn(roleList).when(dswService).getPermittedRoleList();
    doReturn(userList).when(dswService).getPermittedUserList();
    doReturn(null).when(dswService).getGeoContext();
    doReturn(1).when(dswService).getDefaultAcls();
    QueryDatasourceSummary summary = dswService.generateQueryDomain(modelName, query, connectionSpy, datasourceDTO);
    try {
        verify(dswService).executeQuery("[connection &#25509;&#32154; &lt;;&gt;!@#$%^&amp;*()_-=+.,]", query, "1");
    } catch (Exception e) {
        e.printStackTrace();
    }
    verify(connectionSpy).setName("[connection &#25509;&#32154; &lt;;&gt;!@#$%^&amp;*()_-=+.,]");
    verify(connectionSpy).setDatabaseName("[database name &#25509;&#32154; &lt;;&gt;!@#$%^&amp;*()_-=+.,]");
    verify(connectionSpy, times(2)).setDatabasePort("123456");
    verify(connectionSpy).setHostname("[hostname &#25509;&#32154; &lt;;&gt;!@#$%^&amp;*()_-=+.,]");
    verify(connectionSpy).setPassword("[password &#25509;&#32154; &lt;;&gt;!@#$%^&amp;*()_-=+.,]");
    verify(connectionSpy).setUsername("[username &#25509;&#32154; &lt;;&gt;!@#$%^&amp;*()_-=+.,]");
    assertNotNull(summary);
    assertNotNull(summary.getDomain());
    assertEquals(CONNECTION_NAME, summary.getDomain().getId());
}
Also used : IDatabaseType(org.pentaho.database.model.IDatabaseType) CsvFileInfo(org.pentaho.platform.dataaccess.datasource.wizard.models.CsvFileInfo) QueryDatasourceSummary(org.pentaho.platform.dataaccess.datasource.wizard.sources.query.QueryDatasourceSummary) ModelInfo(org.pentaho.platform.dataaccess.datasource.wizard.models.ModelInfo) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DatasourceDTO(org.pentaho.platform.dataaccess.datasource.wizard.models.DatasourceDTO) ModelerException(org.pentaho.agilebi.modeler.ModelerException) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) SQLException(java.sql.SQLException) SqlQueriesNotSupportedException(org.pentaho.platform.dataaccess.datasource.wizard.service.SqlQueriesNotSupportedException) MondrianCatalogServiceException(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogServiceException) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException)

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