Search in sources :

Example 16 with MondrianCatalog

use of org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog in project pentaho-platform by pentaho.

the class PentahoPlatformExporterTest method executeExportMondrianSchemasForDataSourceInfo.

private void executeExportMondrianSchemasForDataSourceInfo(String catalogName, String dataSourceInfo) throws IOException {
    PentahoSystem.registerObject(mondrianCatalogService);
    exporterSpy.setMondrianCatalogRepositoryHelper(mondrianCatalogRepositoryHelper);
    List<MondrianCatalog> catalogs = new ArrayList<>();
    MondrianCatalog catalog = new MondrianCatalog(catalogName, dataSourceInfo, null, null);
    catalogs.add(catalog);
    when(mondrianCatalogService.listCatalogs(any(IPentahoSession.class), anyBoolean())).thenReturn(catalogs);
    Map<String, InputStream> inputMap = new HashMap<>();
    InputStream is = mock(InputStream.class);
    when(is.read(any((new byte[] {}).getClass()))).thenReturn(-1);
    inputMap.put(catalogName, is);
    when(mondrianCatalogRepositoryHelper.getModrianSchemaFiles(catalogName)).thenReturn(inputMap);
    exporterSpy.zos = mock(ZipOutputStream.class);
    exporterSpy.exportMondrianSchemas();
}
Also used : MondrianCatalog(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog) HashMap(java.util.HashMap) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) InputStream(java.io.InputStream) ZipOutputStream(java.util.zip.ZipOutputStream) ArrayList(java.util.ArrayList) Mockito.anyString(org.mockito.Mockito.anyString)

Example 17 with MondrianCatalog

use of org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog in project pentaho-platform by pentaho.

the class MDXBaseComponentTest method shouldAddSolutionPrefixIfFileExistsInRepository.

@Test
@SuppressWarnings("unchecked")
public void shouldAddSolutionPrefixIfFileExistsInRepository() throws ObjectFactoryException, DBDatasourceServiceException {
    mdxBaseComponent.setActionDefinition(connAction);
    when(connAction.getMdxConnectionString()).thenReturn(IActionInput.NULL_INPUT);
    when(connAction.getConnectionProps()).thenReturn(IActionInput.NULL_INPUT);
    when(connAction.getConnection()).thenReturn(IActionInput.NULL_INPUT);
    when(connAction.getJndi()).thenReturn(new ActionInputConstant("", null));
    when(connAction.getLocation()).thenReturn(new ActionInputConstant("", null));
    when(connAction.getRole()).thenReturn(IActionInput.NULL_INPUT);
    when(connAction.getCatalog()).thenReturn(IActionInput.NULL_INPUT);
    when(connAction.getUserId()).thenReturn(IActionInput.NULL_INPUT);
    when(connAction.getPassword()).thenReturn(IActionInput.NULL_INPUT);
    when(connAction.getCatalogResource()).thenReturn(catalogResource);
    when(catalogResource.getName()).thenReturn("catalog name");
    PentahoSystem.registerObject(mdxConnection);
    PentahoSystem.registerPrimaryObjectFactory(objFactory);
    PentahoSessionHolder.setSession(session);
    when(objFactory.get(any(Class.class), anyString(), any(IPentahoSession.class))).thenReturn(mdxConnection);
    IDBDatasourceService datasourceService = mock(IDBDatasourceService.class);
    when(objFactory.objectDefined("IDBDatasourceService")).thenReturn(true);
    when(objFactory.get(any(Class.class), eq("IDBDatasourceService"), any(IPentahoSession.class))).thenReturn(datasourceService);
    DataSource dataSource = mock(DataSource.class);
    when(datasourceService.getDataSource(anyString())).thenReturn(dataSource);
    mdxBaseComponent.setRuntimeContext(runtimeContext);
    when(runtimeContext.getResourceDefintion("catalog name")).thenReturn(catalogActionSeqRes);
    when(catalogActionSeqRes.getSourceType()).thenReturn(IActionSequenceResource.URL_RESOURCE);
    MondrianCatalog mc = mock(MondrianCatalog.class);
    doReturn(mc).when(mdxBaseComponent).getMondrianCatalog(anyString());
    // using the same prepared environment for several checks...
    // if file exists in repository, then the "solution:" prefix should be added
    when(catalogActionSeqRes.getAddress()).thenReturn("fileName");
    doReturn(true).when(mdxBaseComponent).fileExistsInRepository("fileName");
    mdxBaseComponent.getConnectionOrig();
    verify(mdxBaseComponent).getMondrianCatalog("solution:fileName");
    verify(mdxBaseComponent, times(1)).fileExistsInRepository(anyString());
    // if file exists in repository, then the "solution:" prefix should NOT be added,
    // and the file therefore should be read from file system further
    when(catalogActionSeqRes.getAddress()).thenReturn("fileName");
    doReturn(false).when(mdxBaseComponent).fileExistsInRepository("fileName");
    mdxBaseComponent.getConnectionOrig();
    verify(mdxBaseComponent).getMondrianCatalog("fileName");
    verify(mdxBaseComponent, times(2)).fileExistsInRepository(anyString());
    // if filename already starts from "solution:" prefix,
    // then no need to check file existence in repository
    when(catalogActionSeqRes.getAddress()).thenReturn("solution:fileName");
    mdxBaseComponent.getConnectionOrig();
    verify(mdxBaseComponent, times(2)).fileExistsInRepository(anyString());
    // same here: if the resource is http link, then no need to check it in repository
    when(catalogActionSeqRes.getAddress()).thenReturn("http:fileName");
    mdxBaseComponent.getConnectionOrig();
    verify(mdxBaseComponent, times(2)).fileExistsInRepository(anyString());
}
Also used : MondrianCatalog(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog) ActionInputConstant(org.pentaho.actionsequence.dom.ActionInputConstant) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) IDBDatasourceService(org.pentaho.platform.api.data.IDBDatasourceService) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 18 with MondrianCatalog

