示例#1
0
  private void termlist(CSPRequestCache cache, Storage storage, UIRequest request, String path)
      throws UIException {
    try {
      // {tenant}/{tenantname}/{recordType}/termList/{termListType}
      // needs to be {tenant}/{tenantname}/{recordType}/termList/{fieldname}
      // as blanks etc are on a field basis not a vocab basis
      String[] bits = path.split("/");
      Record vb = this.spec.getRecord("vocab");
      Field f = (Field) r.getFieldTopLevel(bits[0]);
      if (f == null) {
        f = (Field) r.getFieldFullList(bits[0]);
      }
      // If the field isn't in this record, look for it in subrecords (e.g. contacts).
      if (f == null) {
        FieldSet[] subRecordFields = r.getAllSubRecords("GET");

        for (int i = 0; i < subRecordFields.length; i++) {
          FieldSet subRecordField = subRecordFields[i];
          Group group = (Group) subRecordField;

          if (group.usesRecord()) {
            Record subRecord = group.usesRecordId();
            f = (Field) subRecord.getFieldTopLevel(bits[0]);

            if (f == null) {
              f = (Field) subRecord.getFieldFullList(bits[0]);
            }

            if (f != null) {
              break;
            }
          }
        }
      }
      JSONArray result = new JSONArray();
      for (Instance ins : f.getAllAutocompleteInstances()) {
        JSONArray getallnames = ctl.get(storage, ins.getTitleRef(), vb);
        for (int i = 0; i < getallnames.length(); i++) {
          result.put(getallnames.get(i));
        }
      }
      JSONObject out = generateENUMField(storage, f, result, false);
      request.sendJSONResponse(out);
      int cacheMaxAgeSeconds = spec.getAdminData().getTermListCacheAge();
      if (cacheMaxAgeSeconds > 0) {
        request.setCacheMaxAgeSeconds(cacheMaxAgeSeconds);
      }
    } catch (JSONException e) {
      throw new UIException("JSONException during autocompletion", e);
    }
  }
示例#2
0
  protected JSONObject generateENUMField(
      Storage storage, Field f, JSONArray getallnames, Boolean showshortID) throws JSONException {
    JSONArray ids = new JSONArray();
    JSONArray names = new JSONArray();
    JSONArray activestatus = new JSONArray();
    int dfault = -1;
    int spacer = 0;
    if (f.hasEnumBlank()) {
      ids.put("");
      activestatus.put("");
      names.put(f.enumBlankValue());
      spacer = 1;
    }
    for (int i = 0; i < getallnames.length(); i++) {
      JSONObject namedata = getallnames.getJSONObject(i);
      String name = namedata.getString("displayName");
      String status = namedata.getString("termStatus");
      activestatus.put(status);
      String shortId = "";
      String refname = namedata.getString("refid");
      if (namedata.has("shortIdentifier") && !namedata.getString("shortIdentifier").equals("")) {
        shortId = namedata.getString("shortIdentifier");
      } else {
        shortId = name.replaceAll("\\W", "");
      }
      // currently only supports single select dropdowns and not multiselect
      if (f.isEnumDefault(name)) {
        dfault = i + spacer;
      }
      if (showshortID) {
        ids.put(shortId.toLowerCase());
      } else {
        ids.put(refname);
      }

      names.put(name);
    }
    // Dropdown entry pulled from service layer data
    JSONObject out = new JSONObject();

    if (dfault != -1) out.put("default", dfault + "");
    out.put("optionlist", ids);
    out.put("optionnames", names);
    out.put("activestatus", activestatus);
    return out;
  }