use of org.springframework.extensions.webscripts.WebScriptException in project records-management by Alfresco.
the class WebScriptUtils method putValueToJSONObject.
/**
* Puts the given key and value to the json object
*
* @param jsonObject The json object
* @param key The key
* @param value The value
*/
public static void putValueToJSONObject(JSONObject jsonObject, String key, Object value) {
mandatory("jsonObject", jsonObject);
mandatoryString("key", key);
mandatory("value", value);
try {
jsonObject.put(key, value);
} catch (JSONException error) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not put the key '" + key + "' with the value '" + value + "' to the json object.", error);
}
}
use of org.springframework.extensions.webscripts.WebScriptException in project records-management by Alfresco.
the class WebScriptUtils method getJSONArrayFromJSONObject.
/**
* Gets the {@link JSONArray} value of a given key from a json object
*
* @param jsonObject The json object
* @param key The key
* @return The {@link JSONArray} value of the given key from the json object
*/
public static JSONArray getJSONArrayFromJSONObject(JSONObject jsonObject, String key) {
JSONArray jsonArray;
mandatory("jsonObject", jsonObject);
mandatory("key", key);
try {
jsonArray = jsonObject.getJSONArray(key);
} catch (JSONException error) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not get the json array for the key '" + key + "'.", error);
}
return jsonArray;
}
use of org.springframework.extensions.webscripts.WebScriptException in project records-management by Alfresco.
the class WebScriptUtils method createJSONObject.
/**
* Creates a json object from the given {@link String}
*
* @param json The json object as {@link String}
* @return The json object created from the given {@link String}
*/
public static JSONObject createJSONObject(String json) {
mandatory("json", json);
JSONObject jsonObject;
try {
jsonObject = new JSONObject(json);
} catch (JSONException error) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Cannot create a json object from the given string '" + json + "'.", error);
}
return jsonObject;
}
use of org.springframework.extensions.webscripts.WebScriptException in project records-management by Alfresco.
the class WebScriptUtils method createJSONArray.
/**
* Creates a json array from the given {@link String}
*
* @param json The json array as {@link String}
* @return The json array created from the given {@link String}
*/
public static JSONArray createJSONArray(String json) {
mandatory("json", json);
JSONArray jsonArray;
try {
jsonArray = new JSONArray(json);
} catch (JSONException error) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Cannot create a json array from the given string '" + json + "'.", error);
}
return jsonArray;
}
use of org.springframework.extensions.webscripts.WebScriptException in project records-management by Alfresco.
the class AuditLogPost method getDestination.
/**
* Helper method to get the destination from the json object
*
* @param json The json object which was created from the request content
* @return {@link NodeRef} The destination of the audit log
*/
private NodeRef getDestination(JSONObject json) {
if (!json.has(PARAM_DESTINATION)) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Mandatory parameter '" + PARAM_DESTINATION + "' has not been supplied.");
}
String destinationParam;
try {
destinationParam = json.getString(PARAM_DESTINATION);
} catch (JSONException error) {
throw new AlfrescoRuntimeException("Error extracting 'destination' from parameter.", error);
}
if (StringUtils.isBlank(destinationParam)) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Please select a record folder.");
}
NodeRef destination = new NodeRef(destinationParam);
if (!nodeService.exists(destination)) {
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Selected node does not exist");
}
// ensure the node is a record folder
if (!RecordsManagementModel.TYPE_RECORD_FOLDER.equals(nodeService.getType(destination))) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Selected node is not a record folder");
}
// ensure the record folder is not closed
if (recordFolderService.isRecordFolderClosed(destination)) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Cannot file into a closed folder.");
}
// ensure the record folder is not cut off
if (dispositionService.isDisposableItemCutoff(destination)) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Cannot file into a cut off folder.");
}
if (logger.isDebugEnabled()) {
logger.debug("Filing audit trail as record in record folder: '" + destination + "'.");
}
return destination;
}
Aggregations