Coverage Report - org.kuali.student.enrollment.class2.courseoffering.service.impl.AdvanceActivityOfferingLookupableImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
AdvanceActivityOfferingLookupableImpl
0%
0/41
0%
0/20
3.4
 
 1  
 package org.kuali.student.enrollment.class2.courseoffering.service.impl;
 2  
 
 3  
 import org.apache.commons.lang.StringUtils;
 4  
 import org.kuali.rice.core.api.criteria.Predicate;
 5  
 import org.kuali.rice.core.api.criteria.PredicateFactory;
 6  
 import org.kuali.rice.core.api.criteria.QueryByCriteria;
 7  
 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
 8  
 import org.kuali.rice.krad.lookup.LookupableImpl;
 9  
 import org.kuali.rice.krad.web.form.LookupForm;
 10  
 import org.kuali.student.enrollment.acal.constants.AcademicCalendarServiceConstants;
 11  
 import org.kuali.student.enrollment.acal.dto.TermInfo;
 12  
 import org.kuali.student.enrollment.acal.service.AcademicCalendarService;
 13  
 import org.kuali.student.enrollment.class2.courseoffering.util.ActivityOfferingConstants;
 14  
 import org.kuali.student.enrollment.class2.courseoffering.util.CourseOfferingResourceLoader;
 15  
 import org.kuali.student.enrollment.common.util.ContextBuilder;
 16  
 import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingInfo;
 17  
 import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo;
 18  
 import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
 19  
 import org.kuali.student.r2.common.dto.ContextInfo;
 20  
 
 21  
 
 22  
 import javax.xml.namespace.QName;
 23  
 import java.util.ArrayList;
 24  
 import java.util.List;
 25  
 import java.util.Map;
 26  
 
 27  0
 public class AdvanceActivityOfferingLookupableImpl extends LookupableImpl {
 28  
 
 29  
     @Override
 30  
     protected List<?> getSearchResults(LookupForm lookupForm, Map<String, String> fieldValues, boolean unbounded) {
 31  0
         List<ActivityOfferingInfo> activityOfferingInfos = new ArrayList<ActivityOfferingInfo>();
 32  0
         String termId = null;
 33  0
         String courseOfferingId = null;
 34  0
         String termCode = fieldValues.get(ActivityOfferingConstants.ACTIVITYOFFERING_TERM_CODE);
 35  0
         String courseOfferingCode = fieldValues.get(ActivityOfferingConstants.ACTIVITYOFFERING_COURSE_OFFERING_CODE);
 36  
         try {
 37  
             //get termId based on termCode
 38  0
             if (StringUtils.isNotBlank(termCode)) {
 39  0
                 QueryByCriteria.Builder qbcBuilder = QueryByCriteria.Builder.create();
 40  0
                 qbcBuilder.setPredicates(PredicateFactory.equal(ActivityOfferingConstants.ATP_CODE, termCode));
 41  0
                 QueryByCriteria criteria = qbcBuilder.build();
 42  
 
 43  
                 // Do search.  In ideal case, termList contains one element, which is the desired term.
 44  0
                 List<TermInfo> termList = getAcalService().searchForTerms(criteria, new ContextInfo());
 45  
 
 46  0
                 if (termList != null  && termList.size()>0 ){
 47  
                     // Always get first term
 48  0
                     termId = termList.get(0).getId();
 49  0
                     System.out.println(">>> termId = "+termId);
 50  0
                     if(termList.size()>1){
 51  
                         //TODO: need to log --> find more than one term for specified termCode
 52  0
                         System.out.println(">>Alert: find more than one term for specified termCode: "+termCode);
 53  
                     }
 54  
                 } else {
 55  0
                     new Exception("Error: Does not find a valid term with the termCode equal to "+ termCode);
 56  
                 }
 57  
             }
 58  
 
 59  
             //get courseOfferingId based on courseOfferingCode
 60  0
             if (StringUtils.isNotBlank(courseOfferingCode)) {
 61  0
                 QueryByCriteria.Builder qbcBuilder = QueryByCriteria.Builder.create();
 62  0
                 qbcBuilder.setPredicates(PredicateFactory.equal(ActivityOfferingConstants.ACTIVITYOFFERING_COURSE_OFFERING_CODE, courseOfferingCode));
 63  0
                 QueryByCriteria criteria = qbcBuilder.build();
 64  
 
 65  
                 //Do search.  In ideal case, returns one element, which is the desired CO.
 66  0
                 List<CourseOfferingInfo> courseOfferingList = getCourseOfferingService().searchForCourseOfferings(criteria, new ContextInfo());
 67  0
                 if(courseOfferingList!=null && courseOfferingList.size()>0){
 68  
                     // Always get first CO
 69  0
                     courseOfferingId = courseOfferingList.get(0).getId();
 70  0
                     System.out.println(">>> courseOfferingId = "+courseOfferingId);
 71  0
                     if(courseOfferingList.size()>1){
 72  
                         //TODO: need to log --> find more than one CO for specified courseOfferingCode
 73  0
                         System.out.println(">>Alert: find more than one CO for specified courseOfferingCode: "+courseOfferingCode);
 74  
                     }
 75  
                 } else {
 76  0
                     new Exception("Error: Does not find a valid Course Offering with the courseOfferingCode equal to "+courseOfferingCode);
 77  
                 }
 78  
             }
 79  
 
 80  
             //get all AOs based on termId and courseOfferingId
 81  0
             QueryByCriteria.Builder qbcBuilder = QueryByCriteria.Builder.create();
 82  0
             if (StringUtils.isNotBlank(termId) && StringUtils.isNotBlank(courseOfferingId)) {
 83  0
                 qbcBuilder.setPredicates(PredicateFactory.and(
 84  
                         PredicateFactory.equalIgnoreCase("termId", termId),
 85  
                         PredicateFactory.equalIgnoreCase("courseOfferingId", courseOfferingId)));
 86  0
                 QueryByCriteria criteria = qbcBuilder.build();
 87  0
                 activityOfferingInfos = getCourseOfferingService().searchForActivityOfferings(criteria, getContextInfo());
 88  
             }
 89  0
         } catch (Exception e) {
 90  0
             throw new RuntimeException(e);
 91  0
         }
 92  
 
 93  0
         return activityOfferingInfos;
 94  
     }
 95  
 
 96  
     private boolean hasCriteria(Map<String, String> fieldValues){
 97  0
         return StringUtils.isNotBlank(fieldValues.get(ActivityOfferingConstants.ACTIVITYOFFERING_ID));
 98  
     }
 99  
 
 100  
     public CourseOfferingService getCourseOfferingService() {
 101  0
         return CourseOfferingResourceLoader.loadCourseOfferingService();
 102  
     }
 103  
 
 104  
     public AcademicCalendarService getAcalService() {
 105  0
         return (AcademicCalendarService) GlobalResourceLoader.getService(new QName(AcademicCalendarServiceConstants.NAMESPACE,
 106  
                 AcademicCalendarServiceConstants.SERVICE_NAME_LOCAL_PART));
 107  
 
 108  
     }
 109  
 
 110  
     public ContextInfo getContextInfo() {
 111  0
         return ContextBuilder.loadContextInfo();
 112  
     }
 113  
 
 114  
 
 115  
 }
 116