use of ddf.catalog.pubsub.predicate.Predicate in project ddf by codice.
the class SubscriptionFilterVisitor method visit.
@Override
public Object visit(Not filter, Object data) {
LOGGER.debug("ENTERING: NOT filter");
Predicate returnPredicate = null;
Filter filterToNot = filter.getFilter();
Predicate predicateToNot = (Predicate) filterToNot.accept(this, null);
returnPredicate = not(predicateToNot);
LOGGER.debug("EXITING: NOT filter");
return returnPredicate;
}
use of ddf.catalog.pubsub.predicate.Predicate in project ddf by codice.
the class SubscriptionFilterVisitor method visit.
/**
* PropertyIsEqualTo filter maps to a Type/Version(s) and Entry search criteria.
*/
@Override
public Object visit(PropertyIsEqualTo filter, Object data) {
LOGGER.debug("ENTERING: PropertyIsEqualTo filter");
// TODO: consider if the contentType parameters are invalid (i.e. anything where type is
// null)
AttributeExpressionImpl exp1 = (AttributeExpressionImpl) filter.getExpression1();
String propertyName = exp1.getPropertyName();
LiteralExpressionImpl exp2 = (LiteralExpressionImpl) filter.getExpression2();
Predicate predicate = null;
if (Metacard.ID.equals(propertyName)) {
String entryId = (String) exp2.getValue();
LOGGER.debug("entry id for new entry predicate: {}", entryId);
predicate = new EntryPredicate(entryId);
} else if (Metacard.CONTENT_TYPE.equals(propertyName)) {
String typeValue = (String) exp2.getValue();
predicate = new ContentTypePredicate(typeValue, null);
} else if (Metacard.CONTENT_TYPE_VERSION.equals(propertyName)) {
String versionValue = (String) exp2.getValue();
predicate = new ContentTypePredicate(null, versionValue);
} else if (Metacard.RESOURCE_URI.equals(propertyName)) {
URI productUri = null;
if (exp2.getValue() instanceof URI) {
productUri = (URI) exp2.getValue();
predicate = new EntryPredicate(productUri);
} else {
try {
productUri = new URI((String) exp2.getValue());
predicate = new EntryPredicate(productUri);
} catch (URISyntaxException e) {
LOGGER.debug("URI Syntax exception creating EntryPredicate", e);
throw new UnsupportedOperationException("Could not create a URI object from the given ResourceURI.", e);
}
}
}
LOGGER.debug("EXITING: PropertyIsEqualTo filter");
return predicate;
}
use of ddf.catalog.pubsub.predicate.Predicate in project ddf by codice.
the class SubscriptionFilterVisitor method visit.
/**
* Intersects filter maps to a OVERLAPS Spatial search criteria.
*/
@Override
public Object visit(Intersects filter, Object data) {
LOGGER.debug("ENTERING: Intersects filter");
LOGGER.debug("Must have received OVERLAPS query criteria.");
com.vividsolutions.jts.geom.Geometry jtsGeometry = getJtsGeometery((LiteralExpressionImpl) filter.getExpression2());
Predicate predicate = new GeospatialPredicate(jtsGeometry, SpatialOperator.OVERLAPS.name(), 0.0);
LOGGER.debug("EXITING: Intersects filter");
return predicate;
}
use of ddf.catalog.pubsub.predicate.Predicate in project ddf by codice.
the class PredicateTest method testMultipleContentTypes.
@Test
public void testMultipleContentTypes() throws IOException {
String methodName = "testMultipleContentTypes";
LOGGER.debug("*************** START: {} *****************", methodName);
String type1 = "type1";
String version1 = "version1";
String type2 = "type2";
String version2 = "version2";
String type3 = "type3";
String version4 = "version4";
MetacardImpl metacard = new MetacardImpl();
metacard.setMetadata(TestDataLibrary.getCatAndDogEntry());
List<MockTypeVersionsExtension> extensions = createContentTypeVersionList("type1,version1|type2,version2|type3,|,version4");
MockQuery query = new MockQuery();
query.addTypeFilter(extensions);
SubscriptionFilterVisitor visitor = new SubscriptionFilterVisitor();
Predicate pred = (Predicate) query.getFilter().accept(visitor, null);
LOGGER.debug("Resulting Predicate: {}", pred);
HashMap<String, Object> properties = new HashMap<>();
properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
Map<String, Object> contextualMap = constructContextualMap(metacard);
properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
// Above Pulled from PubSubProviderImpl
properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, type1 + "," + version1);
Event testEvent = new Event("topic", properties);
assertTrue(pred.matches(testEvent));
properties.clear();
properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, type2 + "," + version2);
testEvent = new Event("topic", properties);
assertTrue(pred.matches(testEvent));
properties.clear();
properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, type2 + "," + version1);
testEvent = new Event("topic", properties);
assertFalse(pred.matches(testEvent));
properties.clear();
properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, type1 + "," + version2);
testEvent = new Event("topic", properties);
assertFalse(pred.matches(testEvent));
properties.clear();
properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, type3 + "," + "random_version");
testEvent = new Event("topic", properties);
assertTrue(pred.matches(testEvent));
properties.clear();
properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, "random_type" + "," + "random_version");
testEvent = new Event("topic", properties);
assertFalse(pred.matches(testEvent));
properties.clear();
properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, "random_type" + "," + version4);
testEvent = new Event("topic", properties);
assertFalse(pred.matches(testEvent));
LOGGER.debug("*************** END: {} *****************", methodName);
}
use of ddf.catalog.pubsub.predicate.Predicate in project ddf by codice.
the class PredicateTest method testMultipleCriteria.
@Test
public void testMultipleCriteria() throws Exception {
String methodName = "testMultipleCriteria";
LOGGER.debug("*************** START: {} *****************", methodName);
// test with temporal, spatial, and entry
MockQuery query = new MockQuery();
DatatypeFactory df = DatatypeFactory.newInstance();
XMLGregorianCalendar start = df.newXMLGregorianCalendarDate(2011, 10, 25, 0);
XMLGregorianCalendar end = df.newXMLGregorianCalendarDate(2011, 10, 27, 0);
query.addTemporalFilter(start, end, Metacard.MODIFIED);
String wkt = "POLYGON((0 10, 0 0, 10 0, 10 10, 0 10))";
query.addSpatialFilter(wkt, 0.0, "Meter", "CONTAINS");
// create entry criteria
String catalogId = "ABC123";
query.addEntryFilter(catalogId);
MetacardImpl metacard = new MetacardImpl();
metacard.setLocation("POINT(5 5)");
metacard.setId(catalogId);
metacard.setCreatedDate(new Date());
metacard.setExpirationDate(new Date());
metacard.setEffectiveDate(new Date());
metacard.setMetadata(TestDataLibrary.getCatAndDogEntry());
XMLGregorianCalendar cal = df.newXMLGregorianCalendarDate(2011, 10, 26, 0);
Date modifiedDate = cal.toGregorianCalendar().getTime();
metacard.setModifiedDate(modifiedDate);
HashMap<String, Object> properties = new HashMap<>();
properties.put(PubSubConstants.HEADER_ID_KEY, metacard.getId());
properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
Map<String, Object> contextualMap = constructContextualMap(metacard);
properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
// Above Pulled from PubSubProviderImpl
Event testEvent = new Event("topic", properties);
// input passes temporal, id, and geo
SubscriptionFilterVisitor visitor = new SubscriptionFilterVisitor();
Predicate pred = (Predicate) query.getFilter().accept(visitor, null);
LOGGER.debug("Resulting Predicate: {}", pred);
Filter filter = query.getFilter();
FilterTransformer transform = new FilterTransformer();
transform.setIndentation(2);
String filterXml = transform.transform(filter);
LOGGER.debug(filterXml);
assertTrue(pred.matches(testEvent));
// input passes temporal, id, but fails geo
// geo out of range
metacard.setLocation("POINT(5 50)");
properties.clear();
properties.put(PubSubConstants.HEADER_ID_KEY, metacard.getId());
properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
// Below Pulled from PubSubProviderImpl
contextualMap = constructContextualMap(metacard);
properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
// Above Pulled from PubSubProviderImpl
testEvent = new Event("topic", properties);
assertFalse(pred.matches(testEvent));
// input passes geo, and id, but fails temporal
metacard.setLocation("POINT(5 5)");
XMLGregorianCalendar cal1 = df.newXMLGregorianCalendarDate(2011, 10, 28, 0);
Date modifiedDate1 = cal1.toGregorianCalendar().getTime();
// date out of range
metacard.setModifiedDate(modifiedDate1);
properties.clear();
properties.put(PubSubConstants.HEADER_ID_KEY, metacard.getId());
properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
// Below Pulled from PubSubProviderImpl
contextualMap = constructContextualMap(metacard);
properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
// Above Pulled from PubSubProviderImpl
testEvent = new Event("topic", properties);
assertFalse(pred.matches(testEvent));
// input passes temporal, geo, but fails id
XMLGregorianCalendar cal2 = df.newXMLGregorianCalendarDate(2011, 10, 26, 0);
Date modifiedDate2 = cal2.toGregorianCalendar().getTime();
metacard.setModifiedDate(modifiedDate2);
// bad id
metacard.setId("invalid_id");
properties.clear();
properties.put(PubSubConstants.HEADER_ID_KEY, metacard.getId());
properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
// Below Pulled from PubSubProviderImpl
contextualMap = constructContextualMap(metacard);
properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
// Above Pulled from PubSubProviderImpl
testEvent = new Event("topic", properties);
assertFalse(pred.matches(testEvent));
LOGGER.debug("*************** END: {} *****************", methodName);
}
Aggregations