View Javadoc

1   package org.kuali.student.enrollment.class2.acal.service.impl;
2   
3   import org.apache.commons.lang.StringUtils;
4   import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
5   import org.kuali.rice.krad.uif.UifParameters;
6   import org.kuali.rice.krad.uif.service.impl.ViewHelperServiceImpl;
7   import org.kuali.rice.krad.util.KRADConstants;
8   import org.kuali.student.r2.common.util.constants.AcademicCalendarServiceConstants;
9   import org.kuali.student.enrollment.acal.dto.AcademicCalendarInfo;
10  import org.kuali.student.enrollment.acal.dto.HolidayCalendarInfo;
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.acal.service.CalendarSearchViewHelperService;
14  import org.kuali.student.enrollment.class2.acal.util.CalendarConstants;
15  import org.kuali.student.enrollment.class2.acal.util.CalendarSearchViewHelperUtil;
16  import org.kuali.student.r2.common.dto.ContextInfo;
17  
18  import javax.xml.namespace.QName;
19  import java.util.List;
20  import java.util.Properties;
21  
22  public class CalendarSearchViewHelperServiceImpl extends ViewHelperServiceImpl implements CalendarSearchViewHelperService {
23  
24      private transient AcademicCalendarService academicCalendarService;
25  
26      public List<TermInfo> searchForTerms(String name, String year,ContextInfo context)throws Exception {
27      	return CalendarSearchViewHelperUtil.searchForTerms(name,year,context,getAcademicCalendarService());
28      }
29  
30      public List<AcademicCalendarInfo> searchForAcademicCalendars(String name, String year,ContextInfo context)throws Exception {
31          return CalendarSearchViewHelperUtil.searchForAcademicCalendars(name,year,context,getAcademicCalendarService());
32      }
33  
34      public List<HolidayCalendarInfo> searchForHolidayCalendars(String name, String year,ContextInfo context)throws Exception {
35          return CalendarSearchViewHelperUtil.searchForHolidayCalendars(name,year,context,getAcademicCalendarService());
36      }
37  
38      public Properties buildTermURLParameters(TermInfo term, String methodToCall, boolean readOnlyView, ContextInfo context){
39  
40          String acalId = null;
41          try {
42              List<AcademicCalendarInfo> atps = getAcademicCalendarService().getAcademicCalendarsForTerm(term.getId(), context);
43              if (!atps.isEmpty()){
44                  acalId = atps.get(0).getId();
45              }
46          } catch (Exception e) {
47              throw new RuntimeException(e);
48          }
49  
50          Properties props = new Properties();
51          props.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, methodToCall);
52          props.put(CalendarConstants.CALENDAR_ID,acalId);
53          props.put(UifParameters.VIEW_ID, CalendarConstants.ACAL_VIEW);
54          props.put(CalendarConstants.PAGE_ID,CalendarConstants.ACADEMIC_CALENDAR_EDIT_PAGE);
55          props.put(CalendarConstants.SELECT_TAB,CalendarConstants.ACAL_TERM_TAB);
56  
57          if (readOnlyView){
58              props.put(CalendarConstants.READ_ONLY_VIEW,""+ true);
59          }
60  
61          return props;
62  
63      }
64  
65      public Properties buildACalURLParameters(AcademicCalendarInfo acal, String methodToCall, boolean readOnlyView, ContextInfo context){
66  
67          Properties props = new Properties();
68          props.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, methodToCall);
69          props.put(CalendarConstants.CALENDAR_ID,acal.getId());
70          props.put(UifParameters.VIEW_ID, CalendarConstants.ACAL_VIEW);
71  
72          if (StringUtils.equals(methodToCall,CalendarConstants.AC_COPY_METHOD)){
73             props.put(CalendarConstants.PAGE_ID,CalendarConstants.ACADEMIC_CALENDAR_COPY_PAGE);
74          } else {
75             props.put(CalendarConstants.PAGE_ID,CalendarConstants.ACADEMIC_CALENDAR_EDIT_PAGE);
76          }
77  
78          if (readOnlyView){
79              props.put(CalendarConstants.READ_ONLY_VIEW,""+ true);
80          }
81  
82          return props;
83  
84      }
85  
86      public Properties buildHCalURLParameters(HolidayCalendarInfo hcInfo, String methodToCall, boolean readOnlyView, ContextInfo context){
87  
88          Properties props = new Properties();
89          props.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, methodToCall);
90          props.put(CalendarConstants.CALENDAR_ID, hcInfo.getId());
91          props.put(UifParameters.VIEW_ID, CalendarConstants.HOLIDAYCALENDAR_FLOWVIEW);
92  
93          if (StringUtils.equals(methodToCall,CalendarConstants.HC_COPY_METHOD)){
94             props.put(CalendarConstants.PAGE_ID,CalendarConstants.HOLIDAYCALENDAR_COPYPAGE);
95          }else if (StringUtils.equals(methodToCall,CalendarConstants.HC_VIEW_METHOD) && readOnlyView){
96              props.put(CalendarConstants.PAGE_ID,CalendarConstants.HOLIDAYCALENDAR_VIEWPAGE);
97          } else {
98             props.put(CalendarConstants.PAGE_ID,CalendarConstants.HOLIDAYCALENDAR_EDITPAGE);
99          }
100 
101         return props;
102 
103     }
104 
105     protected AcademicCalendarService getAcademicCalendarService() {
106          if(academicCalendarService == null) {
107              academicCalendarService = (AcademicCalendarService) GlobalResourceLoader.getService(new QName(AcademicCalendarServiceConstants.NAMESPACE, AcademicCalendarServiceConstants.SERVICE_NAME_LOCAL_PART));
108         }
109         return this.academicCalendarService;
110     }
111 }