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.service.AcademicCalendarService;
10 import org.kuali.student.r2.common.dto.ContextInfo;
11
12 import javax.xml.namespace.QName;
13 import java.util.ArrayList;
14 import java.util.Calendar;
15 import java.util.List;
16 import java.util.Map;
17
18
19 @Deprecated
20 public class TermInfoLookupableImpl extends LookupableImpl {
21 public final static String TERM_TYPE_KEY = "typeKey";
22 public final static String TERM_KEY = "key";
23 private transient AcademicCalendarService academicCalendarService;
24
25
26 @Override
27 protected List<?> getSearchResults(LookupForm lookupForm, Map<String, String> fieldValues, boolean unbounded) {
28 TermInfo termInfo = null;
29 List<TermInfo> termInfoList = new ArrayList<TermInfo>();
30 List<AcademicCalendarInfo> acalInfoList = new ArrayList<AcademicCalendarInfo>();
31
32 String termKey = fieldValues.get(TERM_KEY);
33 ContextInfo context = new ContextInfo();
34 if (StringUtils.isBlank(termKey)) {
35 Calendar now = Calendar.getInstance();
36 int thisYear = now.get(Calendar.YEAR);
37 try {
38
39 acalInfoList.addAll(getAcademicCalendarService().getAcademicCalendarsByStartYear(thisYear + 1, context));
40
41 acalInfoList.addAll(getAcademicCalendarService().getAcademicCalendarsByStartYear(thisYear, context));
42
43 acalInfoList.addAll(getAcademicCalendarService().getAcademicCalendarsByStartYear(thisYear - 1, context));
44 for (AcademicCalendarInfo acalInfo : acalInfoList) {
45 termInfoList.addAll(getAcademicCalendarService().getTermsForAcademicCalendar(acalInfo.getId(), context));
46 }
47 } catch (Exception e) {
48 e.printStackTrace();
49 return null;
50 }
51 }
52 else {
53 try{
54 termInfo = getAcademicCalendarService().getTerm(termKey, context);
55 termInfoList.add(termInfo);
56 } catch (Exception e){
57 e.printStackTrace();
58 return null;
59 }
60 }
61 return termInfoList;
62 }
63
64 protected AcademicCalendarService getAcademicCalendarService() {
65 if(academicCalendarService == null) {
66 academicCalendarService = (AcademicCalendarService) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/acal","AcademicCalendarService"));
67 }
68
69 return academicCalendarService;
70 }
71
72 }