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.detail.web;
17  
18  
19  import javax.servlet.http.HttpServletRequest;
20  import javax.servlet.http.HttpServletResponse;
21  
22  import org.apache.commons.lang.StringUtils;
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.kuali.hr.time.base.web.TkAction;
28  import org.kuali.hr.time.roles.TkUserRoles;
29  import org.kuali.hr.time.roles.UserRoles;
30  import org.kuali.hr.time.service.base.TkServiceLocator;
31  import org.kuali.hr.time.timesheet.TimesheetDocument;
32  import org.kuali.hr.time.util.TKContext;
33  import org.kuali.hr.time.util.TkConstants;
34  import org.kuali.rice.kew.api.document.DocumentStatus;
35  import org.kuali.rice.krad.exception.AuthorizationException;
36  import org.kuali.rice.krad.util.GlobalVariables;
37  
38  public class TimesheetSubmitAction extends TkAction {
39  
40      @Override
41      protected void checkTKAuthorization(ActionForm form, String methodToCall) throws AuthorizationException {
42          TimesheetSubmitActionForm tsaf = (TimesheetSubmitActionForm)form;
43  
44          String principal = TKContext.getPrincipalId();
45          UserRoles roles = TkUserRoles.getUserRoles(GlobalVariables.getUserSession().getPrincipalId());
46  
47          TimesheetDocument document = TkServiceLocator.getTimesheetService().getTimesheetDocument(tsaf.getDocumentId());
48          if (!roles.isDocumentWritable(document)) {
49              throw new AuthorizationException(principal, "TimesheetSubmitAction", "");
50          }
51      }
52  
53  
54  
55  
56      public ActionForward approveTimesheet(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
57          TimesheetSubmitActionForm tsaf = (TimesheetSubmitActionForm)form;
58          TimesheetDocument document = TkServiceLocator.getTimesheetService().getTimesheetDocument(tsaf.getDocumentId());
59  
60          // Switched to grab the target (chain, resolution: target -> backdoor -> actual) user.
61          // Approvals still using backdoor > actual
62          if (StringUtils.equals(tsaf.getAction(), TkConstants.DOCUMENT_ACTIONS.ROUTE)) {
63              if (DocumentStatus.INITIATED.getCode().equals(document.getDocumentHeader().getDocumentStatus())
64                      || DocumentStatus.SAVED.getCode().equals(document.getDocumentHeader().getDocumentStatus())) {
65                  TkServiceLocator.getTimesheetService().routeTimesheet(TKContext.getTargetPrincipalId(), document);
66              }
67          } else if (StringUtils.equals(tsaf.getAction(), TkConstants.DOCUMENT_ACTIONS.APPROVE)) {
68              if (document.getDocumentHeader().getDocumentStatus().equals(DocumentStatus.ENROUTE.getCode())) {
69                  TkServiceLocator.getTimesheetService().approveTimesheet(TKContext.getPrincipalId(), document);
70              }
71          } else if (StringUtils.equals(tsaf.getAction(), TkConstants.DOCUMENT_ACTIONS.DISAPPROVE)) {
72              if (document.getDocumentHeader().getDocumentStatus().equals(DocumentStatus.ENROUTE.getCode())) {
73                  TkServiceLocator.getTimesheetService().disapproveTimesheet(TKContext.getPrincipalId(), document);
74              }
75          }
76          
77          TkServiceLocator.getTkSearchableAttributeService().updateSearchableAttribute(document, document.getAsOfDate());
78          ActionRedirect rd = new ActionRedirect(mapping.findForward("timesheetRedirect"));
79          rd.addParameter("documentId", tsaf.getDocumentId());
80  
81          return rd;
82      }
83  
84      public ActionForward approveApprovalTab(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
85      	TimesheetSubmitActionForm tsaf = (TimesheetSubmitActionForm)form;
86          TimesheetDocument document = TkServiceLocator.getTimesheetService().getTimesheetDocument(tsaf.getDocumentId());
87  
88          // Switched to grab the target (chain, resolution: target -> backdoor -> actual) user.
89          // Approvals still using backdoor > actual
90          if (StringUtils.equals(tsaf.getAction(), TkConstants.DOCUMENT_ACTIONS.ROUTE)) {
91              if (document.getDocumentHeader().getDocumentStatus().equals(DocumentStatus.INITIATED.getCode())) {
92                  TkServiceLocator.getTimesheetService().routeTimesheet(TKContext.getTargetPrincipalId(), document);
93              }
94          } else if (StringUtils.equals(tsaf.getAction(), TkConstants.DOCUMENT_ACTIONS.APPROVE)) {
95              if (document.getDocumentHeader().getDocumentStatus().equals(DocumentStatus.ENROUTE.getCode())) {
96                  TkServiceLocator.getTimesheetService().approveTimesheet(TKContext.getPrincipalId(), document);
97              }
98          } else if (StringUtils.equals(tsaf.getAction(), TkConstants.DOCUMENT_ACTIONS.DISAPPROVE)) {
99              if (document.getDocumentHeader().getDocumentStatus().equals(DocumentStatus.ENROUTE.getCode())) {
100                 TkServiceLocator.getTimesheetService().disapproveTimesheet(TKContext.getPrincipalId(), document);
101             }
102         }
103         TKContext.getUser().clearTargetUser();
104         return new ActionRedirect(mapping.findForward("approverRedirect"));
105 
106 
107     }
108 }