use of cz.metacentrum.perun.core.api.MemberWithSponsors in project perun by CESNET.
the class MembersManagerEntry method convertMemberToMemberWithSponsors.
/**
* Converts member to member with sponsors and sets all his sponsors.
*
* @param sess perun session
* @param member sponsored member
* @return member with sponsors
*/
private MemberWithSponsors convertMemberToMemberWithSponsors(PerunSession sess, RichMember member) {
MemberWithSponsors memberWithSponsors = new MemberWithSponsors(member);
List<Sponsor> sponsors = getPerunBl().getUsersManagerBl().getSponsors(sess, member).stream().map(user -> membersManagerBl.convertUserToSponsor(sess, user, member)).collect(Collectors.toList());
memberWithSponsors.setSponsors(sponsors);
return memberWithSponsors;
}
use of cz.metacentrum.perun.core.api.MemberWithSponsors in project perun by CESNET.
the class MembersManagerEntryIntegrationTest method getSponsoredMembersAndTheirSponsors.
@Test
public void getSponsoredMembersAndTheirSponsors() throws Exception {
System.out.println(CLASS_NAME + "getSponsoredMembersAndTheirSponsors");
Member sponsorMember = setUpSponsor(createdVo);
User sponsorUser = perun.getUsersManagerBl().getUserByMember(sess, sponsorMember);
Group sponsors = new Group("sponsors", "users able to sponsor");
sponsors = perun.getGroupsManagerBl().createGroup(sess, createdVo, sponsors);
AuthzResolverBlImpl.setRole(sess, sponsors, createdVo, Role.SPONSOR);
perun.getGroupsManagerBl().addMember(sess, sponsors, sponsorMember);
Map<String, String> userName = new HashMap<>();
userName.put("guestName", "Ing. Jan Novák");
Member sponsoredMember = createSponsoredMember(sess, createdVo, "dummy", userName, "secret", null, sponsorUser);
ArrayList<String> attrNames = new ArrayList<>();
attrNames.add("urn:perun:user:attribute-def:def:preferredMail");
List<MemberWithSponsors> memberWithSponsors = perun.getMembersManager().getSponsoredMembersAndTheirSponsors(sess, createdVo, attrNames);
assertEquals(memberWithSponsors.get(0).getMember(), sponsoredMember);
assertEquals(memberWithSponsors.get(0).getSponsors().get(0).getUser(), sponsorUser);
assertTrue(memberWithSponsors.get(0).getSponsors().size() == 1);
}
use of cz.metacentrum.perun.core.api.MemberWithSponsors in project perun by CESNET.
the class VosManagerEntryIntegrationTest method convertSponsoredUsers.
@Test
public void convertSponsoredUsers() throws Exception {
System.out.println(CLASS_NAME + "convertSponsoredUsers");
myVo = vosManagerEntry.createVo(sess, myVo);
User user = new User(-1, "Sponsored", "User", "", "", "");
user.setSponsoredUser(true);
User sponsor1 = new User(-1, "Sponsor 1", "", "", "", "");
User sponsor2 = new User(-1, "Sponsor 2", "", "", "", "");
user = perun.getUsersManagerBl().createUser(sess, user);
sponsor1 = perun.getUsersManagerBl().createUser(sess, sponsor1);
sponsor2 = perun.getUsersManagerBl().createUser(sess, sponsor2);
perun.getUsersManagerBl().addSpecificUserOwner(sess, sponsor1, user);
perun.getUsersManagerBl().addSpecificUserOwner(sess, sponsor2, user);
Member member = perun.getMembersManagerBl().createMember(sess, myVo, user);
perun.getVosManager().convertSponsoredUsers(sess, myVo);
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(sponsor1, Collections.emptyList())));
assertThat(sponsors).contains(new Sponsor(new RichUser(sponsor2, Collections.emptyList())));
}
use of cz.metacentrum.perun.core.api.MemberWithSponsors in project perun by CESNET.
the class MembersManagerEntryIntegrationTest method getAllSponsoredMembersAndTheirSponsors.
@Test
public void getAllSponsoredMembersAndTheirSponsors() throws Exception {
System.out.println(CLASS_NAME + "getAllSponsoredMembersAndTheirSponsors");
Member sponsorMember = setUpSponsor(createdVo);
User sponsorUser = perun.getUsersManagerBl().getUserByMember(sess, sponsorMember);
Group sponsors = new Group("sponsors", "users able to sponsor");
sponsors = perun.getGroupsManagerBl().createGroup(sess, createdVo, sponsors);
AuthzResolverBlImpl.setRole(sess, sponsors, createdVo, Role.SPONSOR);
perun.getGroupsManagerBl().addMember(sess, sponsors, sponsorMember);
Map<String, String> userName = new HashMap<>();
userName.put("guestName", "Ing. Jan Novák");
Member sponsoredMember = createSponsoredMember(sess, createdVo, "dummy", userName, "secret", null, sponsorUser);
ArrayList<String> attrNames = new ArrayList<>();
attrNames.add("urn:perun:user:attribute-def:def:preferredMail");
List<MemberWithSponsors> memberWithSponsors = perun.getMembersManager().getAllSponsoredMembersAndTheirSponsors(sess, createdVo, attrNames);
assertEquals(memberWithSponsors.get(0).getMember(), sponsoredMember);
assertEquals(memberWithSponsors.get(0).getSponsors().get(0).getUser(), sponsorUser);
assertEquals(1, memberWithSponsors.get(0).getSponsors().size());
}
use of cz.metacentrum.perun.core.api.MemberWithSponsors 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);
}
Aggregations