use of ddf.catalog.pubsub.predicate.ContentTypePredicate in project ddf by codice.
the class SubscriptionFilterVisitor method visit.
/**
* PropertyIsLike filter maps to a Contextual search criteria.
*/
@Override
public Object visit(PropertyIsLike filter, Object data) {
LOGGER.debug("ENTERING: PropertyIsLike filter");
String wildcard = filter.getWildCard();
String escape = filter.getEscape();
String single = filter.getSingleChar();
boolean isFuzzy = false;
List<String> textPathList = null;
LikeFilterImpl likeFilter = (LikeFilterImpl) filter;
Expression expression = likeFilter.getExpression();
// ContentTypePredicate
if (expression instanceof PropertyName) {
PropertyName propertyName = (PropertyName) expression;
if (Metacard.CONTENT_TYPE.equals(propertyName.getPropertyName())) {
LOGGER.debug("Expression is ContentType.");
String typeValue = likeFilter.getLiteral();
ContentTypePredicate predicate = new ContentTypePredicate(typeValue, null);
return predicate;
} else if (Metacard.CONTENT_TYPE_VERSION.equals(propertyName.getPropertyName())) {
LOGGER.debug("Expression is ContentTypeVersion.");
String versionValue = likeFilter.getLiteral();
ContentTypePredicate predicate = new ContentTypePredicate(null, versionValue);
return predicate;
}
}
if (expression instanceof AttributeExpressionImpl) {
AttributeExpressionImpl textPathExpression = (AttributeExpressionImpl) expression;
textPathList = extractXpathSelectors(textPathExpression);
} else if (expression instanceof FuzzyFunction) {
FuzzyFunction fuzzyFunction = (FuzzyFunction) expression;
LOGGER.debug("fuzzy search");
isFuzzy = true;
List<Expression> expressions = fuzzyFunction.getParameters();
AttributeExpressionImpl firstExpression = (AttributeExpressionImpl) expressions.get(0);
if (!Metacard.ANY_TEXT.equals(firstExpression.getPropertyName())) {
LOGGER.debug("fuzzy search has a text path section");
textPathList = extractXpathSelectors(firstExpression);
}
}
String searchPhrase = likeFilter.getLiteral();
LOGGER.debug("raw searchPhrase = [{}]", searchPhrase);
String sterilizedSearchPhrase = sterilize(searchPhrase, wildcard, escape, single);
LOGGER.debug("sterilizedSearchPhrase = [{}]", sterilizedSearchPhrase);
ContextualPredicate contextPred = new ContextualPredicate(sterilizedSearchPhrase, isFuzzy, likeFilter.isMatchingCase(), textPathList);
LOGGER.debug("EXITING: PropertyIsLike filter");
return contextPred;
}
use of ddf.catalog.pubsub.predicate.ContentTypePredicate in project ddf by codice.
the class ContentTypeEvaluator method evaluate.
public static boolean evaluate(ContentTypeEvaluationCriteriaImpl ctec) {
String methodName = "evaluate";
LOGGER.debug("ENTERING: {}", methodName);
ContentTypePredicate matchContentTypePredicate = ctec.getContentType();
String matchType = matchContentTypePredicate.getType();
String matchVersion = matchContentTypePredicate.getVersion();
// to handle the wildcard.
if (matchType != null) {
matchType = matchType.replaceAll("\\*", ".*");
}
if (matchVersion != null) {
matchVersion = matchVersion.replaceAll("\\*", ".*");
}
String input = ctec.getInputContentType();
LOGGER.debug("Match ContentType: {}", matchContentTypePredicate);
String inputType;
String inputVersion;
//Check if both type and version are blank
if (input == null || input.matches(",")) {
inputType = "null";
inputVersion = "null";
} else {
String[] inputTypeVersionPair = input.split(",");
//Check if content type is blank. If yes, set to null.
if (inputTypeVersionPair[0].isEmpty()) {
inputType = "null";
} else {
inputType = inputTypeVersionPair[0];
}
//Check if version is blank. If yes, set to null.
if (inputTypeVersionPair.length == 1) {
inputVersion = "null";
} else {
inputVersion = inputTypeVersionPair[1];
}
}
LOGGER.debug("inputType = {}, inputVersion = {}", inputType, inputVersion);
LOGGER.debug("matchType = {}, matchVersion = {}", matchType, matchVersion);
if (matchType != null && !matchType.isEmpty() && inputType.matches(matchType)) {
if (matchVersion != null && !matchVersion.isEmpty() && !inputVersion.matches(matchVersion)) {
LOGGER.debug("EXITING: {} - returning false. Did not match version.", methodName);
return false;
}
LOGGER.debug("EXITING: {} - returning true.", methodName);
return true;
}
LOGGER.debug("EXITING: {} - returning false.", methodName);
return false;
}
use of ddf.catalog.pubsub.predicate.ContentTypePredicate in project ddf by codice.
the class PredicateTest method testContentTypeEvaluatorTypeAndVersionTypeMismatch.
@Test
public void testContentTypeEvaluatorTypeAndVersionTypeMismatch() throws Exception {
LOGGER.debug("************************** START: testContentTypeEvaluator_TypeAndVersion_TypeMismatch() ***********************");
// Match on "nitf, v20"
ContentTypePredicate predicate = new ContentTypePredicate("nitf", "v20");
String inputContentType = "video,v20";
ContentTypeEvaluationCriteriaImpl ctec = new ContentTypeEvaluationCriteriaImpl(predicate, inputContentType);
boolean status = ContentTypeEvaluator.evaluate(ctec);
assertFalse(status);
LOGGER.debug("************************** END: testContentTypeEvaluator_TypeAndVersion_TypeMismatch() ***********************");
}
Aggregations