use of org.collectionspace.csp.api.ui.UIException in project application by collectionspace.
the class WebUISession method randomSession.
private String randomSession() throws UIException {
String sessionid = rnd.nextLong() + ":" + rnd.nextLong() + ":" + System.currentTimeMillis();
byte[] defaultBytes = sessionid.getBytes();
try {
MessageDigest algorithm = MessageDigest.getInstance("MD5");
algorithm.reset();
algorithm.update(defaultBytes);
byte[] messageDigest = algorithm.digest();
StringBuffer hexString = new StringBuffer();
for (int i = 0; i < messageDigest.length; i++) {
String hex = Integer.toHexString(0xFF & messageDigest[i]);
if (hex.length() == 1)
hexString.append('0');
hexString.append(hex);
}
return hexString + "";
} catch (NoSuchAlgorithmException nsae) {
throw new UIException("MD5 not supported", nsae);
}
}
use of org.collectionspace.csp.api.ui.UIException 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.ui.UIException 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.ui.UIException 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.ui.UIException 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