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