Search in sources :

Example 6 with IMondrianCatalogService

use of org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService 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 7 with IMondrianCatalogService

use of org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService 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 8 with IMondrianCatalogService

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

the class AnalysisService method processMondrianImport.

/**
 * This is the main method that handles the actual Import Handler to persist to PUR
 *
 * @param dataInputStream
 * @param catalogName
 * @param overwrite
 * @param xmlaEnabledFlag
 * @param parameters
 * @param fileName
 * @param acl acl information for the data source. This parameter is optional.
 * @throws PlatformImportException
 */
protected void processMondrianImport(InputStream dataInputStream, String catalogName, String origCatalogName, boolean overwrite, boolean xmlaEnabledFlag, String parameters, String fileName, RepositoryFileAclDto acl) throws PlatformImportException {
    boolean overWriteInRepository = determineOverwriteFlag(parameters, overwrite);
    IPlatformImportBundle bundle = createPlatformBundle(parameters, dataInputStream, catalogName, overWriteInRepository, fileName, xmlaEnabledFlag, acl);
    if (isChangeCatalogName(origCatalogName, bundle)) {
        IMondrianCatalogService catalogService = PentahoSystem.get(IMondrianCatalogService.class, PentahoSessionHolder.getSession());
        catalogService.removeCatalog(origCatalogName, PentahoSessionHolder.getSession());
    }
    if (isOverwriteAnnotations(parameters, overWriteInRepository)) {
        IMondrianCatalogService catalogService = PentahoSystem.get(IMondrianCatalogService.class, PentahoSessionHolder.getSession());
        List<MondrianCatalog> catalogs = catalogService.listCatalogs(PentahoSessionHolder.getSession(), false);
        for (MondrianCatalog catalog : catalogs) {
            if (catalog.getName().equals(bundle.getName())) {
                catalogService.removeCatalog(bundle.getName(), PentahoSessionHolder.getSession());
                break;
            }
        }
    }
    importer.importFile(bundle);
}
Also used : IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) MondrianCatalog(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog) IMondrianCatalogService(org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService)

Example 9 with IMondrianCatalogService

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

the class PentahoXmlaServlet method createConnectionFactory.

@Override
protected ConnectionFactory createConnectionFactory(final ServletConfig servletConfig) throws ServletException {
    final ConnectionFactory delegate = super.createConnectionFactory(servletConfig);
    /*
     * This wrapper for the connection factory allows us to
     * override the list of roles with the ones defined in
     * the IPentahoSession and filter it through the
     * IConnectionUserRoleMapper.
     */
    return new ConnectionFactory() {

        public Map<String, Object> getPreConfiguredDiscoverDatasourcesResponse() {
            return delegate.getPreConfiguredDiscoverDatasourcesResponse();
        }

        public OlapConnection getConnection(String databaseName, String catalogName, String roleName, Properties props) throws SQLException {
            // What we do here is to filter the role names with the mapper.
            // First, get a user role mapper, if one is configured.
            final IPentahoSession session = PentahoSessionHolder.getSession();
            final IConnectionUserRoleMapper mondrianUserRoleMapper = PentahoSystem.get(IConnectionUserRoleMapper.class, MDXConnection.MDX_CONNECTION_MAPPER_KEY, // Don't use the user session here yet.
            null);
            String[] effectiveRoles = new String[0];
            /*
         * If Catalog/Schema are null (this happens with high level metadata requests,
         * like DISCOVER_DATASOURCES) we can't use the role mapper, even if it
         * is present and configured.
         */
            if (mondrianUserRoleMapper != null && catalogName != null) {
                // Use the role mapper.
                try {
                    effectiveRoles = mondrianUserRoleMapper.mapConnectionRoles(session, catalogName);
                    if (effectiveRoles == null) {
                        effectiveRoles = new String[0];
                    }
                } catch (PentahoAccessControlException e) {
                    throw new SQLException(e);
                }
            }
            // Now we tokenize that list.
            boolean addComma = false;
            // $NON-NLS-1$
            roleName = "";
            for (String role : effectiveRoles) {
                if (addComma) {
                    // $NON-NLS-1$
                    roleName = roleName.concat(",");
                }
                roleName = roleName.concat(role);
                addComma = true;
            }
            // Now let the delegate connection factory do its magic.
            if (catalogName == null) {
                return delegate.getConnection(databaseName, catalogName, roleName.equals("") ? null : roleName, props);
            } else {
                // We create a connection differently so we can ensure that
                // the XMLA servlet shares the same MondrianServer instance as the rest
                // of the platform
                IMondrianCatalogService mcs = PentahoSystem.get(IMondrianCatalogService.class);
                MondrianCatalog mc = mcs.getCatalog(catalogName, PentahoSessionHolder.getSession());
                if (mc == null) {
                    throw new XmlaException(CLIENT_FAULT_FC, HSB_BAD_RESTRICTION_LIST_CODE, HSB_BAD_RESTRICTION_LIST_FAULT_FS, new MondrianException("No such catalog: " + catalogName));
                }
                Connection con = DriverManager.getConnection(mc.getDataSourceInfo() + ";Catalog=" + mc.getDefinition(), catalogLocator);
                try {
                    final MondrianServer server = MondrianServer.forConnection(con);
                    FileRepository fr = new FileRepository(makeContentFinder(makeDataSourcesUrl(servletConfig)), catalogLocator);
                    OlapConnection connection = fr.getConnection(server, databaseName, catalogName, roleName, props);
                    fr.shutdown();
                    return connection;
                } finally {
                    con.close();
                }
            }
        }
    };
}
Also used : FileRepository(mondrian.server.FileRepository) MondrianServer(mondrian.olap.MondrianServer) MondrianCatalog(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog) SQLException(java.sql.SQLException) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) IConnectionUserRoleMapper(org.pentaho.platform.api.engine.IConnectionUserRoleMapper) OlapConnection(org.olap4j.OlapConnection) OlapConnection(org.olap4j.OlapConnection) MDXConnection(org.pentaho.platform.plugin.services.connections.mondrian.MDXConnection) Connection(mondrian.olap.Connection) Properties(java.util.Properties) IMondrianCatalogService(org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) ConnectionFactory(mondrian.xmla.XmlaHandler.ConnectionFactory) SolutionRepositoryVfsFileObject(org.pentaho.platform.repository.solution.filebased.SolutionRepositoryVfsFileObject) XmlaException(mondrian.xmla.XmlaException) MondrianException(mondrian.olap.MondrianException)

Example 10 with IMondrianCatalogService

use of org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService 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)

Aggregations

IMondrianCatalogService (org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService)13 MondrianCatalog (org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog)10 Produces (javax.ws.rs.Produces)4 Facet (org.codehaus.enunciate.Facet)4 Properties (java.util.Properties)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 MondrianException (mondrian.olap.MondrianException)3 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)3 MDXConnection (org.pentaho.platform.plugin.services.connections.mondrian.MDXConnection)3 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 Connection (mondrian.olap.Connection)2 Util (mondrian.olap.Util)2 RolapConnection (mondrian.rolap.RolapConnection)2 Pair (mondrian.util.Pair)2 OlapConnection (org.olap4j.OlapConnection)2 ModelerWorkspace (org.pentaho.agilebi.modeler.ModelerWorkspace)2 LogicalModel (org.pentaho.metadata.model.LogicalModel)2 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)2