use of org.pentaho.platform.plugin.services.importexport.StreamConverter in project pentaho-platform by pentaho.
the class MondrianCatalogRepositoryHelper method addHostedCatalog.
public void addHostedCatalog(InputStream mondrianFile, String catalogName, String datasourceInfo) throws Exception {
RepositoryFile catalog = createCatalog(catalogName, datasourceInfo);
File tempFile = File.createTempFile("tempFile", null);
tempFile.deleteOnExit();
FileOutputStream outputStream = new FileOutputStream(tempFile);
IOUtils.copy(mondrianFile, outputStream);
RepositoryFile repoFile = new RepositoryFile.Builder("schema.xml").build();
org.pentaho.platform.plugin.services.importexport.RepositoryFileBundle repoFileBundle = new org.pentaho.platform.plugin.services.importexport.RepositoryFileBundle(repoFile, null, ETC_MONDRIAN_JCR_FOLDER + RepositoryFile.SEPARATOR + catalogName + RepositoryFile.SEPARATOR, tempFile, "UTF-8", "text/xml");
RepositoryFile schema = repository.getFile(ETC_MONDRIAN_JCR_FOLDER + RepositoryFile.SEPARATOR + catalogName + RepositoryFile.SEPARATOR + "schema.xml");
IRepositoryFileData data = new StreamConverter().convert(repoFileBundle.getInputStream(), repoFileBundle.getCharset(), repoFileBundle.getMimeType());
if (schema == null) {
RepositoryFile schemaFile = repository.createFile(catalog.getId(), repoFileBundle.getFile(), data, null);
if (schemaFile != null) {
// make sure the folder is not set to hidden if the schema is not hidden
RepositoryFile catalogFolder = repository.getFile(ETC_MONDRIAN_JCR_FOLDER + RepositoryFile.SEPARATOR + catalogName);
if (catalogFolder.isHidden() != schemaFile.isHidden()) {
RepositoryFile unhiddenFolder = (new RepositoryFile.Builder(catalogFolder)).hidden(schemaFile.isHidden()).build();
repository.updateFolder(unhiddenFolder, "");
}
}
} else {
repository.updateFile(schema, data, null);
}
}
use of org.pentaho.platform.plugin.services.importexport.StreamConverter in project pentaho-platform by pentaho.
the class FileResourceTest method initTest.
@BeforeClass
public static void initTest() {
IRepositoryContentConverterHandler handler = mock(IRepositoryContentConverterHandler.class);
when(handler.getConverter(XML_EXTENSION)).thenReturn(new StreamConverter());
PentahoSystem.registerObject(handler);
}
use of org.pentaho.platform.plugin.services.importexport.StreamConverter in project pentaho-platform by pentaho.
the class FileResourceIT method testBrowserDownload.
// This is testing the Rest end points, we should instead be testing the underlying functionality in unit tests
@Test
public void testBrowserDownload() {
final String text = "abcdefg";
// mock converters map
StreamConverter streamConverter = new StreamConverter(repo);
Map<String, Converter> converterMap = new HashMap<String, Converter>();
converterMap.put("txt", streamConverter);
// stub DefaultExportProcessor
DefaultExportHandler defaultExportHandler = new DefaultExportHandler();
defaultExportHandler.setConverters(converterMap);
defaultExportHandler.setRepository(repo);
loginAsRepositoryAdmin();
ITenant systemTenant = tenantManager.createTenant(null, ServerRepositoryPaths.getPentahoRootFolderName(), adminAuthorityName, authenticatedAuthorityName, "Anonymous");
userRoleDao.createUser(systemTenant, sysAdminUserName, "password", "", new String[] { adminAuthorityName });
login(sysAdminUserName, systemTenant, new String[] { adminAuthorityName, authenticatedAuthorityName });
ITenant mainTenant_1 = tenantManager.createTenant(systemTenant, MAIN_TENANT_1, adminAuthorityName, authenticatedAuthorityName, "Anonymous");
userRoleDao.createUser(mainTenant_1, "admin", "password", "", new String[] { adminAuthorityName });
try {
login("admin", mainTenant_1, new String[] { authenticatedAuthorityName, adminAuthorityName });
mp.defineInstance(IUnifiedRepository.class, repo);
mp.defineInstance(DefaultExportHandler.class, defaultExportHandler);
final String fileName = "file.txt";
createTestFile("/public".replaceAll("/", ":") + ":" + fileName, text);
// test download of file
WebResource webResource = resource();
webResource.path("repo/files/public:file.txt/download").get(ClientResponse.class);
// test download of dir as a zip file
ClientResponse r2 = webResource.path("repo/files/public:file.txt/download").get(ClientResponse.class);
assertResponse(r2, Status.OK);
JerseyTestUtil.assertResponseIsZip(r2);
} catch (Throwable ex) {
TestCase.fail();
} finally {
cleanupUserAndRoles(mainTenant_1);
cleanupUserAndRoles(systemTenant);
}
}
use of org.pentaho.platform.plugin.services.importexport.StreamConverter in project pentaho-platform by pentaho.
the class SolutionImportHandlerNamingIT method init.
@Before
public void init() throws IOException, PlatformInitializationException, PlatformImportException, DomainIdNullException, DomainAlreadyExistsException, DomainStorageException {
// repository
File repoDir = new File(tempDir.getAbsolutePath() + REPO_PATH);
FileUtils.forceMkdir(repoDir);
FileUtils.cleanDirectory(repoDir);
repoRoot = repoDir;
repo = new FileSystemBackedUnifiedRepository();
repo = Mockito.spy(repo);
repo.setRootDir(repoRoot);
// mimeResolver
final Converter defaultConverter = new StreamConverter();
final List<IMimeType> solutionMimeList = java.util.Collections.singletonList(MIME_SOLUTION);
final List<IMimeType> contentMimeList = java.util.Arrays.asList(new IMimeType[] { MIME_PRPT, MIME_XML });
final List<IMimeType> allMimeTypes = new ArrayList<IMimeType>(solutionMimeList.size() + contentMimeList.size());
{
allMimeTypes.addAll(solutionMimeList);
allMimeTypes.addAll(contentMimeList);
for (IMimeType mimeType : allMimeTypes) {
mimeType.setConverter(defaultConverter);
}
}
final IPlatformMimeResolver mimeResolver = new NameBaseMimeResolver();
for (IMimeType mimeType : allMimeTypes) {
mimeResolver.addMimeType(mimeType);
}
// platform, import handlers
PentahoSystem.clearObjectFactory();
microPlatform = new MicroPlatform(getSolutionPath());
microPlatform.defineInstance(IUnifiedRepository.class, repo);
microPlatform.defineInstance(IPlatformMimeResolver.class, mimeResolver);
microPlatform.defineInstance(ISolutionEngine.class, Mockito.mock(SolutionEngine.class));
microPlatform.defineInstance(IDatasourceMgmtService.class, Mockito.mock(IDatasourceMgmtService.class));
IRepositoryContentConverterHandler converterHandler = new DefaultRepositoryContentConverterHandler(new HashMap<String, Converter>());
RepositoryFileImportFileHandler contentImportFileHandler = new RepositoryFileImportFileHandler(contentMimeList);
contentImportFileHandler.setRepository(repo);
solutionImportHandler = new SolutionImportHandler(solutionMimeList);
List<IPlatformImportHandler> handlers = new ArrayList<IPlatformImportHandler>();
handlers.add(contentImportFileHandler);
handlers.add(solutionImportHandler);
PentahoPlatformImporter importer = new PentahoPlatformImporter(handlers, converterHandler);
importer.setDefaultHandler(contentImportFileHandler);
importer.setRepositoryImportLogger(new Log4JRepositoryImportLogger());
microPlatform.defineInstance(IPlatformImporter.class, importer);
microPlatform.start();
}
Aggregations