Search in sources :

Example 71 with MetacardImpl

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

the class SolrProviderTest method testSpatialNearestNeighbor.

@Test
public void testSpatialNearestNeighbor() throws Exception {
    deleteAllIn(provider);
    MetacardImpl metacard1 = new MockMetacard(Library.getFlagstaffRecord());
    MetacardImpl metacard2 = new MockMetacard(Library.getTampaRecord());
    MetacardImpl metacard3 = new MockMetacard(Library.getShowLowRecord());
    // Add in the geometry
    metacard1.setLocation(FLAGSTAFF_AIRPORT_POINT_WKT);
    metacard2.setLocation(TAMPA_AIRPORT_POINT_WKT);
    metacard3.setLocation(SHOW_LOW_AIRPORT_POINT_WKT);
    List<Metacard> list = Arrays.asList((Metacard) metacard1, metacard2, metacard3);
    create(list);
    // Ascending
    Filter positiveFilter = filterBuilder.attribute(Metacard.GEOGRAPHY).beyond().wkt(PHOENIX_POINT_WKT, 0);
    QueryImpl query = new QueryImpl(positiveFilter);
    SourceResponse sourceResponse = provider.query(new QueryRequestImpl(query));
    assertEquals("Failed to find two records within 1000 nautical miles.", 2, sourceResponse.getResults().size());
    assertTrue("Flagstaff record was not first in ascending order.", sourceResponse.getResults().get(0).getMetacard().getMetadata().indexOf(FLAGSTAFF_QUERY_PHRASE) > 0);
    // Descending
    SortBy sortby = new ddf.catalog.filter.impl.SortByImpl(Result.DISTANCE, org.opengis.filter.sort.SortOrder.DESCENDING);
    query.setSortBy(sortby);
    sourceResponse = provider.query(new QueryRequestImpl(query));
    assertEquals("Failed to find two records within 1000 nautical miles.", 2, sourceResponse.getResults().size());
    assertTrue("Flagstaff record was not last in descending order.", sourceResponse.getResults().get(1).getMetacard().getMetadata().indexOf(FLAGSTAFF_QUERY_PHRASE) > 0);
    // Using WKT polygon
    positiveFilter = filterBuilder.attribute(Metacard.GEOGRAPHY).beyond().wkt(ARIZONA_POLYGON_WKT, 0);
    query = new QueryImpl(positiveFilter);
    sourceResponse = provider.query(new QueryRequestImpl(query));
    assertEquals("Failed to find two records based on polygon centroid.", 2, sourceResponse.getResults().size());
}
Also used : Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) SourceResponse(ddf.catalog.operation.SourceResponse) Filter(org.opengis.filter.Filter) SortByImpl(org.geotools.filter.SortByImpl) SortBy(org.opengis.filter.sort.SortBy) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 72 with MetacardImpl

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

the class SolrProviderTest method testSpatialWithWkt.

private void testSpatialWithWkt(String metacardWkt, Filter positiveFilter, Filter negativeFilter) throws Exception {
    deleteAllIn(provider, 4);
    MetacardImpl metacard = new MockMetacard(Library.getFlagstaffRecord());
    metacard.setLocation(metacardWkt);
    List<Metacard> list = Arrays.asList((Metacard) metacard);
    create(list);
    SourceResponse sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(positiveFilter)));
    assertEquals("Failed to find metacard WKT with filter", 1, sourceResponse.getResults().size());
    sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(negativeFilter)));
    assertEquals("Should not have found metacard record.", 0, sourceResponse.getResults().size());
}
Also used : Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) SourceResponse(ddf.catalog.operation.SourceResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl)

Example 73 with MetacardImpl

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

the class SolrProviderTest method testSpatialQueryWithCounterClockwiseRectangle.

@Test
public void testSpatialQueryWithCounterClockwiseRectangle() throws Exception {
    deleteAllIn(provider);
    MetacardImpl metacard = new MockMetacard(Library.getFlagstaffRecord());
    metacard.setLocation(FLAGSTAFF_AIRPORT_POINT_WKT);
    List<Metacard> list = Arrays.asList((Metacard) metacard);
    /** CREATE **/
    create(list);
    /** POSITIVE **/
    Filter filter = filterBuilder.attribute(Metacard.GEOGRAPHY).intersecting().wkt(COUNTERCLOCKWISE_ARIZONA_RECTANGLE_WKT);
    SourceResponse sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
    assertEquals("Failed to find Flagstaff record.", 1, sourceResponse.getResults().size());
    for (Result r : sourceResponse.getResults()) {
        assertTrue("Wrong record, Flagstaff keyword was not found.", ALL_RESULTS != r.getMetacard().getMetadata().indexOf(FLAGSTAFF_QUERY_PHRASE));
    }
}
Also used : Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) SourceResponse(ddf.catalog.operation.SourceResponse) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 74 with MetacardImpl

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

