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