use of org.collectionspace.csp.api.ui.UIException in project application by collectionspace.
the class AuthoritiesVocabulariesSearchList method run.
@Override
public void run(Object in, String[] tail) throws UIException {
if (tail.length > 0) {
throw new UIException("Illegal search specified. Tail: " + r.getWebURL() + "/" + StringUtils.join(tail, "/"));
}
Request q = (Request) in;
UIRequest uir = q.getUIRequest();
if (search) {
searchtype(q.getStorage(), uir, uir.getRequestArgument(SEARCH_QUERY_PARAM), uir.getRequestArgument(PAGE_SIZE_PARAM), uir.getRequestArgument(PAGE_NUM_PARAM));
} else {
searchtype(q.getStorage(), uir, null, uir.getRequestArgument(PAGE_SIZE_PARAM), uir.getRequestArgument(PAGE_NUM_PARAM));
}
}
use of org.collectionspace.csp.api.ui.UIException in project application by collectionspace.
the class AuthoritiesVocabulariesSearchList method searchtype.
public void searchtype(Storage storage, UIRequest ui, String param, String pageSize, String pageNum) throws UIException {
try {
JSONObject restrictedkey = GenericSearch.setRestricted(ui, param, pageNum, pageSize, search, this.r);
JSONObject restriction = restrictedkey.getJSONObject("restriction");
String resultstring = restrictedkey.getString("key");
if (ui.getBody() == null || StringUtils.isBlank(ui.getBody())) {
search_or_list(storage, ui, restriction, resultstring);
} else {
// advanced search
advancedSearch(storage, ui, restriction, resultstring, ui.getJSONBody());
}
} catch (JSONException e) {
throw new UIException("Cannot generate JSON", e);
} catch (ExistException e) {
throw new UIException("Exist exception", e);
} catch (UnimplementedException e) {
throw new UIException("Unimplemented exception", e);
} catch (UnderlyingStorageException x) {
UIException uiexception = new UIException(x.getMessage(), x.getStatus(), x.getUrl(), x);
ui.sendJSONResponse(uiexception.getJSON());
}
}
use of org.collectionspace.csp.api.ui.UIException in project application by collectionspace.
the class VocabulariesCreateUpdate method store_set.
private void store_set(Storage storage, UIRequest request, String path) throws UIException {
try {
JSONObject data = request.getJSONBody();
String redirectpath = "";
// is this an instance or an item?
if (this.r == null && this.n != null) {
FieldSet displayNameFS = n.getRecord().getDisplayNameField();
String displayNameFieldName = (displayNameFS != null) ? displayNameFS.getID() : null;
boolean quickie = false;
String quickieDisplayName = null;
if (create) {
quickie = (data.has("_view") && data.getString("_view").equals("autocomplete"));
// Check to see if displayName field needs remapping from UI
if (quickie && !"displayName".equals(displayNameFieldName)) {
// Need to map the field for displayName, and put it into a proper structure
JSONObject fields = data.getJSONObject("fields");
quickieDisplayName = fields.getString("displayName");
if (quickieDisplayName != null) {
// displayNames are nested now, so must have a field parent
FieldSet parentTermGroup = (FieldSet) displayNameFS.getParent();
JSONArray parentTermInfoArray = new JSONArray();
JSONObject termInfo = new JSONObject();
termInfo.put(displayNameFieldName, quickieDisplayName);
parentTermInfoArray.put(termInfo);
fields.put(parentTermGroup.getID(), parentTermInfoArray);
fields.remove("displayName");
}
}
}
path = createItem(storage, request, path, data);
data = reader.getJSON(storage, path);
String refid = data.getJSONObject("fields").getString("refid");
data.put("urn", refid);
data.getJSONObject("fields").put("urn", refid);
data.put("csid", data.getJSONObject("fields").getString("csid"));
if (quickie) {
JSONObject newdata = new JSONObject();
newdata.put("urn", refid);
newdata.put("displayName", quickieDisplayName);
data = newdata;
}
redirectpath = n.getWebURL();
}
if (this.r != null && this.n == null) {
path = createInstance(storage, request, path, data);
redirectpath = data.getJSONObject("fields").getString("shortIdentifier");
}
request.sendJSONResponse(data);
request.setOperationPerformed(create ? Operation.CREATE : Operation.UPDATE);
if (create)
request.setSecondaryRedirectPath(new String[] { redirectpath, path });
// request.setSecondaryRedirectPath(new String[]{n.getWebURL(),path});
} 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) {
UIException uiexception = new UIException(x.getMessage(), x.getStatus(), x.getUrl(), x);
request.sendJSONResponse(uiexception.getJSON());
}
}
use of org.collectionspace.csp.api.ui.UIException in project application by collectionspace.
the class VocabulariesDelete method store_delete.
private void store_delete(Storage storage, UIRequest request, String path) throws UIException {
try {
String url = n.getRecord().getID() + "/" + n.getTitleRef() + "/" + path;
JSONObject test = storage.retrieveJSON(url + "/refObjs", new JSONObject());
if (test.has("items") && (test.getJSONArray("items").length() > 0)) {
UIException uiexception = new UIException("This Vocabulary Item has Procedures associated with it");
request.sendJSONResponse(uiexception.getJSON());
return;
}
storage.deleteJSON(url);
} catch (ExistException e) {
throw new UIException("JSON Not found " + e, e);
} catch (JSONException e) {
throw new UIException("JSON Not found (malformed refObjs payload) " + 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());
}
}
use of org.collectionspace.csp.api.ui.UIException in project application by collectionspace.
the class VocabulariesRead method getJSON.
private JSONObject getJSON(Storage storage, String csid, JSONObject restriction) throws UIException {
JSONObject out = new JSONObject();
try {
String refPath = n.getRecord().getID() + "/" + n.getTitleRef() + "/";
if (getInfoMode == GET_FULL_INFO || getInfoMode == GET_BASIC_INFO) {
JSONObject fields = storage.retrieveJSON(refPath + csid, restriction);
// add in equivalent hierarchy if relevant
csid = fields.getString("csid");
fields = getHierarchy(storage, fields);
// fields.put("csid",csid);
// JSONObject relations=createRelations(storage,csid);
out.put("fields", fields);
out.put("csid", csid);
out.put("namespace", n.getWebURL());
}
if (getInfoMode == GET_FULL_INFO) {
out.put("relations", new JSONArray());
// out.put("relations",relations);
}
if (getInfoMode == GET_FULL_INFO) {
JSONObject tusd = this.termsused.getTermsUsed(storage, refPath + csid, new JSONObject());
out.put("termsUsed", tusd.getJSONArray("results"));
}
if (getInfoMode == GET_TERMS_USED_INFO) {
JSONObject tusd = this.termsused.getTermsUsed(storage, refPath + csid, restriction);
out.put("termsUsed", tusd);
}
if (getInfoMode == GET_FULL_INFO) {
getRefObjs(storage, refPath + csid, out, "refobjs", false, restriction);
} else if (getInfoMode == GET_REF_OBJS_INFO) {
getRefObjs(storage, refPath + csid, out, "items", true, restriction);
}
} 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, e);
}
return out;
}
Aggregations