use of org.collectionspace.chain.csp.schema.Record in project application by collectionspace.
the class NullResolver method doMapping.
/**
* Some simple mappings to help with the unfinished functionality to
* allow changing of content on templates based on returned item type
* @param pathinfo
* @param allmappings
* @param spec
* @return
*/
private Map<String, Object> doMapping(String pathinfo, UIMapping[] allmappings, Spec spec) {
Map<String, Object> out = new HashMap<String, Object>();
for (UIMapping map : allmappings) {
out.put("map", map);
out.put("isConfig", false);
out.put("isRecord", false);
out.put("instance", null);
out.put("record", null);
out.put("RecordFile", map.getFile());
out.put("ConfigFile", "");
out.put("File", "");
if (map.hasUrl()) {
if (map.getUrl().equals(pathinfo)) {
return out;
}
} else if (map.hasType()) {
for (Record r : spec.getAllRecords()) {
if (r.isType(map.getType())) {
if (r.isType("authority")) {
for (Instance ins : r.getAllInstances()) {
// config
String tenantInstanceconfig = "/" + spec.getAdminData().getTenantName() + "/config/" + ins.getWebURL() + ".json";
String tenantAuthconfig = "/" + spec.getAdminData().getTenantName() + "/config/" + r.getWebURL() + ".json";
if (pathinfo.equals(tenantInstanceconfig)) {
out.put("instance", ins);
out.put("record", r);
out.put("isConfig", true);
out.put("ConfigFile", tenantAuthconfig);
out.put("File", tenantAuthconfig);
return out;
} else if (pathinfo.equals("/config/" + ins.getWebURL() + ".json")) {
out.put("instance", ins);
out.put("record", r);
out.put("isConfig", true);
out.put("ConfigFile", tenantAuthconfig);
out.put("File", tenantAuthconfig);
return out;
}
// record
if (pathinfo.equals("/" + spec.getAdminData().getTenantName() + "/" + ins.getUIURL())) {
out.put("record", r);
out.put("isRecord", true);
out.put("instance", ins);
out.put("File", map.getFile());
return out;
}
if (pathinfo.equals("/" + spec.getAdminData().getTenantName() + "/html/" + ins.getUIURL())) {
out.put("record", r);
out.put("isRecord", true);
out.put("instance", ins);
out.put("File", map.getFile());
return out;
}
}
}
String test = "/" + spec.getAdminData().getTenantName() + "/html/" + r.getUIURL();
if (pathinfo.equals(test)) {
out.put("record", r);
out.put("isRecord", true);
out.put("File", map.getFile());
return out;
}
}
}
}
}
return null;
}
use of org.collectionspace.chain.csp.schema.Record in project application by collectionspace.
the class RecordCreateUpdate method assignTerms.
private void assignTerms(Storage storage, String path, JSONObject data) throws JSONException, ExistException, UnimplementedException, UnderlyingStorageException, UIException {
JSONObject fields = data.optJSONObject("fields");
String insId = "";
if (fields.has("terms")) {
Record vr = this.spec.getRecord("vocab");
Record thisr = spec.getRecord("vocab");
String sid = fields.getString("shortIdentifier");
String name = fields.getString("displayName");
insId = "vocab-" + sid;
if (create) {
Map<String, String> options = new HashMap<String, String>();
options.put("id", insId);
options.put("title", name);
options.put("web-url", sid);
options.put("title-ref", sid);
Instance ins = new Instance(thisr, options);
vr.addInstance(ins);
}
ctl.get(storage, sid, vr, 0);
}
}
use of org.collectionspace.chain.csp.schema.Record in project application by collectionspace.
the class RecordCreateUpdate method assignPermissions.
private void assignPermissions(Storage storage, String path, JSONObject data) throws JSONException, ExistException, UnimplementedException, UnderlyingStorageException, UIException {
JSONObject fields = data.optJSONObject("fields");
JSONArray permdata = new JSONArray();
JSONObject permcheck = new JSONObject();
if (fields.has("permissions")) {
JSONArray permissions = fields.getJSONArray("permissions");
for (int i = 0; i < permissions.length(); i++) {
JSONObject perm = permissions.getJSONObject(i);
Record recordForPermResource = Generic.RecordNameServices(spec, perm.getString("resourceName"));
if (recordForPermResource != null) {
if (recordForPermResource.hasSoftDeleteMethod()) {
JSONObject permitem = getWorkflowPerm(storage, recordForPermResource, perm.getString("resourceName"), perm.getString("permission"), DELETE_WORKFLOW_TRANSITION);
if (permitem.has("permissionId")) {
if (permcheck.has(permitem.getString("resourceName"))) {
// ignore as we have duplicate name - eek
log.warn("RecordCreateUpdate.assignPermissions got duplicate workflow/delete permission for: " + permitem.getString("resourceName"));
} else {
permcheck.put(permitem.getString("resourceName"), permitem);
permdata.put(permitem);
}
}
}
if (recordForPermResource.supportsLocking()) {
JSONObject permitem = getWorkflowPerm(storage, recordForPermResource, perm.getString("resourceName"), perm.getString("permission"), LOCK_WORKFLOW_TRANSITION);
if (permitem.has("permissionId")) {
if (permcheck.has(permitem.getString("resourceName"))) {
// ignore as we have duplicate name - eek
log.warn("RecordCreateUpdate.assignPermissions got duplicate workflow/lock permission for: " + permitem.getString("resourceName"));
} else {
permcheck.put(permitem.getString("resourceName"), permitem);
permdata.put(permitem);
}
}
}
}
JSONObject permitem = getPerm(storage, recordForPermResource, perm.getString("resourceName"), perm.getString("permission"));
if (permitem.has("permissionId")) {
if (permcheck.has(permitem.getString("resourceName"))) {
// ignore as we have duplicate name - eek
log.warn("RecordCreateUpdate.assignPermissions got duplicate permission for: " + permitem.getString("resourceName"));
} else {
permcheck.put(permitem.getString("resourceName"), permitem);
permdata.put(permitem);
}
}
}
}
// log.info("permdata"+permdata.toString());
JSONObject roledata = new JSONObject();
roledata.put("roleName", fields.getString("roleName"));
String[] ids = path.split("/");
roledata.put("roleId", ids[ids.length - 1]);
JSONObject accountrole = new JSONObject();
JSONObject arfields = new JSONObject();
arfields.put("role", roledata);
arfields.put("permission", permdata);
accountrole.put("fields", arfields);
// log.info("WAAA"+arfields.toString());
if (fields != null)
path = storage.autocreateJSON(spec.getRecordByWebUrl("permrole").getID(), arfields, null);
}
use of org.collectionspace.chain.csp.schema.Record in project application by collectionspace.
the class RecordRead method buildRelationsSection.
// Builds an object, that has a map of record type to Array mappings.
private JSONObject buildRelationsSection(Storage storage, String csid) throws ExistException, UnimplementedException, UnderlyingStorageException, JSONException, UIException {
JSONObject recordtypes = new JSONObject();
JSONObject restrictions = new JSONObject();
JSONObject out = new JSONObject();
JSONArray paginations = new JSONArray();
restrictions.put("src", base + "/" + csid);
// loop over all procedure/recordtypes
for (Record thisr : spec.getAllRecords()) {
if ((thisr.isType("procedure") && !thisr.isType("vocabulary")) || "collection-object".equals(thisr.getID()))
try {
this.relatedObjSearcher = new RecordSearchList(thisr, RecordSearchList.MODE_SEARCH_RELATED);
this.relatedObjSearcher.configure(spec);
JSONObject temp = this.relatedObjSearcher.getResults(null, storage, restrictions, "results", csid);
JSONArray results = temp.getJSONArray("results");
if (results.length() > 0) {
out.put(thisr.getWebURL(), results);
}
} catch (Exception e) {
log.warn("Unable to to retrieve results for " + thisr.getSearchURL(), e);
}
}
return out;
}
use of org.collectionspace.chain.csp.schema.Record in project application by collectionspace.
the class RecordSearchList method getResults.
/**
* This function is the general function that calls the correct funtions to
* get all the data that the UI requested and get it in the correct format
* for the UI.
*
* @param {Storage} storage The type of storage requested (e.g.
* RecordStorage, AuthorizationStorage,...)
* @param {UIRequest} ui The request from the ui to which we send a
* response.
* @param {String} param If a querystring has been added to the
* URL(e.g.'?query='), it will be in this param
* @param {String} pageSize The amount of results per page requested.
* @param {String} pageNum The amount of pages requested.
* @throws UIException
* @throws UnderlyingStorageException
* @throws UnimplementedException
* @throws ExistException
* @throws JSONException
*/
protected JSONObject getResults(UIRequest request, Storage storage, JSONObject restriction, String key, String path) throws UIException, JSONException, ExistException, UnimplementedException, UnderlyingStorageException {
JSONObject results = new JSONObject();
if (this.r.getID().equals("permission")) {
//
// Pagination information is not implemented in permissions. See CSPACE-4785
// Until CSPACE-4785 gets resolved, we'll tread "permission" requests
// as a special case.
//
restriction.put("pageSize", MAX_PERMISSIONS_PAGESIZE);
results = getJSON(storage, restriction, key, base);
log.warn(String.format("Due to issue CSPACE-4785, we can retrieve only the first %d permission records.", MAX_PERMISSIONS_PAGESIZE));
log.debug(results.toString());
} else if (r.getID().equals("reports")) {
String type = "";
if (path != null && !path.equals("")) {
restriction.put("queryTerm", "doctype");
restriction.put("queryString", spec.getRecordByWebUrl(path).getServicesTenantDoctype(false));
}
if (restriction.has("queryTerm") && restriction.getString("queryTerm").equals("doctype")) {
type = restriction.getString("queryString");
results = getJSON(storage, restriction, key, base);
results = showReports(results, type, key);
if (request != null) {
int cacheMaxAgeSeconds = spec.getAdminData().getReportListCacheAge();
if (cacheMaxAgeSeconds > 0) {
request.setCacheMaxAgeSeconds(cacheMaxAgeSeconds);
}
}
} else {
JSONObject reporting = new JSONObject();
for (Record r2 : spec.getAllRecords()) {
if (r2.isInRecordList()) {
type = r2.getServicesTenantSg();
restriction.put("queryTerm", "doctype");
restriction.put("queryString", type);
JSONObject rdata = getJSON(storage, restriction, key, base);
JSONObject procedurereports = showReports(rdata, type, key);
reporting.put(r2.getWebURL(), procedurereports);
}
}
results.put("reporting", reporting);
}
} else if (r.getID().equals("batch")) {
String type = "";
if (path != null && !path.equals("")) {
restriction.put("queryTerm", "doctype");
restriction.put("queryString", spec.getRecordByWebUrl(path).getServicesTenantDoctype(false));
}
if (restriction.has("queryTerm") && restriction.getString("queryTerm").equals("doctype")) {
type = restriction.getString("queryString");
results = getJSON(storage, restriction, key, base);
results = showBatches(results, type, key);
// TODO: Add caching stuff, as with reports
} else {
JSONObject batch = new JSONObject();
for (Record r2 : spec.getAllRecords()) {
if (r2.isInRecordList()) {
type = r2.getServicesTenantSg();
restriction.put("queryTerm", "doctype");
restriction.put("queryString", type);
JSONObject rdata = getJSON(storage, restriction, key, base);
JSONObject procedurebatches = showBatches(rdata, type, key);
batch.put(r2.getWebURL(), procedurebatches);
}
}
results.put("batch", batch);
}
} else {
if ((mode == MODE_SEARCH_RELATED) && !path.isEmpty()) {
// This is a related to case
restriction.put(GenericSearch.SEARCH_RELATED_TO_CSID_AS_SUBJECT, path);
}
if ((searchAllGroup != null) && r.isType("searchall")) {
// Add a new service group name to
restriction.put(GenericSearch.SEARCH_ALL_GROUP, searchAllGroup);
}
results = getJSON(storage, restriction, key, base);
}
return results;
}
Aggregations