Hi Adrian,
sorry that it took so long.

You can find my version at

https://gist.github.com/ilgrosso/3d56e9c57db283bfaef0068bdbc9b697

I have put some comments, please ask if you need clarifications.

As you can see, the code is Java 7 + Apache Commons, in line with Apache Syncope code, you might want to adapt to Java 8, as done below.

Regards.

On 08/07/2016 19:24, Adrian Gonzalez wrote:
Hi Francesco,

I'm more than interested by your inputs when you have the time of course !

Thanks,
P.S. created https://issues.apache.org/jira/browse/SYNCOPE-902

------------------------------------------------------------------------
*De :* Francesco Chicchiriccò <[email protected]>
*À :* [email protected]
*Envoyé le :* Vendredi 8 juillet 2016 19h16
*Objet :* Re: Query : get all groups of a user

Hi Adrian,
nice catch, glad that you have solved!

I might be able to suggest a couple of enhancements to the code below but not before some days.

If you think that yours could be a common use case, we can consider adding it to the standard search features; if so, please open an improvement on JIRA, thanks.

Regards.

On 8 July 2016 18:40:24 CEST, Adrian Gonzalez <[email protected] <mailto:[email protected]>> wrote:
>Hello,
>Just to terminate this thread, the following code retrieves all the
>groups associated to a user.
>    UserTO userTO = ...
>    List<GroupTO> groupTOs = Collections.<GroupTO> emptyList();
>    List<Long> keys = userTO.getMembershipMap().entrySet().stream()
>            .filter(entry ->
>"GROUP".equals(entry.getValue().getRightType()))
>            .map(entry ->
>entry.getValue().getRightKey()).collect(Collectors.toList());
>    if (keys.size() > 0) {
>        // cannot say I like the next 2 lines
>        Long firstKey = keys.get(0);
>        keys.remove(0);
>        String fiql =
>SyncopeClient.getGroupSearchConditionBuilder().is("key")
>                .equalTo(firstKey, keys.toArray(new
>Long[keys.size()])).query();
>        PagedResult<GroupTO> groupTOsPage =
>syncopeClient.getService(GroupService.class)
>                .search(new
>AnySearchQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(fiql).build());
>        groupTOs = (List<GroupTO>) groupTOsPage.getResult();
>    }
>
>Regards,Adrian
>
> De : Adrian Gonzalez <[email protected] <mailto:[email protected]>> >À : "[email protected] <mailto:[email protected]>" <[email protected] <mailto:[email protected]>>; Adrian
>Gonzalez <[email protected] <mailto:[email protected]>>
> Envoyé le : Vendredi 8 juillet 2016 16h27
> Objet : Re: Query : get all groups of a user
>
>Shoot, searching since hours, and think I just found a ways,something
>like [1] should do the trick.
>I'll update the thread once it works ;)
>Thanks
>
>[1]
>List<Integer> groupKeys = new ArrayList<Integer>();
>for (Membership membership : userTO.getMemberships) {  if
>(""GROUP".equals (membership.getRightType()) {
>groupKeys.add(membership.getRightKey());  }
>}GroupFiqlSearchConditionBuilder fiql =
>SyncopeClient.getGroupSearchConditionBuilder();for (int key : keys) {
>fiql.or("key").equalTo(key);}
>new AnySearchQuery.Builder().realm(SyncopeConstants.ROOT_REALM)
>                        .fiql(fiql.query())
>                        .build()
>
> De : Adrian Gonzalez <[email protected] <mailto:[email protected]>> > À : "[email protected] <mailto:[email protected]>" <[email protected] <mailto:[email protected]>>
> Envoyé le : Vendredi 8 juillet 2016 16h14
> Objet : Query : get all groups of a user
>
>Hello,
>Sorry, I'm a bit stuck, should be easy, but I don't find.
>How can I get all the groups (and their scimid atribute) of a User with
>a single call to syncope ?I'm using syncope Client API and have already
>an instance of UserTO.
>From what I see, in userTO I have the memberships, but I can't get the
>group's scimid from there.
>I'm having a look at
>https://github.com/apache/syncope/blob/master/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SearchITCase.java,
>but no inspiration.
>Thanks,Adrian

--
Francesco Chicchiriccò

Tirasa - Open Source Excellence
http://www.tirasa.net/

Involved at The Apache Software Foundation:
member, Syncope PMC chair, Cocoon PMC, Olingo PMC,
CXF Committer, OpenJPA Committer, PonyMail PPMC
http://home.apache.org/~ilgrosso/

Reply via email to