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.commons.lang.StringUtils;
24 import org.apache.commons.lang.math.NumberUtils;
25 import org.apache.log4j.Logger;
26 import org.apache.struts.action.*;
27 import org.itracker.model.*;
28 import org.itracker.model.util.UserUtilities;
29 import org.itracker.services.ConfigurationService;
30 import org.itracker.services.ProjectService;
31 import org.itracker.web.actions.base.ItrackerBaseAction;
32 import org.itracker.web.forms.ProjectScriptForm;
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 java.io.IOException;
40 import java.util.HashMap;
41 import java.util.Iterator;
42
43
44 public class EditProjectScriptAction extends ItrackerBaseAction {
45 private static final Logger log = Logger.getLogger(EditProjectScriptAction.class);
46
47 public EditProjectScriptAction() {
48 }
49
50 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
51
52 ActionMessages errors = new ActionMessages();
53
54 if (!LoginUtilities.hasPermission(PermissionType.USER_ADMIN, request, response)) {
55 return mapping.findForward("unauthorized");
56 }
57
58 if (!isTokenValid(request)) {
59 log.debug("Invalid request token while editing workflow script.");
60 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
61 "itracker.web.error.transaction"));
62 saveErrors(request, errors);
63 return mapping.findForward("listprojectscript");
64 }
65 resetToken(request);
66 ProjectScriptFormitracker/web/forms/ProjectScriptForm.html#ProjectScriptForm">ProjectScriptForm projectScriptForm = (ProjectScriptForm) form;
67
68 try {
69 ConfigurationService configurationService = ServletContextUtils.getItrackerServices().getConfigurationService();
70 ProjectService projectService = ServletContextUtils.getItrackerServices().getProjectService();
71
72 Integer projectId = projectScriptForm.getProjectId();
73 Project project = projectService.getProject(projectId);
74 HashMap<String, String> fieldIds = projectScriptForm.getFieldId();
75 HashMap<String, String> priorities = projectScriptForm.getPriority();
76 HashMap<String, String> scriptItems = projectScriptForm.getScriptItems();
77 for (Iterator<String> siIterator = scriptItems.keySet().iterator(); siIterator.hasNext(); ) {
78 String key = siIterator.next();
79 if (key != null) {
80 String scriptItemsvalue = scriptItems.get(key);
81 if ( (!StringUtils.isBlank(scriptItemsvalue))
82 && StringUtils.equalsIgnoreCase(StringUtils.trim(scriptItemsvalue), "on") ) {
83 Integer wfsIds = Integer.valueOf(key);
84 Integer fieldId = null;
85 Configuration.Type fieldType = Configuration.Type.customfield;
86 if (NumberUtils.isNumber(fieldIds.get(key))) {
87 fieldId = Integer.valueOf(fieldIds.get(key));
88 } else {
89 fieldType = Configuration.Type.valueOf(fieldIds.get(key));
90 fieldId = fieldType.getCode();
91 }
92
93 Integer priority = Integer.valueOf(priorities.get(key));
94 WorkflowScript workflowScript = configurationService.getWorkflowScript(wfsIds);
95 ProjectScript projectScript = new ProjectScript();
96
97 projectScript.setFieldId(fieldId);
98 projectScript.setFieldType(fieldType);
99 projectScript.setPriority(priority);
100 projectScript.setProject(project);
101 projectScript.setScript(workflowScript);
102 projectService.addProjectScript(projectId, projectScript);
103
104 }
105 }
106 }
107
108 saveToken(request);
109 return new ActionForward(
110 mapping.findForward("editproject").getPath()
111 + "?id=" + project.getId() + "&action=update");
112
113 } catch (RuntimeException e) {
114 log.error("Exception processing form data", e);
115 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
116 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.details", e.getMessage()));
117 }
118
119 if (!errors.isEmpty()) {
120 saveErrors(request, errors);
121 }
122 return mapping.findForward("error");
123 }
124
125
126 }