use of org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog 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);
}
use of org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog 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);
}
use of org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog in project pentaho-platform by pentaho.
the class MondrianImportHandler method importFile.
/**
* **************************************** Main entry point from the Spring Interface
*
* @param IPlatformImportBundle
* @throws IOException
* @throws DomainStorageException
* @throws DomainAlreadyExistsException
* @throws DomainIdNullException
* @throws PlatformImportException
* @throws SAXException
* @throws ParserConfigurationException
*/
public void importFile(IPlatformImportBundle bundle) throws PlatformImportException, DomainIdNullException, DomainAlreadyExistsException, DomainStorageException, IOException {
boolean overwriteInRepossitory = bundle.overwriteInRepository();
boolean xmla = "false".equalsIgnoreCase(findParameterPropertyValue(bundle, ENABLE_XMLA)) ? false : true;
final String domainId = (String) bundle.getProperty(DOMAIN_ID);
if (domainId == null) {
throw new PlatformImportException("Bundle missing required domain-id property");
}
try {
InputStream is = bundle.getInputStream();
MondrianCatalog catalog = this.createCatalogObject(domainId, xmla, bundle);
IPentahoSession session = PentahoSessionHolder.getSession();
if (mondrianRepositoryImporter instanceof IAclAwareMondrianCatalogService) {
RepositoryFileAcl acl = bundle.isApplyAclSettings() ? bundle.getAcl() : null;
IAclAwareMondrianCatalogService aware = (IAclAwareMondrianCatalogService) mondrianRepositoryImporter;
aware.addCatalog(is, catalog, overwriteInRepossitory, acl, session);
} else {
mondrianRepositoryImporter.addCatalog(is, catalog, overwriteInRepossitory, session);
}
} catch (MondrianCatalogServiceException mse) {
int statusCode = convertExceptionToStatus(mse);
throw new PlatformImportException(mse.getMessage(), statusCode);
} catch (Exception e) {
throw new PlatformImportException(e.getMessage(), PlatformImportException.PUBLISH_GENERAL_ERROR);
}
}
use of org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog in project pentaho-platform by pentaho.
the class MondrianImportHandler method createCatalogObject.
/**
* Helper method to create a catalog object
*/
protected MondrianCatalog createCatalogObject(String catName, boolean xmlaEnabled, IPlatformImportBundle bundle) throws ParserConfigurationException, SAXException, IOException, PlatformImportException {
final Map<String, String> parameters = findParameters(bundle);
final String dsName = findParameterPropertyValue(bundle, DATA_SOURCE);
final String provider;
if (parameters.containsKey(PROVIDER)) {
provider = findParameterPropertyValue(bundle, PROVIDER);
} else {
// Defaults to 'mondrian'
provider = DEFAULT_PROVIDER;
}
StringBuilder sb = new StringBuilder();
if (dsName != null) {
sb.append("DataSource=\"").append(StringEscapeUtils.escapeXml(dsName.replaceAll(""", "\""))).append("\";");
}
if (!parameters.containsKey("EnableXmla")) {
sb.append("EnableXmla=").append(xmlaEnabled).append(";");
}
sb.append("Provider=\"").append(StringEscapeUtils.escapeXml(provider.replaceAll(""", "\""))).append("\"");
// Build a list of the remaining properties
for (Entry<String, String> parameter : parameters.entrySet()) {
if (!parameter.getKey().equals(DATA_SOURCE) && !parameter.getKey().equals(PROVIDER)) {
// value contains custom-escaped quotes.
// It needs custom unescape and standard escapeXml for following mondrian parsing
String parseSafeValue = StringEscapeUtils.escapeXml(parameter.getValue().replaceAll(""", "\""));
sb.append(";");
sb.append(parameter.getKey());
sb.append("=\"");
sb.append(parseSafeValue);
sb.append("\"");
}
}
MondrianCatalog catalog = new MondrianCatalog(catName, sb.toString(), provider + ":" + RepositoryFile.SEPARATOR + catName, null, null);
return catalog;
}
use of org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog 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();
}
}
}
};
}
Aggregations