[midPoint] Assigning several roles from a single attribute in a resource inbound mapping

Frédéric Lohier frederic at lohier.org
Fri Jun 26 20:00:41 CEST 2020


Hello,

In order to assign several roles from a single attribute value in a
resource inbound mapping, I wrote the following inbound mapping in my
resource, taking some hints from
https://wiki.evolveum.com/display/midPoint/Scripting+Hooks, but I get
the error “com.evolveum.midpoint.util.exception.ExpressionEvaluationException:
No such property: modelContext for class”
Am I on the correct path? Or is there a better way to do what I want?

<attribute>
<ref>ri:my_attribute</ref>
<displayName>My attribute</displayName>
<inbound>
<expression>
<script>
<code>
import com.evolveum.midpoint.prism.delta.*;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
UserType user = (UserType) focus;
roleName = "My_Role"
role = midpoint.searchObjectByName(RoleType.class, roleName)
if (!midpoint.isDirectlyAssigned(role)) {
// The role is not assigned. Let's assign it. We need to construct a
delta to do this
assignment = new AssignmentType();
roleTarget = new ObjectReferenceType();
roleTarget.setOid("00000-0000-0000-000-0000");
roleTarget.setType(RoleType.COMPLEX_TYPE);
assignment.setTargetRef(roleTarget);
assignmentDelta =
prismContext.deltaFactory().container().createModificationAdd(UserType.F_ASSIGNMENT,
UserType.class, assignment);
modelContext.getFocusContext().swallowToPrimaryDelta(assignmentDelta);
log.debug('test assignment  ' + assignmentDelta + ' of user ' + user.getName());
return  my_attribute;
}
</code>
</script>
</expression>
<target>
<path>$focus/extension/my_attribute</path>
</target>
<strength>strong</strength>
</inbound>
</attribute>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.evolveum.com/pipermail/midpoint/attachments/20200626/490b695a/attachment.htm>


More information about the midPoint mailing list