the class SolrProviderTest method testSortedPointRadiusWithComplexQuery.

@Test
public void testSortedPointRadiusWithComplexQuery() throws Exception {
    deleteAllIn(provider);
    MetacardImpl metacard1 = new MockMetacard(Library.getFlagstaffRecord());
    MetacardImpl metacard2 = new MockMetacard(Library.getTampaRecord());
    MetacardImpl metacard3 = new MockMetacard(Library.getShowLowRecord());
    // Add in the geometry
    metacard1.setLocation(FLAGSTAFF_AIRPORT_POINT_WKT);
    metacard2.setLocation(TAMPA_AIRPORT_POINT_WKT);
    metacard3.setLocation(SHOW_LOW_AIRPORT_POINT_WKT);
    // Add in a content type
    metacard1.setAttribute(Metacard.CONTENT_TYPE, "product");
    List<Metacard> list = Arrays.asList((Metacard) metacard1, metacard2, metacard3);
    /** CREATE **/
    create(list);
    // create a filter that has spatial and content type criteria
    Filter contentFilter = filterBuilder.attribute(Metacard.CONTENT_TYPE).is().text("product");
    Filter spatialFilter = filterBuilder.attribute(Metacard.GEOGRAPHY).intersecting().wkt(FLAGSTAFF_AIRPORT_POINT_WKT);
    Filter finalFilter = filterBuilder.allOf(filterBuilder.attribute(Metacard.ANY_TEXT).like().text("flagstaff"), filterBuilder.allOf(contentFilter, spatialFilter));
    // sort by distance
    QueryImpl query = new QueryImpl(finalFilter);
    SortBy sortby = new ddf.catalog.filter.impl.SortByImpl(Result.DISTANCE, org.opengis.filter.sort.SortOrder.DESCENDING);
    query.setSortBy(sortby);
    SourceResponse sourceResponse = provider.query(new QueryRequestImpl(query));
    assertEquals(1, sourceResponse.getResults().size());
}
Also used : Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) SourceResponse(ddf.catalog.operation.SourceResponse) Filter(org.opengis.filter.Filter) SortByImpl(org.geotools.filter.SortByImpl) SortBy(org.opengis.filter.sort.SortBy) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 75 with MetacardImpl

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

the class ResourceCacheImpl method validateCacheEntry.

/**
     * Compares the {@link Metacard} in a {@link ReliableResource} pulled from cache with a Metacard obtained directly
     * from the Catalog to ensure they are the same. Typically used to determine if the cache entry is out-of-date based
     * on the Catalog having an updated Metacard.
     *
     * @param cachedResource
     * @param latestMetacard
     * @return true if the cached ReliableResource still matches the most recent Metacard from the Catalog, false otherwise
     */
protected boolean validateCacheEntry(ReliableResource cachedResource, Metacard latestMetacard) {
    LOGGER.trace("ENTERING: validateCacheEntry");
    if (cachedResource == null || latestMetacard == null) {
        throw new IllegalArgumentException("Neither the cachedResource nor the metacard retrieved from the catalog can be null.");
    }
    Metacard cachedMetacard = cachedResource.getMetacard();
    MetacardImpl latestMetacardImpl = new MetacardImpl(latestMetacard);
    if (isSame(cachedMetacard, latestMetacardImpl)) {
        LOGGER.debug("Metacard has not changed");
        LOGGER.trace("EXITING: validateCacheEntry");
        return true;
    }
    LOGGER.debug("Metacard has changed");
    File cachedFile = new File(cachedResource.getFilePath());
    if (!FileUtils.deleteQuietly(cachedFile)) {
        LOGGER.debug("File was not removed from cache directory.  File Path: {}", cachedResource.getFilePath());
    }
    cache.remove(cachedResource.getKey());
    LOGGER.trace("EXITING: validateCacheEntry");
    return false;
}
Also used : Metacard(ddf.catalog.data.Metacard) File(java.io.File) MetacardImpl(ddf.catalog.data.impl.MetacardImpl)

Aggregations

MetacardImpl (ddf.catalog.data.impl.MetacardImpl)384 Test (org.junit.Test)247 Metacard (ddf.catalog.data.Metacard)144 ArrayList (java.util.ArrayList)102 Result (ddf.catalog.data.Result)62 HashMap (java.util.HashMap)59 Date (java.util.Date)52 ResultImpl (ddf.catalog.data.impl.ResultImpl)51 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)49 URI (java.net.URI)38 Matchers.anyString (org.mockito.Matchers.anyString)38 QueryRequest (ddf.catalog.operation.QueryRequest)36 QueryResponse (ddf.catalog.operation.QueryResponse)35 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)35 Serializable (java.io.Serializable)33 HashSet (java.util.HashSet)31 QueryImpl (ddf.catalog.operation.impl.QueryImpl)29 MetacardTypeImpl (ddf.catalog.data.impl.MetacardTypeImpl)28 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)27 List (java.util.List)27