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
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.commons.beanutils.PropertyUtils;
30 import org.apache.log4j.Logger;
31 import org.apache.struts.action.ActionForm;
32 import org.apache.struts.action.ActionForward;
33 import org.apache.struts.action.ActionMapping;
34 import org.apache.struts.action.ActionMessage;
35 import org.apache.struts.action.ActionMessages;
36 import org.itracker.model.WorkflowScript;
37 import org.itracker.services.ConfigurationService;
38 import org.itracker.services.util.UserUtilities;
39 import org.itracker.web.actions.base.ItrackerBaseAction;
40 import org.itracker.web.util.Constants;
41
42 import bsh.ParseException;
43
44
45 public class EditWorkflowScriptAction extends ItrackerBaseAction {
46 private static final Logger log = Logger.getLogger(EditWorkflowScriptAction.class);
47
48
49 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
50 ActionMessages errors = new ActionMessages();
51
52 if(! hasPermission(UserUtilities.PERMISSION_USER_ADMIN, request, response)) {
53 return mapping.findForward("unauthorized");
54 }
55
56 if(! isTokenValid(request)) {
57 log.debug("Invalid request token while editing workflow script.");
58 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
59 "itracker.web.error.transaction"));
60 saveErrors(request, errors);
61 return mapping.findForward("listworkflow");
62 }
63 resetToken(request);
64
65 WorkflowScript workflowScript = null;
66
67 try {
68 ConfigurationService configurationService = getITrackerServices().getConfigurationService();
69
70 String scriptData = (String) PropertyUtils.getSimpleProperty(form, "script");
71 if ( scriptData != null && scriptData.trim().length() > 0 ) {
72
73
74
75
76
77
78
79
80
81
82 }
83
84 log.info("Kimba: using this module action 1" );
85 workflowScript = new WorkflowScript();
86 workflowScript.setId((Integer) PropertyUtils.getSimpleProperty(form, "id"));
87 workflowScript.setName((String) PropertyUtils.getSimpleProperty(form, "name"));
88 workflowScript.setEvent(((Integer) PropertyUtils.getSimpleProperty(form, "event")).intValue());
89 workflowScript.setScript(scriptData);
90
91 String action = (String) PropertyUtils.getSimpleProperty(form, "action");
92 log.info("Kimba: using this module action 2"+action );
93 if("create".equals(action)) {
94 workflowScript = configurationService.createWorkflowScript(workflowScript);
95 } else if ("update".equals(action)) {
96 workflowScript = configurationService.updateWorkflowScript(workflowScript);
97 }
98
99 if (workflowScript == null) {
100 throw new Exception("Error creating/updating workflow script.");
101 }
102
103 HttpSession session = request.getSession(true);
104 session.removeAttribute(Constants.WORKFLOW_SCRIPT_KEY);
105 request.setAttribute("action",action);
106 saveToken(request);
107
108 return new ActionForward(mapping.findForward("listworkflow").getPath() + "?id=" + workflowScript.getId() +"&action=update");
109 } catch(ParseException pe) {
110 log.debug("Error parseing script. Redisplaying form for correction.", pe);
111 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.invalidscriptdata", pe.getMessage()));
112 saveErrors(request, errors);
113 saveToken(request);
114 return mapping.getInputForward();
115 } catch(Exception e) {
116 log.error("Exception processing form data", e);
117 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
118 }
119
120 if(! errors.isEmpty()) {
121 saveErrors(request, errors);
122 }
123 return mapping.findForward("error");
124 }
125
126 }
127