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