use of org.collectionspace.csp.api.ui.UIException 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.ui.UIException 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.ui.UIException in project application by collectionspace.
the class WebTermList method termlist.
private void termlist(CSPRequestCache cache, Storage storage, UIRequest request, String path) throws UIException {
try {
// {tenant}/{tenantname}/{recordType}/termList/{termListType}
// needs to be {tenant}/{tenantname}/{recordType}/termList/{fieldname}
// as blanks etc are on a field basis not a vocab basis
String[] bits = path.split("/");
Record vb = this.spec.getRecord("vocab");
Field f = (Field) r.getFieldTopLevel(bits[0]);
if (f == null) {
f = (Field) r.getFieldFullList(bits[0]);
}
// If the field isn't in this record, look for it in subrecords (e.g. contacts).
if (f == null) {
FieldSet[] subRecordFields = r.getAllSubRecords("GET");
for (int i = 0; i < subRecordFields.length; i++) {
FieldSet subRecordField = subRecordFields[i];
Group group = (Group) subRecordField;
if (group.usesRecord()) {
Record subRecord = group.usesRecordId();
f = (Field) subRecord.getFieldTopLevel(bits[0]);
if (f == null) {
f = (Field) subRecord.getFieldFullList(bits[0]);
}
if (f != null) {
break;
}
}
}
}
JSONArray result = new JSONArray();
if (f.getAllAutocompleteInstances() != null && f.getAllAutocompleteInstances()[0] != null) {
for (Instance ins : f.getAllAutocompleteInstances()) {
JSONArray getallnames = ctl.get(storage, ins.getTitleRef(), vb);
for (int i = 0; i < getallnames.length(); i++) {
result.put(getallnames.get(i));
}
}
} else {
String msg = String.format("Dynamic term list(s) (aka, \"autocomplete\" list) for the field '%s' of record '%s' does not exist. Check that it is defined in the Application layer configuration.", f.toString(), r.whoamI);
log.error(msg);
}
JSONObject out = generateENUMField(storage, f, result, false);
request.sendJSONResponse(out);
int cacheMaxAgeSeconds = spec.getAdminData().getTermListCacheAge();
if (cacheMaxAgeSeconds > 0) {
request.setCacheMaxAgeSeconds(cacheMaxAgeSeconds);
}
} catch (JSONException e) {
throw new UIException("JSONException during autocompletion", e);
}
}
use of org.collectionspace.csp.api.ui.UIException in project application by collectionspace.
the class CompositeWebUIRequestPart method getPostBody.
@Override
public JSONObject getPostBody() throws UIException {
JSONObject jsondata = new JSONObject();
String jsonString = body_in;
try {
if (jsonString.length() > 0) {
String[] data = jsonString.split("&");
for (String item : data) {
String[] itembits = item.split("=");
jsondata.put(URLDecoder.decode(itembits[0], "UTF-8"), URLDecoder.decode(itembits[1], "UTF-8"));
}
}
} catch (JSONException e) {
throw new UIException("Cannot get request body, JSONException", e);
} catch (UnsupportedEncodingException e) {
throw new UIException("Cannot get request body, UnsupportedEncodingException", e);
}
return jsondata;
}
use of org.collectionspace.csp.api.ui.UIException in project application by collectionspace.
the class CompositeWebUIRequestPart method sendUnknown.
@Override
public void sendUnknown(byte[] data, String contenttype, String contentDisposition) throws UIException {
mime_type_out = contenttype;
try {
body_out.write(data);
body_out.flush();
} catch (IOException e) {
throw new UIException("Could not write data", e);
}
}
Aggregations