Search in sources :

Example 46 with Candidate

use of cz.metacentrum.perun.core.api.Candidate in project perun by CESNET.

the class ResourcesManagerEntryIntegrationTest method setUpMember.

private Member setUpMember(Vo vo) throws Exception {
    Candidate candidate = setUpCandidate();
    Member member = perun.getMembersManagerBl().createMemberSync(sess, vo, candidate);
    // set first candidate as member of test VO
    assertNotNull("No member created", member);
    usersForDeletion.add(perun.getUsersManager().getUserByMember(sess, member));
    // save user for deletion after test
    return member;
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) AssignedMember(cz.metacentrum.perun.core.api.AssignedMember) Member(cz.metacentrum.perun.core.api.Member)

Example 47 with Candidate

use of cz.metacentrum.perun.core.api.Candidate in project perun by CESNET.

the class SearcherEntryIntegrationTest method setUpCandidate2.

private Candidate setUpCandidate2() {
    // Mockito.mock(Candidate.class);
    Candidate candidate = new Candidate();
    candidate.setFirstName("aaa2");
    candidate.setId(0);
    candidate.setMiddleName("");
    candidate.setLastName("bbb2");
    candidate.setTitleBefore("");
    candidate.setTitleAfter("");
    final UserExtSource userExtSource = new UserExtSource(extSource, extLogin2);
    candidate.setUserExtSource(userExtSource);
    candidate.setAttributes(new HashMap<>());
    return candidate;
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource)

Example 48 with Candidate

use of cz.metacentrum.perun.core.api.Candidate in project perun by CESNET.

the class SearcherEntryIntegrationTest method setUpCandidate1.

private Candidate setUpCandidate1() {
    // Mockito.mock(Candidate.class);
    Candidate candidate = new Candidate();
    candidate.setFirstName("aaa1");
    candidate.setId(0);
    candidate.setMiddleName("");
    candidate.setLastName("bbb1");
    candidate.setTitleBefore("");
    candidate.setTitleAfter("");
    final UserExtSource userExtSource = new UserExtSource(extSource, extLogin);
    candidate.setUserExtSource(userExtSource);
    candidate.setAttributes(new HashMap<>());
    return candidate;
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource)

Example 49 with Candidate

use of cz.metacentrum.perun.core.api.Candidate in project perun by CESNET.

the class UsersManagerEntryIntegrationTest method setUpSpecificUser2ForUser.

private void setUpSpecificUser2ForUser(Vo vo) throws Exception {
    Candidate candidate = setUpCandidateForSpecificUser2();
    List<User> owners = new ArrayList<>();
    owners.add(user);
    Member serviceMember = perun.getMembersManagerBl().createServiceMember(sess, vo, candidate, owners);
    perun.getMembersManagerBl().validateMember(sess, serviceMember);
    // set first candidate as member of test VO
    assertNotNull("No member created", serviceMember);
    serviceUser2 = usersManager.getUserByMember(sess, serviceMember);
    usersForDeletion.add(serviceUser2);
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) ArrayList(java.util.ArrayList) Member(cz.metacentrum.perun.core.api.Member)

Example 50 with Candidate

use of cz.metacentrum.perun.core.api.Candidate in project perun by CESNET.

the class GroupsManagerBlImpl method convertSubjectsToCandidates.

/**
 * Convert List of subjects to list of Candidates.
 *
 * To getting Candidate can use 1 of 3 possible options:
 * 1] membersSource and source are not equals => we have just login, other attributes neet to get from membersSource
 * 2] membersSource==source and membersSource is instance of ExtSourceApi => we already have all attributes in subject
 * 3] membersSource==source and membersSource is instance of SimplExtSourceApi => we have just login, need to read other attributes again
 *
 * If candidate cannot be get for some reason, add this reason to skippedMembers list and skip him.
 *
 * @param sess
 * @param subjects list of subjects from ExtSource (at least login should be here)
 * @param membersSource optional member ExtSource (if members attributes are from other source then their logins)
 * @param source default group ExtSource
 * @param actualGroupMembers actual members of synchronized group
 * @param skippedMembers not successfully synchronized members are skipped and information about it should be added here
 *
 * @return list of successfully created candidates from subjects
 *
 * @throws InternalErrorException if some internal error occurs
 */
