Search in sources :

Example 21 with ContactGroup

use of cz.metacentrum.perun.core.api.ContactGroup 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() + ".");
        }
    }
}
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 22 with ContactGroup

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

the class FacilitiesManagerBlImpl method deleteFacility.

public void deleteFacility(PerunSession sess, Facility facility) throws InternalErrorException, RelationExistsException, FacilityAlreadyRemovedException, HostAlreadyRemovedException, GroupAlreadyRemovedException, ResourceAlreadyRemovedException, GroupAlreadyRemovedFromResourceException {
    if (getFacilitiesManagerImpl().getAssignedResources(sess, facility).size() > 0) {
        throw new RelationExistsException("Facility is still used as a resource");
    }
    //remove hosts
    List<Host> hosts = this.getHosts(sess, facility);
    for (Host host : hosts) {
        this.removeHost(sess, host);
    }
    //remove destinations
    getPerunBl().getServicesManagerBl().removeAllDestinations(sess, facility);
    // remove assigned security teams
    List<SecurityTeam> teams = getAssignedSecurityTeams(sess, facility);
    for (SecurityTeam team : teams) {
        removeSecurityTeam(sess, facility, team);
    }
    // remove assigned facility contacts
    List<ContactGroup> contacts = getFacilityContactGroups(sess, facility);
    if (contacts != null && !contacts.isEmpty()) {
        removeFacilityContacts(sess, contacts);
    }
    // remove associated attributes
    try {
        getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, facility);
    } catch (WrongAttributeValueException e) {
        throw new InternalErrorException(e);
    } catch (WrongReferenceAttributeValueException e) {
        throw new InternalErrorException(e);
    }
    //Remove all facility bans
    List<BanOnFacility> bansOnFacility = this.getBansForFacility(sess, facility.getId());
    for (BanOnFacility banOnFacility : bansOnFacility) {
        try {
            this.removeBan(sess, banOnFacility.getId());
        } catch (BanNotExistsException ex) {
        //it is ok, we just want to remove it anyway
        }
    }
    // delete facility
    getFacilitiesManagerImpl().deleteFacilityOwners(sess, facility);
    getFacilitiesManagerImpl().deleteFacility(sess, facility);
    getPerunBl().getAuditer().log(sess, "Facility deleted {}.", facility);
}
Also used : Host(cz.metacentrum.perun.core.api.Host) SecurityTeam(cz.metacentrum.perun.core.api.SecurityTeam) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) BanOnFacility(cz.metacentrum.perun.core.api.BanOnFacility) ContactGroup(cz.metacentrum.perun.core.api.ContactGroup) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) BanNotExistsException(cz.metacentrum.perun.core.api.exceptions.BanNotExistsException)

Example 23 with ContactGroup

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

the class FacilitiesManagerEntryIntegrationTest method addFacilityContactForGroup.

@Test
public void addFacilityContactForGroup() throws Exception {
    System.out.println(CLASS_NAME + "addFacilityContactForGroup");
    Member member = setUpMember(vo);
    Group group = setUpGroup(vo, member);
    String contactGroupName = "testContactGroup01";
    ContactGroup cg = new ContactGroup(contactGroupName, facility);
    cg.setGroups(new ArrayList<>(Arrays.asList(group)));
    facilitiesManagerEntry.addFacilityContact(sess, cg);
    perun.getFacilitiesManagerBl().checkFacilityContactExists(sess, facility, contactGroupName, group);
    List<ContactGroup> cgs = facilitiesManagerEntry.getFacilityContactGroups(sess, group);
    assertTrue(cg.equalsGroup(cgs.get(0)));
    assertEquals(group.getId(), cgs.get(0).getGroups().get(0).getId());
}
Also used : Group(cz.metacentrum.perun.core.api.Group) ContactGroup(cz.metacentrum.perun.core.api.ContactGroup) 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 24 with ContactGroup

use of cz.metacentrum.perun.core.api.ContactGroup 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());
}
Also used : 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 25 with ContactGroup

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

the class FacilitiesManagerEntryIntegrationTest method removeFacilityContactForGroup.

@Test
public void removeFacilityContactForGroup() throws Exception {
    System.out.println(CLASS_NAME + "removeFacilityContactForGroup");
    Member member = setUpMember(vo);
    Group group = setUpGroup(vo, member);
    String contactGroupName = "testContactGroup01";
    ContactGroup cg = new ContactGroup(contactGroupName, facility);
    cg.setGroups(new ArrayList<>(Arrays.asList(group)));
    facilitiesManagerEntry.addFacilityContact(sess, cg);
    perun.getFacilitiesManagerBl().checkFacilityContactExists(sess, facility, contactGroupName, group);
    List<ContactGroup> cgs = facilitiesManagerEntry.getFacilityContactGroups(sess, group);
    assertTrue(cg.equalsGroup(cgs.get(0)));
    assertEquals(group.getId(), cgs.get(0).getGroups().get(0).getId());
    facilitiesManagerEntry.removeFacilityContact(sess, cg);
    cgs = facilitiesManagerEntry.getFacilityContactGroups(sess, group);
    assertTrue(cgs.isEmpty());
}
Also used : Group(cz.metacentrum.perun.core.api.Group) ContactGroup(cz.metacentrum.perun.core.api.ContactGroup) 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

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