1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.admin.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.kuali.hr.lm.leaveblock.LeaveBlock;
27 import org.kuali.hr.lm.workflow.LeaveCalendarDocumentHeader;
28 import org.kuali.hr.time.base.web.TkAction;
29 import org.kuali.hr.time.service.base.TkServiceLocator;
30 import org.kuali.hr.time.workflow.TimesheetDocumentHeader;
31
32 import java.util.List;
33
34 public class DeleteDocumentAction extends TkAction {
35
36 private static final Logger LOG = Logger.getLogger(DeleteDocumentAction.class);
37
38 public ActionForward deleteDocument(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
39 DeleteDocumentForm deleteDocumentForm = (DeleteDocumentForm) form;
40 String documentId = deleteDocumentForm.getDeleteDocumentId();
41
42
43 if (StringUtils.isNotBlank(documentId)) {
44 TimesheetDocumentHeader tdh = TkServiceLocator.getTimesheetDocumentHeaderService().getDocumentHeader(documentId);
45 if(tdh!=null){
46 TkServiceLocator.getTimeBlockService().deleteTimeBlocksAssociatedWithDocumentId(documentId);
47 TkServiceLocator.getTimesheetService().deleteTimesheet(documentId);
48 } else {
49 LeaveCalendarDocumentHeader ldh = TkServiceLocator.getLeaveCalendarDocumentHeaderService().getDocumentHeader(documentId);
50 if (ldh != null) {
51 TkServiceLocator.getLeaveBlockService().deleteLeaveBlocksForDocumentId(documentId);
52 TkServiceLocator.getLeaveCalendarDocumentHeaderService().deleteLeaveCalendarHeader(documentId);
53 }
54 }
55 LOG.debug("Deleting document: " + documentId);
56 }
57
58 return mapping.findForward("basic");
59 }
60
61 }