コード例 #1
0
  private JSONObject generateMiniRecord(
      Storage storage, String auth_type, String inst_type, String csid) throws JSONException {

    JSONObject out = new JSONObject();
    try {
      String postfix = "list";
      if (this.search) {
        postfix = "search";
      }
      out =
          storage.retrieveJSON(
              auth_type + "/" + inst_type + "/" + csid + "/view/" + postfix, new JSONObject());
      out.put("csid", csid);
      out.put("recordtype", inst_type);
    } catch (ExistException e) {
      out.put("csid", csid);
      out.put("isError", true);
      JSONObject msg = new JSONObject();
      msg.put("severity", "error");
      msg.put("message", "Exist Exception:" + e.getMessage());
      JSONArray msgs = new JSONArray();
      msgs.put(msg);
      out.put("messages", msgs);
    } catch (UnimplementedException e) {
      out.put("csid", csid);
      out.put("isError", true);
      JSONObject msg = new JSONObject();
      msg.put("severity", "error");
      msg.put("message", "Unimplemented  Exception:" + e.getMessage());
      JSONArray msgs = new JSONArray();
      msgs.put(msg);
      out.put("messages", msgs);
    } catch (UnderlyingStorageException e) {
      out.put("csid", csid);
      out.put("isError", true);
      JSONObject msg = new JSONObject();
      msg.put("severity", "error");
      msg.put("message", "UnderlyingStorage Exception:" + e.getMessage());
      JSONArray msgs = new JSONArray();
      msgs.put(msg);
      out.put("messages", msgs);
    }
    return out;
  }
コード例 #2
0
  private void search_or_list_vocab(
      JSONObject out,
      Record rd,
      Instance n,
      Storage storage,
      JSONObject restriction,
      String resultstring,
      JSONObject temp)
      throws ExistException, UnimplementedException, UnderlyingStorageException, JSONException,
          UIException {

    JSONObject data = storage.getPathsJSON(rd.getID() + "/" + n.getTitleRef(), restriction);

    String[] paths = (String[]) data.get("listItems");
    JSONObject pagination = new JSONObject();
    if (data.has("pagination")) {
      pagination = data.getJSONObject("pagination");
      pagination.put("numInstances", "1");
    }

    JSONArray members = new JSONArray();
    /* Get a view of each */
    if (temp.has(resultstring)) {
      members = temp.getJSONArray(resultstring);
    }
    for (String result : paths) {

      if (temp.has(resultstring)) {
        temp.getJSONArray(resultstring)
            .put(generateMiniRecord(storage, rd.getID(), n.getTitleRef(), result));
        members = temp.getJSONArray(resultstring);
      } else {
        members.put(generateMiniRecord(storage, rd.getID(), n.getTitleRef(), result));
      }
    }

    out.put(resultstring, members);

    if (pagination != null) {
      if (temp.has("pagination")) {
        JSONObject pag2 = temp.getJSONObject("pagination");
        String itemsInPage = pag2.getString("itemsInPage");
        String pagSize = pag2.getString("pageSize");
        String totalItems = pag2.getString("totalItems");
        String numInstances = pag2.getString("numInstances");

        String itemsInPage1 = pagination.getString("itemsInPage");
        String pagSize1 = pagination.getString("pageSize");
        String totalItems1 = pagination.getString("totalItems");
        Integer numInstances1 = Integer.parseInt(numInstances);
        int iip = Integer.parseInt(itemsInPage) + Integer.parseInt(itemsInPage1);
        int ps = Integer.parseInt(pagSize) + Integer.parseInt(pagSize1);
        int ti = Integer.parseInt(totalItems) + Integer.parseInt(totalItems1);

        pagination.put("itemsInPage", Integer.toString(iip));
        pagination.put("pageSize", Integer.toString(ps));
        pagination.put("totalItems", Integer.toString(ti));
        pagination.put("numInstances", Integer.toString(numInstances1++));
      }
      out.put("pagination", pagination);
    }
    log.debug(restriction.toString());
  }