Search in sources :

Example 21 with Predicate

use of ddf.catalog.pubsub.predicate.Predicate in project ddf by codice.

the class PredicateTest method testContextualQueryTrailingWildcard.

@Test
public void testContextualQueryTrailingWildcard() throws Exception {
    Predicate predicate = getPredicate("test*");
    for (String term : Arrays.asList(TRAILING_TERM, EMBEDDED_TERM)) {
        for (Character specialChar : ContextualTokenizer.SPECIAL_CHARACTERS_SET) {
            String phrase = String.format(term, specialChar);
            String metadata = String.format(METADATA_FORMAT, StringEscapeUtils.escapeXml(phrase));
            Event testEvent = getEvent(metadata);
            assertThat(phrase + " not matched", predicate.matches(testEvent), is(equalTo(true)));
        }
    }
    for (String term : Arrays.asList(LEADING_TERM, EMBEDDED_TERM_REVERSED)) {
        for (Character specialChar : ContextualTokenizer.SPECIAL_CHARACTERS_SET) {
            String phrase = String.format(term, specialChar);
            String metadata = String.format(METADATA_FORMAT, StringEscapeUtils.escapeXml(phrase));
            Event testEvent = getEvent(metadata);
            assertThat(phrase + " matched", predicate.matches(testEvent), is(equalTo(false)));
        }
    }
}
Also used : Event(org.osgi.service.event.Event) GeospatialPredicate(ddf.catalog.pubsub.predicate.GeospatialPredicate) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) Predicate(ddf.catalog.pubsub.predicate.Predicate) Test(org.junit.Test)

Example 22 with Predicate

use of ddf.catalog.pubsub.predicate.Predicate in project ddf by codice.

the class SubscriptionFilterVisitor method visit.

/**
     * Within filter maps to a CONTAINS Spatial search criteria.
     */
@Override
public Object visit(Within filter, Object data) {
    LOGGER.debug("ENTERING: Within filter");
    LOGGER.debug("Must have received CONTAINS query criteria: {}", filter.getExpression2());
    com.vividsolutions.jts.geom.Geometry jtsGeometry = getJtsGeometery((LiteralExpressionImpl) filter.getExpression2());
    Predicate predicate = new GeospatialPredicate(jtsGeometry, SpatialOperator.CONTAINS.name(), 0.0);
    LOGGER.debug("EXITING: Within 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 23 with Predicate

use of ddf.catalog.pubsub.predicate.Predicate in project ddf by codice.

the class SubscriptionFilterVisitor method visit.

/**
     * DWithin filter maps to a Point/Radius distance Spatial search criteria.
     */
@Override
public Object visit(DWithin filter, Object data) {
    LOGGER.debug("ENTERING: DWithin filter");
    LOGGER.debug("Must have received point/radius query criteria.");
    double radius = filter.getDistance();
    com.vividsolutions.jts.geom.Geometry jtsGeometry = getJtsGeometery((LiteralExpressionImpl) filter.getExpression2());
    double radiusInDegrees = (radius * 180.0) / (Math.PI * EQUATORIAL_RADIUS_IN_METERS);
    LOGGER.debug("radius in meters : {}", radius);
    LOGGER.debug("radius in degrees : {}", radiusInDegrees);
    Predicate predicate = new GeospatialPredicate(jtsGeometry, null, radiusInDegrees);
    LOGGER.debug("EXITING: DWithin 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 24 with Predicate

use of ddf.catalog.pubsub.predicate.Predicate in project ddf by codice.

the class SubscriptionFilterVisitor method visit.

@Override
public Object visit(Or filter, Object data) {
    LOGGER.debug("ENTERING: OR filter");
    Predicate returnPredicate = null;
    List<Predicate> predList = new ArrayList<Predicate>();
    List<Filter> childList = filter.getChildren();
    if (childList != null) {
        for (Filter child : childList) {
            if (child == null) {
                continue;
            }
            predList.add((Predicate) child.accept(this, data));
        }
    }
    for (Predicate p : predList) {
        if (returnPredicate == null) {
            returnPredicate = p;
        } else {
            returnPredicate = or(returnPredicate, p);
        }
    }
    LOGGER.debug("EXITING: OR filter");
    return returnPredicate;
}
Also used : IncludeFilter(org.opengis.filter.IncludeFilter) Filter(org.opengis.filter.Filter) ArrayList(java.util.ArrayList) 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 25 with Predicate

use of ddf.catalog.pubsub.predicate.Predicate 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);
}
Also used : SubscriptionFilterVisitor(ddf.catalog.pubsub.internal.SubscriptionFilterVisitor) GeospatialPredicate(ddf.catalog.pubsub.predicate.GeospatialPredicate) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) Predicate(ddf.catalog.pubsub.predicate.Predicate)

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