Search in sources :

Example 1 with MondrianSchema

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

the class UserRoleMapperIT method testReadRolesInSchema.

@Test
public void testReadRolesInSchema() throws Exception {
    final MondrianCatalogHelper helper = (MondrianCatalogHelper) PentahoSystem.get(IMondrianCatalogService.class);
    Assert.assertNotNull(helper);
    MondrianCatalog mc = SecurityHelper.getInstance().runAsUser("admin", new Callable<MondrianCatalog>() {

        @Override
        public MondrianCatalog call() throws Exception {
            return helper.getCatalog("SteelWheelsRoles", PentahoSessionHolder.getSession());
        }
    });
    Assert.assertNotNull(mc);
    MondrianSchema ms = mc.getSchema();
    Assert.assertNotNull(ms);
    String[] roleNames = ms.getRoleNames();
    Assert.assertNotNull(roleNames);
    Assert.assertEquals(2, roleNames.length);
    Assert.assertEquals("Role1", roleNames[0]);
    Assert.assertEquals("Role2", roleNames[1]);
}
Also used : MondrianCatalogHelper(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogHelper) MondrianCatalog(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog) MondrianSchema(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianSchema) IMondrianCatalogService(org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) PlatformInitializationException(org.pentaho.platform.engine.core.system.boot.PlatformInitializationException) DataAccessException(org.springframework.dao.DataAccessException) Test(org.junit.Test)

Example 2 with MondrianSchema

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

the class MondrianAbstractPlatformUserRoleMapper method getMondrianRolesFromCatalog.

/**
 * This method returns the role names as found in the Mondrian schema. The returned names must be ordered (sorted) or
 * code down-stream will not work.
 *
 * @param userSession
 *          Users' session
 * @param catalogName
 *          The name of the catalog
 * @return Array of role names from the schema file
 */
protected String[] getMondrianRolesFromCatalog(IPentahoSession userSession, String context) {
    String[] rtn = null;
    // Get the catalog service
    IMondrianCatalogService catalogService = PentahoSystem.get(IMondrianCatalogService.class);
    if (catalogService != null) {
        // Get the catalog by name
        MondrianCatalog catalog = catalogService.getCatalog(context, userSession);
        if (catalog != null) {
            // The roles are in the schema object
            MondrianSchema schema = catalog.getSchema();
            if (schema != null) {
                // Ask the schema for the role names array
                String[] roleNames = schema.getRoleNames();
                if ((roleNames != null) && (roleNames.length > 0)) {
                    // Return the roles from the schema
                    Arrays.sort(roleNames);
                    return roleNames;
                }
            }
        }
    }
    // Check with the IOlapService and try to get a list of roles there.
    IOlapService olapService = PentahoSystem.get(IOlapService.class);
    if (olapService != null) {
        MondrianCatalogRepositoryHelper helper = new MondrianCatalogRepositoryHelper(PentahoSystem.get(IUnifiedRepository.class));
        String serverName = null;
        for (String name : helper.getOlap4jServers()) {
            PropertyList props = Util.parseConnectString(helper.getOlap4jServerInfo(name).URL);
            if (props.get(RolapConnectionProperties.Catalog.name(), "").equals(context)) {
                serverName = name;
            }
        }
        if (serverName != null) {
            OlapConnection conn = null;
            try {
                // Use a null session for root access.
                conn = olapService.getConnection(serverName, null);
                List<String> roleList = conn.getAvailableRoleNames();
                String[] roleArray = roleList.toArray(new String[roleList.size()]);
                Arrays.sort(roleArray);
                return roleArray;
            } catch (OlapException e) {
                log.error("Failed to get a list of roles from olap connection " + context, e);
                throw new RuntimeException(e);
            } finally {
                if (conn != null) {
                    try {
                        conn.close();
                    } catch (SQLException e) {
                        // OK to squash this one.
                        log.error("Failed to get a list of roles from olap connection " + context, e);
                    }
                }
            }
        }
    }
    // Sort the returned list of roles.
    return rtn;
}
Also used : MondrianCatalog(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog) IOlapService(org.pentaho.platform.plugin.action.olap.IOlapService) SQLException(java.sql.SQLException) MondrianSchema(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianSchema) OlapConnection(org.olap4j.OlapConnection) OlapException(org.olap4j.OlapException) MondrianCatalogRepositoryHelper(org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper) IMondrianCatalogService(org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService) PropertyList(mondrian.olap.Util.PropertyList) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository)

Example 3 with MondrianSchema

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

the class ModelerService method addCatalog.

private void addCatalog(String catName, String catConnectStr, IPentahoSession session) {
    IMondrianCatalogService mondrianCatalogService = // $NON-NLS-1$
    PentahoSystem.get(IMondrianCatalogService.class, "IMondrianCatalogService", session);
    String dsUrl = PentahoSystem.getApplicationContext().getBaseUrl();
    if (!dsUrl.endsWith("/")) {
        // $NON-NLS-1$
        // $NON-NLS-1$
        dsUrl += "/";
    }
    // $NON-NLS-1$
    dsUrl += "Xmla";
    MondrianCatalog cat = new MondrianCatalog(catName, catConnectStr, "", new MondrianSchema(catName, new ArrayList<MondrianCube>()));
    mondrianCatalogService.addCatalog(cat, true, session);
}
Also used : MondrianCatalog(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog) MondrianSchema(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianSchema) ArrayList(java.util.ArrayList) IMondrianCatalogService(org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService)

Example 4 with MondrianSchema

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

the class AnalysisServiceTest method testGetAnalysisDatasourceIds.

@Test
public void testGetAnalysisDatasourceIds() throws Exception {
    final MondrianCatalog foodmartCatalog = new MondrianCatalog("foodmart", "info", "file:///place", new MondrianSchema("foodmart", Collections.emptyList()));
    final MondrianCatalog foodmartCatalog2 = new MondrianCatalog("foodmart2", "info", "file:///place", new MondrianSchema("foodmart2", Collections.emptyList()));
    final List<MondrianCatalog> catalogs = Arrays.asList(foodmartCatalog, foodmartCatalog2);
    doReturn(catalogs).when(catalogService).listCatalogs(any(IPentahoSession.class), eq(false));
    final HashSet<String> domainIds = Sets.newHashSet("foodmart.xmi", "sample.xmi");
    doReturn(domainIds).when(metadataRepository).getDomainIds();
    final List<String> response = analysisService.getAnalysisDatasourceIds();
    assertEquals(Collections.singletonList("foodmart2"), response);
}
Also used : MondrianCatalog(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog) MondrianSchema(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianSchema) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Test(org.junit.Test)

Aggregations

MondrianCatalog (org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog)4 MondrianSchema (org.pentaho.platform.plugin.action.mondrian.catalog.MondrianSchema)4 IMondrianCatalogService (org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService)3 Test (org.junit.Test)2 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 PropertyList (mondrian.olap.Util.PropertyList)1 OlapConnection (org.olap4j.OlapConnection)1 OlapException (org.olap4j.OlapException)1 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)1 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)1 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)1 PlatformInitializationException (org.pentaho.platform.engine.core.system.boot.PlatformInitializationException)1 MondrianCatalogHelper (org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogHelper)1 IOlapService (org.pentaho.platform.plugin.action.olap.IOlapService)1 MondrianCatalogRepositoryHelper (org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper)1 DataAccessException (org.springframework.dao.DataAccessException)1 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)1