Search in sources :

Example 1 with InputCollectionTransformer

use of ddf.catalog.transform.InputCollectionTransformer in project ddf by codice.

the class IngestCommand method processIncludeContent.

private void processIncludeContent(ArrayBlockingQueue<Metacard> metacardQueue) {
    File inputFile = new File(filePath);
    Map<String, Serializable> arguments = new HashMap<>();
    arguments.put(DumpCommand.FILE_PATH, inputFile.getParent() + File.separator);
    arguments.put(FILE_NAME, inputFile.getName());
    ByteSource byteSource = com.google.common.io.Files.asByteSource(inputFile);
    Optional<InputCollectionTransformer> zipDecompression = getZipDecompression();
    if (zipDecompression.isPresent()) {
        try (InputStream inputStream = byteSource.openBufferedStream()) {
            List<Metacard> metacardList = zipDecompression.get().transform(inputStream, arguments).stream().filter(Objects::nonNull).collect(Collectors.toList());
            if (!metacardList.isEmpty()) {
                metacardFileMapping = generateFileMap(new File(inputFile.getParent(), CONTENT_PATH));
                fileCount.set(metacardList.size());
                for (Metacard metacard : metacardList) {
                    putMetacardOnQueue(metacardQueue, metacard);
                }
            }
        } catch (IOException | CatalogTransformerException e) {
            LOGGER.info("Unable to transform zip file into metacard list.", e);
            INGEST_LOGGER.warn("Unable to transform zip file into metacard list.", e);
        }
    } else {
        LOGGER.info("No Zip Transformer found. Unable to transform zip file into metacard list.");
        INGEST_LOGGER.warn("No Zip Transformer found. Unable to transform zip file into metacard list.");
    }
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) ObjectInputStream(java.io.ObjectInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) InputCollectionTransformer(ddf.catalog.transform.InputCollectionTransformer) Metacard(ddf.catalog.data.Metacard) ByteSource(com.google.common.io.ByteSource) File(java.io.File)

Aggregations

ByteSource (com.google.common.io.ByteSource)1 Metacard (ddf.catalog.data.Metacard)1 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)1 InputCollectionTransformer (ddf.catalog.transform.InputCollectionTransformer)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 Serializable (java.io.Serializable)1 UncheckedIOException (java.io.UncheckedIOException)1 HashMap (java.util.HashMap)1