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());
}
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());
}
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));
}
}
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());
}
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;
}
Aggregations