View Javadoc

1   package plugin;
2   
3   import javax.servlet.http.HttpServlet;
4   import javax.servlet.http.HttpServletRequest;
5   import javax.servlet.http.HttpServletResponse;
6   import java.io.IOException;
7   import java.util.StringTokenizer;
8   
9   /**
10   * This servlet intercepts the request that was made from the issue navigator to re-order the issues.
11   * After performing the actions necessary to change the values of the affected issues, it forwards to the top of the issue browser.
12   */
13  public class FAIssueOrdererServlet extends HttpServlet {
14  
15  
16      /**
17       * modify the issue order according to the provided action parameter
18       *
19       * @param request  The request object
20       * @param response The response object
21       * @throws IOException
22       */
23      public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
24  
25          //Recovery of the parameters of the request.
26          String customFieldName = request.getParameter("customFieldName");
27          String action = request.getParameter("action");
28          String issueKey = request.getParameter("issueKey");
29          String weight = request.getParameter("weight");
30          String numberOfBoxes = request.getParameter("numberOfBoxes");
31  
32          //Creation of a ValueAssigner object that handles the changes of the issues' value.
33          ValueAssigner assigner = new ValueAssigner();
34          assigner.doChangeValue(customFieldName, action, issueKey, weight, numberOfBoxes);
35  
36          //Forward to the issue navigator page
37          String adresse = getIssueNavigatorURL(request.getRequestURL().toString(), issueKey);
38          response.sendRedirect(adresse);
39      }
40  
41  
42      /**
43       * Return the URL of the issue navigator page on the anchor associated with the issue
44       *
45       * @param requestURL The request's URL
46       * @param issueKey   The issue's key
47       * @return The URL of the issue navigator page
48       */
49      public String getIssueNavigatorURL(String requestURL, String issueKey) {
50          String element[];
51          StringTokenizer tokenizer = new StringTokenizer(requestURL, "/");
52  
53          int numberOfTokens = tokenizer.countTokens();
54          element = new String[numberOfTokens];
55  
56          for (int i = 0; i < numberOfTokens; i++) {
57              element[i] = tokenizer.nextToken();
58          }
59          return "http://" + element[1] + "/secure/IssueNavigator.jspa#" + issueKey;
60      }
61  
62  
63  }