001package org.kuali.student.enrollment.class2.acal.service.impl; 002 003 004import org.apache.log4j.Logger; 005import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; 006import org.kuali.rice.krad.inquiry.InquirableImpl; 007import org.kuali.student.enrollment.class2.acal.util.AcalCommonUtils; 008import org.kuali.student.r2.core.acal.dto.HolidayCalendarInfo; 009import org.kuali.student.r2.core.acal.dto.HolidayInfo; 010import org.kuali.student.r2.core.acal.service.AcademicCalendarService; 011import org.kuali.student.enrollment.class2.acal.dto.HolidayCalendarWrapper; 012import org.kuali.student.enrollment.class2.acal.dto.HolidayWrapper; 013import org.kuali.student.enrollment.class2.courseoffering.service.impl.ManageSOCViewHelperServiceImpl; 014import org.kuali.student.r2.common.dto.ContextInfo; 015import org.kuali.student.r2.common.exceptions.*; 016import org.kuali.student.r2.core.constants.AcademicCalendarServiceConstants; 017import org.kuali.student.r2.core.class1.state.dto.StateInfo; 018import org.kuali.student.r2.core.class1.type.dto.TypeInfo; 019 020import javax.xml.namespace.QName; 021import java.util.ArrayList; 022import java.util.HashMap; 023import java.util.List; 024import java.util.Map; 025 026public class HolidayCalendarWrapperInquiryViewHelperServiceImpl extends InquirableImpl { 027 private static final long serialVersionUID = 1L; 028 private final static Logger LOG = Logger.getLogger(ManageSOCViewHelperServiceImpl.class); 029 private final static String exceptionComment1 = "call getAcademicCalendarService().getHolidaysForHolidayCalendar(holidayCalendarId, context), and get "; 030 private final static String exceptionComment2 = "call getAcademicCalendarService().getHolidayCalendar(holidayCalendarId, context), and get "; 031 // public final static String ACADEMIC_CALENDAR_KEY = "academicCalendarInfo.key"; 032 public final static String HOLIDAY_CALENDAR_WRAPPER_KEY = "id"; 033 private transient AcademicCalendarService academicCalendarService; 034 035 @Override 036 public HolidayCalendarWrapper retrieveDataObject(Map<String, String> parameters) { 037 ContextInfo context = new ContextInfo(); 038 039 HolidayCalendarWrapper holidayCalendarWrapper = new HolidayCalendarWrapper(); 040 List<HolidayWrapper> holidays = new ArrayList<HolidayWrapper>(); 041 try{ 042 //need to retrieve HolidayCalendarInfo and all Holidays to form the HolidayCalendarWrapper. 043 String holidayCalendarKey = parameters.get(HOLIDAY_CALENDAR_WRAPPER_KEY); 044 if(holidayCalendarKey == null){ 045 AcalCommonUtils.logDebugMsg(LOG, ">>>holidayCalendarKey is null"); 046 return null; 047 } 048 else { 049 AcalCommonUtils.logDebugMsg(LOG, ">>>holidayCalendarKey =" + holidayCalendarKey); 050 } 051 HolidayCalendarInfo holidayCalendarInfo = getAcademicCalendarService().getHolidayCalendar(holidayCalendarKey, context); 052 holidayCalendarWrapper.setHolidayCalendarInfo(holidayCalendarInfo); 053 holidayCalendarWrapper.setId(holidayCalendarInfo.getId()); 054 holidayCalendarWrapper.setAdminOrgName(getAdminOrgNameById(holidayCalendarInfo.getAdminOrgId())); 055 StateInfo hcState = getAcademicCalendarService().getHolidayCalendarState(holidayCalendarInfo.getStateKey(), context); 056 holidayCalendarWrapper.setStateName(hcState.getName()); 057 058 try { 059 List<HolidayInfo> holidayInfoList = getAcademicCalendarService().getHolidaysForHolidayCalendar(holidayCalendarInfo.getId(), context); 060 for(HolidayInfo holidayInfo : holidayInfoList){ 061 HolidayWrapper holiday = new HolidayWrapper(); 062 holiday.setHolidayInfo(holidayInfo); 063 TypeInfo typeInfo = getAcademicCalendarService().getHolidayType(holidayInfo.getTypeKey(), context); 064 holiday.setTypeName(typeInfo.getName()); 065 holidays.add(holiday); 066 } 067 holidayCalendarWrapper.setHolidays(holidays); 068 }catch (DoesNotExistException dnee){ 069 AcalCommonUtils.logDebugMsg(LOG, exceptionComment1 + "DoesNotExistException: " + dnee.toString()); 070 }catch (InvalidParameterException ipe){ 071 AcalCommonUtils.logDebugMsg(LOG, exceptionComment1 + "InvalidParameterException: " + ipe.toString()); 072 }catch (MissingParameterException mpe){ 073 AcalCommonUtils.logDebugMsg(LOG, exceptionComment1 + "MissingParameterException: " + mpe.toString()); 074 }catch (OperationFailedException ofe){ 075 AcalCommonUtils.logDebugMsg(LOG, exceptionComment1 + "OperationFailedException: " + ofe.toString()); 076 }catch (PermissionDeniedException pde){ 077 AcalCommonUtils.logDebugMsg(LOG, exceptionComment1 + "PermissionDeniedException: " + pde.toString()); 078 } 079 return holidayCalendarWrapper; 080 081 }catch (DoesNotExistException dnee){ 082 AcalCommonUtils.logDebugMsg(LOG, exceptionComment2 + "DoesNotExistException: " + dnee.toString()); 083 }catch (InvalidParameterException ipe){ 084 AcalCommonUtils.logDebugMsg(LOG, exceptionComment2 + "InvalidParameterException: " + ipe.toString()); 085 }catch (MissingParameterException mpe){ 086 AcalCommonUtils.logDebugMsg(LOG, exceptionComment2 + "MissingParameterException: " + mpe.toString()); 087 }catch (OperationFailedException ofe){ 088 AcalCommonUtils.logDebugMsg(LOG, exceptionComment2 + "OperationFailedException: " + ofe.toString()); 089 }catch (PermissionDeniedException pde){ 090 AcalCommonUtils.logDebugMsg(LOG, exceptionComment2 + "PermissionDeniedException: " + pde.toString()); 091 } 092 return null; 093 } 094 095 private String getAdminOrgNameById(String id){ 096 //TODO: hard-coded for now, going to call OrgService 097 String adminOrgName = null; 098 Map<String, String> allHcOrgs = new HashMap<String, String>(); 099 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}