Search in sources :

Example 1 with Sponsorship

use of cz.metacentrum.perun.core.api.Sponsorship in project perun by CESNET.

the class MembersManagerBlImpl method convertUserToSponsor.

@Override
public Sponsor convertUserToSponsor(PerunSession sess, User user, Member sponsoredMember) {
    Sponsor sponsor = new Sponsor(user);
    Sponsorship sponsorship;
    try {
        sponsorship = perunBl.getMembersManagerBl().getSponsorship(sess, sponsoredMember, user);
    } catch (SponsorshipDoesNotExistException e) {
        throw new InternalErrorException(e);
    }
    sponsor.setActive(sponsorship.isActive());
    sponsor.setValidityTo(sponsorship.getValidityTo());
    if (user instanceof RichUser) {
        sponsor.setUserAttributes(((RichUser) user).getUserAttributes());
        sponsor.setUserExtSources(((RichUser) user).getUserExtSources());
    }
    return sponsor;
}
Also used : Sponsorship(cz.metacentrum.perun.core.api.Sponsorship) RichUser(cz.metacentrum.perun.core.api.RichUser) Sponsor(cz.metacentrum.perun.core.api.Sponsor) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) SponsorshipDoesNotExistException(cz.metacentrum.perun.core.api.exceptions.SponsorshipDoesNotExistException)

Example 2 with Sponsorship

use of cz.metacentrum.perun.core.api.Sponsorship in project perun by CESNET.

the class MembersManagerEntryIntegrationTest method getSoonExpiringSponsorshipsReturnsLowerBound.

@Test
public void getSoonExpiringSponsorshipsReturnsLowerBound() throws Exception {
    System.out.println(CLASS_NAME + "getSoonExpiringSponsorshipsReturnsLowerBound");
    Member member = setUpMember(createdVo);
    User sponsor1 = perun.getUsersManagerBl().getUserByMember(sess, setUpSponsor(createdVo));
    AuthzResolverBlImpl.setRole(sess, sponsor1, createdVo, Role.SPONSOR);
    LocalDate today = LocalDate.of(2020, 2, 2);
    membersManagerEntry.setSponsorshipForMember(sess, member, sponsor1, today);
    LocalDate nextYear = today.plusYears(1);
    List<Sponsorship> sponsorships = perun.getMembersManagerBl().getSponsorshipsExpiringInRange(sess, today, nextYear);
    assertThat(sponsorships).hasSize(1);
    assertThat(sponsorships.get(0).getValidityTo()).isEqualTo(today);
}
Also used : Sponsorship(cz.metacentrum.perun.core.api.Sponsorship) User(cz.metacentrum.perun.core.api.User) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member) LocalDate(java.time.LocalDate) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 3 with Sponsorship

use of cz.metacentrum.perun.core.api.Sponsorship in project perun by CESNET.

the class MembersManagerEntryIntegrationTest method getSponsorshipsExpiringInRangeDoesntReturnExpiringBeforeRange.

@Test
public void getSponsorshipsExpiringInRangeDoesntReturnExpiringBeforeRange() throws Exception {
    System.out.println(CLASS_NAME + "getSponsorshipsExpiringInRangeDoesntReturnExpiringBeforeRange");
    Member member = setUpMember(createdVo);
    User sponsor1 = perun.getUsersManagerBl().getUserByMember(sess, setUpSponsor(createdVo));
    User sponsor2 = perun.getUsersManagerBl().getUserByMember(sess, setUpSponsor2(createdVo));
    AuthzResolverBlImpl.setRole(sess, sponsor1, createdVo, Role.SPONSOR);
    AuthzResolverBlImpl.setRole(sess, sponsor2, createdVo, Role.SPONSOR);
    LocalDate today = LocalDate.of(2020, 2, 2);
    LocalDate nextDay = today.plusDays(1);
    LocalDate lastWeek = today.minusWeeks(1);
    membersManagerEntry.setSponsorshipForMember(sess, member, sponsor1, nextDay);
    membersManagerEntry.sponsorMember(sess, member, sponsor2, lastWeek);
    LocalDate nextWeek = today.plusDays(7);
    List<Sponsorship> sponsorships = perun.getMembersManagerBl().getSponsorshipsExpiringInRange(sess, today, nextWeek);
    assertThat(sponsorships).hasSize(1);
    assertThat(sponsorships.get(0).getValidityTo()).isEqualTo(nextDay);
}
Also used : Sponsorship(cz.metacentrum.perun.core.api.Sponsorship) User(cz.metacentrum.perun.core.api.User) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member) LocalDate(java.time.LocalDate) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 4 with Sponsorship

