Search in sources :

Example 6 with SubscriptionFilterVisitor

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);
}
Also used : DatatypeFactory(javax.xml.datatype.DatatypeFactory) SubscriptionFilterVisitor(ddf.catalog.pubsub.internal.SubscriptionFilterVisitor) HashMap(java.util.HashMap) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Date(java.util.Date) GeospatialPredicate(ddf.catalog.pubsub.predicate.GeospatialPredicate) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) Predicate(ddf.catalog.pubsub.predicate.Predicate) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Filter(org.opengis.filter.Filter) Event(org.osgi.service.event.Event) FilterTransformer(org.geotools.filter.FilterTransformer) Test(org.junit.Test)

Example 7 with SubscriptionFilterVisitor

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);
}
Also used : SubscriptionFilterVisitor(ddf.catalog.pubsub.internal.SubscriptionFilterVisitor) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) GeospatialPredicate(ddf.catalog.pubsub.predicate.GeospatialPredicate) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) Predicate(ddf.catalog.pubsub.predicate.Predicate) Event(org.osgi.service.event.Event) Test(org.junit.Test)

Example 8 with SubscriptionFilterVisitor

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);
}
Also used : DatatypeFactory(javax.xml.datatype.DatatypeFactory) SubscriptionFilterVisitor(ddf.catalog.pubsub.internal.SubscriptionFilterVisitor) HashMap(java.util.HashMap) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Date(java.util.Date) GeospatialPredicate(ddf.catalog.pubsub.predicate.GeospatialPredicate) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) Predicate(ddf.catalog.pubsub.predicate.Predicate) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Filter(org.opengis.filter.Filter) Event(org.osgi.service.event.Event) FilterTransformer(org.geotools.filter.FilterTransformer) Test(org.junit.Test)

Example 9 with SubscriptionFilterVisitor

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);
}
Also used : SubscriptionFilterVisitor(ddf.catalog.pubsub.internal.SubscriptionFilterVisitor) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) GeospatialPredicate(ddf.catalog.pubsub.predicate.GeospatialPredicate) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) Predicate(ddf.catalog.pubsub.predicate.Predicate) Event(org.osgi.service.event.Event) Test(org.junit.Test)

Example 10 with SubscriptionFilterVisitor

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);
}
Also used : SubscriptionFilterVisitor(ddf.catalog.pubsub.internal.SubscriptionFilterVisitor) Filter(org.opengis.filter.Filter) FilterTransformer(org.geotools.filter.FilterTransformer) GeospatialPredicate(ddf.catalog.pubsub.predicate.GeospatialPredicate) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) Predicate(ddf.catalog.pubsub.predicate.Predicate) Test(org.junit.Test)

Aggregations

SubscriptionFilterVisitor (ddf.catalog.pubsub.internal.SubscriptionFilterVisitor)14 ContentTypePredicate (ddf.catalog.pubsub.predicate.ContentTypePredicate)13 Predicate (ddf.catalog.pubsub.predicate.Predicate)13 GeospatialPredicate (ddf.catalog.pubsub.predicate.GeospatialPredicate)12 Test (org.junit.Test)12 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)11 HashMap (java.util.HashMap)11 Event (org.osgi.service.event.Event)11 FilterTransformer (org.geotools.filter.FilterTransformer)6 Filter (org.opengis.filter.Filter)6 Date (java.util.Date)5 DatatypeFactory (javax.xml.datatype.DatatypeFactory)5 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)5 ArrayList (java.util.ArrayList)4 InvalidSubscriptionException (ddf.catalog.event.InvalidSubscriptionException)1 SubscriptionExistsException (ddf.catalog.event.SubscriptionExistsException)1 SubscriptionNotFoundException (ddf.catalog.event.SubscriptionNotFoundException)1 PluginExecutionException (ddf.catalog.plugin.PluginExecutionException)1 PreSubscriptionPlugin (ddf.catalog.plugin.PreSubscriptionPlugin)1 Hashtable (java.util.Hashtable)1