Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Jun 14, 2016
2 parents 8540663 + c0cedfe commit 87eb81f
Show file tree
Hide file tree
Showing 35 changed files with 1,152 additions and 205 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2015 Evolveum
* Copyright (c) 2010-2016 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,6 +25,7 @@
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.PrettyPrinter;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SystemException;

Expand Down Expand Up @@ -204,6 +205,11 @@ public void setFilter(SearchFilterType filter) {
this.filter = filter;
}

@Override
public PrismReferenceDefinition getDefinition() {
return (PrismReferenceDefinition) super.getDefinition();
}

@Override
public boolean isRaw() {
// Reference value cannot be raw
Expand Down Expand Up @@ -371,11 +377,9 @@ public boolean equalsComplex(PrismReferenceValue other, boolean ignoreMetadata,
}
}
}
if (this.getTargetType() == null) {
if (other.getTargetType() != null)
return false;
} else if (!this.getTargetType().equals(other.getTargetType()))
if (!equalsTargetType(other)) {
return false;
}
if (this.relation == null) {
if (other.relation != null)
return false;
Expand All @@ -384,6 +388,18 @@ public boolean equalsComplex(PrismReferenceValue other, boolean ignoreMetadata,
return true;
}

private boolean equalsTargetType(PrismReferenceValue other) {
QName otherTargetType = other.getTargetType();
if (otherTargetType == null && other.getDefinition() != null) {
otherTargetType = other.getDefinition().getTargetTypeName();
}
QName thisTargetType = this.getTargetType();
if (thisTargetType == null && this.getDefinition() != null) {
thisTargetType = this.getDefinition().getTargetTypeName();
}
return QNameUtil.match(thisTargetType, otherTargetType);
}

@Override
public boolean equals(Object obj) {
if (this == obj)
Expand Down
Expand Up @@ -31,6 +31,7 @@
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -110,6 +111,24 @@ public ItemPath getPath() {
return parent.getPath();
}

/**
* Used when we are removing the value from the previous parent.
* Or when we know that the previous parent will be discarded and we
* want to avoid unnecessary cloning.
*/
public void clearParent() {
parent = null;
}

public static <T> void clearParent(List<PrismPropertyValue<T>> values) {
if (values == null) {
return;
}
for (PrismPropertyValue<T> val: values) {
val.clearParent();
}
}

public PrismContext getPrismContext() {
if (parent != null) {
return parent.getPrismContext();
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2015 Evolveum
* Copyright (c) 2010-2016 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,7 +22,9 @@
import com.evolveum.midpoint.util.Cloner;
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.Foreachable;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.Processor;
import com.evolveum.midpoint.util.Transformer;

import java.io.Serializable;
Expand All @@ -40,7 +42,7 @@
*
* @author Radovan Semancik
*/
public class DeltaSetTriple<T> implements DebugDumpable, Serializable, SimpleVisitable<T> {
public class DeltaSetTriple<T> implements DebugDumpable, Serializable, SimpleVisitable<T>, Foreachable<T> {

/**
* Collection of values that were not changed.
Expand Down Expand Up @@ -344,6 +346,27 @@ private boolean isEmpty(Collection<T> set) {
return set.isEmpty();
}

/**
* Process each element of every set.
* This is different from the visitor. Visitor will go
* deep inside, foreach will remain on the surface.
*/
@Override
public void foreach(Processor<T> processor) {
foreachSet(processor, zeroSet);
foreachSet(processor, plusSet);
foreachSet(processor, minusSet);
}

private void foreachSet(Processor<T> processor, Collection<T> set) {
if (set == null) {
return;
}
for (T element: set) {
processor.process(element);
}
}

@Override
public void accept(SimpleVisitor<T> visitor) {
acceptSet(visitor, zeroSet);
Expand Down
Expand Up @@ -31,6 +31,7 @@
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.Processor;
import com.evolveum.midpoint.util.exception.SchemaException;

import java.util.ArrayList;
Expand Down Expand Up @@ -238,6 +239,16 @@ public void visit(Visitable visitable) {
}
};
accept(visitor);

Processor<V> processor = new Processor<V>() {
@Override
public void process(V pval) {
if (pval.getParent() != null) {
throw new IllegalStateException("Value "+pval+" in triple "+PrismValueDeltaSetTriple.this+" has parent, looks like it was not cloned properly");
}
}
};
foreach(processor);
}

@Override
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2015 Evolveum
* Copyright (c) 2010-2016 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -291,9 +291,13 @@ private static <T,C extends Containerable> ObjectFilter parseComparisonFilter(QN
return null;
} else {
if (isEq) {
return EqualFilter.createEqual(itemPath, (PrismProperty) item, matchingRule);
List<PrismPropertyValue<T>> values = item.getValues();
PrismValue.clearParent(values);
return EqualFilter.createEqual(itemPath,
(PrismPropertyDefinition<T>)item.getDefinition(), matchingRule, values);
}
PrismPropertyValue<T> propertyValue = (PrismPropertyValue<T>) item.getValue(0);
propertyValue.clearParent();
if (isGt || isGtEq) {
return GreaterFilter.createGreater(itemPath, pcd, propertyValue, isGtEq);
} else {
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2015 Evolveum
* Copyright (c) 2010-2016 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,6 +36,7 @@
import com.evolveum.midpoint.prism.PrismProperty;
import com.evolveum.midpoint.prism.PrismPropertyDefinition;
import com.evolveum.midpoint.prism.PrismPropertyValue;
import com.evolveum.midpoint.prism.PrismValue;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
Expand All @@ -45,8 +46,7 @@ public class EqualFilter<T extends Object> extends PropertyValueFilter<PrismProp

public static final QName ELEMENT_NAME = new QName(PrismConstants.NS_QUERY, "equal");

//constructors
EqualFilter(){
EqualFilter() {
}

EqualFilter(ItemPath parentPath, PrismPropertyDefinition<T> definition, QName matchingRule, List<PrismPropertyValue<T>> values) {
Expand All @@ -65,25 +65,37 @@ private EqualFilter(ItemPath parentPath, PrismPropertyDefinition<T> definition,
super(parentPath, definition, matchingRule, expression);
}

public static <T> EqualFilter<T> createEqual(ItemPath path, PrismPropertyDefinition<T> definition, QName matchingRule, ExpressionWrapper expression){
public static <T> EqualFilter<T> createEqual(ItemPath path, PrismPropertyDefinition<T> definition,
QName matchingRule, ExpressionWrapper expression) {
Validate.notNull(path, "Path must not be null");
// Do not check definition. We may want queries for which the definition is supplied later.
return new EqualFilter(path, definition, matchingRule, expression);
return new EqualFilter<>(path, definition, matchingRule, expression);
}

//factory methods
public static <T> EqualFilter<T> createEqual(ItemPath path, PrismProperty<T> item){
public static <T> EqualFilter<T> createEqual(ItemPath path, PrismProperty<T> item) {
return createEqual(path, item, null);
}

public static <T> EqualFilter<T> createEqual(ItemPath path, PrismProperty<T> item, QName matchingRule){
Validate.notNull(item, "Item must not be null");
public static <T> EqualFilter<T> createEqual(ItemPath path, PrismProperty<T> item,
QName matchingRule) {
List<PrismPropertyValue<T>> clonedValues = (List<PrismPropertyValue<T>>) PrismPropertyValue.cloneCollection(item.getValues());
return createEqual(path, item.getDefinition(), matchingRule, clonedValues);
}

public static <T> EqualFilter<T> createEqual(ItemPath path, PrismPropertyDefinition<T> definition,
QName matchingRule, List<PrismPropertyValue<T>> values) {
Validate.notNull(values, "values must not be null");
Validate.notNull(path, "Path must not be null");
return new EqualFilter(path, item.getDefinition(), matchingRule, item.getValues());
EqualFilter<T> equalFilter = new EqualFilter<T>(path, definition, matchingRule, values);
for (PrismPropertyValue<T> value: values) {
value.setParent(equalFilter);
}
return equalFilter;
}

public static <T> EqualFilter<T> createEqual(ItemPath path, PrismPropertyDefinition<T> itemDefinition, T realValues){
return createEqual(path, itemDefinition, null, realValues);
public static <T> EqualFilter<T> createEqual(ItemPath path, PrismPropertyDefinition<T> itemDefinition, T realValue){
return createEqual(path, itemDefinition, null, realValue);
}

public static <T> EqualFilter<T> createEqual(ItemPath path, PrismPropertyDefinition<T> itemDefinition, QName matchingRule, T realValue){
Expand All @@ -94,7 +106,11 @@ public static <T> EqualFilter<T> createEqual(ItemPath path, PrismPropertyDefinit
return createNullEqual(path, itemDefinition, matchingRule);
}
List<PrismPropertyValue<T>> pVals = createPropertyList(itemDefinition, realValue);
return new EqualFilter(path, itemDefinition, matchingRule, pVals);
EqualFilter<T> equalFilter = new EqualFilter<>(path, itemDefinition, matchingRule, pVals);
for (PrismPropertyValue<T> value: pVals) {
value.setParent(equalFilter);
}
return equalFilter;
}

public static <T> EqualFilter<T> createEqualMultiple(ItemPath path, PrismPropertyDefinition<T> itemDefinition, QName matchingRule, T... realValues) {
Expand All @@ -104,7 +120,11 @@ public static <T> EqualFilter<T> createEqualMultiple(ItemPath path, PrismPropert
return createNullEqual(path, itemDefinition, matchingRule);
}
List<PrismPropertyValue<T>> pVals = createPropertyListFromArray(itemDefinition, realValues);
return new EqualFilter(path, itemDefinition, matchingRule, pVals);
EqualFilter<T> equalFilter = new EqualFilter<>(path, itemDefinition, matchingRule, pVals);
for (PrismPropertyValue<T> value: pVals) {
value.setParent(equalFilter);
}
return equalFilter;
}

public static <T> EqualFilter<T> createEqual(QName propertyName, PrismPropertyDefinition<T> propertyDefinition, QName matchingRule, T realValue){
Expand All @@ -114,7 +134,6 @@ public static <T> EqualFilter<T> createEqual(QName propertyName, PrismPropertyDe
public static <T> EqualFilter<T> createEqual(QName propertyName, PrismPropertyDefinition<T> propertyDefinition, T realValues){
return createEqual(new ItemPath(propertyName), propertyDefinition, null, realValues);
}
//

public static <T> EqualFilter<T> createEqual(ItemPath path, PrismPropertyDefinition<T> itemDefinition, PrismPropertyValue<T> values) {
return createEqual(path, itemDefinition, null, values);
Expand All @@ -130,7 +149,11 @@ public static <T> EqualFilter<T> createEqual(ItemPath path, PrismPropertyDefinit

List<PrismPropertyValue<T>> pValues = createPropertyList(itemDefinition, values);

return new EqualFilter(path, itemDefinition, matchingRule, pValues);
EqualFilter<T> equalFilter = new EqualFilter<>(path, itemDefinition, matchingRule, pValues);
for (PrismPropertyValue<T> value: pValues) {
value.setParent(equalFilter);
}
return equalFilter;
}

public static <C extends Containerable, T> EqualFilter<T> createEqual(ItemPath parentPath, PrismContainerDefinition<C> containerDef,
Expand Down Expand Up @@ -190,7 +213,7 @@ public static <T> EqualFilter<T> createNullEqual(ItemPath itemPath, PrismPropert

@Override
public EqualFilter<T> clone() {
EqualFilter<T> clone = new EqualFilter(getFullPath(), getDefinition(), getMatchingRule(), (List<PrismPropertyValue<T>>) getValues());
EqualFilter<T> clone = new EqualFilter<>(getFullPath(), getDefinition(), getMatchingRule(), (List<PrismPropertyValue<T>>) getValues());
clone.setExpression(getExpression());
cloneValues(clone);
clone.copyRightSideThingsFrom(this);
Expand Down Expand Up @@ -219,7 +242,11 @@ public String toString() {

@Override
public PrismContext getPrismContext() {
return getDefinition().getPrismContext();
PrismPropertyDefinition<T> def = getDefinition();
if (def == null) {
return null;
}
return def.getPrismContext();
}

@Override
Expand Down Expand Up @@ -287,7 +314,6 @@ public PrismPropertyDefinition<T> getDefinition(){

@Override
public List<PrismPropertyValue<T>> getValues() {
// TODO Auto-generated method stub
return super.getValues();
}

Expand Down

0 comments on commit 87eb81f

Please sign in to comment.