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.project;
20  
21  //import java.io.ByteArrayInputStream;
22  
23  import org.apache.log4j.Logger;
24  import org.apache.struts.action.*;
25  import org.itracker.model.Project;
26  import org.itracker.model.ProjectScript;
27  import org.itracker.services.ProjectService;
28  import org.itracker.model.util.UserUtilities;
29  import org.itracker.web.actions.base.ItrackerBaseAction;
30  import org.itracker.web.util.Constants;
31  
32  import javax.servlet.ServletException;
33  import javax.servlet.http.HttpServletRequest;
34  import javax.servlet.http.HttpServletResponse;
35  import javax.servlet.http.HttpSession;
36  import java.io.IOException;
37  
38  
39  public class RemoveProjectScriptAction extends ItrackerBaseAction {
40      private static final Logger log = Logger.getLogger(RemoveProjectScriptAction.class);
41  
42  
43      public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
44  
45          ActionMessages errors = new ActionMessages();
46  
47          if (!hasPermission(UserUtilities.PERMISSION_USER_ADMIN, request, response)) {
48              return mapping.findForward("unauthorized");
49          }
50  
51          resetToken(request);
52  
53          try {
54              ProjectService projectService = getITrackerServices().getProjectService();
55              String id = request.getParameter("delId");
56  
57              ProjectScript projectScript = projectService.getProjectScript(Integer.valueOf(id));
58              Project project = projectScript.getProject();
59              boolean status = projectService.removeProjectScript(project.getId(), Integer.valueOf(id));
60              if (!status) {
61                  log.debug("Error deleting script.  Redisplaying form for correction.");
62              }
63              HttpSession session = request.getSession(true);
64              session.removeAttribute(Constants.PROJECT_SCRIPT_KEY);
65              request.setAttribute("action", "update");
66              saveToken(request);
67              return new ActionForward(
68                      mapping.findForward("editproject").getPath()
69                              + "?id=" + project.getId() + "&action=update");
70          } catch (Exception e) {
71              log.error("Exception processing form data", e);
72              errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
73          }
74  
75          if (!errors.isEmpty()) {
76              saveErrors(request, errors);
77          }
78          return mapping.findForward("error");
79      }
80  
81  }