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