Search in sources :

Example 6 with IRepositoryImportLogger

use of org.pentaho.platform.plugin.services.importexport.IRepositoryImportLogger in project pentaho-platform by pentaho.

the class FileService method systemRestore.

public void systemRestore(final InputStream fileUpload, String overwriteFile, String applyAclSettings, String overwriteAclSettings) throws PlatformImportException, SecurityException {
    if (doCanAdminister()) {
        boolean overwriteFileFlag = !"false".equals(overwriteFile);
        boolean applyAclSettingsFlag = !"false".equals(applyAclSettings);
        boolean overwriteAclSettingsFlag = "true".equals(overwriteAclSettings);
        IRepositoryImportLogger importLogger = null;
        Level level = Level.ERROR;
        ByteArrayOutputStream importLoggerStream = new ByteArrayOutputStream();
        String importDirectory = "/";
        RepositoryFileImportBundle.Builder bundleBuilder = new RepositoryFileImportBundle.Builder();
        bundleBuilder.input(fileUpload);
        bundleBuilder.charSet("UTF-8");
        bundleBuilder.hidden(RepositoryFile.HIDDEN_BY_DEFAULT);
        bundleBuilder.schedulable(RepositoryFile.SCHEDULABLE_BY_DEFAULT);
        bundleBuilder.path(importDirectory);
        bundleBuilder.overwriteFile(overwriteFileFlag);
        bundleBuilder.name("SystemBackup.zip");
        bundleBuilder.applyAclSettings(applyAclSettingsFlag);
        bundleBuilder.overwriteAclSettings(overwriteAclSettingsFlag);
        bundleBuilder.retainOwnership(true);
        bundleBuilder.preserveDsw(true);
        ImportSession.getSession().setAclProperties(applyAclSettingsFlag, true, overwriteAclSettingsFlag);
        IPlatformImporter importer = PentahoSystem.get(IPlatformImporter.class);
        importLogger = importer.getRepositoryImportLogger();
        importLogger.startJob(importLoggerStream, importDirectory, level);
        try {
            importer.importFile(bundleBuilder.build());
        } finally {
            importLogger.endJob();
        }
    } else {
        throw new SecurityException();
    }
}
Also used : IRepositoryImportLogger(org.pentaho.platform.plugin.services.importexport.IRepositoryImportLogger) Level(org.apache.log4j.Level) RepositoryFileImportBundle(org.pentaho.platform.plugin.services.importer.RepositoryFileImportBundle) GeneralSecurityException(java.security.GeneralSecurityException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IPlatformImporter(org.pentaho.platform.plugin.services.importer.IPlatformImporter)

Example 7 with IRepositoryImportLogger

use of org.pentaho.platform.plugin.services.importexport.IRepositoryImportLogger in project pentaho-platform by pentaho.

the class ArchiveLoaderTest method testWillImportAllZipsInADirectory.

@Test
public void testWillImportAllZipsInADirectory() throws Exception {
    final IPlatformImporter importer = mock(IPlatformImporter.class);
    final FileInputStream inputStream = mock(FileInputStream.class);
    final ArchiveLoader loader = createArchiveLoader(importer, inputStream);
    final File directory = mock(File.class);
    final File jobs = mock(File.class);
    String jobsName = "jobs.zip";
    when(jobs.getName()).thenReturn(jobsName);
    when(jobs.getPath()).thenReturn("/root/path/" + jobsName);
    final File reports = mock(File.class);
    String reportsName = "reports.zip";
    when(reports.getName()).thenReturn(reportsName);
    when(reports.getPath()).thenReturn("/root/path/" + reportsName);
    when(directory.listFiles(ZIPS_FILTER)).thenReturn(new File[] { jobs, reports });
    IRepositoryImportLogger logger = mock(IRepositoryImportLogger.class);
    when(importer.getRepositoryImportLogger()).thenReturn(logger);
    loader.loadAll(directory, ZIPS_FILTER);
    verify(importer).importFile(argThat(bundleMatcher(jobsName, inputStream)));
    verify(jobs).renameTo(argThat(fileMatcher(jobs)));
    verify(importer).importFile(argThat(bundleMatcher(reportsName, inputStream)));
    verify(reports).renameTo(argThat(fileMatcher(reports)));
}
Also used : IRepositoryImportLogger(org.pentaho.platform.plugin.services.importexport.IRepositoryImportLogger) File(java.io.File) FileInputStream(java.io.FileInputStream) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with IRepositoryImportLogger

use of org.pentaho.platform.plugin.services.importexport.IRepositoryImportLogger in project pentaho-platform by pentaho.

the class PlatformImporterTest method testUseDefaultHandler.

@Test
public void testUseDefaultHandler() throws Exception {
    List<IMimeType> mimeList = Collections.singletonList((IMimeType) new MimeType("text/html", "html"));
    IPlatformImportHandler mockImportHandler = mock(IPlatformImportHandler.class);
    when(mockImportHandler.getMimeTypes()).thenReturn(mimeList);
    List<IPlatformImportHandler> handlers = Collections.singletonList(mockImportHandler);
    NameBaseMimeResolver nameResolver = new NameBaseMimeResolver();
    PentahoSystem.registerObject(nameResolver);
    // mock logger to prevent npe
    IRepositoryImportLogger importLogger = new Log4JRepositoryImportLogger();
    PentahoPlatformImporter importer = new PentahoPlatformImporter(handlers, new DefaultRepositoryContentConverterHandler(new HashMap<String, Converter>()));
    IPlatformImportHandler mockDefaultImportHandler = mock(IPlatformImportHandler.class);
    importer.setDefaultHandler(mockDefaultImportHandler);
    importer.setRepositoryImportLogger(importLogger);
    FileInputStream in = new FileInputStream(new File(TestResourceLocation.TEST_RESOURCES + "/ImportTest/steel-wheels.xmi"));
    // With custom domain id
    final IPlatformImportBundle bundle1 = (new RepositoryFileImportBundle.Builder().input(in).charSet("UTF-8").hidden(false).mime("text/xmi+xml").name("steel-wheels.xmi").comment("Test Metadata Import").withParam("domain-id", "parameterized-domain-id")).build();
    importer.importFile(bundle1);
    verify(mockDefaultImportHandler, times(1)).importFile(bundle1);
}
Also used : HashMap(java.util.HashMap) IRepositoryImportLogger(org.pentaho.platform.plugin.services.importexport.IRepositoryImportLogger) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) MimeType(org.pentaho.platform.core.mimetype.MimeType) FileInputStream(java.io.FileInputStream) IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) Log4JRepositoryImportLogger(org.pentaho.platform.plugin.services.importexport.Log4JRepositoryImportLogger) File(java.io.File) Test(org.junit.Test)

Aggregations

IRepositoryImportLogger (org.pentaho.platform.plugin.services.importexport.IRepositoryImportLogger)8 Test (org.junit.Test)5 File (java.io.File)4 FileInputStream (java.io.FileInputStream)4 IPlatformImportBundle (org.pentaho.platform.api.repository2.unified.IPlatformImportBundle)4 RepositoryFileImportBundle (org.pentaho.platform.plugin.services.importer.RepositoryFileImportBundle)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 HashMap (java.util.HashMap)2 Level (org.apache.log4j.Level)2 IAuthorizationPolicy (org.pentaho.platform.api.engine.IAuthorizationPolicy)2 IMimeType (org.pentaho.platform.api.mimetype.IMimeType)2 MimeType (org.pentaho.platform.core.mimetype.MimeType)2 IMondrianCatalogService (org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService)2 IPlatformImporter (org.pentaho.platform.plugin.services.importer.IPlatformImporter)2 ImportSession (org.pentaho.platform.plugin.services.importexport.ImportSession)2 Log4JRepositoryImportLogger (org.pentaho.platform.plugin.services.importexport.Log4JRepositoryImportLogger)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1