Search in sources :

Example 6 with Option

use of org.collectionspace.chain.csp.schema.Option in project application by collectionspace.

the class AuthoritiesVocabulariesInitialize method doreset.

public void doreset(Storage storage, Instance ins, JSONArray terms) throws JSONException, UIException, ExistException, UnimplementedException, UnderlyingStorageException {
    Option[] allOpts = ins.getAllOptions();
    // remove all opts from instance
    if (allOpts != null && allOpts.length > 0) {
        for (Option opt : allOpts) {
            String name = opt.getName();
            String shortIdentifier = opt.getID();
            String sample = opt.getSample();
            Boolean dfault = opt.isDefault();
            ins.deleteOption(shortIdentifier, name, sample, dfault);
        }
    }
    for (int i = 0; i < terms.length(); i++) {
        JSONObject element = terms.getJSONObject(i);
        if (element.has("description"))
            ins.addOption(element.getString("shortIdentifier"), element.getString("displayName"), null, false, element.getString("description"));
        else
            ins.addOption(element.getString("shortIdentifier"), element.getString("displayName"), null, false);
    }
    allOpts = ins.getAllOptions();
    fillVocab(storage, ins.getRecord(), ins, null, allOpts, false);
}
Also used : JSONObject(org.json.JSONObject) Option(org.collectionspace.chain.csp.schema.Option)

Example 7 with Option

use of org.collectionspace.chain.csp.schema.Option in project application by collectionspace.

the class AuthoritiesVocabulariesInitialize method resetvocabdata.

private void resetvocabdata(Storage storage, UIRequest request, Instance instance) throws UIException, ExistException, UnimplementedException, UnderlyingStorageException, JSONException {
    StringBuffer tty = new StringBuffer();
    tty.append("Initializing Vocab " + instance.getID() + '\n');
    // Where do we get the list from?
    // from Spec
    Option[] allOpts = instance.getAllOptions();
    // but first check: do we have a path?
    Set<String> args = request.getAllRequestArgument();
    if (args.contains("datapath")) {
        tty.append("Using Datapath \n");
        // remove all opts from instance as we have a path
        if (allOpts != null && allOpts.length > 0) {
            tty.append("Removing all opts from instance as we have a path\n");
            for (Option opt : allOpts) {
                String name = opt.getName();
                String shortIdentifier = opt.getID();
                String sample = opt.getSample();
                Boolean dfault = opt.isDefault();
                instance.deleteOption(shortIdentifier, name, sample, dfault);
            }
        }
        // add from path
        String value = request.getRequestArgument("datapath");
        // log.info("getting data from path: "+value);
        try {
            tty.append("Getting data from path: " + value + '\n');
            String names = getResource(value);
            for (String line : names.split("\n")) {
                line = line.trim();
                String[] bits = line.split("\\|");
                if (bits.length > 1) {
                    instance.addOption(bits[0], bits[1], null, false);
                } else {
                    instance.addOption(null, line, null, false);
                }
            }
        } catch (IOException e) {
            throw new UIException("IOException", e);
        }
        allOpts = instance.getAllOptions();
    }
    fillVocab(storage, r, instance, tty, allOpts, this.append);
    if (this.modifyResponse == true) {
        TTYOutputter ttyOut = request.getTTYOutputter();
        ttyOut.line(tty.toString());
    }
}
Also used : UIException(org.collectionspace.csp.api.ui.UIException) Option(org.collectionspace.chain.csp.schema.Option) TTYOutputter(org.collectionspace.csp.api.ui.TTYOutputter) IOException(java.io.IOException)

Example 8 with Option

use of org.collectionspace.chain.csp.schema.Option 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)

Example 9 with Option

use of org.collectionspace.chain.csp.schema.Option in project application by collectionspace.

the class ServiceBindingsGeneration method doAuthorityInstance.

private void doAuthorityInstance(Instance instance, Record r, Element el, Namespace nsservices2) {
    Element webUrl = el.addElement(new QName("web-url", nsservices2));
    webUrl.addText(instance.getWebURL());
    Element titleRef = el.addElement(new QName("title-ref", nsservices2));
    titleRef.addText(instance.getTitleRef());
    Element title = el.addElement(new QName("title", nsservices2));
    title.addText(instance.getTitle());
    Option[] allOptions = instance.getAllOptions();
    if (allOptions.length > 0) {
        Element termList = el.addElement(new QName("termList", nsservices2));
        for (Option option : allOptions) {
            doTerm(option, r, termList, nsservices2);
        }
    }
}
Also used : QName(org.dom4j.QName) Element(org.dom4j.Element) Option(org.collectionspace.chain.csp.schema.Option)

Aggregations

Option (org.collectionspace.chain.csp.schema.Option)9 JSONObject (org.json.JSONObject)7 Field (org.collectionspace.chain.csp.schema.Field)4 JSONArray (org.json.JSONArray)4 Instance (org.collectionspace.chain.csp.schema.Instance)3 UnderlyingStorageException (org.collectionspace.csp.api.persistence.UnderlyingStorageException)3 IOException (java.io.IOException)2 ConfigException (org.collectionspace.chain.csp.config.ConfigException)2 FieldSet (org.collectionspace.chain.csp.schema.FieldSet)2 Structure (org.collectionspace.chain.csp.schema.Structure)2 TTYOutputter (org.collectionspace.csp.api.ui.TTYOutputter)2 UIException (org.collectionspace.csp.api.ui.UIException)2 ConnectionException (org.collectionspace.chain.csp.persistence.services.connection.ConnectionException)1 Record (org.collectionspace.chain.csp.schema.Record)1 AuthoritiesVocabulariesInitialize (org.collectionspace.chain.csp.webui.authorities.AuthoritiesVocabulariesInitialize)1 ExistException (org.collectionspace.csp.api.persistence.ExistException)1 UnimplementedException (org.collectionspace.csp.api.persistence.UnimplementedException)1 Element (org.dom4j.Element)1 QName (org.dom4j.QName)1 JSONException (org.json.JSONException)1