Search in sources :

Example 1 with ExportManifestMondrian

use of org.pentaho.platform.plugin.services.importexport.exportManifest.bindings.ExportManifestMondrian 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 ExportManifestMondrian

use of org.pentaho.platform.plugin.services.importexport.exportManifest.bindings.ExportManifestMondrian in project pentaho-platform by pentaho.

the class ExportManifestTest method testUnMarshal.

@Test
public void testUnMarshal() {
    String xml = XmlToString();
    ExportManifest importManifest = null;
    ByteArrayInputStream input = new ByteArrayInputStream(xml.getBytes());
    try {
        importManifest = ExportManifest.fromXml(input);
    } catch (JAXBException e) {
        fail("Could not un-marshal to object " + e);
    }
    ExportManifestEntity fileEntity = importManifest.getExportManifestEntity("dir2/file1");
    assertNotNull(fileEntity);
    assertEquals("dir2/file1", fileEntity.getPath());
    assertNotNull(fileEntity.getEntityMetaData());
    assertFalse(fileEntity.getEntityMetaData().isIsFolder());
    fileEntity = importManifest.getExportManifestEntity("dir2");
    assertNotNull(fileEntity);
    assertNotNull(fileEntity.getEntityMetaData());
    assertTrue(fileEntity.getEntityMetaData().isIsFolder());
    RepositoryFile r = fileEntity.getRepositoryFile();
    try {
        RepositoryFileAcl rfa = fileEntity.getRepositoryFileAcl();
        assertNotNull(rfa.getAces());
    } catch (ExportManifestFormatException e) {
        e.printStackTrace();
        fail("Could not un-marshal to RepositoryFileAcl");
    }
    assertEquals(1, importManifest.getMetadataList().size());
    assertEquals(1, importManifest.getMondrianList().size());
    assertEquals(1, importManifest.getScheduleList().size());
    assertEquals(1, importManifest.getDatasourceList().size());
    ExportManifestMondrian mondrian1 = importManifest.getMondrianList().get(0);
    assertEquals("cat1", mondrian1.getCatalogName());
    assertTrue(mondrian1.getParameters().containsKey("testKey"));
    assertEquals("testValue", mondrian1.getParameters().get("testKey"));
    assertEquals("testMondrian.xml", mondrian1.getFile());
    ExportManifestMetadata metadata1 = importManifest.getMetadataList().get(0);
    assertEquals("testDomain", metadata1.getDomainId());
    assertEquals("testMetadata.xml", metadata1.getFile());
    DatabaseConnection connection = importManifest.getDatasourceList().get(0);
    assertEquals("SampleData", connection.getDatabaseName());
    assertEquals("9001", connection.getDatabasePort());
    assertEquals("Hypersonic", connection.getDatabaseType().getName());
    assertEquals("HYPERSONIC", connection.getDatabaseType().getShortName());
    assertEquals("localhost", connection.getHostname());
    assertEquals("pentaho_user", connection.getUsername());
    assertEquals("password", connection.getPassword());
    assertEquals(20, connection.getMaximumPoolSize());
}
Also used : ExportManifestMetadata(org.pentaho.platform.plugin.services.importexport.exportManifest.bindings.ExportManifestMetadata) ByteArrayInputStream(java.io.ByteArrayInputStream) JAXBException(javax.xml.bind.JAXBException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) ExportManifestMondrian(org.pentaho.platform.plugin.services.importexport.exportManifest.bindings.ExportManifestMondrian) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) Test(org.junit.Test)

Example 3 with ExportManifestMondrian

use of org.pentaho.platform.plugin.services.importexport.exportManifest.bindings.ExportManifestMondrian in project pentaho-platform by pentaho.

the class ExportManifestTest method testToXml_XmlUnsafeEscaped.

