use of cz.metacentrum.perun.core.api.RichUser in project perun by CESNET.
the class FacilitiesManagerEntry method checkFacilityContactEntitiesExists.
/**
* Check existence of every entity in contactGroup
*
* @param sess
* @param contactGroup
* @throws FacilityNotExistsException
* @throws UserNotExistsException
* @throws OwnerNotExistsException
* @throws GroupNotExistsException
* @throws InternalErrorException
*/
private void checkFacilityContactEntitiesExists(PerunSession sess, ContactGroup contactGroup) throws FacilityNotExistsException, UserNotExistsException, OwnerNotExistsException, GroupNotExistsException, InternalErrorException {
Utils.notNull(contactGroup, "contactGroup");
Utils.notNull(contactGroup.getFacility(), "facility");
Utils.notNull(contactGroup.getName(), "name");
this.getFacilitiesManagerBl().checkFacilityExists(sess, contactGroup.getFacility());
if (contactGroup.getUsers() != null) {
for (RichUser user : contactGroup.getUsers()) {
getPerunBl().getUsersManagerBl().checkUserExists(sess, user);
}
}
if (contactGroup.getGroups() != null) {
for (Group group : contactGroup.getGroups()) {
getPerunBl().getGroupsManagerBl().checkGroupExists(sess, group);
}
}
if (contactGroup.getOwners() != null) {
for (Owner owner : contactGroup.getOwners()) {
getPerunBl().getOwnersManagerBl().checkOwnerExists(sess, owner);
}
}
}
use of cz.metacentrum.perun.core.api.RichUser in project perun by CESNET.
the class ExtSourcePerun method convertListOfRichMembersToListOfRichUsers.
private List<RichUser> convertListOfRichMembersToListOfRichUsers(List<RichMember> richMembers) throws InternalErrorException {
List<RichUser> richUsers = new ArrayList<>();
if (richMembers == null || richMembers.isEmpty())
return richUsers;
for (RichMember rm : richMembers) {
RichUser ru = new RichUser(rm.getUser(), rm.getUserExtSources(), rm.getUserAttributes());
richUsers.add(ru);
}
return richUsers;
}
use of cz.metacentrum.perun.core.api.RichUser in project perun by CESNET.
the class FacilitiesManagerImpl method addFacilityContact.
// FACILITY CONTACTS METHODS
@Override
public ContactGroup addFacilityContact(PerunSession sess, Facility facility, String name, User user) throws InternalErrorException {
Utils.notNull(facility, "facility");
Utils.notNull(user, "user");
if (name == null || name.isEmpty()) {
throw new InternalErrorException("ContactGroupName can't be null or empty.");
}
ContactGroup contactGroup;
try {
jdbc.update("insert into facility_contacts(facility_id, name, user_id) " + "values (?,?,?)", facility.getId(), name, user.getId());
RichUser ru = new RichUser(user, null);
List<RichUser> rulist = new ArrayList<>();
rulist.add(ru);
contactGroup = new ContactGroup(name, facility, new ArrayList<Group>(), new ArrayList<Owner>(), rulist);
log.info("Facility contact {} created", contactGroup);
} catch (RuntimeException ex) {
throw new InternalErrorException(ex);
}
return contactGroup;
}
use of cz.metacentrum.perun.core.api.RichUser in project perun by CESNET.
the class FacilitiesManagerImpl method mergeContactGroups.
/**
* Take list of contact groups and merged them.
*
* Merge means:
* If two groups are from the same facility with the same contactName join
* them to the one with groups, owners and users from both.
*
* @param notMergedContactGroups list of groups to merge
* @return list of merged contact groups
*/
private List<ContactGroup> mergeContactGroups(List<ContactGroup> notMergedContactGroups) {
List<ContactGroup> mergedContactGroups = new ArrayList<>();
while (!notMergedContactGroups.isEmpty()) {
ContactGroup contactGroup = new ContactGroup();
Iterator<ContactGroup> contactGroupIter = notMergedContactGroups.iterator();
boolean first = true;
while (contactGroupIter.hasNext()) {
if (first) {
contactGroup = contactGroupIter.next();
if (contactGroup.getGroups() == null)
contactGroup.setGroups(new ArrayList<Group>());
if (contactGroup.getOwners() == null)
contactGroup.setOwners(new ArrayList<Owner>());
if (contactGroup.getUsers() == null)
contactGroup.setUsers(new ArrayList<RichUser>());
first = false;
} else {
ContactGroup cp = contactGroupIter.next();
//if same facility and same name merge them
if (contactGroup.equalsGroup(cp)) {
List<Group> groups = new ArrayList<>();
groups.addAll(contactGroup.getGroups());
groups.addAll(cp.getGroups());
contactGroup.setGroups(groups);
List<Owner> owners = new ArrayList<>();
owners.addAll(contactGroup.getOwners());
owners.addAll(cp.getOwners());
contactGroup.setOwners(owners);
List<RichUser> users = new ArrayList<>();
users.addAll(contactGroup.getUsers());
users.addAll(cp.getUsers());
contactGroup.setUsers(users);
// if not, skip this one for another round
} else
continue;
}
//remove used groups of contacts
contactGroupIter.remove();
}
mergedContactGroups.add(contactGroup);
}
return mergedContactGroups;
}
use of cz.metacentrum.perun.core.api.RichUser in project perun by CESNET.
the class FacilitiesManagerEntryIntegrationTest method addFacilityContactForAll2.
@Test
public void addFacilityContactForAll2() throws Exception {
System.out.println(CLASS_NAME + "addFacilityContactForAll2");
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);
List<ContactGroup> cgs = facilitiesManagerEntry.getFacilityContactGroups(sess, facility);
assertTrue(cg.equals(cgs.get(0)));
assertEquals(owner.getId(), cgs.get(0).getOwners().get(0).getId());
assertEquals(group.getId(), cgs.get(0).getGroups().get(0).getId());
assertEquals(user.getId(), cgs.get(0).getUsers().get(0).getId());
}
Aggregations