use of cz.metacentrum.perun.core.api.Sponsorship in project perun by CESNET.

the class ExpirationNotifSchedulerTest method testSponsorshipDoesntExpireToday.

@Test
public void testSponsorshipDoesntExpireToday() throws Exception {
    System.out.println(CLASS_NAME + "testSponsorshipDoesntExpireToday");
    LocalDate today = LocalDate.of(2020, 2, 2);
    when(spyScheduler.getCurrentLocalDate()).thenReturn(today);
    Member member = setUpMember();
    User sponsor = perun.getUsersManagerBl().getUserByMember(session, setUpMember());
    AuthzResolverBlImpl.setRole(session, sponsor, vo, Role.SPONSOR);
    perun.getMembersManagerBl().setSponsorshipForMember(session, member, sponsor, today);
    ReflectionTestUtils.invokeMethod(spyScheduler, "expireSponsorships");
    Sponsorship sponsorship = perun.getMembersManagerBl().getSponsorship(session, member, sponsor);
    assertThat(sponsorship.isActive());
}
Also used : Sponsorship(cz.metacentrum.perun.core.api.Sponsorship) EnrichedSponsorship(cz.metacentrum.perun.core.api.EnrichedSponsorship) User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) LocalDate(java.time.LocalDate) Member(cz.metacentrum.perun.core.api.Member) Test(org.junit.Test)

Example 5 with Sponsorship

use of cz.metacentrum.perun.core.api.Sponsorship in project perun by CESNET.

the class ExpirationNotifSchedulerTest method testSponsorshipExpires.

@Test
public void testSponsorshipExpires() throws Exception {
    System.out.println(CLASS_NAME + "testSponsorshipExpires");
    LocalDate today = LocalDate.of(2020, 2, 2);
    when(spyScheduler.getCurrentLocalDate()).thenReturn(today);
    Member member = setUpMember();
    User sponsor = perun.getUsersManagerBl().getUserByMember(session, setUpMember());
    AuthzResolverBlImpl.setRole(session, sponsor, vo, Role.SPONSOR);
    LocalDate lastMonth = today.minusMonths(1);
    perun.getMembersManagerBl().setSponsorshipForMember(session, member, sponsor, lastMonth);
    Sponsorship sponsorshipBefore = perun.getMembersManagerBl().getSponsorship(session, member, sponsor);
    assertThat(sponsorshipBefore.isActive());
    ReflectionTestUtils.invokeMethod(spyScheduler, "expireSponsorships");
    assertThatExceptionOfType(SponsorshipDoesNotExistException.class).isThrownBy(() -> perun.getMembersManagerBl().getSponsorship(session, member, sponsor));
}
Also used : Sponsorship(cz.metacentrum.perun.core.api.Sponsorship) EnrichedSponsorship(cz.metacentrum.perun.core.api.EnrichedSponsorship) User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) SponsorshipDoesNotExistException(cz.metacentrum.perun.core.api.exceptions.SponsorshipDoesNotExistException) LocalDate(java.time.LocalDate) Member(cz.metacentrum.perun.core.api.Member) Test(org.junit.Test)

Aggregations

Sponsorship (cz.metacentrum.perun.core.api.Sponsorship)14 Member (cz.metacentrum.perun.core.api.Member)13 User (cz.metacentrum.perun.core.api.User)13 LocalDate (java.time.LocalDate)12 Test (org.junit.Test)12 RichMember (cz.metacentrum.perun.core.api.RichMember)10 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)9 RichUser (cz.metacentrum.perun.core.api.RichUser)5 SponsorshipDoesNotExistException (cz.metacentrum.perun.core.api.exceptions.SponsorshipDoesNotExistException)4 EnrichedSponsorship (cz.metacentrum.perun.core.api.EnrichedSponsorship)3 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)3 Sponsor (cz.metacentrum.perun.core.api.Sponsor)2 AlreadySponsorException (cz.metacentrum.perun.core.api.exceptions.AlreadySponsorException)2 AlreadySponsoredMemberException (cz.metacentrum.perun.core.api.exceptions.AlreadySponsoredMemberException)2 UserNotInRoleException (cz.metacentrum.perun.core.api.exceptions.UserNotInRoleException)2 Attribute (cz.metacentrum.perun.core.api.Attribute)1 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)1 AttributesManager (cz.metacentrum.perun.core.api.AttributesManager)1 BanOnResource (cz.metacentrum.perun.core.api.BanOnResource)1 BanOnVo (cz.metacentrum.perun.core.api.BanOnVo)1