Search in sources :

Example 1 with PropertyList

use of mondrian.olap.Util.PropertyList 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 2 with PropertyList

use of mondrian.olap.Util.PropertyList in project mondrian by pentaho.

the class MondrianOlap4jExtra method getDataSources.

public List<Map<String, Object>> getDataSources(OlapConnection connection) throws OlapException {
    MondrianOlap4jConnection olap4jConnection = (MondrianOlap4jConnection) connection;
    MondrianServer server = MondrianServer.forConnection(olap4jConnection.getMondrianConnection());
    final List<Map<String, Object>> databases = server.getDatabases(olap4jConnection.getMondrianConnection());
    // it here. This is only called by the XMLA servlets.
    for (Map<String, Object> db : databases) {
        String dsi = (String) db.get("DataSourceInfo");
        if (dsi == null) {
            break;
        }
        PropertyList pl = Util.parseConnectString(dsi);
        boolean removed = pl.remove(RolapConnectionProperties.Jdbc.name());
        removed |= pl.remove(RolapConnectionProperties.JdbcUser.name());
        removed |= pl.remove(RolapConnectionProperties.JdbcPassword.name());
        if (removed) {
            db.put("DataSourceInfo", pl.toString());
        }
    }
    return databases;
}
Also used : PropertyList(mondrian.olap.Util.PropertyList)

Example 3 with PropertyList

use of mondrian.olap.Util.PropertyList in project mondrian by pentaho.

the class FileRepository method getConnection.

public OlapConnection getConnection(MondrianServer server, String databaseName, String catalogName, String roleName, Properties props) throws SQLException {
    final ServerInfo serverInfo = getServerInfo();
    DatabaseInfo datasourceInfo;
    if (databaseName == null) {
        if (serverInfo.datasourceMap.size() == 0) {
            throw new OlapException("No databases configured on this server");
        }
        datasourceInfo = serverInfo.datasourceMap.values().iterator().next();
    } else {
        datasourceInfo = serverInfo.datasourceMap.get(databaseName);
        // that here as well.
        if (datasourceInfo == null) {
            for (DatabaseInfo infos : serverInfo.datasourceMap.values()) {
                PropertyList pl = Util.parseConnectString((String) infos.properties.get("DataSourceInfo"));
                pl.remove(RolapConnectionProperties.Jdbc.name());
                pl.remove(RolapConnectionProperties.JdbcUser.name());
                pl.remove(RolapConnectionProperties.JdbcPassword.name());
                if (pl.toString().equals(databaseName)) {
                    datasourceInfo = infos;
                }
            }
        }
    }
    if (datasourceInfo == null) {
        throw Util.newError("Unknown database '" + databaseName + "'");
    }
    if (catalogName == null) {
        if (datasourceInfo.catalogMap.size() == 0) {
            throw new OlapException("No catalogs in the database named " + datasourceInfo.name);
        }
        for (CatalogInfo catalogInfo : datasourceInfo.catalogMap.values()) {
            try {
                return getConnection(catalogInfo, server, roleName, props);
            } catch (Exception e) {
                LOGGER.warn("Failed getting connection. Skipping", e);
            }
        }
    } else {
        CatalogInfo namedCatalogInfo = datasourceInfo.catalogMap.get(catalogName);
        if (namedCatalogInfo == null) {
            throw Util.newError("Unknown catalog '" + catalogName + "'");
        }
        return getConnection(namedCatalogInfo, server, roleName, props);
    }
    throw Util.newError("No suitable connection found");
}
Also used : PropertyList(mondrian.olap.Util.PropertyList) OlapException(org.olap4j.OlapException) OlapException(org.olap4j.OlapException) SQLException(java.sql.SQLException)

Example 4 with PropertyList

use of mondrian.olap.Util.PropertyList in project mondrian by pentaho.

the class AggTableManager method loadRolapStarAggregates.

/**
 * This method loads and/or reloads the aggregate tables.
 * <p>
 * NOTE: At this point all RolapStars have been made for this
 * schema (except for dynamically added cubes which I am going
 * to ignore for right now). So, All stars have their columns
 * and their BitKeys can be generated.
 *
 * @throws SQLException
 */
