View Javadoc
1   /*
2    * This software was designed and created by Jason Carroll.
3    * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4    * The author can be reached at jcarroll@cowsultants.com
5    * ITracker website: http://www.cowsultants.com
6    * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7    *
8    * This program is free software; you can redistribute it and/or modify
9    * it only under the terms of the GNU General Public License as published by
10   * the Free Software Foundation; either version 2 of the License, or
11   * (at your option) any later version.
12   *
13   * This program is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   * GNU General Public License for more details.
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  }