Skip to content

Commit

Permalink
Refactoring mapping evaluation.
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Jul 16, 2014
1 parent bbd03e3 commit d9262d9
Show file tree
Hide file tree
Showing 12 changed files with 669 additions and 190 deletions.
Expand Up @@ -19,6 +19,7 @@
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.PrettyPrinter;
import com.evolveum.midpoint.util.exception.SchemaException;

Expand All @@ -27,6 +28,7 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Set;

Expand Down Expand Up @@ -170,6 +172,19 @@ public static <V extends PrismValue> boolean containsRealValue(Collection<V> col
return false;
}

public static <V extends PrismValue> boolean equalsRealValues(Collection<V> collection1, Collection<V> collection2) {
Comparator comparator = new Comparator<V>() {
@Override
public int compare(V v1, V v2) {
if (v1.equalsRealValue(v2)) {
return 0;
};
return 1;
}
};
return MiscUtil.unorderedCollectionEquals(collection1, collection2, comparator);
}

public abstract boolean isEmpty();

public void normalize() {
Expand Down
Expand Up @@ -263,6 +263,13 @@ private static void applyObjectClass(PrismObject<? extends ShadowType> shadow,
objectClassDefinition, objectClassDefinition.getPrismContext());
attributesContainer.applyDefinition(racDef, true);
}

public static PrismObjectDefinition<ShadowType> applyObjectClass(PrismObjectDefinition<ShadowType> shadowDefinition,
ObjectClassComplexTypeDefinition objectClassDefinition) throws SchemaException {
PrismObjectDefinition<ShadowType> shadowDefClone = shadowDefinition.cloneWithReplacedDefinition(ShadowType.F_ATTRIBUTES,
objectClassDefinition.toResourceAttributeContainerDefinition());
return shadowDefClone;
}

/**
* Returns intent from the shadow. Backwards compatible with older accountType. May also adjust for default
Expand Down
Expand Up @@ -83,6 +83,7 @@
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;
Expand Down Expand Up @@ -539,4 +540,17 @@ public static Map<QName, Object> compileVariablesAndSources(ExpressionEvaluation
return variablesAndSources;
}

public static boolean hasExplicitTarget(List<MappingType> mappingTypes) {
for (MappingType mappingType: mappingTypes) {
if (hasExplicitTarget(mappingType)) {
return true;
}
}
return false;
}

private static boolean hasExplicitTarget(MappingType mappingType) {
return mappingType.getTarget() != null;
}

}
Expand Up @@ -116,6 +116,7 @@ public class Mapping<V extends PrismValue> implements DebugDumpable {
private ObjectResolver objectResolver = null;
private Source<?> defaultSource = null;
private ItemDefinition defaultTargetDefinition = null;
private ItemPath defaultTargetPath = null;
private ObjectDeltaObject<?> sourceContext = null;
private PrismObjectDefinition<?> targetContext = null;
private PrismValueDeltaSetTriple<V> outputTriple = null;
Expand Down Expand Up @@ -205,6 +206,14 @@ public void setDefaultTargetDefinition(ItemDefinition defaultTargetDefinition) {
this.defaultTargetDefinition = defaultTargetDefinition;
}

public ItemPath getDefaultTargetPath() {
return defaultTargetPath;
}

public void setDefaultTargetPath(ItemPath defaultTargetPath) {
this.defaultTargetPath = defaultTargetPath;
}

public ObjectDeltaObject<?> getSourceContext() {
return sourceContext;
}
Expand Down Expand Up @@ -846,6 +855,7 @@ private void parseTarget() throws SchemaException {
MappingTargetDeclarationType targetType = mappingType.getTarget();
if (targetType == null) {
outputDefinition = defaultTargetDefinition;
outputPath = defaultTargetPath;
} else {
ItemPathType itemPathType = targetType.getPath();
if (itemPathType == null) {
Expand Down
Expand Up @@ -698,6 +698,26 @@ public static <F extends ObjectType, T> PropertyDelta<T> findAPrioriDelta(LensCo
return aPrioriDelta;
}

/**
* Extracts the delta from this projection context and also from all other projection contexts that have
* equivalent discriminator.
*/
public static <F extends ObjectType, T> ObjectDelta<ShadowType> findAPrioriDelta(LensContext<F> context,
LensProjectionContext projCtx) throws SchemaException {
ObjectDelta<ShadowType> aPrioriDelta = null;
for (LensProjectionContext aProjCtx: findRelatedContexts(context, projCtx)) {
ObjectDelta<ShadowType> aProjDelta = aProjCtx.getDelta();
if (aProjDelta != null) {
if (aPrioriDelta == null) {
aPrioriDelta = aProjDelta.clone();
} else {
aPrioriDelta.merge(aProjDelta);
}
}
}
return aPrioriDelta;
}

/**
* Returns a list of context that have equivalent discriminator with the reference context. Ordered by "order" in the
* discriminator.
Expand Down

0 comments on commit d9262d9

Please sign in to comment.