Search in sources :

Example 1 with MimeType

use of org.pentaho.platform.core.mimetype.MimeType in project data-access by pentaho.

the class DatasourceResourceIT method testMetadataImportExport.

@Test
public void testMetadataImportExport() throws PlatformInitializationException, IOException, PlatformImportException {
    List<IMimeType> mimeTypeList = new ArrayList<IMimeType>();
    mimeTypeList.add(new MimeType("Metadata", ".xmi"));
    File metadata = new File("target/test-classes/dsw/testData/metadata.xmi");
    RepositoryFile repoMetadataFile = new RepositoryFile.Builder(metadata.getName()).folder(false).hidden(false).build();
    MetadataImportHandler metadataImportHandler = new MetadataImportHandler(mimeTypeList, (IPentahoMetadataDomainRepositoryImporter) PentahoSystem.get(IMetadataDomainRepository.class));
    RepositoryFileImportBundle bundle1 = new RepositoryFileImportBundle.Builder().file(repoMetadataFile).charSet("UTF-8").input(new FileInputStream(metadata)).mime(".xmi").withParam("domain-id", "SalesData").build();
    metadataImportHandler.importFile(bundle1);
    final Response salesData = new DataSourceWizardResource().doGetDSWFilesAsDownload("SalesData");
    Assert.assertEquals(salesData.getStatus(), Response.Status.OK.getStatusCode());
    Assert.assertNotNull(salesData.getMetadata());
    Assert.assertNotNull(salesData.getMetadata().getFirst("Content-Disposition"));
    Assert.assertEquals(salesData.getMetadata().getFirst("Content-Disposition").getClass(), String.class);
    Assert.assertTrue(((String) salesData.getMetadata().getFirst("Content-Disposition")).endsWith(".xmi\""));
}
Also used : MetadataImportHandler(org.pentaho.platform.plugin.services.importer.MetadataImportHandler) ArrayList(java.util.ArrayList) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) MimeType(org.pentaho.platform.core.mimetype.MimeType) FileInputStream(java.io.FileInputStream) Response(javax.ws.rs.core.Response) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) DataSourceWizardResource(org.pentaho.platform.dataaccess.datasource.api.resources.DataSourceWizardResource) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileImportBundle(org.pentaho.platform.plugin.services.importer.RepositoryFileImportBundle) ZipFile(java.util.zip.ZipFile) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) Test(org.junit.Test)

Example 2 with MimeType

use of org.pentaho.platform.core.mimetype.MimeType in project pentaho-platform by pentaho.

the class MimeTypeListFactoryIT method testGetMimeTypeList.

@Test
public void testGetMimeTypeList() throws Exception {
    MicroPlatform microPlatform = new MicroPlatform();
    StandaloneSpringPentahoObjectFactory objectFactory = new StandaloneSpringPentahoObjectFactory();
    objectFactory.init(TestResourceLocation.TEST_RESOURCES + "/MimeTypeFactoryTest/MimeTypeFactoryTest.spring.xml", null);
    PentahoSystem.registerObjectFactory(objectFactory);
    MimeTypeListFactory factory = new MimeTypeListFactory(TestResourceLocation.TEST_RESOURCES + "/MimeTypeFactoryTest/ImportHandlerMimeTypeDefinitions.xml");
    List<IMimeType> list1 = factory.createMimeTypeList("org.pentaho.platform.plugin.services.importer.RepositoryFileImportFileHandler");
    assertNotNull(list1);
    list1 = factory.createMimeTypeList("this.one.is.not.present");
    assertNotNull(list1);
    assertEquals(0, list1.size());
    list1 = factory.createMimeTypeList("org.pentaho.platform.plugin.services.importer.SolutionImportHandler");
    assertNotNull(list1);
    assertTrue(list1.size() > 0);
    list1 = factory.createMimeTypeList("com.pentaho.repository.importexport.PDIImportFileHandler");
    assertNotNull(list1);
    assert (list1.contains(new MimeType("application/vnd.pentaho.job", "ktr")));
}
Also used : IMimeType(org.pentaho.platform.api.mimetype.IMimeType) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) MimeType(org.pentaho.platform.core.mimetype.MimeType) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory) Test(org.junit.Test)

