Search in sources :

Example 6 with Structure

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;
}
Also used : Field(org.collectionspace.chain.csp.schema.Field) FieldSet(org.collectionspace.chain.csp.schema.FieldSet) JSONObject(org.json.JSONObject) Instance(org.collectionspace.chain.csp.schema.Instance) JSONArray(org.json.JSONArray) Option(org.collectionspace.chain.csp.schema.Option) Structure(org.collectionspace.chain.csp.schema.Structure)

Aggregations

Structure (org.collectionspace.chain.csp.schema.Structure)6 JSONObject (org.json.JSONObject)4 FieldSet (org.collectionspace.chain.csp.schema.FieldSet)3 UIException (org.collectionspace.csp.api.ui.UIException)3 JSONArray (org.json.JSONArray)3 JSONException (org.json.JSONException)3 ConfigException (org.collectionspace.chain.csp.config.ConfigException)2 Field (org.collectionspace.chain.csp.schema.Field)2 Instance (org.collectionspace.chain.csp.schema.Instance)2 Option (org.collectionspace.chain.csp.schema.Option)2 UnderlyingStorageException (org.collectionspace.csp.api.persistence.UnderlyingStorageException)2 BigDecimal (java.math.BigDecimal)1 UISpecRunContext (org.collectionspace.chain.csp.schema.UISpecRunContext)1 ExistException (org.collectionspace.csp.api.persistence.ExistException)1 UnimplementedException (org.collectionspace.csp.api.persistence.UnimplementedException)1