Last active
July 18, 2016 10:53
-
-
Save ilgrosso/3d56e9c57db283bfaef0068bdbc9b697 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.commons.collections4.CollectionUtils; | |
import org.apache.commons.collections4.Transformer; | |
import org.apache.commons.collections4.list.SetUniqueList; | |
// Given this user... | |
UserTO userTO = ... | |
List<String> groupKeys = SetUniqueList.setUniqueList(new ArrayList<String>()); | |
// First statically assigned groups... | |
CollectionUtils.collect(userTO.getMemberships(), new Transformer<MembershipTO, String>() { | |
@Override | |
public String transform(final MembershipTO input) { | |
return input.getGroupKey(); | |
} | |
}, groupKeys); | |
// ...then dinamically assigned groups | |
groupKeys.addAll(userTO.getDynGroups()); | |
if (!groupKeys.isEmpty()) { | |
String fiql; | |
if (groupKeys.size() == 1) { | |
fiql = SyncopeClient.getGroupSearchConditionBuilder(). | |
is("key"). | |
equalTo(groupKeys.get(0)). | |
query(); | |
} else { | |
fiql = SyncopeClient.getGroupSearchConditionBuilder(). | |
is("key"). | |
equalTo(groupKeys.get(0), | |
groupKeys.subList(1, groupKeys.size() - 1).toArray(new String[groupKeys.size() - 1])). | |
query(); | |
} | |
// without page / size parameters in the AnyQuery instance above, this will only | |
// return the first 25 groups at most | |
PagedResult<GroupTO> result = syncopeClient.getService(GroupService.class).search( | |
new AnyQuery.Builder(). | |
realm(SyncopeConstants.ROOT_REALM). | |
fiql(fiql). | |
build()); | |
List<GroupTO> groups = result.getResult(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@gonzalad fixed, thanks for reporting