Search in sources :

Example 1 with IRepositoryContentConverterHandler

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

the class FileResourceTest method initTest.

@BeforeClass
public static void initTest() {
    IRepositoryContentConverterHandler handler = mock(IRepositoryContentConverterHandler.class);
    when(handler.getConverter(XML_EXTENSION)).thenReturn(new StreamConverter());
    PentahoSystem.registerObject(handler);
}
Also used : IRepositoryContentConverterHandler(org.pentaho.platform.api.repository2.unified.IRepositoryContentConverterHandler) StreamConverter(org.pentaho.platform.plugin.services.importexport.StreamConverter) BeforeClass(org.junit.BeforeClass)

Example 2 with IRepositoryContentConverterHandler

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

the class LocaleImportHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    NameBaseMimeResolver nameResolver = new NameBaseMimeResolver();
    PentahoSystem.registerObject(nameResolver);
    IRepositoryContentConverterHandler converterHandler = new DefaultRepositoryContentConverterHandler(new HashMap<String, Converter>());
    List<IMimeType> localeMimeList = new ArrayList<IMimeType>();
    localeMimeList.add(new MimeType("text/locale", "locale"));
    nameResolver.addMimeType(new MimeType("text/prptMimeType", "prpt"));
    nameResolver.addMimeType(new MimeType("text/xactionMimeType", "xaction"));
    MimeType mimeType = new MimeType("text/xml", "xml");
    mimeType.setHidden(true);
    nameResolver.addMimeType(mimeType);
    mimeType = new MimeType("image/png", "png");
    mimeType.setHidden(true);
    nameResolver.addMimeType(mimeType);
    List<String> allowedArtifacts = new ArrayList<String>();
    allowedArtifacts.add("xaction");
    allowedArtifacts.add("url");
    LocaleImportHandler localeImportHandler = new LocaleImportHandler(localeMimeList, allowedArtifacts);
    LocaleImportHandler spylocaleImportHandler = spy(localeImportHandler);
    Log log = mock(Log.class);
    doReturn(log).when(spylocaleImportHandler).getLogger();
    List<IPlatformImportHandler> handlers = new ArrayList<IPlatformImportHandler>();
    handlers.add(spylocaleImportHandler);
    importer = new PentahoPlatformImporter(handlers, converterHandler);
    importer.setRepositoryImportLogger(new Log4JRepositoryImportLogger());
    localeFilesProcessor = new LocaleFilesProcessor();
}
Also used : Log(org.apache.commons.logging.Log) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) MimeType(org.pentaho.platform.core.mimetype.MimeType) 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) Before(org.junit.Before)

Example 3 with IRepositoryContentConverterHandler

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

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

the class DefaultExportHandler method doExport.

/**
 * Perform export with registered handlers
 */
@Override
public InputStream doExport(RepositoryFile repositoryFile, String filePath) throws ExportException, IOException {
    InputStream is = null;
    // Compute the file extension
    final String name = repositoryFile.getName();
    final String ext = RepositoryFilenameUtils.getExtension(name);
    if (StringUtils.isEmpty(ext)) {
        log.debug("Skipping file without extension: " + name);
    }
    // Find the converter - defined in spring xml by import handlers
    if (converters == null) {
        IRepositoryContentConverterHandler converterHandler = PentahoSystem.get(IRepositoryContentConverterHandler.class);
        converters = converterHandler.getConverters();
    }
    final Converter converter = converters.get(ext);
    if (converter == null) {
        log.debug("Skipping file without converter: " + name);
        return null;
    }
    // since it is already based on the file extension
    return converter.convert(repositoryFile.getId());
}
Also used : IRepositoryContentConverterHandler(org.pentaho.platform.api.repository2.unified.IRepositoryContentConverterHandler) InputStream(java.io.InputStream) Converter(org.pentaho.platform.api.repository2.unified.Converter)

Example 5 with IRepositoryContentConverterHandler

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

Aggregations

IRepositoryContentConverterHandler (org.pentaho.platform.api.repository2.unified.IRepositoryContentConverterHandler)8 Converter (org.pentaho.platform.api.repository2.unified.Converter)6 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 IMimeType (org.pentaho.platform.api.mimetype.IMimeType)3 Log4JRepositoryImportLogger (org.pentaho.platform.plugin.services.importexport.Log4JRepositoryImportLogger)3 File (java.io.File)2 Log (org.apache.commons.logging.Log)2 Before (org.junit.Before)2 IPlatformMimeResolver (org.pentaho.platform.api.mimetype.IPlatformMimeResolver)2 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)2 MimeType (org.pentaho.platform.core.mimetype.MimeType)2 StreamConverter (org.pentaho.platform.plugin.services.importexport.StreamConverter)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1 ISolutionEngine (org.pentaho.platform.api.engine.ISolutionEngine)1