Search in sources :

Example 1 with MondrianCatalog

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);
        }
    }
}
Also used : ClientRepositoryPaths(org.pentaho.platform.repository2.ClientRepositoryPaths) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) LoggerFactory(org.slf4j.LoggerFactory) UserDetailsService(org.springframework.security.core.userdetails.UserDetailsService) DefaultExportHandler(org.pentaho.platform.plugin.services.importexport.DefaultExportHandler) UserExport(org.pentaho.platform.plugin.services.importexport.UserExport) IMondrianCatalogService(org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService) Map(java.util.Map) Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) EmbeddedVersionCheckSystemListener(org.pentaho.platform.scheduler2.versionchecker.EmbeddedVersionCheckSystemListener) MondrianCatalogRepositoryHelper(org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper) MondrianVfs(org.pentaho.platform.repository.solution.filebased.MondrianVfs) IRoleAuthorizationPolicyRoleBindingDao(org.pentaho.platform.security.policy.rolebased.IRoleAuthorizationPolicyRoleBindingDao) Set(java.util.Set) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException) SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) FileNotFoundException(java.io.FileNotFoundException) IOUtils(org.apache.commons.io.IOUtils) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) List(java.util.List) XmlMetaStore(org.pentaho.metastore.stores.xml.XmlMetaStore) ExportManifestMetadata(org.pentaho.platform.plugin.services.importexport.exportManifest.bindings.ExportManifestMetadata) Messages(org.pentaho.platform.plugin.services.messages.Messages) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) ZipOutputStream(java.util.zip.ZipOutputStream) IScheduler(org.pentaho.platform.api.scheduler2.IScheduler) KettleException(org.pentaho.di.core.exception.KettleException) IUserSettingService(org.pentaho.platform.api.usersettings.IUserSettingService) PentahoSystem(org.pentaho.platform.engine.core.system.PentahoSystem) ITenant(org.pentaho.platform.api.mt.ITenant) ExportException(org.pentaho.platform.plugin.services.importexport.ExportException) ExportManifestMetaStore(org.pentaho.platform.plugin.services.importexport.exportManifest.bindings.ExportManifestMetaStore) JobScheduleRequest(org.pentaho.platform.web.http.api.resources.JobScheduleRequest) IMetaStore(org.pentaho.metastore.api.IMetaStore) RoleExport(org.pentaho.platform.plugin.services.importexport.RoleExport) Job(org.pentaho.platform.api.scheduler2.Job) StreamSupport(java.util.stream.StreamSupport) IDatasourceMgmtService(org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService) ExportFileNameEncoder(org.pentaho.platform.plugin.services.importexport.ExportFileNameEncoder) IUserSetting(org.pentaho.platform.api.usersettings.pojo.IUserSetting) Parameters(org.pentaho.platform.plugin.services.importexport.exportManifest.Parameters) Logger(org.slf4j.Logger) IUserRoleListService(org.pentaho.platform.api.engine.IUserRoleListService) Files(java.nio.file.Files) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) IPentahoMetadataDomainRepositoryExporter(org.pentaho.platform.plugin.services.metadata.IPentahoMetadataDomainRepositoryExporter) IAnyUserSettingService(org.pentaho.platform.api.usersettings.IAnyUserSettingService) IMetadataDomainRepository(org.pentaho.metadata.repository.IMetadataDomainRepository) File(java.io.File) ExportManifestMondrian(org.pentaho.platform.plugin.services.importexport.exportManifest.bindings.ExportManifestMondrian) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) MetaStoreUtil(org.pentaho.metastore.util.MetaStoreUtil) ExportManifestUserSetting(org.pentaho.platform.plugin.services.importexport.ExportManifestUserSetting) TenantUtils(org.pentaho.platform.engine.core.system.TenantUtils) MondrianCatalog(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog) ZipExportProcessor(org.pentaho.platform.plugin.services.importexport.ZipExportProcessor) StringEscapeUtils(org.apache.commons.lang.StringEscapeUtils) InputStream(java.io.InputStream) Parameters(org.pentaho.platform.plugin.services.importexport.exportManifest.Parameters) MondrianCatalog(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) ExportManifestMondrian(org.pentaho.platform.plugin.services.importexport.exportManifest.bindings.ExportManifestMondrian) IOException(java.io.IOException)

Example 2 with MondrianCatalog

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]);
}
Also used : MondrianCatalogHelper(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogHelper) MondrianCatalog(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog) MondrianSchema(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianSchema) IMondrianCatalogService(org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) PlatformInitializationException(org.pentaho.platform.engine.core.system.boot.PlatformInitializationException) DataAccessException(org.springframework.dao.DataAccessException) Test(org.junit.Test)

Example 3 with MondrianCatalog

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 &quot;Test's&quot; & <Fun>\";" + "DynamicSchemaProcessor=\"DSP's & &quot;Other&quot; <stuff>\"";
    String expectedValue = new StringBuilder().append("DataSource=\"DS &quot;Test&apos;s&quot; &amp; &lt;Fun&gt;\";").append("EnableXmla=true;").append("Provider=\"provider\";").append("DynamicSchemaProcessor=\"DSP&apos;s &amp; &quot;Other&quot; &lt;stuff&gt;\"").toString();
    when(customBundle.getProperty(eq(MondrianImportHandler.ENABLE_XMLA))).thenReturn("true");
    when(customBundle.getProperty(eq(MondrianImportHandler.DATA_SOURCE))).thenReturn("DS &quot;Test's&quot; & <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);
}
Also used : IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) MondrianCatalog(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog) Test(org.junit.Test)

Example 4 with MondrianCatalog

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());
}
Also used : RolapConnection(mondrian.rolap.RolapConnection) ISecurityHelper(org.pentaho.platform.api.engine.ISecurityHelper) MondrianCatalog(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog) XmlaHandler(mondrian.xmla.XmlaHandler) ServletConfig(javax.servlet.ServletConfig) IMondrianCatalogService(org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService) Properties(java.util.Properties) MondrianException(mondrian.olap.MondrianException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with MondrianCatalog

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;
}
Also used : MDXConnection(org.pentaho.platform.plugin.services.connections.mondrian.MDXConnection) MondrianCatalog(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog) TemplateUtil(org.pentaho.platform.engine.services.runtime.TemplateUtil) Util(mondrian.olap.Util) MdxConnectionAction(org.pentaho.actionsequence.dom.actions.MdxConnectionAction) IMondrianCatalogService(org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService) RolapConnectionProperties(mondrian.rolap.RolapConnectionProperties) Properties(java.util.Properties) Pair(mondrian.util.Pair)

Aggregations

MondrianCatalog (org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog)28 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)13 IMondrianCatalogService (org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService)13 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)4 Properties (java.util.Properties)4 InputStream (java.io.InputStream)3 SQLException (java.sql.SQLException)3 MondrianException (mondrian.olap.MondrianException)3 IPentahoConnection (org.pentaho.commons.connection.IPentahoConnection)3 MondrianSchema (org.pentaho.platform.plugin.action.mondrian.catalog.MondrianSchema)3 MDXConnection (org.pentaho.platform.plugin.services.connections.mondrian.MDXConnection)3 IOException (java.io.IOException)2 ZipOutputStream (java.util.zip.ZipOutputStream)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Connection (mondrian.olap.Connection)2 Util (mondrian.olap.Util)2 RolapConnection (mondrian.rolap.RolapConnection)2