use of org.collectionspace.csp.api.persistence.UnderlyingStorageException 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;
}
use of org.collectionspace.csp.api.persistence.UnderlyingStorageException in project application by collectionspace.
the class VocabulariesRead method getInstance.
private JSONObject getInstance(Storage storage, 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, restriction);
if (fields.has("csid")) {
String csid = fields.getString("csid");
out.put("fields", fields);
out.put("csid", csid);
}
}
} 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;
}
use of org.collectionspace.csp.api.persistence.UnderlyingStorageException in project application by collectionspace.
the class VocabulariesWorkflowTransition method store_transition.
private void store_transition(Storage storage, UIRequest request, String path, String transition) throws UIException {
try {
String url = n.getRecord().getID() + "/" + n.getTitleRef() + "/" + path;
storage.transitionWorkflowJSON(url, transition);
} 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());
}
}
use of org.collectionspace.csp.api.persistence.UnderlyingStorageException in project application by collectionspace.
the class ServicesRelationStorage method extractPaths.
// XXX refactor
private String[] extractPaths(String in, String[] prefixes, int var) throws UnderlyingStorageException {
if (in == null)
throw new UnderlyingStorageException("null is not a path");
if (in.startsWith("/"))
in = in.substring(1);
if (in.endsWith("/"))
in = in.substring(0, in.length() - 1);
String[] split = in.split("/");
if (split.length != prefixes.length + var)
throw new UnderlyingStorageException("Path is incorrect length (should be " + (prefixes.length + var) + " but is " + split.length);
for (int i = 0; i < prefixes.length; i++) if (!prefixes[i].equals(split[i]))
throw new UnderlyingStorageException("Path component " + i + " must be " + prefixes[i] + " but is " + split[i]);
if (var == 0)
return new String[0];
String[] ret = new String[var];
System.arraycopy(split, prefixes.length, ret, 0, var);
return ret;
}
use of org.collectionspace.csp.api.persistence.UnderlyingStorageException in project application by collectionspace.
the class ServicesRelationStorage method retrieveJSON.
@Override
public JSONObject retrieveJSON(ContextualisedStorage root, CSPRequestCredentials creds, CSPRequestCache cache, String filePath, JSONObject restrictions) throws ExistException, UnimplementedException, UnderlyingStorageException {
try {
Boolean isHierarchical = false;
String[] parts = null;
if (isPathType(filePath, new String[] { "main" }, 1)) {
parts = extractPaths(filePath, new String[] { "main" }, 1);
} else if (isPathType(filePath, new String[] { "hierarchical" }, 1)) {
parts = extractPaths(filePath, new String[] { "hierarchical" }, 1);
isHierarchical = true;
}
ReturnedMultipartDocument out = conn.getMultipartXMLDocument(RequestMethod.GET, "/relations/" + parts[0], null, creds, cache);
if (out.getStatus() == 404)
throw new UnderlyingStorageException("Could not retrieve relation", out.getStatus(), "/relations/" + parts[0]);
Document doc = out.getDocument("relations_common");
if (doc == null)
throw new UnderlyingStorageException("Could not retrieve relation, missing relations_common", out.getStatus(), "/relations/" + parts[0]);
return relationToData(cache, factory.load(parts[0], doc));
} catch (ConnectionException e) {
throw new UnderlyingStorageException("Could not retrieve relation" + e.getLocalizedMessage(), e.getStatus(), e.getUrl(), e);
} catch (JaxenException e) {
throw new UnderlyingStorageException("Could not retrieve relation" + e.getLocalizedMessage(), e);
} catch (JSONException e) {
throw new UnderlyingStorageException("Could not retrieve relation" + e.getLocalizedMessage(), e);
}
}
Aggregations