Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Jan 20, 2021
2 parents 18acce1 + 5428b27 commit 20f8b11
Show file tree
Hide file tree
Showing 16 changed files with 172 additions and 17 deletions.
@@ -1,5 +1,9 @@
package com.evolveum.midpoint.prism;

import java.util.List;

import com.google.common.collect.ImmutableList;

public abstract class AbstractFreezable implements Freezable {

private boolean frozen = false;
Expand All @@ -10,6 +14,16 @@ public final void freeze() {
this.frozen = true;
}

protected void freeze(Freezable child) {
Freezable.freezeNullable(child);
}

protected void freezeAll(Iterable<? extends Freezable> children) {
for (Freezable freezable : children) {
freeze(freezable);
}
}

protected void performFreeze() {
// Intentional NOOP, for overriding
}
Expand All @@ -18,9 +32,16 @@ protected final boolean isMutable() {
return !this.frozen;
}

@Override
public final boolean isImmutable() {
return this.frozen;
}

protected static <T> List<T> freezeNullableList(List<T> values) {
if (values == null) {
return null;
}
return ImmutableList.copyOf(values);
}

}
Expand Up @@ -7,7 +7,6 @@

package com.evolveum.midpoint.prism;


/**
* Something that can be made immutable.
*/
Expand All @@ -29,4 +28,10 @@ default void checkImmutable() {
}
}

static void freezeNullable(Freezable target) {
if (target != null) {
target.freeze();
}
}

}
Expand Up @@ -7,6 +7,7 @@

package com.evolveum.midpoint.prism.query;

import com.evolveum.midpoint.prism.Freezable;
import com.evolveum.midpoint.prism.PrismContainerValue;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismContextSensitive;
Expand All @@ -17,7 +18,7 @@

import java.io.Serializable;

