use of ddf.catalog.transform.InputTransformer in project ddf by codice.
the class TestRestEndpoint method getMockInputTransformer.
protected InputTransformer getMockInputTransformer() {
InputTransformer inputTransformer = mock(InputTransformer.class);
Metacard generatedMetacard = getSimpleMetacard();
try {
when(inputTransformer.transform(isA(InputStream.class))).thenReturn(generatedMetacard);
when(inputTransformer.transform(isA(InputStream.class), isA(String.class))).thenReturn(generatedMetacard);
} catch (IOException e) {
LOGGER.debug("Exception occurred during test", e);
} catch (CatalogTransformerException e) {
LOGGER.debug("Exception occurred during test", e);
}
return inputTransformer;
}
use of ddf.catalog.transform.InputTransformer in project ddf by codice.
the class TestRestEndpoint method addMatchingService.
private MimeTypeToTransformerMapper addMatchingService(RESTEndpoint rest, List<InputTransformer> sortedListOfTransformers) {
MimeTypeToTransformerMapper matchingService = mock(MimeTypeToTransformerMapper.class);
when(matchingService.findMatches(eq(InputTransformer.class), isA(MimeType.class))).thenReturn((List) sortedListOfTransformers);
rest.setMimeTypeToTransformerMapper(matchingService);
return matchingService;
}
use of ddf.catalog.transform.InputTransformer in project ddf by codice.
the class TestOpenSearchSource method getMockInputTransformer.
protected InputTransformer getMockInputTransformer() {
InputTransformer inputTransformer = mock(InputTransformer.class);
Metacard generatedMetacard = getSimpleMetacard();
try {
when(inputTransformer.transform(isA(InputStream.class))).thenReturn(generatedMetacard);
when(inputTransformer.transform(isA(InputStream.class), isA(String.class))).thenReturn(generatedMetacard);
} catch (IOException e) {
fail();
} catch (CatalogTransformerException e) {
fail();
}
return inputTransformer;
}
use of ddf.catalog.transform.InputTransformer in project ddf by codice.
the class OpenSearchSource method getInputTransformer.
private InputTransformer getInputTransformer(InputStream inputStream) {
XMLStreamReader xmlStreamReader = null;
try {
xmlStreamReader = xmlInputFactory.createXMLStreamReader(inputStream);
while (xmlStreamReader.hasNext()) {
int next = xmlStreamReader.next();
if (next == XMLStreamConstants.START_ELEMENT) {
String namespaceUri = xmlStreamReader.getNamespaceURI();
InputTransformer transformerReference = lookupTransformerReference(namespaceUri);
if (transformerReference != null) {
return transformerReference;
}
}
}
} catch (XMLStreamException | InvalidSyntaxException e) {
LOGGER.debug("Failed to parse transformer namespace", e);
} finally {
try {
if (xmlStreamReader != null) {
xmlStreamReader.close();
}
} catch (XMLStreamException e) {
LOGGER.debug("failed to close namespace reader", e);
}
}
return null;
}
use of ddf.catalog.transform.InputTransformer in project ddf by codice.
the class InputTransformerProducer method generateMetacard.
private Metacard generateMetacard(MimeType mimeType, MimeTypeToTransformerMapper mapper, InputStream message) throws MetacardCreationException {
LOGGER.trace("ENTERING: generateMetacard");
List<InputTransformer> listOfCandidates = mapper.findMatches(InputTransformer.class, mimeType);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("List of matches for mimeType [{}]: {}", mimeType, listOfCandidates);
}
Metacard generatedMetacard = null;
try (TemporaryFileBackedOutputStream fileBackedOutputStream = new TemporaryFileBackedOutputStream()) {
try {
IOUtils.copy(message, fileBackedOutputStream);
} catch (IOException e) {
throw new MetacardCreationException("Could not copy bytes of content message.", e);
}
// can create the metacard, then do not need to try any remaining InputTransformers.
for (InputTransformer transformer : listOfCandidates) {
try (InputStream inputStreamMessageCopy = fileBackedOutputStream.asByteSource().openStream()) {
generatedMetacard = transformer.transform(inputStreamMessageCopy);
} catch (IOException | CatalogTransformerException e) {
LOGGER.debug("Transformer [" + transformer + "] could not create metacard.", e);
}
if (generatedMetacard != null) {
break;
}
}
if (generatedMetacard == null) {
throw new MetacardCreationException("Could not create metacard with mimeType " + mimeType + ". No valid transformers found.");
}
LOGGER.trace("EXITING: generateMetacard");
} catch (IOException e) {
throw new MetacardCreationException("Could not create metacard.", e);
}
return generatedMetacard;
}
Aggregations