Search in sources :

Example 1 with FacilityCreated

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;
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) FacilityCreated(cz.metacentrum.perun.audit.events.FacilityManagerEvents.FacilityCreated) FacilityExistsException(cz.metacentrum.perun.core.api.exceptions.FacilityExistsException) FacilityNotExistsException(cz.metacentrum.perun.core.api.exceptions.FacilityNotExistsException) RoleCannotBeManagedException(cz.metacentrum.perun.core.api.exceptions.RoleCannotBeManagedException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) IllegalArgumentException(cz.metacentrum.perun.core.api.exceptions.IllegalArgumentException) AlreadyAdminException(cz.metacentrum.perun.core.api.exceptions.AlreadyAdminException)

Example 2 with FacilityCreated

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);
}
Also used : FacilityCreated(cz.metacentrum.perun.audit.events.FacilityManagerEvents.FacilityCreated) Facility(cz.metacentrum.perun.core.api.Facility) Before(org.junit.Before)

Example 3 with FacilityCreated

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());
}
Also used : AuditMessage(cz.metacentrum.perun.core.api.AuditMessage) FacilityCreated(cz.metacentrum.perun.audit.events.FacilityManagerEvents.FacilityCreated) Facility(cz.metacentrum.perun.core.api.Facility) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 4 with FacilityCreated

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:"));
}
Also used : AuditMessage(cz.metacentrum.perun.core.api.AuditMessage) FacilityCreated(cz.metacentrum.perun.audit.events.FacilityManagerEvents.FacilityCreated) Facility(cz.metacentrum.perun.core.api.Facility) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Aggregations

FacilityCreated (cz.metacentrum.perun.audit.events.FacilityManagerEvents.FacilityCreated)4 Facility (cz.metacentrum.perun.core.api.Facility)3 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)2 AuditMessage (cz.metacentrum.perun.core.api.AuditMessage)2 Test (org.junit.Test)2 AlreadyAdminException (cz.metacentrum.perun.core.api.exceptions.AlreadyAdminException)1 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)1 FacilityExistsException (cz.metacentrum.perun.core.api.exceptions.FacilityExistsException)1 FacilityNotExistsException (cz.metacentrum.perun.core.api.exceptions.FacilityNotExistsException)1 IllegalArgumentException (cz.metacentrum.perun.core.api.exceptions.IllegalArgumentException)1 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)1 RoleCannotBeManagedException (cz.metacentrum.perun.core.api.exceptions.RoleCannotBeManagedException)1 Before (org.junit.Before)1