Coverage Report - org.kuali.student.enrollment.class2.appointment.service.impl.StudentGroupWrapperLookupableImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
StudentGroupWrapperLookupableImpl
0%
0/37
0%
0/12
3.667
 
 1  
 /**
 2  
  * Copyright 2012 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  
  * Created by Daniel on 3/30/12
 16  
  */
 17  
 package org.kuali.student.enrollment.class2.appointment.service.impl;
 18  
 
 19  
 import org.kuali.rice.core.api.criteria.Predicate;
 20  
 import org.kuali.rice.core.api.criteria.QueryByCriteria;
 21  
 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
 22  
 import org.kuali.rice.krad.lookup.LookupableImpl;
 23  
 import org.kuali.rice.krad.web.form.LookupForm;
 24  
 import org.kuali.student.enrollment.class2.appointment.dto.StudentGroupWrapper;
 25  
 import org.kuali.student.r2.common.constants.CommonServiceConstants;
 26  
 import org.kuali.student.r2.common.dto.ContextInfo;
 27  
 import org.kuali.student.r2.core.population.dto.PopulationInfo;
 28  
 import org.kuali.student.r2.core.population.service.PopulationService;
 29  
 
 30  
 import javax.xml.namespace.QName;
 31  
 import java.util.ArrayList;
 32  
 import java.util.List;
 33  
 import java.util.Map;
 34  
 
 35  
 import static org.kuali.rice.core.api.criteria.PredicateFactory.and;
 36  
 import static org.kuali.rice.core.api.criteria.PredicateFactory.like;
 37  
 
 38  
 /**
 39  
  * This class //TODO ...
 40  
  *
 41  
  * @author Kuali Student Team
 42  
  */
 43  0
 public class StudentGroupWrapperLookupableImpl extends LookupableImpl {
 44  
     private transient PopulationService populationService;
 45  
     @Override
 46  
     protected List<?> getSearchResults(LookupForm lookupForm, Map<String, String> fieldValues, boolean unbounded) {
 47  0
         List<StudentGroupWrapper> results = new ArrayList<StudentGroupWrapper>();
 48  0
         ContextInfo context = new ContextInfo();
 49  
 
 50  0
         QueryByCriteria.Builder qBuilder = QueryByCriteria.Builder.create();
 51  0
         List<Predicate> pList = new ArrayList<Predicate>();
 52  0
         qBuilder.setPredicates();
 53  
         // create predicates for search parameters
 54  0
         for(String key : fieldValues.keySet()){
 55  0
             if(key.equalsIgnoreCase("name")){
 56  0
                 Predicate grpName = like(key,fieldValues.get(key));
 57  0
                 pList.add(grpName);
 58  0
             } else{
 59  0
                 Predicate words = like(key,fieldValues.get(key));
 60  0
                 pList.add(words);
 61  0
             }
 62  
         }
 63  0
         if (!pList.isEmpty()){
 64  0
             Predicate[] preds = new Predicate[pList.size()];
 65  0
             pList.toArray(preds);
 66  0
             qBuilder.setPredicates(and(preds));
 67  
         }
 68  
 
 69  
         try {
 70  
             // method returns list of populationinfos.
 71  0
             java.util.List<PopulationInfo> populationInfos = getPopulationService().searchForPopulations(qBuilder.build(), context);
 72  0
             if(!populationInfos.isEmpty()){
 73  0
                 for(PopulationInfo populationInfo:populationInfos){
 74  0
                     StudentGroupWrapper studentGroupWrapper = new StudentGroupWrapper();
 75  0
                     studentGroupWrapper.setId(populationInfo.getId());
 76  0
                     studentGroupWrapper.setName(populationInfo.getName());
 77  0
                     studentGroupWrapper.setDescription(populationInfo.getDescr().getPlain());
 78  0
                     results.add(studentGroupWrapper);
 79  0
                 }
 80  
             }
 81  0
         } catch (Exception e) {
 82  0
             throw new RuntimeException("Error Performing Search",e); //To change body of catch statement use File | Settings | File Templates.
 83  0
         }
 84  0
         return results;
 85  
     }
 86  
 
 87  
     protected PopulationService getPopulationService() {
 88  
         //populationService is retrieved using global resource loader which is wired in ks-enroll-context.xml
 89  0
         if(populationService == null) {
 90  0
             populationService = (PopulationService) GlobalResourceLoader.getService(new QName(CommonServiceConstants.REF_OBJECT_URI_GLOBAL_PREFIX+"population", "PopulationService"));
 91  
 
 92  
         }
 93  0
         return populationService;
 94  
     }
 95  
 
 96  
     public static void main(String[] args){
 97  0
         StudentGroupWrapperLookupableImpl studentWrapper = new StudentGroupWrapperLookupableImpl();
 98  0
         studentWrapper.getPopulationService();
 99  
 
 100  0
     }
 101  
 }