Search in sources :

Example 1 with IOlapService

use of org.pentaho.platform.plugin.action.olap.IOlapService in project pentaho-platform by pentaho.

the class SystemRefreshResource method flushMondrianSchemaCache.

@GET
@Path("/mondrianSchemaCache")
@Produces({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
@Facet(name = "Unsupported")
public Response flushMondrianSchemaCache() {
    if (canAdminister()) {
        IPentahoSession pentahoSession = PentahoSessionHolder.getSession();
        if (canAdminister()) {
            // Flush the catalog helper (legacy)
            IMondrianCatalogService mondrianCatalogService = // $NON-NLS-1$
            PentahoSystem.get(IMondrianCatalogService.class, "IMondrianCatalogService", pentahoSession);
            mondrianCatalogService.reInit(pentahoSession);
            // Flush the IOlapService
            IOlapService olapService = // $NON-NLS-1$
            PentahoSystem.get(IOlapService.class, "IOlapService", pentahoSession);
            olapService.flushAll(pentahoSession);
        }
        return Response.ok().type(MediaType.TEXT_PLAIN).build();
    } else {
        return Response.status(UNAUTHORIZED).build();
    }
}
Also used : IOlapService(org.pentaho.platform.plugin.action.olap.IOlapService) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) 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 2 with IOlapService

use of org.pentaho.platform.plugin.action.olap.IOlapService 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 IOlapService

use of org.pentaho.platform.plugin.action.olap.IOlapService in project pentaho-platform by pentaho.

the class MondrianCatalogHelper method flushCacheForCatalog.

private void flushCacheForCatalog(String catalogName, IPentahoSession pentahoSession) {
    IOlapService olapService = PentahoSystem.get(IOlapService.class, "IOlapService", pentahoSession);
    Connection unwrap = null;
    try {
        OlapConnection connection = olapService.getConnection(catalogName, pentahoSession);
        unwrap = connection.unwrap(Connection.class);
        unwrap.getCacheControl(null).flushSchema(unwrap.getSchema());
    } catch (Throwable e) {
        MondrianCatalogHelper.logger.warn(Messages.getInstance().getErrorString("MondrianCatalogHelper.ERROR_0019_FAILED_TO_FLUSH", catalogName), e);
    } finally {
        if (unwrap != null) {
            unwrap.close();
        }
    }
}
Also used : IOlapService(org.pentaho.platform.plugin.action.olap.IOlapService) OlapConnection(org.olap4j.OlapConnection) OlapConnection(org.olap4j.OlapConnection) Connection(mondrian.olap.Connection)

Example 4 with IOlapService

use of org.pentaho.platform.plugin.action.olap.IOlapService in project pentaho-platform by pentaho.

the class SystemRefreshResource method flushMondrianSchemaCache.

@GET
@Path("/mondrianSingleSchemaCache")
@Produces({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
@Facet(name = "Unsupported")
public Response flushMondrianSchemaCache(@QueryParam("name") String name) {
    if (canAdminister()) {
        IPentahoSession pentahoSession = PentahoSessionHolder.getSession();
        if (canAdminister()) {
            IOlapService olapService = // $NON-NLS-1$
            PentahoSystem.get(IOlapService.class, "IOlapService", pentahoSession);
            olapService.flush(pentahoSession, name);
        }
        return Response.ok().type(MediaType.TEXT_PLAIN).build();
    } else {
        return Response.status(UNAUTHORIZED).build();
    }
}
Also used : IOlapService(org.pentaho.platform.plugin.action.olap.IOlapService) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Facet(org.codehaus.enunciate.Facet)

Aggregations

IOlapService (org.pentaho.platform.plugin.action.olap.IOlapService)4 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Facet (org.codehaus.enunciate.Facet)2 OlapConnection (org.olap4j.OlapConnection)2 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)2 IMondrianCatalogService (org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService)2 SQLException (java.sql.SQLException)1 Connection (mondrian.olap.Connection)1 PropertyList (mondrian.olap.Util.PropertyList)1 OlapException (org.olap4j.OlapException)1 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)1 MondrianCatalog (org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog)1 MondrianSchema (org.pentaho.platform.plugin.action.mondrian.catalog.MondrianSchema)1 MondrianCatalogRepositoryHelper (org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper)1