use of org.collectionspace.csp.api.persistence.UnimplementedException in project application by collectionspace.
the class RecordDelete method store_delete.
private void store_delete(Storage storage, UIRequest request, String path) throws UIException {
try {
if (base.equals("role")) {
// business logic. Only delete role if no active users exists who have this role set
// CSPACE-3283
// Note that given this, we need not clear the userperms cache when deleting a role.
String url = base + "/" + path + "/" + "accountroles/";
JSONObject accounts = storage.retrieveJSON(url, new JSONObject());
if (accounts.has("account") && accounts.getJSONArray("account").length() > 0) {
if (accounts.getJSONArray("account").getJSONObject(0).length() > 0) {
// refuse to delete as has roles attached
UIException uiexception = new UIException("This Role has Accounts associated with it");
request.sendJSONResponse(uiexception.getJSON());
return;
}
}
}
storage.deleteJSON(base + "/" + path);
} catch (ExistException e) {
throw new UIException("JSON Not found " + e, e);
} catch (UnimplementedException e) {
throw new UIException("Unimplemented ", e);
} catch (UnderlyingStorageException x) {
UIException uiexception = new UIException(x.getMessage(), x.getStatus(), x.getUrl(), x);
request.sendJSONResponse(uiexception.getJSON());
} catch (JSONException e) {
throw new UIException("JSONException ", e);
}
}
use of org.collectionspace.csp.api.persistence.UnimplementedException 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.csp.api.persistence.UnimplementedException in project application by collectionspace.
the class RecordRead method getJSON.
/* Wrapper exists to decomplexify exceptions: also used inCreateUpdate, hence not private */
public JSONObject getJSON(Storage storage, String csid) throws UIException {
JSONObject out = new JSONObject();
JSONObject restrictions = new JSONObject();
try {
if (record_type || authorization_type) {
JSONObject fields = storage.retrieveJSON(base + "/" + csid, restrictions);
// XXX remove this, subject to UI team approval?
fields.put("csid", csid);
out.put("csid", csid);
if (base.equals("role")) {
if (authorization_type) {
JSONObject permissions = storage.retrieveJSON(base + "/" + csid + "/" + "permroles/", restrictions);
JSONArray allperms = getPermissions(storage, permissions);
fields.put("permissions", allperms);
String url = base + "/" + csid + "/" + "accountroles/";
JSONObject accounts = storage.retrieveJSON(url, restrictions);
JSONArray usedby = new JSONArray();
if (accounts.has("account")) {
usedby = accounts.getJSONArray("account");
}
fields.put("usedBy", usedby);
}
} else if (base.equals("termlist")) {
String shortname = fields.getString("shortIdentifier");
JSONArray allUsed = getUsedBy(shortname);
fields.put("usedBys", allUsed);
} else {
fields = getHierarchy(storage, fields);
// JSONObject relations=createRelations(storage,csid);
if (!showbasicinfoonly) {
JSONObject tusd = this.termsused.getTermsUsed(storage, base + "/" + csid, new JSONObject());
out.put("termsUsed", tusd.getJSONArray("results"));
JSONObject relations = buildRelationsSection(storage, csid);
out.put("relations", relations);
}
}
out.put("fields", fields);
} else {
out = storage.retrieveJSON(base + "/" + csid, restrictions);
}
} catch (ExistException e) {
UIException uiexception = new UIException(e.getMessage(), e);
return uiexception.getJSON();
} catch (UnimplementedException e) {
UIException uiexception = new UIException(e.getMessage(), e);
return uiexception.getJSON();
} catch (UnderlyingStorageException x) {
UIException uiexception = new UIException(x.getMessage(), x.getStatus(), x.getUrl(), x);
return uiexception.getJSON();
} catch (JSONException e) {
throw new UIException("Could not create JSON", e);
}
if (out == null) {
UIException uiexception = new UIException("No JSON Found");
return uiexception.getJSON();
}
return out;
}
use of org.collectionspace.csp.api.persistence.UnimplementedException in project application by collectionspace.
the class RecordRelated method getRelation.
private JSONObject getRelation(Storage storage, JSONObject myres, JSONObject recordtypes, JSONArray paginated) throws ExistException, UnimplementedException, UnderlyingStorageException, JSONException {
JSONObject data = storage.getPathsJSON("relations/main", myres);
String[] relations = (String[]) data.get("listItems");
JSONObject pagination = data.getJSONObject("pagination");
// get a list of what is paginated
JSONObject typelist = new JSONObject();
for (String r : relations) {
try {
JSONObject relateitem = generateRelationEntry(storage, r);
String type = relateitem.getString("recordtype");
typelist.put(type, "1");
if (!recordtypes.has(type)) {
recordtypes.put(type, new JSONArray());
}
recordtypes.getJSONArray(type).put(relateitem);
} catch (Exception e) {
// Never mind.
// Probably should do something with the errors... could be a permissions issue
}
}
pagination.put("recordtypes", typelist.names());
if (!pagination.getString("totalItems").equals("0")) {
paginated.put(pagination);
}
return recordtypes;
}
use of org.collectionspace.csp.api.persistence.UnimplementedException in project application by collectionspace.
the class RecordSearchList method advancedSearch.
private void advancedSearch(Storage storage, UIRequest ui, String path, JSONObject params) throws UIException {
try {
JSONObject results = new JSONObject();
JSONObject restrictedkey = GenericSearch.setRestricted(ui, null, null, null, true, this.r);
JSONObject restriction = restrictedkey.getJSONObject("restriction");
String key = restrictedkey.getString("key");
GenericSearch.buildQuery(this.r, params, restriction);
key = "results";
results = getJSON(storage, restriction, key, base);
// cache for record traverser
if (results.has("pagination") && results.getJSONObject("pagination").has("separatelists")) {
GenericSearch.createTraverser(ui, this.r.getID(), "", results, restriction, key, 1);
}
ui.sendJSONResponse(results);
} catch (JSONException e) {
throw new UIException("JSONException during advancedSearch " + e.getMessage(), e);
} catch (ExistException e) {
throw new UIException("ExistException during search_or_list", e);
} catch (UnimplementedException e) {
throw new UIException("UnimplementedException during search_or_list", e);
} catch (UnderlyingStorageException x) {
UIException uiexception = new UIException(x.getMessage(), x.getStatus(), x.getUrl(), x);
ui.sendJSONResponse(uiexception.getJSON());
}
}
Aggregations