Search in sources :

Example 1 with ContentTypePredicate

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

the class SubscriptionFilterVisitor method visit.

@Override
public Object visit(And filter, Object data) {
    LOGGER.debug("ENTERING: AND 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));
        }
    }
    ContentTypePredicate currentContentTypePred = null;
    LOGGER.debug("predicate list size: {}", predList.size());
    for (Predicate p : predList) {
        if (p == null) {
            // filterless subscription
            LOGGER.debug("Found null predicate.  Indicates Filterless Subscription.");
        } else if (p instanceof ContentTypePredicate) {
            LOGGER.debug("Found ContentType Predicate.");
            if (currentContentTypePred == null) {
                currentContentTypePred = (ContentTypePredicate) p;
            } else {
                ContentTypePredicate incomingContentTypePred = (ContentTypePredicate) p;
                String currentType = currentContentTypePred.getType();
                String currentVersion = currentContentTypePred.getVersion();
                String incomingType = incomingContentTypePred.getType();
                String incomingVersion = incomingContentTypePred.getVersion();
                // Combine the two.
                if (currentType != null && incomingType == null && incomingVersion != null) {
                    currentContentTypePred.setVersion(incomingVersion);
                // Case 2
                // First ContentTypePredicate has no type but has a version. Second
                // ContentTypePredicate has no version, but it has a type.
                } else if (currentType == null && currentVersion != null && incomingType != null) {
                    currentContentTypePred.setType(incomingType);
                }
            }
            if (returnPredicate == null) {
                LOGGER.debug("first return predicate");
                returnPredicate = currentContentTypePred;
            } else {
                LOGGER.debug("ANDing the predicates. Pred1: {} Pred2: {}", returnPredicate, currentContentTypePred);
                returnPredicate = and(returnPredicate, currentContentTypePred);
            }
        } else {
            if (returnPredicate == null) {
                LOGGER.debug("first return predicate");
                returnPredicate = p;
            } else {
                LOGGER.debug("ANDing the predicates. Pred1: {} Pred2: {}", returnPredicate, p);
                returnPredicate = and(returnPredicate, p);
            }
        }
    }
    LOGGER.debug("EXITING: AND filter");
    return returnPredicate;
}
Also used : IncludeFilter(org.opengis.filter.IncludeFilter) Filter(org.opengis.filter.Filter) ArrayList(java.util.ArrayList) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) 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 2 with ContentTypePredicate

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

the class PredicateTest method testContentTypeEvaluationNullOperation.

@Test
public void testContentTypeEvaluationNullOperation() throws IOException {
    String methodName = "testContentTypeEvaluationNullOperation";
    LOGGER.debug("***************  START: {}  *****************", methodName);
    MetacardImpl metacard = new MetacardImpl();
    metacard.setMetadata(TestDataLibrary.getCatAndDogEntry());
    ContentTypePredicate ctp = new ContentTypePredicate("type1", "version1");
    HashMap<String, Object> properties = new HashMap<>();
    properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, "type1,version1");
    properties.put(PubSubConstants.HEADER_OPERATION_KEY, null);
    Map<String, Object> contextualMap = constructContextualMap(metacard);
    properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
    Event testEvent = new Event("topic", properties);
    assertTrue(ctp.matches(testEvent));
    LOGGER.debug("***************  END: {}  *****************", methodName);
}
Also used : HashMap(java.util.HashMap) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) Event(org.osgi.service.event.Event) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 3 with ContentTypePredicate

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

the class PredicateTest method testContentTypeEvaluation.

