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();
}
}
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)));
}
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);
}
Aggregations