Search in sources :

Example 11 with PerunException

use of cz.metacentrum.perun.core.api.exceptions.PerunException in project perun by CESNET.

the class ExtSourcePerun method findRichUsers.

private List<RichUser> findRichUsers(String substring) {
    String query;
    // encode query params
    query = "searchString=" + URLEncoder.encode(substring, StandardCharsets.UTF_8);
    List<RichUser> richUsers;
    try {
        richUsers = this.call("usersManager", "findRichUsers", query).readList(RichUser.class);
    } catch (PerunException ex) {
        throw new InternalErrorException(ex);
    }
    Iterator<RichUser> iterator = richUsers.iterator();
    while (iterator.hasNext()) {
        RichUser richUser = iterator.next();
        boolean hasLogin = false;
        for (UserExtSource ues : richUser.getUserExtSources()) {
            if (ues.getExtSource() != null && ues.getExtSource().getName().equals(extSourceNameForLogin)) {
                hasLogin = true;
                continue;
            }
        }
        if (!hasLogin)
            iterator.remove();
    }
    return richUsers;
}
Also used : UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) RichUser(cz.metacentrum.perun.core.api.RichUser) PerunException(cz.metacentrum.perun.core.api.exceptions.PerunException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 12 with PerunException

use of cz.metacentrum.perun.core.api.exceptions.PerunException in project perun by CESNET.

the class ExtSourcePerun method findRichUsers.

private List<RichUser> findRichUsers(Integer groupId) {
    // we don't need to encode query params here, no unsafe char in fixed string
    String query = "group=" + groupId + "&" + "allowedStatuses[]=" + "VALID";
    List<RichMember> richMembers;
    try {
        richMembers = this.call("membersManager", "getRichMembersWithAttributes", query).readList(RichMember.class);
    } catch (PerunException ex) {
        throw new InternalErrorException(ex);
    }
    return convertListOfRichMembersToListOfRichUsers(richMembers);
}
Also used : PerunException(cz.metacentrum.perun.core.api.exceptions.PerunException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) RichMember(cz.metacentrum.perun.core.api.RichMember)

Aggregations

PerunException (cz.metacentrum.perun.core.api.exceptions.PerunException)12 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)6 CabinetException (cz.metacentrum.perun.cabinet.bl.CabinetException)3 Attribute (cz.metacentrum.perun.core.api.Attribute)3 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)3 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)3 User (cz.metacentrum.perun.core.api.User)2 UserExtSource (cz.metacentrum.perun.core.api.UserExtSource)2 Vo (cz.metacentrum.perun.core.api.Vo)2 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)2 RpcException (cz.metacentrum.perun.core.api.exceptions.RpcException)2 PerunRuntimeException (cz.metacentrum.perun.core.api.exceptions.rt.PerunRuntimeException)2 PerunBl (cz.metacentrum.perun.core.bl.PerunBl)2 ArrayList (java.util.ArrayList)2 Authorship (cz.metacentrum.perun.cabinet.model.Authorship)1 Thanks (cz.metacentrum.perun.cabinet.model.Thanks)1 ThanksForGUI (cz.metacentrum.perun.cabinet.model.ThanksForGUI)1 Group (cz.metacentrum.perun.core.api.Group)1 Member (cz.metacentrum.perun.core.api.Member)1 PerunClient (cz.metacentrum.perun.core.api.PerunClient)1