Search in sources :

Example 26 with Predicate

use of ddf.catalog.pubsub.predicate.Predicate 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);
}
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 27 with Predicate

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

Aggregations

Predicate (ddf.catalog.pubsub.predicate.Predicate)27 ContentTypePredicate (ddf.catalog.pubsub.predicate.ContentTypePredicate)26 GeospatialPredicate (ddf.catalog.pubsub.predicate.GeospatialPredicate)26 Test (org.junit.Test)17 Event (org.osgi.service.event.Event)16 SubscriptionFilterVisitor (ddf.catalog.pubsub.internal.SubscriptionFilterVisitor)13 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)10 HashMap (java.util.HashMap)10 Filter (org.opengis.filter.Filter)9 ContextualPredicate (ddf.catalog.pubsub.predicate.ContextualPredicate)8 EntryPredicate (ddf.catalog.pubsub.predicate.EntryPredicate)8 TemporalPredicate (ddf.catalog.pubsub.predicate.TemporalPredicate)8 Date (java.util.Date)6 FilterTransformer (org.geotools.filter.FilterTransformer)6 ArrayList (java.util.ArrayList)5 DatatypeFactory (javax.xml.datatype.DatatypeFactory)5 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)5 IncludeFilter (org.opengis.filter.IncludeFilter)3 AttributeExpressionImpl (org.geotools.filter.AttributeExpressionImpl)2 LiteralExpressionImpl (org.geotools.filter.LiteralExpressionImpl)2