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.workflow;
20
21 import org.apache.commons.beanutils.PropertyUtils;
22 import org.apache.log4j.Logger;
23 import org.apache.struts.action.*;
24 import org.itracker.SystemConfigurationException;
25 import org.itracker.model.NameValuePair;
26 import org.itracker.model.WorkflowScript;
27 import org.itracker.model.util.UserUtilities;
28 import org.itracker.model.util.WorkflowUtilities;
29 import org.itracker.services.ConfigurationService;
30 import org.itracker.web.actions.base.ItrackerBaseAction;
31 import org.itracker.web.forms.WorkflowScriptForm;
32 import org.itracker.web.util.Constants;
33 import org.itracker.web.util.LoginUtilities;
34 import org.itracker.web.util.ServletContextUtils;
35
36 import javax.servlet.ServletException;
37 import javax.servlet.http.HttpServletRequest;
38 import javax.servlet.http.HttpServletResponse;
39 import javax.servlet.http.HttpSession;
40 import java.io.IOException;
41 import java.util.Arrays;
42 import java.util.Locale;
43
44 public class EditWorkflowScriptFormAction extends ItrackerBaseAction {
45 private static final Logger log = Logger.getLogger(EditWorkflowScriptFormAction.class);
46
47
48 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
49 ActionMessages errors = new ActionMessages();
50
51 boolean isUpdate = false;
52
53 try {
54 WorkflowScriptFormracker/web/forms/WorkflowScriptForm.html#WorkflowScriptForm">WorkflowScriptForm workflowScriptForm = (WorkflowScriptForm) form;
55
56 if (workflowScriptForm == null) {
57 workflowScriptForm = new WorkflowScriptForm();
58 }
59 String action = workflowScriptForm.getAction();
60
61
62 WorkflowScript workflowScript = new WorkflowScript();
63 if ("update".equals(action)) {
64 ConfigurationService configurationService = ServletContextUtils.getItrackerServices().getConfigurationService();
65
66
67 Integer id = (Integer) PropertyUtils.getSimpleProperty(workflowScriptForm, "id");
68 workflowScript = configurationService.getWorkflowScript(id);
69
70 if (workflowScript == null) {
71 throw new SystemConfigurationException("Invalid workflow script id " + id);
72 }
73
74 workflowScriptForm.setAction("update");
75 workflowScriptForm.setId(workflowScript.getId());
76 workflowScriptForm.setName(workflowScript.getName());
77 workflowScriptForm.setEvent(workflowScript.getEvent());
78 workflowScriptForm.setScript(workflowScript.getScript());
79 workflowScriptForm.setLanguage(workflowScript.getLanguage().name());
80
81
82 } else {
83 workflowScriptForm.setLanguage(WorkflowScript.ScriptLanguage.BeanShell.name());
84 }
85
86
87 if (errors.isEmpty()) {
88 HttpSession session = request.getSession(true);
89 request.setAttribute("workflowScriptForm", workflowScriptForm);
90 session.setAttribute(Constants.WORKFLOW_SCRIPT_KEY, workflowScript);
91 request.setAttribute("action", action);
92 saveToken(request);
93
94 setupFormEventTypes(workflowScriptForm, getLocale(request));
95
96 return mapping.getInputForward();
97 }
98 } catch (SystemConfigurationException sce) {
99 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.invalidworkflowscript"));
100 } catch (Exception e) {
101 log.error("Exception while creating edit workflowScript form.", e);
102 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
103 }
104
105 if (!errors.isEmpty()) {
106 saveErrors(request, errors);
107 }
108 return mapping.findForward("error");
109 }
110
111 public static void setupFormEventTypes(WorkflowScriptForm form, Locale locale) {
112 form.initEventOptions(locale);
113 }
114 }
115