Search in sources :

Example 61 with ResultImpl

use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.

the class TestMetacardResourceSizePlugin method testWhenCachedResourceSizeIsZero.

@Test
public void testWhenCachedResourceSizeIsZero() throws Exception {
    ResourceCacheInterface cache = mock(ResourceCacheInterface.class);
    ReliableResource cachedResource = mock(ReliableResource.class);
    when(cachedResource.getSize()).thenReturn(0L);
    when(cache.getValid(anyString(), (Metacard) anyObject())).thenReturn(cachedResource);
    MetacardImpl metacard = new MetacardImpl();
    metacard.setId("abc123");
    metacard.setSourceId("ddf-1");
    metacard.setResourceSize("N/A");
    Result result = new ResultImpl(metacard);
    List<Result> results = new ArrayList<Result>();
    results.add(result);
    QueryResponse input = mock(QueryResponse.class);
    when(input.getResults()).thenReturn(results);
    MetacardResourceSizePlugin plugin = new MetacardResourceSizePlugin(cache);
    QueryResponse queryResponse = plugin.process(input);
    assertThat(queryResponse.getResults().size(), is(1));
    Metacard resultMetacard = queryResponse.getResults().get(0).getMetacard();
    assertThat(metacard, is(notNullValue()));
    // Since using Metacard vs. MetacardImpl have to get resource-size as an
    // Attribute vs. Long
    Attribute resourceSizeAttr = resultMetacard.getAttribute(Metacard.RESOURCE_SIZE);
    assertThat((String) resourceSizeAttr.getValue(), equalTo("N/A"));
}
Also used : Metacard(ddf.catalog.data.Metacard) Attribute(ddf.catalog.data.Attribute) QueryResponse(ddf.catalog.operation.QueryResponse) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) ResourceCacheInterface(ddf.catalog.cache.ResourceCacheInterface) ReliableResource(ddf.catalog.resource.data.ReliableResource) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 62 with ResultImpl

use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.

the class MetacardResourceStatusTest method setupSingleResultResponseMock.

private void setupSingleResultResponseMock(MetacardImpl metacard) {
    Result result = new ResultImpl(metacard);
    List<Result> results = new ArrayList<>();
    results.add(result);
    when(queryResponse.getResults()).thenReturn(results);
}
Also used : ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) Result(ddf.catalog.data.Result)

Example 63 with ResultImpl

use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.

the class TestMetacardResourceSizePlugin method testMetacardResourceSizePopulatedAndHasProduct.

@Test
public void testMetacardResourceSizePopulatedAndHasProduct() throws Exception {
    ResourceCacheInterface cache = mock(ResourceCacheInterface.class);
    ReliableResource cachedResource = mock(ReliableResource.class);
    when(cachedResource.getSize()).thenReturn(999L);
    when(cachedResource.hasProduct()).thenReturn(true);
    when(cache.getValid(anyString(), (Metacard) anyObject())).thenReturn(cachedResource);
    MetacardImpl metacard = new MetacardImpl();
    metacard.setId("abc123");
    metacard.setSourceId("ddf-1");
    metacard.setResourceSize("N/A");
    Result result = new ResultImpl(metacard);
    List<Result> results = new ArrayList<Result>();
    results.add(result);
    QueryResponse input = mock(QueryResponse.class);
    when(input.getResults()).thenReturn(results);
    MetacardResourceSizePlugin plugin = new MetacardResourceSizePlugin(cache);
    QueryResponse queryResponse = plugin.process(input);
    assertThat(queryResponse.getResults().size(), is(1));
    Metacard resultMetacard = queryResponse.getResults().get(0).getMetacard();
    assertThat(metacard, is(notNullValue()));
    // Since using Metacard vs. MetacardImpl have to get resource-size as an
    // Attribute vs. Long
    Attribute resourceSizeAttr = resultMetacard.getAttribute(Metacard.RESOURCE_SIZE);
    assertThat((String) resourceSizeAttr.getValue(), is("999"));
}
Also used : Metacard(ddf.catalog.data.Metacard) Attribute(ddf.catalog.data.Attribute) QueryResponse(ddf.catalog.operation.QueryResponse) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) ResourceCacheInterface(ddf.catalog.cache.ResourceCacheInterface) ReliableResource(ddf.catalog.resource.data.ReliableResource) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 64 with ResultImpl

