View Javadoc
1   package org.kuali.student.enrollment.class2.appointment.controller;
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.util.ObjectPropertyUtils;
7   import org.kuali.rice.krad.util.GlobalVariables;
8   import org.kuali.rice.krad.util.KRADConstants;
9   import org.kuali.rice.krad.web.controller.MethodAccessible;
10  import org.kuali.rice.krad.web.controller.UifControllerBase;
11  import org.kuali.rice.krad.web.form.UifFormBase;
12  import org.kuali.student.common.util.security.ContextUtils;
13  import org.kuali.student.enrollment.class2.appointment.dto.AppointmentWindowWrapper;
14  import org.kuali.student.enrollment.class2.appointment.form.RegistrationWindowsManagementForm;
15  import org.kuali.student.enrollment.class2.appointment.service.AppointmentViewHelperService;
16  import org.kuali.student.enrollment.class2.appointment.util.AppointmentConstants;
17  import org.kuali.student.enrollment.class2.appointment.util.AppointmentSlotRuleTypeConversion;
18  import org.kuali.student.r2.common.dto.ContextInfo;
19  import org.kuali.student.r2.common.dto.StatusInfo;
20  import org.kuali.student.r2.common.exceptions.DoesNotExistException;
21  import org.kuali.student.r2.common.exceptions.InvalidParameterException;
22  import org.kuali.student.r2.common.exceptions.MissingParameterException;
23  import org.kuali.student.r2.common.exceptions.OperationFailedException;
24  import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
25  import org.kuali.student.r2.common.util.date.DateFormatters;
26  import org.kuali.student.r2.core.acal.dto.KeyDateInfo;
27  import org.kuali.student.r2.core.acal.dto.TermInfo;
28  import org.kuali.student.r2.core.acal.service.AcademicCalendarService;
29  import org.kuali.student.r2.core.appointment.constants.AppointmentServiceConstants;
30  import org.kuali.student.r2.core.appointment.dto.AppointmentSlotInfo;
31  import org.kuali.student.r2.core.appointment.dto.AppointmentWindowInfo;
32  import org.kuali.student.r2.core.appointment.service.AppointmentService;
33  import org.kuali.student.r2.core.constants.AcademicCalendarServiceConstants;
34  import org.kuali.student.r2.core.constants.PopulationServiceConstants;
35  import org.kuali.student.r2.core.population.dto.PopulationInfo;
36  import org.kuali.student.r2.core.population.service.PopulationService;
37  import org.slf4j.LoggerFactory;
38  import org.springframework.stereotype.Controller;
39  import org.springframework.validation.BindingResult;
40  import org.springframework.web.bind.annotation.ModelAttribute;
41  import org.springframework.web.bind.annotation.RequestMapping;
42  import org.springframework.web.bind.annotation.RequestMethod;
43  import org.springframework.web.servlet.ModelAndView;
44  
45  import javax.servlet.http.HttpServletRequest;
46  import javax.servlet.http.HttpServletResponse;
47  import javax.xml.namespace.QName;
48  import java.util.ArrayList;
49  import java.util.Collection;
50  import java.util.Date;
51  import java.util.List;
52  import java.util.Properties;
53  
54  /**
55   * This class manages UI actions for registration windows
56   *
57   * @author Kuali Student Team
58   */
59  
60  @Controller
61  @RequestMapping(value = "/registrationWindows")
62  public class RegistrationWindowsController extends UifControllerBase {
63      private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(RegistrationWindowsController.class);
64  
65      private AppointmentViewHelperService viewHelperService;
66  
67      private AcademicCalendarService acalService;
68  
69      private AppointmentService appointmentService;
70  
71      private PopulationService populationService;
72  
73      @Override
74      protected UifFormBase createInitialForm(@SuppressWarnings("unused") HttpServletRequest request) {
75          return new RegistrationWindowsManagementForm();
76      }
77  
78      @Override
79      @RequestMapping(method = RequestMethod.GET, params = "methodToCall=start")
80      public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form,
81                                @SuppressWarnings("unused") HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) {
82  
83          if (!(form instanceof RegistrationWindowsManagementForm)) {
84              throw new IllegalArgumentException("Expected RegistrationWindowsManagementForm, got " + form.getClass().getSimpleName());
85          }
86  
87          RegistrationWindowsManagementForm theForm = (RegistrationWindowsManagementForm) form;
88          String termId = request.getParameter("termId");
89  
90          if (StringUtils.isNotBlank(termId)) {
91              try {
92                  getViewHelperService(theForm).loadTermAndPeriods(termId, theForm);
93                  return getUIFModelAndView(theForm);
94              } catch (Exception ex) {
95                  throw new RuntimeException(ex);
96              }
97          }
98  
99          return super.start(theForm, request, response);
100     }
101 
102     /**
103      * Method used to search term
104      */
105     @RequestMapping(params = "methodToCall=searchForTerm")
106     public ModelAndView searchForTerm(@ModelAttribute("KualiForm") RegistrationWindowsManagementForm searchForm, @SuppressWarnings("unused") BindingResult result,
107                                       @SuppressWarnings("unused") HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
108         String termType = searchForm.getTermType();
109         String termYear = searchForm.getTermYear();
110 
111         getViewHelperService(searchForm).searchForTerm(termType, termYear, searchForm);
112 
113         if (StringUtils.isNotEmpty(searchForm.getPeriodId())) {
114             // If they're reselecting a term we should clear out the period values.
115             searchForm.setPeriodId("");
116             populatePeriodCollections(searchForm);
117         }
118 
119         if (GlobalVariables.getMessageMap().hasErrors()) {
120             return getUIFModelAndView(searchForm, AppointmentConstants.SELECT_TERM_PAGE);
121         }
122 
123         return getUIFModelAndView(searchForm, AppointmentConstants.REGISTRATION_WINDOWS_EDIT_PAGE);
124     }
125 
126     @RequestMapping(params = "methodToCall=show")
127     public ModelAndView show(@ModelAttribute("KualiForm") RegistrationWindowsManagementForm form, @SuppressWarnings("unused") BindingResult result,
128                              @SuppressWarnings("unused") HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
129 
130         if (!form.isShowAddWindows()) {
131             form.setShowAddWindows(true);
132         }
133 
134         form = populatePeriodCollections(form);
135 
136         return getUIFModelAndView(form);
137     }
138 
139     @RequestMapping(params = "methodToCall=save")
140     public ModelAndView save(@ModelAttribute("KualiForm") RegistrationWindowsManagementForm form, @SuppressWarnings("unused") BindingResult result,
141                              @SuppressWarnings("unused") HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
142 
143         //Loop through the form's appointment windows and create/update them using the appointmentService
144         getViewHelperService(form).saveWindows(form);
145 
146         return getUIFModelAndView(form);
147     }
148 
149     @Override
150     @RequestMapping(params = "methodToCall=cancel")
151     public ModelAndView cancel(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
152                                HttpServletRequest request, HttpServletResponse response) {
153         // Reroute to the select term page on cancel
154         return getUIFModelAndView(form, AppointmentConstants.SELECT_TERM_PAGE);
155     }
156 
157     @RequestMapping(params = "methodToCall=assignStudents")
158     public ModelAndView assignStudents(@ModelAttribute("KualiForm") RegistrationWindowsManagementForm uifForm, @SuppressWarnings("unused") BindingResult result,
159                                        @SuppressWarnings("unused") HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
160 
161         ///First save selected window
162         AppointmentWindowWrapper window = _getSelectedWindow(uifForm, "Assign Students");
163         boolean isValid = getViewHelperService(uifForm).validateApptWindow(window, uifForm, false);
164         if (isValid) {
165             boolean isSaved = getViewHelperService(uifForm).saveApptWindow(window);
166 
167             //Now do the assignments of slot    s and students
168             if (window != null && isSaved) {
169                 //Create the appointment slots and assign students
170                 List<AppointmentSlotInfo> slots = getAppointmentService().generateAppointmentSlotsByWindow(window.getAppointmentWindowInfo().getId(), new ContextInfo());
171                 StatusInfo status = getAppointmentService().generateAppointmentsByWindow(window.getAppointmentWindowInfo().getId(), window.getAppointmentWindowInfo().getTypeKey(), new ContextInfo());
172 
173                 //Get feedback to the user6
174                 if (status.getIsSuccess()) {
175                     GlobalVariables.getMessageMap().addGrowlMessage("",
176                             AppointmentConstants.APPOINTMENT_MSG_INFO_ASSIGNED, window.getAppointmentWindowInfo().getName(), status.getMessage(), String.valueOf(slots.size()));
177                     //Update window state
178                     window.getAppointmentWindowInfo().setStateKey(AppointmentServiceConstants.APPOINTMENT_WINDOW_STATE_ASSIGNED_KEY);
179                 } else {
180                     //There was an error
181                     GlobalVariables.getMessageMap().addGrowlMessage("",
182                             AppointmentConstants.APPOINTMENT_MSG_ERROR_TOO_MANY_STUDENTS, status.getMessage());
183                 }
184             }
185         }
186         return getUIFModelAndView(uifForm);
187     }
188 
189     @RequestMapping(params = "methodToCall=breakAppointments")
190     public ModelAndView breakAppointments(@ModelAttribute("KualiForm") RegistrationWindowsManagementForm uifForm, @SuppressWarnings("unused") BindingResult result,
191                                           @SuppressWarnings("unused") HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
192 
193         Properties urlParameters = new Properties();
194         urlParameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, "refreshAfterDialog");
195         urlParameters.put(UifParameters.VIEW_ID, AppointmentConstants.REGISTRATION_WINDOWS_MANAGEMENT_VIEW);
196         urlParameters.put(UifParameters.PAGE_ID, AppointmentConstants.REGISTRATION_WINDOWS_EDIT_PAGE);
197         urlParameters.put(AppointmentConstants.URL_PARAM_PERIOD_ID, uifForm.getPeriodId());
198         urlParameters.put(AppointmentConstants.URL_PARAM_TERM_TYPE, uifForm.getTermType());
199         urlParameters.put(AppointmentConstants.URL_PARAM_TERM_YEAR, uifForm.getTermYear());
200         String controllerPath = AppointmentConstants.REGISTRATION_WINDOWS_CONTROLLER_PATH;
201 
202         String dialog = AppointmentConstants.Registration_Windows_ConfirmBreak_Dialog;
203         if (!hasDialogBeenDisplayed(dialog, uifForm) || !hasDialogBeenAnswered(dialog, uifForm)) {
204             AppointmentWindowWrapper window = _getSelectedWindow(uifForm, "Break Appointments");
205             uifForm.setSelectedAppointmentWindow(window);
206 
207             //redirect back to client to display lightbox
208             return showDialog(dialog, uifForm, request, response);
209         }
210 
211         boolean confirmDelete = getBooleanDialogResponse(dialog, uifForm, request, response);
212         uifForm.getDialogManager().resetDialogStatus(dialog);
213         if (!confirmDelete) {
214             return super.performRedirect(uifForm, controllerPath, urlParameters);
215         }
216 
217         AppointmentWindowWrapper window = uifForm.getSelectedAppointmentWindow();
218         if (window != null) {
219             //Delete the appointment slots and appointments for this window
220             StatusInfo status = getAppointmentService().deleteAppointmentSlotsByWindowCascading(window.getAppointmentWindowInfo().getId(), new ContextInfo());
221             if (status.getIsSuccess()) {
222                 //GlobalVariables.getMessageMap().addGrowlMessage( "", AppointmentConstants.APPOINTMENT_MSG_INFO_BREAK_APPOINTMENTS_SUCCESS);
223                 urlParameters.put("growlMessage", AppointmentConstants.APPOINTMENT_MSG_INFO_BREAK_APPOINTMENTS_SUCCESS);
224 
225                 //Update window state back to draft
226                 window.getAppointmentWindowInfo().setStateKey(AppointmentServiceConstants.APPOINTMENT_WINDOW_STATE_DRAFT_KEY);
227             } else {
228                 //There was an error
229                 //GlobalVariables.getMessageMap().addGrowlMessage( "", AppointmentConstants.APPOINTMENT_MSG_ERROR_BREAK_APPOINTMENTS_FAILURE, status.getMessage());
230                 urlParameters.put("growlMessage", AppointmentConstants.APPOINTMENT_MSG_ERROR_BREAK_APPOINTMENTS_FAILURE);
231                 urlParameters.put("windowName", status.getMessage());
232             }
233         }
234 
235         return super.performRedirect(uifForm, controllerPath, urlParameters);
236     }
237 
238     @RequestMapping(params = "methodToCall=deleteLineThroughDialog")
239     public ModelAndView deleteLineWithDialog(@ModelAttribute("KualiForm") RegistrationWindowsManagementForm uifForm, @SuppressWarnings("unused") BindingResult result,
240                                              @SuppressWarnings("unused") HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
241         Properties urlParameters = new Properties();
242         urlParameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, "refreshAfterDialog");
243         urlParameters.put(UifParameters.VIEW_ID, AppointmentConstants.REGISTRATION_WINDOWS_MANAGEMENT_VIEW);
244         urlParameters.put(UifParameters.PAGE_ID, AppointmentConstants.REGISTRATION_WINDOWS_EDIT_PAGE);
245         urlParameters.put(AppointmentConstants.URL_PARAM_PERIOD_ID, uifForm.getPeriodId());
246         urlParameters.put(AppointmentConstants.URL_PARAM_TERM_TYPE, uifForm.getTermType());
247         urlParameters.put(AppointmentConstants.URL_PARAM_TERM_YEAR, uifForm.getTermYear());
248         String controllerPath = AppointmentConstants.REGISTRATION_WINDOWS_CONTROLLER_PATH;
249 
250 //        TODO: KSENROLL-9721: Need to create a confirmation dialog in browser as opposed to make a server side round trip
251 
252         String dialog = AppointmentConstants.Registration_Windows_ConfirmDelete_Dialog;
253         if (!hasDialogBeenDisplayed(dialog, uifForm) || !hasDialogBeenAnswered(dialog, uifForm)) {
254             AppointmentWindowWrapper window = _getSelectedWindow(uifForm, "Delete a Window");
255             uifForm.setSelectedAppointmentWindow(window);
256 
257             //redirect back to client to display lightbox
258             return showDialog(dialog, uifForm, request, response);
259         }
260 
261         boolean confirmDelete = getBooleanDialogResponse(dialog, uifForm, request, response);
262         uifForm.getDialogManager().resetDialogStatus(dialog);
263         if (!confirmDelete) {
264             return super.performRedirect(uifForm, controllerPath, urlParameters);
265         }
266 
267 
268         AppointmentWindowWrapper window = uifForm.getSelectedAppointmentWindow();
269         if (window != null) {
270             if (AppointmentServiceConstants.APPOINTMENT_WINDOW_STATE_ASSIGNED_KEY.equals(window.getAppointmentWindowInfo().getStateKey())) {
271                 //need to break Assignment first
272                 //Delete the appointment slots and appointments for this window
273                 StatusInfo status = getAppointmentService().deleteAppointmentSlotsByWindowCascading(window.getAppointmentWindowInfo().getId(), new ContextInfo());
274                 if (status.getIsSuccess()) {
275                     getAppointmentService().deleteAppointmentWindowCascading(window.getId(), new ContextInfo());
276                     uifForm.removeSelectedAppointmentWindow(window);
277                     urlParameters.put("growlMessage", AppointmentConstants.APPOINTMENT_MSG_INFO_DELETED);
278                     urlParameters.put("windowName", window.getWindowName());
279                 } else {
280                     //There was an error
281                     urlParameters.put("growlMessage", AppointmentConstants.APPOINTMENT_MSG_ERROR_BREAK_APPOINTMENTS_FAILURE);
282                     urlParameters.put("windowName", status.getMessage());
283                 }
284             } else {
285                 getAppointmentService().deleteAppointmentWindowCascading(window.getId(), new ContextInfo());
286                 uifForm.removeSelectedAppointmentWindow(window);
287                 urlParameters.put("growlMessage", AppointmentConstants.APPOINTMENT_MSG_INFO_DELETED);
288                 urlParameters.put("windowName", window.getWindowName());
289             }
290         }
291 
292         return super.performRedirect(uifForm, controllerPath, urlParameters);
293     }
294 
295     @MethodAccessible
296     @RequestMapping(params = "methodToCall=refreshAfterDialog")
297     public ModelAndView refreshAfterDialog(@ModelAttribute("KualiForm") RegistrationWindowsManagementForm uifForm,
298                                            @SuppressWarnings("unused") BindingResult result,
299                                            @SuppressWarnings("unused") HttpServletRequest request,
300                                            @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
301 
302         String windowName = request.getParameter("windowName");
303         String growlMessage = request.getParameter("growlMessage");
304         if (growlMessage != null) {
305             if (windowName != null) {
306                 GlobalVariables.getMessageMap().addGrowlMessage("", growlMessage, windowName);
307             } else {
308                 GlobalVariables.getMessageMap().addGrowlMessage("", growlMessage);
309             }
310         }
311 
312         uifForm.setPeriodId(request.getParameter(AppointmentConstants.URL_PARAM_PERIOD_ID));
313         uifForm.setTermType(request.getParameter(AppointmentConstants.URL_PARAM_TERM_TYPE));
314         uifForm.setTermYear(request.getParameter(AppointmentConstants.URL_PARAM_TERM_YEAR));
315 
316         getViewHelperService(uifForm).searchForTerm(uifForm.getTermType(), uifForm.getTermYear(), uifForm);
317 
318         if (!uifForm.isShowAddWindows()) {
319             uifForm.setShowAddWindows(true);
320         }
321         uifForm = populatePeriodCollections(uifForm);
322 
323         return getUIFModelAndView(uifForm);
324     }
325 
326     private RegistrationWindowsManagementForm populatePeriodCollections(RegistrationWindowsManagementForm uifForm)
327             throws Exception {
328         String periodId = uifForm.getPeriodId();
329         String periodInfoDetails = "";
330 
331         //Clear all the windows
332         uifForm.getAppointmentWindows().clear();
333 
334         if (periodId == null || periodId.isEmpty()) {
335             uifForm.setPeriodInfoDetails(periodInfoDetails);
336             uifForm.setShowAddWindows(false);
337             uifForm.getAppointmentWindows().clear();
338         } else if (!periodId.isEmpty() && !periodId.equals("all")) {
339 
340             //Lookup the period information
341             KeyDateInfo period = getAcalService().getKeyDate(periodId, ContextUtils.getContextInfo());
342 
343             //pull in the windows for this period
344             List<KeyDateInfo> periods = new ArrayList<KeyDateInfo>();
345             periods.add(period);
346             _loadWindowsInfoForm(periods, uifForm);
347 
348             // display the period start/end time in details and the period name in the AddLine
349             AppointmentWindowWrapper addLine = (AppointmentWindowWrapper) uifForm.getNewCollectionLines().get("appointmentWindows");
350             if (addLine == null) {
351                 addLine = new AppointmentWindowWrapper();
352                 uifForm.getNewCollectionLines().put("appointmentWindows", addLine);
353             }
354 
355             if (period.getName() != null) {
356                 periodInfoDetails = period.getName() + " Start Date: " + _getSimpleDate(period.getStartDate()) + "<br>"
357                         + period.getName() + " End Date: " + _getSimpleDate(period.getEndDate());
358                 uifForm.setPeriodName(period.getName());
359                 uifForm.setPeriodId(period.getId());
360                 addLine.setPeriodName(period.getName());
361                 addLine.setPeriodKey(period.getId());
362             } else {
363                 periodInfoDetails = period.getId() + " Start Date: " + _getSimpleDate(period.getStartDate()) + "<br>"
364                         + period.getId() + " End Date: " + _getSimpleDate(period.getEndDate());
365                 uifForm.setPeriodName(period.getId());
366                 uifForm.setPeriodId(period.getId());
367                 addLine.setPeriodName(period.getId());
368                 addLine.setPeriodKey(period.getId());
369             }
370             uifForm.setPeriodInfoDetails(periodInfoDetails);
371 
372             //TODO: pull out all windows for that period and add to the collection
373         } else if (periodId.equals("all")) {
374             List<KeyDateInfo> periodMilestones = uifForm.getPeriodMilestones();
375             if (periodMilestones.isEmpty()) {
376                 TermInfo term = uifForm.getTermInfo();
377                 if (term.getId() != null && !term.getId().isEmpty()) {
378                     getViewHelperService(uifForm).loadPeriods(term.getId(), uifForm);
379                     periodMilestones = uifForm.getPeriodMilestones();
380                 }
381             }
382             for (KeyDateInfo period : periodMilestones) {
383 
384                 if (period.getName() != null) {
385                     periodInfoDetails = periodInfoDetails.concat(period.getName() + " Start Date: " + _getSimpleDate(period.getStartDate()) + "<br>"
386                             + period.getName() + " End Date: " + _getSimpleDate(period.getEndDate()) + "<br>");
387                 } else {
388                     periodInfoDetails = periodInfoDetails.concat(period.getId() + " Start Date: " + period.getStartDate() + "<br>"
389                             + period.getId() + " End Date: " + _getSimpleDate(period.getEndDate()) + "<br>");
390                 }
391             }
392             uifForm.setPeriodInfoDetails(periodInfoDetails);
393             _loadWindowsInfoForm(periodMilestones, uifForm);
394         }
395 
396         return uifForm;
397     }
398 
399     // this is a more generic way to get a selected window when the form contains more than one collection
400     private AppointmentWindowWrapper _getSelectedWindow(RegistrationWindowsManagementForm theForm, String actionLink) {
401         String selectedCollectionPath = theForm.getActionParamaterValue(UifParameters.SELECTED_COLLECTION_PATH);
402         if (StringUtils.isBlank(selectedCollectionPath)) {
403             throw new RuntimeException("Selected collection was not set for " + actionLink);
404         }
405 
406         int selectedLineIndex = -1;
407         String selectedLine = theForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX);
408         if (StringUtils.isNotBlank(selectedLine)) {
409             selectedLineIndex = Integer.parseInt(selectedLine);
410         }
411 
412         if (selectedLineIndex == -1) {
413             throw new RuntimeException("Selected line index was not set");
414         }
415 
416         Collection<Object> collection = ObjectPropertyUtils.getPropertyValue(theForm, selectedCollectionPath);
417         Object window = ((List<Object>) collection).get(selectedLineIndex);
418 
419         return (AppointmentWindowWrapper) window;
420     }
421 
422     private String _getSimpleDate(Date date) {
423         if (date == null) {
424             return "";
425         }
426         return DateFormatters.MONTH_DAY_YEAR_DATE_FORMATTER.format(date);
427     }
428 
429     private void _loadWindowsInfoForm(List<KeyDateInfo> periods, RegistrationWindowsManagementForm form) throws InvalidParameterException, MissingParameterException, DoesNotExistException, PermissionDeniedException, OperationFailedException {
430         for (KeyDateInfo period : periods) {
431             List<AppointmentWindowInfo> windows = getAppointmentService().getAppointmentWindowsByPeriod(period.getId(), new ContextInfo());
432             if (windows != null && windows.size() > 0) {
433                 for (AppointmentWindowInfo window : windows) {
434 
435                     //Look up the population
436                     PopulationInfo population = getPopulationService().getPopulation(window.getAssignedPopulationId(), new ContextInfo());
437 
438                     AppointmentWindowWrapper windowWrapper = new AppointmentWindowWrapper();
439 
440                     windowWrapper.setAppointmentWindowInfo(window);
441                     windowWrapper.setId(window.getId());
442                     windowWrapper.setWindowName(window.getName());
443                     windowWrapper.setPeriodKey(window.getPeriodMilestoneId());
444                     windowWrapper.setPeriodName(period.getName());
445                     windowWrapper.setAssignedPopulationName(population.getName());
446                     windowWrapper.setWindowTypeKey(window.getTypeKey());
447                     if (!AppointmentServiceConstants.APPOINTMENT_WINDOW_TYPE_ONE_SLOT_KEY.equals(window.getTypeKey())) {
448                         windowWrapper.setSlotRuleEnumType(AppointmentSlotRuleTypeConversion.convToAppointmentSlotRuleCode(window.getSlotRule()));
449                     }
450                     windowWrapper.setStartDate(window.getStartDate());
451                     windowWrapper.setStartTime(_parseTime(window.getStartDate()));
452                     windowWrapper.setStartTimeAmPm(_parseAmPm(window.getStartDate()));
453 
454                     windowWrapper.setEndDate(window.getEndDate());
455                     windowWrapper.setEndTime(_parseTime(window.getEndDate()));
456                     windowWrapper.setEndTimeAmPm(_parseAmPm(window.getEndDate()));
457 
458                     form.getAppointmentWindows().add(windowWrapper);
459                 }
460             }
461         }
462     }
463 
464     private String _parseAmPm(Date date) {
465         if (date == null) {
466             return null;
467         }
468         return DateFormatters.AM_PM_TIME_FORMATTER.format(date);
469     }
470 
471     private String _parseTime(Date date) {
472         if (date == null) {
473             return null;
474         }
475         return DateFormatters.HOUR_MINUTE_AM_PM_TIME_FORMATTER.format(date);
476     }
477 
478     public AppointmentViewHelperService getViewHelperService(RegistrationWindowsManagementForm appointmentForm) {
479         if (viewHelperService == null) {
480             viewHelperService = (AppointmentViewHelperService) appointmentForm.getViewHelperService();
481         }
482         return viewHelperService;
483     }
484 
485     public AcademicCalendarService getAcalService() {
486         if (acalService == null) {
487             acalService = (AcademicCalendarService) GlobalResourceLoader.getService(new QName(AcademicCalendarServiceConstants.NAMESPACE, AcademicCalendarServiceConstants.SERVICE_NAME_LOCAL_PART));
488         }
489         return this.acalService;
490     }
491 
492 
493     public AppointmentService getAppointmentService() {
494         if (appointmentService == null) {
495             appointmentService = (AppointmentService) GlobalResourceLoader.getService(new QName(AppointmentServiceConstants.NAMESPACE, AppointmentServiceConstants.SERVICE_NAME_LOCAL_PART));
496         }
497         return appointmentService;
498     }
499 
500     public PopulationService getPopulationService() {
501         if (populationService == null) {
502             populationService = (PopulationService) GlobalResourceLoader.getService(new QName(PopulationServiceConstants.NAMESPACE, "PopulationMockService")); // TODO: Refactor later with real PopService
503         }
504         return populationService;
505     }
506 
507 }