use of io.jans.scim.service.antlr.scimFilter.enums.ScimOperator in project jans by JanssenProject.
the class FilterListener method enterAttrexp.
@Override
public void enterAttrexp(ScimFilterParser.AttrexpContext ctx) {
if (StringUtils.isEmpty(error)) {
log.trace("enterAttrexp.");
String path = ctx.attrpath().getText();
ScimFilterParser.CompvalueContext compValueCtx = ctx.compvalue();
boolean isPrRule = compValueCtx == null && ctx.getChild(1).getText().equals("pr");
Type attrType = null;
Attribute attrAnnot = IntrospectUtil.getFieldAnnotation(path, resourceClass, Attribute.class);
String ldapAttribute = null;
boolean isNested = false;
Boolean multiValued = false;
if (attrAnnot == null) {
ExtensionField field = extService.getFieldOfExtendedAttribute(resourceClass, path);
if (field == null) {
error = String.format("Attribute path '%s' is not recognized in %s", path, resourceClass.getSimpleName());
} else {
attrType = field.getAttributeDefinitionType();
multiValued = field.isMultiValued();
ldapAttribute = path.substring(path.lastIndexOf(":") + 1);
}
} else {
attrType = attrAnnot.type();
Pair<String, Boolean> pair = FilterUtil.getLdapAttributeOfResourceAttribute(path, resourceClass);
ldapAttribute = pair.getFirst();
isNested = pair.getSecond();
multiValued = computeMultivaluedForCoreAttribute(path, attrAnnot, ldapAttribute);
}
if (error != null) {
// Intentionally left empty
} else if (attrType == null) {
error = String.format("Could not determine type of attribute path '%s' in %s", path, resourceClass.getSimpleName());
} else if (ldapAttribute == null) {
error = String.format("Could not determine LDAP attribute for path '%s' in %s", path, resourceClass.getSimpleName());
} else {
String subattr = isNested ? path.substring(path.lastIndexOf(".") + 1) : null;
CompValueType type;
ScimOperator operator;
if (isPrRule) {
type = CompValueType.NULL;
operator = ScimOperator.NOT_EQUAL;
} else {
type = FilterUtil.getCompValueType(compValueCtx);
operator = ScimOperator.getByValue(ctx.compareop().getText());
}
error = FilterUtil.checkFilterConsistency(path, attrType, type, operator);
if (error == null) {
Pair<Filter, String> subf = subFilterGenerator.build(subattr, ldapAttribute, isPrRule ? null : compValueCtx.getText(), attrType, type, operator, multiValued);
Filter subFilth = subf.getFirst();
error = subf.getSecond();
if (subFilth == null) {
if (error == null) {
error = String.format("Operator '%s' is not supported for attribute %s", operator.getValue(), path);
}
} else {
filter.push(subFilth);
}
}
}
}
}
use of io.jans.scim.service.antlr.scimFilter.enums.ScimOperator in project jans by JanssenProject.
the class MatchFilterVisitor method visitAttrexp.
@Override
public Boolean visitAttrexp(ScimFilterParser.AttrexpContext ctx) {
log.trace("visitAttrexp. childs: {}, text: {}", ctx.getChildCount(), ctx.getText());
String path = ctx.attrpath().getText();
ScimFilterParser.CompvalueContext compValueCtx = ctx.compvalue();
boolean isPrRule = compValueCtx == null && ctx.getChild(1).getText().equals("pr");
ScimOperator operator;
CompValueType valueType;
String value;
if (isPrRule) {
operator = ScimOperator.NOT_EQUAL;
valueType = CompValueType.NULL;
value = null;
} else {
operator = ScimOperator.getByValue(ctx.compareop().getText());
valueType = FilterUtil.getCompValueType(compValueCtx);
value = compValueCtx.getText();
if (// drop double quotes
CompValueType.STRING.equals(valueType))
value = value.substring(1, value.length() - 1);
}
SimpleExpression expr = new SimpleExpression(path, operator, valueType, value);
expr.setParentAttribute(parentAttribute);
expr.setResourceClass(resourceClass);
return expr.evaluate(item);
}
Aggregations