use of com.evolveum.midpoint.prism.query.SubstringFilter 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);
}
}
use of com.evolveum.midpoint.prism.query.SubstringFilter in project midpoint by Evolveum.
the class ItemValueRestriction method findOperationForFilter.
protected ItemRestrictionOperation findOperationForFilter(ValueFilter filter) throws QueryException {
ItemRestrictionOperation operation;
if (filter instanceof EqualFilter) {
operation = ItemRestrictionOperation.EQ;
} else if (filter instanceof GreaterFilter) {
GreaterFilter gf = (GreaterFilter) filter;
operation = gf.isEquals() ? ItemRestrictionOperation.GE : ItemRestrictionOperation.GT;
} else if (filter instanceof LessFilter) {
LessFilter lf = (LessFilter) filter;
operation = lf.isEquals() ? ItemRestrictionOperation.LE : ItemRestrictionOperation.LT;
} else if (filter instanceof SubstringFilter) {
SubstringFilter substring = (SubstringFilter) filter;
if (substring.isAnchorEnd()) {
operation = ItemRestrictionOperation.ENDS_WITH;
} else if (substring.isAnchorStart()) {
operation = ItemRestrictionOperation.STARTS_WITH;
} else {
operation = ItemRestrictionOperation.SUBSTRING;
}
} else {
throw new QueryException("Can't translate filter '" + filter + "' to operation.");
}
return operation;
}
Aggregations