use of org.collectionspace.chain.csp.schema.Structure in project application by collectionspace.
the class VocabRedirector method pathForAll.
/**
* Returns information on the vocabularies (Authority namespaces) that are configured
* for autocomplete use for the passed field, in the context record.
* If the record is itself an Authority term editor, hierarchy fields should
* be constrained to the vocabulary named by vocabConstraint
* @param fieldname The name of the field for which to return the info
* @param vocabConstraint The vocabulary when the field is hierarchic and the record is a term.
* @return Information on the configured vocabularies
* @throws JSONException
*/
private JSONArray pathForAll(String fieldname, String vocabConstraint) throws JSONException {
JSONArray out = new JSONArray();
FieldSet fd = r.getFieldFullList(fieldname);
Instance[] allInstances = null;
if (fd == null || !(fd instanceof Field)) {
if (r.hasHierarchyUsed("screen")) {
// Configures the hierarchy section.
Structure s = r.getStructure("screen");
if (s.hasOption(fieldname)) {
// This is one of the hierarchy fields
if (vocabConstraint != null) {
allInstances = new Instance[1];
String fullname = r.getID() + "-" + vocabConstraint;
allInstances[0] = r.getSpec().getInstance(fullname);
} else {
Option a = s.getOption(fieldname);
String[] data = a.getName().split(",");
allInstances = new Instance[data.length];
for (int i = 0; i < data.length; i++) {
allInstances[i] = (r.getSpec().getInstance(data[i]));
}
}
} else {
FieldSet fs = r.getSpec().getRecord("hierarchy").getFieldFullList(fieldname);
if (fs instanceof Field) {
allInstances = ((Field) fs).getAllAutocompleteInstances();
}
}
}
} else {
allInstances = ((Field) fd).getAllAutocompleteInstances();
}
for (Instance autoc : allInstances) {
if (autoc != null) {
JSONObject instance = new JSONObject();
instance.put("url", "/vocabularies/" + autoc.getWebURL());
instance.put("type", autoc.getID());
instance.put("fullName", autoc.getTitle());
out.put(instance);
} else {
log.debug(String.format("A vocab/authority instance for autocompleting the '%s' field was null or missing.", fieldname));
}
}
return out;
}
Aggregations