1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.itracker.web.actions.project;
20
21 import org.apache.log4j.Level;
22 import org.apache.log4j.Logger;
23 import org.apache.struts.action.*;
24 import org.itracker.model.*;
25 import org.itracker.model.util.WorkflowUtilities;
26 import org.itracker.services.IssueService;
27 import org.itracker.services.NotificationService;
28 import org.itracker.web.actions.base.ItrackerBaseAction;
29 import org.itracker.web.forms.IssueForm;
30 import org.itracker.web.util.*;
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 import java.util.Date;
38 import java.util.Map;
39 import java.util.Set;
40
41 public class EditIssueAction extends ItrackerBaseAction {
42 private static final Logger log = Logger.getLogger(EditIssueAction.class);
43
44 public ActionForward execute(ActionMapping mapping, ActionForm form,
45 HttpServletRequest request, HttpServletResponse response)
46 throws ServletException, IOException {
47 log.info("execute: called");
48 ActionMessages errors = new ActionMessages();
49 Date logDate = new Date();
50 Date startDate = new Date();
51 logTimeMillies("execute: called", logDate, log, Level.DEBUG);
52 if (!isTokenValid(request)) {
53 log.debug("execute: Invalid request token while editing issue.");
54
55 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
56 "itracker.web.error.transaction"));
57 saveErrors(request, errors);
58 log.info("execute: return to edit-issue");
59 saveToken(request);
60 return mapping.getInputForward();
61 }
62 resetToken(request);
63
64
65 try {
66 IssueService issueService = ServletContextUtils.getItrackerServices().getIssueService();
67
68
69 logTimeMillies("execute: got issueService", logDate, log, Level.DEBUG);
70 NotificationService notificationService = ServletContextUtils.getItrackerServices()
71 .getNotificationService();
72 HttpSession session = request.getSession(true);
73 User currUser = (User) session.getAttribute(Constants.USER_KEY);
74
75 Map<Integer, Set<PermissionType>> userPermissions = RequestHelper.getUserPermissions(session);
76 IssueForm../../../org/itracker/web/forms/IssueForm.html#IssueForm">IssueForm issueForm = (IssueForm) form;
77 int previousStatus = -1;
78 Issue issue;
79 try {
80 issue = issueService.getIssue(issueForm.getId());
81 } catch (Exception e) {
82 if (log.isDebugEnabled()) {
83 log.debug("could not load issue #" + issueForm.getId(), e);
84 }
85 issue = null;
86 }
87
88 if (issue == null) {
89 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
90 "itracker.web.error.invalidissue"));
91 saveErrors(request, errors);
92 log.info("execute: invalidissue " + issueForm.getId() + ", Forward: Error");
93 return mapping.findForward("error");
94 }
95
96 logTimeMillies("execute: got issue", logDate, log, Level.DEBUG);
97
98 Project project = issue.getProject();
99 logTimeMillies("execute: got project", logDate, log, Level.DEBUG);
100 if (project == null) {
101 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
102 "itracker.web.error.invalidproject"));
103 saveErrors(request, errors);
104 log.info("execute: Forward: Error");
105 return mapping.findForward("error");
106 } else if (project.getStatus() != Status.ACTIVE) {
107 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
108 "itracker.web.error.projectlocked"));
109 saveErrors(request, errors);
110 log.info("execute: Forward: Error");
111 return mapping.findForward("error");
112 } else if (!LoginUtilities.canEditIssue(issue)) {
113 log.info("execute: Forward: unauthorized");
114 return mapping.findForward("unauthorized");
115 }
116
117 logTimeMillies("execute: got scripts", logDate, log, Level.DEBUG);
118
119 issueForm.invokeProjectScripts(project, WorkflowUtilities.EVENT_FIELD_ONPRESUBMIT, errors);
120
121 logTimeMillies("execute: processed field scripts EVENT_FIELD_ONPRESUBMIT", logDate, log, Level.DEBUG);
122
123 if (errors.isEmpty()) {
124 previousStatus = issue.getStatus();
125 try {
126 if (LoginUtilities.hasPermission(project,
127 PermissionType.ISSUE_EDIT_FULL)) {
128 if (log.isDebugEnabled()) {
129 log.debug("execute: process full, " + issue);
130 }
131 issue = issueForm.processFullEdit(issue, project, currUser, userPermissions,
132 getLocale(request), issueService, errors);
133 logTimeMillies("execute: processed fulledit", logDate, log, Level.DEBUG);
134 } else {
135 if (log.isDebugEnabled()) {
136 log.debug("execute: process limited, " + issue);
137 }
138 issue = issueForm.processLimitedEdit(issue, project, currUser, userPermissions,
139 getLocale(request), issueService, errors);
140 logTimeMillies("execute: processed limited edit", logDate, log, Level.DEBUG);
141 }
142 } catch (Exception e) {
143 log.warn("execute: failed to update", e);
144 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.other"));
145 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(e.getMessage(), false));
146 }
147 }
148
149 if (errors.isEmpty()) {
150 if (log.isDebugEnabled()) {
151 log.debug("execute: sending notification for issue: " + issue
152 + " (HISTORIES: " + issueService.getIssueHistory(issue.getId()) + ")");
153 }
154 EditIssueActionUtil.sendNotification(issue.getId(), previousStatus,
155 getBaseURL(request), notificationService);
156 logTimeMillies("execute: sent notification", logDate, log, Level.DEBUG);
157
158 issueForm.invokeProjectScripts(project, WorkflowUtilities.EVENT_FIELD_ONPOSTSUBMIT, errors);
159
160 logTimeMillies("execute: processed field scripts EVENT_FIELD_ONPOSTSUBMIT", logDate, log, Level.DEBUG);
161
162 return EditIssueActionUtil.getReturnForward(issue, project, issueForm.getCaller(), mapping);
163 }
164 } catch (Exception e) {
165 log.error("execute: Exception processing form data", e);
166 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
167 "itracker.web.error.system"));
168 } finally {
169 logTimeMillies("execute: processed", startDate, log, Level.DEBUG);
170 }
171
172 if (!errors.isEmpty()) {
173 saveMessages(request, errors);
174 saveErrors(request, errors);
175 saveToken(request);
176
177 return mapping.getInputForward();
178 }
179
180 log.info("execute: Forward: Error");
181 return mapping.findForward("error");
182 }
183
184 }