Search in sources :

Example 6 with IMimeType

use of org.pentaho.platform.api.mimetype.IMimeType 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 7 with IMimeType

use of org.pentaho.platform.api.mimetype.IMimeType 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 8 with IMimeType

use of org.pentaho.platform.api.mimetype.IMimeType in project pentaho-platform by pentaho.

the class MimeTypeListFactory method createMimeTypeList.

public List<IMimeType> createMimeTypeList(String handlerClass) {
    List<IMimeType> mimeTypeList = new ArrayList<IMimeType>();
    for (ImportHandlerDto importHandler : importHandlerMimeTypeDefinitions.getImportHandler()) {
        if (importHandler.getClazz().equals(handlerClass)) {
            for (MimeTypeDefinitionDto mimeTypeDef : importHandler.getMimeTypeDefinitions().getMimeTypeDefinition()) {
                MimeType mimeType = new MimeType(mimeTypeDef.getMimeType(), mimeTypeDef.getExtension());
                mimeType.setHidden(mimeTypeDef.isHidden());
                mimeType.setLocale(mimeTypeDef.isLocale());
                mimeType.setVersionEnabled(mimeTypeDef.isVersionEnabled());
                mimeType.setVersionCommentEnabled(mimeTypeDef.isVersionCommentEnabled());
                Converter converter = null;
                String converterBeanName = mimeTypeDef.getConverter() != null && !mimeTypeDef.getConverter().isEmpty() ? mimeTypeDef.getConverter() : "streamConverter";
                converter = PentahoSystem.get(Converter.class, /*session*/
                null, Collections.singletonMap("name", converterBeanName));
                if (converter == null) {
                    log.error("Could not find converter class \"" + converterBeanName + "\" for mimeType \"" + mimeTypeDef.getMimeType() + "\" in import handler " + handlerClass);
                }
                mimeType.setConverter(converter);
                mimeTypeList.add(mimeType);
            }
        }
    }
    return mimeTypeList;
}
Also used : MimeTypeDefinitionDto(org.pentaho.platform.plugin.services.importer.mimeType.bindings.MimeTypeDefinitionDto) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) ImportHandlerDto(org.pentaho.platform.plugin.services.importer.mimeType.bindings.ImportHandlerDto) ArrayList(java.util.ArrayList) Converter(org.pentaho.platform.api.repository2.unified.Converter) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) MimeType(org.pentaho.platform.core.mimetype.MimeType)

Example 9 with IMimeType

use of org.pentaho.platform.api.mimetype.IMimeType in project pentaho-platform by pentaho.

the class PentahoPlatformImporter method addHandler.

@Override
public void addHandler(IPlatformImportHandler platformImportHandler) {
    for (IMimeType mimeType : platformImportHandler.getMimeTypes()) {
        this.importHandlers.put(mimeType.getName(), platformImportHandler);
        this.mimeResolver.addMimeType(mimeType);
        for (String extension : mimeType.getExtensions()) {
            repositoryContentConverterHandler.addConverter(extension, mimeType.getConverter());
        }
    }
}
Also used : IMimeType(org.pentaho.platform.api.mimetype.IMimeType)

Example 10 with IMimeType

use of org.pentaho.platform.api.mimetype.IMimeType in project pentaho-platform by pentaho.

the class SolutionFileImportHelper method isInApprovedExtensionList.

public boolean isInApprovedExtensionList(String fileName) {
    boolean isInTheApprovedExtensionList = false;
    IMimeType mimeType = getMimeType(fileName);
    if (mimeType != null) {
        isInTheApprovedExtensionList = (mimeType.getConverter() != null);
    }
    return isInTheApprovedExtensionList;
}
Also used : IMimeType(org.pentaho.platform.api.mimetype.IMimeType)

Aggregations

IMimeType (org.pentaho.platform.api.mimetype.IMimeType)18 MimeType (org.pentaho.platform.core.mimetype.MimeType)12 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)7 Log4JRepositoryImportLogger (org.pentaho.platform.plugin.services.importexport.Log4JRepositoryImportLogger)7 Before (org.junit.Before)6 Converter (org.pentaho.platform.api.repository2.unified.Converter)6 File (java.io.File)5 FileInputStream (java.io.FileInputStream)4 Log (org.apache.commons.logging.Log)3 IPlatformMimeResolver (org.pentaho.platform.api.mimetype.IPlatformMimeResolver)3 IPlatformImportBundle (org.pentaho.platform.api.repository2.unified.IPlatformImportBundle)3 IRepositoryContentConverterHandler (org.pentaho.platform.api.repository2.unified.IRepositoryContentConverterHandler)3 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)3 HashMap (java.util.HashMap)2 ZipFile (java.util.zip.ZipFile)2 Response (javax.ws.rs.core.Response)2 Mockery (org.jmock.Mockery)2 Matchers.anyString (org.mockito.Matchers.anyString)2 DataSourceWizardResource (org.pentaho.platform.dataaccess.datasource.api.resources.DataSourceWizardResource)2