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