Coverage Report - org.kuali.student.enrollment.class2.acal.service.TermInfoLookupableImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
TermInfoLookupableImpl
0%
0/29
0%
0/6
4.5
 
 1  
 package org.kuali.student.enrollment.class2.acal.service;
 2  
 
 3  
 import org.apache.commons.lang.StringUtils;
 4  
 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
 5  
 import org.kuali.rice.krad.lookup.LookupableImpl;
 6  
 import org.kuali.rice.krad.web.form.LookupForm;
 7  
 import org.kuali.student.enrollment.acal.dto.AcademicCalendarInfo;
 8  
 import org.kuali.student.enrollment.acal.dto.TermInfo;
 9  
 import org.kuali.student.enrollment.acal.infc.AcademicCalendar;
 10  
 import org.kuali.student.enrollment.acal.service.AcademicCalendarService;
 11  
 import org.kuali.student.r2.common.dto.ContextInfo;
 12  
 import org.kuali.student.r2.common.exceptions.*;
 13  
 
 14  
 import javax.xml.namespace.QName;
 15  
 import java.util.*;
 16  
 
 17  0
 public class TermInfoLookupableImpl extends LookupableImpl {
 18  
     public final static String TERM_TYPE_KEY = "typeKey";
 19  
     public final static String TERM_KEY = "key";
 20  
          private transient AcademicCalendarService academicCalendarService;
 21  
          
 22  
 
 23  
     @Override
 24  
     protected List<?> getSearchResults(LookupForm lookupForm, Map<String, String> fieldValues, boolean unbounded) {
 25  0
             TermInfo termInfo = null;
 26  0
             List<TermInfo> termInfoList = new ArrayList<TermInfo>();
 27  0
         List<AcademicCalendarInfo> acalInfoList = new ArrayList<AcademicCalendarInfo>();
 28  
 
 29  0
             String termKey = fieldValues.get(TERM_KEY);
 30  0
             ContextInfo context = new ContextInfo();
 31  0
         if (StringUtils.isBlank(termKey)) {
 32  0
             Calendar now = Calendar.getInstance();
 33  0
             int thisYear = now.get(Calendar.YEAR);
 34  
             try {
 35  
                 // next year
 36  0
                 acalInfoList.addAll(getAcademicCalendarService().getAcademicCalendarsByStartYear(thisYear + 1, context));
 37  
                 // this year
 38  0
                 acalInfoList.addAll(getAcademicCalendarService().getAcademicCalendarsByStartYear(thisYear, context));
 39  
                 // and last
 40  0
                 acalInfoList.addAll(getAcademicCalendarService().getAcademicCalendarsByStartYear(thisYear - 1, context));
 41  0
                 for (AcademicCalendarInfo acalInfo : acalInfoList) {
 42  0
                     termInfoList.addAll(getAcademicCalendarService().getTermsForAcademicCalendar(acalInfo.getId(), context));
 43  
                 }
 44  0
             } catch (Exception e) {
 45  0
                 e.printStackTrace();
 46  0
                 return null;
 47  0
             }
 48  0
         }
 49  
         else {
 50  
             try{
 51  0
                 termInfo = getAcademicCalendarService().getTerm(termKey, context);
 52  0
                 termInfoList.add(termInfo);
 53  0
             } catch (Exception e){
 54  0
                 e.printStackTrace();
 55  0
                 return null;
 56  0
             }
 57  
         }
 58  0
         return termInfoList;
 59  
     }
 60  
     
 61  
     protected AcademicCalendarService getAcademicCalendarService() {
 62  0
          if(academicCalendarService == null) {
 63  0
                  academicCalendarService = (AcademicCalendarService) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/acal","AcademicCalendarService"));
 64  
         }
 65  
 
 66  0
         return academicCalendarService;
 67  
     }
 68  
 
 69  
 }