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