use of org.collectionspace.chain.csp.schema.Record in project application by collectionspace.
the class RecordRelated method configure.
public void configure(WebUI ui, Spec spec) {
for (Record r : spec.getAllRecords()) {
type_to_url.put(r.getID(), r.getWebURL());
servicename_to_serviceid.put(r.getServicesTenantSg(), r.getID());
}
}
use of org.collectionspace.chain.csp.schema.Record in project application by collectionspace.
the class RecordRelated method getRelations.
protected JSONObject getRelations(Storage storage, JSONObject restriction, JSONObject recordtypes, JSONArray paginated) throws JSONException, ExistException, UnimplementedException, UnderlyingStorageException {
JSONObject myres = restriction;
if (this.relatedrecord == null) {
// return all of the procedures etc
for (Record r2 : this.record.getSpec().getAllRecords()) {
if (r2.isType("procedure") && !r2.isType("vocabulary")) {
myres.put("dstType", r2.getServicesTenantSg());
getRelation(storage, myres, recordtypes, paginated);
}
}
} else {
myres.put("dstType", this.relatedrecord.getServicesTenantSg());
getRelation(storage, myres, recordtypes, paginated);
}
JSONObject out = new JSONObject();
out.put("results", recordtypes);
out.put("pagination", paginated);
return out;
}
use of org.collectionspace.chain.csp.schema.Record in project application by collectionspace.
the class RecordRelated method configure.
public void configure(Spec spec) {
for (Record r : spec.getAllRecords()) {
type_to_url.put(r.getID(), r.getWebURL());
servicename_to_serviceid.put(r.getServicesTenantSg(), r.getID());
}
}
use of org.collectionspace.chain.csp.schema.Record in project application by collectionspace.
the class RecordSearchList method generateMiniRecord.
/**
* Retrieve the mini summary information e.g. summary and number and append
* the csid and recordType to it
*
* @param {Storage} storage Type of storage (e.g. AuthorizationStorage,
* RecordStorage,...)
* @param {String} type The type of record requested (e.g. permission)
* @param {String} csid The csid of the record
* @return {JSONObject} The JSON string containing the mini record
* @throws ExistException
* @throws UnimplementedException
* @throws UnderlyingStorageException
* @throws JSONException
*/
private JSONObject generateMiniRecord(Storage storage, String type, String csid) throws JSONException {
String postfix = "list";
if (this.mode == MODE_SEARCH) {
postfix = "search";
}
JSONObject restrictions = new JSONObject();
JSONObject out = new JSONObject();
try {
if (csid == null || csid.equals("")) {
return out;
}
out = storage.retrieveJSON(type + "/" + csid + "/view/" + postfix, restrictions);
out.put("csid", csid);
String recordtype = null;
if (!r.isType("searchall")) {
recordtype = type_to_url.get(type);
} else {
JSONObject summarylist = out.getJSONObject("summarylist");
String uri = summarylist.getString("uri");
if (uri != null && uri.startsWith("/")) {
uri = uri.substring(1);
}
String[] parts = uri.split("/");
String recordurl = parts[0];
Record itemr = r.getSpec().getRecordByServicesUrl(recordurl);
if (itemr == null) {
String docType = summarylist.getString("docType");
itemr = r.getSpec().getRecordByServicesDocType(docType);
}
if (itemr == null) {
recordtype = UNKNOWN_RECORD_TYPE;
log.warn("Could not get record type for record with services URI " + uri);
} else {
recordtype = type_to_url.get(itemr.getID());
String refName = null;
if (summarylist.has("refName")) {
refName = summarylist.getString("refName");
}
// For an authority item (i.e. an item in a vocabulary),
// include the name of its parent vocabulary in a
// "namespace" value within the mini summary.
RefName.AuthorityItem item = null;
if (refName != null) {
item = RefName.AuthorityItem.parse(refName);
}
// authority item refName, then include the "namespace" value.
if (item != null) {
String namespace = item.getParentShortIdentifier();
if (namespace != null) {
out.put("namespace", namespace);
} else {
log.warn("Could not get vocabulary namespace for record with services URI " + uri);
}
}
}
}
out.put("recordtype", recordtype);
// CSPACE-2894
if (this.r.getID().equals("permission")) {
String summary = out.getString("summary");
String name = Generic.ResourceNameUI(this.r.getSpec(), summary);
if (name.contains(WORKFLOW_SUB_RESOURCE)) {
return null;
}
out.put("summary", name);
out.put("display", Generic.getPermissionView(this.r.getSpec(), summary));
}
} catch (ExistException e) {
out.put("csid", csid);
out.put("isError", true);
JSONObject msg = new JSONObject();
msg.put("severity", "error");
msg.put("message", "Exist Exception:" + e.getMessage());
JSONArray msgs = new JSONArray();
msgs.put(msg);
out.put("messages", msgs);
} catch (UnimplementedException e) {
out.put("csid", csid);
out.put("isError", true);
JSONObject msg = new JSONObject();
msg.put("severity", "error");
msg.put("message", "Exist Exception:" + e.getMessage());
JSONArray msgs = new JSONArray();
msgs.put(msg);
out.put("messages", msgs);
} catch (UnderlyingStorageException e) {
out.put("csid", csid);
out.put("isError", true);
JSONObject msg = new JSONObject();
msg.put("severity", "error");
msg.put("message", "Exist Exception:" + e.getMessage());
JSONArray msgs = new JSONArray();
msgs.put(msg);
out.put("messages", msgs);
}
return out;
}
use of org.collectionspace.chain.csp.schema.Record in project application by collectionspace.
the class WebUI method configure_finish.
private void configure_finish(Spec spec) {
final String MEDIA_RECORD_ID = "media";
for (Operation op : Operation.values()) tries.put(op, new Trie());
// Operation.CREATE/UPDATE = method= POST
// Operation.READ = method= GET
addMethod(Operation.READ, new String[] { "login" }, 0, new WebLogin(this, spec));
addMethod(Operation.CREATE, new String[] { "login" }, 0, new WebLogin(this, spec));
addMethod(Operation.CREATE, new String[] { "uploads" }, 0, new BlobCreateUpdate(spec.getRecord("blobs"), true));
addMethod(Operation.READ, new String[] { "uploads" }, 0, new BlobCreateUpdate(spec.getRecord("blobs"), true));
addMethod(Operation.READ, new String[] { "download" }, 1, new BlobRead());
addMethod(Operation.READ, new String[] { "logout" }, 0, new WebLogout());
addMethod(Operation.READ, new String[] { "loginstatus" }, 0, new WebLoginStatus(spec));
addMethod(Operation.READ, new String[] { "authorities", "initialise" }, 0, new WebReset(false, false));
addMethod(Operation.READ, new String[] { "reset" }, 0, new WebReset(false, true));
addMethod(Operation.READ, new String[] { "quick-reset" }, 0, new WebReset(true, true));
// addMethod(Operation.READ,new String[]{find_page,"uispec"},0,new
// FindEditUISpec(spec.getAllRecords()));//removed as I don't think
// anyone uses it
addMethod(Operation.CREATE, new String[] { "passwordreset" }, 0, new UserDetailsReset(false, spec));
addMethod(Operation.CREATE, new String[] { "resetpassword" }, 0, new UserDetailsReset(true, spec));
addMethod(Operation.READ, new String[] { "adjacentRecords" }, 2, new RecordTraverser(spec));
addMethod(Operation.READ, new String[] { "parseDate" }, 0, new StructuredDateParser());
for (Schemas s : spec.getAllSchemas()) {
addMethod(Operation.READ, new String[] { s.getWebURL(), "uischema" }, 0, new UISchema(spec, s));
}
addMethod(Operation.READ, new String[] { "generator" }, 0, new DataGenerator(spec));
Record mediaR = spec.getRecord(MEDIA_RECORD_ID);
if (mediaR == null) {
log.error("No media record configured!!!");
}
for (Record r : spec.getAllRecords()) {
addMethod(Operation.READ, new String[] { r.getWebURL(), "generator" }, 0, new DataGenerator(r, "screen"));
addMethod(Operation.READ, new String[] { r.getWebURL(), "serviceschema" }, 0, new ServicesXsd(r, "common"));
addMethod(Operation.READ, new String[] { r.getWebURL(), "uischema" }, 0, new UISchema(r, "screen"));
addMethod(Operation.READ, new String[] { r.getTabURL(), "uischema" }, 0, new UISchema(r, "tab"));
addMethod(Operation.READ, new String[] { r.getSearchURL(), "uischema" }, 0, new UISchema(r, "search"));
addMethod(Operation.READ, new String[] { r.getWebURL(), "uispec" }, 0, new UISpec(r, "screen"));
addMethod(Operation.READ, new String[] { r.getTabURL(), "uispec" }, 0, new UISpec(r, "tab"));
addMethod(Operation.READ, new String[] { r.getSearchURL(), "uispec" }, 0, new UISpec(r, "search"));
addMethod(Operation.READ, new String[] { r.getWebURL(), "termList" }, 1, new WebTermList(r));
if (r.isType("authority")) {
// urls like record urls to make life easier for the UI
// CSPACE-1139
addMethod(Operation.READ, new String[] { r.getWebURL() }, 0, new AuthoritiesVocabulariesSearchList(r, false));
addMethod(Operation.READ, new String[] { r.getWebURL(), "search" }, 0, new AuthoritiesVocabulariesSearchList(r, true));
addMethod(Operation.CREATE, new String[] { r.getWebURL(), "search" }, 0, new AuthoritiesVocabulariesSearchList(r, true));
addMethod(Operation.READ, new String[] { "authorities", r.getWebURL() }, 0, new AuthoritiesVocabulariesSearchList(r, false));
addMethod(Operation.READ, new String[] { "authorities", r.getWebURL(), "search" }, 0, new AuthoritiesVocabulariesSearchList(r, true));
addMethod(Operation.CREATE, new String[] { "authorities", r.getWebURL(), "search" }, 0, new AuthoritiesVocabulariesSearchList(r, true));
addMethod(Operation.CREATE, new String[] { "authorities", r.getWebURL() }, 0, new VocabulariesCreateUpdate(r, true));
addMethod(Operation.READ, new String[] { "authorities", r.getWebURL(), "initialize" }, 0, new AuthoritiesVocabulariesInitialize(r, true));
addMethod(Operation.READ, new String[] { "authorities", r.getWebURL(), "refresh" }, 0, new AuthoritiesVocabulariesInitialize(r, false));
// We'll search on media related to the CSID tail.
if (mediaR != null) {
addMethod(Operation.READ, new String[] { r.getWebURL(), mediaR.getWebURL() }, 1, new RecordSearchList(mediaR, RecordSearchList.MODE_SEARCH_RELATED));
}
for (Instance n : r.getAllInstances()) {
addMethod(Operation.READ, new String[] { "vocabularies", n.getWebURL() }, 0, new AuthoritiesVocabulariesSearchList(n, false));
addMethod(Operation.READ, new String[] { "vocabularies", n.getWebURL(), "search" }, 0, new AuthoritiesVocabulariesSearchList(n, true));
addMethod(Operation.CREATE, new String[] { "vocabularies", n.getWebURL(), "search" }, 0, new AuthoritiesVocabulariesSearchList(n, true));
addMethod(Operation.READ, new String[] { "vocabularies", n.getWebURL(), "initialize" }, 0, new AuthoritiesVocabulariesInitialize(n, true, true));
addMethod(Operation.READ, new String[] { "vocabularies", n.getWebURL(), "refresh" }, 0, new AuthoritiesVocabulariesInitialize(n, false, true));
addMethod(Operation.READ, new String[] { "vocabularies", n.getWebURL() }, 1, new VocabulariesRead(n, VocabulariesRead.GET_FULL_INFO));
addMethod(Operation.READ, new String[] { "vocabularies", "basic", n.getWebURL() }, 1, new VocabulariesRead(n, VocabulariesRead.GET_BASIC_INFO));
addMethod(Operation.READ, new String[] { "vocabularies", n.getWebURL(), "authorities" }, 1, new VocabulariesRead(n, VocabulariesRead.GET_TERMS_USED_INFO));
addMethod(Operation.READ, new String[] { "vocabularies", n.getWebURL(), "refobjs" }, 1, new VocabulariesRead(n, VocabulariesRead.GET_REF_OBJS_INFO));
addMethod(Operation.READ, new String[] { "vocabularies", n.getWebURL(), "autocomplete" }, 0, new WebAutoComplete(spec.getRecord(r.getID())));
addMethod(Operation.CREATE, new String[] { "vocabularies", n.getWebURL() }, 0, new VocabulariesCreateUpdate(n, true));
addMethod(Operation.UPDATE, new String[] { "vocabularies", n.getWebURL() }, 1, new VocabulariesCreateUpdate(n, false));
addMethod(Operation.DELETE, new String[] { "vocabularies", n.getWebURL() }, 0, new VocabulariesDelete(n));
addMethod(Operation.UPDATE, new String[] { "vocabularies", n.getWebURL(), "workflow" }, 2, new VocabulariesWorkflowTransition(n));
addMethod(Operation.READ, new String[] { "vocabularies", n.getWebURL(), "source-vocab" }, 1, new VocabRedirector(r));
}
} else if (r.isType("record") || r.isType("blob") || r.isType("authorizationdata")) {
addMethod(Operation.READ, new String[] { r.getWebURL(), "__auto" }, 0, new WebAuto());
addMethod(Operation.READ, new String[] { r.getWebURL(), "autocomplete" }, 0, new WebAutoComplete(spec.getRecord(r.getID())));
addMethod(Operation.READ, new String[] { r.getWebURL(), "search" }, 0, new RecordSearchList(r, RecordSearchList.MODE_SEARCH));
addMethod(Operation.CREATE, new String[] { r.getWebURL(), "search" }, 0, new RecordSearchList(r, RecordSearchList.MODE_SEARCH));
addMethod(Operation.READ, new String[] { r.getWebURL() }, 0, new RecordSearchList(r, RecordSearchList.MODE_LIST));
addMethod(Operation.READ, new String[] { r.getWebURL() }, 1, new RecordRead(r));
addMethod(Operation.READ, new String[] { "basic", r.getWebURL() }, 1, new RecordRead(r, true));
addMethod(Operation.DELETE, new String[] { r.getWebURL() }, 1, new RecordDelete(r.getID()));
addMethod(Operation.CREATE, new String[] { r.getWebURL() }, 0, new RecordCreateUpdate(r, true));
addMethod(Operation.UPDATE, new String[] { r.getWebURL() }, 1, new RecordCreateUpdate(r, false));
addMethod(Operation.READ, new String[] { r.getWebURL(), "source-vocab" }, 1, new VocabRedirector(r));
addMethod(Operation.READ, new String[] { r.getWebURL(), "authorities" }, 1, new RecordAuthorities(r));
// relatable records.
if ((r.isType("procedure") && !r.isType("vocabulary")) || "collection-object".equals(r.getID())) {
for (Record r2 : spec.getAllRecords()) {
if ((r2.isType("procedure") && !r2.isType("vocabulary")) || "collection-object".equals(r2.getID())) {
// We do not actually care about the type of r, but
// rather just the CSID tail.
// We'll search on r2's related to the CSID tail.
addMethod(Operation.READ, new String[] { r.getWebURL(), r2.getWebURL() }, 1, new RecordSearchList(r2, RecordSearchList.MODE_SEARCH_RELATED));
} else if (r2.isType("searchall")) {
// Allow to ask for all procedures related to this
// record. Use SearchAll with a related search.
addMethod(Operation.READ, new String[] { r.getWebURL(), "procedures" }, 1, new RecordSearchList(r2, RecordSearchList.MODE_SEARCH_RELATED, "procedure"));
}
}
}
} else if (r.isType("userdata")) {
addMethod(Operation.READ, new String[] { r.getWebURL(), "search" }, 0, new UserDetailsSearchList(r, true));
addMethod(Operation.READ, new String[] { r.getWebURL() }, 1, new UserDetailsRead(r));
addMethod(Operation.READ, new String[] { r.getWebURL() }, 0, new UserDetailsSearchList(r, false));
addMethod(Operation.DELETE, new String[] { r.getWebURL() }, 1, new UserDetailsDelete(r.getID()));
addMethod(Operation.CREATE, new String[] { r.getWebURL() }, 0, new UserDetailsCreateUpdate(r, true));
addMethod(Operation.UPDATE, new String[] { r.getWebURL() }, 1, new UserDetailsCreateUpdate(r, false));
addMethod(Operation.READ, new String[] { r.getWebURL() }, 3, new UserRolesRead(spec.getRecordByWebUrl("userrole")));
addMethod(Operation.CREATE, new String[] { r.getWebURL() }, 2, new UserRolesCreate(spec.getRecordByWebUrl("userrole")));
addMethod(Operation.DELETE, new String[] { r.getWebURL() }, 3, new UserRolesDelete(spec.getRecordByWebUrl("userrole").getID()));
} else if (r.isType("id")) {
// XXX this isn't right but it does work. NEEDS to have it's own
// methods rather than piggy backing on RECORD
addMethod(Operation.READ, new String[] { r.getWebURL(), "__auto" }, 0, new WebAuto());
addMethod(Operation.READ, new String[] { r.getWebURL(), "autocomplete" }, 0, new WebAutoComplete(spec.getRecord(r.getID())));
addMethod(Operation.READ, new String[] { r.getWebURL(), "search" }, 0, new RecordSearchList(r, RecordSearchList.MODE_SEARCH));
addMethod(Operation.READ, new String[] { r.getWebURL() }, 0, new RecordSearchList(r, RecordSearchList.MODE_LIST));
addMethod(Operation.READ, new String[] { r.getWebURL() }, 1, new RecordRead(r));
addMethod(Operation.DELETE, new String[] { r.getWebURL() }, 1, new RecordDelete(r.getID()));
addMethod(Operation.CREATE, new String[] { r.getWebURL() }, 0, new RecordCreateUpdate(r, true));
addMethod(Operation.UPDATE, new String[] { r.getWebURL() }, 1, new RecordCreateUpdate(r, false));
addMethod(Operation.READ, new String[] { r.getWebURL(), "source-vocab" }, 1, new VocabRedirector(r));
} else if (r.isType("searchall")) {
addMethod(Operation.READ, new String[] { r.getWebURL(), "search" }, 0, new RecordSearchList(r, RecordSearchList.MODE_SEARCH));
}
}
addMethod(Operation.CREATE, new String[] { "relationships" }, 0, new RelateCreateUpdate(true));
addMethod(Operation.UPDATE, new String[] { "relationships" }, 1, new RelateCreateUpdate(false));
addMethod(Operation.READ, new String[] { "relationships" }, 1, new RelateRead());
addMethod(Operation.READ, new String[] { "relationships", "hierarchical" }, 1, new RelateRead("hierarchical"));
addMethod(Operation.DELETE, new String[] { "relationships" }, 1, new RelateDelete(false));
addMethod(Operation.DELETE, new String[] { "relationships", "one-way" }, 1, new RelateDelete(true));
addMethod(Operation.READ, new String[] { "relationships", "search" }, 0, new RelateSearchList(true));
addMethod(Operation.READ, new String[] { "relationships", "hierarchical", "search" }, 0, new RelateSearchList(true, "hierarchical"));
addMethod(Operation.READ, new String[] { "relationships", "hierarchical" }, 0, new RelateSearchList(false, "hierarchical"));
addMethod(Operation.READ, new String[] { "relationships" }, 0, new RelateSearchList(false));
}
Aggregations