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));
}
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() + ".");
}
}
}
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;
}
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);
}
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;
}
Aggregations