View Javadoc

1   package org.kuali.student.enrollment.class2.acal.service.impl;
2   
3   
4   import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
5   import org.kuali.rice.krad.inquiry.InquirableImpl;
6   import org.kuali.student.r2.common.util.constants.AcademicCalendarServiceConstants;
7   import org.kuali.student.enrollment.acal.dto.HolidayCalendarInfo;
8   import org.kuali.student.enrollment.acal.dto.HolidayInfo;
9   import org.kuali.student.enrollment.acal.service.AcademicCalendarService;
10  import org.kuali.student.enrollment.class2.acal.dto.HolidayCalendarWrapper;
11  import org.kuali.student.enrollment.class2.acal.dto.HolidayWrapper;
12  import org.kuali.student.r2.common.dto.ContextInfo;
13  import org.kuali.student.r2.common.exceptions.*;
14  import org.kuali.student.r2.core.class1.state.dto.StateInfo;
15  import org.kuali.student.r2.core.class1.type.dto.TypeInfo;
16  
17  import javax.xml.namespace.QName;
18  import java.util.ArrayList;
19  import java.util.HashMap;
20  import java.util.List;
21  import java.util.Map;
22  
23  public class HolidayCalendarWrapperInquiryViewHelperServiceImpl extends InquirableImpl {
24      //	 public final static String ACADEMIC_CALENDAR_KEY = "academicCalendarInfo.key";
25      public final static String HOLIDAY_CALENDAR_WRAPPER_KEY = "id";
26      private transient AcademicCalendarService academicCalendarService;
27  
28      @Override
29      public HolidayCalendarWrapper retrieveDataObject(Map<String, String> parameters) {
30          ContextInfo context = new ContextInfo();
31  
32          HolidayCalendarWrapper holidayCalendarWrapper = new HolidayCalendarWrapper();
33          List<HolidayWrapper> holidays = new ArrayList<HolidayWrapper>();
34          try{
35              //need to retrieve HolidayCalendarInfo and all Holidays to form the HolidayCalendarWrapper.
36              String holidayCalendarKey = parameters.get(HOLIDAY_CALENDAR_WRAPPER_KEY);
37              if(holidayCalendarKey == null){
38                  System.out.println(">>>holidayCalendarKey is null");
39                  return null;
40              }
41              else {
42                  System.out.println(">>>holidayCalendarKey ="+holidayCalendarKey);
43              }
44              HolidayCalendarInfo holidayCalendarInfo = getAcademicCalendarService().getHolidayCalendar(holidayCalendarKey, context);
45              holidayCalendarWrapper.setHolidayCalendarInfo(holidayCalendarInfo);
46              holidayCalendarWrapper.setId(holidayCalendarInfo.getId());
47              holidayCalendarWrapper.setAdminOrgName(getAdminOrgNameById(holidayCalendarInfo.getAdminOrgId()));
48              StateInfo hcState = getAcademicCalendarService().getHolidayCalendarState(holidayCalendarInfo.getStateKey(), context);
49              holidayCalendarWrapper.setStateName(hcState.getName());
50  
51              try {
52                  List<HolidayInfo> holidayInfoList = getAcademicCalendarService().getHolidaysForHolidayCalendar(holidayCalendarInfo.getId(), context);
53                  for(HolidayInfo holidayInfo : holidayInfoList){
54                      HolidayWrapper holiday = new HolidayWrapper();
55                      holiday.setHolidayInfo(holidayInfo);
56                      TypeInfo typeInfo = getAcademicCalendarService().getHolidayType(holidayInfo.getTypeKey(), context);
57                      holiday.setTypeName(typeInfo.getName());
58                      holidays.add(holiday);
59                  }
60                  holidayCalendarWrapper.setHolidays(holidays);
61              }catch (DoesNotExistException dnee){
62                  System.out.println("call getAcademicCalendarService().getHolidaysForHolidayCalendar(holidayCalendarId, context), and get DoesNotExistException:  "+dnee.toString());
63              }catch (InvalidParameterException ipe){
64                  System.out.println("call getAcademicCalendarService().getHolidaysForHolidayCalendar(holidayCalendarId, context), and get InvalidParameterException:  "+ipe.toString());
65              }catch (MissingParameterException mpe){
66                  System.out.println("call getAcademicCalendarService().getHolidaysForHolidayCalendar(holidayCalendarId, context), and get MissingParameterException:  "+mpe.toString());
67              }catch (OperationFailedException ofe){
68                  System.out.println("call getAcademicCalendarService().getHolidaysForHolidayCalendar(holidayCalendarId, context), and get OperationFailedException:  "+ofe.toString());
69              }catch (PermissionDeniedException pde){
70                  System.out.println("call getAcademicCalendarService().getHolidaysForHolidayCalendar(holidayCalendarId, context), and get PermissionDeniedException:  "+pde.toString());
71              }
72              return holidayCalendarWrapper;
73  
74          }catch (DoesNotExistException dnee){
75              System.out.println("call getAcademicCalendarService().getHolidayCalendar(holidayCalendarId, context), and get DoesNotExistException:  "+dnee.toString());
76          }catch (InvalidParameterException ipe){
77              System.out.println("call getAcademicCalendarService().getHolidayCalendar(holidayCalendarId, context), and get InvalidParameterException:  "+ipe.toString());
78          }catch (MissingParameterException mpe){
79              System.out.println("call getAcademicCalendarService().getHolidayCalendar(holidayCalendarId, context), and get MissingParameterException:  "+mpe.toString());
80          }catch (OperationFailedException ofe){
81              System.out.println("call getAcademicCalendarService().getHolidayCalendar(holidayCalendarId, context), and get OperationFailedException:  "+ofe.toString());
82          }catch (PermissionDeniedException pde){
83              System.out.println("call getAcademicCalendarService().getHolidayCalendar(holidayCalendarId, context), and get PermissionDeniedException:  "+pde.toString());
84          }
85          return null;
86      }
87  
88      private String getAdminOrgNameById(String id){
89          //TODO: hard-coded for now, going to call OrgService
90          String adminOrgName = null;
91          Map<String, String> allHcOrgs = new HashMap<String, String>();
92          allHcOrgs.put("102", "Registrar's Office");
93  
94          if(allHcOrgs.containsKey(id)){
95              adminOrgName = allHcOrgs.get(id);
96          }
97  
98          return adminOrgName;
99      }
100 
101     protected AcademicCalendarService getAcademicCalendarService() {
102         if(academicCalendarService == null) {
103             academicCalendarService = (AcademicCalendarService) GlobalResourceLoader.getService(new QName(AcademicCalendarServiceConstants.NAMESPACE, AcademicCalendarServiceConstants.SERVICE_NAME_LOCAL_PART));
104         }
105 
106         return academicCalendarService;
107     }
108 }