Esempio n. 1
0
  /**
   * Processes the request for suggesting developers who can fix an issue
   *
   * @param request
   * @param response
   * @throws JMSException
   * @throws ServletException
   * @throws IOException
   */
  private void processSuggestDevelopersRq(HttpServletRequest request, HttpServletResponse response)
      throws JMSException, ServletException, IOException {
    final AsyncContext context = request.startAsync();

    Long issueId = Long.parseLong(request.getParameter("issueId"));

    String requestId = Utils.genRequestID();
    String requestMsg =
        MessageUtils.genRecommenderIdentityMsg(Arrays.asList(new Long[] {issueId}), requestId);

    getRecommenderIdentityResponse(
        requestMsg,
        requestId,
        new MsgCallbackImpl(context) {
          @Override
          public void onSuccess(String msg) throws Exception {
            JSONObject result = MessageParser.parseRecommenderIdentitiesMsg(msg);

            Writer out = context.getResponse().getWriter();
            result.writeJSONString(out);
            out.flush();
            out.close();
            context.complete();
          }
        });
  }
Esempio n. 2
0
  /**
   * Processes the clients Duplicate issue detection request.
   *
   * @param request
   * @param response
   * @throws Exception
   */
  private void processDuplicateIssueRq(HttpServletRequest request, HttpServletResponse response)
      throws Exception {
    final AsyncContext context = request.startAsync();

    Properties props = createRequestProps(request);

    String requestId = Utils.genRequestID();
    String requestMsg = MessageUtils.genKEUIDuplicateIssueMsg(props, requestId);

    getKEUIResponse(
        requestMsg,
        requestId,
        new MsgCallbackImpl(context) {
          @Override
          public void onSuccess(String msg) throws Exception {
            JSONObject result = MessageParser.parseKEUIDuplicateResponse(msg);

            Writer out = context.getResponse().getWriter();
            result.writeJSONString(out);
            out.flush();
            out.close();
            context.complete();
          }
        });
  }
Esempio n. 3
0
  /**
   * Processes the clients commit details request.
   *
   * @param request
   * @param response
   * @throws Exception
   */
  private void processCommitDetailsRq(HttpServletRequest request, HttpServletResponse response)
      throws Exception {
    final AsyncContext context = request.startAsync();

    String itemId = request.getParameter(QUERY_PARAM);
    String requestId = Utils.genRequestID();

    String requestMsg = MessageUtils.genAPICommitDetailsMsg(itemId, requestId);

    getAPIResponse(
        requestMsg,
        requestId,
        new MsgCallbackImpl(context) {
          @Override
          public void onSuccess(String msg) throws Exception {
            JSONObject result = MessageParser.parseAPICommitDetailsMessage(msg);

            Writer out = context.getResponse().getWriter();
            result.writeJSONString(out);
            out.flush();
            out.close();
            context.complete();
          }
        });
  }
Esempio n. 4
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();
                    }
                  }
                });
          }
        });
  }
Esempio n. 5
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();
    }
  }