Search in sources :

Example 1 with MemberWithSponsors

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;
}
Also used : InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Arrays(java.util.Arrays) Validation(cz.metacentrum.perun.core.api.Validation) Candidate(cz.metacentrum.perun.core.api.Candidate) AuthzResolver(cz.metacentrum.perun.core.api.AuthzResolver) Vo(cz.metacentrum.perun.core.api.Vo) Date(java.util.Date) MemberNotExistsException(cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException) LoggerFactory(org.slf4j.LoggerFactory) SpecificUserType(cz.metacentrum.perun.core.api.SpecificUserType) MembersManager(cz.metacentrum.perun.core.api.MembersManager) ExtSource(cz.metacentrum.perun.core.api.ExtSource) MembersManagerBl(cz.metacentrum.perun.core.bl.MembersManagerBl) AlreadySponsoredMemberException(cz.metacentrum.perun.core.api.exceptions.AlreadySponsoredMemberException) LoginNotExistsException(cz.metacentrum.perun.core.api.exceptions.LoginNotExistsException) NamespaceRulesNotExistsException(cz.metacentrum.perun.core.api.exceptions.NamespaceRulesNotExistsException) Map(java.util.Map) Role(cz.metacentrum.perun.core.api.Role) MemberNotValidYetException(cz.metacentrum.perun.core.api.exceptions.MemberNotValidYetException) Attribute(cz.metacentrum.perun.core.api.Attribute) MembersPageQuery(cz.metacentrum.perun.core.api.MembersPageQuery) MemberAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.MemberAlreadyRemovedException) MemberWithSponsors(cz.metacentrum.perun.core.api.MemberWithSponsors) PasswordCreationFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordCreationFailedException) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) ExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) Collectors(java.util.stream.Collectors) User(cz.metacentrum.perun.core.api.User) Sponsor(cz.metacentrum.perun.core.api.Sponsor) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException) List(java.util.List) MemberNotSponsoredException(cz.metacentrum.perun.core.api.exceptions.MemberNotSponsoredException) LocalDate(java.time.LocalDate) AlreadySponsorException(cz.metacentrum.perun.core.api.exceptions.AlreadySponsorException) RichMember(cz.metacentrum.perun.core.api.RichMember) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) PasswordStrengthException(cz.metacentrum.perun.core.api.exceptions.PasswordStrengthException) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) SponsoredUserData(cz.metacentrum.perun.core.api.SponsoredUserData) Resource(cz.metacentrum.perun.core.api.Resource) PerunSession(cz.metacentrum.perun.core.api.PerunSession) GroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException) NamespaceRules(cz.metacentrum.perun.core.api.NamespaceRules) Paginated(cz.metacentrum.perun.core.api.Paginated) Group(cz.metacentrum.perun.core.api.Group) ArrayList(java.util.ArrayList) ParentGroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.ParentGroupNotExistsException) MemberNotSuspendedException(cz.metacentrum.perun.core.api.exceptions.MemberNotSuspendedException) SponsorshipDoesNotExistException(cz.metacentrum.perun.core.api.exceptions.SponsorshipDoesNotExistException) PasswordResetMailNotExistsException(cz.metacentrum.perun.core.api.exceptions.PasswordResetMailNotExistsException) Member(cz.metacentrum.perun.core.api.Member) Logger(org.slf4j.Logger) UserNotInRoleException(cz.metacentrum.perun.core.api.exceptions.UserNotInRoleException) Iterator(java.util.Iterator) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) ResourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ResourceNotExistsException) AlreadyMemberException(cz.metacentrum.perun.core.api.exceptions.AlreadyMemberException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) ExtendMembershipException(cz.metacentrum.perun.core.api.exceptions.ExtendMembershipException) VoNotExistsException(cz.metacentrum.perun.core.api.exceptions.VoNotExistsException) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) Utils(cz.metacentrum.perun.core.impl.Utils) InvalidLoginException(cz.metacentrum.perun.core.api.exceptions.InvalidLoginException) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) InvalidSponsoredUserDataException(cz.metacentrum.perun.core.api.exceptions.InvalidSponsoredUserDataException) UserExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceNotExistsException) Collections(java.util.Collections) Status(cz.metacentrum.perun.core.api.Status) Sponsor(cz.metacentrum.perun.core.api.Sponsor) MemberWithSponsors(cz.metacentrum.perun.core.api.MemberWithSponsors)

Example 2 with 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);
}
Also used : Group(cz.metacentrum.perun.core.api.Group) User(cz.metacentrum.perun.core.api.User) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) MemberWithSponsors(cz.metacentrum.perun.core.api.MemberWithSponsors) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 3 with MemberWithSponsors

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())));
}
Also used : RichUser(cz.metacentrum.perun.core.api.RichUser) User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) Sponsor(cz.metacentrum.perun.core.api.Sponsor) MemberWithSponsors(cz.metacentrum.perun.core.api.MemberWithSponsors) Member(cz.metacentrum.perun.core.api.Member) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 4 with MemberWithSponsors

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());
}
Also used : Group(cz.metacentrum.perun.core.api.Group) User(cz.metacentrum.perun.core.api.User) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) MemberWithSponsors(cz.metacentrum.perun.core.api.MemberWithSponsors) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 5 with MemberWithSponsors

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);
}
Also used : User(cz.metacentrum.perun.core.api.User) Sponsor(cz.metacentrum.perun.core.api.Sponsor) MemberWithSponsors(cz.metacentrum.perun.core.api.MemberWithSponsors) 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)

Aggregations

Member (cz.metacentrum.perun.core.api.Member)6 MemberWithSponsors (cz.metacentrum.perun.core.api.MemberWithSponsors)6 User (cz.metacentrum.perun.core.api.User)6 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)5 Test (org.junit.Test)5 RichMember (cz.metacentrum.perun.core.api.RichMember)4 Sponsor (cz.metacentrum.perun.core.api.Sponsor)4 Group (cz.metacentrum.perun.core.api.Group)3 ArrayList (java.util.ArrayList)3 RichUser (cz.metacentrum.perun.core.api.RichUser)2 Attribute (cz.metacentrum.perun.core.api.Attribute)1 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)1 AuthzResolver (cz.metacentrum.perun.core.api.AuthzResolver)1 Candidate (cz.metacentrum.perun.core.api.Candidate)1 ExtSource (cz.metacentrum.perun.core.api.ExtSource)1 MembersManager (cz.metacentrum.perun.core.api.MembersManager)1 MembersPageQuery (cz.metacentrum.perun.core.api.MembersPageQuery)1 NamespaceRules (cz.metacentrum.perun.core.api.NamespaceRules)1 Paginated (cz.metacentrum.perun.core.api.Paginated)1 PerunSession (cz.metacentrum.perun.core.api.PerunSession)1