@Test
public void testToXml_XmlUnsafeEscaped() {
    final String keyFirst = "DataSource";
    final String keySecond = "DynamicSchemaProcessor";
    final String valueFirst = "\"DS \"Test's\" & <Fun>\"";
    final String valueSecond = "\"DSP's & \"Other\" <stuff>\"";
    final String expectedValueFirst = "&quot;DS &quot;Test's&quot; &amp; &lt;Fun&gt;&quot;";
    final String expectedValueSecond = "&quot;DSP's &amp; &quot;Other&quot; &lt;stuff&gt;&quot;";
    ExportManifestMondrian mondrian = new ExportManifestMondrian();
    Parameters mondrianParameters = new Parameters();
    mondrianParameters.put(keyFirst, valueFirst);
    mondrianParameters.put(keySecond, valueSecond);
    mondrian.setParameters(mondrianParameters);
    mondrian.setCatalogName("mondrian");
    mondrian.setXmlaEnabled(false);
    String lineParamFirst = null;
    String lineParamSecond = null;
    exportManifest.addMondrian(mondrian);
    try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        exportManifest.toXml(out);
        try (ByteArrayInputStream inputStream = new ByteArrayInputStream(out.toByteArray());
            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
            String line;
            while ((line = reader.readLine()) != null) {
                if (line.contains(keyFirst)) {
                    lineParamFirst = line;
                }
                if (line.contains(keySecond)) {
                    lineParamSecond = line;
                }
                if (lineParamFirst != null && lineParamSecond != null) {
                    break;
                }
            }
        }
    } catch (Exception e) {
        fail("Could not marshal to XML " + e);
    }
    assertNotNull(lineParamFirst);
    assertTrue(lineParamFirst.contains("value=\"" + expectedValueFirst + "\""));
    assertNotNull(lineParamSecond);
    assertTrue(lineParamSecond.contains("value=\"" + expectedValueSecond + "\""));
}
Also used : InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedReader(java.io.BufferedReader) ExportManifestMondrian(org.pentaho.platform.plugin.services.importexport.exportManifest.bindings.ExportManifestMondrian) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JAXBException(javax.xml.bind.JAXBException) Test(org.junit.Test)

Example 4 with ExportManifestMondrian

use of org.pentaho.platform.plugin.services.importexport.exportManifest.bindings.ExportManifestMondrian in project pentaho-platform by pentaho.

the class SolutionImportHandler method importFile.

