use of org.collectionspace.csp.api.persistence.UnimplementedException in project application by collectionspace.
the class AuthorizationStorage method updateJSON.
@Override
public void updateJSON(ContextualisedStorage root, CSPRequestCredentials creds, CSPRequestCache cache, String filePath, JSONObject jsonObject, JSONObject restrictions) throws ExistException, UnimplementedException, UnderlyingStorageException {
try {
Map<String, Document> parts = new HashMap<String, Document>();
Document doc = null;
for (String section : r.getServicesRecordPathKeys()) {
String path = r.getServicesRecordPath(section);
String[] record_path = path.split(":", 2);
doc = XmlJsonConversion.convertToXml(r, jsonObject, section, "PUT");
parts.put(record_path[0], doc);
}
int status = 0;
if (r.isMultipart()) {
ReturnedMultipartDocument docm = conn.getMultipartXMLDocument(RequestMethod.PUT, r.getServicesURL() + "/" + filePath, parts, creds, cache);
status = docm.getStatus();
} else {
ReturnedDocument docm = conn.getXMLDocument(RequestMethod.PUT, r.getServicesURL() + "/" + filePath, doc, creds, cache);
status = docm.getStatus();
}
if (status == 404)
throw new ExistException("Not found: " + r.getServicesURL() + "/" + filePath);
if (status > 299 || status < 200)
throw new UnderlyingStorageException("Bad response " + status, status, r.getServicesURL() + "/" + filePath);
} catch (ConnectionException e) {
throw new UnderlyingStorageException("Service layer exception", e);
} catch (JSONException e) {
throw new UnimplementedException("JSONException", e);
}
}
use of org.collectionspace.csp.api.persistence.UnimplementedException in project application by collectionspace.
the class AuthoritiesVocabulariesInitialize method initializeVocab.
private void initializeVocab(Storage storage, UIRequest request, String path) throws UIException {
try {
if (fInstance == null) {
// For now simply loop through all the instances one after the other.
for (Instance instance : r.getAllInstances()) {
log.info(instance.getID());
// does instance exist?
if (createIfMissingAuthority(storage, null, this.r, instance) == -1) {
log.warn(String.format("The currently authenticated user does not have sufficient permission to determine if the '%s' authority/term-list is properly initialized.", instance.getID()));
}
resetvocabdata(storage, request, instance);
}
} else {
log.info(fInstance.getID());
resetvocabdata(storage, request, this.fInstance);
}
} 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);
request.sendJSONResponse(uiexception.getJSON());
}
}
use of org.collectionspace.csp.api.persistence.UnimplementedException 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.persistence.UnimplementedException 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.persistence.UnimplementedException 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());
}
}
Aggregations