001 /** 002 * Copyright 2004-2013 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.hr.time.detail.web; 017 018 019 import javax.servlet.http.HttpServletRequest; 020 import javax.servlet.http.HttpServletResponse; 021 022 import org.apache.commons.lang.StringUtils; 023 import org.apache.struts.action.ActionForm; 024 import org.apache.struts.action.ActionForward; 025 import org.apache.struts.action.ActionMapping; 026 import org.apache.struts.action.ActionRedirect; 027 import org.kuali.hr.time.base.web.TkAction; 028 import org.kuali.hr.time.roles.TkUserRoles; 029 import org.kuali.hr.time.roles.UserRoles; 030 import org.kuali.hr.time.service.base.TkServiceLocator; 031 import org.kuali.hr.time.timesheet.TimesheetDocument; 032 import org.kuali.hr.time.util.TKContext; 033 import org.kuali.hr.time.util.TkConstants; 034 import org.kuali.rice.kew.api.document.DocumentStatus; 035 import org.kuali.rice.krad.exception.AuthorizationException; 036 import org.kuali.rice.krad.util.GlobalVariables; 037 038 public class TimesheetSubmitAction extends TkAction { 039 040 @Override 041 protected void checkTKAuthorization(ActionForm form, String methodToCall) throws AuthorizationException { 042 TimesheetSubmitActionForm tsaf = (TimesheetSubmitActionForm)form; 043 044 String principal = TKContext.getPrincipalId(); 045 UserRoles roles = TkUserRoles.getUserRoles(GlobalVariables.getUserSession().getPrincipalId()); 046 047 TimesheetDocument document = TkServiceLocator.getTimesheetService().getTimesheetDocument(tsaf.getDocumentId()); 048 if (!roles.isDocumentWritable(document)) { 049 throw new AuthorizationException(principal, "TimesheetSubmitAction", ""); 050 } 051 } 052 053 054 055 056 public ActionForward approveTimesheet(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 057 TimesheetSubmitActionForm tsaf = (TimesheetSubmitActionForm)form; 058 TimesheetDocument document = TkServiceLocator.getTimesheetService().getTimesheetDocument(tsaf.getDocumentId()); 059 060 // Switched to grab the target (chain, resolution: target -> backdoor -> actual) user. 061 // Approvals still using backdoor > actual 062 if (StringUtils.equals(tsaf.getAction(), TkConstants.DOCUMENT_ACTIONS.ROUTE)) { 063 if (DocumentStatus.INITIATED.getCode().equals(document.getDocumentHeader().getDocumentStatus()) 064 || DocumentStatus.SAVED.getCode().equals(document.getDocumentHeader().getDocumentStatus())) { 065 TkServiceLocator.getTimesheetService().routeTimesheet(TKContext.getTargetPrincipalId(), document); 066 } 067 } else if (StringUtils.equals(tsaf.getAction(), TkConstants.DOCUMENT_ACTIONS.APPROVE)) { 068 if (document.getDocumentHeader().getDocumentStatus().equals(DocumentStatus.ENROUTE.getCode())) { 069 TkServiceLocator.getTimesheetService().approveTimesheet(TKContext.getPrincipalId(), document); 070 } 071 } else if (StringUtils.equals(tsaf.getAction(), TkConstants.DOCUMENT_ACTIONS.DISAPPROVE)) { 072 if (document.getDocumentHeader().getDocumentStatus().equals(DocumentStatus.ENROUTE.getCode())) { 073 TkServiceLocator.getTimesheetService().disapproveTimesheet(TKContext.getPrincipalId(), document); 074 } 075 } 076 077 TkServiceLocator.getTkSearchableAttributeService().updateSearchableAttribute(document, document.getAsOfDate()); 078 ActionRedirect rd = new ActionRedirect(mapping.findForward("timesheetRedirect")); 079 rd.addParameter("documentId", tsaf.getDocumentId()); 080 081 return rd; 082 } 083 084 public ActionForward approveApprovalTab(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 085 TimesheetSubmitActionForm tsaf = (TimesheetSubmitActionForm)form; 086 TimesheetDocument document = TkServiceLocator.getTimesheetService().getTimesheetDocument(tsaf.getDocumentId()); 087 088 // Switched to grab the target (chain, resolution: target -> backdoor -> actual) user. 089 // Approvals still using backdoor > actual 090 if (StringUtils.equals(tsaf.getAction(), TkConstants.DOCUMENT_ACTIONS.ROUTE)) { 091 if (document.getDocumentHeader().getDocumentStatus().equals(DocumentStatus.INITIATED.getCode())) { 092 TkServiceLocator.getTimesheetService().routeTimesheet(TKContext.getTargetPrincipalId(), document); 093 } 094 } else if (StringUtils.equals(tsaf.getAction(), TkConstants.DOCUMENT_ACTIONS.APPROVE)) { 095 if (document.getDocumentHeader().getDocumentStatus().equals(DocumentStatus.ENROUTE.getCode())) { 096 TkServiceLocator.getTimesheetService().approveTimesheet(TKContext.getPrincipalId(), document); 097 } 098 } else if (StringUtils.equals(tsaf.getAction(), TkConstants.DOCUMENT_ACTIONS.DISAPPROVE)) { 099 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 }