示例#1
0
  public Issue findById(String issueId) throws ServiceException {
    Issue issue = null;
    SearchParams params = new SearchParams();
    params.setIds(Arrays.asList(new String[] {issueId}));
    List<Issue> issues = search(params).getIssues();
    if (issues.size() > 0) issue = issues.get(0);

    return issue;
  }
示例#2
0
  public Issue exists(Issue issue) throws ServiceException {
    String hash = createHash(issue);

    SearchParams params = new SearchParams();
    params.setHash(hash);
    List<Issue> issues = search(params).getIssues();

    if (issues.size() > 0) {
      if (Config.LOGD) Log.d(TAG, "Hashed bug exists:  '" + hash + "'");
      return issues.get(0);
    } else {
      if (Config.LOGD) Log.d(TAG, "Hashed bug does not exist:  '" + hash + "'");
      return null;
    }
  }
示例#3
0
  /* (non-Javadoc)
   * @see net.heroicefforts.viable.android.Repository#search(net.heroicefforts.viable.android.SearchParams)
   */
  public SearchResults search(SearchParams params) throws ServiceException {
    try {
      HttpPost post = new HttpPost(rootURL + "/search");
      List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);

      if (params.getHash() != null)
        nameValuePairs.add(new BasicNameValuePair("hash", params.getHash()));

      if (params.getIds() != null)
        for (String id : params.getIds())
          nameValuePairs.add(new BasicNameValuePair("issue_id", id));

      if (params.getAffectedVersions() != null)
        for (String version : params.getAffectedVersions())
          nameValuePairs.add(new BasicNameValuePair("affected_version", version));

      if (params.getAppName() != null)
        nameValuePairs.add(new BasicNameValuePair("app_name", params.getAppName()));

      if (params.getPage() > 0)
        nameValuePairs.add(new BasicNameValuePair("page", String.valueOf(params.getPage())));

      if (params.getPageSize() > 0)
        nameValuePairs.add(
            new BasicNameValuePair("page_size", String.valueOf(params.getPageSize())));

      if (Config.LOGD) Log.d(TAG, "Posting search paramters:  " + nameValuePairs.toString());

      post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
      HttpResponse response = execute(post);
      int code = response.getStatusLine().getStatusCode();
      if (HttpStatus.SC_NOT_FOUND == code) {
        if (Config.LOGD) Log.d(TAG, "Search returned no results:  '" + params + "'");
        List<Issue> empty = Collections.emptyList();
        return new SearchResults(empty, false);
      } else if (HttpStatus.SC_OK == code) {
        JSONObject obj = readJSON(response);
        if (Config.LOGV) Log.v(TAG, "Search JSON:  " + obj.toString(4));
        List<Issue> issues = loadIssues(obj);
        boolean more = obj.getBoolean("more");
        if (Config.LOGD) Log.d(TAG, "Searched returned " + issues.size() + " results:  " + params);
        return new SearchResults(issues, more);
      } else throw new ServiceException(MSG_REMOTE_ERROR + code);
    } catch (JSONException e) {
      throw new ServiceException(MSG_PARSE_ERROR, e);
    } catch (IOException e) {
      throw new ServiceException(MSG_CONNECT_ERROR, e);
    }
  }