Search in sources :

Example 6 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 7 with MimeType

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

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

the class LocaleFilesProcessorTest method testProcessLocaleFilesTwoLocaleFiles.

@Test
public void testProcessLocaleFilesTwoLocaleFiles() throws Exception {
    IRepositoryContentConverterHandler converterHandler = new DefaultRepositoryContentConverterHandler(new HashMap<String, Converter>());
    List<IMimeType> localeMimeList = new ArrayList<IMimeType>();
    localeMimeList.add(new MimeType("text/locale", "locale"));
    LocaleImportHandler localeImportHandler = new LocaleImportHandler(localeMimeList, null);
    LocaleImportHandler localeImportHandlerSpy = spy(localeImportHandler);
    Log log = mock(Log.class);
    doReturn(log).when(localeImportHandlerSpy).getLogger();
    String localeFileName = "SampleTransformationWithParameters";
    List<IPlatformImportHandler> handlers = new ArrayList<IPlatformImportHandler>();
    handlers.add(localeImportHandlerSpy);
    importer = new PentahoPlatformImporter(handlers, converterHandler);
    importer.setRepositoryImportLogger(new Log4JRepositoryImportLogger());
    localeFilesProcessor = new LocaleFilesProcessor();
    StringBuffer localePropertiesContent = new StringBuffer();
    localePropertiesContent.append("description=This runs a simple Kettle transformation filtering records from the Quandrant_Actuals sample data " + "table, and sending a Hello message to each position.\n");
    localePropertiesContent.append("name=1. Hello ETL");
    assertTrue(processIsLocalFile("SampleTransformation.properties", localePropertiesContent));
    StringBuffer localeContent = new StringBuffer();
    localeContent.append("file.title=" + localeFileName + "\n");
    localeContent.append("title=SampleTransformation\n");
    localeContent.append("file.description=");
    assertTrue(processIsLocalFile("SampleTransformation.xaction.locale", localeContent));
    localeFilesProcessor.processLocaleFiles(importer);
    // verify that in case of both .properties and .locale files are at input the only one proceeded is .locale
    Mockito.verify(localeImportHandlerSpy, times(1)).importFile(any(IPlatformImportBundle.class));
    ArgumentCaptor<IPlatformImportBundle> argument = ArgumentCaptor.forClass(IPlatformImportBundle.class);
    Mockito.verify(localeImportHandlerSpy).importFile(argument.capture());
    assertEquals(localeFileName, argument.getValue().getName());
}
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) IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) IRepositoryContentConverterHandler(org.pentaho.platform.api.repository2.unified.IRepositoryContentConverterHandler) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) Log4JRepositoryImportLogger(org.pentaho.platform.plugin.services.importexport.Log4JRepositoryImportLogger) Converter(org.pentaho.platform.api.repository2.unified.Converter) Test(org.junit.Test)

Example 9 with MimeType

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

the class MetadataImportHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    context = new Mockery();
    metadataImporter = context.mock(IPentahoMetadataDomainRepositoryImporter.class);
    List<IMimeType> mimeList = new ArrayList<IMimeType>();
    mimeList.add(new MimeType("text/xmi+xml", "xmi"));
    metadataHandler = new MetadataImportHandler(mimeList, metadataImporter);
}
Also used : IPentahoMetadataDomainRepositoryImporter(org.pentaho.platform.plugin.services.metadata.IPentahoMetadataDomainRepositoryImporter) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) ArrayList(java.util.ArrayList) Mockery(org.jmock.Mockery) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) MimeType(org.pentaho.platform.core.mimetype.MimeType) Before(org.junit.Before)

Example 10 with MimeType

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

the class NameBaseMimeResolverTest method testResolveMimeTypeForFileName.

@Test
public void testResolveMimeTypeForFileName() {
    MimeType expectedMimeType = new MimeType("othertest/other-test-mime", "smt");
    IMimeType actualMimeType = resolver.resolveMimeTypeForFileName("test.smt");
    assertEquals(actualMimeType, expectedMimeType);
}
Also used : IMimeType(org.pentaho.platform.api.mimetype.IMimeType) MimeType(org.pentaho.platform.core.mimetype.MimeType) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) Test(org.junit.Test)

Aggregations

IMimeType (org.pentaho.platform.api.mimetype.IMimeType)12 MimeType (org.pentaho.platform.core.mimetype.MimeType)12 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 Log4JRepositoryImportLogger (org.pentaho.platform.plugin.services.importexport.Log4JRepositoryImportLogger)6 Converter (org.pentaho.platform.api.repository2.unified.Converter)5 File (java.io.File)4 FileInputStream (java.io.FileInputStream)4 Before (org.junit.Before)3 IPlatformImportBundle (org.pentaho.platform.api.repository2.unified.IPlatformImportBundle)3 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 Mockery (org.jmock.Mockery)2 Matchers.anyString (org.mockito.Matchers.anyString)2 IRepositoryContentConverterHandler (org.pentaho.platform.api.repository2.unified.IRepositoryContentConverterHandler)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