Search in sources :

Example 6 with RichUser

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

the class FacilitiesManagerEntryIntegrationTest method removeAdmin.

@Test
public void removeAdmin() throws Exception {
    System.out.println(CLASS_NAME + "removeAdmin");
    final Member member = setUpMember(vo);
    User u = perun.getUsersManagerBl().getUserByMember(sess, member);
    final RichUser richUser = new RichUser(u, perun.getUsersManagerBl().getUserExtSources(sess, u));
    facilitiesManagerEntry.addAdmin(sess, facility, u);
    assertTrue(facilitiesManagerEntry.getAdmins(sess, facility).contains(u));
    facilitiesManagerEntry.removeAdmin(sess, facility, u);
    assertFalse(facilitiesManagerEntry.getAdmins(sess, facility).contains(u));
}
Also used : User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) RichUser(cz.metacentrum.perun.core.api.RichUser) Member(cz.metacentrum.perun.core.api.Member) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 7 with RichUser

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

the class FacilitiesManagerBlImpl method removeFacilityContact.

@Override
public void removeFacilityContact(PerunSession sess, ContactGroup contactGroupToRemove) throws InternalErrorException {
    if (contactGroupToRemove != null) {
        if (contactGroupToRemove.getUsers() != null) {
            List<Integer> usersId = new ArrayList<>();
            for (RichUser user : contactGroupToRemove.getUsers()) {
                usersId.add(user.getId());
                this.facilitiesManagerImpl.removeFacilityContact(sess, contactGroupToRemove.getFacility(), contactGroupToRemove.getName(), user);
            }
            sess.getPerun().getAuditer().log(sess, "Users (" + usersId.toString() + ") successfully removed from contact group " + contactGroupToRemove.toString() + ".");
        }
        if (contactGroupToRemove.getGroups() != null) {
            List<Integer> groupsId = new ArrayList<>();
            for (Group group : contactGroupToRemove.getGroups()) {
                groupsId.add(group.getId());
                this.facilitiesManagerImpl.removeFacilityContact(sess, contactGroupToRemove.getFacility(), contactGroupToRemove.getName(), group);
            }
            sess.getPerun().getAuditer().log(sess, "Groups (" + groupsId.toString() + ") successfully removed from contact group " + contactGroupToRemove.toString() + ".");
        }
        if (contactGroupToRemove.getOwners() != null) {
            List<Integer> ownersId = new ArrayList<>();
            for (Owner owner : contactGroupToRemove.getOwners()) {
                ownersId.add(owner.getId());
                this.facilitiesManagerImpl.removeFacilityContact(sess, contactGroupToRemove.getFacility(), contactGroupToRemove.getName(), owner);
            }
            sess.getPerun().getAuditer().log(sess, "Owners (" + ownersId.toString() + ") successfully removed from contact group " + contactGroupToRemove.toString() + ".");
        }
    }
}
Also used : Group(cz.metacentrum.perun.core.api.Group) ContactGroup(cz.metacentrum.perun.core.api.ContactGroup) Owner(cz.metacentrum.perun.core.api.Owner) RichUser(cz.metacentrum.perun.core.api.RichUser) ArrayList(java.util.ArrayList)

Example 8 with RichUser

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

the class VosManagerBlImpl method getRichAdmins.

@Override
public List<RichUser> getRichAdmins(PerunSession perunSession, Vo vo, Role role, List<String> specificAttributes, boolean allUserAttributes, boolean onlyDirectAdmins) throws InternalErrorException, UserNotExistsException {
    List<User> users = this.getAdmins(perunSession, vo, role, onlyDirectAdmins);
    List<RichUser> richUsers;
    if (allUserAttributes) {
        richUsers = perunBl.getUsersManagerBl().getRichUsersWithAttributesFromListOfUsers(perunSession, users);
    } else {
        try {
            richUsers = getPerunBl().getUsersManagerBl().convertUsersToRichUsersWithAttributes(perunSession, perunBl.getUsersManagerBl().getRichUsersFromListOfUsers(perunSession, users), getPerunBl().getAttributesManagerBl().getAttributesDefinition(perunSession, specificAttributes));
        } catch (AttributeNotExistsException ex) {
            throw new InternalErrorException("One of Attribute not exist.", ex);
        }
    }
    return richUsers;
}
Also used : RichUser(cz.metacentrum.perun.core.api.RichUser) User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 9 with RichUser

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

the class ExtSourcePerun method findRichUser.

private RichUser findRichUser(String login) throws InternalErrorException, SubjectNotExistsException {
    Map<String, Object> params = new HashMap<String, Object>();
    List<RichUser> richUsers = this.findRichUsers(login);
    List<RichUser> matchesRichUsers = new ArrayList<>();
    for (RichUser richUser : richUsers) {
        List<UserExtSource> userExtSources = richUser.getUserExtSources();
        for (UserExtSource userExtSource : userExtSources) {
            if (extSourceNameForLogin.equals(userExtSource.getExtSource().getName())) {
                if (login.equals(userExtSource.getLogin()))
                    matchesRichUsers.add(richUser);
            }
        }
    }
    if (matchesRichUsers.isEmpty())
        throw new SubjectNotExistsException("There is no subject with login " + login + " in extSource " + extSourceNameForLogin + " in System perun with RPC url: " + perunUrl);
    if (matchesRichUsers.size() > 1)
        throw new InternalErrorException("There are more then one subject with login " + login + " in extSource " + extSourceNameForLogin + " in System perun with RPC url: " + perunUrl);
    return richUsers.get(0);
}
Also used : HashMap(java.util.HashMap) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) RichUser(cz.metacentrum.perun.core.api.RichUser) ArrayList(java.util.ArrayList) SubjectNotExistsException(cz.metacentrum.perun.core.api.exceptions.SubjectNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 10 with RichUser

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

the class ExtSourcePerun method findRichUsers.

private List<RichUser> findRichUsers(String substring) throws InternalErrorException {
    String query;
    try {
        // encode query params
        query = "searchString=" + URLEncoder.encode(substring, "UTF-8");
    } catch (UnsupportedEncodingException ex) {
        // sent query params not encoded
        query = "searchString=" + substring;
    }
    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) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PerunException(cz.metacentrum.perun.core.api.exceptions.PerunException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Aggregations

RichUser (cz.metacentrum.perun.core.api.RichUser)15 ContactGroup (cz.metacentrum.perun.core.api.ContactGroup)9 User (cz.metacentrum.perun.core.api.User)7 Group (cz.metacentrum.perun.core.api.Group)6 ArrayList (java.util.ArrayList)6 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)5 Member (cz.metacentrum.perun.core.api.Member)5 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)5 Test (org.junit.Test)5 Owner (cz.metacentrum.perun.core.api.Owner)4 UserExtSource (cz.metacentrum.perun.core.api.UserExtSource)2 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)2 RichMember (cz.metacentrum.perun.core.api.RichMember)1 PerunException (cz.metacentrum.perun.core.api.exceptions.PerunException)1 SubjectNotExistsException (cz.metacentrum.perun.core.api.exceptions.SubjectNotExistsException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashMap (java.util.HashMap)1