diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/AssignmentEditorPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/AssignmentEditorPanel.java index 07b41a38bd8..527f72d1c0c 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/AssignmentEditorPanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/AssignmentEditorPanel.java @@ -582,7 +582,7 @@ private WebMarkupContainer createOrgContainer() { protected ObjectQuery getChooseQuery() { return QueryBuilder.queryFor(OrgType.class, getPageBase().getPrismContext()) .item(OrgType.F_TENANT).eq(false) - .or().item(OrgType.F_TENANT).eq(null) + .or().item(OrgType.F_TENANT).isNull() .build(); } diff --git a/infra/prism/pom.xml b/infra/prism/pom.xml index 4fcd220ad3e..5a234425281 100644 --- a/infra/prism/pom.xml +++ b/infra/prism/pom.xml @@ -60,7 +60,7 @@ org.apache.commons commons-lang3 - + org.apache.santuario xmlsec diff --git a/infra/prism/src/main/java/com/evolveum/midpoint/prism/Itemable.java b/infra/prism/src/main/java/com/evolveum/midpoint/prism/Itemable.java index 3697920dc6a..e48e00474a3 100644 --- a/infra/prism/src/main/java/com/evolveum/midpoint/prism/Itemable.java +++ b/infra/prism/src/main/java/com/evolveum/midpoint/prism/Itemable.java @@ -24,18 +24,20 @@ * * Currently provides common abstraction on top of Item and ItemDelta, as both can hold values and * construct them in a similar way. + * + * Also used for ValueFilter, although semantics of e.g. getPath() is quite different in this case. * * @author Radovan Semancik * */ public interface Itemable { - public QName getElementName(); + QName getElementName(); - public ItemDefinition getDefinition(); + ItemDefinition getDefinition(); - public PrismContext getPrismContext(); + PrismContext getPrismContext(); - public ItemPath getPath(); + ItemPath getPath(); } diff --git a/infra/prism/src/main/java/com/evolveum/midpoint/prism/marshaller/QueryConvertor.java b/infra/prism/src/main/java/com/evolveum/midpoint/prism/marshaller/QueryConvertor.java index 9c22e04a9cb..0533aec6eff 100644 --- a/infra/prism/src/main/java/com/evolveum/midpoint/prism/marshaller/QueryConvertor.java +++ b/infra/prism/src/main/java/com/evolveum/midpoint/prism/marshaller/QueryConvertor.java @@ -278,7 +278,7 @@ private static ObjectFilter parseComparisonFilter(QN ItemPath rightSidePath = getPath(clauseXMap, ELEMENT_RIGHT_HAND_SIDE_PATH); ItemDefinition itemDefinition = locateItemDefinition(valueXnode, itemPath, pcd, prismContext); - if (itemDefinition != null){ + if (itemDefinition != null) { itemName = itemDefinition.getName(); } @@ -299,9 +299,10 @@ private static ObjectFilter parseComparisonFilter(QN PrismPropertyValue propertyValue = (PrismPropertyValue) item.getValue(0); propertyValue.clearParent(); if (isGt || isGtEq) { - return GreaterFilter.createGreater(itemPath, pcd, propertyValue, isGtEq); + return GreaterFilter.createGreater(itemPath, (PrismPropertyDefinition) itemDefinition, isGtEq, prismContext, propertyValue); } else { - return LessFilter.createLess(itemPath, pcd, propertyValue, isLtEq); + return LessFilter.createLess(itemPath, (PrismPropertyDefinition) itemDefinition, prismContext, + propertyValue, isLtEq); } } } else if (rightSidePath != null) { @@ -312,9 +313,11 @@ private static ObjectFilter parseComparisonFilter(QN if (isEq) { return EqualFilter.createEqual(itemPath, (PrismPropertyDefinition) itemDefinition, matchingRule, rightSidePath, rightSideDefinition); } else if (isGt || isGtEq) { - return GreaterFilter.createGreater(itemPath, (PrismPropertyDefinition) itemDefinition, rightSidePath, rightSideDefinition, isGtEq); + return GreaterFilter.createGreater(itemPath, (PrismPropertyDefinition) itemDefinition, rightSidePath, + rightSideDefinition, isGtEq); } else { - return LessFilter.createLess(itemPath, (PrismPropertyDefinition) itemDefinition, rightSidePath, rightSideDefinition, isLtEq); + return LessFilter.createLess(itemPath, (PrismPropertyDefinition) itemDefinition, rightSidePath, + rightSideDefinition, isLtEq); } } } else { @@ -331,9 +334,11 @@ private static ObjectFilter parseComparisonFilter(QN if (isEq) { return EqualFilter.createEqual(itemPath, (PrismPropertyDefinition) itemDefinition, matchingRule, expressionWrapper); } else if (isGt || isGtEq) { - return GreaterFilter.createGreater(itemPath, (PrismPropertyDefinition) itemDefinition, expressionWrapper, isGtEq); + return GreaterFilter.createGreater(itemPath, (PrismPropertyDefinition) itemDefinition, + expressionWrapper, isGtEq); } else { - return LessFilter.createLess(itemPath, (PrismPropertyDefinition) itemDefinition, expressionWrapper, isLtEq); + return LessFilter.createLess(itemPath, (PrismPropertyDefinition) itemDefinition, expressionWrapper, + isLtEq); } } } else { @@ -343,7 +348,7 @@ private static ObjectFilter parseComparisonFilter(QN if (preliminaryParsingOnly) { return null; } else { - return EqualFilter.createEqual(itemPath, (PrismPropertyDefinition) itemDefinition, matchingRule, prismContext); + return EqualFilter.createEqual(itemPath, (PrismPropertyDefinition) itemDefinition, matchingRule); } } } @@ -738,7 +743,7 @@ private static MapXNode serializeInOidFilter(InOidFilter filter, XNodeSerializer return createFilter(CLAUSE_IN_OID, clauseMap); } - private static MapXNode serializeComparisonFilter(PropertyValueFilter filter, XNodeSerializer xnodeSerializer) throws SchemaException{ + private static MapXNode serializeComparisonFilter(PropertyValueFilter filter, XNodeSerializer xnodeSerializer) throws SchemaException{ MapXNode map = new MapXNode(); QName clause; if (filter instanceof EqualFilter) { @@ -754,15 +759,15 @@ private static MapXNode serializeComparisonFilter(Propert return map; } - private static MapXNode serializeValueFilter(PropertyValueFilter filter, XNodeSerializer xnodeSerializer) throws SchemaException { + private static MapXNode serializeValueFilter(ValueFilter filter, XNodeSerializer xnodeSerializer) throws SchemaException { MapXNode map = new MapXNode(); serializeMatchingRule(filter, map); serializePath(map, filter.getFullPath(), filter); - List values = filter.getValues(); + List values = filter.getValues(); if (values != null) { ListXNode valuesNode = new ListXNode(); - for (T val : values) { + for (V val : values) { if (val.getParent() == null) { val.setParent(filter); } diff --git a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/AllFilter.java b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/AllFilter.java index 0b83cfbf861..e7f1eeb0877 100644 --- a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/AllFilter.java +++ b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/AllFilter.java @@ -40,6 +40,7 @@ public static AllFilter createAll() { return new AllFilter(); } + @SuppressWarnings("CloneDoesntCallSuperClone") @Override public AllFilter clone() { return new AllFilter(); @@ -61,7 +62,6 @@ public String debugDump(int indent) { DebugUtil.indentDebugDump(sb, indent); sb.append("ALL"); return sb.toString(); - } @Override diff --git a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/AndFilter.java b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/AndFilter.java index 641327bda3a..7fd581d6432 100644 --- a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/AndFilter.java +++ b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/AndFilter.java @@ -16,20 +16,17 @@ package com.evolveum.midpoint.prism.query; -import java.util.ArrayList; -import java.util.List; - -import javax.xml.namespace.QName; - -import com.evolveum.midpoint.prism.Containerable; -import com.evolveum.midpoint.prism.Objectable; import com.evolveum.midpoint.prism.PrismConstants; import com.evolveum.midpoint.prism.PrismContainerValue; -import com.evolveum.midpoint.prism.PrismObject; import com.evolveum.midpoint.prism.match.MatchingRuleRegistry; import com.evolveum.midpoint.util.DebugUtil; import com.evolveum.midpoint.util.exception.SchemaException; +import javax.xml.namespace.QName; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + public class AndFilter extends NaryLogicalFilter { public static final QName ELEMENT_NAME = new QName(PrismConstants.NS_QUERY, "and"); @@ -39,11 +36,8 @@ public AndFilter(List condition) { } public static AndFilter createAnd(ObjectFilter... conditions){ - List filters = new ArrayList(); - for (ObjectFilter condition : conditions){ - filters.add(condition); - } - + List filters = new ArrayList<>(conditions.length); + Collections.addAll(filters, conditions); return new AndFilter(filters); } @@ -51,6 +45,7 @@ public static AndFilter createAnd(List conditions){ return new AndFilter(conditions); } + @SuppressWarnings("CloneDoesntCallSuperClone") @Override public AndFilter clone() { return new AndFilter(getClonedConditions()); @@ -75,9 +70,7 @@ public String debugDump(int indent) { sb.append("\n"); sb.append(filter.debugDump(indent + 1)); } - return sb.toString(); - } @Override @@ -87,7 +80,7 @@ public String toString() { sb.append("("); for (int i = 0; i < getConditions().size(); i++){ sb.append(getConditions().get(i)); - if (i != getConditions().size() -1){ + if (i != getConditions().size() - 1) { sb.append(","); } } diff --git a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/ComparativeFilter.java b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/ComparativeFilter.java index 2ea3404d483..e242af652f8 100644 --- a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/ComparativeFilter.java +++ b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/ComparativeFilter.java @@ -16,24 +16,31 @@ package com.evolveum.midpoint.prism.query; +import java.util.Collections; import java.util.List; +import java.util.Objects; -import com.evolveum.midpoint.prism.ItemDefinition; -import com.evolveum.midpoint.prism.PrismPropertyDefinition; -import com.evolveum.midpoint.prism.PrismPropertyValue; +import com.evolveum.midpoint.prism.*; +import com.evolveum.midpoint.prism.match.MatchingRuleRegistry; import com.evolveum.midpoint.prism.path.ItemPath; +import com.evolveum.midpoint.util.exception.SchemaException; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -public abstract class ComparativeFilter extends PropertyValueFilter> { +import javax.xml.namespace.QName; + +public abstract class ComparativeFilter extends PropertyValueFilter { private boolean equals; - - ComparativeFilter(ItemPath path, PrismPropertyDefinition definition, PrismPropertyValue value, boolean equals) { - super(path, definition, value); - this.equals = equals; - } - public ComparativeFilter(ItemPath path, PrismPropertyDefinition definition, ItemPath rightSidePath, ItemDefinition rightSideDefinition, boolean equals) { - super(path, definition, null, rightSidePath, rightSideDefinition); + ComparativeFilter(@NotNull ItemPath path, + @Nullable PrismPropertyDefinition definition, + @Nullable PrismPropertyValue value, + @Nullable ExpressionWrapper expression, @Nullable ItemPath rightHandSidePath, + @Nullable ItemDefinition rightHandSideDefinition, boolean equals) { + super(path, definition, null, + value != null ? Collections.singletonList(value) : null, + expression, rightHandSidePath, rightHandSideDefinition); this.equals = equals; } @@ -44,19 +51,17 @@ public boolean isEquals() { public void setEquals(boolean equals) { this.equals = equals; } - - static PrismPropertyValue createPropertyValue(PrismPropertyDefinition itemDefinition, T realValue){ - List> values = realValueToPropertyList(itemDefinition, realValue); - if (values == null || values.isEmpty()){ + + @Nullable + static PrismPropertyValue anyValueToPropertyValue(@NotNull PrismContext prismContext, Object value) { + List> values = anyValueToPropertyValueList(prismContext, value); + if (values.isEmpty()) { return null; + } else if (values.size() > 1) { + throw new UnsupportedOperationException("Comparative filter with more than one value is not supported"); + } else { + return values.iterator().next(); } - - if (values.size() > 1 ){ - throw new UnsupportedOperationException("Greater filter with more than one value is not supported"); - } - - return values.iterator().next(); - } @Override @@ -67,17 +72,17 @@ public boolean equals(Object o, boolean exact) { return false; if (!super.equals(o, exact)) return false; - ComparativeFilter that = (ComparativeFilter) o; - return equals == that.equals; + } + @Override + public boolean match(PrismContainerValue value, MatchingRuleRegistry matchingRuleRegistry) throws SchemaException { + throw new UnsupportedOperationException("Matching object and greater/less filter is not supported yet"); } @Override public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (equals ? 1 : 0); - return result; + return Objects.hash(super.hashCode(), equals); } } diff --git a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/EqualFilter.java b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/EqualFilter.java index 2ac2e6cc565..35a748388b6 100644 --- a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/EqualFilter.java +++ b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/EqualFilter.java @@ -16,109 +16,98 @@ package com.evolveum.midpoint.prism.query; -import java.util.Collection; -import java.util.List; - -import javax.xml.namespace.QName; - -import com.evolveum.midpoint.prism.ItemDefinition; -import com.evolveum.midpoint.prism.PrismContainerValue; +import com.evolveum.midpoint.prism.*; import com.evolveum.midpoint.prism.match.MatchingRule; import com.evolveum.midpoint.prism.match.MatchingRuleRegistry; - -import com.evolveum.midpoint.prism.Containerable; -import com.evolveum.midpoint.prism.Item; -import com.evolveum.midpoint.prism.Itemable; -import com.evolveum.midpoint.prism.PrismConstants; -import com.evolveum.midpoint.prism.PrismContext; -import com.evolveum.midpoint.prism.PrismProperty; -import com.evolveum.midpoint.prism.PrismPropertyDefinition; -import com.evolveum.midpoint.prism.PrismPropertyValue; import com.evolveum.midpoint.prism.path.ItemPath; -import com.evolveum.midpoint.util.DebugUtil; import com.evolveum.midpoint.util.exception.SchemaException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class EqualFilter extends PropertyValueFilter> implements Itemable { +import javax.xml.namespace.QName; +import java.util.List; + +public class EqualFilter extends PropertyValueFilter implements Itemable { private static final long serialVersionUID = 3284478412180258355L; public static final QName ELEMENT_NAME = new QName(PrismConstants.NS_QUERY, "equal"); - private EqualFilter(@NotNull ItemPath fullPath, PrismPropertyDefinition definition, QName matchingRule, - @NotNull ItemPath rightSidePath, ItemDefinition rightSideDefinition) { - super(fullPath, definition, matchingRule, rightSidePath, rightSideDefinition); - } - - private EqualFilter(@NotNull ItemPath fullPath, PrismPropertyDefinition definition, QName matchingRule, - List> values, ExpressionWrapper expression) { - super(fullPath, definition, matchingRule, values, expression); - } - - //factory methods - // Do not require definition. We may want queries for which the definition is supplied later. - - // right-side-related - @NotNull - public static EqualFilter createEqual(ItemPath propertyPath, PrismPropertyDefinition propertyDefinition, QName matchingRule, ItemPath rightSidePath, ItemDefinition rightSideDefinition) { - return new EqualFilter<>(propertyPath, propertyDefinition, matchingRule, rightSidePath, rightSideDefinition); - } - - // expression-related + /* + * The pattern for factory methods and constructors signatures is: + * - path and definition + * - matching rule (if applicable) + * - values (incl. prismContext if needed) + * - expressionWrapper + * - right hand things + * - filter-specific flags (equal, anchors) + * + * Ordering of methods: + * - constructor + * - factory methods: [null], value(s), expression, right-side + * - match + * - equals + * + * Parent for prism values is set in the appropriate constructor; so there's no need to do that at other places. + * + * Normalization of "Object"-typed values is done in anyArrayToXXX and anyValueToXXX methods. This includes cloning + * of values that have a parent (note that we recompute the PolyString values as part of conversion process; if that's + * a problem for the client, it has to do cloning itself). + * + * Please respect these conventions in order to make these classes understandable and maintainable. + */ + + public EqualFilter(@NotNull ItemPath path, @Nullable PrismPropertyDefinition definition, + @Nullable QName matchingRule, + @Nullable List> prismPropertyValues, + @Nullable ExpressionWrapper expression, @Nullable ItemPath rightHandSidePath, + @Nullable ItemDefinition rightHandSideDefinition) { + super(path, definition, matchingRule, prismPropertyValues, expression, rightHandSidePath, rightHandSideDefinition); + } + + // factory methods + + // empty (different from values as it generates filter with null 'values' attribute) @NotNull - public static EqualFilter createEqual(@NotNull ItemPath path, @Nullable PrismPropertyDefinition definition, - @Nullable QName matchingRule, @Nullable ExpressionWrapper expression) { - return new EqualFilter<>(path, definition, matchingRule, null, expression); + public static EqualFilter createEqual(@NotNull ItemPath path, @NotNull PrismPropertyDefinition definition, + @Nullable QName matchingRule) { + return new EqualFilter(path, definition, matchingRule, null, null, null, null); } // values @NotNull public static EqualFilter createEqual(@NotNull ItemPath path, @NotNull PrismPropertyDefinition definition, @Nullable QName matchingRule, @NotNull PrismContext prismContext, Object... values) { - return new EqualFilter(path, definition, matchingRule, (List) createPropertyListFromArray(prismContext, values), null); + List> propertyValues = anyArrayToPropertyValueList(prismContext, values); + return new EqualFilter(path, definition, matchingRule, propertyValues, null, null, null); } - @Override - public EqualFilter clone() { - EqualFilter clone = new EqualFilter<>(getFullPath(), getDefinition(), getMatchingRule(), getCloneValuesList(), getExpression()); - clone.copyRightSideThingsFrom(this); - return clone; - } - - @Override - public String debugDump() { - return debugDump(0); + // expression-related + @NotNull + public static EqualFilter createEqual(@NotNull ItemPath path, @Nullable PrismPropertyDefinition definition, + @Nullable QName matchingRule, @NotNull ExpressionWrapper expression) { + return new EqualFilter<>(path, definition, matchingRule, null, expression, null, null); } - @Override - public String debugDump(int indent) { - StringBuilder sb = new StringBuilder(); - DebugUtil.indentDebugDump(sb, indent); - sb.append("EQUAL:"); - return debugDump(indent, sb); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("EQUAL: "); - return toString(sb); + // right-side-related; right side can be supplied later (therefore it's nullable) + @NotNull + public static EqualFilter createEqual(@NotNull ItemPath propertyPath, PrismPropertyDefinition propertyDefinition, + QName matchingRule, @NotNull ItemPath rightSidePath, ItemDefinition rightSideDefinition) { + return new EqualFilter<>(propertyPath, propertyDefinition, matchingRule, null, null, rightSidePath, rightSideDefinition); } + @SuppressWarnings("CloneDoesntCallSuperClone") @Override - public PrismContext getPrismContext() { - PrismPropertyDefinition def = getDefinition(); - if (def == null) { - return null; - } - return def.getPrismContext(); + public EqualFilter clone() { + return new EqualFilter<>(getFullPath(), getDefinition(), getMatchingRule(), getClonedValues(), + getExpression(), getRightHandSidePath(), getRightHandSideDefinition()); } @Override - public ItemPath getPath() { - return getFullPath(); + protected String getFilterName() { + return "EQUAL"; } + // TODO revise @Override public boolean match(PrismContainerValue cvalue, MatchingRuleRegistry matchingRuleRegistry) throws SchemaException { Item filterItem = getFilterItem(); @@ -172,19 +161,9 @@ private boolean isInFilterItem(PrismPropertyValue v, Item filterItem, MatchingRu return false; } - @Override - public PrismPropertyDefinition getDefinition(){ - return (PrismPropertyDefinition) super.getDefinition(); - } - - @Override - public List> getValues() { - return super.getValues(); - } - @Override public boolean equals(Object obj, boolean exact) { - return super.equals(obj, exact) && obj instanceof EqualFilter; + return obj instanceof EqualFilter && super.equals(obj, exact); } } diff --git a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/ExistsFilter.java b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/ExistsFilter.java index 3a2bdc9e891..a2723d22f68 100644 --- a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/ExistsFilter.java +++ b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/ExistsFilter.java @@ -16,19 +16,13 @@ package com.evolveum.midpoint.prism.query; -import com.evolveum.midpoint.prism.Containerable; -import com.evolveum.midpoint.prism.ItemDefinition; -import com.evolveum.midpoint.prism.PrismContainerDefinition; -import com.evolveum.midpoint.prism.PrismContainerValue; -import com.evolveum.midpoint.prism.PrismContext; -import com.evolveum.midpoint.prism.PrismPropertyDefinition; +import com.evolveum.midpoint.prism.*; import com.evolveum.midpoint.prism.match.MatchingRuleRegistry; import com.evolveum.midpoint.prism.path.ItemPath; import com.evolveum.midpoint.util.DebugUtil; import com.evolveum.midpoint.util.PrettyPrinter; import com.evolveum.midpoint.util.exception.SchemaException; - -import javax.xml.namespace.QName; +import org.jetbrains.annotations.NotNull; /** * TODO think about creating abstract ItemFilter (ItemRelatedFilter) for this filter and ValueFilter. @@ -38,18 +32,19 @@ */ public class ExistsFilter extends ObjectFilter { - private ItemPath fullPath; + @NotNull private final ItemPath fullPath; private ItemDefinition definition; private ObjectFilter filter; - public ExistsFilter(ItemPath fullPath, ItemDefinition definition, ObjectFilter filter) { + public ExistsFilter(@NotNull ItemPath fullPath, ItemDefinition definition, ObjectFilter filter) { this.fullPath = fullPath; this.definition = definition; this.filter = filter; checkConsistence(true); } - public ItemPath getFullPath() { + @NotNull + public ItemPath getFullPath() { return fullPath; } @@ -77,7 +72,8 @@ public static ExistsFilter createExists(ItemPath itemP return new ExistsFilter(itemPath, itemDefinition, filter); } - @Override + @SuppressWarnings("CloneDoesntCallSuperClone") + @Override public ObjectFilter clone() { ObjectFilter f = filter != null ? filter.clone() : null; return new ExistsFilter(fullPath, definition, f); @@ -94,7 +90,7 @@ public boolean match(PrismContainerValue value, MatchingRuleRegistry matchingRul @Override public void checkConsistence(boolean requireDefinitions) { - if (fullPath == null || fullPath.isEmpty()) { + if (fullPath.isEmpty()) { throw new IllegalArgumentException("Null or empty path in "+this); } if (requireDefinitions && definition == null) { @@ -160,7 +156,7 @@ public boolean equals(Object o, boolean exact) { ExistsFilter that = (ExistsFilter) o; - if (fullPath != null ? !fullPath.equals(that.fullPath, exact) : that.fullPath != null) + if (!fullPath.equals(that.fullPath, exact)) return false; if (exact) { if (definition != null ? !definition.equals(that.definition) : that.definition != null) diff --git a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/GreaterFilter.java b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/GreaterFilter.java index d989a58e5a5..c8085bf03ce 100644 --- a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/GreaterFilter.java +++ b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/GreaterFilter.java @@ -15,14 +15,9 @@ */ package com.evolveum.midpoint.prism.query; -import javax.xml.namespace.QName; - -import com.evolveum.midpoint.prism.Containerable; import com.evolveum.midpoint.prism.ItemDefinition; -import com.evolveum.midpoint.prism.PrismContainerDefinition; import com.evolveum.midpoint.prism.PrismContainerValue; -import com.evolveum.midpoint.prism.Objectable; import com.evolveum.midpoint.prism.PrismContext; import com.evolveum.midpoint.prism.PrismPropertyDefinition; import com.evolveum.midpoint.prism.PrismPropertyValue; @@ -30,132 +25,62 @@ import com.evolveum.midpoint.prism.path.ItemPath; import com.evolveum.midpoint.util.DebugUtil; import com.evolveum.midpoint.util.exception.SchemaException; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class GreaterFilter extends ComparativeFilter { - - GreaterFilter(ItemPath itemPath, PrismPropertyDefinition definition, PrismPropertyValue value, boolean equals) { - super(itemPath, definition, value, equals); - } - - GreaterFilter(ItemPath itemPath, PrismPropertyDefinition definition, ItemPath rightSidePath, ItemDefinition rightSideDefinition, boolean equals) { - super(itemPath, definition, rightSidePath, rightSideDefinition, equals); - } - - public static GreaterFilter createGreater(ItemPath itemPath, PrismPropertyDefinition definition, PrismPropertyValue value, boolean equals){ - GreaterFilter greaterFilter = new GreaterFilter<>(itemPath, definition, value, equals); - if (value != null) { - value.setParent(greaterFilter); - } - return greaterFilter; - } - - public static GreaterFilter createGreater(ItemPath itemPath, PrismContainerDefinition containerDef, - PrismPropertyValue value, boolean equals) throws SchemaException { - PrismPropertyDefinition def = (PrismPropertyDefinition) FilterUtils.findItemDefinition(itemPath, containerDef); - GreaterFilter greaterFilter = createGreater(itemPath, def, value, equals); - if (value != null) { - value.setParent(greaterFilter); - } - return greaterFilter; - } - public static GreaterFilter createGreater(ItemPath itemPath, PrismPropertyDefinition itemDefinition, T realValue, boolean equals) { - PrismPropertyValue value = createPropertyValue(itemDefinition, realValue); - - if (value == null){ - //TODO: create null - } - - GreaterFilter greaterFilter = createGreater(itemPath, itemDefinition, value, equals); - value.setParent(greaterFilter); - return greaterFilter; + public GreaterFilter(@NotNull ItemPath path, @Nullable PrismPropertyDefinition definition, + @Nullable PrismPropertyValue prismPropertyValue, + @Nullable ExpressionWrapper expression, @Nullable ItemPath rightHandSidePath, + @Nullable ItemDefinition rightHandSideDefinition, boolean equals) { + super(path, definition, prismPropertyValue, expression, rightHandSidePath, rightHandSideDefinition, equals); } - public static GreaterFilter createGreater(ItemPath itemPath, PrismContainerDefinition containerDef, - T realValue, boolean equals) throws SchemaException { - PrismPropertyDefinition def = (PrismPropertyDefinition) FilterUtils.findItemDefinition(itemPath, containerDef); - return createGreater(itemPath, def, realValue, equals); - } - - public static GreaterFilter createGreater(QName propertyName, Class type, PrismContext prismContext, T realValue, boolean equals) - throws SchemaException { - return createGreater(new ItemPath(propertyName), type, prismContext, realValue, equals); - } - - public static GreaterFilter createGreater(ItemPath path, Class type, PrismContext prismContext, T realValue, boolean equals) - throws SchemaException { - - PrismPropertyDefinition def = (PrismPropertyDefinition) FilterUtils.findItemDefinition(path, type, prismContext); - - return createGreater(path, def, realValue, equals); - } + // factory methods - public static GreaterFilter createGreater(ItemPath propertyPath, PrismPropertyDefinition propertyDefinition, ItemPath rightSidePath, ItemDefinition rightSideDefinition, boolean equals) { - return new GreaterFilter(propertyPath, propertyDefinition, rightSidePath, rightSideDefinition, equals); - } - - @Override - public GreaterFilter clone() { - PrismPropertyValue clonedValue = null; - PrismPropertyValue value = getSingleValue(); - if (value != null) { - clonedValue = value.clone(); - } - GreaterFilter clone = new GreaterFilter<>(getFullPath(), getDefinition(), clonedValue, isEquals()); - if (clonedValue != null) { - clonedValue.setParent(clone); - } - clone.copyRightSideThingsFrom(this); - return clone; + // empty (can be filled-in later) + @NotNull + public static GreaterFilter createGreater(@NotNull ItemPath itemPath, PrismPropertyDefinition definition, boolean equals) { + return new GreaterFilter(itemPath, definition, null, null, null, null, equals); } - @Override - public String debugDump() { - return debugDump(0); + // value + @NotNull + public static GreaterFilter createGreater(@NotNull ItemPath itemPath, PrismPropertyDefinition definition, + boolean equals, @NotNull PrismContext prismContext, Object anyValue) { + PrismPropertyValue propertyValue = anyValueToPropertyValue(prismContext, anyValue); + return new GreaterFilter(itemPath, definition, propertyValue, null, null, null, equals); } - @Override - public String debugDump(int indent) { - StringBuilder sb = new StringBuilder(); - DebugUtil.indentDebugDump(sb, indent); - sb.append("GREATER:"); - return debugDump(indent, sb); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("GREATER: "); - return toString(sb); + // expression-related + @NotNull + public static GreaterFilter createGreater(@NotNull ItemPath itemPath, PrismPropertyDefinition definition, + @NotNull ExpressionWrapper wrapper, boolean equals) { + return new GreaterFilter<>(itemPath, definition, null, wrapper, null, null, equals); } - @Override - public boolean match(PrismContainerValue value, MatchingRuleRegistry matchingRuleRegistry) throws SchemaException { - throw new UnsupportedOperationException("Matching object and greater filter not supported yet"); - } - - @Override - public PrismPropertyDefinition getDefinition() { - return (PrismPropertyDefinition) super.getDefinition(); + // right-side-related + @NotNull + public static GreaterFilter createGreater(@NotNull ItemPath propertyPath, PrismPropertyDefinition definition, + @NotNull ItemPath rightSidePath, ItemDefinition rightSideDefinition, boolean equals) { + return new GreaterFilter<>(propertyPath, definition, null, null, rightSidePath, rightSideDefinition, equals); } + @SuppressWarnings("CloneDoesntCallSuperClone") @Override - public PrismContext getPrismContext() { - return getDefinition().getPrismContext(); + public GreaterFilter clone() { + return new GreaterFilter(getFullPath(), getDefinition(), getClonedValue(), getExpression(), + getRightHandSidePath(), getRightHandSideDefinition(), isEquals()); } @Override - public ItemPath getPath() { - return getFullPath(); - } - - public static GreaterFilter createGreaterThanItem(ItemPath itemPath, PrismPropertyDefinition propertyDefinition, ItemPath rightSidePath, ItemDefinition rightSideDefinition, boolean equals) { - return new GreaterFilter<>(itemPath, propertyDefinition, rightSidePath, rightSideDefinition, equals); + protected String getFilterName() { + return "GREATER"; } @Override public boolean equals(Object obj, boolean exact) { - return super.equals(obj, exact) && obj instanceof GreaterFilter; + return obj instanceof GreaterFilter && super.equals(obj, exact); } - } diff --git a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/InFilter.java b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/InFilter.java deleted file mode 100644 index 35ad6ad2c7f..00000000000 --- a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/InFilter.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2010-2014 Evolveum - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.evolveum.midpoint.prism.query; - -import java.util.List; - -import javax.xml.namespace.QName; - -import com.evolveum.midpoint.prism.PrismContext; -import com.evolveum.midpoint.prism.PrismPropertyDefinition; -import com.evolveum.midpoint.prism.PrismPropertyValue; -import com.evolveum.midpoint.prism.path.ItemPath; -import com.evolveum.midpoint.util.DebugUtil; - -@Deprecated // deprecated because of confusing name/semantics; see https://wiki.evolveum.com/display/midPoint/Query+API+Evolution -public class InFilter extends PropertyValueFilter { - - InFilter(ItemPath path, PrismPropertyDefinition definition, QName matchingRule, List values ) { - super(path, definition, matchingRule, values); - } - - public static InFilter createIn(ItemPath path, PrismPropertyDefinition definition, QName matchingRule, V values){ - - List> pVals = realValueToPropertyList(definition, values); - - return new InFilter(path, definition, matchingRule, pVals); - } - - - public static InFilter createIn(ItemPath path, PrismPropertyDefinition definition, QName matchingRule, PrismPropertyValue... values) { - - List> pVals = createPropertyList(definition, values); - - return new InFilter(path, definition, matchingRule, pVals); - } - - public static InFilter createIn(ItemPath path, PrismPropertyDefinition definition, PrismPropertyValue... values) { - return createIn(path, definition, null, values); - } - - public static InFilter createIn(ItemPath path, Class type, PrismContext prismContext, QName matchingRule, V values) { - - PrismPropertyDefinition definition = (PrismPropertyDefinition) FilterUtils.findItemDefinition(path, type, prismContext); - return createIn(path, definition, null, values); - } - - - - @Override - public PrismContext getPrismContext() { - return getDefinition().getPrismContext(); - } - - @Override - public ItemPath getPath() { - return getFullPath(); - } - - @Override - public String debugDump() { - return debugDump(0); - } - - @Override - public String debugDump(int indent) { - StringBuilder sb = new StringBuilder(); - DebugUtil.indentDebugDump(sb, indent); - sb.append("IN: "); - return debugDump(indent, sb); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("IN: "); - return toString(sb); - } - - @Override - public InFilter clone() { - return new InFilter(getFullPath(), getDefinition(),getMatchingRule(), getValues()); - } - - @Override - public PrismPropertyDefinition getDefinition() { - return (PrismPropertyDefinition) super.getDefinition(); - } - - @Override - public boolean equals(Object obj, boolean exact) { - return super.equals(obj, exact) && obj instanceof InFilter; - } - -} diff --git a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/LessFilter.java b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/LessFilter.java index c58dd73a215..546a55f86ae 100644 --- a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/LessFilter.java +++ b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/LessFilter.java @@ -16,153 +16,66 @@ package com.evolveum.midpoint.prism.query; -import javax.xml.namespace.QName; - -import com.evolveum.midpoint.prism.Containerable; import com.evolveum.midpoint.prism.ItemDefinition; -import com.evolveum.midpoint.prism.Objectable; -import com.evolveum.midpoint.prism.PrismContainerDefinition; -import com.evolveum.midpoint.prism.PrismContainerValue; import com.evolveum.midpoint.prism.PrismContext; import com.evolveum.midpoint.prism.PrismPropertyDefinition; import com.evolveum.midpoint.prism.PrismPropertyValue; -import com.evolveum.midpoint.prism.match.MatchingRuleRegistry; import com.evolveum.midpoint.prism.path.ItemPath; -import com.evolveum.midpoint.util.DebugUtil; -import com.evolveum.midpoint.util.exception.SchemaException; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class LessFilter extends ComparativeFilter { - LessFilter(ItemPath itemPath, PrismPropertyDefinition definition, PrismPropertyValue value, boolean equals) { - super(itemPath, definition, value, equals); - } - - LessFilter(ItemPath itemPath, PrismPropertyDefinition definition, ItemPath rightSidePath, ItemDefinition rightSideDefinition, boolean equals) { - super(itemPath, definition, rightSidePath, rightSideDefinition, equals); - } - - public static LessFilter createLess(QName itemPath, PrismPropertyDefinition definition, PrismPropertyValue value, boolean equals){ - LessFilter lessFilter = new LessFilter<>(new ItemPath(itemPath), definition, value, equals); - if (value != null) { - value.setParent(lessFilter); - } - return lessFilter; - } - - public static LessFilter createLess(ItemPath itemPath, PrismPropertyDefinition definition, PrismPropertyValue value, boolean equals){ - LessFilter lessFilter = new LessFilter<>(itemPath, definition, value, equals); - if (value != null) { - value.setParent(lessFilter); - } - return lessFilter; - } - - public static LessFilter createLess(ItemPath itemPath, PrismContainerDefinition containerDef, - PrismPropertyValue value, boolean equals) throws SchemaException { - PrismPropertyDefinition def = (PrismPropertyDefinition) FilterUtils.findItemDefinition(itemPath, containerDef); - return createLess(itemPath, def, value, equals); + public LessFilter(@NotNull ItemPath path, @Nullable PrismPropertyDefinition definition, + @Nullable PrismPropertyValue value, @Nullable ExpressionWrapper expression, + @Nullable ItemPath rightHandSidePath, @Nullable ItemDefinition rightHandSideDefinition, boolean equals) { + super(path, definition, value, expression, rightHandSidePath, rightHandSideDefinition, equals); } - public static LessFilter createLess(QName itemPath, PrismPropertyDefinition itemDefinition, T realValue, boolean equals) { - return createLess(new ItemPath(itemPath), itemDefinition, realValue, equals); - } - - public static LessFilter createLess(ItemPath itemPath, PrismPropertyDefinition itemDefinition, T realValue, boolean equals) { - PrismPropertyValue value = createPropertyValue(itemDefinition, realValue); - - if (value == null){ - // create null filter - } - - return createLess(itemPath, itemDefinition, value, equals); - } + // factory methods - public static LessFilter createLessThanItem(ItemPath itemPath, PrismPropertyDefinition propertyDefinition, ItemPath rightSidePath, ItemDefinition rightSideDefinition, boolean equals) { - return new LessFilter<>(itemPath, propertyDefinition, rightSidePath, rightSideDefinition, equals); + // empty (can be filled-in later) + @NotNull + public static LessFilter createLess(@NotNull ItemPath itemPath, PrismPropertyDefinition definition, boolean equals) { + return new LessFilter(itemPath, definition, null, null, null, null, equals); } - public static LessFilter createLess(ItemPath itemPath, PrismContainerDefinition containerDef, - T realValue, boolean equals) throws SchemaException { - PrismPropertyDefinition def = (PrismPropertyDefinition) FilterUtils.findItemDefinition(itemPath, containerDef); - return createLess(itemPath, def, realValue, equals); + // value + @NotNull + public static LessFilter createLess(@NotNull ItemPath itemPath, PrismPropertyDefinition definition, + @NotNull PrismContext prismContext, Object anyValue, boolean equals) { + PrismPropertyValue propertyValue = anyValueToPropertyValue(prismContext, anyValue); + return new LessFilter(itemPath, definition, propertyValue, null, null, null, equals); } - public static LessFilter createLess(QName propertyName, Class type, PrismContext prismContext, T realValue, boolean equals) - throws SchemaException { - return createLess(new ItemPath(propertyName), type, prismContext, realValue, equals); - } - - public static LessFilter createLess(ItemPath path, Class type, PrismContext prismContext, T realValue, boolean equals) - throws SchemaException { - - PrismPropertyDefinition def = (PrismPropertyDefinition) FilterUtils.findItemDefinition(path, type, prismContext); - - return createLess(path, def, realValue, equals); + // expression-related + @NotNull + public static LessFilter createLess(@NotNull ItemPath itemPath, PrismPropertyDefinition itemDefinition, + @NotNull ExpressionWrapper wrapper, boolean equals) { + return new LessFilter<>(itemPath, itemDefinition, null, wrapper, null, null, equals); } - public static LessFilter createLess(ItemPath propertyPath, PrismPropertyDefinition propertyDefinition, ItemPath rightSidePath, ItemDefinition rightSideDefinition, boolean equals) { - return new LessFilter<>(propertyPath, propertyDefinition, rightSidePath, rightSideDefinition, equals); + // right-side-related + @NotNull + public static LessFilter createLess(@NotNull ItemPath propertyPath, PrismPropertyDefinition definition, + @NotNull ItemPath rightSidePath, ItemDefinition rightSideDefinition, boolean equals) { + return new LessFilter<>(propertyPath, definition, null, null, rightSidePath, rightSideDefinition, equals); } + @SuppressWarnings("CloneDoesntCallSuperClone") @Override public LessFilter clone() { - PrismPropertyValue clonedValue = null; - PrismPropertyValue value = getSingleValue(); - if (value != null) { - clonedValue = value.clone(); - } - LessFilter clone = new LessFilter<>(getFullPath(), getDefinition(), clonedValue, isEquals()); - if (clonedValue != null) { - clonedValue.setParent(clone); - } - clone.copyRightSideThingsFrom(this); - return clone; - } - - @Override - public String debugDump() { - return debugDump(0); - } - - @Override - public String debugDump(int indent) { - StringBuilder sb = new StringBuilder(); - DebugUtil.indentDebugDump(sb, indent); - sb.append("LESS:"); - return debugDump(indent, sb); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("LESS: "); - return toString(sb); - } - - @Override - public boolean match(PrismContainerValue value, MatchingRuleRegistry matchingRuleRegistry) throws SchemaException { - throw new UnsupportedOperationException("Matching object and less filter not supported yet"); - } - - @Override - public PrismPropertyDefinition getDefinition() { - return (PrismPropertyDefinition) super.getDefinition(); + return new LessFilter(getFullPath(), getDefinition(), getClonedValue(), getExpression(), + getRightHandSidePath(), getRightHandSideDefinition(), isEquals()); } @Override - public PrismContext getPrismContext() { - return getDefinition().getPrismContext(); - } - - @Override - public ItemPath getPath() { - return getFullPath(); + protected String getFilterName() { + return "LESS"; } @Override public boolean equals(Object obj, boolean exact) { - return super.equals(obj, exact) && obj instanceof LessFilter; + return obj instanceof LessFilter && super.equals(obj, exact); } - - } diff --git a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/NotFilter.java b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/NotFilter.java index 77321630c4f..e8c4f79bf70 100644 --- a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/NotFilter.java +++ b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/NotFilter.java @@ -32,10 +32,7 @@ public class NotFilter extends UnaryLogicalFilter { -// private ObjectFilter filter; - public NotFilter() { - } public NotFilter(ObjectFilter filter) { @@ -46,6 +43,7 @@ public static NotFilter createNot(ObjectFilter filter) { return new NotFilter(filter); } + @SuppressWarnings("CloneDoesntCallSuperClone") @Override public NotFilter clone() { return new NotFilter(getFilter().clone()); @@ -70,9 +68,7 @@ public String debugDump(int indent) { sb.append("\n"); sb.append(getFilter().debugDump(indent + 1)); } - return sb.toString(); - } @Override diff --git a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/ObjectFilter.java b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/ObjectFilter.java index 6b555a4c673..a35c675aef1 100644 --- a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/ObjectFilter.java +++ b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/ObjectFilter.java @@ -27,11 +27,10 @@ import com.evolveum.midpoint.util.exception.SchemaException; public abstract class ObjectFilter implements DebugDumpable, Serializable, Revivable { - - ObjectFilter() { - // Nothing to do - } - + + /** + * Does a SHALLOW clone. + */ public abstract ObjectFilter clone(); public abstract boolean match(PrismContainerValue value, MatchingRuleRegistry matchingRuleRegistry) throws SchemaException; @@ -41,7 +40,7 @@ public void accept(Visitor visitor) { } @Override - public void revive(final PrismContext prismContext) throws SchemaException { + public void revive(PrismContext prismContext) throws SchemaException { QueryConvertor.revive(this, prismContext); } diff --git a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/ObjectQuery.java b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/ObjectQuery.java index f5cde569b33..19570e63bd0 100644 --- a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/ObjectQuery.java +++ b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/ObjectQuery.java @@ -209,6 +209,7 @@ public Integer getMaxSize() { return paging.getMaxSize(); } + @SuppressWarnings("EqualsWhichDoesntCheckParameterClass") public boolean equals(Object o) { return equals(o, true); } diff --git a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/OrFilter.java b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/OrFilter.java index 137a40cda76..a2f97bf1eec 100644 --- a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/OrFilter.java +++ b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/OrFilter.java @@ -17,6 +17,7 @@ package com.evolveum.midpoint.prism.query; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import com.evolveum.midpoint.prism.Containerable; @@ -33,13 +34,9 @@ public OrFilter(List condition) { super(condition); } - public static OrFilter createOr(ObjectFilter... conditions){ List filters = new ArrayList(); - for (ObjectFilter condition : conditions){ - filters.add(condition); - } - + Collections.addAll(filters, conditions); return new OrFilter(filters); } @@ -47,6 +44,7 @@ public static OrFilter createOr(List conditions){ return new OrFilter(conditions); } + @SuppressWarnings("CloneDoesntCallSuperClone") @Override public OrFilter clone() { return new OrFilter(getClonedConditions()); diff --git a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/OrgFilter.java b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/OrgFilter.java index 30b87629cba..f8e657681c1 100644 --- a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/OrgFilter.java +++ b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/OrgFilter.java @@ -50,10 +50,6 @@ public static OrgFilter createOrg(String baseOrgOid, Scope scope) { return new OrgFilter(new PrismReferenceValue(baseOrgOid), scope); } - public static OrgFilter createOrg(String baseOrgRef) { - return new OrgFilter(new PrismReferenceValue(baseOrgRef), Scope.SUBTREE); - } - public static OrgFilter createRootOrg() { OrgFilter filter = new OrgFilter(); filter.setRoot(true); @@ -64,18 +60,10 @@ public PrismReferenceValue getOrgRef() { return baseOrgRef; } - public void setOrgRef(PrismReferenceValue baseOrgRef) { - this.baseOrgRef = baseOrgRef; - } - public Scope getScope() { return scope; } - public void setScope(Scope scope) { - this.scope = scope; - } - private void setRoot(boolean root) { this.root = root; } diff --git a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/PropertyValueFilter.java b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/PropertyValueFilter.java index 615aff6b81b..5b43e02dc10 100644 --- a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/PropertyValueFilter.java +++ b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/PropertyValueFilter.java @@ -32,87 +32,51 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public abstract class PropertyValueFilter extends ValueFilter implements Itemable { - - private ExpressionWrapper expression; - private List values; - private ItemPath rightHandSidePath; // alternative to "values" - private ItemDefinition rightHandSideDefinition; // optional (needed only if path points to extension item) - - /* - * TODO clean up the right side path/definition mess - */ - - PropertyValueFilter(@NotNull ItemPath path, @Nullable ItemDefinition definition, @Nullable QName matchingRule, - @NotNull ItemPath rightHandSidePath, @Nullable ItemDefinition rightHandSideDefinition) { - super(path, definition, matchingRule); - this.rightHandSidePath = rightHandSidePath; - this.rightHandSideDefinition = rightHandSideDefinition; - } - - protected PropertyValueFilter(@NotNull ItemPath path, @Nullable ItemDefinition definition, @Nullable QName matchingRule, - @Nullable List values, @Nullable ExpressionWrapper expression) { - super(path, definition, matchingRule); - if (values != null) { - for (V value : values) { - value.setParent(this); - } - } - this.values = values; - this.expression = expression; - } - - PropertyValueFilter(@NotNull ItemPath path, @Nullable ItemDefinition definition, @Nullable QName matchingRule, @Nullable List values) { - this(path, definition, matchingRule, values, null); - } - - PropertyValueFilter(@NotNull ItemPath path, @Nullable ItemDefinition definition, @Nullable V value) { - this(path, definition, (QName) null, value != null ? Collections.singletonList(value) : null); - } - - PropertyValueFilter(@NotNull ItemPath path, @Nullable ItemDefinition definition, @Nullable QName matchingRule) { - this(path, definition, matchingRule, (List) null); - } - - PropertyValueFilter(@NotNull ItemPath path, @Nullable ItemDefinition definition, @Nullable ExpressionWrapper expression, @Nullable List values) { - this(path, definition, null, values, expression); - } - - static protected List> createPropertyList(@NotNull PrismPropertyDefinition itemDefinition, @Nullable PrismPropertyValue pValue) { - List> pValues = new ArrayList<>(); - if (pValue == null) { - return pValues; - } else { - PrismUtil.recomputePrismPropertyValue(pValue, itemDefinition.getPrismContext()); - pValues.add(pValue); - return pValues; - } - } - - static List> createPropertyList(PrismPropertyDefinition itemDefinition, PrismPropertyValue[] values) { - Validate.notNull(itemDefinition, "Item definition in substring filter must not be null."); - - List> pValues = new ArrayList>(); - - for (PrismPropertyValue val : values){ - PrismUtil.recomputePrismPropertyValue(val, itemDefinition.getPrismContext()); - pValues.add(val); - } - - return pValues; - } +public abstract class PropertyValueFilter extends ValueFilter, PrismPropertyDefinition> implements Itemable { + + PropertyValueFilter(@NotNull ItemPath path, @Nullable PrismPropertyDefinition definition, @Nullable QName matchingRule, + @Nullable List> values, @Nullable ExpressionWrapper expression, + @Nullable ItemPath rightHandSidePath, @Nullable ItemDefinition rightHandSideDefinition) { + super(path, definition, matchingRule, values, expression, rightHandSidePath, rightHandSideDefinition); + } + +// static protected List> createPropertyList(@NotNull PrismPropertyDefinition itemDefinition, @Nullable PrismPropertyValue pValue) { +// List> pValues = new ArrayList<>(); +// if (pValue == null) { +// return pValues; +// } else { +// PrismUtil.recomputePrismPropertyValue(pValue, itemDefinition.getPrismContext()); +// pValues.add(pValue); +// return pValues; +// } +// } +// +// static List> createPropertyList(PrismPropertyDefinition itemDefinition, PrismPropertyValue[] values) { +// Validate.notNull(itemDefinition, "Item definition in substring filter must not be null."); +// +// List> pValues = new ArrayList>(); +// +// for (PrismPropertyValue val : values){ +// PrismUtil.recomputePrismPropertyValue(val, itemDefinition.getPrismContext()); +// pValues.add(val); +// } +// +// return pValues; +// } - static List> createPropertyListFromArray(PrismContext prismContext, Object[] values) { - List> pVals = new ArrayList<>(); + @NotNull + static List> anyArrayToPropertyValueList(PrismContext prismContext, Object[] values) { + List> pVals = new ArrayList<>(); if (values != null) { for (Object value : values) { - addToPrismValues(pVals, prismContext, value); + addToPrismValues((List) pVals, prismContext, value); } } return pVals; } - static List> createPropertyListFromValue(PrismContext prismContext, Object value) { + @NotNull + static List> anyValueToPropertyValueList(PrismContext prismContext, Object value) { List> pVals = new ArrayList<>(); if (value != null) { addToPrismValues((List) pVals, prismContext, value); @@ -120,14 +84,6 @@ static List> createPropertyListFromValue(PrismContext return pVals; } -// static List> createPropertyListFromCollection(PrismContext prismContext, Collection realValues) { -// List> pVals = new ArrayList<>(); -// for (T realValue : realValues) { -// addToPrismValues(pVals, realValue, prismContext); -// } -// return pVals; -// } - private static void addToPrismValues(List> pVals, PrismContext prismContext, Object value) { if (value == null) { return; @@ -155,313 +111,43 @@ private static void addToPrismValues(List> pVals, PrismCon pVals.add(pVal); } - static List> realValueToPropertyList(PrismPropertyDefinition itemDefinition, T realValue) { - List> pVals = new ArrayList<>(); - if (realValue == null) { - return pVals; - } - - if (realValue.getClass() != null && Collection.class.isAssignableFrom(realValue.getClass())) { - for (Object o : (Iterable)realValue){ - if (o instanceof PrismPropertyValue){ - PrismPropertyValue pVal = (PrismPropertyValue) o; - PrismUtil.recomputePrismPropertyValue(pVal, itemDefinition.getPrismContext()); - pVals.add(pVal); - }else{ - // TODO what's this??? - pVals.addAll(PrismPropertyValue.createCollection((Collection) realValue)); - } - } - - } else { - PrismUtil.recomputeRealValue(realValue, itemDefinition.getPrismContext()); - pVals.add(new PrismPropertyValue(realValue)); - } - return pVals; - } - - public List getValues() { - return values; - } - - public V getSingleValue() { - if (values == null || values.isEmpty()) { - return null; - } - if (values.size() > 1) { - throw new IllegalArgumentException("Filter '" + this + "' should contain at most one value, but it has " + values.size() + " of them."); - } - return values.iterator().next(); - } - - public void setValue(V value) { - List values = new ArrayList(); - if (value != null) { - value.setParent(this); - values.add(value); - } - this.values = values; - } - - protected void cloneValues(PropertyValueFilter clone) { - clone.values = getCloneValuesList(); - if (clone.values != null) { - for (V clonedValue: clone.values) { - clonedValue.setParent(clone); - } - } - } - - protected List getCloneValuesList() { - if (values == null) { - return null; - } - List clonedValues = new ArrayList(values.size()); - for(V value: values) { - clonedValues.add((V) value.clone()); - } - return clonedValues; - } - - public Item getObjectItem(PrismContainerValue value){ - ItemPath path = getFullPath(); - return value.findItem(path); - } - - public Item getFilterItem() throws SchemaException{ - - if (getDefinition() == null){ - throw new SchemaException("Could not find definition for item " + getPath()); - } - Item filterItem = getDefinition().instantiate(); - if (getValues() != null && !getValues().isEmpty()) { - try { - for (PrismValue v : getValues()){ - filterItem.add(v.clone()); - } - } catch (SchemaException e) { - throw new IllegalArgumentException(e.getMessage(), e); - } - } - - return filterItem; - } - - public ItemPath getRightHandSidePath() { - return rightHandSidePath; - } - - public ItemDefinition getRightHandSideDefinition() { - return rightHandSideDefinition; - } - - public void setRightHandSidePath(ItemPath rightHandSidePath) { - this.rightHandSidePath = rightHandSidePath; - if (rightHandSidePath != null) { - values = null; - } - } - - public void setRightHandSideDefinition(ItemDefinition rightHandSideDefinition) { - this.rightHandSideDefinition = rightHandSideDefinition; - } - - public ExpressionWrapper getExpression() { - return expression; - } - - public void setExpression(ExpressionWrapper expression) { - this.expression = expression; - } - - @Override - public void checkConsistence(boolean requireDefinitions) { - super.checkConsistence(requireDefinitions); - if (values == null) { - return; // this is OK, searching for item with no value - } - for (V value: values) { - if (value.getParent() != this) { - throw new IllegalArgumentException("Value "+value+" in "+this+" has a bad parent "+value.getParent()); - } - if (value == null) { - throw new IllegalArgumentException("Null value in "+this); - } - if (value.isEmpty() && !value.isRaw()) { - throw new IllegalArgumentException("Empty value in "+this); - } - } - } - - @Override - public boolean isRaw() { - if (values != null) { - for (V value: values) { - if (value.isRaw()) { - return true; - } - } - } - return false; - } - - @Override - public boolean match(PrismContainerValue cvalue, MatchingRuleRegistry matchingRuleRegistry) throws SchemaException { - - Item item = getObjectItem(cvalue); - - boolean filterItemIsEmpty = getValues() == null || getValues().isEmpty(); - boolean objectItemIsEmpty = item == null || item.isEmpty(); - - if (filterItemIsEmpty && !objectItemIsEmpty) { - return false; - } - - if (!filterItemIsEmpty && objectItemIsEmpty) { - return false; - } - - return true; - } +// static List> realValueToPropertyList(PrismPropertyDefinition itemDefinition, Object realValue) { +// List> pVals = new ArrayList<>(); +// if (realValue == null) { +// return pVals; +// } +// +// if (realValue.getClass() != null && Collection.class.isAssignableFrom(realValue.getClass())) { +// for (Object o : (Iterable)realValue){ +// if (o instanceof PrismPropertyValue){ +// PrismPropertyValue pVal = (PrismPropertyValue) o; +// PrismUtil.recomputePrismPropertyValue(pVal, itemDefinition.getPrismContext()); +// pVals.add(pVal); +// }else{ +// // TODO what's this??? +// pVals.addAll(PrismPropertyValue.createCollection((Collection) realValue)); +// } +// } +// +// } else { +// PrismUtil.recomputeRealValue(realValue, itemDefinition.getPrismContext()); +// pVals.add(new PrismPropertyValue(realValue)); +// } +// return pVals; +// } - @Override - public boolean equals(Object o) { - return equals(o, true); - } - - @Override - public boolean equals(Object o, boolean exact) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - if (!super.equals(o, exact)) - return false; - - PropertyValueFilter that = (PropertyValueFilter) o; - - if (expression != null ? !expression.equals(that.expression) : that.expression != null) - return false; - if (values != null ? !values.equals(that.values) : that.values != null) - return false; - if (rightHandSidePath != null ? !rightHandSidePath.equals(that.rightHandSidePath, exact) : that.rightHandSidePath != null) - return false; - if (exact) { - return rightHandSideDefinition != null ? - rightHandSideDefinition.equals(that.rightHandSideDefinition) : - that.rightHandSideDefinition == null; - } else { - return true; - } - } - @Override - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (expression != null ? expression.hashCode() : 0); - result = 31 * result + (values != null ? values.hashCode() : 0); - result = 31 * result + (rightHandSidePath != null ? rightHandSidePath.hashCode() : 0); - result = 31 * result + (rightHandSideDefinition != null ? rightHandSideDefinition.hashCode() : 0); - return result; - } - - public String debugDump(int indent, StringBuilder sb){ - if (getFullPath() != null){ - sb.append("\n"); - DebugUtil.indentDebugDump(sb, indent+1); - sb.append("PATH: "); - sb.append(getFullPath().toString()); - } - - sb.append("\n"); - DebugUtil.indentDebugDump(sb, indent+1); - sb.append("DEF: "); - if (getDefinition() != null) { - sb.append(getDefinition().toString()); - } else { - sb.append("null"); - } - - List values = getValues(); - if (values != null) { - sb.append("\n"); - DebugUtil.indentDebugDump(sb, indent+1); - sb.append("VALUE:"); - sb.append("\n"); - for (PrismValue val : getValues()) { - sb.append(DebugUtil.debugDump(val, indent + 2)); - } - } - - ExpressionWrapper expression = getExpression(); - if (expression != null && expression.getExpression() != null) { - sb.append("\n"); - DebugUtil.indentDebugDump(sb, indent+1); - sb.append("EXPRESSION:"); - sb.append("\n"); - sb.append(DebugUtil.debugDump(expression.getExpression(), indent + 2)); - } - - if (getRightHandSidePath() != null) { - sb.append("\n"); - DebugUtil.indentDebugDump(sb, indent+1); - sb.append("RIGHT SIDE PATH: "); - sb.append(getFullPath().toString()); - sb.append("\n"); - DebugUtil.indentDebugDump(sb, indent+1); - sb.append("RIGHT SIDE DEF: "); - if (getRightHandSideDefinition() != null) { - sb.append(getRightHandSideDefinition().toString()); - } else { - sb.append("null"); - } - } - - QName matchingRule = getMatchingRule(); - if (matchingRule != null) { - sb.append("\n"); - DebugUtil.indentDebugDump(sb, indent+1); - sb.append("MATCHING: "); - sb.append(matchingRule); - } - - return sb.toString(); - } - - public String toString(StringBuilder sb){ - if (getFullPath() != null){ - sb.append(getFullPath().toString()); - sb.append(","); - } - if (getValues() != null){ - for (int i = 0; i< getValues().size() ; i++){ - PrismValue value = getValues().get(i); - if (value == null) { - sb.append("null"); - } else { - sb.append(value.toString()); - } - if ( i != getValues().size() -1){ - sb.append(","); - } - } - } - if (rightHandSidePath != null) { - sb.append(getRightHandSidePath()); - } - return sb.toString(); - } +// protected void cloneValues(PropertyValueFilter clone) { +// clone.values = getCloneValuesList(); +// if (clone.values != null) { +// for (V clonedValue: clone.values) { +// clonedValue.setParent(clone); +// } +// } +// } // TODO cleanup this mess - how values are cloned, that expression is not cloned in LT/GT filter etc public abstract PropertyValueFilter clone(); - protected void copyRightSideThingsFrom(PropertyValueFilter original) { - if (original.getRightHandSidePath() != null) { - setRightHandSidePath(original.getRightHandSidePath()); - } - if (original.getRightHandSideDefinition() != null) { - setRightHandSideDefinition(original.getRightHandSideDefinition()); - } - } } diff --git a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/RefFilter.java b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/RefFilter.java index 356a5dc4f3d..18c4fea831b 100644 --- a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/RefFilter.java +++ b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/RefFilter.java @@ -15,55 +15,45 @@ */ package com.evolveum.midpoint.prism.query; -import com.evolveum.midpoint.prism.*; +import com.evolveum.midpoint.prism.Item; +import com.evolveum.midpoint.prism.PrismContainerValue; +import com.evolveum.midpoint.prism.PrismReferenceDefinition; +import com.evolveum.midpoint.prism.PrismReferenceValue; import com.evolveum.midpoint.prism.match.MatchingRuleRegistry; import com.evolveum.midpoint.prism.path.ItemPath; -import com.evolveum.midpoint.util.DebugUtil; import com.evolveum.midpoint.util.exception.SchemaException; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collection; import java.util.List; -public class RefFilter extends PropertyValueFilter { +public class RefFilter extends ValueFilter { private static final long serialVersionUID = 1L; - private RefFilter(ItemPath path, PrismReferenceDefinition definition, ExpressionWrapper expression, List values) { - super(path, definition, expression, values); + public RefFilter(@NotNull ItemPath fullPath, @Nullable PrismReferenceDefinition definition, + @Nullable List values, @Nullable ExpressionWrapper expression) { + super(fullPath, definition, null, values, expression, null, null); } - + public static RefFilter createReferenceEqual(ItemPath path, PrismReferenceDefinition definition, Collection values) { - return new RefFilter(path, definition, null, values != null ? new ArrayList<>(values) : null); + return new RefFilter(path, definition, values != null ? new ArrayList<>(values) : null, null); } public static RefFilter createReferenceEqual(ItemPath path, PrismReferenceDefinition definition, ExpressionWrapper expression) { - return new RefFilter(path, definition, expression, null); + return new RefFilter(path, definition, null, expression); } + @SuppressWarnings("CloneDoesntCallSuperClone") @Override public RefFilter clone() { - return new RefFilter(getFullPath(), getDefinition(), getExpression(), getCloneValuesList()); - } - - @Override - public String debugDump() { - return debugDump(0); + return new RefFilter(getFullPath(), getDefinition(), getClonedValues(), getExpression()); } @Override - public String debugDump(int indent) { - StringBuilder sb = new StringBuilder(); - DebugUtil.indentDebugDump(sb, indent); - sb.append("REF:"); - - return debugDump(indent, sb); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("REF: "); - return toString(sb); + protected String getFilterName() { + return "REF"; } @Override @@ -113,25 +103,9 @@ private boolean isInFilterItem(PrismReferenceValue v, Item filterItem) { return false; } - @Override - public PrismContext getPrismContext() { - return getDefinition().getPrismContext(); - } - - @Override - public ItemPath getPath() { - return getFullPath(); - } - - @Override - public PrismReferenceDefinition getDefinition() { - // TODO Auto-generated method stub - return (PrismReferenceDefinition) super.getDefinition(); - } - @Override public boolean equals(Object obj, boolean exact) { - return super.equals(obj, exact) && obj instanceof RefFilter; + return obj instanceof RefFilter && super.equals(obj, exact); } } diff --git a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/SubstringFilter.java b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/SubstringFilter.java index 0542a846776..21666fc8727 100644 --- a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/SubstringFilter.java +++ b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/SubstringFilter.java @@ -16,17 +16,10 @@ package com.evolveum.midpoint.prism.query; -import com.evolveum.midpoint.prism.Item; -import com.evolveum.midpoint.prism.ItemDefinition; -import com.evolveum.midpoint.prism.PrismContainerValue; -import com.evolveum.midpoint.prism.PrismContext; -import com.evolveum.midpoint.prism.PrismPropertyDefinition; -import com.evolveum.midpoint.prism.PrismPropertyValue; -import com.evolveum.midpoint.prism.PrismReferenceValue; +import com.evolveum.midpoint.prism.*; import com.evolveum.midpoint.prism.match.MatchingRule; import com.evolveum.midpoint.prism.match.MatchingRuleRegistry; import com.evolveum.midpoint.prism.path.ItemPath; -import com.evolveum.midpoint.util.DebugUtil; import com.evolveum.midpoint.util.exception.SchemaException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -34,16 +27,20 @@ import javax.xml.namespace.QName; import java.util.Iterator; import java.util.List; +import java.util.Objects; import java.util.Set; import java.util.regex.Pattern; -public class SubstringFilter extends PropertyValueFilter> { +public class SubstringFilter extends PropertyValueFilter { private boolean anchorStart; private boolean anchorEnd; - SubstringFilter(ItemPath parentPath, ItemDefinition definition, QName matchingRule, List> values, boolean anchorStart, boolean anchorEnd) { - super(parentPath, definition, matchingRule, values); + public SubstringFilter(@NotNull ItemPath path, @Nullable PrismPropertyDefinition definition, + @Nullable QName matchingRule, + @Nullable List> prismPropertyValues, + @Nullable ExpressionWrapper expression, boolean anchorStart, boolean anchorEnd) { + super(path, definition, matchingRule, prismPropertyValues, expression, null, null); this.anchorStart = anchorStart; this.anchorEnd = anchorEnd; } @@ -52,13 +49,13 @@ public class SubstringFilter extends PropertyValueFilter SubstringFilter createSubstring(@NotNull ItemPath path, @Nullable PrismPropertyDefinition itemDefinition, @NotNull PrismContext prismContext, - @Nullable QName matchingRule, Object value, boolean anchorStart, boolean anchorEnd) { - List> pValues = createPropertyListFromValue(prismContext, value); - return new SubstringFilter(path, itemDefinition, matchingRule, pValues, anchorStart, anchorEnd); + @Nullable QName matchingRule, Object anyValue, boolean anchorStart, boolean anchorEnd) { + List> values = anyValueToPropertyValueList(prismContext, anyValue); + return new SubstringFilter<>(path, itemDefinition, matchingRule, values, null, anchorStart, anchorEnd); } // TODO expression based substring filter @@ -73,40 +70,17 @@ public boolean isAnchorEnd() { @Override public SubstringFilter clone() { - return new SubstringFilter<>(getFullPath(), getDefinition(), getMatchingRule(), getCloneValuesList(), anchorStart, anchorEnd); + return new SubstringFilter<>(getFullPath(), getDefinition(), getMatchingRule(), getClonedValues(), + getExpression(), anchorStart, anchorEnd); } @Override - public String debugDump() { - return debugDump(0); - } - - @Override - public String debugDump(int indent) { - StringBuilder sb = new StringBuilder(); - DebugUtil.indentDebugDump(sb, indent); - sb.append("SUBSTRING:"); - if (anchorStart) { - sb.append(" anchorStart"); - } - if (anchorEnd) { - sb.append(" anchorEnd"); - } - return debugDump(indent, sb); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("SUBSTRING: "); - String rv = toString(sb); - if (anchorStart) { - rv += ",S"; - } - if (anchorEnd) { - rv += ",E"; - } - return rv; + protected String getFilterName() { + return "SUBSTRING(" + + (anchorStart ? "S" : "") + + (anchorStart && anchorEnd ? "," : "") + + (anchorEnd ? "E" : "") + + ")"; } @Override @@ -145,21 +119,6 @@ public boolean match(PrismContainerValue containerValue, MatchingRuleRegistry ma private Set toRealValues(){ return PrismPropertyValue.getRealValuesOfCollection(getValues()); } - - @Override - public PrismContext getPrismContext() { - return getDefinition().getPrismContext(); - } - - @Override - public ItemPath getPath() { - return getFullPath(); - } - - @Override - public PrismPropertyDefinition getDefinition() { - return (PrismPropertyDefinition) super.getDefinition(); - } @Override public boolean equals(Object o, boolean exact) { @@ -169,20 +128,13 @@ public boolean equals(Object o, boolean exact) { return false; if (!super.equals(o, exact)) return false; - SubstringFilter that = (SubstringFilter) o; - - if (anchorStart != that.anchorStart) - return false; - return anchorEnd == that.anchorEnd; - + return anchorStart == that.anchorStart && + anchorEnd == that.anchorEnd; } @Override public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (anchorStart ? 1 : 0); - result = 31 * result + (anchorEnd ? 1 : 0); - return result; + return Objects.hash(super.hashCode(), anchorStart, anchorEnd); } } diff --git a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/TypeFilter.java b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/TypeFilter.java index 49b98cc0154..56b0a76a086 100644 --- a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/TypeFilter.java +++ b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/TypeFilter.java @@ -24,6 +24,7 @@ import com.evolveum.midpoint.util.exception.SchemaException; import com.evolveum.midpoint.util.logging.Trace; import com.evolveum.midpoint.util.logging.TraceManager; +import org.jetbrains.annotations.NotNull; import javax.xml.namespace.QName; @@ -34,14 +35,15 @@ public class TypeFilter extends ObjectFilter { private static final Trace LOGGER = TraceManager.getTrace(TypeFilter.class); - private QName type; + @NotNull private final QName type; private ObjectFilter filter; - public TypeFilter(QName type, ObjectFilter filter) { + public TypeFilter(@NotNull QName type, ObjectFilter filter) { this.type = type; this.filter = filter; } + @NotNull public QName getType() { return type; } @@ -58,6 +60,7 @@ public static TypeFilter createType(QName type, ObjectFilter filter) { return new TypeFilter(type, filter); } + @SuppressWarnings("CloneDoesntCallSuperClone") @Override public ObjectFilter clone() { ObjectFilter f = filter != null ? filter.clone() : null; @@ -134,7 +137,7 @@ public boolean equals(Object o, boolean exact) { TypeFilter that = (TypeFilter) o; - if (type != null ? !type.equals(that.type) : that.type != null) return false; + if (!type.equals(that.type)) return false; if (filter != null ? !filter.equals(that.filter, exact) : that.filter != null) return false; return true; @@ -142,7 +145,7 @@ public boolean equals(Object o, boolean exact) { @Override public int hashCode() { - return type != null ? type.hashCode() : 0; + return type.hashCode(); } @Override diff --git a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/UnaryLogicalFilter.java b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/UnaryLogicalFilter.java index 1fab9414c2b..37c0a76b00a 100644 --- a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/UnaryLogicalFilter.java +++ b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/UnaryLogicalFilter.java @@ -21,15 +21,10 @@ public abstract class UnaryLogicalFilter extends LogicalFilter { - public UnaryLogicalFilter() { + UnaryLogicalFilter() { super(); } - public UnaryLogicalFilter(ObjectFilter condition) { - super(); - setFilter(condition); - } - public ObjectFilter getFilter() { if (conditions == null) { return null; @@ -45,7 +40,7 @@ public ObjectFilter getFilter() { } public void setFilter(ObjectFilter filter){ - conditions = new ArrayList(); + conditions = new ArrayList<>(); conditions.add(filter); } diff --git a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/ValueFilter.java b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/ValueFilter.java index 29a5b633d03..e3a1b41f536 100644 --- a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/ValueFilter.java +++ b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/ValueFilter.java @@ -16,69 +16,70 @@ package com.evolveum.midpoint.prism.query; -import com.evolveum.midpoint.prism.ComplexTypeDefinition; -import com.evolveum.midpoint.prism.Containerable; -import com.evolveum.midpoint.prism.Item; -import com.evolveum.midpoint.prism.ItemDefinition; -import com.evolveum.midpoint.prism.PrismContainerDefinition; -import com.evolveum.midpoint.prism.PrismContext; -import com.evolveum.midpoint.prism.PrismValue; +import com.evolveum.midpoint.prism.*; import com.evolveum.midpoint.prism.match.MatchingRule; import com.evolveum.midpoint.prism.match.MatchingRuleRegistry; 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.util.DebugUtil; +import com.evolveum.midpoint.util.MiscUtil; import com.evolveum.midpoint.util.exception.SchemaException; import org.apache.commons.lang.Validate; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.xml.namespace.QName; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; -public abstract class ValueFilter extends ObjectFilter { +public abstract class ValueFilter extends ObjectFilter implements Itemable { private static final long serialVersionUID = 1L; @NotNull private final ItemPath fullPath; - /** - * Definition is not required and not final, because it can be filled-in after creation of the filter (e.g. in provisioning) - */ - @Nullable private ItemDefinition definition; + @Nullable private D definition; // not required, because it can be filled-in after creation of the filter (e.g. in provisioning) @Nullable private QName matchingRule; + @Nullable private List values; + @Nullable private ExpressionWrapper expression; + @Nullable private ItemPath rightHandSidePath; // alternative to values/expression; can be provided later + @Nullable private ItemDefinition rightHandSideDefinition; // optional (needed only if path points to dynamically defined item) + + // At most one of values, expression, rightHandSidePath can be non-null. + // It is a responsibility of the client to ensure it. - // path is not empty - protected ValueFilter(@NotNull ItemPath fullPath, @Nullable ItemDefinition definition) { - this(fullPath, definition, null); + /** + * TODO decide whether to make these fields final. It makes the code simpler, but maybe not that much + * that it is worth the discomfort of the clients (they cannot change they if the would wish). + * Some of them like definition, matchingRule, and right-hand things are filled-in later in some cases (provisioning, query builder). + */ + protected ValueFilter(@NotNull ItemPath fullPath, @Nullable D definition) { + this(fullPath, definition, null, null, null, null, null); } - protected ValueFilter(@NotNull ItemPath fullPath, @Nullable ItemDefinition definition, @Nullable QName matchingRule) { + protected ValueFilter(@NotNull ItemPath fullPath, @Nullable D definition, @Nullable QName matchingRule, + @Nullable List values, @Nullable ExpressionWrapper expression, + @Nullable ItemPath rightHandSidePath, @Nullable ItemDefinition rightHandSideDefinition) { Validate.isTrue(!ItemPath.isNullOrEmpty(fullPath), "path in filter is null or empty"); this.fullPath = fullPath; this.definition = definition; this.matchingRule = matchingRule; - } - - @Nullable - public ItemDefinition getDefinition() { - return definition; + this.expression = expression; + this.values = values; + this.rightHandSidePath = rightHandSidePath; + this.rightHandSideDefinition = rightHandSideDefinition; + if (values != null) { + for (V value : values) { + value.setParent(this); + } + } + checkConsistence(false); } - public void setDefinition(@Nullable ItemDefinition definition) { - this.definition = definition; - } - @NotNull public ItemPath getFullPath() { return fullPath; } - - @Nullable - public QName getMatchingRule() { - return matchingRule; - } - - public void setMatchingRule(@Nullable QName matchingRule) { - this.matchingRule = matchingRule; - } @NotNull public ItemPath getParentPath() { @@ -99,8 +100,26 @@ public QName getElementName() { throw new IllegalStateException("Got "+lastPathSegement+" as a last path segment in value filter "+this); } } + + @Nullable + public D getDefinition() { + return definition; + } + + public void setDefinition(@Nullable D definition) { + this.definition = definition; + } - protected MatchingRule getMatchingRuleFromRegistry(MatchingRuleRegistry matchingRuleRegistry, Item filterItem) { + @Nullable + public QName getMatchingRule() { + return matchingRule; + } + + public void setMatchingRule(@Nullable QName matchingRule) { + this.matchingRule = matchingRule; + } + + MatchingRule getMatchingRuleFromRegistry(MatchingRuleRegistry matchingRuleRegistry, Item filterItem) { try { return matchingRuleRegistry.getMatchingRule(matchingRule, filterItem.getDefinition().getTypeName()); } catch (SchemaException ex){ @@ -108,49 +127,332 @@ protected MatchingRule getMatchingRuleFromRegistry(MatchingRuleRegistry matching } } - public abstract boolean isRaw(); - + @Nullable + public List getValues() { + return values; + } + + @Nullable + List getClonedValues() { + if (values == null) { + return null; + } else { + List clonedValues = new ArrayList<>(values.size()); + for (V value : values) { + @SuppressWarnings("unchecked") + V cloned = (V) value.clone(); + clonedValues.add(cloned); + } + return clonedValues; + } + } + + @Nullable + V getClonedValue() { + V value = getSingleValue(); + if (value == null) { + return null; + } else { + @SuppressWarnings("unchecked") + V cloned = (V) value.clone(); + return cloned; + } + } + + @Nullable + public V getSingleValue() { + if (values == null || values.isEmpty()) { + return null; + } else if (values.size() > 1) { + throw new IllegalArgumentException("Filter '" + this + "' should contain at most one value, but it has " + values.size() + " of them."); + } else { + return values.iterator().next(); + } + } + + /** + * @pre value has to be parent-less + */ + public void setValue(V value) { + this.values = new ArrayList<>(); + if (value != null) { + value.setParent(this); + values.add(value); + } + } + + @Nullable + public ExpressionWrapper getExpression() { + return expression; + } + + public void setExpression(@Nullable ExpressionWrapper expression) { + this.expression = expression; + } + + @Nullable + public ItemPath getRightHandSidePath() { + return rightHandSidePath; + } + + public void setRightHandSidePath(@Nullable ItemPath rightHandSidePath) { + this.rightHandSidePath = rightHandSidePath; + } + + @Nullable + public ItemDefinition getRightHandSideDefinition() { + return rightHandSideDefinition; + } + + public void setRightHandSideDefinition(@Nullable ItemDefinition rightHandSideDefinition) { + this.rightHandSideDefinition = rightHandSideDefinition; + } + + @Override + public PrismContext getPrismContext() { + D def = getDefinition(); + if (def == null) { + return null; + } + return def.getPrismContext(); + } + + @Override + public ItemPath getPath() { + return getFullPath(); + } + + public boolean isRaw() { + if (values != null) { + for (V value: values) { + if (value.isRaw()) { + return true; + } + } + } + return false; + } + + // TODO revise + @Override + public boolean match(PrismContainerValue cvalue, MatchingRuleRegistry matchingRuleRegistry) throws SchemaException { + + Item item = getObjectItem(cvalue); + + boolean filterItemIsEmpty = getValues() == null || getValues().isEmpty(); + boolean objectItemIsEmpty = item == null || item.isEmpty(); + + if (filterItemIsEmpty && !objectItemIsEmpty) { + return false; + } + + if (!filterItemIsEmpty && objectItemIsEmpty) { + return false; + } + + return true; + } + + // TODO revise + Item getObjectItem(PrismContainerValue value) { + ItemPath path = getFullPath(); + return value.findItem(path); + } + + // TODO revise + Item getFilterItem() throws SchemaException { + + if (getDefinition() == null){ + throw new SchemaException("Could not find definition for item " + getPath()); + } + Item filterItem = getDefinition().instantiate(); + if (getValues() != null && !getValues().isEmpty()) { + try { + for (PrismValue v : getValues()){ + filterItem.add(v.clone()); + } + } catch (SchemaException e) { + throw new IllegalArgumentException(e.getMessage(), e); + } + } + + return filterItem; + } + @Override public void checkConsistence(boolean requireDefinitions) { if (requireDefinitions && definition == null) { throw new IllegalArgumentException("Null definition in "+this); } + if (fullPath.isEmpty()) { + throw new IllegalArgumentException("Empty path in "+this); + } + if (rightHandSidePath != null && rightHandSidePath.isEmpty()) { + throw new IllegalArgumentException("Not-null but empty right side path in "+this); + } + int count = 0; + if (values != null) { + count++; + } + if (expression != null) { + count++; + } + if (rightHandSidePath != null) { + count++; + } + if (count > 1) { + throw new IllegalStateException("Two or more of the following are non-null: values (" + values + + "), expression (" + expression + "), rightHandSidePath (" + rightHandSidePath + ") in " + this); + } + if (values != null) { + for (V value: values) { + if (value == null) { + throw new IllegalArgumentException("Null value in "+this); + } + if (value.getParent() != this) { + throw new IllegalArgumentException("Value "+value+" in "+this+" has a bad parent "+value.getParent()); + } + if (value.isEmpty() && !value.isRaw()) { + throw new IllegalArgumentException("Empty value in "+this); + } + } + } } @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((definition == null) ? 0 : definition.hashCode()); - result = prime * result + fullPath.hashCode(); - result = prime * result + ((matchingRule == null) ? 0 : matchingRule.hashCode()); - return result; + public abstract ValueFilter clone(); + + @SuppressWarnings("EqualsWhichDoesntCheckParameterClass") + @Override + public boolean equals(Object o) { + return equals(o, true); } @Override - public boolean equals(Object obj, boolean exact) { - if (this == obj) + public boolean equals(Object o, boolean exact) { + if (this == o) return true; - if (obj == null) + if (o == null || getClass() != o.getClass()) return false; - if (getClass() != obj.getClass()) - return false; - ValueFilter other = (ValueFilter) obj; - if (exact) { - if (definition == null) { - if (other.definition != null) - return false; - } else if (!definition.equals(other.definition)) - return false; - } - if (!fullPath.equals(other.fullPath, exact)) - return false; - if (matchingRule == null) { - if (other.matchingRule != null) - return false; - } else if (!matchingRule.equals(other.matchingRule)) - return false; - return true; + ValueFilter that = (ValueFilter) o; + return fullPath.equals(that.fullPath, exact) && + (!exact || Objects.equals(definition, that.definition)) && + Objects.equals(matchingRule, that.matchingRule) && + MiscUtil.nullableCollectionsEqual(values, that.values) && + Objects.equals(expression, that.expression) && + (rightHandSidePath == null && that.rightHandSidePath == null || + rightHandSidePath != null && rightHandSidePath.equals(that.rightHandSidePath, exact)) && + (!exact || Objects.equals(rightHandSideDefinition, that.rightHandSideDefinition)); } - + + @Override + public int hashCode() { + return Objects.hash(fullPath, matchingRule, values, expression, rightHandSidePath); + } + + @Override + public String debugDump() { + return debugDump(0); + } + + @Override + public String debugDump(int indent) { + StringBuilder sb = new StringBuilder(); + DebugUtil.indentDebugDump(sb, indent); + sb.append(getFilterName()).append(":"); + return debugDump(indent, sb); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getFilterName()).append(": "); + return toString(sb); + } + + protected abstract String getFilterName(); + + protected String debugDump(int indent, StringBuilder sb) { + sb.append("\n"); + DebugUtil.indentDebugDump(sb, indent+1); + sb.append("PATH: "); + sb.append(getFullPath().toString()); + + sb.append("\n"); + DebugUtil.indentDebugDump(sb, indent+1); + sb.append("DEF: "); + if (getDefinition() != null) { + sb.append(getDefinition().toString()); + } else { + sb.append("null"); + } + + List values = getValues(); + if (values != null) { + sb.append("\n"); + DebugUtil.indentDebugDump(sb, indent+1); + sb.append("VALUE:"); + sb.append("\n"); + for (PrismValue val : getValues()) { + sb.append(DebugUtil.debugDump(val, indent + 2)); + } + } + + ExpressionWrapper expression = getExpression(); + if (expression != null && expression.getExpression() != null) { + sb.append("\n"); + DebugUtil.indentDebugDump(sb, indent+1); + sb.append("EXPRESSION:"); + sb.append("\n"); + sb.append(DebugUtil.debugDump(expression.getExpression(), indent + 2)); + } + + if (getRightHandSidePath() != null) { + sb.append("\n"); + DebugUtil.indentDebugDump(sb, indent+1); + sb.append("RIGHT SIDE PATH: "); + sb.append(getFullPath().toString()); + sb.append("\n"); + DebugUtil.indentDebugDump(sb, indent+1); + sb.append("RIGHT SIDE DEF: "); + if (getRightHandSideDefinition() != null) { + sb.append(getRightHandSideDefinition().toString()); + } else { + sb.append("null"); + } + } + + QName matchingRule = getMatchingRule(); + if (matchingRule != null) { + sb.append("\n"); + DebugUtil.indentDebugDump(sb, indent+1); + sb.append("MATCHING: "); + sb.append(matchingRule); + } + + return sb.toString(); + } + + protected String toString(StringBuilder sb){ + sb.append(getFullPath().toString()); + sb.append(","); + if (getValues() != null){ + for (int i = 0; i< getValues().size() ; i++){ + PrismValue value = getValues().get(i); + if (value == null) { + sb.append("null"); + } else { + sb.append(value.toString()); + } + if ( i != getValues().size() -1){ + sb.append(","); + } + } + } + if (getRightHandSidePath() != null) { + sb.append(getRightHandSidePath()); + } + return sb.toString(); + } + } diff --git a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/builder/R_AtomicFilter.java b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/builder/R_AtomicFilter.java index 1fadc0bfa8c..b5f79796dad 100644 --- a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/builder/R_AtomicFilter.java +++ b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/builder/R_AtomicFilter.java @@ -23,14 +23,7 @@ import com.evolveum.midpoint.prism.match.StringIgnoreCaseMatchingRule; import com.evolveum.midpoint.prism.path.ItemPath; import com.evolveum.midpoint.prism.polystring.PolyString; -import com.evolveum.midpoint.prism.query.EqualFilter; -import com.evolveum.midpoint.prism.query.GreaterFilter; -import com.evolveum.midpoint.prism.query.LessFilter; -import com.evolveum.midpoint.prism.query.ObjectFilter; -import com.evolveum.midpoint.prism.query.ObjectQuery; -import com.evolveum.midpoint.prism.query.PropertyValueFilter; -import com.evolveum.midpoint.prism.query.RefFilter; -import com.evolveum.midpoint.prism.query.SubstringFilter; +import com.evolveum.midpoint.prism.query.*; import org.apache.commons.lang.Validate; @@ -47,7 +40,7 @@ public class R_AtomicFilter implements S_ConditionEntry, S_MatchingRuleEntry, S_ final ItemPath itemPath; final PrismPropertyDefinition propertyDefinition; final PrismReferenceDefinition referenceDefinition; - final PropertyValueFilter filter; + final ValueFilter filter; final R_Filter owner; final boolean expectingRightSide; @@ -70,7 +63,7 @@ public class R_AtomicFilter implements S_ConditionEntry, S_MatchingRuleEntry, S_ this.expectingRightSide = false; } - R_AtomicFilter(R_AtomicFilter original, PropertyValueFilter filter, boolean expectingRightSide) { + R_AtomicFilter(R_AtomicFilter original, ValueFilter filter, boolean expectingRightSide) { Validate.notNull(original); Validate.notNull(filter); this.itemPath = original.itemPath; @@ -81,7 +74,7 @@ public class R_AtomicFilter implements S_ConditionEntry, S_MatchingRuleEntry, S_ this.expectingRightSide = expectingRightSide; } - public R_AtomicFilter(R_AtomicFilter original, PropertyValueFilter filter) { + public R_AtomicFilter(R_AtomicFilter original, ValueFilter filter) { this(original, filter, false); } @@ -102,7 +95,7 @@ public S_AtomicFilterExit item(ItemPath itemPath, ItemDefinition itemDefinition) if (filter == null) { throw new IllegalStateException("item() call with no filter"); } - PropertyValueFilter newFilter = filter.clone(); + ValueFilter newFilter = filter.clone(); newFilter.setRightHandSidePath(itemPath); newFilter.setRightHandSideDefinition(itemDefinition); return new R_AtomicFilter(this, newFilter); @@ -124,57 +117,57 @@ public S_MatchingRuleEntry eq(Object... values) { @Override public S_RightHandItemEntry eq() { - return new R_AtomicFilter(this, EqualFilter.createEqual(itemPath, propertyDefinition, null, owner.getPrismContext()), true); + return new R_AtomicFilter(this, EqualFilter.createEqual(itemPath, propertyDefinition, null), true); } @Override public S_MatchingRuleEntry eqPoly(String orig, String norm) { - return new R_AtomicFilter(this, EqualFilter.createEqual(itemPath, propertyDefinition, null, owner.getPrismContext(), new PolyString(orig, norm))); + return eq(new PolyString(orig, norm)); } @Override public S_MatchingRuleEntry eqPoly(String orig) { - return new R_AtomicFilter(this, EqualFilter.createEqual(itemPath, propertyDefinition, null, owner.getPrismContext(), new PolyString(orig))); + return eq(new PolyString(orig)); } @Override public S_MatchingRuleEntry gt(Object value) { - return new R_AtomicFilter(this, GreaterFilter.createGreater(itemPath, propertyDefinition, value, false)); + return new R_AtomicFilter(this, GreaterFilter.createGreater(itemPath, propertyDefinition, false, owner.getPrismContext(), value)); } @Override public S_RightHandItemEntry gt() { - return new R_AtomicFilter(this, GreaterFilter.createGreater(itemPath, propertyDefinition, null, false), true); + return new R_AtomicFilter(this, GreaterFilter.createGreater(itemPath, propertyDefinition, false), true); } @Override public S_MatchingRuleEntry ge(Object value) { - return new R_AtomicFilter(this, GreaterFilter.createGreater(itemPath, propertyDefinition, value, true)); + return new R_AtomicFilter(this, GreaterFilter.createGreater(itemPath, propertyDefinition, true, owner.getPrismContext(), value)); } @Override public S_RightHandItemEntry ge() { - return new R_AtomicFilter(this, GreaterFilter.createGreater(itemPath, propertyDefinition, null, true), true); + return new R_AtomicFilter(this, GreaterFilter.createGreater(itemPath, propertyDefinition, true), true); } @Override public S_MatchingRuleEntry lt(Object value) { - return new R_AtomicFilter(this, LessFilter.createLess(itemPath, propertyDefinition, value, false)); + return new R_AtomicFilter(this, LessFilter.createLess(itemPath, propertyDefinition, owner.getPrismContext(), value, false)); } @Override public S_RightHandItemEntry lt() { - return new R_AtomicFilter(this, LessFilter.createLess(itemPath, propertyDefinition, null, false), true); + return new R_AtomicFilter(this, LessFilter.createLess(itemPath, propertyDefinition, false), true); } @Override public S_MatchingRuleEntry le(Object value) { - return new R_AtomicFilter(this, LessFilter.createLess(itemPath, propertyDefinition, value, true)); + return new R_AtomicFilter(this, LessFilter.createLess(itemPath, propertyDefinition, owner.getPrismContext(), value, true)); } @Override public S_RightHandItemEntry le() { - return new R_AtomicFilter(this, LessFilter.createLess(itemPath, propertyDefinition, null, true), true); + return new R_AtomicFilter(this, LessFilter.createLess(itemPath, propertyDefinition, true), true); } @Override @@ -224,7 +217,7 @@ public S_MatchingRuleEntry containsPoly(String orig) { @Override public S_AtomicFilterExit ref(PrismReferenceValue value) { - return ref(Collections.singleton(value)); + return ref(value != null ? Collections.singleton(value) : Collections.emptyList()); } @Override @@ -234,12 +227,16 @@ public S_AtomicFilterExit ref(Collection values) { @Override public S_AtomicFilterExit ref(String oid) { - return ref(new PrismReferenceValue(oid)); + return ref(oid != null ? new PrismReferenceValue(oid) : null); } @Override public S_AtomicFilterExit ref(String oid, QName targetTypeName) { - return ref(new PrismReferenceValue(oid, targetTypeName)); + if (oid != null) { + return ref(new PrismReferenceValue(oid, targetTypeName)); + } else { + return ref((PrismReferenceValue) null); + } } @Override @@ -255,7 +252,7 @@ public S_AtomicFilterExit isNull() { @Override public S_AtomicFilterExit matching(QName matchingRuleName) { - PropertyValueFilter clone = filter.clone(); + ValueFilter clone = filter.clone(); clone.setMatchingRule(matchingRuleName); return new R_AtomicFilter(this, clone); } diff --git a/infra/prism/src/test/java/com/evolveum/midpoint/prism/query/TestQueryBuilder.java b/infra/prism/src/test/java/com/evolveum/midpoint/prism/query/TestQueryBuilder.java index ba3286e3faa..26043954d29 100644 --- a/infra/prism/src/test/java/com/evolveum/midpoint/prism/query/TestQueryBuilder.java +++ b/infra/prism/src/test/java/com/evolveum/midpoint/prism/query/TestQueryBuilder.java @@ -511,7 +511,7 @@ public void test310LessThanItem() throws Exception { .item(new ItemPath(UserType.F_NAME), nameDef) .build(); ObjectQuery expected = ObjectQuery.createObjectQuery( - LessFilter.createLessThanItem( + LessFilter.createLess( new ItemPath(UserType.F_LOCALITY), localityDef, new ItemPath(UserType.F_NAME), diff --git a/infra/schema/src/main/java/com/evolveum/midpoint/schema/util/ObjectQueryUtil.java b/infra/schema/src/main/java/com/evolveum/midpoint/schema/util/ObjectQueryUtil.java index 330bd9e5851..e3d6c4e341e 100644 --- a/infra/schema/src/main/java/com/evolveum/midpoint/schema/util/ObjectQueryUtil.java +++ b/infra/schema/src/main/java/com/evolveum/midpoint/schema/util/ObjectQueryUtil.java @@ -175,8 +175,7 @@ public static ObjectQuery createNameQuery(Class clazz, } public static ObjectQuery createRootOrgQuery(PrismContext prismContext) throws SchemaException { - ObjectQuery objectQuery = ObjectQuery.createObjectQuery(OrgFilter.createRootOrg()); - return objectQuery; + return QueryBuilder.queryFor(ObjectType.class, prismContext).isRoot().build(); } public static boolean hasAllDefinitions(ObjectQuery query) { @@ -190,7 +189,7 @@ public static boolean hasAllDefinitions(ObjectFilter filter) { @Override public void visit(ObjectFilter filter) { if (filter instanceof ValueFilter) { - ItemDefinition definition = ((ValueFilter)filter).getDefinition(); + ItemDefinition definition = ((ValueFilter)filter).getDefinition(); if (definition == null) { hasAllDefinitions.setValue(false); } diff --git a/infra/util/src/main/java/com/evolveum/midpoint/util/MiscUtil.java b/infra/util/src/main/java/com/evolveum/midpoint/util/MiscUtil.java index 96c5d5f658f..6494e202d5d 100644 --- a/infra/util/src/main/java/com/evolveum/midpoint/util/MiscUtil.java +++ b/infra/util/src/main/java/com/evolveum/midpoint/util/MiscUtil.java @@ -517,4 +517,16 @@ public static void addIfNotPresent(List receivingList, T supplyingElement receivingList.add(supplyingElement); } } + + public static boolean nullableCollectionsEqual(Collection c1, Collection c2) { + boolean empty1 = c1 == null || c1.isEmpty(); + boolean empty2 = c2 == null || c2.isEmpty(); + if (empty1) { + return empty2; + } else if (empty2) { + return false; + } else { + return c1.equals(c2); + } + } } diff --git a/model/model-common/src/main/java/com/evolveum/midpoint/model/common/expression/ExpressionUtil.java b/model/model-common/src/main/java/com/evolveum/midpoint/model/common/expression/ExpressionUtil.java index 883a59626b3..197d641d3b8 100644 --- a/model/model-common/src/main/java/com/evolveum/midpoint/model/common/expression/ExpressionUtil.java +++ b/model/model-common/src/main/java/com/evolveum/midpoint/model/common/expression/ExpressionUtil.java @@ -567,7 +567,7 @@ private static ObjectFilter evaluateFilterExpressionsInternal(ObjectFilter filte LOGGER.trace("Search filter expression in the rule for {} evaluated to {}.", new Object[] { shortDesc, expressionResult }); - PropertyValueFilter evaluatedFilter = (PropertyValueFilter) pvfilter.clone(); + ValueFilter evaluatedFilter = pvfilter.clone(); evaluatedFilter.setValue(expressionResult); evaluatedFilter.setExpression(null); // } diff --git a/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/sync/ReconciliationTaskHandler.java b/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/sync/ReconciliationTaskHandler.java index 37b52beb9c5..b1581c61da7 100644 --- a/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/sync/ReconciliationTaskHandler.java +++ b/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/sync/ReconciliationTaskHandler.java @@ -15,17 +15,6 @@ */ package com.evolveum.midpoint.model.impl.sync; -import java.util.Collection; -import java.util.List; - -import javax.annotation.PostConstruct; -import javax.xml.namespace.QName; - -import com.evolveum.midpoint.prism.query.builder.QueryBuilder; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Component; - import com.evolveum.midpoint.audit.api.AuditEventRecord; import com.evolveum.midpoint.audit.api.AuditEventStage; import com.evolveum.midpoint.audit.api.AuditEventType; @@ -37,20 +26,12 @@ import com.evolveum.midpoint.model.impl.util.Utils; import com.evolveum.midpoint.prism.PrismContext; import com.evolveum.midpoint.prism.PrismObject; -import com.evolveum.midpoint.prism.PrismObjectDefinition; import com.evolveum.midpoint.prism.delta.ChangeType; import com.evolveum.midpoint.prism.delta.ItemDelta; import com.evolveum.midpoint.prism.delta.ObjectDelta; import com.evolveum.midpoint.prism.delta.PropertyDelta; -import com.evolveum.midpoint.prism.path.ItemPath; -import com.evolveum.midpoint.prism.query.AndFilter; -import com.evolveum.midpoint.prism.query.EqualFilter; -import com.evolveum.midpoint.prism.query.LessFilter; -import com.evolveum.midpoint.prism.query.NotFilter; -import com.evolveum.midpoint.prism.query.ObjectFilter; import com.evolveum.midpoint.prism.query.ObjectQuery; -import com.evolveum.midpoint.prism.query.OrFilter; -import com.evolveum.midpoint.prism.query.RefFilter; +import com.evolveum.midpoint.prism.query.builder.QueryBuilder; import com.evolveum.midpoint.prism.xml.XmlTypeConverter; import com.evolveum.midpoint.provisioning.api.ChangeNotificationDispatcher; import com.evolveum.midpoint.provisioning.api.ProvisioningOperationOptions; @@ -68,29 +49,26 @@ import com.evolveum.midpoint.schema.result.OperationResultStatus; import com.evolveum.midpoint.schema.util.ObjectTypeUtil; import com.evolveum.midpoint.schema.util.ShadowUtil; -import com.evolveum.midpoint.task.api.Task; -import com.evolveum.midpoint.task.api.TaskCategory; -import com.evolveum.midpoint.task.api.TaskHandler; -import com.evolveum.midpoint.task.api.TaskManager; -import com.evolveum.midpoint.task.api.TaskRunResult; +import com.evolveum.midpoint.task.api.*; import com.evolveum.midpoint.task.api.TaskRunResult.TaskRunResultStatus; import com.evolveum.midpoint.util.Holder; import com.evolveum.midpoint.util.QNameUtil; -import com.evolveum.midpoint.util.exception.CommunicationException; -import com.evolveum.midpoint.util.exception.ConfigurationException; -import com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException; -import com.evolveum.midpoint.util.exception.ObjectNotFoundException; -import com.evolveum.midpoint.util.exception.SchemaException; -import com.evolveum.midpoint.util.exception.SecurityViolationException; +import com.evolveum.midpoint.util.exception.*; import com.evolveum.midpoint.util.logging.LoggingUtils; import com.evolveum.midpoint.util.logging.Trace; import com.evolveum.midpoint.util.logging.TraceManager; -import com.evolveum.midpoint.xml.ns._public.common.common_3.FailedOperationTypeType; import com.evolveum.midpoint.xml.ns._public.common.common_3.LayerType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType; import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType; import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType; import com.evolveum.prism.xml.ns._public.types_3.PolyStringType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import javax.xml.namespace.QName; +import java.util.Collection; +import java.util.List; /** * The task hander for reconciliation. diff --git a/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/trigger/TriggerScannerTaskHandler.java b/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/trigger/TriggerScannerTaskHandler.java index fe8eadb3260..02ecf04496f 100644 --- a/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/trigger/TriggerScannerTaskHandler.java +++ b/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/trigger/TriggerScannerTaskHandler.java @@ -24,7 +24,6 @@ import com.evolveum.midpoint.prism.delta.ContainerDelta; import com.evolveum.midpoint.prism.delta.ItemDelta; import com.evolveum.midpoint.prism.path.ItemPath; -import com.evolveum.midpoint.prism.query.LessFilter; import com.evolveum.midpoint.prism.query.ObjectFilter; import com.evolveum.midpoint.prism.query.ObjectQuery; import com.evolveum.midpoint.prism.query.builder.QueryBuilder; @@ -129,8 +128,9 @@ protected ObjectQuery createQuery(AbstractScannerResultHandler handl PrismContainerDefinition triggerContainerDef = focusObjectDef.findContainerDefinition(F_TRIGGER); if (handler.getLastScanTimestamp() == null) { - filter = LessFilter.createLess(new ItemPath(F_TRIGGER, F_TIMESTAMP), focusObjectDef, - handler.getThisScanTimestamp(), true); + filter = QueryBuilder.queryFor(ObjectType.class, prismContext) + .item(F_TRIGGER, F_TIMESTAMP).le(handler.getThisScanTimestamp()) + .buildFilter(); } else { filter = QueryBuilder.queryFor(ObjectType.class, prismContext) .exists(F_TRIGGER) diff --git a/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/ReportManagerImpl.java b/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/ReportManagerImpl.java index 547c67e029c..d262e768f90 100644 --- a/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/ReportManagerImpl.java +++ b/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/ReportManagerImpl.java @@ -16,33 +16,6 @@ package com.evolveum.midpoint.report.impl; -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.InputStream; -import java.io.Serializable; -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.List; -import java.util.Map; - -import javax.annotation.PostConstruct; -import javax.xml.datatype.Duration; -import javax.xml.datatype.XMLGregorianCalendar; - -import net.sf.jasperreports.engine.JRException; -import net.sf.jasperreports.engine.JasperCompileManager; -import net.sf.jasperreports.engine.JasperReport; -import net.sf.jasperreports.engine.design.JasperDesign; -import net.sf.jasperreports.engine.xml.JRXmlLoader; - -import org.apache.commons.codec.binary.Base64; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - import com.evolveum.midpoint.model.api.ModelService; import com.evolveum.midpoint.model.api.context.ModelContext; import com.evolveum.midpoint.model.api.context.ModelElementContext; @@ -51,18 +24,12 @@ import com.evolveum.midpoint.model.api.hooks.HookOperationMode; import com.evolveum.midpoint.model.api.hooks.HookRegistry; import com.evolveum.midpoint.model.api.hooks.ReadHook; -import com.evolveum.midpoint.prism.Containerable; import com.evolveum.midpoint.prism.PrismContainer; -import com.evolveum.midpoint.prism.PrismContainerDefinition; import com.evolveum.midpoint.prism.PrismContext; import com.evolveum.midpoint.prism.PrismObject; -import com.evolveum.midpoint.prism.PrismProperty; -import com.evolveum.midpoint.prism.PrismPropertyDefinition; import com.evolveum.midpoint.prism.delta.ObjectDelta; -import com.evolveum.midpoint.prism.path.ItemPath; -import com.evolveum.midpoint.prism.query.LessFilter; import com.evolveum.midpoint.prism.query.ObjectQuery; -import com.evolveum.midpoint.prism.schema.PrismSchema; +import com.evolveum.midpoint.prism.query.builder.QueryBuilder; import com.evolveum.midpoint.prism.xml.XmlTypeConverter; import com.evolveum.midpoint.report.api.ReportManager; import com.evolveum.midpoint.schema.GetOperationOptions; @@ -70,27 +37,36 @@ import com.evolveum.midpoint.schema.result.OperationResult; import com.evolveum.midpoint.schema.result.OperationResultStatus; import com.evolveum.midpoint.schema.util.MiscSchemaUtil; -import com.evolveum.midpoint.schema.util.ParamsTypeUtil; import com.evolveum.midpoint.schema.util.ReportTypeUtil; import com.evolveum.midpoint.task.api.Task; import com.evolveum.midpoint.task.api.TaskManager; -import com.evolveum.midpoint.util.exception.CommunicationException; -import com.evolveum.midpoint.util.exception.ConfigurationException; -import com.evolveum.midpoint.util.exception.ObjectNotFoundException; -import com.evolveum.midpoint.util.exception.SchemaException; -import com.evolveum.midpoint.util.exception.SecurityViolationException; -import com.evolveum.midpoint.util.exception.SystemException; +import com.evolveum.midpoint.util.exception.*; import com.evolveum.midpoint.util.logging.LoggingUtils; import com.evolveum.midpoint.util.logging.Trace; import com.evolveum.midpoint.util.logging.TraceManager; -import com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.MetadataType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.ReportConfigurationType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.ReportOutputType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.ReportParameterType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.ReportType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.ThreadStopActionType; +import com.evolveum.midpoint.xml.ns._public.common.common_3.*; +import net.sf.jasperreports.engine.JRException; +import net.sf.jasperreports.engine.JasperCompileManager; +import net.sf.jasperreports.engine.JasperReport; +import net.sf.jasperreports.engine.design.JasperDesign; +import net.sf.jasperreports.engine.xml.JRXmlLoader; +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.annotation.PostConstruct; +import javax.xml.datatype.Duration; +import javax.xml.datatype.XMLGregorianCalendar; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.List; /** @@ -312,9 +288,9 @@ public void cleanupReports(CleanupPolicyType cleanupPolicy, OperationResult pare List> obsoleteReportOutputs = new ArrayList>(); try { - ObjectQuery obsoleteReportOutputsQuery = ObjectQuery.createObjectQuery(LessFilter.createLess( - new ItemPath(ReportOutputType.F_METADATA, MetadataType.F_CREATE_TIMESTAMP), - ReportOutputType.class, prismContext, timeXml, true)); + ObjectQuery obsoleteReportOutputsQuery = QueryBuilder.queryFor(ReportOutputType.class, prismContext) + .item(ReportOutputType.F_METADATA, MetadataType.F_CREATE_TIMESTAMP).le(timeXml) + .build(); obsoleteReportOutputs = modelService.searchObjects(ReportOutputType.class, obsoleteReportOutputsQuery, null, null, result); } catch (Exception e) { throw new SystemException("Couldn't get the list of obsolete report outputs: " + e.getMessage(), e); diff --git a/provisioning/provisioning-impl/src/main/java/com/evolveum/midpoint/provisioning/impl/ShadowCache.java b/provisioning/provisioning-impl/src/main/java/com/evolveum/midpoint/provisioning/impl/ShadowCache.java index a2f28a4be40..c1db5e0d61b 100644 --- a/provisioning/provisioning-impl/src/main/java/com/evolveum/midpoint/provisioning/impl/ShadowCache.java +++ b/provisioning/provisioning-impl/src/main/java/com/evolveum/midpoint/provisioning/impl/ShadowCache.java @@ -15,90 +15,35 @@ */ package com.evolveum.midpoint.provisioning.impl; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - -import javax.xml.namespace.QName; - -import com.evolveum.midpoint.prism.Item; -import com.evolveum.midpoint.schema.util.ObjectQueryUtil; - -import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.Validate; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; - import com.evolveum.midpoint.common.refinery.RefinedAssociationDefinition; -import com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition; import com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition; import com.evolveum.midpoint.common.refinery.ShadowDiscriminatorObjectDelta; -import com.evolveum.midpoint.prism.Containerable; -import com.evolveum.midpoint.prism.ItemDefinition; -import com.evolveum.midpoint.prism.PrismContainer; -import com.evolveum.midpoint.prism.PrismContainerDefinition; -import com.evolveum.midpoint.prism.PrismContainerValue; -import com.evolveum.midpoint.prism.PrismContext; -import com.evolveum.midpoint.prism.PrismObject; -import com.evolveum.midpoint.prism.PrismObjectDefinition; -import com.evolveum.midpoint.prism.PrismProperty; -import com.evolveum.midpoint.prism.PrismPropertyValue; -import com.evolveum.midpoint.prism.PrismValue; -import com.evolveum.midpoint.prism.Visitable; +import com.evolveum.midpoint.prism.*; import com.evolveum.midpoint.prism.Visitor; -import com.evolveum.midpoint.prism.delta.ChangeType; -import com.evolveum.midpoint.prism.delta.ContainerDelta; -import com.evolveum.midpoint.prism.delta.ItemDelta; -import com.evolveum.midpoint.prism.delta.ObjectDelta; -import com.evolveum.midpoint.prism.delta.PropertyDelta; +import com.evolveum.midpoint.prism.delta.*; import com.evolveum.midpoint.prism.match.MatchingRuleRegistry; import com.evolveum.midpoint.prism.path.IdItemPathSegment; import com.evolveum.midpoint.prism.path.ItemPath; import com.evolveum.midpoint.prism.path.NameItemPathSegment; -import com.evolveum.midpoint.prism.polystring.PolyString; -import com.evolveum.midpoint.prism.query.AndFilter; -import com.evolveum.midpoint.prism.query.EqualFilter; -import com.evolveum.midpoint.prism.query.NaryLogicalFilter; -import com.evolveum.midpoint.prism.query.ObjectFilter; -import com.evolveum.midpoint.prism.query.ObjectPaging; -import com.evolveum.midpoint.prism.query.ObjectQuery; -import com.evolveum.midpoint.prism.query.OrFilter; -import com.evolveum.midpoint.prism.query.RefFilter; -import com.evolveum.midpoint.prism.query.SubstringFilter; -import com.evolveum.midpoint.prism.query.ValueFilter; -import com.evolveum.midpoint.prism.util.PrismUtil; -import com.evolveum.midpoint.provisioning.api.ChangeNotificationDispatcher; -import com.evolveum.midpoint.provisioning.api.GenericConnectorException; -import com.evolveum.midpoint.provisioning.api.ProvisioningOperationOptions; -import com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription; -import com.evolveum.midpoint.provisioning.api.ResourceOperationDescription; +import com.evolveum.midpoint.prism.query.*; +import com.evolveum.midpoint.provisioning.api.*; import com.evolveum.midpoint.provisioning.consistency.api.ErrorHandler; import com.evolveum.midpoint.provisioning.consistency.api.ErrorHandler.FailedOperation; import com.evolveum.midpoint.provisioning.consistency.impl.ErrorHandlerFactory; import com.evolveum.midpoint.provisioning.ucf.api.Change; import com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance; import com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException; -import com.evolveum.midpoint.provisioning.ucf.api.PropertyModificationOperation; import com.evolveum.midpoint.provisioning.ucf.api.ResultHandler; import com.evolveum.midpoint.provisioning.util.ProvisioningUtil; import com.evolveum.midpoint.repo.api.RepositoryService; -import com.evolveum.midpoint.schema.DeltaConvertor; -import com.evolveum.midpoint.schema.GetOperationOptions; -import com.evolveum.midpoint.schema.ResourceShadowDiscriminator; -import com.evolveum.midpoint.schema.RetrieveOption; -import com.evolveum.midpoint.schema.SearchResultMetadata; -import com.evolveum.midpoint.schema.SelectorOptions; +import com.evolveum.midpoint.schema.*; import com.evolveum.midpoint.schema.constants.SchemaConstants; import com.evolveum.midpoint.schema.internals.InternalMonitor; import com.evolveum.midpoint.schema.internals.InternalsConfig; -import com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition; -import com.evolveum.midpoint.schema.processor.ResourceAttribute; -import com.evolveum.midpoint.schema.processor.ResourceAttributeContainer; -import com.evolveum.midpoint.schema.processor.ResourceAttributeContainerDefinition; -import com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition; +import com.evolveum.midpoint.schema.processor.*; import com.evolveum.midpoint.schema.result.OperationResult; import com.evolveum.midpoint.schema.result.OperationResultStatus; +import com.evolveum.midpoint.schema.util.ObjectQueryUtil; import com.evolveum.midpoint.schema.util.ObjectTypeUtil; import com.evolveum.midpoint.schema.util.SchemaDebugUtil; import com.evolveum.midpoint.schema.util.ShadowUtil; @@ -107,31 +52,23 @@ import com.evolveum.midpoint.util.DebugUtil; import com.evolveum.midpoint.util.Holder; import com.evolveum.midpoint.util.QNameUtil; -import com.evolveum.midpoint.util.exception.CommunicationException; -import com.evolveum.midpoint.util.exception.ConfigurationException; -import com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException; -import com.evolveum.midpoint.util.exception.ObjectNotFoundException; -import com.evolveum.midpoint.util.exception.SchemaException; -import com.evolveum.midpoint.util.exception.SecurityViolationException; -import com.evolveum.midpoint.util.exception.SystemException; -import com.evolveum.midpoint.util.exception.TunnelException; +import com.evolveum.midpoint.util.exception.*; import com.evolveum.midpoint.util.logging.Trace; import com.evolveum.midpoint.util.logging.TraceManager; -import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.AvailabilityStatusType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.FailedOperationTypeType; -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.OperationProvisioningScriptsType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAttributesType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType; +import com.evolveum.midpoint.xml.ns._public.common.common_3.*; import com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.CountObjectsCapabilityType; import com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.CountObjectsSimulateType; import com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType; import com.evolveum.prism.xml.ns._public.types_3.PolyStringType; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.Validate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; + +import javax.xml.namespace.QName; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; /** * Shadow cache is a facade that covers all the operations with shadows. It @@ -692,11 +629,10 @@ private void applyDefinition(final ProvisioningContext ctx, final ObjectQuery qu com.evolveum.midpoint.prism.query.Visitor visitor = new com.evolveum.midpoint.prism.query.Visitor() { @Override public void visit(ObjectFilter filter) { - if (filter instanceof ValueFilter) { - ValueFilter valueFilter = (ValueFilter) filter; + if (filter instanceof PropertyValueFilter) { + PropertyValueFilter valueFilter = (PropertyValueFilter) filter; ItemDefinition definition = valueFilter.getDefinition(); if (definition == null) { - ItemPath itemPath = valueFilter.getFullPath(); if (attributesPath.equivalent(valueFilter.getParentPath())) { QName attributeName = valueFilter.getElementName(); ResourceAttributeDefinition attributeDefinition = objectClassDefinition diff --git a/provisioning/provisioning-impl/src/main/java/com/evolveum/midpoint/provisioning/impl/ShadowManager.java b/provisioning/provisioning-impl/src/main/java/com/evolveum/midpoint/provisioning/impl/ShadowManager.java index 5d69a2cfcfa..37a52b2077c 100644 --- a/provisioning/provisioning-impl/src/main/java/com/evolveum/midpoint/provisioning/impl/ShadowManager.java +++ b/provisioning/provisioning-impl/src/main/java/com/evolveum/midpoint/provisioning/impl/ShadowManager.java @@ -713,10 +713,6 @@ private void processQueryMatchingRuleFilter(ObjectFilter filter, RefinedObje return; } MatchingRule matchingRule = matchingRuleRegistry.getMatchingRule(matchingRuleQName, rAttrDef.getTypeName()); - if (matchingRule == null) { - // TODO: warning? - return; - } List newValues = new ArrayList(); for (PrismPropertyValue ppval: eqFilter.getValues()) { T normalizedRealValue = matchingRule.normalize(ppval.getValue()); diff --git a/provisioning/provisioning-impl/src/main/java/com/evolveum/midpoint/provisioning/ucf/query/ValueOperation.java b/provisioning/provisioning-impl/src/main/java/com/evolveum/midpoint/provisioning/ucf/query/ValueOperation.java index eda8fb312e3..6c79b149726 100644 --- a/provisioning/provisioning-impl/src/main/java/com/evolveum/midpoint/provisioning/ucf/query/ValueOperation.java +++ b/provisioning/provisioning-impl/src/main/java/com/evolveum/midpoint/provisioning/ucf/query/ValueOperation.java @@ -33,7 +33,6 @@ import com.evolveum.midpoint.prism.PrismValue; import com.evolveum.midpoint.prism.path.ItemPath; import com.evolveum.midpoint.prism.query.EqualFilter; -import com.evolveum.midpoint.prism.query.InFilter; import com.evolveum.midpoint.prism.query.ObjectFilter; import com.evolveum.midpoint.prism.query.SubstringFilter; import com.evolveum.midpoint.prism.query.ValueFilter; @@ -83,17 +82,6 @@ public Filter interpret(ObjectFilter objectFilter, IcfNameMapper icfNameMapp } } - } else if (objectFilter instanceof InFilter) { - InFilter in = (InFilter) objectFilter; - - Collection convertedValues = convertValues(propName, (List) in.getValues()); - if (convertedValues.isEmpty()) { - throw new IllegalArgumentException("In filter with a null value makes no sense"); - } else { - Attribute attr = AttributeBuilder.build(icfName, convertedValues); - return FilterBuilder.equalTo(attr); - } - } else if (objectFilter instanceof SubstringFilter) { SubstringFilter substring = (SubstringFilter) objectFilter; Collection convertedValues = convertValues(propName, substring.getValues()); diff --git a/repo/repo-sql-impl-test/src/test/java/com/evolveum/midpoint/repo/sql/ModifyTest.java b/repo/repo-sql-impl-test/src/test/java/com/evolveum/midpoint/repo/sql/ModifyTest.java index ebd90f987f1..b49d8898eb8 100644 --- a/repo/repo-sql-impl-test/src/test/java/com/evolveum/midpoint/repo/sql/ModifyTest.java +++ b/repo/repo-sql-impl-test/src/test/java/com/evolveum/midpoint/repo/sql/ModifyTest.java @@ -23,8 +23,8 @@ import com.evolveum.midpoint.prism.delta.PropertyDelta; import com.evolveum.midpoint.prism.delta.ReferenceDelta; import com.evolveum.midpoint.prism.path.ItemPath; -import com.evolveum.midpoint.prism.query.LessFilter; import com.evolveum.midpoint.prism.query.ObjectQuery; +import com.evolveum.midpoint.prism.query.builder.QueryBuilder; import com.evolveum.midpoint.prism.util.PrismTestUtil; import com.evolveum.midpoint.prism.xml.XmlTypeConverter; import com.evolveum.midpoint.repo.api.RepoModifyOptions; @@ -509,10 +509,9 @@ public void testModifyAccountSynchronizationSituation() throws Exception { AssertJUnit.assertNotNull(afterModifytimestamp); assertEquals(afterSecondModifyType.getSynchronizationTimestamp(), description.getTimestamp()); - LessFilter filter = LessFilter.createLess(ShadowType.F_SYNCHRONIZATION_TIMESTAMP, afterSecondModify.findProperty( - ShadowType.F_SYNCHRONIZATION_TIMESTAMP).getDefinition(), afterModifytimestamp, true); - ObjectQuery query = ObjectQuery.createObjectQuery(filter); - + ObjectQuery query = QueryBuilder.queryFor(ShadowType.class, prismContext) + .item(ShadowType.F_SYNCHRONIZATION_TIMESTAMP).le(afterModifytimestamp) + .build(); List> shadows = repositoryService.searchObjects(ShadowType.class, query, null, result); AssertJUnit.assertNotNull(shadows); assertEquals(1, shadows.size()); diff --git a/repo/repo-sql-impl-test/src/test/java/com/evolveum/midpoint/repo/sql/OrgStructTest.java b/repo/repo-sql-impl-test/src/test/java/com/evolveum/midpoint/repo/sql/OrgStructTest.java index 045e5c16842..d4e4391cf6c 100644 --- a/repo/repo-sql-impl-test/src/test/java/com/evolveum/midpoint/repo/sql/OrgStructTest.java +++ b/repo/repo-sql-impl-test/src/test/java/com/evolveum/midpoint/repo/sql/OrgStructTest.java @@ -514,8 +514,10 @@ public void test005deleteOrg() throws Exception { public void test006searchOrgStructUserUnbounded() throws Exception { OperationResult parentResult = new OperationResult("test006searchOrgStructUserUnbounded"); - ObjectQuery objectQuery = ObjectQuery.createObjectQuery(OrgFilter.createOrg(SEARCH_ORG_OID_UNBOUNDED_DEPTH)); - objectQuery.setPaging(ObjectPaging.createPaging(null, null, ObjectType.F_NAME, OrderDirection.ASCENDING)); + ObjectQuery objectQuery = QueryBuilder.queryFor(ObjectType.class, prismContext) + .isChildOf(SEARCH_ORG_OID_UNBOUNDED_DEPTH) + .asc(ObjectType.F_NAME) + .build(); List> orgClosure = repositoryService.searchObjects(ObjectType.class, objectQuery, null, parentResult); @@ -564,9 +566,10 @@ public void test007searchOrgStructOrgDepth() throws Exception { public void test008searchRootOrg() throws Exception { OperationResult parentResult = new OperationResult("test008searchRootOrg"); - ObjectQuery qSearch = ObjectQuery.createObjectQuery(OrgFilter.createRootOrg()); - qSearch.setPaging(ObjectPaging.createPaging(null, null, ObjectType.F_NAME, OrderDirection.ASCENDING)); - + ObjectQuery qSearch = QueryBuilder.queryFor(ObjectType.class, prismContext) + .isRoot() + .asc(ObjectType.F_NAME) + .build(); List> rootOrgs = repositoryService.searchObjects(OrgType.class, qSearch, null, parentResult); for (PrismObject ro : rootOrgs) { diff --git a/repo/repo-sql-impl-test/src/test/java/com/evolveum/midpoint/repo/sql/QueryInterpreter2Test.java b/repo/repo-sql-impl-test/src/test/java/com/evolveum/midpoint/repo/sql/QueryInterpreter2Test.java index 62b3f113673..a127db89658 100644 --- a/repo/repo-sql-impl-test/src/test/java/com/evolveum/midpoint/repo/sql/QueryInterpreter2Test.java +++ b/repo/repo-sql-impl-test/src/test/java/com/evolveum/midpoint/repo/sql/QueryInterpreter2Test.java @@ -16,36 +16,10 @@ package com.evolveum.midpoint.repo.sql; -import com.evolveum.midpoint.prism.Containerable; -import com.evolveum.midpoint.prism.Objectable; -import com.evolveum.midpoint.prism.PrismConstants; -import com.evolveum.midpoint.prism.PrismContainerDefinition; -import com.evolveum.midpoint.prism.PrismObject; -import com.evolveum.midpoint.prism.PrismObjectDefinition; -import com.evolveum.midpoint.prism.PrismProperty; -import com.evolveum.midpoint.prism.PrismPropertyDefinition; -import com.evolveum.midpoint.prism.PrismReferenceValue; -import com.evolveum.midpoint.prism.match.PolyStringNormMatchingRule; -import com.evolveum.midpoint.prism.match.PolyStringOrigMatchingRule; +import com.evolveum.midpoint.prism.*; import com.evolveum.midpoint.prism.path.ItemPath; -import com.evolveum.midpoint.prism.polystring.PolyString; -import com.evolveum.midpoint.prism.query.AndFilter; -import com.evolveum.midpoint.prism.query.EqualFilter; -import com.evolveum.midpoint.prism.query.ExistsFilter; -import com.evolveum.midpoint.prism.query.GreaterFilter; -import com.evolveum.midpoint.prism.query.InOidFilter; -import com.evolveum.midpoint.prism.query.LessFilter; -import com.evolveum.midpoint.prism.query.ObjectFilter; -import com.evolveum.midpoint.prism.query.ObjectPaging; -import com.evolveum.midpoint.prism.query.ObjectQuery; -import com.evolveum.midpoint.prism.query.OrFilter; -import com.evolveum.midpoint.prism.query.OrgFilter; -import com.evolveum.midpoint.prism.query.QueryJaxbConvertor; -import com.evolveum.midpoint.prism.query.RefFilter; -import com.evolveum.midpoint.prism.query.SubstringFilter; -import com.evolveum.midpoint.prism.query.TypeFilter; +import com.evolveum.midpoint.prism.query.*; import com.evolveum.midpoint.prism.query.builder.QueryBuilder; -import com.evolveum.midpoint.prism.query.builder.S_FilterEntry; import com.evolveum.midpoint.prism.schema.SchemaRegistry; import com.evolveum.midpoint.prism.util.PrismTestUtil; import com.evolveum.midpoint.prism.xml.XmlTypeConverter; @@ -69,7 +43,6 @@ import com.evolveum.midpoint.xml.ns._public.common.common_3.*; import com.evolveum.prism.xml.ns._public.query_3.QueryType; import org.apache.commons.lang.StringUtils; -import org.hibernate.Query; import org.hibernate.Session; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -86,7 +59,6 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.Date; import java.util.List; @@ -97,11 +69,7 @@ import static com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignStateType.IN_REVIEW_STAGE; import static com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType.F_OWNER_REF; import static com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType.F_STATE; -import static com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType.F_CURRENT_STAGE_NUMBER; -import static com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType.F_DECISION; -import static com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType.F_CURRENT_REVIEWER_REF; -import static com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType.F_CURRENT_REVIEW_DEADLINE; -import static com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType.F_CURRENT_REVIEW_REQUESTED_TIMESTAMP; +import static com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType.*; import static com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationDecisionType.F_RESPONSE; import static com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationDecisionType.F_STAGE_NUMBER; import static com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationResponseType.NO_RESPONSE; @@ -110,15 +78,10 @@ import static com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType.F_ASSIGNMENT; import static com.evolveum.midpoint.xml.ns._public.common.common_3.MetadataType.F_CREATE_APPROVER_REF; import static com.evolveum.midpoint.xml.ns._public.common.common_3.MetadataType.F_CREATOR_REF; -import static com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType.F_EXTENSION; -import static com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType.F_METADATA; -import static com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType.F_NAME; -import static com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType.F_OBJECT_REF; +import static com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType.*; import static com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType.F_WORKFLOW_CONTEXT; import static com.evolveum.midpoint.xml.ns._public.common.common_3.TriggerType.F_TIMESTAMP; -import static com.evolveum.midpoint.xml.ns._public.common.common_3.WfContextType.F_PROCESS_INSTANCE_ID; -import static com.evolveum.midpoint.xml.ns._public.common.common_3.WfContextType.F_REQUESTER_REF; -import static com.evolveum.midpoint.xml.ns._public.common.common_3.WfContextType.F_START_TIMESTAMP; +import static com.evolveum.midpoint.xml.ns._public.common.common_3.WfContextType.*; import static org.testng.AssertJUnit.assertEquals; /** @@ -1119,12 +1082,9 @@ public void test160QueryTrigger() throws Exception { Session session = open(); try { XMLGregorianCalendar thisScanTimestamp = XmlTypeConverter.createXMLGregorianCalendar(NOW.getTime()); - - SchemaRegistry registry = prismContext.getSchemaRegistry(); - PrismObjectDefinition objectDef = registry.findObjectDefinitionByCompileTimeClass(ObjectType.class); - ItemPath triggerPath = new ItemPath(ObjectType.F_TRIGGER, F_TIMESTAMP); - ObjectFilter filter = LessFilter.createLess(triggerPath, objectDef, thisScanTimestamp, true); - ObjectQuery query = ObjectQuery.createObjectQuery(filter); + ObjectQuery query = QueryBuilder.queryFor(ObjectType.class, prismContext) + .item(ObjectType.F_TRIGGER, F_TIMESTAMP).le(thisScanTimestamp) + .build(); String real = getInterpretedQuery2(session, ObjectType.class, query); String expected = "select\n" + @@ -1321,15 +1281,11 @@ public void test200QueryTriggerTimestampDoubleWrong() throws Exception { try { XMLGregorianCalendar thisScanTimestamp = XmlTypeConverter.createXMLGregorianCalendar(NOW.getTime()); - SchemaRegistry registry = prismContext.getSchemaRegistry(); - PrismObjectDefinition objectDef = registry.findObjectDefinitionByCompileTimeClass(ObjectType.class); - ItemPath triggerPath = new ItemPath(ObjectType.F_TRIGGER, F_TIMESTAMP); - ObjectFilter greater = GreaterFilter.createGreater(triggerPath, objectDef, thisScanTimestamp, false); - ObjectFilter lesser = LessFilter.createLess(triggerPath, objectDef, thisScanTimestamp, false); - AndFilter and = AndFilter.createAnd(greater, lesser); - LOGGER.info(and.debugDump()); - - ObjectQuery query = ObjectQuery.createObjectQuery(and); + ObjectQuery query = QueryBuilder.queryFor(ObjectType.class, prismContext) + .item(ObjectType.F_TRIGGER, F_TIMESTAMP).gt(thisScanTimestamp) + .and().item(ObjectType.F_TRIGGER, F_TIMESTAMP).lt(thisScanTimestamp) + .build(); + LOGGER.info(query.debugDump()); String real = getInterpretedQuery2(session, ObjectType.class, query); // correct translation but the filter is wrong: we need to point to THE SAME timestamp -> i.e. ForValue should be used here @@ -1473,11 +1429,6 @@ public void test340QueryOrgTreeFindOrgs() throws Exception { Session session = open(); try { - OrgFilter orgFilter = OrgFilter.createOrg("some oid", OrgFilter.Scope.ONE_LEVEL); - ObjectQuery query0 = ObjectQuery.createObjectQuery(orgFilter); - query0.setPaging(ObjectPaging.createPaging(null, null, F_NAME, ASCENDING)); - query0.setUseNewQueryInterpreter(true); - ObjectQuery query = QueryBuilder.queryFor(OrgType.class, prismContext) .isDirectChildOf("some oid") .asc(ObjectType.F_NAME) @@ -1616,18 +1567,6 @@ public void test400ActivationQueryWrong() throws Exception { XMLGregorianCalendar thisScanTimestamp = XMLGregorianCalendarType.asXMLGregorianCalendar(new Date()); - OrFilter filter = OrFilter.createOr( - LessFilter.createLess(new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_VALID_FROM), focusObjectDef, - thisScanTimestamp, true), - LessFilter.createLess(new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_VALID_TO), focusObjectDef, - thisScanTimestamp, true), - LessFilter.createLess(new ItemPath(F_ASSIGNMENT, AssignmentType.F_ACTIVATION, ActivationType.F_VALID_FROM), - focusObjectDef, thisScanTimestamp, true), - LessFilter.createLess(new ItemPath(F_ASSIGNMENT, AssignmentType.F_ACTIVATION, ActivationType.F_VALID_TO), - focusObjectDef, thisScanTimestamp, true) - ); - ObjectQuery query0 = ObjectQuery.createObjectQuery(filter); - ObjectQuery query = QueryBuilder.queryFor(FocusType.class, prismContext) .item(FocusType.F_ACTIVATION, ActivationType.F_VALID_FROM).le(thisScanTimestamp) .or().item(FocusType.F_ACTIVATION, ActivationType.F_VALID_TO).le(thisScanTimestamp) @@ -1677,19 +1616,6 @@ public void test405ActivationQueryCorrect() throws Exception { XMLGregorianCalendar thisScanTimestamp = XMLGregorianCalendarType.asXMLGregorianCalendar(new Date()); - OrFilter filter = OrFilter.createOr( - LessFilter.createLess(new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_VALID_FROM), focusObjectDef, - thisScanTimestamp, true), - LessFilter.createLess(new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_VALID_TO), focusObjectDef, - thisScanTimestamp, true), - ExistsFilter.createExists(new ItemPath(F_ASSIGNMENT), focusObjectDef, - OrFilter.createOr( - LessFilter.createLess(new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_VALID_FROM), - assignmentDef, thisScanTimestamp, true), - LessFilter.createLess(new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_VALID_TO), - assignmentDef, thisScanTimestamp, true)))); - ObjectQuery query0 = ObjectQuery.createObjectQuery(filter); - ObjectQuery query = QueryBuilder.queryFor(FocusType.class, prismContext) .item(FocusType.F_ACTIVATION, ActivationType.F_VALID_FROM).le(thisScanTimestamp) .or().item(FocusType.F_ACTIVATION, ActivationType.F_VALID_TO).le(thisScanTimestamp) @@ -1739,34 +1665,6 @@ public void test410ActivationQueryWrong() throws Exception { XMLGregorianCalendar lastScanTimestamp = XMLGregorianCalendarType.asXMLGregorianCalendar(new Date()); XMLGregorianCalendar thisScanTimestamp = XMLGregorianCalendarType.asXMLGregorianCalendar(new Date()); - OrFilter filter = OrFilter.createOr( - AndFilter.createAnd( - GreaterFilter.createGreater(new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_VALID_FROM), focusObjectDef, - lastScanTimestamp, false), - LessFilter.createLess(new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_VALID_FROM), focusObjectDef, - thisScanTimestamp, true) - ), - AndFilter.createAnd( - GreaterFilter.createGreater(new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_VALID_TO), focusObjectDef, - lastScanTimestamp, false), - LessFilter.createLess(new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_VALID_TO), focusObjectDef, - thisScanTimestamp, true) - ), - AndFilter.createAnd( - GreaterFilter.createGreater(new ItemPath(F_ASSIGNMENT, FocusType.F_ACTIVATION, ActivationType.F_VALID_FROM), - focusObjectDef, lastScanTimestamp, false), - LessFilter.createLess(new ItemPath(F_ASSIGNMENT, FocusType.F_ACTIVATION, ActivationType.F_VALID_FROM), - focusObjectDef, thisScanTimestamp, true) - ), - AndFilter.createAnd( - GreaterFilter.createGreater(new ItemPath(F_ASSIGNMENT, FocusType.F_ACTIVATION, ActivationType.F_VALID_TO), - focusObjectDef, lastScanTimestamp, false), - LessFilter.createLess(new ItemPath(F_ASSIGNMENT, FocusType.F_ACTIVATION, ActivationType.F_VALID_TO), - focusObjectDef, thisScanTimestamp, true) - ) - ); - ObjectQuery query0 = ObjectQuery.createObjectQuery(filter); - ObjectQuery query = QueryBuilder.queryFor(FocusType.class, prismContext) .block() .item(FocusType.F_ACTIVATION, ActivationType.F_VALID_FROM).gt(lastScanTimestamp) @@ -1786,8 +1684,6 @@ public void test410ActivationQueryWrong() throws Exception { .endBlock() .build(); - //QueryBuilder.queryFor(UserType.class, prismContext); - Session session = open(); try { String real = getInterpretedQuery2(session, UserType.class, query, false); @@ -1843,37 +1739,6 @@ public void test415ActivationQueryCorrect() throws Exception { XMLGregorianCalendar lastScanTimestamp = XMLGregorianCalendarType.asXMLGregorianCalendar(new Date()); XMLGregorianCalendar thisScanTimestamp = XMLGregorianCalendarType.asXMLGregorianCalendar(new Date()); - OrFilter filter = OrFilter.createOr( - AndFilter.createAnd( - GreaterFilter.createGreater(new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_VALID_FROM), focusObjectDef, - lastScanTimestamp, false), - LessFilter.createLess(new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_VALID_FROM), focusObjectDef, - thisScanTimestamp, true) - ), - AndFilter.createAnd( - GreaterFilter.createGreater(new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_VALID_TO), focusObjectDef, - lastScanTimestamp, false), - LessFilter.createLess(new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_VALID_TO), focusObjectDef, - thisScanTimestamp, true) - ), - AndFilter.createAnd( - ExistsFilter.createExists(new ItemPath(F_ASSIGNMENT), focusObjectDef, - OrFilter.createOr( - AndFilter.createAnd( - GreaterFilter.createGreater(new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_VALID_FROM), - assignmentDef, lastScanTimestamp, false), - LessFilter.createLess(new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_VALID_FROM), - assignmentDef, thisScanTimestamp, true) - ), - AndFilter.createAnd( - GreaterFilter.createGreater(new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_VALID_TO), - assignmentDef, lastScanTimestamp, false), - LessFilter.createLess(new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_VALID_TO), - assignmentDef, thisScanTimestamp, true)))) - ) - ); - ObjectQuery query0 = ObjectQuery.createObjectQuery(filter); - ObjectQuery query = QueryBuilder.queryFor(FocusType.class, prismContext) .block() .item(FocusType.F_ACTIVATION, ActivationType.F_VALID_FROM).gt(lastScanTimestamp) @@ -1979,9 +1844,10 @@ private void checkQueryResult(Class type, String oid, throws Exception { LOGGER.info("checkQueryResult"); - OrgFilter orgFilter = OrgFilter.createOrg(oid, scope); - ObjectQuery query = ObjectQuery.createObjectQuery(orgFilter); - query.setPaging(ObjectPaging.createPaging(null, null, F_NAME, ASCENDING)); + ObjectQuery query = QueryBuilder.queryFor(type, prismContext) + .isInScopeOf(oid, scope) + .asc(F_NAME) + .build(); query.setUseNewQueryInterpreter(true); OperationResult result = new OperationResult("checkQueryResult"); @@ -1990,13 +1856,13 @@ private void checkQueryResult(Class type, String oid, LOGGER.info("{}", object.getOid()); } int realCount = objects.size(); - assertEquals("Expected count doesn't match for searchObjects " + orgFilter, count, realCount); + assertEquals("Expected count doesn't match for searchObjects " + query, count, realCount); result.computeStatusIfUnknown(); AssertJUnit.assertTrue(result.isSuccess()); realCount = repositoryService.countObjects(type, query, result); - assertEquals("Expected count doesn't match for countObjects " + orgFilter, count, realCount); + assertEquals("Expected count doesn't match for countObjects " + query, count, realCount); result.computeStatusIfUnknown(); AssertJUnit.assertTrue(result.isSuccess()); @@ -2169,12 +2035,10 @@ public void test560queryMetadataTimestamp() throws Exception { try { XMLGregorianCalendar timeXml = XMLGregorianCalendarType.asXMLGregorianCalendar(new Date()); - - LessFilter less = LessFilter.createLess( - new ItemPath(ReportOutputType.F_METADATA, MetadataType.F_CREATE_TIMESTAMP), - ReportOutputType.class, prismContext, timeXml, true); - - String real = getInterpretedQuery2(session, ReportOutputType.class, ObjectQuery.createObjectQuery(less)); + ObjectQuery query = QueryBuilder.queryFor(ReportOutputType.class, prismContext) + .item(ReportOutputType.F_METADATA, MetadataType.F_CREATE_TIMESTAMP).le(timeXml) + .build(); + String real = getInterpretedQuery2(session, ReportOutputType.class, query); String expected = "select\n" + " r.fullObject,\n" + " r.stringsCount,\n" + diff --git a/repo/repo-sql-impl-test/src/test/java/com/evolveum/midpoint/repo/sql/closure/AbstractOrgClosureTest.java b/repo/repo-sql-impl-test/src/test/java/com/evolveum/midpoint/repo/sql/closure/AbstractOrgClosureTest.java index 9c8b9f635eb..c643ea75fa7 100644 --- a/repo/repo-sql-impl-test/src/test/java/com/evolveum/midpoint/repo/sql/closure/AbstractOrgClosureTest.java +++ b/repo/repo-sql-impl-test/src/test/java/com/evolveum/midpoint/repo/sql/closure/AbstractOrgClosureTest.java @@ -30,6 +30,7 @@ import com.evolveum.midpoint.prism.query.ObjectFilter; import com.evolveum.midpoint.prism.query.ObjectQuery; import com.evolveum.midpoint.prism.query.OrgFilter; +import com.evolveum.midpoint.prism.query.builder.QueryBuilder; import com.evolveum.midpoint.repo.sql.BaseSQLRepoTest; import com.evolveum.midpoint.repo.sql.data.common.ROrgClosure; import com.evolveum.midpoint.repo.sql.data.common.other.RObjectType; @@ -647,9 +648,9 @@ protected void removeOrgStructure(OperationResult result) throws Exception { protected void removeOrgStructure(String nodeOid, OperationResult result) throws Exception { removeUsersFromOrg(nodeOid, result); - ObjectQuery query = new ObjectQuery(); - ObjectFilter filter = OrgFilter.createOrg(nodeOid, OrgFilter.Scope.ONE_LEVEL); - query.setFilter(filter); + ObjectQuery query = QueryBuilder.queryFor(OrgType.class, prismContext) + .isDirectChildOf(nodeOid) + .build(); List> subOrgs = repositoryService.searchObjects(OrgType.class, query, null, result); for (PrismObject subOrg : subOrgs) { removeOrgStructure(subOrg.getOid(), result); @@ -663,9 +664,9 @@ protected void removeOrgStructure(String nodeOid, OperationResult result) throws } protected void removeUsersFromOrg(String nodeOid, OperationResult result) throws Exception { - ObjectQuery query = new ObjectQuery(); - ObjectFilter filter = OrgFilter.createOrg(nodeOid, OrgFilter.Scope.ONE_LEVEL); - query.setFilter(filter); + ObjectQuery query = QueryBuilder.queryFor(UserType.class, prismContext) + .isDirectChildOf(nodeOid) + .build(); List> users = repositoryService.searchObjects(UserType.class, query, null, result); for (PrismObject user : users) { try { diff --git a/repo/security-impl/src/main/java/com/evolveum/midpoint/security/impl/SecurityEnforcerImpl.java b/repo/security-impl/src/main/java/com/evolveum/midpoint/security/impl/SecurityEnforcerImpl.java index 99c64765e22..ce0c56293d6 100644 --- a/repo/security-impl/src/main/java/com/evolveum/midpoint/security/impl/SecurityEnforcerImpl.java +++ b/repo/security-impl/src/main/java/com/evolveum/midpoint/security/impl/SecurityEnforcerImpl.java @@ -24,6 +24,7 @@ import com.evolveum.midpoint.prism.query.builder.QueryBuilder; import com.evolveum.midpoint.prism.query.builder.S_AtomicFilterExit; +import com.evolveum.midpoint.prism.query.builder.S_FilterEntryOrEmpty; import org.aopalliance.intercept.MethodInvocation; import org.apache.commons.lang.BooleanUtils; import org.apache.commons.lang.mutable.MutableBoolean; @@ -1022,7 +1023,8 @@ private ObjectFilter preProcessObje // Org if (specOrgRef != null) { - OrgFilter orgFilter = OrgFilter.createOrg(specOrgRef.getOid()); + ObjectFilter orgFilter = QueryBuilder.queryFor(ObjectType.class, prismContext) + .isChildOf(specOrgRef.getOid()).buildFilter(); objSpecSecurityFilter = ObjectQueryUtil.filterAnd(objSpecSecurityFilter, orgFilter); LOGGER.trace(" applying org filter {}", orgFilter); } else { @@ -1035,23 +1037,21 @@ private ObjectFilter preProcessObje QName subjectRelation = specOrgRelation.getSubjectRelation(); for (ObjectReferenceType subjectParentOrgRef: principal.getUser().getParentOrgRef()) { if (MiscSchemaUtil.compareRelation(subjectRelation, subjectParentOrgRef.getRelation())) { - OrgFilter orgFilter = null; + S_FilterEntryOrEmpty q = QueryBuilder.queryFor(ObjectType.class, prismContext); + S_AtomicFilterExit q2; if (specOrgRelation.getScope() == null || specOrgRelation.getScope() == OrgScopeType.ALL_DESCENDANTS) { - orgFilter = OrgFilter.createOrg(subjectParentOrgRef.getOid(), OrgFilter.Scope.SUBTREE); + q2 = q.isChildOf(subjectParentOrgRef.getOid()); } else if (specOrgRelation.getScope() == OrgScopeType.DIRECT_DESCENDANTS) { - orgFilter = OrgFilter.createOrg(subjectParentOrgRef.getOid(), OrgFilter.Scope.ONE_LEVEL); + q2 = q.isDirectChildOf(subjectParentOrgRef.getOid()); } else if (specOrgRelation.getScope() == OrgScopeType.ALL_ANCESTORS) { - orgFilter = OrgFilter.createOrg(subjectParentOrgRef.getOid(), OrgFilter.Scope.ANCESTORS); + q2 = q.isParentOf(subjectParentOrgRef.getOid()); } else { throw new UnsupportedOperationException("Unknown orgRelation scope "+specOrgRelation.getScope()); } if (BooleanUtils.isTrue(specOrgRelation.isIncludeReferenceOrg())) { - InOidFilter oidFilter = InOidFilter.createInOid(subjectParentOrgRef.getOid()); - objSpecOrgRelationFilter = ObjectQueryUtil.filterAnd(objSpecOrgRelationFilter, - ObjectQueryUtil.filterOr(orgFilter, oidFilter)); - } else { - objSpecOrgRelationFilter = ObjectQueryUtil.filterAnd(objSpecOrgRelationFilter, orgFilter); + q2 = q2.or().id(subjectParentOrgRef.getOid()); } + objSpecOrgRelationFilter = ObjectQueryUtil.filterAnd(objSpecOrgRelationFilter, q2.buildFilter()); } } if (objSpecOrgRelationFilter == null) { diff --git a/repo/task-quartz-impl/src/main/java/com/evolveum/midpoint/task/quartzimpl/TaskManagerQuartzImpl.java b/repo/task-quartz-impl/src/main/java/com/evolveum/midpoint/task/quartzimpl/TaskManagerQuartzImpl.java index da2552bb85b..78c9dd77d9c 100644 --- a/repo/task-quartz-impl/src/main/java/com/evolveum/midpoint/task/quartzimpl/TaskManagerQuartzImpl.java +++ b/repo/task-quartz-impl/src/main/java/com/evolveum/midpoint/task/quartzimpl/TaskManagerQuartzImpl.java @@ -22,14 +22,9 @@ import com.evolveum.midpoint.prism.delta.ItemDelta; import com.evolveum.midpoint.prism.path.ItemPath; import com.evolveum.midpoint.prism.polystring.PolyString; -import com.evolveum.midpoint.prism.query.AndFilter; -import com.evolveum.midpoint.prism.query.EqualFilter; -import com.evolveum.midpoint.prism.query.LessFilter; -import com.evolveum.midpoint.prism.query.ObjectFilter; import com.evolveum.midpoint.prism.query.ObjectQuery; import com.evolveum.midpoint.prism.query.builder.QueryBuilder; import com.evolveum.midpoint.prism.query.builder.S_AtomicFilterEntry; -import com.evolveum.midpoint.prism.query.builder.S_FilterEntryOrEmpty; import com.evolveum.midpoint.prism.xml.XmlTypeConverter; import com.evolveum.midpoint.repo.api.RepositoryService; import com.evolveum.midpoint.schema.GetOperationOptions; @@ -50,16 +45,8 @@ import com.evolveum.midpoint.util.logging.LoggingUtils; import com.evolveum.midpoint.util.logging.Trace; import com.evolveum.midpoint.util.logging.TraceManager; -import com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.NodeErrorStatusType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.NodeExecutionStatusType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.OperationStatsType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskExecutionStatusType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType; +import com.evolveum.midpoint.xml.ns._public.common.common_3.*; import com.evolveum.prism.xml.ns._public.types_3.PolyStringType; - import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.Validate; import org.quartz.JobKey; @@ -77,16 +64,8 @@ import javax.annotation.PreDestroy; import javax.xml.datatype.Duration; import javax.xml.datatype.XMLGregorianCalendar; - import java.text.ParseException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors;