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 java.io.IOException;
11  import java.lang.reflect.InvocationTargetException;
12  import java.util.Map;
13  import java.util.Set;
14  
15  import javax.servlet.ServletException;
16  import javax.servlet.http.HttpServletRequest;
17  import javax.servlet.http.HttpServletResponse;
18  import javax.servlet.http.HttpSession;
19  
20  import org.apache.commons.beanutils.PropertyUtils;
21  import org.apache.log4j.Logger;
22  import org.apache.struts.action.ActionForm;
23  import org.apache.struts.action.ActionForward;
24  import org.apache.struts.action.ActionMapping;
25  import org.apache.struts.action.ActionMessage;
26  import org.apache.struts.action.ActionMessages;
27  import org.itracker.model.PermissionType;
28  import org.itracker.services.util.UserUtilities;
29  import org.itracker.web.actions.base.ItrackerBaseAction;
30  
31  /**
32   * Action to remove a workflow script
33   *
34   * <ol>
35   *   <li>get all project and remove the script to be deleted</li>
36   *   <li>delete the script</li>
37   * </ol>
38   *
39   * @author mbae@bcwin.ch
40   */
41  public class RemoveWorkflowScriptAction extends ItrackerBaseAction {
42  	private static final Logger log = Logger.getLogger(RemoveWorkflowScriptAction.class);
43  	
44      /**
45       * executes the action which removes a workflow script 
46       *
47       * @param form the form with user input
48       * @param request the request triggering the action
49       * @param response response to the client
50       * @param mapping The action mapping
51       *
52       * @throws ServletException thrown if execution fails
53       * @throws IOException thrown if io to client fails
54       *
55       * @return the <code>ActionForward</code> to forward to
56       */
57  	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
58          ActionMessages errors = new ActionMessages();
59          ActionForward fw = mapping.findForward("error");
60  
61          
62          // check permissions
63          HttpSession session = request.getSession(true);
64          Map<Integer, Set<PermissionType>> userPermissionsMap = getUserPermissions(session);
65          if(! UserUtilities.hasPermission(userPermissionsMap, UserUtilities.PERMISSION_USER_ADMIN)) {
66              return mapping.findForward("unauthorized");
67          }
68          try {
69  
70              // get the id from the form
71              Integer scriptId = (Integer) PropertyUtils.getSimpleProperty(form, "id");
72              
73              // remove the script
74              this.getITrackerServices().getConfigurationService()
75                  .removeWorkflowScript(scriptId);
76          
77              // find the mapping for the list of all worksflows
78              fw = mapping.findForward( "listworkflow" );
79              
80          } catch (InvocationTargetException ex) {
81              log.error( ex.getMessage(), ex );
82              errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.invalidworkflowscript"));
83          } catch (NoSuchMethodException ex) {
84              log.error( ex.getMessage(), ex );
85              errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.invalidworkflowscript"));
86          } catch (IllegalAccessException ex) {
87              log.error( ex.getMessage(), ex );
88              errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.invalidworkflowscript"));
89          }
90          
91          if(! errors.isEmpty()) {
92          	saveErrors(request, errors);
93          }
94          return fw;
95       }
96  }