View Javadoc
1   /*
2    * RemoveWorkflowScriptAction.java
3    *
4    * Created on 13. November 2005, 04:51
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   * Action to remove a workflow script
32   * <p/>
33   * <ol>
34   * <li>get all project and remove the script to be deleted</li>
35   * <li>delete the script</li>
36   * </ol>
37   *
38   * @author mbae@bcwin.ch
39   */
40  public class RemoveWorkflowScriptAction extends ItrackerBaseAction {
41      private static final Logger log = Logger.getLogger(RemoveWorkflowScriptAction.class);
42  
43      /**
44       * executes the action which removes a workflow script
45       *
46       * @param form     the form with user input
47       * @param request  the request triggering the action
48       * @param response response to the client
49       * @param mapping  The action mapping
50       * @return the <code>ActionForward</code> to forward to
51       * @throws ServletException thrown if execution fails
52       * @throws IOException      thrown if io to client fails
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          // check permissions
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              // get the id from the form
68              Integer scriptId = (Integer) PropertyUtils.getSimpleProperty(form, "id");
69  
70              // remove the script
71              ServletContextUtils.getItrackerServices().getConfigurationService()
72                      .removeWorkflowScript(scriptId);
73  
74              // find the mapping for the list of all worksflows
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  }