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