[midPoint] Apply a bulk action to a specific object type and subtype

Paul Caskey pcaskey at internet2.edu
Wed Jul 19 15:44:38 CEST 2023


Thank you, Kamil.  That works perfectly!

And you are correct.   There is no need to fetch the org object.  I thought I might need it, but your solution works great without it.


Thanks again!
-Paul

From: Kamil Jires <kamil.jires at evolveum.com>
Sent: Wednesday, July 19, 2023 6:50 AM
To: midPoint General Discussion <midpoint at lists.evolveum.com>
Cc: Paul Caskey <pcaskey at internet2.edu>
Subject: Re: [midPoint] Apply a bulk action to a specific object type and subtype

Hi Paul,
 let me share the task definition doing the stuff.

Few notes:
- As you are loging just oid, the request for the object from the repository would be wasting of the performance (I have left it there as comment).
- if you need to limit to Org only, you can make the condition ( a == "test-assignment" ) more complex involving other tests e.g. related to the assignment.targetRef.type .

I hope it will help you with your issue...

BR,
 Kamil
-----
<task xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
      xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
      xmlns:icfs="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/resource-schema-3"
      xmlns:org="http://midpoint.evolveum.com/xml/ns/public/common/org-3"
      xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3"
      xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3"
      xmlns:t="http://prism.evolveum.com/xml/ns/public/types-3"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      oid="00000000-c001-cafe-0000-000000000001">
    <name>remove assignment by subtype</name>
    <assignment>
        <targetRef oid="00000000-0000-0000-0000-000000000509" relation="org:default" type="c:ArchetypeType"/>
    </assignment>
    <ownerRef oid="00000000-0000-0000-0000-000000000002" relation="org:default" type="c:UserType"/>
    <executionState>runnable</executionState>
    <category>BulkActions</category>
    <binding>loose</binding>
    <schedule>
        <recurrence>single</recurrence>
    </schedule>
    <activity>
        <work>
            <iterativeScripting>
                <objects>
                    <type>UserType</type>
                    <query>
                        <q:filter>
                            <q:equal>
                                <q:path>assignment/subtype</q:path>
                                <q:value>test-assignment</q:value>
                            </q:equal>
                        </q:filter>
                    </query>
                </objects>
                <scriptExecutionRequest xmlns:s="http://midpoint.evolveum.com/xml/ns/public/model/scripting-3">
                    <s:action>
                        <s:type>execute-script</s:type>
                        <s:parameter>
                            <s:name>script</s:name>
                            <value xsi:type="c:ScriptExpressionEvaluatorType">
                                <code>
                                    import com.evolveum.midpoint.prism.delta.ObjectDelta
                                    import com.evolveum.midpoint.prism.delta.builder.S_ItemEntry
                                    import com.evolveum.midpoint.prism.path.ItemPath
                                    import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType
                                    import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType

                                    UserType user = input as UserType
                                    List<AssignmentType> assignmentsToRemove = new ArrayList()
                                    for (AssignmentType assignment : user.getAssignment()) {
                                        if (assignment.subtype != null && assignment.subtype.size() != 0) {
                                            for (String a : assignment.subtype) {
                                                if (a == "test-assignment") {
// ###################
//                                                    OrgType org = midpoint.resolveReferenceIfExists(assignment.targetRef)
//                                                    log.info("Found test-assignment to Org: {}",org.oid)
// # Why to resolve the Org object in case you are logging just oid ?
// ###################
                                                    log.info("Found test-assignment to {}: {}",
                                                            assignment.targetRef.type.localPart,
                                                            assignment.targetRef.oid
                                                    )
                                                    if (!assignmentsToRemove.contains(assignment)) {
                                                        assignmentsToRemove.add(assignment)
                                                        break
                                                    }
                                                }

                                            }
                                        }
                                    }
                                    S_ItemEntry removeAssignments = midpoint.prismContext.deltaFor(UserType.class)
                                    for (AssignmentType assignmentToRemove : assignmentsToRemove) {
                                        removeAssignments = removeAssignments.item(ItemPath.create(UserType.F_ASSIGNMENT)).delete(assignmentToRemove.clone())
                                    }
                                    ObjectDelta removeAssignmentsDelta = removeAssignments.asObjectDelta(user.oid)
                                    if (removeAssignmentsDelta) {
                                        log.info("Removing the selected assignments...")
                                        midpoint.executeChanges(Arrays.asList(removeAssignmentsDelta))
                                    }
                                </code>
                            </value>
                        </s:parameter>
                    </s:action>
                </scriptExecutionRequest>
            </iterativeScripting>
        </work>
    </activity>
</task>

________________________________
From: "Paul Caskey via midPoint" <midpoint at lists.evolveum.com<mailto:midpoint at lists.evolveum.com>>
To: "midPoint General Discussion" <midpoint at lists.evolveum.com<mailto:midpoint at lists.evolveum.com>>, "martin spanik" <martin.spanik at evolveum.com<mailto:martin.spanik at evolveum.com>>
Cc: "Paul Caskey" <pcaskey at internet2.edu<mailto:pcaskey at internet2.edu>>
Sent: Monday, July 17, 2023 2:01:41 AM
Subject: Re: [midPoint] Apply a bulk action to a specific object type and subtype

Hi-

I’m working with Keith (the OP) and our use case for this is trying to remove old assignments.  These are assignments on user objects to orgs that have already been deleted.

The code below selects exactly the assignments I need to remove, but I can’t figure out how to remove or unassign the assignments.

Does anyone know how to remove/unassign an assignment inside a bulk action of type ‘execute-script’?

