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;
}
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);
}
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);
}
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;
}
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() ***********************");
}
Aggregations