Search in sources :

Example 6 with Predicate

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;
}
Also used : IncludeFilter(org.opengis.filter.IncludeFilter) Filter(org.opengis.filter.Filter) GeospatialPredicate(ddf.catalog.pubsub.predicate.GeospatialPredicate) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) EntryPredicate(ddf.catalog.pubsub.predicate.EntryPredicate) TemporalPredicate(ddf.catalog.pubsub.predicate.TemporalPredicate) ContextualPredicate(ddf.catalog.pubsub.predicate.ContextualPredicate) Predicate(ddf.catalog.pubsub.predicate.Predicate)

Example 7 with Predicate

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;
}
Also used : AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) URISyntaxException(java.net.URISyntaxException) EntryPredicate(ddf.catalog.pubsub.predicate.EntryPredicate) URI(java.net.URI) GeospatialPredicate(ddf.catalog.pubsub.predicate.GeospatialPredicate) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) EntryPredicate(ddf.catalog.pubsub.predicate.EntryPredicate) TemporalPredicate(ddf.catalog.pubsub.predicate.TemporalPredicate) ContextualPredicate(ddf.catalog.pubsub.predicate.ContextualPredicate) Predicate(ddf.catalog.pubsub.predicate.Predicate)

Example 8 with 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;
}
Also used : GeospatialPredicate(ddf.catalog.pubsub.predicate.GeospatialPredicate) GeospatialPredicate(ddf.catalog.pubsub.predicate.GeospatialPredicate) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) EntryPredicate(ddf.catalog.pubsub.predicate.EntryPredicate) TemporalPredicate(ddf.catalog.pubsub.predicate.TemporalPredicate) ContextualPredicate(ddf.catalog.pubsub.predicate.ContextualPredicate) Predicate(ddf.catalog.pubsub.predicate.Predicate)

Example 9 with 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);
}
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)

Example 10 with Predicate

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);
}
Also used : DatatypeFactory(javax.xml.datatype.DatatypeFactory) HashMap(java.util.HashMap) SubscriptionFilterVisitor(ddf.catalog.pubsub.internal.SubscriptionFilterVisitor) 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)

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