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 java.util.*;
19
20 import javax.servlet.http.HttpServletRequest;
21
22 import org.apache.commons.lang.StringUtils;
23 import org.apache.struts.action.ActionForm;
24 import org.displaytag.tags.TableTagParameters;
25 import org.displaytag.util.ParamEncoder;
26 import org.kuali.kpme.core.assignment.Assignment;
27 import org.kuali.kpme.core.calendar.entry.CalendarEntry;
28 import org.kuali.kpme.core.service.HrServiceLocator;
29 import org.kuali.kpme.core.util.HrConstants;
30 import org.kuali.kpme.core.util.HrContext;
31 import org.kuali.kpme.core.workarea.WorkArea;
32 import org.kuali.kpme.tklm.time.detail.web.ActionFormUtils;
33 import org.kuali.kpme.tklm.time.util.TkContext;
34 import org.kuali.rice.krad.exception.AuthorizationException;
35 import org.kuali.rice.krad.util.GlobalVariables;
36
37 public abstract class CalendarApprovalFormAction extends ApprovalFormAction {
38
39 @Override
40 protected void checkTKAuthorization(ActionForm form, String methodToCall) throws AuthorizationException {
41 if (!HrContext.isReviewer() && !HrContext.isAnyApprover() && !HrContext.isSystemAdmin() && !TkContext.isLocationAdmin() && !HrContext.isGlobalViewOnly()
42 && !TkContext.isDepartmentViewOnly() && !TkContext.isDepartmentAdmin() && !HrContext.isAnyPayrollProcessor()) {
43 throw new AuthorizationException(GlobalVariables.getUserSession().getPrincipalId(), "CalendarApprovalFormAction", "");
44 }
45 }
46
47 protected void setSearchFields(CalendarApprovalForm calendarApprovalForm) {
48 super.setSearchFields(calendarApprovalForm);
49
50 if (calendarApprovalForm.getCalendarDocument() != null) {
51 calendarApprovalForm.setSelectedPayCalendarGroup(calendarApprovalForm.getCalendarDocument().getCalendarEntry().getCalendarName());
52 for (Assignment assignment : calendarApprovalForm.getCalendarDocument().getAssignments()) {
53 WorkArea workArea = HrServiceLocator.getWorkAreaService().getWorkAreaWithoutRoles(assignment.getWorkArea(), assignment.getEffectiveLocalDate());
54 if (calendarApprovalForm.getDepartments().contains(workArea.getDept())) {
55 calendarApprovalForm.setSelectedDept(workArea.getDept());
56 break;
57 }
58 }
59 }
60 }
61
62 protected void setCalendarFields(CalendarApprovalForm calendarApprovalForm) {
63 Set<String> calendarYears = new TreeSet<String>(Collections.reverseOrder());
64 List<CalendarEntry> calendarEntries = getCalendarEntries(calendarApprovalForm.getCalendarEntry());
65
66 for (CalendarEntry calendarEntry : calendarEntries) {
67 String calendarEntryYear = calendarEntry.getBeginPeriodFullDateTime().toString("yyyy");
68 calendarYears.add(calendarEntryYear);
69 }
70
71 String currentCalendarYear = calendarApprovalForm.getCalendarEntry().getBeginPeriodFullDateTime().toString("yyyy");
72 String selectedCalendarYear = StringUtils.isNotBlank(calendarApprovalForm.getSelectedCalendarYear()) ? calendarApprovalForm.getSelectedCalendarYear() : currentCalendarYear;
73
74 calendarApprovalForm.setCalendarYears(new ArrayList<String>(calendarYears));
75 calendarApprovalForm.setPayPeriodsMap(ActionFormUtils.getPayPeriodsMap(ActionFormUtils.getAllCalendarEntriesForYear(calendarEntries, selectedCalendarYear), null));
76
77 calendarApprovalForm.setSelectedCalendarYear(selectedCalendarYear);
78 calendarApprovalForm.setSelectedPayPeriod(calendarApprovalForm.getCalendarEntry().getHrCalendarEntryId());
79 }
80
81 protected List<CalendarEntry> getCalendarEntries(CalendarEntry currentCalendarEntry) {
82 return HrServiceLocator.getCalendarEntryService().getAllCalendarEntriesForCalendarId(currentCalendarEntry.getHrCalendarId());
83 }
84
85
86
87
88
89
90
91
92
93
94
95 protected Boolean getAscending(HttpServletRequest request) {
96
97 String ascending = request.getParameter((new ParamEncoder(HrConstants.APPROVAL_TABLE_ID).encodeParameterName(TableTagParameters.PARAMETER_ORDER)));
98 return StringUtils.isEmpty(ascending) || StringUtils.equals(ascending, "1");
99 }
100
101 protected String getSortField(HttpServletRequest request) {
102 return request.getParameter((new ParamEncoder(HrConstants.APPROVAL_TABLE_ID).encodeParameterName(TableTagParameters.PARAMETER_SORT)));
103 }
104
105 }