use of ddf.catalog.data.impl.BinaryContentImpl in project ddf by codice.
the class TestCswQueryResponseTransformer method verifyResultOrderIsMaintained.
@Test
public void verifyResultOrderIsMaintained() throws CatalogTransformerException, IOException {
// when
when(mockPrintWriterProvider.build((Class<Metacard>) notNull())).thenReturn(mockPrintWriter);
when(mockPrintWriter.makeString()).thenReturn(new String());
when(mockSourceResponse.getResults()).thenReturn(createResults(1, 10));
when(mockSourceResponse.getRequest()).thenReturn(mockQueryRequest);
when(mockQueryRequest.getQuery()).thenReturn(mockQuery);
when(mockArguments.get(CswConstants.RESULT_TYPE_PARAMETER)).thenReturn(ResultType.RESULTS);
when(mockTransformerManager.getTransformerBySchema(anyString())).thenReturn(mockMetacardTransformer);
when(mockMetacardTransformer.transform(any(Metacard.class), any(Map.class))).thenAnswer(invocationOnMock -> {
Metacard metacard = (Metacard) invocationOnMock.getArguments()[0];
BinaryContentImpl bci = new BinaryContentImpl(IOUtils.toInputStream(metacard.getId() + ","), new MimeType("application/xml"));
return bci;
});
// given
transformer.init();
transformer.transform(mockSourceResponse, mockArguments);
transformer.destroy();
// then
ArgumentCaptor<String> tmCaptor = ArgumentCaptor.forClass(String.class);
verify(mockTransformerManager, times(1)).getTransformerBySchema(tmCaptor.capture());
ArgumentCaptor<Map> mapCaptor = ArgumentCaptor.forClass(Map.class);
ArgumentCaptor<Metacard> mcCaptor = ArgumentCaptor.forClass(Metacard.class);
verify(mockMetacardTransformer, times(10)).transform(mcCaptor.capture(), mapCaptor.capture());
ArgumentCaptor<String> strCaptor = ArgumentCaptor.forClass(String.class);
verify(mockPrintWriter, times(2)).setRawValue(strCaptor.capture());
String order = strCaptor.getAllValues().get(1);
String[] ids = order.split(",");
for (int i = 1; i < ids.length; i++) {
assertThat(ids[i - 1], is(String.valueOf("id_" + i)));
}
}
use of ddf.catalog.data.impl.BinaryContentImpl in project ddf by codice.
the class PropertyJsonMetacardTransformer method transform.
@Override
public BinaryContent transform(Metacard metacard, Map<String, Serializable> arguments) throws CatalogTransformerException {
Map<String, Object> rootObject = convertToJSON(metacard);
String jsonText = json.serialize(rootObject).toString();
return new BinaryContentImpl(new ByteArrayInputStream(jsonText.getBytes(StandardCharsets.UTF_8)), DEFAULT_MIME_TYPE);
}
use of ddf.catalog.data.impl.BinaryContentImpl in project ddf by codice.
the class TestCswTransformProvider method testMarshalOtherSchema.
@Test
public void testMarshalOtherSchema() throws Exception {
when(mockMetacardManager.getTransformerByProperty(TransformerManager.SCHEMA, OTHER_SCHEMA)).thenReturn(mockMetacardTransformer);
when(mockMetacardTransformer.transform(any(Metacard.class), any(Map.class))).thenReturn(new BinaryContentImpl(IOUtils.toInputStream(getRecord()), new MimeType(MediaType.APPLICATION_XML)));
StringWriter stringWriter = new StringWriter();
HierarchicalStreamWriter writer = new WstxDriver().createWriter(stringWriter);
CswTransformProvider provider = new CswTransformProvider(mockMetacardManager, null);
MarshallingContext context = new TreeMarshaller(writer, null, null);
context.put(CswConstants.TRANSFORMER_LOOKUP_KEY, TransformerManager.SCHEMA);
context.put(CswConstants.TRANSFORMER_LOOKUP_VALUE, OTHER_SCHEMA);
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
provider.marshal(getMetacard(), writer, context);
// Verify the context arguments were set correctly
verify(mockMetacardManager, times(1)).getTransformerByProperty(captor.capture(), captor.capture());
String outputSchema = captor.getValue();
assertThat(outputSchema, is(OTHER_SCHEMA));
}
use of ddf.catalog.data.impl.BinaryContentImpl in project ddf by codice.
the class ConfigurationStore method getDocument.
@GET
@Path("/config")
public Response getDocument(@Context UriInfo uriInfo, @Context HttpServletRequest httpRequest) {
Response response;
Map<String, Object> config = new HashMap<>();
config.put("branding", getProductName());
config.put("version", getProductVersion());
config.put("showWelcome", isSignIn);
config.put("showTask", isTask);
config.put("format", format);
config.put("timeout", timeout);
config.put("resultCount", resultCount);
config.put("typeNameMapping", typeNameMapping);
config.put("terrainProvider", proxiedTerrainProvider);
config.put("imageryProviders", getProxiedImageryProviders());
config.put("gazetteer", isGazetteer);
config.put("showIngest", isIngest);
config.put("projection", projection);
config.put("helpUrl", helpUrl);
config.put("bingKey", bingKey);
config.put("externalAuthentication", isExternalAuthentication);
String configJson = toJson(config);
BinaryContent content = new BinaryContentImpl(new ByteArrayInputStream(configJson.getBytes(StandardCharsets.UTF_8)), jsonMimeType);
response = Response.ok(content.getInputStream(), content.getMimeTypeValue()).build();
return response;
}
use of ddf.catalog.data.impl.BinaryContentImpl in project ddf by codice.
the class XmlResponseQueueTransformer method transform.
@Override
public BinaryContent transform(SourceResponse response, Map<String, Serializable> args) throws CatalogTransformerException {
try {
PrintWriter writer = printWriterProvider.build(Metacard.class);
writer.setRawValue("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n");
writer.startNode("metacards");
for (Map.Entry<String, String> nsRow : NAMESPACE_MAP.entrySet()) {
writer.addAttribute(nsRow.getKey(), nsRow.getValue());
}
if (response.getResults() != null && !response.getResults().isEmpty()) {
StringWriter metacardContent = fjp.invoke(new MetacardForkTask(ImmutableList.copyOf(response.getResults()), fjp, geometryTransformer, threshold, metacardMarshaller));
writer.setRawValue(metacardContent.getBuffer().toString());
}
// metacards
writer.endNode();
ByteArrayInputStream bais = new ByteArrayInputStream(writer.makeString().getBytes(StandardCharsets.UTF_8));
return new BinaryContentImpl(bais, mimeType);
} catch (Exception e) {
LOGGER.info("Failed Query response transformation", e);
throw new CatalogTransformerException("Failed Query response transformation");
}
}
Aggregations