use of org.collectionspace.csp.api.persistence.UnderlyingStorageException in project application by collectionspace.
the class ServicesRelationStorage method autocreateJSON.
@Override
public String autocreateJSON(ContextualisedStorage root, CSPRequestCredentials creds, CSPRequestCache cache, String filePath, JSONObject data, JSONObject restrictions) throws ExistException, UnimplementedException, UnderlyingStorageException {
try {
extractPaths(filePath, new String[] { "main" }, 0);
Map<String, Document> in = new HashMap<String, Document>();
Document datapath = dataToRelation(cache, null, data).toDocument();
// log.info("AUTOCREATE"+datapath.asXML());
in.put("relations_common", datapath);
ReturnedURL out = conn.getMultipartURL(RequestMethod.POST, "/relations/", in, creds, cache);
if (out.getStatus() > 299)
throw new UnderlyingStorageException("Could not add relation status=" + out.getStatus(), out.getStatus(), "/relations/");
return out.getURLTail();
} catch (ConnectionException e) {
throw new UnderlyingStorageException("Could not add relation" + e.getLocalizedMessage(), e.getStatus(), e.getUrl(), e);
} catch (JSONException e) {
throw new UnderlyingStorageException("Could not retrieve data" + e.getLocalizedMessage());
}
}
use of org.collectionspace.csp.api.persistence.UnderlyingStorageException in project application by collectionspace.
the class ServicesRelationStorage method deleteJSON.
@Override
public void deleteJSON(ContextualisedStorage root, CSPRequestCredentials creds, CSPRequestCache cache, String filePath) throws ExistException, UnimplementedException, UnderlyingStorageException {
try {
String[] parts = extractPaths(filePath, new String[] { "main" }, 1);
// log.info("DELETE"+parts[0]);
int status = conn.getNone(RequestMethod.DELETE, "/relations/" + parts[0], null, creds, cache);
if (status > 299)
throw new UnderlyingStorageException("Could not delete relation, status=" + status, status, "/relations/" + parts[0]);
} catch (ConnectionException e) {
throw new UnderlyingStorageException("Could not delete relation" + e.getLocalizedMessage(), e.getStatus(), e.getUrl(), e);
}
}
use of org.collectionspace.csp.api.persistence.UnderlyingStorageException in project application by collectionspace.
the class UserStorage method updateJSON.
@Override
public void updateJSON(ContextualisedStorage root, CSPRequestCredentials creds, CSPRequestCache cache, String filePath, JSONObject jsonObject, JSONObject restrictions) throws ExistException, UnimplementedException, UnderlyingStorageException {
try {
// XXX when CSPACE-1458 is fixed, remove the call to
// xxx_cspace1458_fix, and just pass jsonObject as this arg. (fao
// Chris or somoeone else at CARET).
jsonObject = correctPassword(jsonObject);
Document in = XmlJsonConversion.convertToXml(r, jsonObject, "common", "PUT");
// Document
// in=XmlJsonConversion.convertToXml(r,xxx_cspace1458_fix(filePath,jsonObject,creds,cache),"common");
// log.info("Sending: " + in.asXML());
ReturnedDocument doc = conn.getXMLDocument(RequestMethod.PUT, r.getServicesURL() + "/" + filePath, in, creds, cache);
// ExistException("Not found: "+r.getServicesURL()+"/"+filePath);
if (doc.getStatus() > 299 || doc.getStatus() < 200)
throw new UnderlyingStorageException("Bad response ", doc.getStatus(), r.getServicesURL() + "/" + filePath);
} catch (ConnectionException e) {
throw new UnderlyingStorageException("Service layer exception" + e.getLocalizedMessage(), e.getStatus(), e.getUrl(), e);
} catch (JSONException e) {
throw new UnimplementedException("JSONException" + e.getLocalizedMessage(), e);
}
}
use of org.collectionspace.csp.api.persistence.UnderlyingStorageException in project application by collectionspace.
the class UserStorage method autoCreateSub.
@Override
protected ReturnedURL autoCreateSub(CSPRequestCredentials creds, CSPRequestCache cache, JSONObject jsonObject, Document doc, String savePrefix, Record r) throws JSONException, UnderlyingStorageException, ConnectionException {
ReturnedURL url;
jsonObject = correctPassword(jsonObject);
jsonObject = correctScreenName(jsonObject);
jsonObject = correctUserId(jsonObject);
doc = XmlJsonConversion.convertToXml(r, jsonObject, "common", "POST");
url = conn.getURL(RequestMethod.POST, r.getServicesURL() + "/", doc, creds, cache);
if (url.getStatus() > 299 || url.getStatus() < 200)
throw new UnderlyingStorageException("Bad response ", url.getStatus(), r.getServicesURL() + "/");
return url;
}
use of org.collectionspace.csp.api.persistence.UnderlyingStorageException in project application by collectionspace.
the class UserStorage method retrieveJSON.
@Override
public JSONObject retrieveJSON(ContextualisedStorage root, CSPRequestCredentials creds, CSPRequestCache cache, String filePath, JSONObject restrictions) throws ExistException, UnimplementedException, UnderlyingStorageException {
try {
Boolean isUserRole = false;
String[] parts = filePath.split("/");
if (parts.length >= 2 && parts[1].equals("userrole")) {
isUserRole = true;
String path = r.getSpec().getRecord("userrole").getServicesURL();
int len = parts.length - 1;
int i = 0;
for (i = 0; i < len; i++) {
path = path.replace("*", parts[i]);
i++;
}
if (len >= i) {
path = path + "/" + parts[len];
} else {
path = path + "/";
}
filePath = path;
} else {
filePath = r.getServicesURL() + "/" + filePath;
}
ReturnedDocument doc = conn.getXMLDocument(RequestMethod.GET, filePath, null, creds, cache);
JSONObject out = new JSONObject();
Document xml = null;
xml = doc.getDocument();
if ((doc.getStatus() < 200 || doc.getStatus() >= 300))
throw new UnderlyingStorageException("Does not exist ", doc.getStatus(), filePath);
if (isUserRole)
out = XmlJsonConversion.convertToJson(r.getSpec().getRecord("userrole"), xml, "GET", "common", "", // XXX hardwired common section :(
"");
else
// XXX hardwired common section :(
out = XmlJsonConversion.convertToJson(r, xml, "GET", "common", "", "");
return out;
} catch (ConnectionException e) {
throw new UnderlyingStorageException("Service layer exception" + e.getLocalizedMessage(), e.getStatus(), e.getUrl(), e);
} catch (JSONException e) {
throw new UnderlyingStorageException("Service layer exception" + e.getLocalizedMessage(), e);
}
}
Aggregations