use of ddf.catalog.transform.CatalogTransformerException in project ddf by codice.
the class RestReplicatorPlugin method transform.
private String transform(Metacard m, WebClient client) throws PluginExecutionException {
BinaryContent binaryContent;
try {
binaryContent = transformer.transform(m, new HashMap<>());
client.type(getValidMimeType(binaryContent.getMimeTypeValue()));
return new String(binaryContent.getByteArray(), StandardCharsets.UTF_8);
} catch (IOException e) {
LOGGER.debug("Could not understand metacard.", e);
throw new PluginExecutionException("Could not send metacard.");
} catch (CatalogTransformerException e) {
LOGGER.debug("Could not transform metacard.", e);
throw new PluginExecutionException("Could not send metacard.");
}
}
use of ddf.catalog.transform.CatalogTransformerException in project ddf by codice.
the class ExportCommand method writeResultToZip.
private void writeResultToZip(/*Mutable,IO*/
ZipOutputStream zipOutputStream, Result result) {
String id = result.getMetacard().getId();
ZipEntry zipEntry = new ZipEntry(Paths.get("metacards", id.substring(0, 3), id, "metacard", id + ".xml").toString());
try {
BinaryContent binaryMetacard = transformer.transform(result.getMetacard(), Collections.emptyMap());
try (InputStream metacardStream = binaryMetacard.getInputStream()) {
zipOutputStream.putNextEntry(zipEntry);
IOUtils.copy(metacardStream, zipOutputStream);
}
} catch (CatalogTransformerException | IOException e) {
LOGGER.warn("Could not transform metacard. Metacard will not be added to zip [{}]", result.getMetacard().getId());
console.printf("%sCould not transform metacard. Metacard will not be included in export. %s - %s%s%n", Ansi.ansi().fg(Ansi.Color.RED).toString(), result.getMetacard().getId(), result.getMetacard().getTitle(), Ansi.ansi().reset().toString());
}
}
use of ddf.catalog.transform.CatalogTransformerException 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.");
}
}
use of ddf.catalog.transform.CatalogTransformerException in project ddf by codice.
the class DumpCommand method exportMetacard.
private void exportMetacard(File dumpLocation, Metacard metacard, AtomicLong resultCount) throws IOException {
if (SERIALIZED_OBJECT_ID.matches(transformerId)) {
try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(getOutputFile(dumpLocation, metacard)))) {
oos.writeObject(new MetacardImpl(metacard));
oos.flush();
resultCount.incrementAndGet();
}
} else {
BinaryContent binaryContent;
if (metacard != null) {
for (MetacardTransformer transformer : transformers) {
try {
binaryContent = transformer.transform(metacard, new HashMap<>());
if (binaryContent != null) {
try (FileOutputStream fos = new FileOutputStream(getOutputFile(dumpLocation, metacard))) {
fos.write(binaryContent.getByteArray());
fos.flush();
}
resultCount.incrementAndGet();
break;
}
} catch (CatalogTransformerException e) {
LOGGER.info("One or more metacards failed to transform. Enable debug log for more details.");
}
}
}
}
}
use of ddf.catalog.transform.CatalogTransformerException in project ddf by codice.
the class DumpCommand method createZip.
private void createZip(CatalogFacade catalog, QueryRequest queryRequest, File outputFile, AtomicLong resultCount) throws CatalogTransformerException {
try (FileOutputStream fileOutputStream = new FileOutputStream(outputFile);
ZipOutputStream zipOutputStream = new ZipOutputStream(fileOutputStream)) {
// write the metacards to the zip
ResultIterable.resultIterable(catalog::query, queryRequest).stream().map(Result::getMetacard).forEach(metacard -> {
writeMetacardToZip(zipOutputStream, metacard);
if (hasLocalResources(metacard)) {
// write the resources to the zip
Map<String, Resource> resourceMap = getAllMetacardContent(metacard);
resourceMap.forEach((filename, resource) -> writeResourceToZip(zipOutputStream, filename, resource));
}
resultCount.incrementAndGet();
});
} catch (IOException e) {
throw new CatalogTransformerException(String.format("Error occurred when initializing/closing ZipOutputStream with path %s.", outputFile.getAbsoluteFile()), e);
}
}
Aggregations