Search in sources :

Example 1 with MetadataTransformer

use of org.codice.ddf.spatial.ogc.catalog.MetadataTransformer in project ddf by codice.

the class TestCswSourceBase method setUp.

@Before
public void setUp() {
    ServiceReference ref = mock(ServiceReference.class);
    ServiceReference[] serviceRefs = new ServiceReference[] { ref };
    try {
        when(mockContext.getServiceReferences(eq(MetadataTransformer.class.getName()), anyString())).thenReturn(serviceRefs);
    } catch (InvalidSyntaxException e) {
        LOGGER.error(e.getMessage(), e);
    }
    MetadataTransformer transformer = mock(MetadataTransformer.class);
    // Just return same Metacard that was passed in
    when(mockContext.getService(any(ServiceReference.class))).thenReturn(transformer);
    try {
        when(transformer.transform(any(Metacard.class))).thenAnswer(invocation -> invocation.getArguments()[0]);
    } catch (CatalogTransformerException e) {
        LOGGER.error(e.getMessage(), e);
    }
    when(mockAvailabilityTask.isAvailable()).thenReturn(true);
}
Also used : Metacard(ddf.catalog.data.Metacard) MetadataTransformer(org.codice.ddf.spatial.ogc.catalog.MetadataTransformer) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) ServiceReference(org.osgi.framework.ServiceReference) Before(org.junit.Before)

Example 2 with MetadataTransformer

use of org.codice.ddf.spatial.ogc.catalog.MetadataTransformer in project ddf by codice.

the class AbstractCswSource method createResults.

protected List<Result> createResults(CswRecordCollection cswRecordCollection) {
    List<Result> results = new ArrayList<>();
    LOGGER.debug("Found {} metacard(s) in the CswRecordCollection.", cswRecordCollection.getCswRecords().size());
    String transformerId = getMetadataTransformerId();
    MetadataTransformer transformer = lookupMetadataTransformer(transformerId);
    for (Metacard metacard : cswRecordCollection.getCswRecords()) {
        MetacardImpl wrappedMetacard = new MetacardImpl(metacard);
        wrappedMetacard.setSourceId(getId());
        if (wrappedMetacard.getAttribute(Core.RESOURCE_DOWNLOAD_URL) != null && wrappedMetacard.getAttribute(Core.RESOURCE_DOWNLOAD_URL).getValue() != null) {
            wrappedMetacard.setAttribute(Core.RESOURCE_URI, wrappedMetacard.getAttribute(Core.RESOURCE_DOWNLOAD_URL).getValue());
        }
        if (wrappedMetacard.getAttribute(Core.DERIVED_RESOURCE_DOWNLOAD_URL) != null && !wrappedMetacard.getAttribute(Core.DERIVED_RESOURCE_DOWNLOAD_URL).getValues().isEmpty()) {
            wrappedMetacard.setAttribute(new AttributeImpl(Core.DERIVED_RESOURCE_URI, wrappedMetacard.getAttribute(Core.DERIVED_RESOURCE_DOWNLOAD_URL).getValues()));
        }
        Metacard tranformedMetacard = wrappedMetacard;
        if (transformer != null) {
            tranformedMetacard = transform(metacard, transformer);
        }
        Result result = new ResultImpl(tranformedMetacard);
        results.add(result);
    }
    return results;
}
Also used : Metacard(ddf.catalog.data.Metacard) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) MetadataTransformer(org.codice.ddf.spatial.ogc.catalog.MetadataTransformer) ResultImpl(ddf.catalog.data.impl.ResultImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result)

Aggregations

Metacard (ddf.catalog.data.Metacard)2 MetadataTransformer (org.codice.ddf.spatial.ogc.catalog.MetadataTransformer)2 Result (ddf.catalog.data.Result)1 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)1 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)1 ResultImpl (ddf.catalog.data.impl.ResultImpl)1 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1 ServiceReference (org.osgi.framework.ServiceReference)1