Here’s what selects the assignments I need to delete:

<s:executeScript xmlns:s=http://midpoint.evolveum.com/xml/ns/public/model/scripting-3 xmlns:c=http://midpoint.evolveum.com/xml/ns/public/common/common-3 xmlns:icfs=http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/resource-schema-3 xmlns:org=http://midpoint.evolveum.com/xml/ns/public/common/org-3 xmlns:q=http://prism.evolveum.com/xml/ns/public/query-3 xmlns:ri=http://midpoint.evolveum.com/xml/ns/public/resource/instance-3 xmlns:t=http://prism.evolveum.com/xml/ns/public/types-3 xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance>
    <s:search>
        <s:type>c:UserType</s:type>
        <s:query>
            <q:filter>
                <q:equal>
                    <q:path>assignment/subtype</q:path>
                    <q:value>test-assignment</q:value>
                </q:equal>
            </q:filter>
        </s:query>
        <s:action>
            <s:type>execute-script</s:type>
            <s:parameter>
                <s:name>script</s:name>
                <s:value>
                    <code xmlns=http://midpoint.evolveum.com/xml/ns/public/common/common-3>
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.midpoint.model.api.*;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType;
import com.evolveum.midpoint.model.api.ModelExecuteOptions;

for (a in input.assignment) {
  if (a.subtype[0] == "test-assignment") {
    OrgType org = midpoint.resolveReferenceIfExists(a.targetRef);
    log.info ("Found test-assignment to Org: {}", org.oid)

    //need to delete/unassign this assignment (a)

  }
}
</code>
                </s:value>
            </s:parameter>
        </s:action>
    </s:search>
</s:executeScript>



Thanks in advance for any help and insight!
-Paul


From: midPoint <midpoint-bounces at lists.evolveum.com<mailto:midpoint-bounces at lists.evolveum.com>> On Behalf Of Paul Caskey via midPoint
Sent: Thursday, July 13, 2023 5:32 PM
To: martin.spanik at evolveum.com<mailto:martin.spanik at evolveum.com>; midPoint General Discussion <midpoint at lists.evolveum.com<mailto:midpoint at lists.evolveum.com>>
Cc: Paul Caskey <pcaskey at internet2.edu<mailto:pcaskey at internet2.edu>>
Subject: Re: [midPoint] Apply a bulk action to a specific object type and subtype

Thanks, Martin!

In our case, it’s the assignment itself that has the subtype, not the role (or org).

Like this (taken from a user object):
    <assignment>
        <subtype>groupRole</subtype>
        <targetRef oid="c0053265-dd8f-496f-92bc-72209ee61eb4" relation="org:default" type="c:OrgType"/>
        <activation>
            <effectiveStatus>enabled</effectiveStatus>
        </activation>
    </assignment>

It seems like a bulk action should be able to do it. But I can’t figure it out yet.  :)

Thanks again!
-Paul

From: midPoint <midpoint-bounces at lists.evolveum.com<mailto:midpoint-bounces at lists.evolveum.com>> On Behalf Of Martin Spanik via midPoint
Sent: Thursday, July 13, 2023 3:18 AM
To: 'midPoint General Discussion' <midpoint at lists.evolveum.com<mailto:midpoint at lists.evolveum.com>>
Cc: Martin Spanik <martin.spanik at evolveum.com<mailto:martin.spanik at evolveum.com>>
Subject: Re: [midPoint] Apply a bulk action to a specific object type and subtype

Hello Keith

Yes it is possible. I prepared example of such task – you can use and tune it.
It’s tested on 4.7 and 4.4. I don’t know which version you are using.

Let’s assume that your groups are represented by roles in midPoint and you have set of roles having attribute subtype with value ‘groupRole’. The role has ‘Internal’ service assigned. You want to modify these roles.
Example of the role is attached too.

Let’s get to the task:

You filter the objects in <objects> element of task/activity/work/iteractiveScripting.

<objects>
    <type>RoleType</type>
    <query>
        <q:filter>
            <q:text>subtype = 'groupRole'</q:text>
        </q:filter>
    </query>
</objects>

Then you just run action on this set of objects.  This action applies defined modification delta on the objects you selected in the filter.

The example task removes the assigned service. Commented part modifies just description attribute - just as an example.

I hope it will help you.

Best regards,

Martin Spanik
Senior Identity Engineer

+421 905 334 507
martin.spanik at evolveum.com<mailto:martin.spanik at evolveum.com>
https://evolveum.com<https://www.evolveum.com/>


From: midPoint [mailto:midpoint-bounces at lists.evolveum.com] On Behalf Of Keith Hazelton via midPoint
Sent: streda 12. júla 2023 22:01
To: midpoint at lists.evolveum.com<mailto:midpoint at lists.evolveum.com>
Cc: Keith Hazelton <hazelton at internet2.edu<mailto:hazelton at internet2.edu>>
Subject: [midPoint] Apply a bulk action to a specific object type and subtype

Is it possible to use a filter to perform a bulk action on a specific object type and subtype?

I know pt can be done, for example, for user subtypes, but we want to remove assignments for a specific subtype of group.

        Thanks in advance,   --Keith Hazelton


_________________________
hazelton at internet2.edu<mailto:hazelton at internet2.edu>

_______________________________________________
midPoint mailing list
midPoint at lists.evolveum.com<mailto:midPoint at lists.evolveum.com>
https://lists.evolveum.com/mailman/listinfo/midpoint
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.evolveum.com/pipermail/midpoint/attachments/20230719/679a12b8/attachment-0001.htm>


More information about the midPoint mailing list