use of org.collectionspace.chain.csp.schema.Record 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.Record 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.Record in project application by collectionspace.
the class UISpec method generateUISpecHierarchySection.
/**
* Create hierarchy section for the uispec
* @param affix
* @param addMessages
* @return
* @throws JSONException
*/
protected JSONObject generateUISpecHierarchySection(UISpecRunContext affix, Boolean addMessages) throws JSONException {
JSONObject out = new JSONObject();
Record subf = this.spec.getRecord("hierarchy");
String extra = "";
if (this.record.getRecord().isType("authority"))
extra = "vocabularies/";
affix.setUIRecordUrl(extra + record.getWebURL());
makeASubRecord(subf, out, false, affix, out);
if (addMessages) {
makeAllRecordMessageKey(affix, out, subf);
}
return out;
}
use of org.collectionspace.chain.csp.schema.Record in project application by collectionspace.
the class TestService method testXMLJSON.
/**
* This doesn't currently test multipart xml conversion
*
* @param spec
* @param objtype
* @param xmlfile
* @param jsonfile
* @throws Exception
*/
private void testXMLJSON(Spec spec, String objtype, String xmlfile, String jsonfile) throws Exception {
log.info("Converting XML to JSON for record type " + objtype);
Document testxml = getDocument(xmlfile);
String test = testxml.asXML();
log.trace("Original XML:\n" + test);
JSONObject j = getJSON(jsonfile);
// log.info("Original JSON:\n" + j.toString());
Record r = spec.getRecord(objtype);
JSONObject repeatjson = org.collectionspace.chain.csp.persistence.services.XmlJsonConversion.convertToJson(r, testxml, "", "common", "", // this is where we specify the multipart section
"");
// we are considering
boolean result = JSONUtils.checkJSONEquivOrEmptyStringKey(repeatjson, j);
if (!result) {
log.info("Original JSON:\n" + j.toString());
log.info("After XML->JSON conversion:\n" + repeatjson.toString());
}
assertTrue("Generated JSON for record type: " + objtype + " doesn't match original JSON", result);
}
use of org.collectionspace.chain.csp.schema.Record in project application by collectionspace.
the class RecordRead method getPermissions.
private JSONArray getPermissions(Storage storage, JSONObject activePermissionInfo) throws ExistException, UnimplementedException, UnderlyingStorageException, JSONException, UIException {
final String WORKFLOW_DELETE_RESOURCE_TAIL = WORKFLOW_SUB_RESOURCE + "delete";
final String WORKFLOW_LOCK_RESOURCE_TAIL = WORKFLOW_SUB_RESOURCE + "lock";
JSONArray set = new JSONArray();
JSONObject activePermissions = new JSONObject();
// mark active roles
if (activePermissionInfo.has("permission")) {
JSONArray active = activePermissionInfo.getJSONArray("permission");
for (int j = 0; j < active.length(); j++) {
if (active.getJSONObject(j).length() != 0) {
activePermissions.put(active.getJSONObject(j).getString("resourceName"), active.getJSONObject(j));
}
}
}
JSONObject mergedPermissions = new JSONObject();
// get all permissions
int pageNum = 0;
JSONObject permrestrictions = new JSONObject();
permrestrictions.put("queryTerm", "actGrp");
permrestrictions.put("queryString", "CRUDL");
// Passing page size 0 gets all the perms in one call.
permrestrictions.put("pageSize", Integer.toString(pageNum));
String permbase = spec.getRecordByWebUrl("permission").getID();
JSONObject returndata = searcher.getJSON(storage, permrestrictions, "items", permbase);
// Using pageSize=0, we get all perms in one call, so no need to loop
if (returndata.has("items") && returndata.getJSONArray("items").length() > 0) {
// merge active and nonactive
JSONArray items = returndata.getJSONArray("items");
for (int i = 0; i < items.length(); i++) {
JSONObject item = items.getJSONObject(i);
JSONObject permission = new JSONObject();
String resourceName = item.getString("summary");
String resourceNameUI;
// Need to get baseResource for workflow perms
int startWorkflowSubResource = resourceName.indexOf(WORKFLOW_SUB_RESOURCE);
if (startWorkflowSubResource > 0) {
// Contains the workflow subresource
// Get the base resource that the workflow is related to
int start = (resourceName.startsWith("/")) ? 1 : 0;
String baseResource = resourceName.substring(start, startWorkflowSubResource);
resourceNameUI = Generic.ResourceNameUI(spec, baseResource);
} else {
resourceNameUI = Generic.ResourceNameUI(spec, resourceName);
}
permission.put("resourceName", resourceNameUI);
String permlevel = "none";
Record recordForPermResource = Generic.RecordNameServices(spec, resourceNameUI);
if ((startWorkflowSubResource > 0) && (recordForPermResource != null)) {
// Handle the lock workflow resource
if (recordForPermResource.supportsLocking() && resourceName.endsWith("lock") && activePermissions.has(resourceName) && Generic.PermissionIncludesWritable(activePermissions.getJSONObject(resourceName).getString("actionGroup"))) {
// Should be, but UI not ready: permission.put("permission", Generic.LOCK_PERMISSION);
if (!mergedPermissions.has(resourceNameUI)) {
// With no other knowledge, assume lock perm means writable
permission.put("permission", Generic.WRITE_PERMISSION);
mergedPermissions.put(resourceNameUI, permission);
} else {
// We could check it and make sure it makes sense, but we have to trust that the UI has
// done something reasonable by not combining lock perm with read-only or other silliness.
}
} else // Handle the delete workflow resource
if (recordForPermResource.hasSoftDeleteMethod() && resourceName.endsWith("delete") && activePermissions.has(resourceName) && Generic.PermissionIncludesWritable(activePermissions.getJSONObject(resourceName).getString("actionGroup"))) {
// If we have write or delete perms on the workflow resource, set the permLevel
// on the base resource.
permission.put("permission", Generic.DELETE_PERMISSION);
mergedPermissions.put(resourceNameUI, permission);
} else {
// Filter these out - no need to model them, as we do not support them
// This is a performance improvement so we do not have to handle them on
// update.
}
} else if (activePermissions.has(resourceName) && !mergedPermissions.has(resourceNameUI)) {
permlevel = Generic.PermissionLevelString(activePermissions.getJSONObject(resourceName).getString("actionGroup"));
permission.put("permission", permlevel);
mergedPermissions.put(resourceNameUI, permission);
} else if (!mergedPermissions.has(resourceNameUI)) {
permlevel = "none";
permission.put("permission", permlevel);
mergedPermissions.put(resourceNameUI, permission);
}
}
// pageNum++;
// permrestrictions.put("pageNum", Integer.toString(pageNum));
// returndata = searcher.getJSON(storage,permrestrictions,"items",permbase);
}
// change soft workflow to main Delete
// now put the permissions in order...
String[] recordsweburl = spec.getAllRecordsOrdered();
for (String weburl : recordsweburl) {
if (mergedPermissions.has(weburl)) {
Object value = mergedPermissions.get(weburl);
set.put(value);
}
}
Iterator rit = mergedPermissions.keys();
while (rit.hasNext()) {
String key = (String) rit.next();
Object value = mergedPermissions.get(key);
if (!spec.hasRecordByWebUrl(key)) {
set.put(value);
}
}
return set;
}
Aggregations