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);
}
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());
}
}
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;
}
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);
}
}
}
Aggregations