use of cz.metacentrum.perun.core.api.Sponsor in project perun by CESNET.
the class MembersManagerEntryIntegrationTest method sponsorMemberWithValidityTo.
@Test
public void sponsorMemberWithValidityTo() throws Exception {
System.out.println(CLASS_NAME + "sponsorMemberWithValidityTo");
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);
membersManagerEntry.setSponsorshipForMember(sess, member, sponsor1, null);
LocalDate validity = LocalDate.now().plusMonths(1);
membersManagerEntry.sponsorMember(sess, member, sponsor2, validity);
List<MemberWithSponsors> memberWithSponsors = perun.getMembersManager().getSponsoredMembersAndTheirSponsors(sess, createdVo, Collections.emptyList());
assertThat(memberWithSponsors).hasSize(1);
assertThat(memberWithSponsors.get(0).getSponsors()).hasSize(2);
Sponsor sponsor1FromDb = memberWithSponsors.get(0).getSponsors().get(0);
assertThat(sponsor1FromDb.getUser()).isEqualTo(sponsor1);
assertThat(sponsor1FromDb.getValidityTo()).isNull();
Sponsor sponsor2FromDb = memberWithSponsors.get(0).getSponsors().get(1);
assertThat(sponsor2FromDb.getUser()).isEqualTo(sponsor2);
assertThat(sponsor2FromDb.getValidityTo()).isEqualTo(validity);
}
use of cz.metacentrum.perun.core.api.Sponsor in project perun by CESNET.
the class UsersManagerEntry method getSponsorsForMember.
@Override
public List<Sponsor> getSponsorsForMember(PerunSession sess, Member member, List<String> attrNames) throws PrivilegeException {
Utils.checkPerunSession(sess);
Utils.notNull(member, "member");
// Authorization
if (!AuthzResolver.authorizedInternal(sess, "getSponsorsForMember_Member_List<String>_policy", member)) {
throw new PrivilegeException(sess, "getSponsorsForMember");
}
List<User> sponsors = usersManagerBl.getSponsors(sess, member);
List<RichUser> richUsers;
if (attrNames == null || attrNames.isEmpty()) {
// adds all existing atributes
try {
richUsers = usersManagerBl.convertRichUsersToRichUsersWithAttributes(sess, usersManagerBl.convertUsersToRichUsers(sess, sponsors));
} catch (UserNotExistsException e) {
throw new InternalErrorException(e);
}
} else {
// adds only selected atributes (if the list would be empty, it will return no attributes)
richUsers = usersManagerBl.convertUsersToRichUsersWithAttributesByNames(sess, sponsors, attrNames);
}
return richUsers.stream().map(richUser -> perunBl.getMembersManagerBl().convertUserToSponsor(sess, richUser, member)).collect(Collectors.toList());
}
use of cz.metacentrum.perun.core.api.Sponsor in project perun by CESNET.
the class VosManagerEntryIntegrationTest method convertSponsoredUsersWithNewSponsor.
@Test
public void convertSponsoredUsersWithNewSponsor() throws Exception {
System.out.println(CLASS_NAME + "convertSponsoredUsersWithNewSponsor");
myVo = vosManagerEntry.createVo(sess, myVo);
User user = new User(-1, "Sponsored", "User", "", "", "");
user.setSponsoredUser(true);
User originalSponsor = new User(-1, "Sponsor 1", "", "", "", "");
User newSponsor = new User(-1, "Sponsor 2", "", "", "", "");
user = perun.getUsersManagerBl().createUser(sess, user);
originalSponsor = perun.getUsersManagerBl().createUser(sess, originalSponsor);
newSponsor = perun.getUsersManagerBl().createUser(sess, newSponsor);
perun.getUsersManagerBl().addSpecificUserOwner(sess, originalSponsor, user);
Member member = perun.getMembersManagerBl().createMember(sess, myVo, user);
perun.getVosManager().convertSponsoredUsersWithNewSponsor(sess, myVo, newSponsor);
List<MemberWithSponsors> sponsoredMembersAndTheirSponsors = perun.getMembersManager().getSponsoredMembersAndTheirSponsors(sess, myVo, Collections.emptyList());
assertThat(sponsoredMembersAndTheirSponsors).hasSize(1);
Member sponsoredMember = sponsoredMembersAndTheirSponsors.get(0).getMember();
List<Sponsor> sponsors = sponsoredMembersAndTheirSponsors.get(0).getSponsors();
assertThat(sponsoredMember).isEqualTo(member);
assertThat(sponsors).contains(new Sponsor(new RichUser(newSponsor, Collections.emptyList())));
}
Aggregations