Search in sources :

Example 1 with RichUser

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);
        }
    }
}
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)

Example 2 with RichUser

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;
}
Also used : RichUser(cz.metacentrum.perun.core.api.RichUser) ArrayList(java.util.ArrayList) RichMember(cz.metacentrum.perun.core.api.RichMember)

Example 3 with RichUser

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;
}
Also used : RichUser(cz.metacentrum.perun.core.api.RichUser) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) ContactGroup(cz.metacentrum.perun.core.api.ContactGroup)

Example 4 with RichUser

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;
}
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) ContactGroup(cz.metacentrum.perun.core.api.ContactGroup)

Example 5 with RichUser

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());
}
Also used : Group(cz.metacentrum.perun.core.api.Group) ContactGroup(cz.metacentrum.perun.core.api.ContactGroup) User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) RichUser(cz.metacentrum.perun.core.api.RichUser) ContactGroup(cz.metacentrum.perun.core.api.ContactGroup) Member(cz.metacentrum.perun.core.api.Member) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

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