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 import org.apache.commons.beanutils.PropertyUtils;
22 import org.apache.log4j.Logger;
23 import org.apache.struts.action.*;
24 import org.itracker.model.CustomField;
25 import org.itracker.model.Project;
26 import org.itracker.model.ProjectScript;
27 import org.itracker.model.WorkflowScript;
28 import org.itracker.model.util.CustomFieldUtilities;
29 import org.itracker.model.util.UserUtilities;
30 import org.itracker.services.ConfigurationService;
31 import org.itracker.services.ProjectService;
32 import org.itracker.web.actions.base.ItrackerBaseAction;
33 import org.itracker.web.forms.ProjectScriptForm;
34 import org.itracker.web.util.EditProjectFormActionUtil;
35 import org.itracker.web.util.LoginUtilities;
36 import org.itracker.web.util.ServletContextUtils;
37
38 import javax.servlet.ServletException;
39 import javax.servlet.http.HttpServletRequest;
40 import javax.servlet.http.HttpServletResponse;
41 import java.io.IOException;
42 import java.lang.reflect.InvocationTargetException;
43 import java.util.HashMap;
44 import java.util.List;
45 import java.util.Locale;
46 import java.util.Map;
47
48
49
50
51
52 public class EditProjectScriptFormAction extends ItrackerBaseAction {
53 private static final Logger log = Logger.getLogger(EditProjectScriptFormAction.class);
54
55 public EditProjectScriptFormAction() {
56 }
57
58 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
59
60 ActionMessages errors = new ActionMessages();
61
62 if (!LoginUtilities.hasPermission(UserUtilities.PERMISSION_USER_ADMIN, request, response)) {
63 return mapping.findForward("unauthorized");
64 }
65 boolean isUpdate = false;
66 String pageTitleKey = "";
67 String pageTitleArg = "";
68 String action = "";
69 Project project;
70
71 try {
72
73 ProjectScriptFormitracker/web/forms/ProjectScriptForm.html#ProjectScriptForm">ProjectScriptForm projectScriptForm = (ProjectScriptForm) form;
74 final ProjectService projectService = ServletContextUtils.getItrackerServices().getProjectService();
75 final ConfigurationService configurationService = ServletContextUtils.getItrackerServices().getConfigurationService();
76
77 if (projectScriptForm == null) {
78 projectScriptForm = new ProjectScriptForm();
79 }
80 final List<WorkflowScript> workflowScripts = configurationService.getWorkflowScripts();
81
82
83 Integer projectId = (Integer) PropertyUtils.getSimpleProperty(projectScriptForm, "projectId");
84 projectScriptForm.setProjectId(projectId);
85 project = projectService.getProject(projectId);
86
87 final List<ProjectScript> projectScripts = project.getScripts();
88 pageTitleKey = "itracker.web.admin.editprojectscript.title.create";
89
90
91 if (errors.isEmpty()) {
92 request.setAttribute("workflowScripts", workflowScripts);
93 request.setAttribute("projectScripts", projectScripts);
94
95 final Locale locale = LoginUtilities.getCurrentLocale(request);
96 Map<String, String> customFieldsMapped = new HashMap<String, String>(project.getCustomFields().size());
97 for (CustomField field: project.getCustomFields()) {
98 String name = CustomFieldUtilities.getCustomFieldName(field.getId(), locale);
99 name += " ";
100 name += CustomFieldUtilities.getTypeString(field.getFieldType(), locale);
101 customFieldsMapped.put(String.valueOf(field.getId()), name);
102 }
103
104 request.setAttribute("customFields", customFieldsMapped);
105 request.setAttribute("projectScriptForm", projectScriptForm);
106 EditProjectFormActionUtil.setUpPrioritiesInEnv(request);
107 request.setAttribute("project", project);
108
109 saveToken(request);
110 request.setAttribute("pageTitleKey", pageTitleKey);
111 request.setAttribute("pageTitleArg", pageTitleArg);
112 return mapping.getInputForward();
113 }
114 } catch (RuntimeException e) {
115 log.error("Exception while the " + action + " of ProjectScript form.", e);
116 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
117 } catch (IllegalAccessException e) {
118 log.error("Exception while the " + action + " of ProjectScript form.", e);
119 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
120 } catch (InvocationTargetException e) {
121 log.error("Exception while the " + action + " of ProjectScript form.", e);
122 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
123 } catch (NoSuchMethodException e) {
124 log.error("Exception while the " + action + " of ProjectScript form.", e);
125 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
126 }
127
128 if (!errors.isEmpty()) {
129 saveErrors(request, errors);
130 }
131 request.setAttribute("pageTitleKey", pageTitleKey);
132 request.setAttribute("pageTitleArg", pageTitleArg);
133 request.setAttribute("isUpdate", isUpdate);
134 return mapping.findForward("error");
135 }
136
137 }