private void loadRolapStarAggregates(PropertyList connectInfo) throws SQLException {
    ListRecorder msgRecorder = new ListRecorder();
    try {
        DefaultRules rules = DefaultRules.getInstance();
        JdbcSchema db = getJdbcSchema();
        // calls to other instances of AggTableManager.finalCleanUp()
        synchronized (db) {
            // fix for MONDRIAN-496
            // flush any existing usages of the jdbc schema, so we
            // don't accidentally use another star's metadata
            db.flushUsages();
            // loads tables, not their columns
            db.load(connectInfo);
            loop: for (RolapStar star : getStars()) {
                // This removes any AggStars from any previous invocation of
                // this method (if any)
                star.prepareToLoadAggregates();
                List<ExplicitRules.Group> aggGroups = getAggGroups(star);
                for (ExplicitRules.Group group : aggGroups) {
                    group.validate(msgRecorder);
                }
                String factTableName = getFactTableName(star);
                JdbcSchema.Table dbFactTable = db.getTable(factTableName);
                if (dbFactTable == null) {
                    msgRecorder.reportWarning("No Table found for fact name=" + factTableName);
                    continue loop;
                }
                // For each column in the dbFactTable, figure out it they
                // are measure or foreign key columns
                bindToStar(dbFactTable, star, msgRecorder);
                String schema = dbFactTable.table.schema;
                for (JdbcSchema.Table dbTable : db.getTables()) {
                    String name = dbTable.getName();
                    // this table name.
                    if (ExplicitRules.excludeTable(name, aggGroups)) {
                        continue;
                    }
                    // First see if there is an ExplicitRules match. If so,
                    // then if all of the columns match up, then make an
                    // AggStar. On the other hand, if there is no
                    // ExplicitRules match, see if there is a Default
                    // match. If so and if all the columns match up, then
                    // also make an AggStar.
                    ExplicitRules.TableDef tableDef = ExplicitRules.getIncludeByTableDef(name, aggGroups);
                    boolean makeAggStar = false;
                    int approxRowCount = Integer.MIN_VALUE;
                    // Is it handled by the ExplicitRules
                    if (tableDef != null) {
                        // load columns
                        dbTable.load();
                        makeAggStar = tableDef.columnsOK(star, dbFactTable, dbTable, msgRecorder);
                        approxRowCount = tableDef.getApproxRowCount();
                    }
                    if (!makeAggStar && MondrianProperties.instance().ReadAggregates.get()) {
                        // Is it handled by the DefaultRules
                        if (rules.matchesTableName(factTableName, name)) {
                            // load columns
                            dbTable.load();
                            makeAggStar = rules.columnsOK(star, dbFactTable, dbTable, msgRecorder);
                        }
                    }
                    if (makeAggStar) {
                        dbTable.setTableUsageType(JdbcSchema.TableUsageType.AGG);
                        dbTable.table = new MondrianDef.Table(schema, name, // null alias
                        null, // don't know about table hints
                        null);
                        AggStar aggStar = AggStar.makeAggStar(star, dbTable, msgRecorder, approxRowCount);
                        if (aggStar.getSize() > 0) {
                            star.addAggStar(aggStar);
                        } else {
                            getLogger().warn(mres.AggTableZeroSize.str(aggStar.getFactTable().getName(), factTableName));
                        }
                    }
                // Note: if the dbTable name matches but the columnsOK
                // does not, then this is an error and the aggregate
                // tables can not be loaded.
                // We do not "reset" the column usages in the dbTable
                // allowing it maybe to match another rule.
                }
            }
        }
    } catch (RecorderException ex) {
        throw new MondrianException(ex);
    } finally {
        msgRecorder.logInfoMessage(getLogger());
        msgRecorder.logWarningMessage(getLogger());
        msgRecorder.logErrorMessage(getLogger());
        if (msgRecorder.hasErrors()) {
            throw mres.AggLoadingExceededErrorCount.ex(msgRecorder.getErrorCount());
        }
    }
}
Also used : RolapStar(mondrian.rolap.RolapStar) RecorderException(mondrian.recorder.RecorderException) PropertyList(mondrian.olap.Util.PropertyList) ArrayList(java.util.ArrayList) List(java.util.List) MondrianException(mondrian.olap.MondrianException) ListRecorder(mondrian.recorder.ListRecorder)

Example 5 with PropertyList

use of mondrian.olap.Util.PropertyList in project pentaho-platform by pentaho.

the class MondrianCatalogHelper method applyDSP.

protected String applyDSP(IPentahoSession ps, String catalogDsInfo, String catalogDefinition) throws Exception {
    PropertyList pl = Util.parseConnectString(catalogDsInfo);
    String dsp = pl.get(RolapConnectionProperties.DynamicSchemaProcessor.name());
    if (dsp != null) {
        if (MondrianCatalogHelper.logger.isDebugEnabled()) {
            // $NON-NLS-1$
            MondrianCatalogHelper.logger.debug("applyDSP: " + dsp);
        }
        DynamicSchemaProcessor dynProc = ClassResolver.INSTANCE.instantiateSafe(dsp);
        pl.put("Locale", getLocale().toString());
        return dynProc.processSchema(catalogDefinition, pl);
    } else {
        return docAtUrlToString(catalogDefinition, ps);
    }
}
Also used : PropertyList(mondrian.olap.Util.PropertyList) LocalizingDynamicSchemaProcessor(mondrian.i18n.LocalizingDynamicSchemaProcessor) DynamicSchemaProcessor(mondrian.spi.DynamicSchemaProcessor)

Aggregations

PropertyList (mondrian.olap.Util.PropertyList)11 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 LocalizingDynamicSchemaProcessor (mondrian.i18n.LocalizingDynamicSchemaProcessor)2 MondrianException (mondrian.olap.MondrianException)2 OlapException (org.olap4j.OlapException)2 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Properties (java.util.Properties)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 Transformer (javax.xml.transform.Transformer)1 TransformerFactory (javax.xml.transform.TransformerFactory)1 DOMSource (javax.xml.transform.dom.DOMSource)1 StreamResult (javax.xml.transform.stream.StreamResult)1