Search in sources :

Example 1 with SponsorshipExpired

use of cz.metacentrum.perun.audit.events.ExpirationNotifScheduler.SponsorshipExpired in project perun by CESNET.

the class AuditMessagesManagerEntryIntegrationTest method testLocalDate.

@Test
public void testLocalDate() throws Exception {
    System.out.println(CLASS_NAME + "testLocalDate");
    AuditMessagesManagerImpl auditMessagesManagerImpl = (AuditMessagesManagerImpl) ReflectionTestUtils.getField(perun.getAuditMessagesManagerBl(), "auditMessagesManagerImpl");
    assertThat(auditMessagesManagerImpl).isNotNull();
    ObjectMapper mapper = (ObjectMapper) ReflectionTestUtils.getField(auditMessagesManagerImpl, "mapper");
    assertThat(mapper).isNotNull();
    AuditEvent event = new SponsorshipEstablished(null, null, LocalDate.MIN);
    testAuditEventMapper(mapper, event);
    EnrichedSponsorship enrichedSponsorship = new EnrichedSponsorship();
    enrichedSponsorship.setValidityTo(LocalDate.MAX);
    AuditEvent event2 = new SponsorshipExpired();
    testAuditEventMapper(mapper, event2);
}
Also used : SponsorshipEstablished(cz.metacentrum.perun.audit.events.MembersManagerEvents.SponsorshipEstablished) EnrichedSponsorship(cz.metacentrum.perun.core.api.EnrichedSponsorship) SponsorshipExpired(cz.metacentrum.perun.audit.events.ExpirationNotifScheduler.SponsorshipExpired) AuditMessagesManagerImpl(cz.metacentrum.perun.core.impl.AuditMessagesManagerImpl) AuditEvent(cz.metacentrum.perun.audit.events.AuditEvent) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 2 with SponsorshipExpired

use of cz.metacentrum.perun.audit.events.ExpirationNotifScheduler.SponsorshipExpired in project perun by CESNET.

the class ExpirationNotifScheduler method expireSponsorship.

/**
 * Cancel given sponsorship and log the SponsorshipExpired audit event.
 *
 * @param sponsorship sponsorship to be cancelled
 */
private void expireSponsorship(Sponsorship sponsorship) {
    try {
        Member member = perun.getMembersManagerBl().getMemberById(sess, sponsorship.getSponsoredId());
        User sponsor = perun.getUsersManagerBl().getUserById(sess, sponsorship.getSponsorId());
        perun.getMembersManagerBl().removeSponsor(sess, member, sponsor);
        perun.getAuditer().log(sess, new SponsorshipExpired(convertSponsorshipToEnriched(sponsorship)));
    } catch (MemberNotExistsException | UserNotExistsException e) {
        log.error("Failed to expire sponsorship. Sponsorship: {}", sponsorship, e);
    }
}
Also used : User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) MemberNotExistsException(cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) SponsorshipExpired(cz.metacentrum.perun.audit.events.ExpirationNotifScheduler.SponsorshipExpired) Member(cz.metacentrum.perun.core.api.Member)

Aggregations

SponsorshipExpired (cz.metacentrum.perun.audit.events.ExpirationNotifScheduler.SponsorshipExpired)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 AuditEvent (cz.metacentrum.perun.audit.events.AuditEvent)1 SponsorshipEstablished (cz.metacentrum.perun.audit.events.MembersManagerEvents.SponsorshipEstablished)1 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)1 EnrichedSponsorship (cz.metacentrum.perun.core.api.EnrichedSponsorship)1 Member (cz.metacentrum.perun.core.api.Member)1 RichUser (cz.metacentrum.perun.core.api.RichUser)1 User (cz.metacentrum.perun.core.api.User)1 MemberNotExistsException (cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException)1 UserNotExistsException (cz.metacentrum.perun.core.api.exceptions.UserNotExistsException)1 AuditMessagesManagerImpl (cz.metacentrum.perun.core.impl.AuditMessagesManagerImpl)1 Test (org.junit.Test)1