use of org.collectionspace.chain.csp.schema.Field in project application by collectionspace.
the class UISpec method actualExternalURL.
/**
* This is a bit of JSON needed by the UI so they display fields decorated
* with external URL-handling behavior in the UIspec
* @param f
* @param context
* @return
* @throws JSONException
*/
private JSONObject actualExternalURL(FieldSet fs, UISpecRunContext context, JSONArray decorators) throws JSONException {
JSONObject out = new JSONObject();
Field f = (Field) fs;
JSONObject decorator = getDecorator("fluid", null, "cspace.externalURL", null, f.isReadOnly());
if (!f.isRefactored()) {
if (f.hasContainer()) {
decorator.put("container", getSelector(f, context));
}
}
if (decorators == null) {
decorators = new JSONArray();
}
decorators.put(decorator);
out.put(DECORATORS_KEY, decorators);
out.put("value", actualFieldEntry(f, context));
return out;
}
use of org.collectionspace.chain.csp.schema.Field in project application by collectionspace.
the class UISpec method actualWorkflowState.
private JSONObject actualWorkflowState(FieldSet fs, UISpecRunContext context, JSONArray decorators) throws JSONException {
JSONObject out = new JSONObject();
Field f = (Field) fs;
JSONObject decorator = getDecorator("fluid", null, "cspace.util.workflowToStyleFieldConverter", null, f.isReadOnly());
if (!f.isRefactored()) {
if (f.hasContainer()) {
decorator.put("container", getSelector(f, context));
}
}
if (decorators == null) {
decorators = new JSONArray();
}
decorators.put(decorator);
out.put(DECORATORS_KEY, decorators);
out.put("value", actualFieldEntry(f, context));
return out;
}
use of org.collectionspace.chain.csp.schema.Field in project application by collectionspace.
the class XmlJsonConversion method FieldListFROMConfig.
private static List<String> FieldListFROMConfig(FieldSet f, String operation) {
List<String> children = new ArrayList<String>();
if (f.getUIType().startsWith("groupfield")) {
String[] parts = f.getUIType().split("/");
Record subitems = f.getRecord().getSpec().getRecordByServicesUrl(parts[1]);
for (FieldSet fs : subitems.getAllFieldTopLevel(operation)) {
children.add(fs.getID());
}
}
if (f instanceof Repeat) {
for (FieldSet a : ((Repeat) f).getChildren(operation)) {
if (a instanceof Repeat && ((Repeat) a).hasServicesParent()) {
children.add(((Repeat) a).getServicesParent()[0]);
} else if (a.getUIType().startsWith("groupfield")) {
// structuredates etc
String[] parts = a.getUIType().split("/");
Record subitems = a.getRecord().getSpec().getRecordByServicesUrl(parts[1]);
if (a instanceof Group) {
if (((Group) a).getXxxServicesNoRepeat()) {
for (FieldSet fs : subitems.getAllFieldTopLevel(operation)) {
if (fs instanceof Repeat && ((Repeat) fs).hasServicesParent()) {
children.add(((Repeat) fs).getServicesParent()[0]);
} else {
children.add(fs.getID());
}
}
} else {
children.add(a.getID());
}
}
} else {
children.add(a.getID());
}
}
}
if (f instanceof Group) {
for (FieldSet ab : ((Group) f).getChildren(operation)) {
children.add(ab.getID());
}
}
if (f instanceof Field) {
}
return children;
}
use of org.collectionspace.chain.csp.schema.Field in project application by collectionspace.
the class ConfiguredVocabStorage method autocreateJSON.
@Override
public String autocreateJSON(ContextualisedStorage root, CSPRequestCredentials creds, CSPRequestCache cache, String filePath, JSONObject jsonObject, JSONObject restrictions) throws ExistException, UnimplementedException, UnderlyingStorageException {
try {
Map<String, Document> body = new HashMap<String, Document>();
String vocab = null;
String pathurl = "/" + r.getServicesURL() + "/";
if (filePath.equals("")) {
for (String section : r.getServicesInstancesPaths()) {
String path = r.getServicesInstancesPath(section);
String[] record_path = path.split(":", 2);
String[] tag_path = record_path[1].split(",", 2);
Document temp = createEntry(section, tag_path[0], tag_path[1], jsonObject, vocab, null, r, true);
if (temp != null) {
body.put(record_path[0], temp);
// log.info(temp.asXML());
}
}
} else {
vocab = RefName.shortIdToPath(filePath);
pathurl = "/" + r.getServicesURL() + "/" + vocab + ITEMS_SUFFIX;
for (String section : r.getServicesRecordPathKeys()) {
String path = r.getServicesRecordPath(section);
String[] record_path = path.split(":", 2);
String[] tag_path = record_path[1].split(",", 2);
Document temp = createEntry(section, tag_path[0], tag_path[1], jsonObject, vocab, null, r, false);
if (temp != null) {
body.put(record_path[0], temp);
// log.info(temp.asXML());
}
}
}
handleHierarchyPayloadSend(r, body, jsonObject, null);
ReturnedURL out = conn.getMultipartURL(RequestMethod.POST, pathurl, body, creds, cache);
if (out.getStatus() > 299)
throw new UnderlyingStorageException("Could not create vocabulary", out.getStatus(), pathurl);
String csid = out.getURLTail();
// create related sub records?
for (FieldSet fs : r.getAllSubRecords("POST")) {
Record sr = fs.usesRecordId();
// sr.getID()
if (sr.isType("authority")) {
String savePath = out.getURL() + "/" + sr.getServicesURL();
if (fs instanceof Field) {
// get the fields form inline XXX untested - might not work...
JSONObject subdata = new JSONObject();
// loop thr jsonObject and find the fields I need
for (FieldSet subfs : sr.getAllFieldTopLevel("POST")) {
String key = subfs.getID();
if (jsonObject.has(key)) {
subdata.put(key, jsonObject.get(key));
}
}
subautocreateJSON(root, creds, cache, sr, subdata, savePath);
} else if (fs instanceof Group) {
// JSONObject
if (jsonObject.has(fs.getID())) {
Object subdata = jsonObject.get(fs.getID());
if (subdata instanceof JSONObject) {
JSONObject subrecord = (JSONObject) subdata;
subautocreateJSON(root, creds, cache, sr, subrecord, savePath);
} else {
log.warn("autocreateJSON: Contact subrecord is malformed (not a JSONObject)!");
if (log.isDebugEnabled()) {
log.debug("autocreateJSON: Contact subrecord: " + subdata.toString());
}
}
}
} else {
// JSONArray
if (jsonObject.has(fs.getID())) {
Object subdata = jsonObject.get(fs.getID());
if (subdata instanceof JSONArray) {
JSONArray subarray = (JSONArray) subdata;
for (int i = 0; i < subarray.length(); i++) {
JSONObject subrecord = subarray.getJSONObject(i);
subautocreateJSON(root, creds, cache, sr, subrecord, savePath);
}
}
}
}
}
}
return csid;
} catch (ConnectionException e) {
throw new UnderlyingStorageException("Connection exception" + e.getLocalizedMessage(), e.getStatus(), e.getUrl(), e);
} catch (JSONException e) {
throw new UnderlyingStorageException("Cannot parse surrounding JSON" + e.getLocalizedMessage(), e);
}
}
use of org.collectionspace.chain.csp.schema.Field 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