use of org.collectionspace.chain.csp.schema.Group in project application by collectionspace.
the class GenericStorage method refObjViewRetrieveJSON.
/**
* get data needed for list of objects related to a termUsed
* @param storage
* @param creds
* @param cache
* @param path
* @return
* @throws ExistException
* @throws UnderlyingStorageException
* @throws JSONException
* @throws UnimplementedException
*/
public JSONObject refObjViewRetrieveJSON(ContextualisedStorage storage, CSPRequestCredentials creds, CSPRequestCache cache, String path, JSONObject restrictions, Record vr) throws ExistException, UnderlyingStorageException, JSONException, UnimplementedException {
JSONObject out = new JSONObject();
try {
// map of servicenames of fields to descriptors
Map<String, String> refObj_view_good = new HashMap<String, String>();
// map of csid to service name of field
Map<String, String> refObj_view_map = new HashMap<String, String>();
if (vr.hasRefObjUsed()) {
path = getRestrictedPath(path, restrictions, "kw", "", false, "");
// XXX need a way to append the data needed from the field,
// which we don't know until after we have got the information...
refObj_view_map.put("docType", "docType");
refObj_view_map.put("docId", "docId");
refObj_view_map.put("docName", "docName");
refObj_view_map.put("docNumber", "docNumber");
refObj_view_map.put("sourceField", "sourceField");
refObj_view_map.put("uri", "uri");
refObj_view_map.put("refName", "refName");
refObj_view_good.put("terms_docType", "docType");
refObj_view_good.put("terms_docId", "docId");
refObj_view_good.put("terms_docName", "docName");
refObj_view_good.put("terms_docNumber", "docNumber");
refObj_view_good.put("terms_sourceField", "sourceField");
refObj_view_good.put("terms_refName", "refName");
// XXX this might be the wrong record to pass to checkf or hard/soft delet listing
JSONObject data = getRepeatableListView(storage, creds, cache, path, "authority-ref-doc-list/authority-ref-doc-item", "uri", true, vr, refObj_view_map);
JSONArray recs = data.getJSONArray("listItems");
if (data.has("pagination")) {
out.put("pagination", data.getJSONObject("pagination"));
}
JSONArray items = new JSONArray();
// String[] filepaths = (String[]) data.get("listItems");
for (int i = 0; i < recs.length(); ++i) {
String uri = recs.getJSONObject(i).getString("csid");
// recs.getJSONObject(i).getString("csid");
String filePath = uri;
if (filePath != null && filePath.startsWith("/"))
filePath = filePath.substring(1);
String[] parts = filePath.split("/");
String recordurl = parts[0];
Record thisr = vr.getSpec().getRecordByServicesUrl(recordurl);
// Set up the glean maps required for this record. We need to reset these each time
// through the loop, because every record could be a different type.
Map<String, String> thisr_view_good = new HashMap<String, String>(refObj_view_good);
Map<String, String> thisr_view_map = new HashMap<String, String>(refObj_view_map);
Set<String> thisr_xxx_view_deurn = new HashSet<String>();
Set<String> thisr_view_search_optional = new HashSet<String>();
Map<String, List<String>> thisr_view_merge = new HashMap<String, List<String>>();
Map<String, List<String>> thisr_view_useCsid = new HashMap<String, List<String>>();
initializeGlean(thisr, thisr_view_good, thisr_view_map, thisr_xxx_view_deurn, thisr_view_search_optional, thisr_view_merge, thisr_view_useCsid);
String csid = parts[parts.length - 1];
JSONObject dataitem = miniViewRetrieveJSON(cache, creds, csid, "terms", uri, thisr, thisr_view_good, thisr_xxx_view_deurn, thisr_view_search_optional, thisr_view_merge, thisr_view_useCsid);
dataitem.getJSONObject("summarylist").put("uri", filePath);
String key = recs.getJSONObject(i).getString("sourceField");
dataitem.getJSONObject("summarylist").put("sourceField", key);
String fieldName = "unknown";
String fieldSelector = "unknown";
if (key.contains(":")) {
fieldName = key.split(":")[1];
// FIXME: We might remove the following if CSPACE-2909's fix makes this moot - ADR 2012-07-19
while (thisr.getFieldFullList(fieldName) instanceof Repeat || thisr.getFieldFullList(fieldName) instanceof Group) {
fieldName = ((Repeat) thisr.getFieldFullList(fieldName)).getChildren("GET")[0].getID();
}
Field fieldinstance = (Field) thisr.getFieldFullList(fieldName);
fieldSelector = fieldinstance.getSelector();
}
dataitem.put("csid", csid);
dataitem.put("sourceFieldselector", fieldSelector);
dataitem.put("sourceFieldName", fieldName);
dataitem.put("sourceFieldType", dataitem.getJSONObject("summarylist").getString("docType"));
dataitem.put("sourceFieldType", dataitem.getJSONObject("summarylist").getString("docType"));
// items.put(csid+":"+key,dataitem);
items.put(dataitem);
}
out.put("items", items);
}
return out;
} catch (ConnectionException e) {
log.error("failed to retrieve refObjs for " + path);
JSONObject dataitem = new JSONObject();
dataitem.put("csid", "");
dataitem.put("sourceFieldselector", "Functionality Failed");
dataitem.put("sourceFieldName", "Functionality Failed");
dataitem.put("sourceFieldType", "Functionality Failed");
dataitem.put("message", e.getMessage());
out.put("Functionality Failed", dataitem);
// return out;
throw new UnderlyingStorageException("Connection problem" + e.getLocalizedMessage(), e.getStatus(), e.getUrl(), e);
} catch (UnsupportedEncodingException uae) {
log.error("failed to retrieve refObjs for " + path);
JSONObject dataitem = new JSONObject();
dataitem.put("message", uae.getMessage());
out.put("Functionality Failed", dataitem);
throw new UnderlyingStorageException("Problem building query" + uae.getLocalizedMessage(), uae);
}
}
use of org.collectionspace.chain.csp.schema.Group in project application by collectionspace.
the class SchemaStructure method makeASubRecordEntry.
/**
* Do all the magic to make a sub record thing first is it nested directly
* in the data or one level under
*
* @param out
* @param fs
* @param context
* @throws JSONException
*/
protected void makeASubRecordEntry(JSONObject out, FieldSet fs, UISpecRunContext context, JSONObject outerlayer) throws JSONException {
// create group item or field at the same level as parent fields - do not nest
UISpecRunContext sub = context;
if (!fs.getUISpecInherit()) {
// default behaviour do group or field as expected by changing the context (adds more info to the selectors etc)
sub = context.createChild();
if (!fs.getSelectorAffix().equals("")) {
sub.setUIAffix(fs.getSelectorAffix());
}
String sp = fs.getUISpecPrefix();
if (sp != null)
sub.setUIPrefix(sp);
}
Record subrecord = fs.usesRecordId();
Boolean repeated = false;
if (fs.getParent() instanceof Repeat || (fs instanceof Repeat && !(fs instanceof Group))) {
repeated = true;
}
if (outerlayer == null) {
outerlayer = out;
}
if (fs instanceof Group) {
Group gp = (Group) fs;
if (gp.isGrouped()) {
sub.setPad(false);
}
}
actualSubRecordField(out, fs, sub, subrecord, repeated, outerlayer);
}
use of org.collectionspace.chain.csp.schema.Group in project application by collectionspace.
the class UISchema method actualSubRecordField.
@Override
protected void actualSubRecordField(JSONObject out, FieldSet fs, UISpecRunContext context, Record subr, Boolean repeated, JSONObject parent) throws JSONException {
if (fs instanceof Group) {
Group gp = (Group) fs;
if (!gp.isGrouped()) {
makeASubRecord(subr, out, repeated, context, parent);
return;
}
}
JSONObject insidebit = new JSONObject();
makeASubRecord(subr, insidebit, repeated, context, parent);
JSONObject chooser = new JSONObject();
actualSchemaObject("object", null, insidebit, null, chooser);
out.put(getSelector(fs, context), chooser);
}
use of org.collectionspace.chain.csp.schema.Group in project application by collectionspace.
the class UISpec method actualRepeatNonSiblingEntry.
/**
* Overwrite with the output you need for the thing you are doing.
* @param out
* @param r
* @param context
* @param preProtoTree
* @throws JSONException
*/
@Override
protected void actualRepeatNonSiblingEntry(JSONObject out, Repeat r, UISpecRunContext context, JSONObject preProtoTree) throws JSONException {
JSONArray decorators = new JSONArray();
JSONObject content = new JSONObject();
JSONObject options = new JSONObject();
JSONObject expander = new JSONObject();
expander.put("type", "fluid.noexpand");
expander.put("tree", preProtoTree);
JSONObject repeatTree = new JSONObject();
repeatTree.put("expander", expander);
if (r.getParent() instanceof Record) {
options.put("elPath", displayAsveryplainWithoutEnclosure(r, context));
} else {
options.put("elPath", r.getID());
options.put("root", "{row}");
}
options.put("repeatTree", repeatTree);
// is this a uispec for search - if so no primary tags wanted
if (r.getSearchType().startsWith("repeator") && this.spectype.equals("search")) {
options.put("hidePrimary", true);
}
JSONObject decorator = getDecorator("fluid", null, "cspace.makeRepeatable", options, r.isReadOnly());
decorators.put(decorator);
content.put(DECORATORS_KEY, decorators);
String selector = getSelector(r, context);
// CSPACE-2619 scalar repeatables are different from group repeats
if (r.getChildren("").length == 1) {
FieldSet child = getFirstChild(r);
if (child instanceof Field || child instanceof Group) {
selector = getSelector(child, context);
}
}
if (r.isExpander()) {
JSONArray expanders = out.getJSONArray("expander");
makeExpander(out, expanders);
} else {
out.put(selector, content);
}
}
use of org.collectionspace.chain.csp.schema.Group in project application by collectionspace.
the class UISpec method actualStructuredDate.
/**
* Overwrite with output you need for this thing you are doing
* @param fs
* @param out
* @param sub
* @param subexpander
* @param subitems
* @param options
* @throws JSONException
*/
@Override
protected void actualStructuredDate(FieldSet fs, JSONObject out, UISpecRunContext sub, JSONObject subexpander, Record subitems, JSONObject options) throws JSONException {
out.put("value", displayAsveryplain("fields." + fs.getPrimaryKey()));
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)) {
String prefix = "";
if (fs instanceof Group && !((Group) fs).getXxxServicesNoRepeat()) {
// XXX refacetor with some idea of UIContext.
// add a prefix for nested non repeatables
prefix = fs.getID() + ".";
}
truerepeat = true;
for (FieldSet fs2 : subitems.getAllFieldTopLevel("")) {
subexpander.put(getSelector(fs2, sub), prefix + fs2.getID());
}
if (fs instanceof Group && !((Group) fs).getXxxServicesNoRepeat()) {
options.put("elPath", prefix + fs.getPrimaryKey());
options.put("root", "{row}");
out.put("value", displayAsveryplain("{row}." + prefix + fs.getPrimaryKey()));
} else if (fs instanceof Repeat) {
options.put("elPath", fs.getPrimaryKey());
options.put("root", "{row}");
out.put("value", displayAsveryplain("{row}." + fs.getPrimaryKey()));
}
}
}
if (!truerepeat) {
options.put("elPath", "fields." + fs.getPrimaryKey());
for (FieldSet fs2 : subitems.getAllFieldTopLevel("")) {
if (!fs2.getSearchType().equals("false") || !this.spectype.equals("search")) {
// only hide if this is a search uispec - need to extend to all uispec stuff
subexpander.put(getSelector(fs2, sub), displayAsveryplainWithoutEnclosure(fs2, sub));
}
}
}
options.put("elPaths", subexpander);
}
Aggregations