Search in sources :

Example 6 with ModelerException

use of org.pentaho.agilebi.modeler.ModelerException in project data-access by pentaho.

the class DSWDatasourceServiceImpl 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 = createModelerService();
    modelerWorkspace.setModelName(name);
    try {
        UtilHtmlSanitizer.getInstance().sanitizeConnectionParameters(connection);
        executeQuery(UtilHtmlSanitizer.getInstance().safeEscapeHtml(datasourceDTO.getConnectionName()), query, "1");
        Boolean securityEnabled = (getPermittedRoleList() != null && getPermittedRoleList().size() > 0) || (getPermittedUserList() != null && getPermittedUserList().size() > 0);
        SerializedResultSet resultSet = DatasourceServiceHelper.getSerializeableResultSet(connection.getName(), query, 10, PentahoSessionHolder.getSession());
        SQLModelGenerator sqlModelGenerator = new SQLModelGenerator(name, connection.getName(), connection.getDatabaseType().getShortName(), resultSet.getColumnTypes(), resultSet.getColumns(), query, securityEnabled, getEffectivePermittedUserList(securityEnabled), getPermittedRoleList(), getDefaultAcls(), (PentahoSessionHolder.getSession() != null) ? PentahoSessionHolder.getSession().getName() : null);
        Domain domain = sqlModelGenerator.generate();
        domain.getPhysicalModels().get(0).setId(connection.getName());
        modelerWorkspace.setDomain(domain);
        modelerWorkspace.getWorkspaceHelper().autoModelFlat(modelerWorkspace);
        modelerWorkspace.getWorkspaceHelper().autoModelRelationalFlat(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();
        prepareForSerializaton(domain);
        modelerService.serializeModels(domain, modelerWorkspace.getModelName());
        summary.setDomain(domain);
        return summary;
    } catch (SQLModelGeneratorException smge) {
        logger.error(// $NON-NLS-1$
        Messages.getErrorString(// $NON-NLS-1$
        "DatasourceServiceImpl.ERROR_0011_UNABLE_TO_GENERATE_MODEL", smge.getLocalizedMessage()), smge);
        throw new DatasourceServiceException(Messages.getErrorString("DatasourceServiceImpl.ERROR_0011_UNABLE_TO_GENERATE_MODEL", smge.getLocalizedMessage()), // $NON-NLS-1$
        smge);
    } catch (QueryValidationException e) {
        logger.error(Messages.getErrorString("DatasourceServiceImpl.ERROR_0009_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
        e);
        throw new DatasourceServiceException(Messages.getErrorString("DatasourceServiceImpl.ERROR_0009_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
        e);
    } catch (ModelerException e) {
        logger.error(// $NON-NLS-1$
        Messages.getErrorString(// $NON-NLS-1$
        "DatasourceServiceImpl.ERROR_0011_UNABLE_TO_GENERATE_MODEL", e.getLocalizedMessage()), e);
        throw new DatasourceServiceException(Messages.getErrorString("DatasourceServiceImpl.ERROR_0011_UNABLE_TO_GENERATE_MODEL", e.getLocalizedMessage()), // $NON-NLS-1$
        e);
    } catch (SqlQueriesNotSupportedException e) {
        // $NON-NLS-1$
        throw new DatasourceServiceException(e.getLocalizedMessage(), e);
    } catch (Exception e) {
        logger.error(// $NON-NLS-1$
        Messages.getErrorString(// $NON-NLS-1$
        "DatasourceServiceImpl.ERROR_0011_UNABLE_TO_GENERATE_MODEL", e.getLocalizedMessage()), e);
        throw new DatasourceServiceException(Messages.getErrorString("DatasourceServiceImpl.ERROR_0011_UNABLE_TO_GENERATE_MODEL", e.getLocalizedMessage()), // $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) 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) 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) SqlQueriesNotSupportedException(org.pentaho.platform.dataaccess.datasource.wizard.service.SqlQueriesNotSupportedException) Domain(org.pentaho.metadata.model.Domain) ModelerWorkspace(org.pentaho.agilebi.modeler.ModelerWorkspace) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)

Example 7 with ModelerException

use of org.pentaho.agilebi.modeler.ModelerException in project data-access by pentaho.

the class InMemoryDSWDatasourceServiceImpl method getGeoContext.

public GeoContext getGeoContext() throws DatasourceServiceException {
    try {
        Properties props = new Properties();
        props.load(new FileInputStream(new File("target/test-classes/geoContextSample.properties")));
        GeoContext geo = GeoContextFactory.create(new GeoContextPropertiesProvider(props));
        return geo;
    } catch (ModelerException e) {
        throw new DatasourceServiceException(e);
    } catch (FileNotFoundException e) {
        throw new DatasourceServiceException(e);
    } catch (IOException e) {
        // To change body of catch statement use File | Settings | File Templates.
        e.printStackTrace();
    }
    return null;
}
Also used : ModelerException(org.pentaho.agilebi.modeler.ModelerException) GeoContextPropertiesProvider(org.pentaho.agilebi.modeler.geo.GeoContextPropertiesProvider) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream) GeoContext(org.pentaho.agilebi.modeler.geo.GeoContext) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)

Aggregations

ModelerException (org.pentaho.agilebi.modeler.ModelerException)7 Domain (org.pentaho.metadata.model.Domain)4 DatasourceServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)4 IOException (java.io.IOException)3 FileNotFoundException (java.io.FileNotFoundException)2 SQLException (java.sql.SQLException)2 ModelerWorkspace (org.pentaho.agilebi.modeler.ModelerWorkspace)2 GeoContext (org.pentaho.agilebi.modeler.geo.GeoContext)2 GwtModelerWorkspaceHelper (org.pentaho.agilebi.modeler.gwt.GwtModelerWorkspaceHelper)2 DomainAlreadyExistsException (org.pentaho.metadata.repository.DomainAlreadyExistsException)2 DomainIdNullException (org.pentaho.metadata.repository.DomainIdNullException)2 DomainStorageException (org.pentaho.metadata.repository.DomainStorageException)2 SQLModelGenerator (org.pentaho.metadata.util.SQLModelGenerator)2 SQLModelGeneratorException (org.pentaho.metadata.util.SQLModelGeneratorException)2 SerializedResultSet (org.pentaho.platform.dataaccess.datasource.beans.SerializedResultSet)2 QueryValidationException (org.pentaho.platform.dataaccess.datasource.wizard.service.QueryValidationException)2 QueryDatasourceSummary (org.pentaho.platform.dataaccess.datasource.wizard.sources.query.QueryDatasourceSummary)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 Properties (java.util.Properties)1