Skip to content

Commit

Permalink
Fixing value policy expressions (MID-1657)
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Mar 6, 2017
1 parent 0c2df16 commit 2964b19
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Expand Up @@ -15,6 +15,7 @@
*/
package com.evolveum.midpoint.model.common.expression;

import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.schema.util.SchemaDebugUtil;
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.util.DebugDumpable;
Expand All @@ -24,6 +25,8 @@
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;

import org.apache.commons.lang.StringUtils;
import org.w3c.dom.Element;

Expand Down Expand Up @@ -158,6 +161,21 @@ public <T> T get(QName name, Class<T> type) throws SchemaException {
throw new SchemaException("Expected type "+type.getSimpleName()+" in variable "+name+", but found type "+object.getClass());
}

public <O extends ObjectType> PrismObject<O> getObjectNew(QName name) throws SchemaException {
Object object = get(name);
if (object == null) {
return null;
}
if (object instanceof PrismObject) {
return (PrismObject<O>) object;
}
if (object instanceof ObjectDeltaObject<?>) {
ObjectDeltaObject<O> odo = (ObjectDeltaObject<O>)object;
return odo.getNewObject();
}
throw new SchemaException("Expected object in variable "+name+", but found type "+object.getClass());
}

public Set<Entry<QName,Object>> entrySet() {
return variables.entrySet();
}
Expand Down
Expand Up @@ -186,11 +186,11 @@ private <O extends ObjectType> PrismObject<O> getObject(ExpressionEvaluationCont
if (variables == null) {
return null;
}
PrismObject<O> object = variables.get(ExpressionConstants.VAR_PROJECTION, PrismObject.class);
PrismObject<O> object = variables.getObjectNew(ExpressionConstants.VAR_PROJECTION);
if (object != null) {
return object;
}
object = variables.get(ExpressionConstants.VAR_FOCUS, PrismObject.class);
object = variables.getObjectNew(ExpressionConstants.VAR_FOCUS);
return object;
}

Expand Down

0 comments on commit 2964b19

Please sign in to comment.