View Javadoc

1   /**
2    * Copyright 2004-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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              // Handle security validation in targetEmployee action, we may need
58              // to check the document for validity, since the user may not
59              // necessarily be a system administrator.
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          //boolean synch = TKUser.isSynchronous();
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             //if (assignment != null) {
114             //    assignment.get
115             //}
116         /*if (principalId != null) {
117             if (TKUser.isSystemAdmin()) {
118                 return new ActionRedirect("/portal.do");
119             } else if (TKUser.isDepartmentAdmin()
120                     && !synch) {
121                 return new ActionRedirect("/portal.do");
122             } else if (TKUser.isApprover()
123                     && !synch) {
124                 return new ActionRedirect("/TimeApproval.do");
125             } else if (TKUser.isReviewer()
126                     && !synch) {
127                 return new ActionRedirect("/TimeApproval.do");
128             } else if (TKUser.isActiveEmployee()
129                     && !synch) {
130                 return new ActionRedirect("/TimeDetail.do");
131             } else if (synch) {
132                 return new ActionRedirect("/Clock.do");
133             } else {
134                 return new ActionRedirect("/PersonInfo.do");
135             }
136         }
137 	return super.execute(mapping, form, request, response);*/
138 }
139     
140 }