Search in sources :

Example 1 with ExportManifestMetaStore

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

the class SolutionImportHandler method importMetaStore.

protected void importMetaStore(ExportManifest manifest, boolean overwrite) {
    // get the metastore
    if (manifest != null) {
        ExportManifestMetaStore manifestMetaStore = manifest.getMetaStore();
        if (manifestMetaStore != null) {
            // get the zipped metastore from the export bundle
            RepositoryFileImportBundle.Builder bundleBuilder = new RepositoryFileImportBundle.Builder().path(manifestMetaStore.getFile()).name(manifestMetaStore.getName()).withParam("description", manifestMetaStore.getDescription()).charSet("UTF-8").overwriteFile(overwrite).mime("application/vnd.pentaho.metastore");
            cachedImports.put(manifestMetaStore.getFile(), bundleBuilder);
        }
    }
}
Also used : ExportManifestMetaStore(org.pentaho.platform.plugin.services.importexport.exportManifest.bindings.ExportManifestMetaStore)

Example 2 with ExportManifestMetaStore

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

the class PentahoPlatformExporter method exportMetastore.

protected void exportMetastore() throws IOException {
    log.debug("export the metastore");
    try {
        Path tempDirectory = Files.createTempDirectory(METASTORE);
        IMetaStore xmlMetaStore = new XmlMetaStore(tempDirectory.toString());
        MetaStoreUtil.copy(getRepoMetaStore(), xmlMetaStore);
        File zippedMetastore = Files.createTempFile(METASTORE, EXPORT_TEMP_FILENAME_EXT).toFile();
        ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(zippedMetastore));
        zipFolder(tempDirectory.toFile(), zipOutputStream, tempDirectory.toString());
        zipOutputStream.close();
        // now that we have the zipped content of an xml metastore, we need to write that to the export bundle
        FileInputStream zis = new FileInputStream(zippedMetastore);
        String zipFileLocation = METASTORE + METASTORE_BACKUP_EXT;
        ZipEntry metastoreZipFileZipEntry = new ZipEntry(zipFileLocation);
        zos.putNextEntry(metastoreZipFileZipEntry);
        try {
            IOUtils.copy(zis, zos);
        } catch (IOException e) {
            throw e;
        } finally {
            zis.close();
            zos.closeEntry();
        }
        // add an ExportManifest entry for the metastore.
        ExportManifestMetaStore exportManifestMetaStore = new ExportManifestMetaStore(zipFileLocation, getRepoMetaStore().getName(), getRepoMetaStore().getDescription());
        getExportManifest().setMetaStore(exportManifestMetaStore);
        zippedMetastore.deleteOnExit();
        tempDirectory.toFile().deleteOnExit();
    } catch (Exception e) {
        log.error(Messages.getInstance().getString("PentahoPlatformExporter.ERROR.ExportingMetaStore"));
        log.debug(Messages.getInstance().getString("PentahoPlatformExporter.ERROR.ExportingMetaStore"), e);
    }
}
Also used : Path(java.nio.file.Path) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) XmlMetaStore(org.pentaho.metastore.stores.xml.XmlMetaStore) IMetaStore(org.pentaho.metastore.api.IMetaStore) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) FileInputStream(java.io.FileInputStream) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException) SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) FileNotFoundException(java.io.FileNotFoundException) KettleException(org.pentaho.di.core.exception.KettleException) ExportException(org.pentaho.platform.plugin.services.importexport.ExportException) IOException(java.io.IOException) ExportManifestMetaStore(org.pentaho.platform.plugin.services.importexport.exportManifest.bindings.ExportManifestMetaStore)

Example 3 with ExportManifestMetaStore

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

the class SolutionImportHandlerTest method testImportMetaStore.

@Test
public void testImportMetaStore() throws Exception {
    ExportManifest manifest = Mockito.spy(new ExportManifest());
    String path = "/path/to/file.zip";
    ExportManifestMetaStore manifestMetaStore = new ExportManifestMetaStore(path, "metastore", "description of the metastore");
    importHandler.cachedImports = new HashMap<String, RepositoryFileImportBundle.Builder>();
    Mockito.when(manifest.getMetaStore()).thenReturn(manifestMetaStore);
    importHandler.importMetaStore(manifest, true);
    Assert.assertEquals(1, importHandler.cachedImports.size());
    Assert.assertTrue(importHandler.cachedImports.get(path) != null);
}
Also used : ExportManifest(org.pentaho.platform.plugin.services.importexport.exportManifest.ExportManifest) ExportManifestMetaStore(org.pentaho.platform.plugin.services.importexport.exportManifest.bindings.ExportManifestMetaStore) Test(org.junit.Test)

Aggregations

ExportManifestMetaStore (org.pentaho.platform.plugin.services.importexport.exportManifest.bindings.ExportManifestMetaStore)3 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 ZipEntry (java.util.zip.ZipEntry)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 Test (org.junit.Test)1 KettleException (org.pentaho.di.core.exception.KettleException)1 IMetaStore (org.pentaho.metastore.api.IMetaStore)1 XmlMetaStore (org.pentaho.metastore.stores.xml.XmlMetaStore)1 DatasourceMgmtServiceException (org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)1 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)1 SchedulerException (org.pentaho.platform.api.scheduler2.SchedulerException)1 ExportException (org.pentaho.platform.plugin.services.importexport.ExportException)1 ExportManifest (org.pentaho.platform.plugin.services.importexport.exportManifest.ExportManifest)1