Search in sources :

Example 1 with ValueFilter

use of com.evolveum.midpoint.prism.query.ValueFilter in project midpoint by Evolveum.

the class ValueOperation method interpret.

@Override
public <T> Filter interpret(ObjectFilter objectFilter, ConnIdNameMapper icfNameMapper) throws SchemaException {
    OperationResult parentResult = new OperationResult("interpret");
    ValueFilter valueFilter = (ValueFilter) objectFilter;
    if (valueFilter.getParentPath().isEmpty()) {
        throw new UnsupportedOperationException("Empty path is not supported (filter: " + objectFilter + ")");
    }
    if (valueFilter.getParentPath().equivalent(new ItemPath(ShadowType.F_ATTRIBUTES))) {
        try {
            QName propName = valueFilter.getDefinition().getName();
            String icfName = icfNameMapper.convertAttributeNameToIcf(propName, getInterpreter().getObjectClassDefinition(), "(attribute in the filter)");
            if (objectFilter instanceof EqualFilter) {
                EqualFilter<T> eq = (EqualFilter<T>) objectFilter;
                Collection<Object> convertedValues = convertValues(propName, eq.getValues());
                if (convertedValues == null || convertedValues.isEmpty()) {
                    // See MID-1460
                    throw new UnsupportedOperationException("Equals filter with a null value is NOT supported by ICF");
                } else {
                    Attribute attr = AttributeBuilder.build(icfName, convertedValues);
                    if (valueFilter.getDefinition().isSingleValue()) {
                        return FilterBuilder.equalTo(attr);
                    } else {
                        return FilterBuilder.containsAllValues(attr);
                    }
                }
            } else if (objectFilter instanceof SubstringFilter) {
                SubstringFilter substring = (SubstringFilter) objectFilter;
                Collection<Object> convertedValues = convertValues(propName, substring.getValues());
                if (convertedValues.isEmpty()) {
                    throw new IllegalArgumentException("Substring filter with null value makes no sense");
                } else {
                    if (convertedValues.size() != 1) {
                        throw new IllegalArgumentException("Substring filter with multiple values makes no sense");
                    //maybe it does, through OR clauses
                    }
                    return FilterBuilder.contains(AttributeBuilder.build(icfName, convertedValues.iterator().next()));
                }
            } else {
                throw new UnsupportedOperationException("Unsupported filter type: " + objectFilter);
            }
        } catch (SchemaException ex) {
            throw ex;
        }
    } else if (valueFilter.getParentPath().equivalent(new ItemPath(ShadowType.F_ACTIVATION))) {
        if (objectFilter instanceof EqualFilter) {
            QName propName = valueFilter.getDefinition().getName();
            EqualFilter<T> eq = (EqualFilter<T>) objectFilter;
            List<PrismPropertyValue<T>> values = eq.getValues();
            if (values.size() != 1) {
                throw new SchemaException("Unexpected number of values in filter " + objectFilter);
            }
            PrismPropertyValue<T> pval = values.get(0);
            String icfName;
            Object convertedValue;
            if (propName.equals(ActivationType.F_ADMINISTRATIVE_STATUS)) {
                icfName = OperationalAttributes.ENABLE_NAME;
                convertedValue = pval.getValue() == ActivationStatusType.ENABLED;
            } else if (propName.equals(ActivationType.F_LOCKOUT_STATUS)) {
                icfName = OperationalAttributes.LOCK_OUT_NAME;
                convertedValue = pval.getValue() == LockoutStatusType.LOCKED;
            } else {
                throw new UnsupportedOperationException("Unsupported activation property " + propName + " in filter: " + objectFilter);
            }
            Attribute attr = AttributeBuilder.build(icfName, convertedValue);
            if (valueFilter.getDefinition().isSingleValue()) {
                return FilterBuilder.equalTo(attr);
            } else {
                return FilterBuilder.containsAllValues(attr);
            }
        } else {
            throw new UnsupportedOperationException("Unsupported filter type in filter: " + objectFilter);
        }
    } else {
        throw new UnsupportedOperationException("Unsupported parent path " + valueFilter.getParentPath() + " in filter: " + objectFilter);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Attribute(org.identityconnectors.framework.common.objects.Attribute) QName(javax.xml.namespace.QName) SubstringFilter(com.evolveum.midpoint.prism.query.SubstringFilter) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Collection(java.util.Collection) ValueFilter(com.evolveum.midpoint.prism.query.ValueFilter) EqualFilter(com.evolveum.midpoint.prism.query.EqualFilter) ArrayList(java.util.ArrayList) List(java.util.List) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Aggregations

PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 EqualFilter (com.evolveum.midpoint.prism.query.EqualFilter)1 SubstringFilter (com.evolveum.midpoint.prism.query.SubstringFilter)1 ValueFilter (com.evolveum.midpoint.prism.query.ValueFilter)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 QName (javax.xml.namespace.QName)1 Attribute (org.identityconnectors.framework.common.objects.Attribute)1