use of cz.metacentrum.perun.audit.events.FacilityManagerEvents.FacilityCreated in project perun by CESNET.
the class FacilitiesManagerBlImpl method createFacility.
@Override
public Facility createFacility(PerunSession sess, Facility facility) throws FacilityExistsException {
// check facility name, it can contain only a-zA-Z.0-9_-
if (!facility.getName().matches("^[ a-zA-Z.0-9_-]+$")) {
throw new IllegalArgumentException("Wrong facility name, facility name can contain only a-Z0-9.-_ and space characters");
}
// check if facility have uniq name
try {
this.getFacilityByName(sess, facility.getName());
throw new FacilityExistsException(facility);
} catch (FacilityNotExistsException ex) {
/* OK */
}
// create facility
facility = getFacilitiesManagerImpl().createFacility(sess, facility);
getPerunBl().getAuditer().log(sess, new FacilityCreated(facility));
// set creator as Facility manager
if (sess.getPerunPrincipal().getUser() != null) {
try {
AuthzResolverBlImpl.setRole(sess, sess.getPerunPrincipal().getUser(), facility, Role.FACILITYADMIN);
} catch (AlreadyAdminException ex) {
throw new ConsistencyErrorException("Add manager to newly created Facility failed because there is particular manager already assigned", ex);
} catch (RoleCannotBeManagedException e) {
throw new InternalErrorException(e);
}
} else {
log.warn("Can't set Facility manager during creating of the Facility. User from perunSession is null. {} {}", facility, sess);
}
return facility;
}
use of cz.metacentrum.perun.audit.events.FacilityManagerEvents.FacilityCreated in project perun by CESNET.
the class AuditMessagesManagerEntryIntegrationTest method setUp.
/**
*/
@Before
public void setUp() {
Facility testFacility = new Facility(0, "AuditMessageManagerEntryIntegrationTestFacility");
FacilityCreated facilityCreatedEvent = new FacilityCreated(testFacility);
createdAuditMessage.setEvent(facilityCreatedEvent);
}
use of cz.metacentrum.perun.audit.events.FacilityManagerEvents.FacilityCreated in project perun by CESNET.
the class AuditerImplIntegrationTest method logMessage.
@Test
public void logMessage() throws Exception {
System.out.println("AuditerTest.logMessage");
perun.getAuditer().clean();
Facility testFacility = new Facility(0, "AuditorTestFacility");
FacilityCreated facilityCreatedEvent = new FacilityCreated(testFacility);
perun.getAuditer().log(sess, facilityCreatedEvent);
perun.getAuditer().flush();
List<AuditMessage> messages = perun.getAuditMessagesManagerBl().getMessagesByCount(sess, 1);
assertEquals("Invalid number of messages.", 1, messages.size());
assertEquals("Invalid number of messages.", facilityCreatedEvent, messages.get(0).getEvent());
}
use of cz.metacentrum.perun.audit.events.FacilityManagerEvents.FacilityCreated in project perun by CESNET.
the class AuditerImplIntegrationTest method getCorrectMessages.
@Test
public void getCorrectMessages() throws Exception {
System.out.println("AuditerTest.getCorrectMessages");
perun.getAuditer().clean();
Facility testFacility = new Facility(0, "AuditorTestFacility");
FacilityCreated facilityCreatedEvent = new FacilityCreated(testFacility);
perun.getAuditer().log(sess, facilityCreatedEvent);
perun.getAuditer().flush();
List<AuditMessage> messages = perun.getAuditMessagesManagerBl().getMessagesByCount(sess, 1);
assertEquals("Invalid number of messages.", 1, messages.size());
assertEquals(facilityCreatedEvent, messages.get(0).getEvent());
// assertTrue("Invalid message received.", messages.get(0).getEvent().getMessage().contains("\"message\":\"Facility created Facility:"));
}
Aggregations