Пример #1
0
 public boolean vote(Issue issue) throws ServiceException {
   try {
     HttpPost post = new HttpPost(rootURL + "/issue/" + issue.getIssueId() + "/vote.json");
     HttpResponse response = execute(post);
     if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) {
       issue.setVoted(true);
       issue.setVotes(issue.getVotes() + 1);
       return true;
     } else return false;
   } catch (IOException e) {
     throw new ServiceException(MSG_CONNECT_ERROR, e);
   }
 }
Пример #2
0
  private String createHash(Issue issue) {
    String hash = null;
    try {
      MessageDigest md = MessageDigest.getInstance("SHA");

      try {
        md.update(issue.getAppName().getBytes("UTF8"));
        md.update(issue.getStacktrace().getBytes("UTF8"));
        byte[] hashBytes = md.digest();
        String hex = new BigInteger(1, hashBytes).toString(16);
        if (hex.length() % 2 != 0) hex = "0" + hex;
        hash = hex;
      } catch (UnsupportedEncodingException e) {
        Log.e(TAG, "Error generating bug hash using UTF8 encoding.", e);
      }
    } catch (NoSuchAlgorithmException e) {
      Log.e(TAG, "Error generating bug hash.  Failed to find SHA digest.", e);
    }
    return hash;
  }
Пример #3
0
  /* (non-Javadoc)
   * @see net.heroicefforts.viable.android.Repository#postIssue(net.heroicefforts.viable.android.Issue)
   */
  public int postIssue(Issue issue) throws ServiceException {
    try {
      HttpPost post = new HttpPost(rootURL + "/issue.json");
      List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(12);
      nameValuePairs.add(new BasicNameValuePair("issue_type", issue.getType()));
      nameValuePairs.add(new BasicNameValuePair("priority", issue.getPriority()));
      nameValuePairs.add(new BasicNameValuePair("app_name", issue.getAppName()));
      nameValuePairs.add(new BasicNameValuePair("summary", issue.getSummary()));
      nameValuePairs.add(new BasicNameValuePair("description", issue.getDescription()));
      for (String version : issue.getAffectedVersions())
        nameValuePairs.add(new BasicNameValuePair("app_version_name", version));
      if (issue.getStacktrace() != null)
        nameValuePairs.add(new BasicNameValuePair("stacktrace", issue.getStacktrace()));

      if (issue instanceof BugContext) {
        nameValuePairs.add(new BasicNameValuePair("phone_model", Build.MODEL));
        nameValuePairs.add(new BasicNameValuePair("phone_device", Build.DEVICE));
        nameValuePairs.add(
            new BasicNameValuePair("phone_version", String.valueOf(Build.VERSION.SDK_INT)));
      }

      if (Config.LOGD) Log.d(TAG, "post params:  " + nameValuePairs.toString());
      post.setEntity(new UrlEncodedFormEntity(nameValuePairs));

      // Execute HTTP Post Request
      HttpResponse response = execute(post);
      int responseCode = response.getStatusLine().getStatusCode();
      if (HttpStatus.SC_OK == responseCode || HttpStatus.SC_CREATED == responseCode) {
        JSONObject obj = readJSON(response);
        if (Config.LOGV) Log.v(TAG, "postIssue response:  \n" + obj.toString(4));
        // TODO pull dates from response
        Issue newIssue = new Issue(obj.getJSONObject("issue").toString(4));
        issue.copy(newIssue);
      } else throw new ServiceException(MSG_REMOTE_ERROR + responseCode);

      if (Config.LOGD) Log.d(TAG, "postIssue code " + responseCode);

      return responseCode;
    } catch (UnsupportedEncodingException e) {
      throw new ServiceException("Encoding error occurred parsing JIRA response", e);
    } catch (IOException e) {
      throw new ServiceException(MSG_CONNECT_ERROR, e);
    } catch (JSONException e) {
      throw new ServiceException(MSG_PARSE_ERROR, e);
    }
  }
Пример #4
0
  public int postIssueComment(Issue issue, Comment comment) throws ServiceException {
    try {
      HttpPost post = new HttpPost(rootURL + "/issue/" + issue.getIssueId() + "/comments.json");
      List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(12);
      nameValuePairs.add(new BasicNameValuePair("app_name", issue.getAppName()));
      nameValuePairs.add(new BasicNameValuePair("body", comment.getBody()));

      if (issue.getStacktrace() != null) {
        nameValuePairs.add(new BasicNameValuePair("phone_model", Build.MODEL));
        nameValuePairs.add(new BasicNameValuePair("phone_device", Build.DEVICE));
        nameValuePairs.add(
            new BasicNameValuePair("phone_version", String.valueOf(Build.VERSION.SDK_INT)));
      }

      if (Config.LOGD) Log.d(TAG, "post params:  " + nameValuePairs.toString());
      post.setEntity(new UrlEncodedFormEntity(nameValuePairs));

      // Execute HTTP Post Request
      HttpResponse response = execute(post);
      int responseCode = response.getStatusLine().getStatusCode();
      if (HttpStatus.SC_OK == responseCode || HttpStatus.SC_CREATED == responseCode) {
        JSONObject obj = readJSON(response);
        if (Config.LOGV) Log.v(TAG, "postIssueComment response:  \n" + obj.toString(4));
        // TODO pull dates from response
        Comment newComment = new Comment(obj);
        comment.copy(newComment);
      } else throw new ServiceException(MSG_REMOTE_ERROR + responseCode);

      if (Config.LOGD) Log.d(TAG, "postIssueComment code " + responseCode);

      return responseCode;
    } catch (UnsupportedEncodingException e) {
      throw new ServiceException("Encoding error occurred parsing JIRA response", e);
    } catch (IOException e) {
      throw new ServiceException(MSG_CONNECT_ERROR, e);
    } catch (JSONException e) {
      throw new ServiceException(MSG_PARSE_ERROR, e);
    }
  }