[midPoint] Groovy Expression - ObjectQuery - Midpoint 4.0+

František Dvořák valtri at civ.zcu.cz
Fri Oct 30 16:39:17 CET 2020


Hi,

it doesn't answer you second question, but a basic query groovy code
example in midPoint 4.x:


import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType;
import com.evolveum.midpoint.prism.query.ObjectFilter;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.GetOperationOptions;

options = SelectorOptions.createCollection(GetOperationOptions.createNoFetch());
ObjectFilter filter = prismContext.queryFor(RoleType.class)
        .item(ObjectType.F_SUBTYPE).eq('EXAMPLE_SUBTYPE')
        .and()
        .item(RoleType.F_IDENTIFIER).eq('EXAMPLE_IDENTIFIER')
        .buildFilter();

role = midpoint.searchObjects(RoleType.class, prismContext.queryFactory().createQuery(filter), options);


You can look also at migration to 4.x documentation [1], or the midPoint samples [2].

Cheers,
  František

[1] https://wiki.evolveum.com/display/midPoint/Upgrade+to+4.0+-+Prism+API+migration+notes
[2] https://github.com/Evolveum/midpoint-samples

Loïc Schamber via midPoint píše v Pá 30. 10. 2020 v 14:35 +0000:
> Hi everybody,
>  
> Today I needed to retrieve the list of all approver for a role in a
> groovy Script ( For a policy rule  constraint), sadly I struggle to
> achieve my goal.
> I already have my RoleType object and all I need to do is to find all
> approver for it.
>  
> I looked thought the Javadoc do find a way to retrieve this
> information. There is no method on RoleType objects, nor in the
> MidpointFunction interface. So I wated to use
> “midpoint.searchObjects(Class<T> type, ObjectQuery query)” method
> but I don’t understand how to create the ObjectQuery.
> 
> I looked on the documentation / Mailing list archive:
> https://wiki.evolveum.com/display/midPoint/Query+API#QueryAPI-Filterclassification
> https://lists.evolveum.com/pipermail/midpoint/2015-March/000938.html
> https://lists.evolveum.com/pipermail/midpoint/2018-October/005030.html
> But I fear they may not be accurate anymore.
>  
> According to the Documentation there is two way to create ObjectQuery
> objects:
> ·         Traditional Java API :
> ObjectQuery.createObjectQuery(AllFilter.createAll()); 
> ·         Fluent Java API:
> QueryBuilder.queryFor(UserType.class,midpoint.getPrismContext()).item
> (UserType.F_ROLE_MEMBERSHIP_REF).ref("xxxxxxxx-0000-0000-0000-
> xxxxxxxxxxxx").build();
>  
> However I cannot find QueryBuilder or ObjectQuery classes in the 4.0+
> documentation. It seems that they were located in the packages
> “com.evolveum.midpoint.prism.query” and
> “com.evolveum.midpoint.prism.query.builder” until 4.0.
> In 4.0 there interfaces that replaces theses classes. I searched for
> a prism.query.impl packages, with no success either.
>  
> Can you explain me how we should use the searchObjects method in
> 4.0+?
> Moreover I am not sure how to specify “approver” relationship with
> the JAVA API, so any advice would be appreciated.
>  
> Thanks a lot,
> 
> Best regards.
>  
>  
>  
>  
>  
>  
> Loïc Schamber  | IT Consultant
> lschamber at positivethinking.tech
> Tel. +41 22 721 07 77  | Direct. +41 22 555 27 69 
>  
> 
>       
> Chemin du Pré-Fleuri 5 – CH 1228 Plan-les-Ouates 
> Help save paper, do you really need to print this email? 
> The content of this email and any attachments are confidential and
> are intended solely for the person and/or company to whom they are
> addressed. The information may also be legally privileged. No
> employee or agent is authorized to conclude any binding agreement on
> behalf of Positive Thinking Company with another party by email
> without express written confirmation. If you have received this email
> in error, any use, reproduction or dissemination of this transmission
> is strictly prohibited. If you are not the intended recipient, please
> immediately notify the sender by return E-mail and delete this
> message, its attachments and all copies from your system. Internet
> communications cannot be guaranteed to be timely, secure, error or
> virus-free. The sender does not accept liability for any errors or
> omissions. Thank you for your cooperation. 
>  
>  
> _______________________________________________
> midPoint mailing list
> midPoint at lists.evolveum.com
> https://lists.evolveum.com/mailman/listinfo/midpoint



More information about the midPoint mailing list