1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.web;
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.log4j.Logger;
23 import org.apache.struts.action.ActionForm;
24 import org.apache.struts.action.ActionForward;
25 import org.apache.struts.action.ActionMapping;
26 import org.apache.struts.action.ActionRedirect;
27 import org.joda.time.DateTime;
28 import org.kuali.hr.job.Job;
29 import org.kuali.hr.time.assignment.Assignment;
30 import org.kuali.hr.time.base.web.TkAction;
31 import org.kuali.hr.time.base.web.TkForm;
32 import org.kuali.hr.time.collection.rule.TimeCollectionRule;
33 import org.kuali.hr.time.principal.PrincipalHRAttributes;
34 import org.kuali.hr.time.roles.TkUserRoles;
35 import org.kuali.hr.time.roles.UserRoles;
36 import org.kuali.hr.time.service.base.TkServiceLocator;
37 import org.kuali.hr.time.util.TKContext;
38 import org.kuali.hr.time.util.TKUser;
39 import org.kuali.hr.time.util.TkConstants;
40 import org.kuali.hr.time.workarea.WorkArea;
41 import org.kuali.rice.krad.exception.AuthorizationException;
42 import org.kuali.rice.krad.util.GlobalVariables;
43
44 import java.sql.Date;
45 import java.util.List;
46 import java.util.Set;
47
48 public class TimeAction extends TkAction {
49
50 private static final Logger LOG = Logger.getLogger(TimeAction.class);
51
52 @Override
53 protected void checkTKAuthorization(ActionForm form, String methodToCall) throws AuthorizationException {
54 TkForm tkForm = (TkForm) form;
55
56 if (StringUtils.equals(methodToCall, "targetEmployee") || StringUtils.equals(methodToCall, "changeEmployee") || StringUtils.equals(methodToCall, "clearBackdoor") || StringUtils.equals(methodToCall, "clearChangeUser")) {
57
58
59
60 } else {
61 if (!TKUser.isSystemAdmin()
62 && !TKUser.isLocationAdmin()
63 && !TKUser.isDepartmentAdmin()
64 && !TKUser.isGlobalViewOnly()
65 && !TKUser.isDeptViewOnly()
66 && (tkForm.getDocumentId() != null && !TKUser.isApproverForTimesheet(tkForm.getDocumentId()))
67 && (tkForm.getDocumentId() != null && !TKUser.isDocumentReadable(tkForm.getDocumentId()))) {
68 throw new AuthorizationException("", "TimeAction", "");
69 }
70 }
71 }
72
73
74 @Override
75 public ActionForward execute(ActionMapping mapping, ActionForm form,
76 HttpServletRequest request, HttpServletResponse response)
77 throws Exception {
78
79 DateTime now = new DateTime();
80 String principalId = TKContext.getTargetPrincipalId();
81 if (TKUser.isSystemAdmin()) {
82 return new ActionRedirect("/portal.do");
83 }
84 PrincipalHRAttributes phra = TkServiceLocator.getPrincipalHRAttributeService().getPrincipalCalendar(principalId, now.toDate());
85 if (phra == null) {
86 return new ActionRedirect("/PersonInfo.do");
87 }
88 Job job = TkServiceLocator.getJobService().getPrimaryJob(principalId, now.toDate());
89 boolean activeAssignments = false;
90 if (job != null) {
91 String flsa = job.getFlsaStatus();
92 List<Assignment> assignments = TkServiceLocator.getAssignmentService().getActiveAssignmentsForJob(principalId, job.getJobNumber(), new Date(now.getMillis()));
93 for (Assignment asmnt : assignments) {
94 if (asmnt.isActive()) {
95 if (job.getFlsaStatus().equals(TkConstants.FLSA_STATUS_NON_EXEMPT)) {
96 TimeCollectionRule tcr = asmnt.getTimeCollectionRule();
97 if (tcr.isClockUserFl()) {
98 return new ActionRedirect("/Clock.do");
99 } else {
100 return new ActionRedirect("/TimeDetail.do");
101 }
102 } else {
103 if (job.isEligibleForLeave()) {
104 return new ActionRedirect("/LeaveCalendar.do");
105 }
106 }
107 }
108 }
109 }
110
111 return new ActionRedirect("/PersonInfo.do");
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138 }
139
140 }