View Javadoc
1   /**
2    * Copyright 2004-2014 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.kpme.tklm.common;
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.struts.action.ActionForm;
23  import org.apache.struts.action.ActionForward;
24  import org.apache.struts.action.ActionMapping;
25  import org.kuali.kpme.core.web.KPMEAction;
26  import org.kuali.kpme.tklm.leave.service.LmServiceLocator;
27  import org.kuali.kpme.tklm.leave.workflow.LeaveCalendarDocumentHeader;
28  import org.kuali.kpme.tklm.time.service.TkServiceLocator;
29  import org.kuali.kpme.tklm.time.workflow.TimesheetDocumentHeader;
30  import org.kuali.rice.kew.service.KEWServiceLocator;
31  
32  public class DeleteDocumentAction extends KPMEAction {
33  
34      public ActionForward deleteDocument(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
35      	DeleteDocumentForm deleteDocumentForm = (DeleteDocumentForm) form;
36      	String documentId = deleteDocumentForm.getDeleteDocumentId();
37  
38      	if (StringUtils.isNotBlank(documentId)) {
39              TimesheetDocumentHeader tdh = TkServiceLocator.getTimesheetDocumentHeaderService().getDocumentHeader(documentId);
40              LeaveCalendarDocumentHeader ldh = LmServiceLocator.getLeaveCalendarDocumentHeaderService().getDocumentHeader(documentId);
41              
42              if(tdh != null) {
43              	TkServiceLocator.getClockLogService().deleteClockLogsForDocumentId(documentId);
44                  TkServiceLocator.getTimeBlockService().deleteTimeBlocksAssociatedWithDocumentId(documentId);
45      		    TkServiceLocator.getTimesheetService().deleteTimesheet(documentId);
46      		    deleteDocumentForm.setMessage("Timesheet deleted sucessfully.");
47              } else if (ldh != null) {
48              	LmServiceLocator.getLeaveBlockService().deleteLeaveBlocksForDocumentId(documentId);
49                  LmServiceLocator.getLeaveCalendarDocumentHeaderService().deleteLeaveCalendarHeader(documentId);
50                  deleteDocumentForm.setMessage("Leave Calendar deleted sucessfully.");
51              }
52              
53              // KPME - 3294 : Delete ActionList items
54             KEWServiceLocator.getActionListService().deleteByDocumentId(documentId);
55      		
56      	}
57      	
58      	return mapping.findForward("basic");
59      }
60  
61  }