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