Пример #1
0
  private JSONResult parse(String jsonString) {
    JSONResult ret = new JSONResult();

    JSON json = JSONSerializer.toJSON(jsonString);
    JSONObject jo = (JSONObject) json;
    ret.total = jo.getInt("totalCount");

    Set<String> names;

    JSONArray arrResults = jo.optJSONArray("results");
    if (arrResults != null) {
      names = getArray(arrResults);
    } else {
      JSONObject results = jo.optJSONObject("results");

      if (results != null) {
        names = Collections.singleton(getSingle(results));
      } else {
        LOGGER.warn("No results found");
        names = Collections.EMPTY_SET;
      }
    }

    ret.names = names;
    ret.returnedCount = names.size();

    return ret;
  }
 /**
  * Queries gerrit for the files included in this patch set.
  *
  * @param gerritQueryHandler the query handler, responsible for the queries to gerrit.
  * @return a list of files that are part of this patch set.
  */
 public List<String> getFiles(GerritQueryHandler gerritQueryHandler) {
   if (files == null) {
     files = new LinkedList<String>();
     try {
       List<JSONObject> jsonList = gerritQueryHandler.queryFiles("change:" + getChange().getId());
       for (JSONObject json : jsonList) {
         if (json.has("type") && "stats".equalsIgnoreCase(json.getString("type"))) {
           continue;
         }
         if (json.has("currentPatchSet")) {
           JSONObject currentPatchSet = json.getJSONObject("currentPatchSet");
           if (currentPatchSet.has("files")) {
             JSONArray changedFiles = currentPatchSet.optJSONArray("files");
             for (int i = 0; i < changedFiles.size(); i++) {
               JSONObject file = changedFiles.getJSONObject(i);
               files.add(file.getString("file"));
             }
           }
         }
       }
     } catch (IOException e) {
       logger.error("IOException occured. ", e);
     } catch (GerritQueryException e) {
       logger.error("Bad query. ", e);
     }
   }
   return files;
 }