use of org.collectionspace.csp.api.ui.UIException in project application by collectionspace.
the class UserDetailsRead method getJSON.
/* Wrapper exists to decomplexify exceptions */
private JSONObject getJSON(Storage storage, String csid) throws UIException {
JSONObject out = new JSONObject();
try {
if (record_type) {
JSONObject fields = storage.retrieveJSON(base + "/" + csid, new JSONObject());
// XXX remove this, subject to UI team approval?
fields.put("csid", csid);
JSONObject roles = storage.retrieveJSON(base + "/" + csid + "/" + "userrole", new JSONObject());
JSONArray allroles = Generic.getRoles(storage, roles);
fields.put("role", allroles);
out.put("fields", fields);
out.put("isError", false);
JSONObject messages = new JSONObject();
messages.put("message", "");
messages.put("severity", "info");
JSONArray arr = new JSONArray();
arr.put(messages);
out.put("messages", arr);
out.put("relations", new JSONArray());
} else {
out = storage.retrieveJSON(base + "/" + csid, new JSONObject());
}
} catch (ExistException e) {
throw new UIException("JSON Not found ", e);
} catch (UnimplementedException e) {
throw new UIException("Unimplemented", e);
} 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, e);
}
if (out == null) {
throw new UIException("No JSON Found");
}
return out;
}
use of org.collectionspace.csp.api.ui.UIException in project application by collectionspace.
the class UserDetailsReset method getcsID.
private JSONObject getcsID(Storage storage, String emailparam) throws UIException {
JSONObject restriction = new JSONObject();
JSONObject failedJSON = new JSONObject();
try {
failedJSON.put("isError", true);
if (emailparam != null && emailparam != "") {
restriction.put("email", emailparam);
restriction.put("pageSize", "40");
int resultsize = 1;
int pagenum = 0;
String checkpagination = "";
while (resultsize > 0) {
restriction.put("pageNum", pagenum);
/* XXX need to force it to only do an exact match */
JSONObject data = storage.getPathsJSON(base, restriction);
String[] paths = (String[]) data.get("listItems");
pagenum++;
if (paths.length == 0 || checkpagination.equals(paths[0])) {
resultsize = 0;
// testing whether we have actually returned the same page or the next page - all csid returned should be unique
} else {
checkpagination = paths[0];
/* make sure it is an exact match */
for (int i = 0; i < paths.length; i++) {
// GET full details
JSONObject fields = storage.retrieveJSON(base + "/" + paths[i], new JSONObject());
String emailtest = fields.getString("email");
if (emailtest.equals(emailparam)) {
JSONObject outputJSON = new JSONObject();
outputJSON.put("fields", fields);
outputJSON.put("isError", false);
outputJSON.put("csid", paths[i]);
return outputJSON;
}
}
}
}
failedJSON.put("message", "Could not find a user with email " + emailparam);
} else {
failedJSON.put("message", "No email specified ");
}
return failedJSON;
} catch (JSONException e) {
throw new UIException("JSONException during search on email address", e);
} catch (ExistException e) {
throw new UIException("ExistException during search on email address", e);
} catch (UnimplementedException e) {
throw new UIException("UnimplementedException during search on email address", e);
} catch (UnderlyingStorageException x) {
UIException uiexception = new UIException(x.getMessage(), x.getStatus(), x.getUrl(), x);
return uiexception.getJSON();
}
}
use of org.collectionspace.csp.api.ui.UIException in project application by collectionspace.
the class UserRolesRead method getJSON.
/* Wrapper exists to decomplexify exceptions */
private JSONObject getJSON(Storage storage, String csid) throws UIException {
JSONObject out = new JSONObject();
try {
if (!record_type) {
JSONObject fields = storage.retrieveJSON("base+/" + csid, new JSONObject());
// XXX remove this, subject to UI team approval?
fields.put("csid", csid);
out.put("fields", fields);
out.put("isError", false);
JSONObject messages = new JSONObject();
messages.put("message", "");
messages.put("severity", "info");
JSONArray arr = new JSONArray();
arr.put(messages);
out.put("messages", arr);
out.put("relations", new JSONArray());
} else {
out = storage.retrieveJSON(this.sub_base + "/" + csid, new JSONObject());
}
} catch (ExistException e) {
throw new UIException("ExistException " + e, e);
} catch (UnimplementedException e) {
throw new UIException("Unimplemented", e);
} 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, e);
}
if (out == null) {
throw new UIException("No JSON Found");
}
return out;
}
use of org.collectionspace.csp.api.ui.UIException in project application by collectionspace.
the class StreamUIRequest method print.
private static void print(OutputStream stream, String x) throws UIException {
try {
stream.write(x.getBytes("UTF-8"));
stream.flush();
} catch (IOException e) {
throw new UIException("IOException writing line", e);
}
}
use of org.collectionspace.csp.api.ui.UIException in project application by collectionspace.
the class DataGenerator method createAllRecords.
/**
* Create all record types (that make sense)
* @param storage
* @param ui
* @return
* @throws UIException
*/
protected JSONObject createAllRecords(Storage storage, UIRequest ui) throws UIException {
log.info("Lets make some records");
tty.line("Lets make some records");
tty.flush();
JSONObject returnData = new JSONObject();
try {
for (Record r : spec.getAllRecords()) {
if (r.isType("authority") || r.isType("authorizationdata") || r.isType("id") || r.isType("userdata")) {
// don't do these yet (if ever)
} else if (r.getID().equals("structureddate") || r.getID().equals("media") || r.getID().equals("hierarchy") || r.getID().equals("blobs") || r.getID().equals("dimension") || r.getID().equals("contacts") || r.isType("searchall")) {
// and ignore these
} else if (r.getID().equals("termlist") || r.getID().equals("termlistitem")) {
// and ignore these
} else {
this.record = r;
this.structureview = "screen";
this.writer = new RecordCreateUpdate(r, true);
JSONObject items = createRecords(storage, ui);
returnData.put(r.getID(), items.getJSONObject(r.getID()));
}
}
// lets create some relationships
log.info("Initializing relationships");
tty.line("Initializing relationships");
tty.flush();
createDataSetRelationships(returnData);
} catch (JSONException x) {
throw new UIException("Failed to parse json: ", x);
} catch (ExistException x) {
throw new UIException("Existence exception: ", x);
} catch (UnimplementedException x) {
throw new UIException("Unimplemented exception: ", x);
} catch (UnderlyingStorageException x) {
throw new UIException("Problem storing: " + x.getLocalizedMessage(), x.getStatus(), x.getUrl(), x);
}
return returnData;
}
Aggregations