Coverage Report - org.kuali.student.core.personsearch.service.impl.PersonSearch
 
Classes in this File Line Coverage Branch Coverage Complexity
PersonSearch
0%
0/21
0%
0/12
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  
 import org.kuali.rice.core.api.criteria.QueryByCriteria;
 22  
 
 23  
 import org.kuali.rice.kim.api.identity.IdentityService;
 24  
 import org.kuali.rice.kim.api.identity.Person;
 25  
 import org.kuali.rice.kim.api.identity.entity.EntityDefault;
 26  
 import org.kuali.rice.kim.api.identity.entity.EntityDefaultQueryResults;
 27  
 import org.kuali.rice.kim.api.identity.principal.Principal;
 28  
 import org.kuali.rice.kim.api.identity.type.EntityTypeContactInfoDefault;
 29  
 
 30  
 /**
 31  
  * Utility methods for dealing with Person searches
 32  
  *
 33  
  * @author Kuali Rice Team (kuali-rice@googlegroups.com)
 34  
  *
 35  
  */
 36  0
 public class PersonSearch {
 37  
 
 38  
     @SuppressWarnings("unchecked")
 39  
     protected List<Person> findPeopleInternal(IdentityService identityService, Map<String, String> criteria, boolean unbounded) {
 40  
 
 41  0
         List<Person> people = new ArrayList<Person>();
 42  
 
 43  
         // TODO: map the old call parameters into the criteria parametsrs
 44  
 //        identityService.lookupEntityDefault(criteria, unbounded);
 45  0
         QueryByCriteria queryByCriteria = null;
 46  0
         EntityDefaultQueryResults results = identityService.findEntityDefaults(queryByCriteria);
 47  0
         List<EntityDefault> entities = results.getResults();
 48  0
         if (entities != null) {
 49  0
             for (EntityDefault e : entities) {
 50  
                 // get to get all principals for the entity as well
 51  0
                 for (Principal p : e.getPrincipals()) {
 52  0
                     Person person = convertEntityToPerson(e, p);
 53  0
                     if (person != null) {
 54  0
                         people.add(person);
 55  
                     }
 56  0
                 }
 57  
             }
 58  
         }
 59  
 
 60  
 //        if (entities instanceof CollectionIncomplete) {
 61  
 //            return new CollectionIncomplete(people, ((CollectionIncomplete) entities).getActualSizeIfTruncated());
 62  
 //        }
 63  0
         return people;
 64  
     }
 65  
 
 66  
     protected Person convertEntityToPerson(EntityDefault entity, Principal principal) {
 67  
         try {
 68  
             // get the EntityEntityType for the EntityType corresponding to a Person
 69  0
             EntityTypeContactInfoDefault entType = entity.getEntityType(PersonSearchServiceImpl.PERSON_ENTITY_TYPE);
 70  
             // if no "person" entity type present for the given principal, skip to the next type in the list
 71  0
             if (entType == null) {
 72  0
                 return null;
 73  
             }
 74  
             // attach the principal and entity objects
 75  
             // PersonImpl has logic to pull the needed elements from the KimEntity-related classes
 76  0
             return new KsPerson(entity, principal);
 77  
 
 78  0
         } catch (Exception ex) {
 79  
             // allow runtime exceptions to pass through
 80  0
             if (ex instanceof RuntimeException) {
 81  0
                 throw (RuntimeException) ex;
 82  
             } else {
 83  0
                 throw new RuntimeException("Problem building person object", ex);
 84  
             }
 85  
         }
 86  
     }
 87  
 
 88  
 
 89  
 }