1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.tklm.common;
17
18 import javax.servlet.http.HttpServletRequest;
19 import javax.servlet.http.HttpServletResponse;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.apache.struts.action.ActionForm;
23 import org.apache.struts.action.ActionForward;
24 import org.apache.struts.action.ActionMapping;
25 import org.kuali.kpme.core.calendar.Calendar;
26 import org.kuali.kpme.core.calendar.entry.CalendarEntry;
27 import org.kuali.kpme.core.service.HrServiceLocator;
28 import org.kuali.kpme.core.web.KPMEAction;
29 import org.kuali.kpme.tklm.leave.service.LmServiceLocator;
30 import org.kuali.kpme.tklm.time.service.TkServiceLocator;
31 import org.kuali.rice.kim.api.identity.principal.Principal;
32 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
33
34 public class InitiateDocumentAction extends KPMEAction {
35
36 public ActionForward initiateDocument(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
37 InitiateDocumentForm initiateDocumentForm = (InitiateDocumentForm) form;
38 String principalId = initiateDocumentForm.getPrincipalId();
39 String hrCalendarEntryId = initiateDocumentForm.getHrCalendarEntryId();
40
41 if (StringUtils.isNotBlank(principalId) && StringUtils.isNotBlank(hrCalendarEntryId)) {
42 Principal principal = KimApiServiceLocator.getIdentityService().getPrincipal(principalId);
43 CalendarEntry calendarEntry = HrServiceLocator.getCalendarEntryService().getCalendarEntry(hrCalendarEntryId);
44
45 if (principal != null && calendarEntry != null) {
46 Calendar calendar = HrServiceLocator.getCalendarService().getCalendar(calendarEntry.getHrCalendarId());
47
48 if (calendar != null) {
49 if (StringUtils.equals(calendar.getCalendarTypes(), TkConstants.CALENDAR_TYPE_PAY)) {
50 TkServiceLocator.getTimesheetService().openTimesheetDocument(principalId, calendarEntry);
51 } else if (StringUtils.equals(calendar.getCalendarTypes(), TkConstants.CALENDAR_TYPE_LEAVE)) {
52 LmServiceLocator.getLeaveCalendarService().openLeaveCalendarDocument(principalId, calendarEntry);
53 }
54 }
55 }
56 }
57
58 return mapping.findForward("basic");
59 }
60
61 }