Search in sources :

Example 11 with MetacardTransformer

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;
}
Also used : MetacardTransformer(ddf.catalog.transform.MetacardTransformer) SourceResponse(ddf.catalog.operation.SourceResponse) ResultImpl(ddf.catalog.data.impl.ResultImpl) Result(ddf.catalog.data.Result)

Example 12 with MetacardTransformer

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);
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) MetacardTransformer(ddf.catalog.transform.MetacardTransformer) SourceResponse(ddf.catalog.operation.SourceResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) ResultImpl(ddf.catalog.data.impl.ResultImpl) BinaryContent(ddf.catalog.data.BinaryContent) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 13 with MetacardTransformer

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);
}
Also used : XmlParser(org.codice.ddf.parser.xml.XmlParser) MetacardTransformer(ddf.catalog.transform.MetacardTransformer) XmlMetacardTransformer(ddf.catalog.transformer.xml.XmlMetacardTransformer) Attribute(ddf.catalog.data.Attribute) MetacardMarshaller(ddf.catalog.transformer.api.MetacardMarshaller) InputStream(java.io.InputStream) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) XmlMetacardTransformer(ddf.catalog.transformer.xml.XmlMetacardTransformer) XmlInputTransformer(ddf.catalog.transformer.xml.XmlInputTransformer) InputTransformer(ddf.catalog.transform.InputTransformer) BinaryContent(ddf.catalog.data.BinaryContent) Parser(org.codice.ddf.parser.Parser) XmlParser(org.codice.ddf.parser.xml.XmlParser) MetacardMarshallerImpl(ddf.catalog.transformer.xml.MetacardMarshallerImpl) Metacard(ddf.catalog.data.Metacard) PrintWriterProviderImpl(ddf.catalog.transformer.xml.PrintWriterProviderImpl) XmlInputTransformer(ddf.catalog.transformer.xml.XmlInputTransformer) Test(org.junit.Test)

Example 14 with MetacardTransformer

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;
}
Also used : MetacardTransformer(ddf.catalog.transform.MetacardTransformer) ArrayList(java.util.ArrayList) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ServiceReference(org.osgi.framework.ServiceReference)

Example 15 with MetacardTransformer

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);
}
Also used : MetacardTransformer(ddf.catalog.transform.MetacardTransformer) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

MetacardTransformer (ddf.catalog.transform.MetacardTransformer)30 BinaryContent (ddf.catalog.data.BinaryContent)26 Test (org.junit.Test)21 SourceResponse (ddf.catalog.operation.SourceResponse)19 Metacard (ddf.catalog.data.Metacard)16 Result (ddf.catalog.data.Result)12 HashMap (java.util.HashMap)12 ResultImpl (ddf.catalog.data.impl.ResultImpl)10 FileOutputStream (java.io.FileOutputStream)9 Map (java.util.Map)9 File (java.io.File)8 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)4 ServiceReference (org.osgi.framework.ServiceReference)4 BinaryContentImpl (ddf.catalog.data.impl.BinaryContentImpl)3 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)3 Serializable (java.io.Serializable)3 Matchers.anyString (org.mockito.Matchers.anyString)3 Action (ddf.action.Action)2 ActionProvider (ddf.action.ActionProvider)2 CatalogFramework (ddf.catalog.CatalogFramework)2