Search in sources :

Example 6 with Sponsor

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);
}
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)

Example 7 with Sponsor

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());
}
Also used : SpecificUserExpectedException(cz.metacentrum.perun.core.api.exceptions.SpecificUserExpectedException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Arrays(java.util.Arrays) Candidate(cz.metacentrum.perun.core.api.Candidate) RichUserExtSource(cz.metacentrum.perun.core.api.RichUserExtSource) AuthzResolver(cz.metacentrum.perun.core.api.AuthzResolver) Vo(cz.metacentrum.perun.core.api.Vo) ServiceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ServiceNotExistsException) MemberNotExistsException(cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException) LoggerFactory(org.slf4j.LoggerFactory) SpecificUserType(cz.metacentrum.perun.core.api.SpecificUserType) ExtSource(cz.metacentrum.perun.core.api.ExtSource) LoginNotExistsException(cz.metacentrum.perun.core.api.exceptions.LoginNotExistsException) RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) PerunBean(cz.metacentrum.perun.core.api.PerunBean) Map(java.util.Map) Role(cz.metacentrum.perun.core.api.Role) UsersManagerBl(cz.metacentrum.perun.core.bl.UsersManagerBl) Attribute(cz.metacentrum.perun.core.api.Attribute) Facility(cz.metacentrum.perun.core.api.Facility) MemberAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.MemberAlreadyRemovedException) PasswordCreationFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordCreationFailedException) NotSpecificUserExpectedException(cz.metacentrum.perun.core.api.exceptions.NotSpecificUserExpectedException) BeansUtils(cz.metacentrum.perun.core.api.BeansUtils) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) UserExtSourceAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceAlreadyRemovedException) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) ExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) FacilityNotExistsException(cz.metacentrum.perun.core.api.exceptions.FacilityNotExistsException) Collectors(java.util.stream.Collectors) User(cz.metacentrum.perun.core.api.User) Sponsor(cz.metacentrum.perun.core.api.Sponsor) List(java.util.List) UsersPageQuery(cz.metacentrum.perun.core.api.UsersPageQuery) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) Service(cz.metacentrum.perun.core.api.Service) PasswordStrengthException(cz.metacentrum.perun.core.api.exceptions.PasswordStrengthException) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) Resource(cz.metacentrum.perun.core.api.Resource) PerunSession(cz.metacentrum.perun.core.api.PerunSession) PasswordStrengthFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordStrengthFailedException) Paginated(cz.metacentrum.perun.core.api.Paginated) SpecificUserAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.SpecificUserAlreadyRemovedException) Group(cz.metacentrum.perun.core.api.Group) AlreadyReservedLoginException(cz.metacentrum.perun.core.api.exceptions.AlreadyReservedLoginException) UsersManagerImplApi(cz.metacentrum.perun.core.implApi.UsersManagerImplApi) SpecificUserOwnerAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.SpecificUserOwnerAlreadyRemovedException) ArrayList(java.util.ArrayList) PasswordDeletionFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordDeletionFailedException) UserExtSourceExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException) UsersManager(cz.metacentrum.perun.core.api.UsersManager) UserAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.UserAlreadyRemovedException) PasswordOperationTimeoutException(cz.metacentrum.perun.core.api.exceptions.PasswordOperationTimeoutException) RichResource(cz.metacentrum.perun.core.api.RichResource) RichUser(cz.metacentrum.perun.core.api.RichUser) PasswordChangeFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordChangeFailedException) Member(cz.metacentrum.perun.core.api.Member) Logger(org.slf4j.Logger) LoginExistsException(cz.metacentrum.perun.core.api.exceptions.LoginExistsException) RichGroup(cz.metacentrum.perun.core.api.RichGroup) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) RelationNotExistsException(cz.metacentrum.perun.core.api.exceptions.RelationNotExistsException) ActionType(cz.metacentrum.perun.core.api.ActionType) PasswordDoesntMatchException(cz.metacentrum.perun.core.api.exceptions.PasswordDoesntMatchException) ResourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ResourceNotExistsException) AttributesManager(cz.metacentrum.perun.core.api.AttributesManager) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) PasswordResetLinkExpiredException(cz.metacentrum.perun.core.api.exceptions.PasswordResetLinkExpiredException) PasswordResetLinkNotValidException(cz.metacentrum.perun.core.api.exceptions.PasswordResetLinkNotValidException) 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) UserExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceNotExistsException) AnonymizationNotSupportedException(cz.metacentrum.perun.core.api.exceptions.AnonymizationNotSupportedException) User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) RichUser(cz.metacentrum.perun.core.api.RichUser) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 8 with Sponsor

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())));
}
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)

Aggregations

Sponsor (cz.metacentrum.perun.core.api.Sponsor)8 Member (cz.metacentrum.perun.core.api.Member)7 User (cz.metacentrum.perun.core.api.User)6 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)5 MemberWithSponsors (cz.metacentrum.perun.core.api.MemberWithSponsors)5 Attribute (cz.metacentrum.perun.core.api.Attribute)4 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)4 RichUser (cz.metacentrum.perun.core.api.RichUser)4 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)4 Test (org.junit.Test)4 Candidate (cz.metacentrum.perun.core.api.Candidate)3 ExtSource (cz.metacentrum.perun.core.api.ExtSource)3 Group (cz.metacentrum.perun.core.api.Group)3 Paginated (cz.metacentrum.perun.core.api.Paginated)3 PerunSession (cz.metacentrum.perun.core.api.PerunSession)3 Resource (cz.metacentrum.perun.core.api.Resource)3 RichMember (cz.metacentrum.perun.core.api.RichMember)3 Role (cz.metacentrum.perun.core.api.Role)3 SpecificUserType (cz.metacentrum.perun.core.api.SpecificUserType)3 UserExtSource (cz.metacentrum.perun.core.api.UserExtSource)3