@Override
public void importFile(IPlatformImportBundle bundle) throws PlatformImportException, DomainIdNullException, DomainAlreadyExistsException, DomainStorageException, IOException {
    RepositoryFileImportBundle importBundle = (RepositoryFileImportBundle) bundle;
    ZipInputStream zipImportStream = new ZipInputStream(bundle.getInputStream());
    SolutionRepositoryImportSource importSource = new SolutionRepositoryImportSource(zipImportStream);
    LocaleFilesProcessor localeFilesProcessor = new LocaleFilesProcessor();
    setOverwriteFile(bundle.overwriteInRepository());
    // importSession.set(ImportSession.getSession());
    IPlatformImporter importer = PentahoSystem.get(IPlatformImporter.class);
    cachedImports = new HashMap<String, RepositoryFileImportBundle.Builder>();
    // Process Manifest Settings
    ExportManifest manifest = getImportSession().getManifest();
    String manifestVersion = null;
    if (manifest != null) {
        manifestVersion = manifest.getManifestInformation().getManifestVersion();
    }
    // Process Metadata
    if (manifest != null) {
        // import the users
        Map<String, List<String>> roleToUserMap = importUsers(manifest.getUserExports());
        // import the roles
        importRoles(manifest.getRoleExports(), roleToUserMap);
        List<ExportManifestMetadata> metadataList = manifest.getMetadataList();
        for (ExportManifestMetadata exportManifestMetadata : metadataList) {
            String domainId = exportManifestMetadata.getDomainId();
            if (domainId != null && !domainId.endsWith(XMI_EXTENSION)) {
                domainId = domainId + XMI_EXTENSION;
            }
            boolean overWriteInRepository = isOverwriteFile();
            RepositoryFileImportBundle.Builder bundleBuilder = new RepositoryFileImportBundle.Builder().charSet("UTF-8").hidden(RepositoryFile.HIDDEN_BY_DEFAULT).schedulable(RepositoryFile.SCHEDULABLE_BY_DEFAULT).preserveDsw(bundle.isPreserveDsw()).overwriteFile(overWriteInRepository).mime("text/xmi+xml").withParam("domain-id", domainId);
            cachedImports.put(exportManifestMetadata.getFile(), bundleBuilder);
        }
        // Process Mondrian
        List<ExportManifestMondrian> mondrianList = manifest.getMondrianList();
        for (ExportManifestMondrian exportManifestMondrian : mondrianList) {
            String catName = exportManifestMondrian.getCatalogName();
            Parameters parametersMap = exportManifestMondrian.getParameters();
            StringBuilder parametersStr = new StringBuilder();
            for (String s : parametersMap.keySet()) {
                parametersStr.append(s).append("=").append(parametersMap.get(s)).append(sep);
            }
            RepositoryFileImportBundle.Builder bundleBuilder = new RepositoryFileImportBundle.Builder().charSet("UTF_8").hidden(RepositoryFile.HIDDEN_BY_DEFAULT).schedulable(RepositoryFile.SCHEDULABLE_BY_DEFAULT).name(catName).overwriteFile(isOverwriteFile()).mime("application/vnd.pentaho.mondrian+xml").withParam("parameters", parametersStr.toString()).withParam("domain-id", // TODO: this is
            catName);
            // definitely
            // named wrong
            // at the very
            // least.
            // pass as param if not in parameters string
            String xmlaEnabled = "" + exportManifestMondrian.isXmlaEnabled();
            bundleBuilder.withParam("EnableXmla", xmlaEnabled);
            cachedImports.put(exportManifestMondrian.getFile(), bundleBuilder);
            String annotationsFile = exportManifestMondrian.getAnnotationsFile();
            if (annotationsFile != null) {
                RepositoryFileImportBundle.Builder annotationsBundle = new RepositoryFileImportBundle.Builder().path(MondrianCatalogRepositoryHelper.ETC_MONDRIAN_JCR_FOLDER + RepositoryFile.SEPARATOR + catName).name("annotations.xml").charSet("UTF_8").overwriteFile(isOverwriteFile()).mime("text/xml").hidden(RepositoryFile.HIDDEN_BY_DEFAULT).schedulable(RepositoryFile.SCHEDULABLE_BY_DEFAULT).withParam("domain-id", catName);
                cachedImports.put(annotationsFile, annotationsBundle);
            }
        }
    }
    importMetaStore(manifest, bundle.overwriteInRepository());
    for (IRepositoryFileBundle fileBundle : importSource.getFiles()) {
        String fileName = fileBundle.getFile().getName();
        String actualFilePath = fileBundle.getPath();
        if (manifestVersion != null) {
            fileName = ExportFileNameEncoder.decodeZipFileName(fileName);
            actualFilePath = ExportFileNameEncoder.decodeZipFileName(actualFilePath);
        }
        String repositoryFilePath = RepositoryFilenameUtils.concat(PentahoPlatformImporter.computeBundlePath(actualFilePath), fileName);
        if (this.cachedImports.containsKey(repositoryFilePath)) {
            byte[] bytes = IOUtils.toByteArray(fileBundle.getInputStream());
            RepositoryFileImportBundle.Builder builder = cachedImports.get(repositoryFilePath);
            builder.input(new ByteArrayInputStream(bytes));
            importer.importFile(build(builder));
            continue;
        }
        RepositoryFileImportBundle.Builder bundleBuilder = new RepositoryFileImportBundle.Builder();
        InputStream bundleInputStream = null;
        String decodedFilePath = fileBundle.getPath();
        RepositoryFile decodedFile = fileBundle.getFile();
        if (manifestVersion != null) {
            decodedFile = new RepositoryFile.Builder(decodedFile).path(decodedFilePath).name(fileName).title(fileName).build();
            decodedFilePath = ExportFileNameEncoder.decodeZipFileName(fileBundle.getPath());
        }
        if (fileBundle.getFile().isFolder()) {
            bundleBuilder.mime("text/directory");
            bundleBuilder.file(decodedFile);
            fileName = repositoryFilePath;
            repositoryFilePath = importBundle.getPath();
        } else {
            byte[] bytes = IOUtils.toByteArray(fileBundle.getInputStream());
            bundleInputStream = new ByteArrayInputStream(bytes);
            // If is locale file store it for later processing.
            if (localeFilesProcessor.isLocaleFile(fileBundle, importBundle.getPath(), bytes)) {
                log.trace("Skipping [" + repositoryFilePath + "], it is a locale property file");
                continue;
            }
            bundleBuilder.input(bundleInputStream);
            bundleBuilder.mime(solutionHelper.getMime(fileName));
            String filePath = (decodedFilePath.equals("/") || decodedFilePath.equals("\\")) ? "" : decodedFilePath;
            repositoryFilePath = RepositoryFilenameUtils.concat(importBundle.getPath(), filePath);
        }
        bundleBuilder.name(fileName);
        bundleBuilder.path(repositoryFilePath);
        String sourcePath;
        if (fileBundle.getFile().isFolder()) {
            sourcePath = fileName;
        } else {
            sourcePath = RepositoryFilenameUtils.concat(PentahoPlatformImporter.computeBundlePath(actualFilePath), fileName);
        }
        // may not have rights to such as /home or /public
        if (manifest != null && manifest.getExportManifestEntity(sourcePath) == null && fileBundle.getFile().isFolder()) {
            continue;
        }
        getImportSession().setCurrentManifestKey(sourcePath);
        bundleBuilder.charSet(bundle.getCharset());
        bundleBuilder.overwriteFile(bundle.overwriteInRepository());
        bundleBuilder.applyAclSettings(bundle.isApplyAclSettings());
        bundleBuilder.retainOwnership(bundle.isRetainOwnership());
        bundleBuilder.overwriteAclSettings(bundle.isOverwriteAclSettings());
        bundleBuilder.acl(getImportSession().processAclForFile(sourcePath));
        RepositoryFile file = getFile(importBundle, fileBundle);
        ManifestFile manifestFile = getImportSession().getManifestFile(sourcePath, file != null);
        bundleBuilder.hidden(isFileHidden(file, manifestFile, sourcePath));
        boolean isSchedulable = isSchedulable(file, manifestFile);
        if (isSchedulable) {
            bundleBuilder.schedulable(isSchedulable);
        } else {
            bundleBuilder.schedulable(fileIsScheduleInputSource(manifest, sourcePath));
        }
        IPlatformImportBundle platformImportBundle = build(bundleBuilder);
        importer.importFile(platformImportBundle);
        if (bundleInputStream != null) {
            bundleInputStream.close();
            bundleInputStream = null;
        }
    }
    if (manifest != null) {
        importSchedules(manifest.getScheduleList());
        // Add Hitachi Vantara Connections
        List<org.pentaho.database.model.DatabaseConnection> datasourceList = manifest.getDatasourceList();
        if (datasourceList != null) {
            IDatasourceMgmtService datasourceMgmtSvc = PentahoSystem.get(IDatasourceMgmtService.class);
            for (org.pentaho.database.model.DatabaseConnection databaseConnection : datasourceList) {
                if (databaseConnection.getDatabaseType() == null) {
                    // don't try to import the connection if there is no type it will cause an error
                    // However, if this is the DI Server, and the connection is defined in a ktr, it will import automatically
                    log.warn("Can't import connection " + databaseConnection.getName() + " because it doesn't have a databaseType");
                    continue;
                }
                try {
                    IDatabaseConnection existingDBConnection = datasourceMgmtSvc.getDatasourceByName(databaseConnection.getName());
                    if (existingDBConnection != null && existingDBConnection.getName() != null) {
                        if (isOverwriteFile()) {
                            databaseConnection.setId(existingDBConnection.getId());
                            datasourceMgmtSvc.updateDatasourceByName(databaseConnection.getName(), databaseConnection);
                        }
                    } else {
                        datasourceMgmtSvc.createDatasource(databaseConnection);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
    // Process locale files.
    localeFilesProcessor.processLocaleFiles(importer);
}
Also used : ExportManifestMetadata(org.pentaho.platform.plugin.services.importexport.exportManifest.bindings.ExportManifestMetadata) ExportManifest(org.pentaho.platform.plugin.services.importexport.exportManifest.ExportManifest) IDatasourceMgmtService(org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService) IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) List(java.util.List) ArrayList(java.util.ArrayList) ExportManifestMondrian(org.pentaho.platform.plugin.services.importexport.exportManifest.bindings.ExportManifestMondrian) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) IRepositoryFileBundle(org.pentaho.platform.plugin.services.importexport.ImportSource.IRepositoryFileBundle) Parameters(org.pentaho.platform.plugin.services.importexport.exportManifest.Parameters) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) ManifestFile(org.pentaho.platform.plugin.services.importexport.ImportSession.ManifestFile) AlreadyExistsException(org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) IOException(java.io.IOException) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection)

Example 5 with ExportManifestMondrian

use of org.pentaho.platform.plugin.services.importexport.exportManifest.bindings.ExportManifestMondrian in project pentaho-platform by pentaho.

the class ExportManifestTest method testToXml_XmlUnsafeManifestParameters.

@Test
public void testToXml_XmlUnsafeManifestParameters() {
    final String keyFirst = "DataSource";
    final String keySecond = "DynamicSchemaProcessor";
    final String valueFirst = "\"DS \"Test's\" & <Fun>\"";
    final String valueSecond = "\"DSP's & \"Other\" <stuff>\"";
    ExportManifestMondrian mondrian = new ExportManifestMondrian();
    Parameters mondrianParameters = new Parameters();
    mondrianParameters.put(keyFirst, valueFirst);
    mondrianParameters.put(keySecond, valueSecond);
    mondrian.setParameters(mondrianParameters);
    mondrian.setCatalogName("mondrian");
    mondrian.setXmlaEnabled(false);
    exportManifest.addMondrian(mondrian);
    try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        try {
            exportManifest.toXml(out);
        } catch (Exception e) {
            fail("Could not marshal to XML " + e);
        }
        try (ByteArrayInputStream inputStream = new ByteArrayInputStream(out.toByteArray())) {
            ExportManifest ex = null;
            try {
                ex = ExportManifest.fromXml(inputStream);
            } catch (Exception e) {
                fail("Could not un-marshal from XML " + e);
            }
            List<ExportManifestMondrian> catalogs = ex.getMondrianList();
            assertNotNull(catalogs);
            assertTrue(!catalogs.isEmpty());
            ExportManifestMondrian mondrianCatalog = null;
            for (ExportManifestMondrian catalog : catalogs) {
                if ("mondrian".equals(catalog.getCatalogName())) {
                    mondrianCatalog = catalog;
                    break;
                }
            }
            assertNotNull(mondrianCatalog);
            Parameters parameters = mondrianCatalog.getParameters();
            assertNotNull(parameters);
            assertTrue(!parameters.isEmpty());
            String parameter = parameters.get(keyFirst);
            assertNotNull(parameter);
            assertTrue(valueFirst.equals(parameter));
            parameter = parameters.get(keySecond);
            assertNotNull(parameter);
            assertTrue(valueSecond.equals(parameter));
        }
    } catch (Exception e) {
        fail(e.toString());
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ExportManifestMondrian(org.pentaho.platform.plugin.services.importexport.exportManifest.bindings.ExportManifestMondrian) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JAXBException(javax.xml.bind.JAXBException) Test(org.junit.Test)

Aggregations

ExportManifestMondrian (org.pentaho.platform.plugin.services.importexport.exportManifest.bindings.ExportManifestMondrian)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 JAXBException (javax.xml.bind.JAXBException)3 Test (org.junit.Test)3 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)3 ExportManifestMetadata (org.pentaho.platform.plugin.services.importexport.exportManifest.bindings.ExportManifestMetadata)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 List (java.util.List)2 DatabaseConnection (org.pentaho.database.model.DatabaseConnection)2 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)2 IDatasourceMgmtService (org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 Files (java.nio.file.Files)1