View Javadoc

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