Search in sources :

Example 1 with CompValueType

use of io.jans.scim.service.antlr.scimFilter.enums.CompValueType 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);
                }
            }
        }
    }
}
Also used : Attribute(io.jans.scim.model.scim2.annotations.Attribute) ScimOperator(io.jans.scim.service.antlr.scimFilter.enums.ScimOperator) Type(io.jans.scim.model.scim2.AttributeDefinition.Type) NullType(javax.lang.model.type.NullType) CompValueType(io.jans.scim.service.antlr.scimFilter.enums.CompValueType) ExtensionField(io.jans.scim.model.scim2.extensions.ExtensionField) Filter(io.jans.orm.search.filter.Filter) ScimFilterParser(io.jans.scim.service.antlr.scimFilter.antlr4.ScimFilterParser) CompValueType(io.jans.scim.service.antlr.scimFilter.enums.CompValueType)

Example 2 with CompValueType

use of io.jans.scim.service.antlr.scimFilter.enums.CompValueType 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);
}
Also used : ScimOperator(io.jans.scim.service.antlr.scimFilter.enums.ScimOperator) ScimFilterParser(io.jans.scim.service.antlr.scimFilter.antlr4.ScimFilterParser) CompValueType(io.jans.scim.service.antlr.scimFilter.enums.CompValueType) SimpleExpression(io.jans.scim.service.antlr.scimFilter.util.SimpleExpression)

Aggregations

ScimFilterParser (io.jans.scim.service.antlr.scimFilter.antlr4.ScimFilterParser)2 CompValueType (io.jans.scim.service.antlr.scimFilter.enums.CompValueType)2 ScimOperator (io.jans.scim.service.antlr.scimFilter.enums.ScimOperator)2 Filter (io.jans.orm.search.filter.Filter)1 Type (io.jans.scim.model.scim2.AttributeDefinition.Type)1 Attribute (io.jans.scim.model.scim2.annotations.Attribute)1 ExtensionField (io.jans.scim.model.scim2.extensions.ExtensionField)1 SimpleExpression (io.jans.scim.service.antlr.scimFilter.util.SimpleExpression)1 NullType (javax.lang.model.type.NullType)1