use of cz.metacentrum.perun.core.api.Sponsor 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;
}
use of cz.metacentrum.perun.core.api.Sponsor 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.Sponsor 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.Sponsor in project perun by CESNET.
the class UsersManagerEntryIntegrationTest method getSponsors.
@Test
public void getSponsors() throws Exception {
System.out.println(CLASS_NAME + "getSponsors");
setUpNamespaceAttribute();
String email = "email@sdf.sd";
AttributeDefinition emailAD = perun.getAttributesManagerBl().getAttributeDefinition(sess, URN_ATTR_USER_PREFERRED_MAIL);
Attribute emailAttribute = new Attribute(emailAD);
emailAttribute.setValue(email);
perun.getAttributesManagerBl().setAttribute(sess, user, emailAttribute);
Member member = perun.getMembersManagerBl().getMemberByUser(sess, vo, sponsoredUser);
LocalDate validity = LocalDate.now();
perun.getMembersManagerBl().updateSponsorshipValidity(sess, member, user, validity);
Member sponsoredMember = perun.getMembersManagerBl().getMemberByUser(sess, vo, sponsoredUser);
List<Sponsor> sponsors = usersManager.getSponsorsForMember(sess, sponsoredMember, Collections.singletonList(URN_ATTR_USER_PREFERRED_MAIL));
assertThat(sponsors).hasSize(1);
assertThat(sponsors.get(0).getUser()).isEqualTo(user);
assertThat(sponsors.get(0).getValidityTo()).isEqualTo(validity);
assertThat(sponsors.get(0).getUserAttributes()).hasSize(1);
assertThat(sponsors.get(0).getUserAttributes().get(0).getName()).isEqualTo(URN_ATTR_USER_PREFERRED_MAIL);
assertThat(sponsors.get(0).getUserAttributes().get(0).valueAsString()).isEqualTo(email);
}
use of cz.metacentrum.perun.core.api.Sponsor in project perun by CESNET.
the class MembersManagerEntryIntegrationTest method addSponsor.
@Test
public void addSponsor() throws Exception {
System.out.println(CLASS_NAME + "addSponsor");
// create user which can sponsor
User sponsorUser = perun.getUsersManagerBl().getUserByMember(sess, setUpSponsor(createdVo));
AuthzResolverBlImpl.setRole(sess, sponsorUser, createdVo, Role.SPONSOR);
assertTrue("user must have SPONSOR role", perun.getVosManagerBl().isUserInRoleForVo(sess, sponsorUser, Role.SPONSOR, createdVo, true));
// create another user which can sponsor
User sponsorUser2 = perun.getUsersManagerBl().getUserByMember(sess, setUpSponsor2(createdVo));
AuthzResolverBlImpl.setRole(sess, sponsorUser2, createdVo, Role.SPONSOR);
assertTrue("user must have SPONSOR role", perun.getVosManagerBl().isUserInRoleForVo(sess, sponsorUser2, Role.SPONSOR, createdVo, true));
// create user that cannot sponsor
User notsponsorUser = perun.getUsersManagerBl().getUserByMember(sess, setUpNotSponsor(createdVo));
assertFalse("user must not have SPONSOR role", perun.getVosManagerBl().isUserInRoleForVo(sess, notsponsorUser, Role.SPONSOR, createdVo, true));
// create sponsored member
Map<String, String> nameOfUser1 = new HashMap<>();
nameOfUser1.put("guestName", "Ing. Jiří Novák, CSc.");
Member sponsoredMember = createSponsoredMember(sess, createdVo, "dummy", nameOfUser1, "secret", null, sponsorUser);
assertNotNull("sponsored member must not be null", sponsoredMember);
assertTrue("sponsored memer must have flag 'sponsored' set", sponsoredMember.isSponsored());
assertTrue("sponsored member should have status VALID", sponsoredMember.getStatus() == Status.VALID);
// try add user that cannot sponsor, should fail
try {
perun.getMembersManager().sponsorMember(sess, sponsoredMember, notsponsorUser, null);
fail("user cannot sponsor but was added as sponsor");
} catch (UserNotInRoleException ex) {
// expected
}
// try to add user that already is sponsor, should fail
try {
perun.getMembersManager().sponsorMember(sess, sponsoredMember, sponsorUser, null);
fail("user cannot sponsor twice a single member");
} catch (AlreadySponsorException ex) {
// expected
}
// try to add sponsor, should succeed
perun.getMembersManager().sponsorMember(sess, sponsoredMember, sponsorUser2, null);
List<User> sponsors = perun.getUsersManagerBl().getSponsors(sess, sponsoredMember);
assertTrue("sponsor 1 is not reported as sponsor", sponsors.contains(sponsorUser));
assertTrue("sponsor 2 is not reported as sponsor", sponsors.contains(sponsorUser2));
assertTrue("unexpected sponsors", sponsors.size() == 2);
// check that it is reported
List<RichMember> sponsoredMembers1 = perun.getMembersManager().getSponsoredMembers(sess, createdVo, sponsorUser);
assertTrue("member is not in list of sponsored members for sponsor 1", sponsoredMembers1.stream().map(PerunBean::getId).anyMatch(id -> id == sponsoredMember.getId()));
List<RichMember> sponsoredMembers2 = perun.getMembersManager().getSponsoredMembers(sess, createdVo, sponsorUser2);
assertTrue("member is not in list of sponsored members for sponsor 2", sponsoredMembers2.stream().map(PerunBean::getId).anyMatch(id -> id == sponsoredMember.getId()));
// remove sponsor and add him again, sponsorship should reactivate
Sponsorship sponsorship = perun.getMembersManagerBl().getSponsorship(sess, sponsoredMember, sponsorUser);
assertTrue(sponsorship.isActive());
perun.getMembersManager().removeSponsor(sess, sponsoredMember, sponsorUser);
sponsorship = perun.getMembersManagerBl().getSponsorship(sess, sponsoredMember, sponsorUser);
assertFalse(sponsorship.isActive());
perun.getMembersManager().sponsorMember(sess, sponsoredMember, sponsorUser, null);
sponsorship = perun.getMembersManagerBl().getSponsorship(sess, sponsoredMember, sponsorUser);
assertTrue(sponsorship.isActive());
}
Aggregations