Example 3 with MimeType

use of org.pentaho.platform.core.mimetype.MimeType in project pentaho-platform by pentaho.

the class MetadataImportHandlerIT method setUp.

@Before
public void setUp() throws Exception {
    // mock logger to prevent npe
    importLogger = new Log4JRepositoryImportLogger();
    context = new Mockery();
    metadataImporter = context.mock(IPentahoMetadataDomainRepositoryImporter.class);
    MicroPlatform microPlatform = new MicroPlatform();
    NameBaseMimeResolver nameResolver = new NameBaseMimeResolver();
    microPlatform.defineInstance(IPlatformMimeResolver.class, nameResolver);
    List<IMimeType> mimeList = new ArrayList<IMimeType>();
    mimeList.add(new MimeType("text/xmi+xml", "xmi"));
    metadataHandler = new MetadataImportHandler(mimeList, metadataImporter);
    handlers.add(metadataHandler);
    importer = new PentahoPlatformImporter(handlers, new DefaultRepositoryContentConverterHandler(new HashMap<String, Converter>()));
    importer.setRepositoryImportLogger(importLogger);
}
Also used : ArrayList(java.util.ArrayList) Mockery(org.jmock.Mockery) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) MimeType(org.pentaho.platform.core.mimetype.MimeType) IPentahoMetadataDomainRepositoryImporter(org.pentaho.platform.plugin.services.metadata.IPentahoMetadataDomainRepositoryImporter) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) Log4JRepositoryImportLogger(org.pentaho.platform.plugin.services.importexport.Log4JRepositoryImportLogger) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) Converter(org.pentaho.platform.api.repository2.unified.Converter) Before(org.junit.Before)

Example 4 with MimeType

use of org.pentaho.platform.core.mimetype.MimeType in project pentaho-platform by pentaho.

the class RepositoryFileImportFileHandlerTest method setup.

private void setup(String mimeTypeName, String extension, String path, String fileName, boolean folder) {
    List<String> extensions = Collections.singletonList(extension);
    IMimeType mimeType = new MimeType(mimeTypeName, extensions);
    mimeType.setConverter(mock(Converter.class));
    List<IMimeType> mimeTypeList = Collections.singletonList(mimeType);
    NameBaseMimeResolver mimeResolver = new NameBaseMimeResolver();
    mimeResolver.addMimeType(mimeType);
    SolutionFileImportHelper.testMimeResolver = mimeResolver;
    userProvider = new UserProvider();
    mockRepository = new MockUnifiedRepository(userProvider);
    fileHandler = new RepositoryFileImportFileHandler(mimeTypeList);
    fileHandler.setRepository(mockRepository);
    fileHandler.setDefaultAclHandler(new DefaultAclHandler());
    fileHandler.setKnownExtensions(Collections.singletonList("prpt"));
    IPlatformImporter mockPlatformImporter = mock(IPlatformImporter.class);
    when(mockPlatformImporter.getRepositoryImportLogger()).thenReturn(new Log4JRepositoryImportLogger());
    ImportSession.iPlatformImporter = mockPlatformImporter;
    importSession = fileHandler.getImportSession();
    importSession.initialize();
    mockBundle = mock(RepositoryFileImportBundle.class);
    when(mockBundle.getPath()).thenReturn(path);
    when(mockBundle.getName()).thenReturn(fileName);
    when(mockBundle.getMimeType()).thenReturn(mimeTypeName);
    when(mockBundle.isFolder()).thenReturn(folder);
}
Also used : MockUnifiedRepository(org.pentaho.test.platform.repository2.unified.MockUnifiedRepository) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) MimeType(org.pentaho.platform.core.mimetype.MimeType) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) IRepositoryDefaultAclHandler(org.pentaho.platform.api.repository2.unified.IRepositoryDefaultAclHandler) ICurrentUserProvider(org.pentaho.test.platform.repository2.unified.MockUnifiedRepository.ICurrentUserProvider) Log4JRepositoryImportLogger(org.pentaho.platform.plugin.services.importexport.Log4JRepositoryImportLogger) Converter(org.pentaho.platform.api.repository2.unified.Converter)

