use of cz.metacentrum.perun.core.api.RichUser in project perun by CESNET.
the class FacilitiesManagerEntryIntegrationTest method removeFacilityContactForUser.
@Test
public void removeFacilityContactForUser() throws Exception {
System.out.println(CLASS_NAME + "removeFacilityContactForUser");
Member member = setUpMember(vo);
User user = perun.getUsersManagerBl().getUserByMember(sess, member);
String contactGroupName = "testContactGroup01";
ContactGroup cg = new ContactGroup(contactGroupName, facility);
RichUser richUser = new RichUser(user, null);
List<RichUser> users = perun.getUsersManagerBl().convertUsersToRichUsersWithAttributes(sess, Arrays.asList(richUser), getMandatoryAttrs());
cg.setUsers(new ArrayList<>(users));
facilitiesManagerEntry.addFacilityContact(sess, cg);
perun.getFacilitiesManagerBl().checkFacilityContactExists(sess, facility, contactGroupName, user);
List<ContactGroup> cgs = facilitiesManagerEntry.getFacilityContactGroups(sess, user);
assertTrue(cg.equals(cgs.get(0)));
assertEquals(user.getId(), cgs.get(0).getUsers().get(0).getId());
facilitiesManagerEntry.removeFacilityContact(sess, cg);
cgs = facilitiesManagerEntry.getFacilityContactGroups(sess, user);
assertTrue(cgs.isEmpty());
}
use of cz.metacentrum.perun.core.api.RichUser in project perun by CESNET.
the class FacilitiesManagerEntryIntegrationTest method addFacilityContactForAll1.
@Test
public void addFacilityContactForAll1() throws Exception {
System.out.println(CLASS_NAME + "addFacilityContactForAll1");
Member member = setUpMember(vo);
Group group = setUpGroup(vo, member);
User user = perun.getUsersManagerBl().getUserByMember(sess, member);
String contactGroupName = "testContactGroup01";
ContactGroup cg = new ContactGroup(contactGroupName, facility);
cg.setOwners(new ArrayList<>(Arrays.asList(owner)));
cg.setGroups(new ArrayList<>(Arrays.asList(group)));
RichUser richUser = new RichUser(user, null);
List<RichUser> users = perun.getUsersManagerBl().convertUsersToRichUsersWithAttributes(sess, Arrays.asList(richUser), getMandatoryAttrs());
cg.setUsers(new ArrayList<>(users));
facilitiesManagerEntry.addFacilityContact(sess, cg);
ContactGroup cgReturned = facilitiesManagerEntry.getFacilityContactGroup(sess, facility, contactGroupName);
assertTrue(cg.equals(cgReturned));
assertEquals(owner.getId(), cgReturned.getOwners().get(0).getId());
assertEquals(group.getId(), cgReturned.getGroups().get(0).getId());
assertEquals(user.getId(), cgReturned.getUsers().get(0).getId());
}
use of cz.metacentrum.perun.core.api.RichUser in project perun by CESNET.
the class FacilitiesManagerBlImpl method addFacilityContact.
@Override
public void addFacilityContact(PerunSession sess, ContactGroup contactGroupToAdd) throws InternalErrorException {
if (contactGroupToAdd != null) {
if (contactGroupToAdd.getUsers() != null) {
List<Integer> usersId = new ArrayList<>();
for (RichUser user : contactGroupToAdd.getUsers()) {
usersId.add(user.getId());
this.facilitiesManagerImpl.addFacilityContact(sess, contactGroupToAdd.getFacility(), contactGroupToAdd.getName(), user);
}
sess.getPerun().getAuditer().log(sess, "Users (" + usersId.toString() + ") successfully added to contact group " + contactGroupToAdd.toString() + ".");
}
if (contactGroupToAdd.getGroups() != null) {
List<Integer> groupsId = new ArrayList<>();
for (Group group : contactGroupToAdd.getGroups()) {
groupsId.add(group.getId());
this.facilitiesManagerImpl.addFacilityContact(sess, contactGroupToAdd.getFacility(), contactGroupToAdd.getName(), group);
}
sess.getPerun().getAuditer().log(sess, "Groups (" + groupsId.toString() + ") successfully added to contact group " + contactGroupToAdd.toString() + ".");
}
if (contactGroupToAdd.getOwners() != null) {
List<Integer> ownersId = new ArrayList<>();
for (Owner owner : contactGroupToAdd.getOwners()) {
ownersId.add(owner.getId());
this.facilitiesManagerImpl.addFacilityContact(sess, contactGroupToAdd.getFacility(), contactGroupToAdd.getName(), owner);
}
sess.getPerun().getAuditer().log(sess, "Owners (" + ownersId.toString() + ") successfully added to contact group " + contactGroupToAdd.toString() + ".");
}
}
}
use of cz.metacentrum.perun.core.api.RichUser in project perun by CESNET.
the class FacilitiesManagerBlImpl method getRichAdmins.
public List<RichUser> getRichAdmins(PerunSession perunSession, Facility facility, List<String> specificAttributes, boolean allUserAttributes, boolean onlyDirectAdmins) throws InternalErrorException, UserNotExistsException {
List<User> users = this.getAdmins(perunSession, facility, 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 FacilitiesManagerEntryIntegrationTest method addFacilityContactForUser.
// FACILITY CONTACTS TEST METHODS
@Test
public void addFacilityContactForUser() throws Exception {
System.out.println(CLASS_NAME + "addFacilityContactForUser");
Member member = setUpMember(vo);
User user = perun.getUsersManagerBl().getUserByMember(sess, member);
String contactGroupName = "testContactGroup01";
ContactGroup cg = new ContactGroup(contactGroupName, facility);
RichUser richUser = new RichUser(user, null);
List<RichUser> users = perun.getUsersManagerBl().convertUsersToRichUsersWithAttributes(sess, Arrays.asList(richUser), getMandatoryAttrs());
cg.setUsers(new ArrayList<>(users));
facilitiesManagerEntry.addFacilityContact(sess, cg);
perun.getFacilitiesManagerBl().checkFacilityContactExists(sess, facility, contactGroupName, user);
List<ContactGroup> cgs = facilitiesManagerEntry.getFacilityContactGroups(sess, user);
assertTrue(cg.equals(cgs.get(0)));
assertEquals(user.getId(), cgs.get(0).getUsers().get(0).getId());
}
Aggregations