use of ddf.catalog.data.Metacard 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.Metacard in project ddf by codice.
the class CachedResourceMetacardComparator method allMetacardAttributesEqual.
private static boolean allMetacardAttributesEqual(Metacard cachedMetacard, Metacard updatedMetacard) {
MetacardType cachedMetacardType = cachedMetacard.getMetacardType();
MetacardType updatedMetacardType = updatedMetacard.getMetacardType();
if (!Objects.equals(cachedMetacardType, updatedMetacardType)) {
return false;
}
// attributes need to be compared so we can return true.
if (cachedMetacardType == null) {
return true;
}
Set<AttributeDescriptor> cachedDescriptors = cachedMetacardType.getAttributeDescriptors();
// as well and no attributes need to be compared so we can return true.
if (cachedDescriptors == null) {
return true;
}
Optional<String> difference = cachedDescriptors.stream().map(AttributeDescriptor::getName).filter(attributeName -> !ATTRIBUTES_TO_IGNORE.contains(attributeName)).filter(attributeName -> !Objects.equals(cachedMetacard.getAttribute(attributeName), updatedMetacard.getAttribute(attributeName))).findFirst();
if (LOGGER.isDebugEnabled() && difference.isPresent()) {
String attributeName = difference.get();
LOGGER.debug("Metacard updated. Attribute changed: {}, cached value: {}, updated value: {}", attributeName, cachedMetacard.getAttribute(attributeName), updatedMetacard.getAttribute(attributeName));
}
return !difference.isPresent();
}
use of ddf.catalog.data.Metacard 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;
}
use of ddf.catalog.data.Metacard in project ddf by codice.
the class SolrProviderTest method testSpatialCreateAndUpdateWithClockwiseRectangle.
@Test
public void testSpatialCreateAndUpdateWithClockwiseRectangle() throws Exception {
deleteAllIn(provider);
/** CREATE **/
MockMetacard metacard = new MockMetacard(Library.getFlagstaffRecord());
metacard.setLocation(CLOCKWISE_ARIZONA_RECTANGLE_WKT);
CreateResponse createResponse = create(Arrays.asList((Metacard) metacard));
assertEquals(1, createResponse.getCreatedMetacards().size());
Filter filter = filterBuilder.attribute(Metacard.GEOGRAPHY).intersecting().wkt(FLAGSTAFF_AIRPORT_POINT_WKT);
SourceResponse sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
assertEquals("Failed to find correct record.", 1, sourceResponse.getResults().size());
/** UPDATE **/
MockMetacard updatedMetacard = new MockMetacard(Library.getTampaRecord());
updatedMetacard.setLocation(CLOCKWISE_ARIZONA_RECTANGLE_WKT);
String[] ids = { metacard.getId() };
UpdateResponse updateResponse = update(ids, Arrays.asList((Metacard) updatedMetacard));
assertEquals(1, updateResponse.getUpdatedMetacards().size());
filter = filterBuilder.attribute(Metacard.GEOGRAPHY).intersecting().wkt(FLAGSTAFF_AIRPORT_POINT_WKT);
sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
assertEquals("Failed to find correct record.", 1, sourceResponse.getResults().size());
}
use of ddf.catalog.data.Metacard in project ddf by codice.
the class SolrProviderTest method testGetContentTypesComplicated.
@Test
public void testGetContentTypesComplicated() throws Exception {
deleteAllIn(provider);
List<Metacard> list = new ArrayList<Metacard>();
// Single content type and version
MockMetacard metacard1 = new MockMetacard(Library.getFlagstaffRecord());
metacard1.setContentTypeName(SAMPLE_CONTENT_TYPE_1);
metacard1.setContentTypeVersion(SAMPLE_CONTENT_VERSION_1);
list.add(metacard1);
// one content type with multiple versions
metacard1 = new MockMetacard(Library.getFlagstaffRecord());
metacard1.setContentTypeName(SAMPLE_CONTENT_TYPE_2);
metacard1.setContentTypeVersion(SAMPLE_CONTENT_VERSION_1);
list.add(metacard1);
MockMetacard metacard2 = new MockMetacard(Library.getFlagstaffRecord());
metacard2.setContentTypeName(SAMPLE_CONTENT_TYPE_2);
metacard2.setContentTypeVersion(SAMPLE_CONTENT_VERSION_2);
list.add(metacard2);
// multiple records with different content type but same version
metacard1 = new MockMetacard(Library.getFlagstaffRecord());
metacard1.setContentTypeName(SAMPLE_CONTENT_TYPE_3);
metacard1.setContentTypeVersion(SAMPLE_CONTENT_VERSION_3);
list.add(metacard1);
metacard2 = new MockMetacard(Library.getFlagstaffRecord());
metacard2.setContentTypeName(SAMPLE_CONTENT_TYPE_3);
metacard2.setContentTypeVersion(SAMPLE_CONTENT_VERSION_4);
list.add(metacard2);
// multiple records with different content type and different version
metacard1 = new MockMetacard(Library.getFlagstaffRecord());
metacard1.setContentTypeName(SAMPLE_CONTENT_TYPE_4);
metacard1.setContentTypeVersion(SAMPLE_CONTENT_VERSION_1);
list.add(metacard1);
metacard2 = new MockMetacard(Library.getFlagstaffRecord());
metacard2.setContentTypeName(SAMPLE_CONTENT_TYPE_1);
metacard2.setContentTypeVersion(SAMPLE_CONTENT_VERSION_4);
list.add(metacard2);
metacard1 = new MockMetacard(Library.getFlagstaffRecord());
metacard1.setContentTypeName(SAMPLE_CONTENT_TYPE_4);
metacard1.setContentTypeVersion(SAMPLE_CONTENT_VERSION_1);
list.add(metacard1);
metacard2 = new MockMetacard(Library.getFlagstaffRecord());
metacard2.setContentTypeName(SAMPLE_CONTENT_TYPE_1);
metacard2.setContentTypeVersion(SAMPLE_CONTENT_VERSION_4);
list.add(metacard2);
create(list);
Set<ContentType> contentTypes = provider.getContentTypes();
assertEquals(7, contentTypes.size());
assertThat(contentTypes, hasItem((ContentType) new ContentTypeImpl(SAMPLE_CONTENT_TYPE_1, SAMPLE_CONTENT_VERSION_1)));
assertThat(contentTypes, hasItem((ContentType) new ContentTypeImpl(SAMPLE_CONTENT_TYPE_2, SAMPLE_CONTENT_VERSION_1)));
assertThat(contentTypes, hasItem((ContentType) new ContentTypeImpl(SAMPLE_CONTENT_TYPE_2, SAMPLE_CONTENT_VERSION_2)));
assertThat(contentTypes, hasItem((ContentType) new ContentTypeImpl(SAMPLE_CONTENT_TYPE_3, SAMPLE_CONTENT_VERSION_3)));
assertThat(contentTypes, hasItem((ContentType) new ContentTypeImpl(SAMPLE_CONTENT_TYPE_3, SAMPLE_CONTENT_VERSION_4)));
assertThat(contentTypes, hasItem((ContentType) new ContentTypeImpl(SAMPLE_CONTENT_TYPE_4, SAMPLE_CONTENT_VERSION_1)));
assertThat(contentTypes, hasItem((ContentType) new ContentTypeImpl(SAMPLE_CONTENT_TYPE_1, SAMPLE_CONTENT_VERSION_4)));
}
Aggregations