Search in sources :

Example 16 with LogicalModel

use of org.pentaho.metadata.model.LogicalModel in project data-access by pentaho.

the class DataSourceWizardServiceTest method testRemoveDswById.

public void testRemoveDswById(String dswId) 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";
    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);
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            returnedDswId = (String) args[0];
            return null;
        }
    }).when(dataSourceWizardService.metadataDomainRepository).removeDomain(dswId);
    dataSourceWizardService.removeDSW(dswId);
    assertEquals("The method should call removal for original id", dswId, returnedDswId);
    verify(dataSourceWizardService, times(1)).removeDSW(dswId);
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Matchers.anyString(org.mockito.Matchers.anyString) Domain(org.pentaho.metadata.model.Domain) ModelerWorkspace(org.pentaho.agilebi.modeler.ModelerWorkspace)

Example 17 with LogicalModel

use of org.pentaho.metadata.model.LogicalModel in project data-access by pentaho.

the class DataSourceWizardServiceTest method testDoGetDSWFilesAsDownload.

@Test
public void testDoGetDSWFilesAsDownload() throws Exception {
    Map<String, InputStream> mockFileData = mock(Map.class);
    ModelerWorkspace mockModelerWorkspace = mock(ModelerWorkspace.class);
    MondrianCatalogRepositoryHelper mockMondrianCatalogRepositoryHelper = mock(MondrianCatalogRepositoryHelper.class);
    LogicalModel mockLogicalModel = mock(LogicalModel.class);
    String mockObject = "not null";
    String dswId = "dswId";
    doReturn(true).when(dataSourceWizardService).canManageACL();
    doReturn(mockFileData).when(dataSourceWizardService).getMetadataFiles(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(mockMondrianCatalogRepositoryHelper).when(dataSourceWizardService).createMondrianCatalogRepositoryHelper();
    doNothing().when(dataSourceWizardService).parseMondrianSchemaNameWrapper(dswId, mockFileData);
    Map<String, InputStream> response = dataSourceWizardService.doGetDSWFilesAsDownload("dswId");
    assertEquals(mockFileData, response);
    verify(dataSourceWizardService, times(1)).doGetDSWFilesAsDownload("dswId");
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) InputStream(java.io.InputStream) MondrianCatalogRepositoryHelper(org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper) Matchers.anyString(org.mockito.Matchers.anyString) ModelerWorkspace(org.pentaho.agilebi.modeler.ModelerWorkspace) Test(org.junit.Test)

Example 18 with LogicalModel

use of org.pentaho.metadata.model.LogicalModel in project data-access by pentaho.

the class DataSourceWizardServiceTest method testErrorRemovingMondrianDoesNotStopXMIRemoval.

@Test
public void testErrorRemovingMondrianDoesNotStopXMIRemoval() 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";
    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();
    doThrow(new MondrianCatalogServiceException("who cares")).when(dataSourceWizardService.mondrianCatalogService).removeCatalog("not null", mockIPentahoSession);
    doNothing().when(dataSourceWizardService.metadataDomainRepository).removeDomain(dswId);
    dataSourceWizardService.removeDSW("dswId");
    verify(dataSourceWizardService, times(1)).removeDSW("dswId");
    verify(dataSourceWizardService.metadataDomainRepository).removeDomain(dswId);
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) MondrianCatalogServiceException(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogServiceException) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Matchers.anyString(org.mockito.Matchers.anyString) Domain(org.pentaho.metadata.model.Domain) ModelerWorkspace(org.pentaho.agilebi.modeler.ModelerWorkspace) Test(org.junit.Test)

Example 19 with LogicalModel

use of org.pentaho.metadata.model.LogicalModel 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 20 with LogicalModel

use of org.pentaho.metadata.model.LogicalModel 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)

Aggregations

LogicalModel (org.pentaho.metadata.model.LogicalModel)53 Domain (org.pentaho.metadata.model.Domain)29 LocalizedString (org.pentaho.metadata.model.concept.types.LocalizedString)14 Test (org.junit.Test)13 ModelerWorkspace (org.pentaho.agilebi.modeler.ModelerWorkspace)11 LogicalTable (org.pentaho.metadata.model.LogicalTable)11 ArrayList (java.util.ArrayList)10 LogicalColumn (org.pentaho.metadata.model.LogicalColumn)9 Category (org.pentaho.metadata.model.Category)8 Matchers.anyString (org.mockito.Matchers.anyString)7 SqlPhysicalModel (org.pentaho.metadata.model.SqlPhysicalModel)7 SqlPhysicalTable (org.pentaho.metadata.model.SqlPhysicalTable)6 IMetadataDomainRepository (org.pentaho.metadata.repository.IMetadataDomainRepository)6 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)6 DomainIdNullException (org.pentaho.metadata.repository.DomainIdNullException)5 DomainStorageException (org.pentaho.metadata.repository.DomainStorageException)5 ConnectionServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException)5 DatasourceServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)5 IOException (java.io.IOException)4 SqlDataSource (org.pentaho.metadata.model.SqlDataSource)4