use of org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog in project pentaho-platform by pentaho.

the class UserConsoleResource method getMondrianCatalogs.

/**
 * Return the list of mondrian cubes in the platform
 *
 * @return list of cubes
 */
@GET
@Path("/cubes")
@Facet(name = "Unsupported")
@Produces({ APPLICATION_JSON, APPLICATION_XML })
public List<Cube> getMondrianCatalogs() {
    ArrayList<Cube> cubes = new ArrayList<Cube>();
    IMondrianCatalogService catalogService = PentahoSystem.get(IMondrianCatalogService.class, "IMondrianCatalogService", UserConsoleService.getPentahoSession());
    List<MondrianCatalog> catalogs = catalogService.listCatalogs(UserConsoleService.getPentahoSession(), true);
    for (MondrianCatalog cat : catalogs) {
        for (MondrianCube cube : cat.getSchema().getCubes()) {
            cubes.add(new Cube(cat.getName(), cube.getName(), cube.getId()));
        }
    }
    return cubes;
}
Also used : MondrianCatalog(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog) MondrianCube(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCube) ArrayList(java.util.ArrayList) MondrianCube(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCube) IMondrianCatalogService(org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Facet(org.codehaus.enunciate.Facet)

Example 19 with MondrianCatalog

use of org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog in project data-access by pentaho.

the class ModelerServiceIT method testRemoveCatalogDuringSerializeModels.

@Test
public void testRemoveCatalogDuringSerializeModels() throws Exception {
    when(policy.isAllowed(anyString())).thenReturn(Boolean.TRUE);
    when(pluginResourceLoader.getPluginSetting((Class) anyObject(), anyString(), anyString())).thenReturn(SimpleDataAccessPermissionHandler.class.getName());
    MondrianCatalog mockCatalog = mock(MondrianCatalog.class);
    when(mondrianCatalogService.getCatalog(anyString(), (IPentahoSession) anyObject())).thenReturn(mockCatalog);
    modelerService.serializeModels(domain, TEST_CATALOG_NAME);
    // verify removeCatalog is called
    verify(mondrianCatalogService, times(1)).removeCatalog(anyString(), (IPentahoSession) anyObject());
}
Also used : MondrianCatalog(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog) Test(org.junit.Test)

Example 20 with MondrianCatalog

use of org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog in project data-access by pentaho.

the class AnalysisService method getAnalysisDatasourceIds.

public List<String> getAnalysisDatasourceIds() {
    List<String> analysisIds = new ArrayList<String>();
    List<MondrianCatalog> mockMondrianCatalogList = mondrianCatalogService.listCatalogs(getSession(), false);
    Set<String> ids = metadataDomainRepository.getDomainIds();
    for (MondrianCatalog mondrianCatalog : mockMondrianCatalogList) {
        String domainId = mondrianCatalog.getName() + METADATA_EXT;
        if (!ids.contains(domainId)) {
            analysisIds.add(mondrianCatalog.getName());
        }
    }
    return analysisIds;
}
Also used : MondrianCatalog(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog) ArrayList(java.util.ArrayList)

Aggregations

MondrianCatalog (org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog)28 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)13 IMondrianCatalogService (org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService)13 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)4 Properties (java.util.Properties)4 InputStream (java.io.InputStream)3 SQLException (java.sql.SQLException)3 MondrianException (mondrian.olap.MondrianException)3 IPentahoConnection (org.pentaho.commons.connection.IPentahoConnection)3 MondrianSchema (org.pentaho.platform.plugin.action.mondrian.catalog.MondrianSchema)3 MDXConnection (org.pentaho.platform.plugin.services.connections.mondrian.MDXConnection)3 IOException (java.io.IOException)2 ZipOutputStream (java.util.zip.ZipOutputStream)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Connection (mondrian.olap.Connection)2 Util (mondrian.olap.Util)2 RolapConnection (mondrian.rolap.RolapConnection)2