use of ddf.catalog.pubsub.internal.SubscriptionFilterVisitor in project ddf by codice.
the class PredicateTest method testTemporal.
@Test
public void testTemporal() throws Exception {
String methodName = "testTemporal";
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, PubSubConstants.CREATE);
Map<String, Object> contextualMap = constructContextualMap(metacard);
properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
// Above Pulled from PubSubProviderImpl
properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
Event testEvent = new Event("topic", properties);
boolean b = pred.matches(testEvent);
assertTrue(b);
// input that fails temporal
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_ENTRY_KEY, metacard);
testEvent = new Event("topic", properties);
assertFalse(pred.matches(testEvent));
LOGGER.debug("*************** END: {} *****************", methodName);
}
use of ddf.catalog.pubsub.internal.SubscriptionFilterVisitor in project ddf by codice.
the class PredicateTest method testContentTypeFilter.
@Test
public void testContentTypeFilter() throws Exception {
String methodName = "testContentTypeFilter";
LOGGER.debug("*************** START: {} *****************", methodName);
MetacardImpl metacard = new MetacardImpl();
metacard.setMetadata(TestDataLibrary.getCatAndDogEntry());
String type = "type_1";
String version = "v1";
List<MockTypeVersionsExtension> extensions = new ArrayList<>();
MockTypeVersionsExtension ext1 = new MockTypeVersionsExtension();
List<String> ext1Versions = ext1.getVersions();
ext1Versions.add(version);
ext1.setExtensionTypeName(type);
extensions.add(ext1);
MockQuery query = new MockQuery();
query.addTypeFilter(extensions);
SubscriptionFilterVisitor visitor = new SubscriptionFilterVisitor();
Predicate pred = (Predicate) query.getFilter().accept(visitor, null);
HashMap<String, Object> properties = new HashMap<>();
properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, type + "," + version);
properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
// Below Pulled from PubSubProviderImpl
Map<String, Object> contextualMap = constructContextualMap(metacard);
properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
// Above Pulled from PubSubProviderImpl
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, type + "," + "unmatching_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, "unmatchingtype" + "," + 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, "unmatchingtype" + "," + "unmatchingversion");
testEvent = new Event("topic", properties);
assertFalse(pred.matches(testEvent));
LOGGER.debug("*************** END: {} *****************", methodName);
}
use of ddf.catalog.pubsub.internal.SubscriptionFilterVisitor in project ddf by codice.
the class PredicateTest method testTemporalNullMetadata.
@Test
public void testTemporalNullMetadata() throws Exception {
String methodName = "testTemporalNullMetadata";
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());
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);
// no contextual map containing indexed contextual data
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 testContentTypesWildcard.
@Test
public void testContentTypesWildcard() throws IOException {
String methodName = "testContentTypesWildcard";
LOGGER.debug("*************** START: {} *****************", methodName);
String type1 = "type1*";
String type1Input = "type1";
String version1 = "version1";
String type2 = "type2";
String version2 = "version2*";
String version2Input = "version2abc";
String type3 = "ty*pe3";
String type3Input = "type3";
String version4 = "version4";
MetacardImpl metacard = new MetacardImpl();
metacard.setMetadata(TestDataLibrary.getCatAndDogEntry());
List<MockTypeVersionsExtension> extensions = new ArrayList<>();
MockTypeVersionsExtension ext1 = new MockTypeVersionsExtension();
List<String> ext1Versions = ext1.getVersions();
ext1Versions.add(version1);
ext1.setExtensionTypeName(type1);
extensions.add(ext1);
MockTypeVersionsExtension ext2 = new MockTypeVersionsExtension();
List<String> ext2Versions = ext2.getVersions();
ext2Versions.add(version2);
ext2.setExtensionTypeName(type2);
extensions.add(ext2);
// No version
MockTypeVersionsExtension ext3 = new MockTypeVersionsExtension();
ext3.setExtensionTypeName(type3);
extensions.add(ext3);
// No type, only version(s)
MockTypeVersionsExtension ext4 = new MockTypeVersionsExtension();
List<String> ext4Versions = ext4.getVersions();
ext4Versions.add(version4);
extensions.add(ext4);
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, type1Input + "," + 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 + "," + version2Input);
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, type3Input + "," + "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.internal.SubscriptionFilterVisitor in project ddf by codice.
the class PredicateTest method testSpatial.
@Test
public void testSpatial() throws Exception {
String methodName = "testSpatial";
LOGGER.debug("*************** START: {} *****************", methodName);
MockQuery query = new MockQuery();
// XMLGregorianCalendar start = df.newXMLGregorianCalendarDate( 2011, 10, 25, 0 );
// XMLGregorianCalendar end = df.newXMLGregorianCalendarDate( 2011, 10, 27, 0 );
// query.addTemporalFilter( start, end, Metacard.EFFECTIVE );
String geometryWkt = "POINT(44.5 34.5)";
Double inputRadius = 66672.0;
String linearUnit = Distance.LinearUnit.METER.name();
String spatialType = "POINT_RADIUS";
query.addSpatialFilter(geometryWkt, inputRadius, linearUnit, spatialType);
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);
}
Aggregations