Skip to content

Commit

Permalink
Introduced queryInterpretationOfNoValue in expression
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Nov 2, 2015
1 parent 09d0fbe commit ac966f3
Show file tree
Hide file tree
Showing 9 changed files with 300 additions and 116 deletions.
73 changes: 73 additions & 0 deletions infra/schema/src/main/resources/xml/ns/public/common/common-3.xsd
Expand Up @@ -5249,6 +5249,13 @@
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="queryInterpretationOfNoValue" type="tns:QueryInterpretationOfNoValueType" minOccurs="0" default="filterEqualNull">
<xsd:annotation>
<xsd:documentation>
TODO
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element ref="tns:expressionEvaluator" minOccurs="1" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
Expand Down Expand Up @@ -5305,6 +5312,72 @@
</xsd:enumeration>
</xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="QueryInterpretationOfNoValueType">
<xsd:annotation>
<xsd:documentation>
Defined how the expression will be interpreted in queries when it returns
empty (or null) values.
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumClass/>
</xsd:appinfo>
</xsd:annotation>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="filterEqualNull">
<xsd:annotation>
<xsd:documentation>
The expression will be intepreted as an EQUAL filter
that looks for entries with no (null) value.
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="FILTER_EQUAL_NULL"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="filterUndefined">
<xsd:annotation>
<xsd:documentation>
The expression will be intepreted as an UNDEFINED filter.
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="FILTER_UNDEFINED"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="filterNone">
<xsd:annotation>
<xsd:documentation>
The expression will be intepreted as an NONE filter.
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="FILTER_NONE"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="filterAll">
<xsd:annotation>
<xsd:documentation>
The expression will be intepreted as an NONE filter.
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="FILTER_ALL"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="error">
<xsd:annotation>
<xsd:documentation>
Error will be thrown if the expression results in
empty (null) values.
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="ERROR"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
</xsd:restriction>
</xsd:simpleType>

<xsd:complexType name="StringFilterType">
<xsd:annotation>
Expand Down
Expand Up @@ -51,6 +51,7 @@
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.path.ItemPathSegment;
import com.evolveum.midpoint.prism.path.NameItemPathSegment;
import com.evolveum.midpoint.prism.query.AllFilter;
import com.evolveum.midpoint.prism.query.ExpressionWrapper;
import com.evolveum.midpoint.prism.query.InOidFilter;
import com.evolveum.midpoint.prism.query.LogicalFilter;
Expand Down Expand Up @@ -85,6 +86,7 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.QueryInterpretationOfNoValueType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType;

Expand Down Expand Up @@ -428,7 +430,7 @@ private static ObjectFilter evaluateFilterExpressionsInternal(ObjectFilter filte
if (expressionResult == null || expressionResult.isEmpty()) {
LOGGER.debug("Result of search filter expression was null or empty. Expression: {}",
valueExpression);
return evaluateFilter(filter, valueExpression);
return createFilterForNoValue(filter, valueExpression);
}
// TODO: log more context
LOGGER.trace("Search filter expression in the rule for {} evaluated to {}.",
Expand Down Expand Up @@ -482,7 +484,7 @@ private static ObjectFilter evaluateFilterExpressionsInternal(ObjectFilter filte
LOGGER.debug("Result of search filter expression was null or empty. Expression: {}",
valueExpression);

return evaluateFilter(pvfilter, valueExpression);
return createFilterForNoValue(pvfilter, valueExpression);
}
// TODO: log more context
LOGGER.trace("Search filter expression in the rule for {} evaluated to {}.",
Expand Down Expand Up @@ -526,20 +528,42 @@ private static ObjectFilter evaluateFilterExpressionsInternal(ObjectFilter filte

}

private static ObjectFilter evaluateFilter(ObjectFilter filter, ExpressionType valueExpression) {
if (valueExpression.isAllowEmptyValues() != null && !valueExpression.isAllowEmptyValues()) {
return UndefinedFilter.createUndefined();
}

if (filter instanceof PropertyValueFilter) {
PropertyValueFilter evaluatedFilter = (PropertyValueFilter) filter.clone();
evaluatedFilter.setExpression(null);
return evaluatedFilter;
} else if (filter instanceof InOidFilter) {
return NoneFilter.createNone();
}

throw new IllegalArgumentException("Unknow filter to evaluate: " + filter);
private static ObjectFilter createFilterForNoValue(ObjectFilter filter, ExpressionType valueExpression) throws ExpressionEvaluationException {
QueryInterpretationOfNoValueType queryInterpretationOfNoValue = valueExpression.getQueryInterpretationOfNoValue();
if (queryInterpretationOfNoValue == null) {
queryInterpretationOfNoValue = QueryInterpretationOfNoValueType.FILTER_EQUAL_NULL;
}

switch (queryInterpretationOfNoValue) {

case FILTER_UNDEFINED:
return UndefinedFilter.createUndefined();

case FILTER_NONE:
return NoneFilter.createNone();

case FILTER_ALL:
return AllFilter.createAll();

case FILTER_EQUAL_NULL:
if (filter instanceof PropertyValueFilter) {
PropertyValueFilter evaluatedFilter = (PropertyValueFilter) filter.clone();
evaluatedFilter.setExpression(null);
return evaluatedFilter;
} else if (filter instanceof InOidFilter) {
return NoneFilter.createNone();
} else {
throw new IllegalArgumentException("Unknow filter to evaluate: " + filter);
}

case ERROR:
throw new ExpressionEvaluationException("Expression "+valueExpression+" evaluated to no value");

default:
throw new IllegalArgumentException("Unknown value "+queryInterpretationOfNoValue+" in queryInterpretationOfNoValue in "+valueExpression);

}

}

private static <V extends PrismValue> V evaluateExpression(ExpressionVariables variables,
Expand Down

0 comments on commit ac966f3

Please sign in to comment.