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