Search in sources :

Example 6 with Converter

use of org.pentaho.platform.api.repository2.unified.Converter in project pentaho-platform by pentaho.

the class MimeTypeTest method setAndGetConverterTest.

@Test
public void setAndGetConverterTest() {
    Converter conv = mock(Converter.class);
    mimeType.setConverter(conv);
    assertEquals(conv, mimeType.getConverter());
}
Also used : Converter(org.pentaho.platform.api.repository2.unified.Converter) Test(org.junit.Test)

Example 7 with Converter

use of org.pentaho.platform.api.repository2.unified.Converter in project pentaho-platform by pentaho.

the class RepositoryFileHelper method getFileData.

public static IRepositoryFileData getFileData(RepositoryFile repositoryFile) {
    IRepositoryContentConverterHandler converterHandler;
    Map<String, Converter> converters;
    IPlatformMimeResolver mimeResolver;
    IRepositoryFileData repositoryFileData = null;
    if (!repositoryFile.isFolder()) {
        // Get the extension
        final String ext = RepositoryFilenameUtils.getExtension(repositoryFile.getName());
        if ((ext == null) || (ext.isEmpty())) {
            return null;
        }
        // Find the converter
        // If we have not been given a handler, try PentahoSystem
        converterHandler = PentahoSystem.get(IRepositoryContentConverterHandler.class);
        // fail if we have no converter handler
        if (converterHandler == null) {
            return null;
        }
        converters = converterHandler.getConverters();
        final Converter converter = converters.get(ext);
        if (converter == null) {
            return null;
        }
        // Check the mime type
        mimeResolver = PentahoSystem.get(IPlatformMimeResolver.class);
        // fail if we have no mime resolver
        if (mimeResolver == null) {
            return null;
        }
        final String mimeType = mimeResolver.resolveMimeTypeForFileName(repositoryFile.getName()).getName();
        if ((mimeType == null) || (mimeType.isEmpty())) {
            return null;
        }
        // Get the input stream
        InputStream inputStream = converter.convert(repositoryFile.getId());
        if (inputStream == null) {
            return null;
        }
        // Get the file data
        repositoryFileData = converter.convert(inputStream, "UTF-8", mimeType);
        if (repositoryFileData == null) {
            return null;
        }
    }
    return repositoryFileData;
}
Also used : IRepositoryFileData(org.pentaho.platform.api.repository2.unified.IRepositoryFileData) IRepositoryContentConverterHandler(org.pentaho.platform.api.repository2.unified.IRepositoryContentConverterHandler) IPlatformMimeResolver(org.pentaho.platform.api.mimetype.IPlatformMimeResolver) InputStream(java.io.InputStream) Converter(org.pentaho.platform.api.repository2.unified.Converter)

Example 8 with Converter

use of org.pentaho.platform.api.repository2.unified.Converter 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 9 with Converter

use of org.pentaho.platform.api.repository2.unified.Converter in project pentaho-kettle by pentaho.

the class StreamToTransNodeConverterTest method convertPostRepoSave.

@Test
public void convertPostRepoSave() throws Exception {
    StreamToTransNodeConverter converter = mock(StreamToTransNodeConverter.class);
    doCallRealMethod().when(converter).convertPostRepoSave(any(RepositoryFile.class));
    Repository repository = mock(Repository.class);
    when(converter.connectToRepository()).thenReturn(repository);
    TransMeta transMeta = mock(TransMeta.class);
    when(repository.loadTransformation(any(), anyString())).thenReturn(transMeta);
    RepositoryFile file = mock(RepositoryFile.class);
    when(file.getId()).thenReturn("fileId");
    PluginMockInterface pluginInterface = mock(PluginMockInterface.class);
    when(pluginInterface.getName()).thenReturn(KettleExtensionPoint.TransImportAfterSaveToRepo.id);
    when(pluginInterface.getMainType()).thenReturn((Class) ExtensionPointInterface.class);
    when(pluginInterface.getIds()).thenReturn(new String[] { "extensionpointId" });
    ExtensionPointInterface extensionPoint = mock(ExtensionPointInterface.class);
    when(pluginInterface.loadClass(ExtensionPointInterface.class)).thenReturn(extensionPoint);
    PluginRegistry.addPluginType(ExtensionPointPluginType.getInstance());
    PluginRegistry.getInstance().registerPlugin(ExtensionPointPluginType.class, pluginInterface);
    converter.convertPostRepoSave(file);
    verify(extensionPoint, times(1)).callExtensionPoint(any(LogChannelInterface.class), same(transMeta));
}
Also used : Repository(org.pentaho.di.repository.Repository) TransMeta(org.pentaho.di.trans.TransMeta) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) ExtensionPointInterface(org.pentaho.di.core.extension.ExtensionPointInterface) Test(org.junit.Test)

Example 10 with Converter

use of org.pentaho.platform.api.repository2.unified.Converter 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)

Aggregations

Converter (org.pentaho.platform.api.repository2.unified.Converter)13 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)7 IMimeType (org.pentaho.platform.api.mimetype.IMimeType)7 Log4JRepositoryImportLogger (org.pentaho.platform.plugin.services.importexport.Log4JRepositoryImportLogger)7 IRepositoryContentConverterHandler (org.pentaho.platform.api.repository2.unified.IRepositoryContentConverterHandler)6 MimeType (org.pentaho.platform.core.mimetype.MimeType)6 File (java.io.File)5 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)5 FileInputStream (java.io.FileInputStream)4 HashMap (java.util.HashMap)4 IPlatformImportBundle (org.pentaho.platform.api.repository2.unified.IPlatformImportBundle)4 IRepositoryFileData (org.pentaho.platform.api.repository2.unified.IRepositoryFileData)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 Before (org.junit.Before)3 FileNotFoundException (java.io.FileNotFoundException)2 Log (org.apache.commons.logging.Log)2 IPlatformMimeResolver (org.pentaho.platform.api.mimetype.IPlatformMimeResolver)2 IRepositoryImportLogger (org.pentaho.platform.plugin.services.importexport.IRepositoryImportLogger)2