1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.itracker.web.actions.admin.report;
20
21 import org.apache.log4j.Logger;
22 import org.apache.struts.action.*;
23 import org.itracker.model.PermissionType;
24 import org.itracker.model.util.UserUtilities;
25 import org.itracker.services.ReportService;
26 import org.itracker.web.actions.base.ItrackerBaseAction;
27 import org.itracker.web.util.RequestHelper;
28 import org.itracker.web.util.ServletContextUtils;
29
30 import javax.servlet.ServletException;
31 import javax.servlet.http.HttpServletRequest;
32 import javax.servlet.http.HttpServletResponse;
33 import javax.servlet.http.HttpSession;
34 import java.io.IOException;
35 import java.util.Map;
36 import java.util.Set;
37
38 public class RemoveReportAction extends ItrackerBaseAction {
39 private static final Logger log = Logger.getLogger(RemoveReportAction.class);
40
41 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
42 ActionMessages errors = new ActionMessages();
43
44 try {
45 HttpSession session = request.getSession(true);
46 Map<Integer, Set<PermissionType>> userPermissionsMap = RequestHelper.getUserPermissions(session);
47 if (!UserUtilities.hasPermission(userPermissionsMap, UserUtilities.PERMISSION_USER_ADMIN)) {
48 return mapping.findForward("unauthorized");
49 }
50
51 ReportService reportService = ServletContextUtils.getItrackerServices().getReportService();
52
53 Integer reportId = new Integer((request.getParameter("id") == null ? "-1" : request.getParameter("id")));
54 reportService.getReportDAO().delete(reportService.getReportDAO().findByPrimaryKey(reportId));
55 return mapping.findForward("listreportsadmin");
56 } catch (NumberFormatException nfe) {
57 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.invalidreport"));
58 log.debug("Invalid report id " + request.getParameter("id") + " specified.");
59 } catch (Exception e) {
60 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
61 log.error("System Error.", e);
62 }
63 if (!errors.isEmpty()) {
64 saveErrors(request, errors);
65 }
66 return mapping.findForward("error");
67 }
68
69 }