use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.

the class CatalogFrameworkImplTest method testGetResourceOptions.

/**
     * Tests that you can get a resource's (product) options. Covers the case where the source ID
     * specified is actually the local catalog provider's site name (so this reduces down to a
     * getResourceOptions for local provider); and the case where a federated source is specified.
     * <p>
     * Test for DDF-1763.
     *
     * @throws Exception
     */
@Test
public void testGetResourceOptions() throws Exception {
    String localProviderName = "ddf";
    String federatedSite1Name = "fed-site-1";
    String metacardId = "123";
    // The resource's URI
    URI metacardUri = new URI("http:///27+Nov+12+12%3A30%3A04?MyPhotograph%0Ahttp%3A%2F%2F172.18.14.53%3A8080%2Fabc%2Fimages%2FActionable.jpg%0AMyAttachment%0Ahttp%3A%2F%2F172.18.14.53%3A8080%2Fabc#abc.xyz.dao.URLResourceOptionDataAccessObject");
    Set<String> supportedOptions = new HashSet<String>();
    supportedOptions.add("MyPhotograph");
    supportedOptions.add("MyAttachment");
    // Catalog Provider
    CatalogProvider provider = mock(CatalogProvider.class);
    when(provider.getId()).thenReturn(localProviderName);
    when(provider.isAvailable(isA(SourceMonitor.class))).thenReturn(true);
    when(provider.isAvailable()).thenReturn(true);
    // Federated Source 1
    FederatedSource federatedSource1 = mock(FederatedSource.class);
    when(federatedSource1.getId()).thenReturn(federatedSite1Name);
    when(federatedSource1.isAvailable(isA(SourceMonitor.class))).thenReturn(true);
    when(federatedSource1.isAvailable()).thenReturn(true);
    when(federatedSource1.getOptions(isA(Metacard.class))).thenReturn(supportedOptions);
    List<FederatedSource> federatedSources = new ArrayList<FederatedSource>();
    federatedSources.add(federatedSource1);
    // Mock register the provider in the container
    // Mock the source poller
    SourcePoller mockPoller = mock(SourcePoller.class);
    when(mockPoller.getCachedSource(isA(Source.class))).thenReturn(null);
    MetacardImpl metacard = new MetacardImpl(BASIC_METACARD);
    metacard.setId(metacardId);
    metacard.setResourceURI(metacardUri);
    Result result = new ResultImpl(metacard);
    List<Result> results = new ArrayList<>();
    results.add(result);
    QueryResponse queryResponse = mock(QueryResponse.class);
    when(queryResponse.getResults()).thenReturn(results);
    FederationStrategy strategy = mock(FederationStrategy.class);
    when(strategy.federate(isA(federatedSources.getClass()), isA(QueryRequest.class))).thenReturn(queryResponse);
    ResourceReader resourceReader = mock(ResourceReader.class);
    Set<String> supportedSchemes = new HashSet<String>();
    supportedSchemes.add("http");
    when(resourceReader.getSupportedSchemes()).thenReturn(supportedSchemes);
    when(resourceReader.getOptions(isA(Metacard.class))).thenReturn(supportedOptions);
    List<ResourceReader> resourceReaders = new ArrayList<ResourceReader>();
    resourceReaders.add(resourceReader);
    FrameworkProperties props = new FrameworkProperties();
    props.setCatalogProviders(Collections.singletonList((CatalogProvider) provider));
    props.setFederatedSources(Collections.singletonMap(federatedSite1Name, federatedSource1));
    props.setResourceReaders(resourceReaders);
    props.setFederationStrategy(strategy);
    props.setQueryResponsePostProcessor(mock(QueryResponsePostProcessor.class));
    props.setSourcePoller(mockPoller);
    props.setFilterBuilder(new GeotoolsFilterBuilder());
    props.setDefaultAttributeValueRegistry(defaultAttributeValueRegistry);
    CatalogFrameworkImpl framework = createFramework(props);
    framework.setId("ddf");
    Set<String> ids = new HashSet<String>();
    for (FederatedSource source : federatedSources) {
        ids.add(source.getId());
    }
    ids.add(framework.getId());
    // site name = local provider
    Map<String, Set<String>> optionsMap = framework.getResourceOptions(metacardId, localProviderName);
    LOGGER.debug("localProvider optionsMap = {}", optionsMap);
    assertThat(optionsMap, hasEntry("RESOURCE_OPTION", supportedOptions));
    // site name = federated site's name
    optionsMap = framework.getResourceOptions(metacardId, federatedSite1Name);
    LOGGER.debug("federatedSource optionsMap = {}", optionsMap);
    assertThat(optionsMap, hasEntry("RESOURCE_OPTION", supportedOptions));
    // site name = null (should default to local provider)
    optionsMap = framework.getResourceOptions(metacardId, null);
    LOGGER.debug("localProvider optionsMap = {}", optionsMap);
    assertThat(optionsMap, hasEntry("RESOURCE_OPTION", supportedOptions));
    // site name = empty string (should default to local provider)
    optionsMap = framework.getResourceOptions(metacardId, "");
    LOGGER.debug("localProvider optionsMap = {}", optionsMap);
    assertThat(optionsMap, hasEntry("RESOURCE_OPTION", supportedOptions));
}
Also used : ResourceReader(ddf.catalog.resource.ResourceReader) Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) Matchers.anyString(org.mockito.Matchers.anyString) URI(java.net.URI) Source(ddf.catalog.source.Source) ByteSource(com.google.common.io.ByteSource) CachedSource(ddf.catalog.util.impl.CachedSource) FederatedSource(ddf.catalog.source.FederatedSource) SourcePoller(ddf.catalog.util.impl.SourcePoller) Result(ddf.catalog.data.Result) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) HashSet(java.util.HashSet) QueryRequest(ddf.catalog.operation.QueryRequest) FederationStrategy(ddf.catalog.federation.FederationStrategy) SourceMonitor(ddf.catalog.source.SourceMonitor) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) FederatedSource(ddf.catalog.source.FederatedSource) Metacard(ddf.catalog.data.Metacard) CatalogProvider(ddf.catalog.source.CatalogProvider) QueryResponse(ddf.catalog.operation.QueryResponse) Test(org.junit.Test)

Example 65 with ResultImpl

use of ddf.catalog.data.impl.ResultImpl 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

ResultImpl (ddf.catalog.data.impl.ResultImpl)91 Result (ddf.catalog.data.Result)59 Test (org.junit.Test)56 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)47 Metacard (ddf.catalog.data.Metacard)46 ArrayList (java.util.ArrayList)35 SourceResponse (ddf.catalog.operation.SourceResponse)30 QueryRequest (ddf.catalog.operation.QueryRequest)28 SourceResponseImpl (ddf.catalog.operation.impl.SourceResponseImpl)20 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)18 QueryResponse (ddf.catalog.operation.QueryResponse)15 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)15 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)12 BinaryContent (ddf.catalog.data.BinaryContent)10 MetacardTransformer (ddf.catalog.transform.MetacardTransformer)10 QueryImpl (ddf.catalog.operation.impl.QueryImpl)9 Query (ddf.catalog.operation.Query)7 PolicyResponse (ddf.catalog.plugin.PolicyResponse)7 File (java.io.File)7 Before (org.junit.Before)7