Search in sources :

Example 16 with DatasourceServiceException

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

the class DSWDatasourceServiceImplTest method testDoPreview.

@Test
public void testDoPreview() throws DatasourceServiceException {
    doReturn(true).when(dswService).hasDataAccessPermission();
    SerializedResultSet result = dswService.doPreview(CONNECTION_NAME, VALID_QUERY, PREVIEW_LIMIT);
    try {
        verify(dswService).executeQuery("[connection 接続 <;>!@#$%^&*()_-=+.,]", 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 17 with DatasourceServiceException

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

the class DSWDatasourceServiceImplTest method testGenerateLogicalModel.

private void testGenerateLogicalModel(String modelName, String connName, String query, List<String> roleList, List<String> userList) throws DatasourceServiceException {
    doReturn(true).when(dswService).hasDataAccessPermission();
    doReturn(roleList).when(dswService).getPermittedRoleList();
    doReturn(userList).when(dswService).getPermittedUserList();
    doReturn(1).when(dswService).getDefaultAcls();
    BusinessData businessData = dswService.generateLogicalModel(modelName, connName, DB_TYPE, query, PREVIEW_LIMIT);
    try {
        verify(dswService).executeQuery("[connection &#25509;&#32154; &lt;;&gt;!@#$%^&amp;*()_-=+.,]", query, PREVIEW_LIMIT);
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertNotNull(businessData);
    assertNotNull(businessData.getDomain());
    assertNotNull(businessData.getData());
}
Also used : BusinessData(org.pentaho.platform.dataaccess.datasource.beans.BusinessData) 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)

Example 18 with DatasourceServiceException

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

the class DSWDatasourceServiceImpl method deSerializeModelState.

public DatasourceDTO deSerializeModelState(String dtoStr) throws DatasourceServiceException {
    XStream xs = new XStream();
    xs.setClassLoader(DatasourceDTO.class.getClassLoader());
    if (dtoStr.startsWith("<org.pentaho.platform.dataaccess.datasource.wizard.models.DatasourceDTO>") && dtoStr.endsWith("</org.pentaho.platform.dataaccess.datasource.wizard.models.DatasourceDTO>")) {
        return (DatasourceDTO) xs.fromXML(dtoStr);
    } else {
        logger.error(Messages.getErrorString(// $NON-NLS-1$
        "DatasourceServiceImpl.ERROR_0025_STRING_FOR_DESERIALIZATION_IS_NOT_VALID"));
        throw new DatasourceServiceException(Messages.getErrorString(// $NON-NLS-1$
        "DatasourceServiceImpl.ERROR_0025_STRING_FOR_DESERIALIZATION_IS_NOT_VALID"));
    }
}
Also used : XStream(com.thoughtworks.xstream.XStream) DatasourceDTO(org.pentaho.platform.dataaccess.datasource.wizard.models.DatasourceDTO) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)

Example 19 with DatasourceServiceException

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

the class DSWDatasourceServiceImpl method generateLogicalModel.

/**
 * This method gets the business data which are the business columns, columns types and sample preview data
 *
 * @param modelName, connection, query, previewLimit
 * @return BusinessData
 * @throws DatasourceServiceException
 */
public BusinessData generateLogicalModel(String modelName, String connectionName, String dbType, String query, String previewLimit) throws DatasourceServiceException {
    if (!hasDataAccessPermission()) {
        // $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"));
    }
    try {
        // Testing whether the query is correct or not
        connectionName = UtilHtmlSanitizer.getInstance().safeEscapeHtml(connectionName);
        executeQuery(connectionName, query, previewLimit);
        Boolean securityEnabled = (getPermittedRoleList() != null && getPermittedRoleList().size() > 0) || (getPermittedUserList() != null && getPermittedUserList().size() > 0);
        SerializedResultSet resultSet = DatasourceServiceHelper.getSerializeableResultSet(connectionName, query, Integer.parseInt(previewLimit), PentahoSessionHolder.getSession());
        SQLModelGenerator sqlModelGenerator = new SQLModelGenerator(modelName, connectionName, dbType, resultSet.getColumnTypes(), resultSet.getColumns(), query, securityEnabled, getEffectivePermittedUserList(securityEnabled), getPermittedRoleList(), getDefaultAcls(), (PentahoSessionHolder.getSession() != null) ? PentahoSessionHolder.getSession().getName() : null);
        Domain domain = sqlModelGenerator.generate();
        return new BusinessData(domain, resultSet.getData());
    } catch (SQLModelGeneratorException smge) {
        logger.error(Messages.getErrorString("DatasourceServiceImpl.ERROR_0011_UNABLE_TO_GENERATE_MODEL", smge.getLocalizedMessage()), // $NON-NLS-1$
        smge);
        throw new DatasourceServiceException(Messages.getErrorString("DatasourceServiceImpl.ERROR_0011_UNABLE_TO_GENERATE_MODEL", smge.getLocalizedMessage()), // $NON-NLS-1$
        smge);
    } catch (QueryValidationException e) {
        throw new DatasourceServiceException(Messages.getErrorString("DatasourceServiceImpl.ERROR_0009_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
        e);
    } catch (SqlQueriesNotSupportedException e) {
        // $NON-NLS-1$
        throw new DatasourceServiceException(e.getLocalizedMessage(), e);
    }
}
Also used : BusinessData(org.pentaho.platform.dataaccess.datasource.beans.BusinessData) SQLModelGeneratorException(org.pentaho.metadata.util.SQLModelGeneratorException) SQLModelGenerator(org.pentaho.metadata.util.SQLModelGenerator) QueryValidationException(org.pentaho.platform.dataaccess.datasource.wizard.service.QueryValidationException) SerializedResultSet(org.pentaho.platform.dataaccess.datasource.beans.SerializedResultSet) SqlQueriesNotSupportedException(org.pentaho.platform.dataaccess.datasource.wizard.service.SqlQueriesNotSupportedException) Domain(org.pentaho.metadata.model.Domain) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)

Example 20 with DatasourceServiceException

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

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