use of ddf.catalog.pubsub.internal.SubscriptionFilterVisitor in project ddf by codice.
the class PredicateTest method testMultipleCriteriaWithContentTypes.
@Test
public void testMultipleCriteriaWithContentTypes() throws Exception {
String methodName = "testMultipleCriteriaWithContentTypes";
LOGGER.debug("*************** START: {} *****************", methodName);
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.EFFECTIVE);
// create content type criteria
String version1 = "version1";
String type1 = "type1";
List<MockTypeVersionsExtension> extensions = new ArrayList<>();
MockTypeVersionsExtension ext1 = new MockTypeVersionsExtension();
List<String> ext1Versions = ext1.getVersions();
ext1Versions.add(version1);
ext1.setExtensionTypeName(type1);
extensions.add(ext1);
query.addTypeFilter(extensions);
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);
// input that passes both temporal and content type
LOGGER.debug("\npass temporal and pass content type.\n");
MetacardImpl metacard = new MetacardImpl();
metacard.setCreatedDate(new Date());
metacard.setExpirationDate(new Date());
metacard.setModifiedDate(new Date());
metacard.setMetadata(TestDataLibrary.getCatAndDogEntry());
XMLGregorianCalendar cal = df.newXMLGregorianCalendarDate(2011, 10, 26, 0);
Date effectiveDate = cal.toGregorianCalendar().getTime();
metacard.setEffectiveDate(effectiveDate);
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);
properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
Event testEvent = new Event("topic", properties);
boolean b = pred.matches(testEvent);
assertTrue(b);
// input that fails both temporal and content type
LOGGER.debug("\nfail temporal. fail content type.\n");
// time out of
XMLGregorianCalendar cal1 = df.newXMLGregorianCalendarDate(2012, 10, 30, 0);
// range
Date effectiveDate1 = cal1.toGregorianCalendar().getTime();
metacard.setEffectiveDate(effectiveDate1);
LOGGER.debug("metacard date: {}", metacard.getEffectiveDate());
properties.clear();
properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, "invalid_type" + "," + version1);
properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
testEvent = new Event("topic", properties);
assertFalse(pred.matches(testEvent));
// input that passes temporal and fails content type
LOGGER.debug("\npass temporal. fail content type\n");
// time in
XMLGregorianCalendar cal2 = df.newXMLGregorianCalendarDate(2011, 10, 26, 0);
// range
Date effectiveDate2 = cal2.toGregorianCalendar().getTime();
metacard.setEffectiveDate(effectiveDate2);
LOGGER.debug("metacard date: {}", metacard.getEffectiveDate());
properties.clear();
properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, "invalid_type" + "," + version1);
properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
testEvent = new Event("topic", properties);
assertFalse(pred.matches(testEvent));
// input that fails temporal and passes content type
LOGGER.debug("\nfail temporal. pass content type\n");
// time out of
XMLGregorianCalendar cal3 = df.newXMLGregorianCalendarDate(2012, 10, 26, 0);
// range
Date effectiveDate3 = cal3.toGregorianCalendar().getTime();
metacard.setEffectiveDate(effectiveDate3);
LOGGER.debug("metacard date: {}", metacard.getEffectiveDate());
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 + "," + version1);
properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
testEvent = new Event("topic", properties);
assertFalse(pred.matches(testEvent));
// multiple content types
LOGGER.debug("\nTesting multiple content types.\n");
String type2 = "type2";
String version2 = "version2";
MockTypeVersionsExtension ext2 = new MockTypeVersionsExtension();
List<String> ext2Versions = ext2.getVersions();
ext2Versions.add(version2);
ext2.setExtensionTypeName(type2);
extensions.add(ext2);
// No version
String type3 = "type3";
MockTypeVersionsExtension ext3 = new MockTypeVersionsExtension();
ext3.setExtensionTypeName(type3);
extensions.add(ext3);
MockQuery query2 = new MockQuery();
query2.addTemporalFilter(start, end, Metacard.EFFECTIVE);
query2.addTypeFilter(extensions);
SubscriptionFilterVisitor visitor1 = new SubscriptionFilterVisitor();
Predicate pred1 = (Predicate) query2.getFilter().accept(visitor1, null);
LOGGER.debug("resulting predicate: " + pred1);
// Create metacard for input
// time and contentType match
// time in
XMLGregorianCalendar cal4 = df.newXMLGregorianCalendarDate(2011, 10, 26, 0);
// range
Date effectiveDate4 = cal4.toGregorianCalendar().getTime();
metacard.setEffectiveDate(effectiveDate4);
LOGGER.debug("metacard date: {}", metacard.getEffectiveDate());
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 + "," + version1);
properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
testEvent = new Event("topic", properties);
assertTrue(pred1.matches(testEvent));
// time and contentType match against content type 3 with any version
// time in
XMLGregorianCalendar cal5 = df.newXMLGregorianCalendarDate(2011, 10, 26, 0);
// range
Date effectiveDate5 = cal5.toGregorianCalendar().getTime();
metacard.setEffectiveDate(effectiveDate5);
LOGGER.debug("metacard date: {}", metacard.getEffectiveDate());
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");
properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
testEvent = new Event("topic", properties);
assertTrue(pred1.matches(testEvent));
// time matches and contentType matches type2
// time in
XMLGregorianCalendar cal6 = df.newXMLGregorianCalendarDate(2011, 10, 26, 0);
// range
Date effectiveDate6 = cal6.toGregorianCalendar().getTime();
metacard.setEffectiveDate(effectiveDate6);
LOGGER.debug("metacard date: {}", metacard.getEffectiveDate());
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);
properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
testEvent = new Event("topic", properties);
assertTrue(pred1.matches(testEvent));
// time matches and content type doesn't match
// time in
XMLGregorianCalendar cal7 = df.newXMLGregorianCalendarDate(2011, 10, 26, 0);
// range
Date effectiveDate7 = cal7.toGregorianCalendar().getTime();
metacard.setEffectiveDate(effectiveDate7);
LOGGER.debug("metacard date: {}", metacard.getEffectiveDate());
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);
properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
testEvent = new Event("topic", properties);
assertFalse(pred1.matches(testEvent));
LOGGER.debug("*************** END: {} *****************", methodName);
}
use of ddf.catalog.pubsub.internal.SubscriptionFilterVisitor in project ddf by codice.
the class PredicateTest method getPredicate.
private Predicate getPredicate(String searchPhrase, String textPathSections, boolean caseSensitive) {
MockQuery query = new MockQuery();
query.addContextualFilter(searchPhrase, textPathSections, caseSensitive);
SubscriptionFilterVisitor visitor = new SubscriptionFilterVisitor();
return (Predicate) query.getFilter().accept(visitor, null);
}
use of ddf.catalog.pubsub.internal.SubscriptionFilterVisitor in project ddf by codice.
the class PredicateTest method testTemporalNullOperation.
@Test
public void testTemporalNullOperation() throws Exception {
String methodName = "testTemporalNullOperation";
LOGGER.debug("*************** START: {} *****************", methodName);
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.EFFECTIVE);
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);
// input that passes temporal
LOGGER.debug("\npass temporal.\n");
MetacardImpl metacard = new MetacardImpl();
metacard.setCreatedDate(new Date());
metacard.setExpirationDate(new Date());
metacard.setModifiedDate(new Date());
metacard.setMetadata(TestDataLibrary.getCatAndDogEntry());
XMLGregorianCalendar cal = df.newXMLGregorianCalendarDate(2011, 10, 26, 0);
Date effectiveDate = cal.toGregorianCalendar().getTime();
metacard.setEffectiveDate(effectiveDate);
HashMap<String, Object> properties = new HashMap<>();
properties.put(PubSubConstants.HEADER_OPERATION_KEY, null);
Map<String, Object> contextualMap = constructContextualMap(metacard);
properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
Event testEvent = new Event("topic", properties);
boolean b = pred.matches(testEvent);
assertTrue(b);
LOGGER.debug("*************** END: {} *****************", methodName);
}
use of ddf.catalog.pubsub.internal.SubscriptionFilterVisitor in project ddf by codice.
the class PredicateTest method testContextualQueryNullMetadata.
@Test
public void testContextualQueryNullMetadata() throws Exception {
String methodName = "testContextualQueryNullMetadata";
LOGGER.debug("*************** START: {} *****************", methodName);
String searchPhrase = "serengeti event";
MockQuery query = new MockQuery();
query.addContextualFilter(searchPhrase, null);
SubscriptionFilterVisitor visitor = new SubscriptionFilterVisitor();
Predicate predicate = (Predicate) query.getFilter().accept(visitor, null);
MetacardImpl metacard = new MetacardImpl();
metacard.setId("ABC123");
metacard.setMetadata(TestDataLibrary.getCatAndDogEntry());
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);
// No contextual map containing indexed metadata added to properties
Event testEvent = new Event("topic", properties);
assertFalse(predicate.matches(testEvent));
LOGGER.debug("*************** END: {} *****************", methodName);
}
Aggregations