RemoveHistoryEntryAction.java

  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. package org.itracker.web.actions.project;

  19. import org.apache.commons.beanutils.PropertyUtils;
  20. import org.apache.log4j.Logger;
  21. import org.apache.struts.action.*;
  22. import org.itracker.model.User;
  23. import org.itracker.services.IssueService;
  24. import org.itracker.web.actions.base.ItrackerBaseAction;
  25. import org.itracker.web.util.Constants;
  26. import org.itracker.web.util.ServletContextUtils;

  27. import javax.servlet.ServletException;
  28. import javax.servlet.http.HttpServletRequest;
  29. import javax.servlet.http.HttpServletResponse;
  30. import javax.servlet.http.HttpSession;
  31. import java.io.IOException;


  32. public class RemoveHistoryEntryAction extends ItrackerBaseAction {
  33.     private static final Logger log = Logger.getLogger(RemoveHistoryEntryAction.class);


  34.     public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

  35.         ActionMessages errors = new ActionMessages();

  36.         try {
  37.             IssueService issueService = ServletContextUtils.getItrackerServices().getIssueService();

  38.             Integer historyId = (Integer) PropertyUtils.getSimpleProperty(form, "historyId");
  39.             String caller = (String) PropertyUtils.getSimpleProperty(form, "caller");
  40.             if (caller == null) {
  41.                 caller = "";
  42.             }

  43.             HttpSession session = request.getSession(true);
  44.             User currUser = (User) session.getAttribute(Constants.USER_KEY);
  45.             if (!currUser.isSuperUser()) {
  46.                 return mapping.findForward("unauthorized");
  47.             } else {
  48.                 Integer issueId = issueService.removeIssueHistoryEntry(historyId, currUser.getId());
  49.                 return new ActionForward(mapping.findForward("editissue").getPath() + "?id=" + issueId + "&caller=" + caller);
  50.             }
  51.         } catch (Exception e) {
  52.             errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
  53.             log.error("System Error.", e);
  54.         }
  55.         if (!errors.isEmpty()) {
  56.             saveErrors(request, errors);
  57.         }
  58.         return mapping.findForward("error");
  59.     }

  60. }
  61.