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