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());
}
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;
}
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);
}
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));
}
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;
}
Aggregations