use of ddf.catalog.transform.MetacardTransformer in project ddf by codice.
the class TestAtomTransformer method basicSetup.
protected SourceResponse basicSetup(AtomTransformer transformer) throws IOException, CatalogTransformerException {
MetacardTransformer metacardTransformer = getXmlMetacardTransformerStub();
transformer.setMetacardTransformer(metacardTransformer);
setDefaultSystemConfiguration();
SourceResponse response = mock(SourceResponse.class);
when(response.getRequest()).thenReturn(getStubRequest());
ResultImpl result = new ResultImpl();
MetacardStub metacard = new MetacardStub("");
metacard.setId(SAMPLE_ID);
metacard.setSourceId(SAMPLE_SOURCE_ID);
result.setMetacard(metacard);
when(response.getResults()).thenReturn(Arrays.asList((Result) result));
return response;
}
use of ddf.catalog.transform.MetacardTransformer in project ddf by codice.
the class TestAtomTransformer method testTotalResultsNegative.
@Test
public void testTotalResultsNegative() throws IOException, CatalogTransformerException, XpathException, SAXException {
// given
AtomTransformer transformer = new AtomTransformer();
MetacardTransformer metacardTransformer = getXmlMetacardTransformerStub();
transformer.setMetacardTransformer(metacardTransformer);
setDefaultSystemConfiguration();
SourceResponse response = mock(SourceResponse.class);
when(response.getHits()).thenReturn(new Long(-1));
QueryImpl query = new QueryImpl(FILTER_BUILDER.attribute(Metacard.METADATA).text("you"));
query.setPageSize(1);
query.setStartIndex(2);
query.setRequestsTotalResultsCount(true);
QueryRequestImpl queryRequestImpl = new QueryRequestImpl(query);
when(response.getRequest()).thenReturn(queryRequestImpl);
ResultImpl result1 = new ResultImpl();
MetacardStub metacard = new MetacardStub("");
metacard.setId(SAMPLE_ID);
result1.setMetacard(metacard);
when(response.getResults()).thenReturn(Arrays.asList((Result) result1));
// when
BinaryContent binaryContent = transformer.transform(response, null);
// then
assertThat(binaryContent.getMimeType(), is(AtomTransformer.MIME_TYPE));
byte[] bytes = binaryContent.getByteArray();
String output = new String(bytes);
assertFeedCompliant(output);
assertEntryCompliant(output);
validateAgainstAtomSchema(bytes);
assertXpathNotExists("/atom:feed/os:totalResults", output);
}
use of ddf.catalog.transform.MetacardTransformer in project ddf by codice.
the class IntegrationTest method testInputAndOutput.
@Test
public void testInputAndOutput() throws CatalogTransformerException, IOException {
Parser parser = new XmlParser();
InputTransformer inputTransformer = new XmlInputTransformer(parser);
MetacardMarshaller metacardMarshaller = new MetacardMarshallerImpl(parser, new PrintWriterProviderImpl());
MetacardTransformer outputTransformer = new XmlMetacardTransformer(metacardMarshaller);
InputStream input = getClass().getResourceAsStream("/extensibleMetacard.xml");
Metacard metacard = inputTransformer.transform(input);
LOGGER.info("Attributes: ");
for (AttributeDescriptor descriptor : metacard.getMetacardType().getAttributeDescriptors()) {
Attribute attribute = metacard.getAttribute(descriptor.getName());
LOGGER.info("\t" + descriptor.getName() + ": " + ((attribute == null) ? attribute : attribute.getValue()));
}
BinaryContent output = outputTransformer.transform(metacard, mockArguments);
String outputString = new String(output.getByteArray());
// TODO test equivalence with XMLUnit.
LOGGER.info(outputString);
}
use of ddf.catalog.transform.MetacardTransformer in project ddf by codice.
the class DumpCommand method getTransformers.
private List<MetacardTransformer> getTransformers() {
ServiceReference[] refs = null;
try {
refs = bundleContext.getAllServiceReferences(MetacardTransformer.class.getName(), "(|" + "(" + Constants.SERVICE_ID + "=" + transformerId + ")" + ")");
} catch (InvalidSyntaxException e) {
console.printf("Fail to get MetacardTransformer references due to %s", e.getMessage());
}
if (refs == null || refs.length == 0) {
return null;
}
List<MetacardTransformer> metacardTransformerList = new ArrayList<>();
for (ServiceReference ref : refs) {
metacardTransformerList.add((MetacardTransformer) bundleContext.getService(ref));
}
return metacardTransformerList;
}
use of ddf.catalog.transform.MetacardTransformer in project ddf by codice.
the class TransformOperations method transform.
//
// Delegate methods
//
public BinaryContent transform(Metacard metacard, String transformerId, Map<String, Serializable> requestProperties) throws CatalogTransformerException {
if (metacard == null) {
throw new IllegalArgumentException("Metacard is null.");
}
ServiceReference[] refs;
try {
// TODO replace shortname with id
refs = frameworkProperties.getBundleContext().getServiceReferences(MetacardTransformer.class.getName(), "(|" + "(" + Constants.SERVICE_SHORTNAME + "=" + transformerId + ")" + "(" + Constants.SERVICE_ID + "=" + transformerId + ")" + ")");
} catch (InvalidSyntaxException e) {
throw new IllegalArgumentException("Invalid transformer shortName: " + transformerId, e);
}
if (refs == null || refs.length == 0) {
throw new IllegalArgumentException("Transformer " + transformerId + " not found");
}
MetacardTransformer transformer = (MetacardTransformer) frameworkProperties.getBundleContext().getService(refs[0]);
return transformer.transform(metacard, requestProperties);
}
Aggregations