private List<Candidate> convertSubjectsToCandidates(PerunSession sess, List<Map<String, String>> subjects, ExtSource membersSource, ExtSource source, List<RichMember> actualGroupMembers, List<String> skippedMembers) {
    List<Candidate> candidates = new ArrayList<>();
    // mapping structure for more efficient searching of actual group members
    Map<UserExtSource, RichMember> mappingStructure = this.createMappingStructure(actualGroupMembers);
    for (Map<String, String> subject : subjects) {
        String login = subject.get("login");
        // Skip subjects, which doesn't have login
        if (login == null || login.isEmpty()) {
            log.debug("Subject {} doesn't contain attribute login, skipping.", subject);
            skippedMembers.add("MemberEntry:[" + subject + "] was skipped because login is missing");
            continue;
        }
        try {
            // 1] sources of login and other attributes are not same
            if (!membersSource.equals(source)) {
                // need to read attributes from the new memberSource, we can't use locally data there (there are from other extSource)
                candidates.add(new Candidate(getPerunBl().getExtSourcesManagerBl().getCandidate(sess, membersSource, login)));
            // 2] sources are same and we work with source which is instance of ExtSourceApi
            } else if (membersSource instanceof ExtSourceApi) {
                // we can use the data from this source without reading them again (all exists in the map of subject attributes)
                candidates.add(new Candidate(getPerunBl().getExtSourcesManagerBl().getCandidate(sess, subject, membersSource, login)));
            // 3] sources are same and we work with source which is instace of ExtSourceSimpleApi
            } else if (membersSource instanceof ExtSourceSimpleApi) {
                // we can't use the data from this source, we need to read them again (they are not in the map of subject attributes)
                candidates.add(new Candidate(getPerunBl().getExtSourcesManagerBl().getCandidate(sess, membersSource, login)));
            } else {
                // this could not happen without change in extSource API code
                throw new InternalErrorException("ExtSource is other instance than SimpleApi or Api and this is not supported!");
            }
        } catch (CandidateNotExistsException e) {
            log.warn("getGroupSubjects subjects returned login {}, but it cannot be obtained using getCandidate()", login);
            // If member can't be find in the member's extSource (we are missing other attributes) we can try find him in the group
            UserExtSource subjectUserExtSource = new UserExtSource(membersSource, login);
            // If member is in the group, we can create a simple object from him to preserve his existence in the group
            if (mappingStructure.containsKey(subjectUserExtSource)) {
                RichMember richMember = mappingStructure.get(subjectUserExtSource);
                // convert richMember to simple candidate object (to prevent wrong attribute updating)
                candidates.add(BeansUtils.convertRichMemberToCandidate(richMember, subjectUserExtSource));
                skippedMembers.add("MemberEntry:[" + richMember + "] was skipped from updating in the group, because he can't be found by login:'" + login + "' in extSource " + membersSource);
            } else {
                skippedMembers.add("MemberEntry:[" + subject + "] was skipped from adding to the group because he can't be found by login:'" + login + "' in extSource " + membersSource);
            }
        } catch (ExtSourceUnsupportedOperationException e) {
            log.warn("ExtSource {} doesn't support getCandidate operation.", membersSource);
            skippedMembers.add("MemberEntry:[" + subject + "] was skipped because extSource " + membersSource + " not support method getCandidate");
        } catch (ParserException e) {
            log.warn("Can't parse value {} from candidate with login {}", e.getParsedValue(), login);
            skippedMembers.add("MemberEntry:[" + subject + "] was skipped because of problem with parsing value '" + e.getParsedValue() + "'");
        }
    }
    return candidates;
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) ParserException(cz.metacentrum.perun.core.api.exceptions.ParserException) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) ExtSourceApi(cz.metacentrum.perun.core.implApi.ExtSourceApi) RichMember(cz.metacentrum.perun.core.api.RichMember) RichUserExtSource(cz.metacentrum.perun.core.api.RichUserExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) ExtSourceUnsupportedOperationException(cz.metacentrum.perun.core.api.exceptions.ExtSourceUnsupportedOperationException) ExtSourceSimpleApi(cz.metacentrum.perun.core.implApi.ExtSourceSimpleApi) CandidateNotExistsException(cz.metacentrum.perun.core.api.exceptions.CandidateNotExistsException)

Aggregations

Candidate (cz.metacentrum.perun.core.api.Candidate)100 UserExtSource (cz.metacentrum.perun.core.api.UserExtSource)52 Test (org.junit.Test)41 Member (cz.metacentrum.perun.core.api.Member)37 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)30 ExtSource (cz.metacentrum.perun.core.api.ExtSource)25 RichMember (cz.metacentrum.perun.core.api.RichMember)24 User (cz.metacentrum.perun.core.api.User)23 HashMap (java.util.HashMap)23 ArrayList (java.util.ArrayList)21 Group (cz.metacentrum.perun.core.api.Group)15 Attribute (cz.metacentrum.perun.core.api.Attribute)14 Map (java.util.Map)12 MemberCandidate (cz.metacentrum.perun.core.api.MemberCandidate)11 RichUser (cz.metacentrum.perun.core.api.RichUser)11 Vo (cz.metacentrum.perun.core.api.Vo)11 LinkedHashMap (java.util.LinkedHashMap)11 RichUserExtSource (cz.metacentrum.perun.core.api.RichUserExtSource)9 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)9 CandidateNotExistsException (cz.metacentrum.perun.core.api.exceptions.CandidateNotExistsException)8