use of org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog in project pentaho-platform by pentaho.
the class PentahoPlatformExporter method exportMondrianSchemas.
protected void exportMondrianSchemas() {
log.debug("export mondrian schemas");
// Get the mondrian catalogs available in the repo
List<MondrianCatalog> catalogs = getMondrianCatalogService().listCatalogs(getSession(), false);
for (MondrianCatalog catalog : catalogs) {
// get the files for this catalog
Map<String, InputStream> files = getMondrianCatalogRepositoryHelper().getModrianSchemaFiles(catalog.getName());
ExportManifestMondrian mondrian = new ExportManifestMondrian();
for (String fileName : files.keySet()) {
// write the file to the zip
String path = ANALYSIS_PATH_IN_ZIP + catalog.getName() + "/" + fileName;
ZipEntry zipEntry = new ZipEntry(new ZipEntry(ExportFileNameEncoder.encodeZipPathName(path)));
InputStream inputStream = files.get(fileName);
// ignore *.annotated.xml files, they are not needed
if (fileName.equals("schema.annotated.xml")) {
// with the original schema xml file to re-generate the model properly
continue;
} else if (MondrianVfs.ANNOTATIONS_XML.equals(fileName)) {
// annotations.xml should be written to the zip file and referenced in the export manifest entry for the
// related mondrian model
mondrian.setAnnotationsFile(path);
} else {
// must be a true mondrian model
mondrian.setCatalogName(catalog.getName());
boolean xmlaEnabled = parseXmlaEnabled(catalog.getDataSourceInfo());
mondrian.setXmlaEnabled(xmlaEnabled);
mondrian.setFile(path);
Parameters mondrianParameters = new Parameters();
mondrianParameters.put("Provider", "mondrian");
// DataSource can be escaped
mondrianParameters.put("DataSource", StringEscapeUtils.unescapeXml(catalog.getJndi()));
mondrianParameters.put("EnableXmla", Boolean.toString(xmlaEnabled));
StreamSupport.stream(catalog.getConnectProperties().spliterator(), false).filter(p -> !mondrianParameters.containsKey(p.getKey())).forEach(p -> mondrianParameters.put(p.getKey(), StringEscapeUtils.unescapeXml(p.getValue())));
mondrian.setParameters(mondrianParameters);
}
try {
zos.putNextEntry(zipEntry);
IOUtils.copy(inputStream, zos);
} catch (IOException e) {
log.warn(e.getMessage(), e);
} finally {
IOUtils.closeQuietly(inputStream);
try {
zos.closeEntry();
} catch (IOException e) {
// can't close the entry of input stream
}
}
}
if (mondrian.getCatalogName() != null && mondrian.getFile() != null) {
getExportManifest().addMondrian(mondrian);
}
}
}
use of org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog 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]);
}
use of org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog in project pentaho-platform by pentaho.
the class MondrianImportHandlerTest method testCreateCatalogObject_SpecificSymbolsInBundle.
@Test
public void testCreateCatalogObject_SpecificSymbolsInBundle() throws Exception {
// createCatalogObject method has input parameters with custom-escaped only quotes
// should unescape it and escape all symbols by standard escapeXml
IPlatformImportBundle customBundle = mock(IPlatformImportBundle.class);
parameters = MondrianImportHandler.PROVIDER + "=provider;" + MondrianImportHandler.DATA_SOURCE + "=\"DS "Test's" & <Fun>\";" + "DynamicSchemaProcessor=\"DSP's & "Other" <stuff>\"";
String expectedValue = new StringBuilder().append("DataSource=\"DS "Test's" & <Fun>\";").append("EnableXmla=true;").append("Provider=\"provider\";").append("DynamicSchemaProcessor=\"DSP's & "Other" <stuff>\"").toString();
when(customBundle.getProperty(eq(MondrianImportHandler.ENABLE_XMLA))).thenReturn("true");
when(customBundle.getProperty(eq(MondrianImportHandler.DATA_SOURCE))).thenReturn("DS "Test's" & <Fun>");
when(customBundle.getProperty(eq(MondrianImportHandler.PARAMETERS))).thenReturn(parameters);
MondrianImportHandler mondrianImportHandler = new MondrianImportHandler(mimeTypes, mondrianImporter);
MondrianCatalog catalog = mondrianImportHandler.createCatalogObject("catalog", true, customBundle);
assertEquals(catalog.getDataSourceInfo(), expectedValue);
}
use of org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog in project pentaho-platform by pentaho.
the class PentahoXmlaServletTest method createConnectionFactory.
@Test
public void createConnectionFactory() throws Exception {
ISecurityHelper securityHelper = mock(ISecurityHelper.class);
SecurityHelper.setMockInstance(securityHelper);
when(securityHelper.runAsSystem(any((Callable.class)))).thenReturn(DATASOURCE_XML);
IMondrianCatalogService catalogService = mock(MondrianCatalogHelper.class);
MondrianCatalog mondrianCatalog = mock(MondrianCatalog.class);
when(mondrianCatalog.getDataSourceInfo()).thenReturn("DataSource=foo");
doReturn(mondrianCatalog).when(catalogService).getCatalog(anyString(), anyObject());
PowerMockito.mockStatic(DriverManager.class);
when(DriverManager.getConnection(anyString(), anyObject())).thenReturn(mock(RolapConnection.class));
PentahoSystem.registerObject(catalogService);
PentahoXmlaServlet xmlaServlet = spy(new PentahoXmlaServlet());
XmlaHandler.ConnectionFactory connectionFactory = xmlaServlet.createConnectionFactory(mock(ServletConfig.class));
Properties properties = new Properties();
properties.put("DataSource", "bogus");
try {
connectionFactory.getConnection("SampleData", "SampleData", "baz", properties);
} catch (MondrianException exception) {
// ignored
}
try {
connectionFactory.getConnection("SampleData", "SampleData", "baz", properties);
} catch (MondrianException exception) {
// ignored
}
// We verify that only one Catalog Locator is created for multiple requests
verify(xmlaServlet, times(1)).makeCatalogLocator(anyObject());
}
use of org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog in project pentaho-platform by pentaho.
the class MDXBaseComponent method getConnection.
protected IPentahoConnection getConnection() {
// first attempt to get the connection metadata from the catalog service. if that is not successful,
// get the connection using the original approach.
MdxConnectionAction connAction = (MdxConnectionAction) getActionDefinition();
String catalogName = connAction.getCatalog().getStringValue();
IMondrianCatalogService mondrianCatalogService = // $NON-NLS-1$
PentahoSystem.get(IMondrianCatalogService.class, "IMondrianCatalogService", PentahoSessionHolder.getSession());
MondrianCatalog catalog = mondrianCatalogService.getCatalog(catalogName, PentahoSessionHolder.getSession());
if (catalog == null) {
return getConnectionOrig();
}
Util.PropertyList connectProperties = Util.parseConnectString(catalog.getDataSourceInfo());
Properties properties = new Properties();
Iterator<Pair<String, String>> iter = connectProperties.iterator();
while (iter.hasNext()) {
Pair<String, String> pair = iter.next();
properties.put(pair.getKey(), pair.getValue());
}
properties.put("Catalog", catalog.getDefinition());
properties.put("Provider", "mondrian");
properties.put("PoolNeeded", "false");
properties.put(RolapConnectionProperties.Locale.name(), LocaleHelper.getLocale().toString());
debug("Mondrian Connection Properties: " + properties.toString());
MDXConnection mdxConnection = (MDXConnection) PentahoConnectionFactory.getConnection(IPentahoConnection.MDX_DATASOURCE, properties, PentahoSessionHolder.getSession(), this);
if (connAction != null) {
if ((connAction.getExtendedColumnNames() != ActionInputConstant.NULL_INPUT)) {
mdxConnection.setUseExtendedColumnNames(connAction.getExtendedColumnNames().getBooleanValue());
}
}
return mdxConnection;
}
Aggregations