Search in sources :

Example 16 with ContactGroup

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

the class FacilitiesManagerImpl method addFacilityContact.

@Override
public ContactGroup addFacilityContact(PerunSession sess, Facility facility, String name, Owner owner) throws InternalErrorException {
    Utils.notNull(facility, "facility");
    Utils.notNull(owner, "owner");
    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, owner_id) " + "values (?,?,?)", facility.getId(), name, owner.getId());
        List<Owner> ownlist = new ArrayList<>();
        ownlist.add(owner);
        contactGroup = new ContactGroup(name, facility, new ArrayList<Group>(), ownlist, new ArrayList<RichUser>());
        log.info("Facility contact {} created", contactGroup);
    } catch (RuntimeException ex) {
        throw new InternalErrorException(ex);
    }
    return contactGroup;
}
Also used : Owner(cz.metacentrum.perun.core.api.Owner) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) ContactGroup(cz.metacentrum.perun.core.api.ContactGroup)

Example 17 with ContactGroup

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

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

the class FacilitiesManagerEntryIntegrationTest method removeFacilityContactForOwner.

@Test
public void removeFacilityContactForOwner() throws Exception {
    System.out.println(CLASS_NAME + "removeFacilityContactForOwner");
    Member member = setUpMember(vo);
    String contactGroupName = "testContactGroup01";
    ContactGroup cg = new ContactGroup(contactGroupName, facility);
    cg.setOwners(new ArrayList<>(Arrays.asList(owner)));
    facilitiesManagerEntry.addFacilityContact(sess, cg);
    perun.getFacilitiesManagerBl().checkFacilityContactExists(sess, facility, contactGroupName, owner);
    List<ContactGroup> cgs = facilitiesManagerEntry.getFacilityContactGroups(sess, owner);
    assertTrue(cg.equals(cgs.get(0)));
    assertEquals(owner.getId(), cgs.get(0).getOwners().get(0).getId());
    facilitiesManagerEntry.removeFacilityContact(sess, cg);
    cgs = facilitiesManagerEntry.getFacilityContactGroups(sess, owner);
    assertTrue(cgs.isEmpty());
}
Also used : 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 19 with ContactGroup

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

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

the class FacilitiesManagerEntryIntegrationTest method addFacilityContactForOwner.

@Test
public void addFacilityContactForOwner() throws Exception {
    System.out.println(CLASS_NAME + "addFacilityContactForOwner");
    Member member = setUpMember(vo);
    String contactGroupName = "testContactGroup01";
    ContactGroup cg = new ContactGroup(contactGroupName, facility);
    cg.setOwners(new ArrayList<>(Arrays.asList(owner)));
    facilitiesManagerEntry.addFacilityContact(sess, cg);
    perun.getFacilitiesManagerBl().checkFacilityContactExists(sess, facility, contactGroupName, owner);
    List<ContactGroup> cgs = facilitiesManagerEntry.getFacilityContactGroups(sess, owner);
    assertTrue(cg.equals(cgs.get(0)));
    assertEquals(owner.getId(), cgs.get(0).getOwners().get(0).getId());
}
Also used : 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