Example 5 with MimeType

use of org.pentaho.platform.core.mimetype.MimeType in project pentaho-platform by pentaho.

the class LocaleImportHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    mockUnifiedRepository = mock(IUnifiedRepository.class);
    pentahoSystemMock.when(() -> PentahoSystem.get(IUnifiedRepository.class)).thenReturn(mockUnifiedRepository);
    NameBaseMimeResolver nameResolver = new NameBaseMimeResolver();
    PentahoSystem.registerObject(nameResolver);
    IRepositoryContentConverterHandler converterHandler = new DefaultRepositoryContentConverterHandler(new HashMap<>());
    List<IMimeType> localeMimeList = new ArrayList<>();
    localeMimeList.add(new MimeType("text/locale", "locale"));
    nameResolver.addMimeType(new MimeType("text/prptMimeType", "prpt"));
    nameResolver.addMimeType(new MimeType("text/xactionMimeType", "xaction"));
    MimeType mimeType = new MimeType("text/xml", "xml");
    mimeType.setHidden(true);
    nameResolver.addMimeType(mimeType);
    mimeType = new MimeType("image/png", "png");
    mimeType.setHidden(true);
    nameResolver.addMimeType(mimeType);
    pentahoSystemMock.when(() -> PentahoSystem.get(IPlatformMimeResolver.class)).thenReturn(nameResolver);
    List<String> allowedArtifacts = new ArrayList<>();
    allowedArtifacts.add("xaction");
    allowedArtifacts.add("url");
    allowedArtifacts.add("properties");
    LocaleImportHandler localeImportHandler = new LocaleImportHandler(localeMimeList, allowedArtifacts);
    LocaleImportHandler spylocaleImportHandler = spy(localeImportHandler);
    Log log = mock(Log.class);
    doReturn(log).when(spylocaleImportHandler).getLogger();
    List<IPlatformImportHandler> handlers = new ArrayList<>();
    handlers.add(spylocaleImportHandler);
    importer = new PentahoPlatformImporter(handlers, converterHandler);
    importer.setRepositoryImportLogger(new Log4JRepositoryImportLogger());
    localeFilesProcessor = new LocaleFilesProcessor();
    this.localeImportHandler = new LocaleImportHandler(localeMimeList, allowedArtifacts);
}
Also used : Log(org.apache.commons.logging.Log) ArrayList(java.util.ArrayList) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) MimeType(org.pentaho.platform.core.mimetype.MimeType) IRepositoryContentConverterHandler(org.pentaho.platform.api.repository2.unified.IRepositoryContentConverterHandler) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) Log4JRepositoryImportLogger(org.pentaho.platform.plugin.services.importexport.Log4JRepositoryImportLogger) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Before(org.junit.Before)

Aggregations

IMimeType (org.pentaho.platform.api.mimetype.IMimeType)14 MimeType (org.pentaho.platform.core.mimetype.MimeType)14 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 Log4JRepositoryImportLogger (org.pentaho.platform.plugin.services.importexport.Log4JRepositoryImportLogger)8 Converter (org.pentaho.platform.api.repository2.unified.Converter)6 File (java.io.File)4 FileInputStream (java.io.FileInputStream)4 IRepositoryContentConverterHandler (org.pentaho.platform.api.repository2.unified.IRepositoryContentConverterHandler)4 Before (org.junit.Before)3 IPlatformImportBundle (org.pentaho.platform.api.repository2.unified.IPlatformImportBundle)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 HashMap (java.util.HashMap)2 ZipFile (java.util.zip.ZipFile)2 Response (javax.ws.rs.core.Response)2 Log (org.apache.commons.logging.Log)2 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)2 DataSourceWizardResource (org.pentaho.platform.dataaccess.datasource.api.resources.DataSourceWizardResource)2 RepositoryFileImportBundle (org.pentaho.platform.plugin.services.importer.RepositoryFileImportBundle)2 IRepositoryImportLogger (org.pentaho.platform.plugin.services.importexport.IRepositoryImportLogger)2