1
2
3
4
5
6
7 package org.itracker.web.actions.admin.workflow;
8
9
10 import org.apache.commons.beanutils.PropertyUtils;
11 import org.apache.log4j.Logger;
12 import org.apache.struts.action.*;
13 import org.hibernate.exception.ConstraintViolationException;
14 import org.itracker.model.PermissionType;
15 import org.itracker.model.util.UserUtilities;
16 import org.itracker.web.actions.base.ItrackerBaseAction;
17 import org.itracker.web.util.RequestHelper;
18 import org.itracker.web.util.ServletContextUtils;
19 import org.springframework.dao.DataIntegrityViolationException;
20
21 import javax.servlet.ServletException;
22 import javax.servlet.http.HttpServletRequest;
23 import javax.servlet.http.HttpServletResponse;
24 import javax.servlet.http.HttpSession;
25 import java.io.IOException;
26 import java.lang.reflect.InvocationTargetException;
27 import java.util.Map;
28 import java.util.Set;
29
30
31
32
33
34
35
36
37
38
39
40 public class RemoveWorkflowScriptAction extends ItrackerBaseAction {
41 private static final Logger log = Logger.getLogger(RemoveWorkflowScriptAction.class);
42
43
44
45
46
47
48
49
50
51
52
53
54 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
55 ActionMessages errors = new ActionMessages();
56 ActionForward fw = mapping.findForward("error");
57
58
59
60 HttpSession session = request.getSession(true);
61 Map<Integer, Set<PermissionType>> userPermissionsMap = RequestHelper.getUserPermissions(session);
62 if (!UserUtilities.hasPermission(userPermissionsMap, UserUtilities.PERMISSION_USER_ADMIN)) {
63 return mapping.findForward("unauthorized");
64 }
65 try {
66
67
68 Integer scriptId = (Integer) PropertyUtils.getSimpleProperty(form, "id");
69
70
71 ServletContextUtils.getItrackerServices().getConfigurationService()
72 .removeWorkflowScript(scriptId);
73
74
75 fw = mapping.findForward("listworkflow");
76
77 } catch (InvocationTargetException ex) {
78 log.error(ex.getMessage(), ex);
79 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.invalidworkflowscript"));
80 } catch (NoSuchMethodException ex) {
81 log.error(ex.getMessage(), ex);
82 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.invalidworkflowscript"));
83 } catch (IllegalAccessException ex) {
84 log.error(ex.getMessage(), ex);
85 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.invalidworkflowscript"));
86 } catch (DataIntegrityViolationException ex) {
87 if (ex.getCause() instanceof ConstraintViolationException) {
88 log.error(ex.getMessage(), ex);
89 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.details",
90 ex.getLocalizedMessage()));
91 }
92 }
93
94 if (!errors.isEmpty()) {
95 saveErrors(request, errors);
96 }
97 return fw;
98 }
99 }