Search in sources :

Example 6 with ContactGroup

use of cz.metacentrum.perun.core.api.ContactGroup 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)

Example 7 with ContactGroup

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

the class FacilitiesManagerEntryIntegrationTest method removeAllFacilityContacts.

@Test
public void removeAllFacilityContacts() throws Exception {
    System.out.println(CLASS_NAME + "removeAllFacilityContacts");
    String contactGroupName1 = "testContactGroup01";
    String contactGroupName2 = "testContactGroup02";
    String contactGroupName3 = "testContactGroup03";
    ContactGroup cg1 = new ContactGroup(contactGroupName1, facility);
    ContactGroup cg2 = new ContactGroup(contactGroupName2, facility);
    ContactGroup cg3 = new ContactGroup(contactGroupName3, facility);
    cg1.setOwners(new ArrayList<>(Arrays.asList(owner)));
    cg2.setOwners(new ArrayList<>(Arrays.asList(owner)));
    cg3.setOwners(new ArrayList<>(Arrays.asList(owner)));
    List<ContactGroup> cgs = new ArrayList<>(Arrays.asList(cg1, cg2, cg3));
    facilitiesManagerEntry.addFacilityContacts(sess, cgs);
    List<ContactGroup> cgnames = facilitiesManagerEntry.getFacilityContactGroups(sess, facility);
    assertTrue(cgnames.contains(cg1));
    assertTrue(cgnames.contains(cg2));
    assertTrue(cgnames.contains(cg3));
    facilitiesManagerEntry.removeFacilityContacts(sess, cgs);
    cgnames = facilitiesManagerEntry.getFacilityContactGroups(sess, facility);
    assertTrue(cgnames.isEmpty());
}
Also used : ArrayList(java.util.ArrayList) ContactGroup(cz.metacentrum.perun.core.api.ContactGroup) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 8 with ContactGroup

use of cz.metacentrum.perun.core.api.ContactGroup 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 9 with ContactGroup

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

the class OwnersManagerBlImpl method deleteOwner.

public void deleteOwner(PerunSession sess, Owner owner, boolean forceDelete) throws InternalErrorException, RelationExistsException, OwnerAlreadyRemovedException {
    // Check if the owner is assigned to some facility
    List<Facility> facilities = getPerunBl().getFacilitiesManagerBl().getOwnerFacilities(sess, owner);
    if (facilities != null && facilities.size() > 0) {
        if (!forceDelete) {
            throw new RelationExistsException("Owner own " + facilities.size() + " facilities");
        } else {
            for (Facility facility : facilities) {
                try {
                    getPerunBl().getFacilitiesManagerBl().removeOwner(sess, facility, owner);
                } catch (OwnerAlreadyRemovedException e) {
                    throw new InternalErrorException(e);
                }
            }
        }
    }
    //Remove all information about owner on facilities (facilities contacts)
    List<ContactGroup> ownerContactGroups = getPerunBl().getFacilitiesManagerBl().getFacilityContactGroups(sess, owner);
    if (!ownerContactGroups.isEmpty()) {
        if (forceDelete) {
            getPerunBl().getFacilitiesManagerBl().removeAllOwnerContacts(sess, owner);
        } else {
            throw new RelationExistsException("Owner has still some facilities contacts : " + ownerContactGroups);
        }
    }
    getOwnersManagerImpl().deleteOwner(sess, owner);
    getPerunBl().getAuditer().log(sess, "{} deleted.", owner);
}
Also used : RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) Facility(cz.metacentrum.perun.core.api.Facility) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) OwnerAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.OwnerAlreadyRemovedException) ContactGroup(cz.metacentrum.perun.core.api.ContactGroup)

Example 10 with ContactGroup

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

the class FacilitiesManagerBlImpl method removeAllGroupContacts.

@Override
public void removeAllGroupContacts(PerunSession sess, Group group) throws InternalErrorException {
    List<ContactGroup> contactGroups = getFacilityContactGroups(sess, group);
    this.facilitiesManagerImpl.removeAllGroupContacts(sess, group);
    for (ContactGroup contactGroup : contactGroups) {
        sess.getPerun().getAuditer().log(sess, "Group (" + group.getId() + ") successfully removed from contact groups " + contactGroup.toString() + ".");
    }
}
Also used : ContactGroup(cz.metacentrum.perun.core.api.ContactGroup)

Aggregations

ContactGroup (cz.metacentrum.perun.core.api.ContactGroup)26 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)10 Test (org.junit.Test)10 Group (cz.metacentrum.perun.core.api.Group)9 RichUser (cz.metacentrum.perun.core.api.RichUser)9 Member (cz.metacentrum.perun.core.api.Member)8 ArrayList (java.util.ArrayList)8 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)6 Owner (cz.metacentrum.perun.core.api.Owner)5 User (cz.metacentrum.perun.core.api.User)4 RelationExistsException (cz.metacentrum.perun.core.api.exceptions.RelationExistsException)2 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)1 BanOnFacility (cz.metacentrum.perun.core.api.BanOnFacility)1 Facility (cz.metacentrum.perun.core.api.Facility)1 Host (cz.metacentrum.perun.core.api.Host)1 SecurityTeam (cz.metacentrum.perun.core.api.SecurityTeam)1 BanNotExistsException (cz.metacentrum.perun.core.api.exceptions.BanNotExistsException)1 FacilityContactNotExistsException (cz.metacentrum.perun.core.api.exceptions.FacilityContactNotExistsException)1 OwnerAlreadyRemovedException (cz.metacentrum.perun.core.api.exceptions.OwnerAlreadyRemovedException)1 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)1