Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
PersonSearch |
|
| 6.5;6.5 |
1 | /** | |
2 | * Copyright 2010 The Kuali Foundation Licensed under the | |
3 | * Educational Community License, Version 2.0 (the "License"); you may | |
4 | * not use this file except in compliance with the License. You may | |
5 | * obtain a copy of the License at | |
6 | * | |
7 | * http://www.osedu.org/licenses/ECL-2.0 | |
8 | * | |
9 | * Unless required by applicable law or agreed to in writing, | |
10 | * software distributed under the License is distributed on an "AS IS" | |
11 | * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
12 | * or implied. See the License for the specific language governing | |
13 | * permissions and limitations under the License. | |
14 | */ | |
15 | ||
16 | package org.kuali.student.core.personsearch.service.impl; | |
17 | ||
18 | import java.util.ArrayList; | |
19 | import java.util.List; | |
20 | import java.util.Map; | |
21 | ||
22 | import org.kuali.rice.kim.bo.Person; | |
23 | import org.kuali.rice.kim.bo.entity.KimPrincipal; | |
24 | import org.kuali.rice.kim.bo.entity.dto.KimEntityDefaultInfo; | |
25 | import org.kuali.rice.kim.bo.entity.dto.KimEntityEntityTypeDefaultInfo; | |
26 | import org.kuali.rice.kim.service.IdentityManagementService; | |
27 | ||
28 | /** | |
29 | * Utility methods for dealing with Person searches | |
30 | * | |
31 | * @author Kuali Rice Team (kuali-rice@googlegroups.com) | |
32 | * | |
33 | */ | |
34 | 0 | public class PersonSearch { |
35 | ||
36 | @SuppressWarnings("unchecked") | |
37 | protected List<Person> findPeopleInternal(IdentityManagementService identityService, Map<String, String> criteria, boolean unbounded) { | |
38 | ||
39 | 0 | List<Person> people = new ArrayList<Person>(); |
40 | ||
41 | 0 | List<? extends KimEntityDefaultInfo> entities = identityService.lookupEntityDefaultInfo(criteria, unbounded); |
42 | 0 | if (entities != null) { |
43 | 0 | for (KimEntityDefaultInfo e : entities) { |
44 | // get to get all principals for the entity as well | |
45 | 0 | for (KimPrincipal p : e.getPrincipals()) { |
46 | 0 | Person person = convertEntityToPerson(e, p); |
47 | 0 | if (person != null) { |
48 | 0 | people.add(person); |
49 | } | |
50 | 0 | } |
51 | } | |
52 | } | |
53 | ||
54 | // if (entities instanceof CollectionIncomplete) { | |
55 | // return new CollectionIncomplete(people, ((CollectionIncomplete) entities).getActualSizeIfTruncated()); | |
56 | // } | |
57 | 0 | return people; |
58 | } | |
59 | ||
60 | protected Person convertEntityToPerson(KimEntityDefaultInfo entity, KimPrincipal principal) { | |
61 | try { | |
62 | // get the EntityEntityType for the EntityType corresponding to a Person | |
63 | 0 | KimEntityEntityTypeDefaultInfo entType = entity.getEntityType(PersonSearchServiceImpl.PERSON_ENTITY_TYPE); |
64 | // if no "person" entity type present for the given principal, skip to the next type in the list | |
65 | 0 | if (entType == null) { |
66 | 0 | return null; |
67 | } | |
68 | // attach the principal and entity objects | |
69 | // PersonImpl has logic to pull the needed elements from the KimEntity-related classes | |
70 | 0 | return new KsPerson(entity, principal); |
71 | ||
72 | 0 | } catch (Exception ex) { |
73 | // allow runtime exceptions to pass through | |
74 | 0 | if (ex instanceof RuntimeException) { |
75 | 0 | throw (RuntimeException) ex; |
76 | } else { | |
77 | 0 | throw new RuntimeException("Problem building person object", ex); |
78 | } | |
79 | } | |
80 | } | |
81 | ||
82 | ||
83 | } |