1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.itracker.web.actions.admin.project;
20
21
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 }