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); } }
// search a specific instance of an authority public AuthoritiesVocabulariesSearchList(Instance n, boolean search) { this.n = n; this.r = n.getRecord(); this.search = search; }
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()); }