コード例 #1
0
  /**
   * Processes the request for recommending developers to fix an issue.
   *
   * @param request
   * @param response
   * @throws IOException
   * @throws ServletException
   * @throws JMSException
   */
  @SuppressWarnings("unchecked")
  private void processSuggestForPeopleRq(
      final HttpServletRequest request, HttpServletResponse response)
      throws IOException, JMSException, ServletException {
    final AsyncContext context = request.startAsync();

    final List<String> uuidList = Arrays.asList(new String[] {request.getParameter("person")});

    final Integer offset = Utils.parseInt(request.getParameter("offset"));
    final Integer limit = Utils.parseInt(request.getParameter("limit"));

    // send messages to Recommender to get the IDs
    final String requestId1 = Utils.genRequestID();

    String recommenderIssueRq = MessageUtils.genRecommenderIssuesMsg(uuidList, requestId1);
    getRecommenderIssueResponse(
        recommenderIssueRq,
        requestId1,
        new MsgCallbackImpl(context) {
          @Override
          public void onSuccess(String recommenderIssueResp) throws Exception {
            List<Long> issueIds = MessageParser.parseRecommenderIssueIdsMsg(recommenderIssueResp);
            Properties props = createRequestProps(request);

            // now that I have the issueIDs I have to send them to the KEUI component
            final String requestId2 = Utils.genRequestID();
            String keuiRq =
                MessageUtils.genKEUIIssueListByIdMsg(issueIds, props, offset, limit, requestId2);

            getKEUIResponse(
                keuiRq,
                requestId2,
                new MsgCallbackImpl(context) {
                  @Override
                  public void onSuccess(String keuiResp) throws Exception {
                    final JSONObject result = MessageParser.parseKEUIItemsResponse(keuiResp);

                    // on the first page also show the modules
                    if (offset == 0) {
                      final String requestId3 = Utils.genRequestID();
                      String recommenderModuleRq =
                          MessageUtils.genRecommenderModulesMsg(uuidList, requestId3);

                      getRecommenderModuleResponse(
                          recommenderModuleRq,
                          requestId3,
                          new MsgCallbackImpl(context) {
                            @Override
                            public void onSuccess(String recommenderModuleResp) throws Exception {
                              List<String> moduleIds =
                                  MessageParser.parseRecommenderModuleIdsMsg(recommenderModuleResp);

                              JSONArray modulesJSon = new JSONArray();
                              modulesJSon.addAll(moduleIds);
                              result.put("modules", modulesJSon);

                              Writer out = context.getResponse().getWriter();
                              result.writeJSONString(out);
                              out.flush();
                              out.close();
                              context.complete();
                            }
                          });
                    } else {
                      Writer out = context.getResponse().getWriter();
                      result.writeJSONString(out);
                      out.flush();
                      out.close();
                      context.complete();
                    }
                  }
                });
          }
        });
  }
コード例 #2
0
  /**
   * Processes the Issues related to my code request.
   *
   * @param request
   * @param response
   * @throws IOException
   * @throws ServletException
   * @throws JMSException
   * @throws SOAPException
   */
  private void processRelatedMyCodeRq(
      final HttpServletRequest request, HttpServletResponse response)
      throws IOException, JMSException, SOAPException, ServletException {
    final AsyncContext context = request.startAsync();

    // first check if the user is authenticated
    HttpSession session = request.getSession();

    boolean isAuthenticated =
        AuthenticatorService.authenticateUser(
            session.getAttribute(Configuration.USER_PRINCIPAL) != null
                ? (UserPrincipal) session.getAttribute(Configuration.USER_PRINCIPAL)
                : null);

    if (isAuthenticated) {
      UserPrincipal user = (UserPrincipal) session.getAttribute(Configuration.USER_PRINCIPAL);

      // send a message to Recommender to get the IDs of issues
      String uuid = user.getUuid();
      final Integer offset = Utils.parseInt(request.getParameter("offset"));
      final Integer limit = Utils.parseInt(request.getParameter("limit"));

      // first call API to get a list of issue URIs
      String requestId1 = Utils.genRequestID();
      String apiRq = MessageUtils.genAPIIssuesForUserMsg(uuid, requestId1);

      getAPIResponse(
          apiRq,
          requestId1,
          new MsgCallbackImpl(context) {
            @Override
            public void onSuccess(String apiResponse) throws Exception {
              List<Long> issueIds = MessageParser.parseAPIIssuesResponse(apiResponse);
              Properties props = createRequestProps(request);

              // now that I have the URIs, I have to call KEUI, to get the actual items
              String requestId2 = Utils.genRequestID();
              String keuiRq =
                  MessageUtils.genKEUIIssueListByIdMsg(issueIds, props, offset, limit, requestId2);

              getKEUIResponse(
                  keuiRq,
                  requestId2,
                  new MsgCallbackImpl(context) {
                    @Override
                    public void onSuccess(String keuiResp) throws Exception {
                      JSONObject result = MessageParser.parseKEUIItemsResponse(keuiResp);

                      Writer out = context.getResponse().getWriter();
                      result.writeJSONString(out);
                      out.flush();
                      out.close();
                      context.complete();
                    }
                  });
            }
          });
    } else {
      // if no user => send unauthorized
      if (log.isDebugEnabled())
        log.debug(
            "User with no session searching for issues related to their code, sending code 401!");

      response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
      context.complete();
    }
  }