public interface ObjectFilter extends DebugDumpable, Serializable, Revivable, PrismContextSensitive {
public interface ObjectFilter extends DebugDumpable, Serializable, Revivable, Freezable, PrismContextSensitive {

/**
* Does a SHALLOW clone.
Expand Down
Expand Up @@ -35,6 +35,11 @@ public AllFilterImpl clone() {
return new AllFilterImpl();
}

@Override
public void performFreeze() {
// NOOP
}

@Override
public void checkConsistence(boolean requireDefinitions) {
// nothing to do
Expand Down
Expand Up @@ -54,6 +54,7 @@ public boolean isEquals() {
}

public void setEquals(boolean equals) {
checkMutable();
this.equals = equals;
}

Expand Down
Expand Up @@ -27,7 +27,7 @@
public final class ExistsFilterImpl extends ObjectFilterImpl implements ExistsFilter {

@NotNull private final ItemPath fullPath;
private ItemDefinition definition;
private final ItemDefinition definition;
private ObjectFilter filter;

private ExistsFilterImpl(@NotNull ItemPath fullPath, ItemDefinition definition, ObjectFilter filter) {
Expand All @@ -43,18 +43,27 @@ public ItemPath getFullPath() {
return fullPath;
}

@Override
public ItemDefinition getDefinition() {
return definition;
}

@Override
public ObjectFilter getFilter() {
return filter;
}

@Override
public void setFilter(ObjectFilter filter) {
checkMutable();
this.filter = filter;
}

@Override
protected void performFreeze() {
freeze(filter);
}

public static <C extends Containerable> ExistsFilter createExists(ItemPath itemPath, PrismContainerDefinition<C> containerDef,
ObjectFilter filter) throws SchemaException {
ItemDefinition itemDefinition = FilterImplUtil.findItemDefinition(itemPath, containerDef);
Expand All @@ -74,6 +83,7 @@ public ExistsFilterImpl clone() {
return new ExistsFilterImpl(fullPath, definition, f);
}

@Override
public ExistsFilter cloneEmpty() {
return new ExistsFilterImpl(fullPath, definition, null);
}
Expand Down
Expand Up @@ -13,6 +13,7 @@
import com.evolveum.midpoint.prism.query.FullTextFilter;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.google.common.collect.ImmutableList;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -46,22 +47,34 @@ public static FullTextFilter createFullText(@NotNull ExpressionWrapper expressio
return new FullTextFilterImpl(expression);
}

@Override
public Collection<String> getValues() {
return values;
}

@Override
public void setValues(Collection<String> values) {
checkMutable();
this.values = values;
}

@Override
public ExpressionWrapper getExpression() {
return expression;
}

@Override
public void setExpression(ExpressionWrapper expression) {
checkMutable();
this.expression = expression;
}

@Override
protected void performFreeze() {
values = ImmutableList.copyOf(values);
freeze(expression);
}

@Override
public void checkConsistence(boolean requireDefinitions) {
if (values == null) {
Expand Down
Expand Up @@ -60,26 +60,39 @@ public static InOidFilter createInOid(boolean considerOwner, ExpressionWrapper e
return new InOidFilterImpl(considerOwner, expression);
}

@Override
public Collection<String> getOids() {
return oids;
}

@Override
public void setOids(Collection<String> oids) {
checkMutable();
this.oids = oids != null ? new ArrayList<>(oids) : null;
}

@Override
public boolean isConsiderOwner() {
return considerOwner;
}

@Override
public ExpressionWrapper getExpression() {
return expression;
}

@Override
public void setExpression(ExpressionWrapper expression) {
checkMutable();
this.expression = expression;
}

@Override
protected void performFreeze() {
oids = freezeNullableList(oids);
freeze(expression);
}

@Override
public void checkConsistence(boolean requireDefinitions) {
if (oids == null) {
Expand Down Expand Up @@ -163,7 +176,7 @@ public boolean match(PrismContainerValue value, MatchingRuleRegistry matchingRul
if (!(container.getParent() instanceof PrismContainerValue)) {
return false;
}
pcvToConsider = (PrismContainerValue) container.getParent();
pcvToConsider = container.getParent();
} else {
pcvToConsider = value;
}
Expand Down
Expand Up @@ -14,33 +14,49 @@
import com.evolveum.midpoint.prism.query.ObjectFilter;
import com.evolveum.midpoint.prism.query.Visitor;
import com.evolveum.midpoint.util.DebugUtil;
import com.google.common.collect.ImmutableList;

public abstract class LogicalFilterImpl extends ObjectFilterImpl implements LogicalFilter {

protected List<ObjectFilter> conditions;

@Override
public List<ObjectFilter> getConditions() {
if (conditions == null){
conditions = new ArrayList<>();
}
return conditions;
}

@Override
public void setConditions(List<ObjectFilter> condition) {
checkMutable();
this.conditions = condition;
}

@Override
public void addCondition(ObjectFilter condition) {
checkMutable();
if (this.conditions == null) {
conditions = new ArrayList<>();
}
this.conditions.add(condition);
}

@Override
public boolean contains(ObjectFilter condition) {
return this.conditions.contains(condition);
}

@Override
protected void performFreeze() {
conditions = ImmutableList.copyOf(getConditions());
for (ObjectFilter objectFilter : conditions) {
freeze(objectFilter);
}
}

@Override
abstract public LogicalFilter cloneEmpty();

protected List<ObjectFilter> getClonedConditions() {
Expand All @@ -54,6 +70,7 @@ protected List<ObjectFilter> getClonedConditions() {
return clonedConditions;
}

@Override
public boolean isEmpty() {
return conditions == null || conditions.isEmpty();
}
Expand Down
Expand Up @@ -18,6 +18,7 @@
*
* @author Radovan Semancik
*/
// FIXME: This could be singleton
public class NoneFilterImpl extends ObjectFilterImpl implements NoneFilter {

public NoneFilterImpl() {
Expand All @@ -33,6 +34,11 @@ public NoneFilterImpl clone() {
return new NoneFilterImpl();
}

@Override
protected void performFreeze() {
// NOOP
}

@Override
public void checkConsistence(boolean requireDefinitions) {
// nothing to do
Expand Down
Expand Up @@ -7,14 +7,16 @@

package com.evolveum.midpoint.prism.impl.query;

import com.evolveum.midpoint.prism.AbstractFreezable;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.query.ObjectFilter;
import com.evolveum.midpoint.prism.query.Visitor;

public abstract class ObjectFilterImpl implements ObjectFilter {
public abstract class ObjectFilterImpl extends AbstractFreezable implements ObjectFilter {

protected transient PrismContext prismContext;

@Override
public void accept(Visitor visitor) {
visitor.visit(this);
}
Expand All @@ -24,6 +26,7 @@ public void revive(PrismContext prismContext) {
this.prismContext = prismContext;
}

@Override
public PrismContext getPrismContext() {
return prismContext;
}
Expand All @@ -32,6 +35,9 @@ public void setPrismContext(PrismContext prismContext) {
this.prismContext = prismContext;
}

@Override
protected abstract void performFreeze();

@Override
public abstract ObjectFilterImpl clone();
}

0 comments on commit 20f8b11

Please sign in to comment.