Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Following scripting hook removes all assignments from disabled users. Please note usage of modelContext.rot()

Code Block
languagehtml/xml
<hook>
    <name>Remove assignments from disabled users</name>
    <state>secondary</state>
    <focusType>c:UserType</focusType>
    <script>
       <code>
            import com.evolveum.midpoint.prism.delta.*;
            import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

            UserType user = (UserType) focus;
            ActivationStatusType administrativeStatus = user.getActivation().getAdministrativeStatus();
            if (administrativeStatus == ActivationStatusType.DISABLED) {     
				changed = false;               
                for (AssignmentType assign : user.getAssignment()) {
                    assignmentDelta = ContainerDelta.createModificationDelete(UserType.F_ASSIGNMENT, UserType.class, prismContext, assign.clone());                                                            
                    log.debug('Removing assignment ' + assignmentDelta + ' from disabled user ' + user.getName());                    
                    modelContext.getFocusContext().swallowToSecondaryDelta(assignmentDelta);
					changed = true;
                }
				if (changed) {  
                    modelContext.rot(); // this makes Projector to recompute the model context
                }
            }
        </code>
    </script>
</hook>

...