@Test
public void testContentTypeEvaluation() throws IOException {
    String methodName = "testContentTypeEvaluation";
    LOGGER.debug("***************  START: {}  *****************", methodName);
    // test input that has type1:version1 matches
    // test input that has type1:version2 doesn't match
    // TODO: tests input that has type2:version1 doesn't match
    // TODO: test input that has type1:""
    // TODO: test input that has "":""
    // TODO: test input that has "":version1
    // TODO: test UNKNOWN for entire contentType String
    MetacardImpl metacard = new MetacardImpl();
    metacard.setMetadata(TestDataLibrary.getCatAndDogEntry());
    ContentTypePredicate ctp = new ContentTypePredicate("type1", "version1");
    HashMap<String, Object> properties = new HashMap<>();
    properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, "type1,version1");
    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);
    assertTrue(ctp.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");
    Event testEvent1 = new Event("topic1", properties);
    assertFalse(ctp.matches(testEvent1));
    properties.clear();
    properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
    properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
    properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, ",version2");
    testEvent1 = new Event("topic1", properties);
    assertFalse(ctp.matches(testEvent1));
    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,");
    testEvent1 = new Event("topic1", properties);
    assertFalse(ctp.matches(testEvent1));
    properties.clear();
    properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
    properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
    properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, ",");
    testEvent1 = new Event("topic1", properties);
    assertFalse(ctp.matches(testEvent1));
    properties.clear();
    properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
    properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
    properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, "UNKNOWN");
    testEvent1 = new Event("topic1", properties);
    assertFalse(ctp.matches(testEvent1));
    // TODO: test input type1:version1 matches
    // TODO: test input type1:someversion matches
    // TODO: test input type2:version1 doesn't match
    ContentTypePredicate ctp2 = new ContentTypePredicate("type1", null);
    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,version1");
    Event testEvent2 = new Event("topic", properties);
    assertTrue(ctp2.matches(testEvent2));
    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,someversion");
    Event testEvent3 = new Event("topic", properties);
    assertTrue(ctp2.matches(testEvent3));
    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,someversion");
    Event testEvent4 = new Event("topic", properties);
    assertFalse(ctp2.matches(testEvent4));
    LOGGER.debug("***************  END: {}  *****************", methodName);
}
Also used : HashMap(java.util.HashMap) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) Event(org.osgi.service.event.Event) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 4 with ContentTypePredicate

use of ddf.catalog.pubsub.predicate.ContentTypePredicate 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 5 with ContentTypePredicate

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

the class PredicateTest method testContentTypeEvaluatorTypeAndVersionMatch.

@Test
public void testContentTypeEvaluatorTypeAndVersionMatch() throws Exception {
    LOGGER.debug("**************************  START: testContentTypeEvaluator_TypeAndVersion_Match()  ***********************");
    // Match on "nitf, v20"
    ContentTypePredicate predicate = new ContentTypePredicate("nitf", "v20");
    String inputContentType = "nitf,v20";
    ContentTypeEvaluationCriteriaImpl ctec = new ContentTypeEvaluationCriteriaImpl(predicate, inputContentType);
    boolean status = ContentTypeEvaluator.evaluate(ctec);
    assertTrue(status);
    LOGGER.debug("**************************  END: testContentTypeEvaluator_TypeAndVersion_Match()  ***********************");
}
Also used : ContentTypeEvaluationCriteriaImpl(ddf.catalog.pubsub.criteria.contenttype.ContentTypeEvaluationCriteriaImpl) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) Test(org.junit.Test)

Aggregations

ContentTypePredicate (ddf.catalog.pubsub.predicate.ContentTypePredicate)13 Test (org.junit.Test)9 ContentTypeEvaluationCriteriaImpl (ddf.catalog.pubsub.criteria.contenttype.ContentTypeEvaluationCriteriaImpl)5 HashMap (java.util.HashMap)4 Event (org.osgi.service.event.Event)4 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)3 ContextualPredicate (ddf.catalog.pubsub.predicate.ContextualPredicate)3 ArrayList (java.util.ArrayList)3 EntryPredicate (ddf.catalog.pubsub.predicate.EntryPredicate)2 GeospatialPredicate (ddf.catalog.pubsub.predicate.GeospatialPredicate)2 Predicate (ddf.catalog.pubsub.predicate.Predicate)2 TemporalPredicate (ddf.catalog.pubsub.predicate.TemporalPredicate)2 AttributeExpressionImpl (org.geotools.filter.AttributeExpressionImpl)2 FuzzyFunction (ddf.catalog.impl.filter.FuzzyFunction)1 SubscriptionFilterVisitor (ddf.catalog.pubsub.internal.SubscriptionFilterVisitor)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 List (java.util.List)1 LikeFilterImpl (org.geotools.filter.LikeFilterImpl)1 LiteralExpressionImpl (org.geotools.filter.LiteralExpressionImpl)1