use of org.collectionspace.csp.api.persistence.UnimplementedException in project application by collectionspace.
the class VocabulariesRead method getRefObjs.
/**
* Returns all the objects that are linked to a vocabulary item
* @param storage
* @param path
* @return
* @throws ExistException
* @throws UnimplementedException
* @throws UnderlyingStorageException
* @throws JSONException
*/
@SuppressWarnings("unchecked")
private void getRefObjs(Storage storage, String path, JSONObject out, String itemsKey, boolean addPagination, JSONObject restrictions) throws JSONException {
JSONArray items = new JSONArray();
try {
JSONObject refObjs = storage.retrieveJSON(path + "/refObjs", restrictions);
if (refObjs != null) {
if (refObjs.has("items")) {
JSONArray ritems = refObjs.getJSONArray("items");
for (int i = 0; i < ritems.length(); i++) {
JSONObject in = ritems.getJSONObject(i);
// JSONObject in=ritems.getJSONObject(field);
String rt = in.getString("sourceFieldType");
Record rec = this.spec.getRecordByServicesDocType(rt);
// as the key.
if (rec == null) {
if (in.has("summarylist")) {
JSONObject summaryList = in.getJSONObject("summarylist");
if (summaryList.has("uri")) {
String uri = summaryList.getString("uri");
if (Tools.notBlank(uri)) {
String recordtypekey = uri.split("/")[0];
if (Tools.notBlank(recordtypekey)) {
rec = this.spec.getRecordByServicesUrl(recordtypekey);
}
}
}
}
}
String uiname;
if (rec != null) {
uiname = rec.getWebURL();
if (rec.isType("authority")) {
// Need to add namespace for authorities
String refName = null;
if (in.has("refName")) {
refName = in.getString("refName");
} else if (in.has("summarylist")) {
JSONObject summList = in.getJSONObject("summarylist");
if (summList.has("refName")) {
refName = summList.getString("refName");
}
}
if (refName != null) {
RefName.AuthorityItem item = RefName.AuthorityItem.parse(refName);
in.put("namespace", item.getParentShortIdentifier());
}
}
} else {
uiname = rt;
}
in.put("recordtype", uiname);
/*
JSONObject entry=new JSONObject();
entry.put("csid",in.getString("csid"));
entry.put("recordtype",in.getString("sourceFieldType"));
entry.put("sourceFieldName",field);
entry.put("number",in.getString("sourceFieldName"));
*/
items.put(in);
}
}
out.put(itemsKey, items);
if (addPagination && refObjs.has("pagination")) {
out.put("pagination", refObjs.get("pagination"));
}
}
} catch (JSONException ex) {
log.debug("JSONException" + ex.getLocalizedMessage());
// wordlessly eat the errors at the moment as they might be permission errors
} catch (ExistException e) {
log.debug("ExistException" + e.getLocalizedMessage());
// wordlessly eat the errors at the moment as they might be permission errors
} catch (UnimplementedException e) {
log.debug("UnimplementedException" + e.getLocalizedMessage());
// wordlessly eat the errors at the moment as they might be permission errors
} catch (UnderlyingStorageException e) {
log.debug("UnderlyingStorageException" + e.getLocalizedMessage());
// wordlessly eat the errors at the moment as they might be permission errors
}
}
use of org.collectionspace.csp.api.persistence.UnimplementedException 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.UnimplementedException 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.UnimplementedException 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.UnimplementedException 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);
}
}
Aggregations