Coverage Report - org.kuali.student.enrollment.class2.courseoffering.service.impl.ActivityOfferingLookupableImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ActivityOfferingLookupableImpl
0%
0/20
0%
0/4
1.8
 
 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  
  */
 16  
 package org.kuali.student.enrollment.class2.courseoffering.service.impl;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.core.api.criteria.Predicate;
 20  
 import org.kuali.rice.core.api.criteria.PredicateFactory;
 21  
 import org.kuali.rice.core.api.criteria.QueryByCriteria;
 22  
 import org.kuali.rice.krad.lookup.LookupableImpl;
 23  
 import org.kuali.rice.krad.web.form.LookupForm;
 24  
 import org.kuali.student.enrollment.class2.courseoffering.util.ActivityOfferingConstants;
 25  
 import org.kuali.student.enrollment.class2.courseoffering.util.CourseOfferingResourceLoader;
 26  
 import org.kuali.student.enrollment.common.util.ContextBuilder;
 27  
 import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingInfo;
 28  
 import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
 29  
 import org.kuali.student.r2.common.dto.ContextInfo;
 30  
 import org.kuali.student.r2.common.exceptions.*;
 31  
 
 32  
 import java.util.*;
 33  
 
 34  
 /**
 35  
  * This class //TODO ...
 36  
  *
 37  
  * @author Kuali Student Team
 38  
  */
 39  0
 public class ActivityOfferingLookupableImpl extends LookupableImpl {
 40  
 
 41  
     @Override
 42  
     protected List<?> getSearchResults(LookupForm lookupForm, Map<String, String> fieldValues, boolean unbounded) {
 43  0
         List<ActivityOfferingInfo> activityOfferingInfos = new ArrayList<ActivityOfferingInfo>();
 44  
 
 45  
         try {
 46  0
             if(hasCriteria(fieldValues)){
 47  0
                 QueryByCriteria qbc = buildQueryByCriteria(fieldValues);
 48  0
                 activityOfferingInfos = getCourseOfferingService().searchForActivityOfferings(qbc, getContextInfo());
 49  
             }
 50  0
         } catch (Exception e) {
 51  0
            throw new RuntimeException(e);
 52  0
         }
 53  
 
 54  0
         return activityOfferingInfos;
 55  
     }
 56  
 
 57  
     private QueryByCriteria buildQueryByCriteria(Map<String, String> fieldValues){
 58  0
         String aoId = fieldValues.get(ActivityOfferingConstants.ACTIVITYOFFERING_ID);
 59  
 
 60  0
         List<Predicate> predicates = new ArrayList<Predicate>();
 61  0
         if (StringUtils.isNotBlank(aoId)) {
 62  0
             predicates.add(PredicateFactory.equalIgnoreCase("id", aoId));
 63  
         }
 64  
 
 65  0
         QueryByCriteria.Builder qbcBuilder = QueryByCriteria.Builder.create();
 66  0
         qbcBuilder.setPredicates(predicates.toArray(new Predicate[predicates.size()]));
 67  0
         QueryByCriteria qbc = qbcBuilder.build();
 68  
 
 69  0
         return qbc;
 70  
     }
 71  
 
 72  
     private boolean hasCriteria(Map<String, String> fieldValues){
 73  0
         return StringUtils.isNotBlank(fieldValues.get(ActivityOfferingConstants.ACTIVITYOFFERING_ID));
 74  
     }
 75  
 
 76  
     public CourseOfferingService getCourseOfferingService() {
 77  0
         return CourseOfferingResourceLoader.loadCourseOfferingService();
 78  
     }
 79  
 
 80  
     public ContextInfo getContextInfo() {
 81  0
         return ContextBuilder.loadContextInfo();
 82  
     }
 83  
 }