Search in sources :

Example 1 with StreamConverter

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);
    }
}
Also used : IRepositoryFileData(org.pentaho.platform.api.repository2.unified.IRepositoryFileData) FileOutputStream(java.io.FileOutputStream) StreamConverter(org.pentaho.platform.plugin.services.importexport.StreamConverter) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 2 with StreamConverter

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);
}
Also used : IRepositoryContentConverterHandler(org.pentaho.platform.api.repository2.unified.IRepositoryContentConverterHandler) StreamConverter(org.pentaho.platform.plugin.services.importexport.StreamConverter) BeforeClass(org.junit.BeforeClass)

Example 3 with StreamConverter

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);
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ITenant(org.pentaho.platform.api.mt.ITenant) HashMap(java.util.HashMap) StreamConverter(org.pentaho.platform.plugin.services.importexport.StreamConverter) StreamConverter(org.pentaho.platform.plugin.services.importexport.StreamConverter) Converter(org.pentaho.platform.api.repository2.unified.Converter) WebResource(com.sun.jersey.api.client.WebResource) DefaultExportHandler(org.pentaho.platform.plugin.services.importexport.DefaultExportHandler) JerseyTest(com.sun.jersey.test.framework.JerseyTest) Test(org.junit.Test)

Example 4 with StreamConverter

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();
}
Also used : ArrayList(java.util.ArrayList) ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) SolutionEngine(org.pentaho.platform.engine.services.solution.SolutionEngine) IDatasourceMgmtService(org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) IRepositoryContentConverterHandler(org.pentaho.platform.api.repository2.unified.IRepositoryContentConverterHandler) IPlatformMimeResolver(org.pentaho.platform.api.mimetype.IPlatformMimeResolver) Log4JRepositoryImportLogger(org.pentaho.platform.plugin.services.importexport.Log4JRepositoryImportLogger) StreamConverter(org.pentaho.platform.plugin.services.importexport.StreamConverter) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) Converter(org.pentaho.platform.api.repository2.unified.Converter) StreamConverter(org.pentaho.platform.plugin.services.importexport.StreamConverter) File(java.io.File) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) FileSystemBackedUnifiedRepository(org.pentaho.platform.repository2.unified.fs.FileSystemBackedUnifiedRepository) Before(org.junit.Before)

Aggregations

StreamConverter (org.pentaho.platform.plugin.services.importexport.StreamConverter)4 File (java.io.File)2 Converter (org.pentaho.platform.api.repository2.unified.Converter)2 IRepositoryContentConverterHandler (org.pentaho.platform.api.repository2.unified.IRepositoryContentConverterHandler)2 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)2 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 WebResource (com.sun.jersey.api.client.WebResource)1 JerseyTest (com.sun.jersey.test.framework.JerseyTest)1 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Before (org.junit.Before)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1 ISolutionEngine (org.pentaho.platform.api.engine.ISolutionEngine)1 IMimeType (org.pentaho.platform.api.mimetype.IMimeType)1 IPlatformMimeResolver (org.pentaho.platform.api.mimetype.IPlatformMimeResolver)1 ITenant (org.pentaho.platform.api.mt.ITenant)1 IDatasourceMgmtService (org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService)1 IRepositoryFileData (org.pentaho.platform.api.repository2.unified.IRepositoryFileData)1