use of org.collectionspace.chain.csp.schema.Group in project application by collectionspace.
the class SchemaStructure method actualSelfRenderer.
/**
* render the mark up needed by the UISpec for self renderers
*
* @param fs
* @param context
* @param subexpander
* @param subitems
* @param options
* @throws JSONException
*/
protected void actualSelfRenderer(FieldSet fs, UISpecRunContext context, JSONObject subexpander, Record subitems) throws JSONException {
Boolean truerepeat = false;
FieldParent fsp = fs.getParent();
if (fsp instanceof Repeat && !(fsp instanceof Group)) {
// remove bogus repeats used in search
Repeat rp = (Repeat) fsp;
if (isATrueRepeat(rp)) {
truerepeat = true;
for (FieldSet fs2 : subitems.getAllFieldTopLevel("")) {
whatIsThisFieldSet(subexpander, fs2, context);
}
makeAllRecordMessageKey(context, subexpander, subitems);
}
}
if (!truerepeat) {
for (FieldSet fs2 : subitems.getAllFieldTopLevel("")) {
whatIsThisFieldSet(subexpander, fs2, context);
}
makeAllRecordMessageKey(context, subexpander, subitems);
}
}
use of org.collectionspace.chain.csp.schema.Group in project application by collectionspace.
the class SchemaStructure method makeAGroupEntry.
/**
* Do all the magic to make a Group thing
*
* @param out
* @param fs
* @param contexts
* @throws JSONException
*/
protected void makeAGroupEntry(JSONObject out, FieldSet fs, UISpecRunContext context) throws JSONException {
Group g = (Group) fs;
JSONObject contents = new JSONObject();
for (FieldSet child : g.getChildren("")) {
whatIsThisFieldSet(contents, child, context);
}
// make the item
if (fs.isASelfRenderer()) {
JSONObject renderedcontents = new JSONObject();
actualSelfRenderer(renderedcontents, contents);
contents = renderedcontents;
} else if (isAGroupField(fs)) {
contents = makeAGroupField(g, context);
}
actualGroupEntry(fs, out, context, contents);
}
use of org.collectionspace.chain.csp.schema.Group in project application by collectionspace.
the class UISpec method actualUploaderEntry.
/**
* Overwrite with the output you need for the thing you are doing.
* @param out
* @param fs
* @param context
* @throws JSONException
*/
@Override
protected void actualUploaderEntry(JSONObject out, FieldSet fs, UISpecRunContext context) throws JSONException {
String condition = "cspace.mediaUploader.assertBlob";
JSONObject cond = new JSONObject();
if (fs instanceof Group) {
Group gp = (Group) fs;
String test = gp.usesRecordValidator();
FieldSet tester = record.getFieldTopLevel(test);
if (tester instanceof Field) {
cond.put("args", displayAsplain((Field) tester, context));
}
cond.put("funcName", condition);
}
JSONObject ttree = new JSONObject();
ttree.put(getSelector(fs, context), new JSONObject());
JSONObject decorator = getDecorator("addClass", "hidden", null, null, fs.isReadOnly());
JSONObject decorators = new JSONObject();
decorators.put(DECORATORS_KEY, decorator);
JSONObject ftree = new JSONObject();
ftree.put(getSelector(fs, context), decorators);
JSONObject cexpander = new JSONObject();
cexpander.put("type", "fluid.renderer.condition");
cexpander.put("condition", cond);
cexpander.put("trueTree", ttree);
cexpander.put("falseTree", ftree);
actualTrueTreeSub(out, cexpander);
}
use of org.collectionspace.chain.csp.schema.Group in project application by collectionspace.
the class MakeXsd method generateDataEntry.
private void generateDataEntry(Element ele, FieldSet fs, Namespace ns, Element root, Boolean unbounded) throws Exception {
//
if (fs.isInServices() == false) {
sendToDebugLog(String.format("Field set is not part of the Services schema %s:%s", fs.getSection(), fs.getID()));
return;
}
String sectionName = fs.getSection();
String listName = fs.getServicesTag();
// to the "GroupField's" structured types -e.g., structuredData and dimension types
if (fs.isAGroupField() == true) {
String groupFieldType = generateFieldGroup(fs, ele, ns, root);
fs.setServicesType(groupFieldType);
}
if (fs.isAGroupField() && fs.isAStructureDate() == false) {
//
return;
}
if (fs instanceof Field || fs instanceof Group) {
String servicesTag = fs.getServicesTag();
if (isOrphaned(fs) == true) {
// If we have a Repeat with a single child that is a "Group" with a "ui-type=groupfield/foo" attribute.
servicesTag = fs.getParentID();
unbounded = true;
}
// <xs:element name="csid" type="xs:string"/>
Element field = ele.addElement(new QName("element", ns));
if (fs.isAGroupField() && fs.isAStructureDate() == false) {
servicesTag = fs.getServicesType();
}
field.addAttribute("name", servicesTag);
String servicesType = fs.getServicesType();
String fieldType = "xs:string";
if (servicesType != null) {
fieldType = servicesType;
}
field.addAttribute("type", fieldType);
if (unbounded == true) {
field.addAttribute("minOccurs", "0");
field.addAttribute("maxOccurs", "unbounded");
}
}
if (isRepeatType(fs) == true) {
// Has to be a Repeat class instance and not any descendant (e.g. not a Group instance)
Element fieldElement = root;
Repeat rfs = (Repeat) fs;
if (rfs.hasServicesParent()) {
// group repeatable
// <xs:element name="objectNameList" type="ns:objectNameList"/>
Element newField = ele.addElement(new QName("element", ns));
newField.addAttribute("name", rfs.getServicesParent()[0]);
String fieldType = rfs.getServicesParent()[0];
newField.addAttribute("type", FieldSet.NS + fieldType);
} else {
// single repeatable
// <xs:element name="responsibleDepartments"
// type="responsibleDepartmentList"/>
fieldElement = ele.addElement(new QName("element", ns));
fieldElement.addAttribute("name", rfs.getServicesTag());
FieldSet[] fieldSetArray = rfs.getChildren("");
if (fieldSetArray != null && fieldSetArray.length > 0) {
if (rfs.isServicesAnonymousType() == true) {
// Ends up creating an embedded anonymous complex type
listName = null;
} else {
listName = rfs.getChildren("")[0].getServicesTag() + "List";
fieldElement.addAttribute("type", FieldSet.NS + listName);
fieldElement = fieldElement.getParent();
}
} else {
// If there is no children to define the type, there better be an explicit services type declaration
String servicesType = rfs.getServicesType();
if (servicesType != null) {
fieldElement.addAttribute("type", servicesType);
} else {
sendToErrorLog("Repeat/Group fieldset child array was null or the first element was null. Field attribute name: " + fieldElement.toString());
}
}
}
generateRepeat(rfs, fieldElement, listName, ns, root);
}
}
use of org.collectionspace.chain.csp.schema.Group in project application by collectionspace.
the class ConfiguredVocabStorage method get.
private JSONObject get(ContextualisedStorage storage, CSPRequestCredentials creds, CSPRequestCache cache, String url, String ims_url) throws ConnectionException, ExistException, UnderlyingStorageException, JSONException {
// int status=0;
String csid = "";
JSONObject out = new JSONObject();
// XXX pagination support
String softurl = url;
if (r.hasSoftDeleteMethod()) {
softurl = softpath(url);
}
if (r.hasHierarchyUsed("screen")) {
softurl = hierarchicalpath(softurl);
}
ReturnedMultipartDocument doc = conn.getMultipartXMLDocument(RequestMethod.GET, softurl, null, creds, cache);
if (doc.getStatus() == 404)
throw new ExistException("Does not exist " + softurl);
if (doc.getStatus() == 403) {
// permission error - keep calm and carry on with what we can glean
out.put("displayName", getDisplayNameKey());
out.put("csid", csid);
out.put("recordtype", r.getWebURL());
return out;
}
if (doc.getStatus() > 299)
throw new UnderlyingStorageException("Could not retrieve vocabulary status=" + doc.getStatus(), doc.getStatus(), softurl);
String name = null;
String refid = null;
String termStatus = null;
String parentcsid = null;
String shortIdentifier = "";
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 result = doc.getDocument(record_path[0].trim());
if (result != null) {
if ("common".equals(section)) {
// XXX hardwired :(
String dnXPath = getDisplayNameXPath();
name = result.selectSingleNode(tag_path[1] + "/" + dnXPath).getText();
if (result.selectSingleNode(tag_path[1] + "/shortIdentifier") != null) {
shortIdentifier = result.selectSingleNode(tag_path[1] + "/shortIdentifier").getText();
}
refid = result.selectSingleNode(tag_path[1] + "/refName").getText();
// We need to replace this with the same model as for displayName
if (result.selectSingleNode(tag_path[1] + "/termStatus") != null) {
termStatus = result.selectSingleNode(tag_path[1] + "/termStatus").getText();
} else {
termStatus = "";
}
csid = result.selectSingleNode(tag_path[1] + "/csid").getText();
parentcsid = result.selectSingleNode(tag_path[1] + "/inAuthority").getText();
XmlJsonConversion.convertToJson(out, r, result, "GET", section, csid, ims_url);
} else {
XmlJsonConversion.convertToJson(out, r, result, "GET", section, csid, ims_url);
}
} else {
log.warn(String.format("XML Payload for '%s' was missing part '%s'.", url, record_path[0]));
}
}
// If this record has hierarchy, will pull out the relations section and map it to the hierarchy
// fields (special case handling of XML-JSON
handleHierarchyPayloadRetrieve(r, doc, out, csid);
// get related sub records?
for (FieldSet fs : r.getAllSubRecords("GET")) {
Record sr = fs.usesRecordId();
// sr.getID()
if (sr.isType("authority")) {
String getPath = url + "/" + sr.getServicesURL();
JSONArray subout = get(storage, creds, cache, url, getPath, sr);
if (fs instanceof Field) {
JSONObject fielddata = subout.getJSONObject(0);
Iterator<String> rit = fielddata.keys();
while (rit.hasNext()) {
String key = rit.next();
out.put(key, fielddata.get(key));
}
} else if (fs instanceof Group) {
if (subout.length() > 0) {
out.put(fs.getID(), subout.getJSONObject(0));
}
} else {
out.put(fs.getID(), subout);
}
}
}
// csid = urn_processor.deconstructURN(refid,false)[4];
out.put(getDisplayNameKey(), name);
out.put("csid", csid);
out.put("refid", refid);
RefName.AuthorityItem item = RefName.AuthorityItem.parse(refid);
out.put("namespace", item.getParentShortIdentifier());
out.put("shortIdentifier", shortIdentifier);
out.put("termStatus", termStatus);
out.put("authorityid", parentcsid);
out.put("recordtype", r.getWebURL());
return out;
}
Aggregations