Class RestUtils
java.lang.Object
org.opencastproject.index.service.util.RestUtils
Utils method for the Rest Endpoint implementation
-
Method Summary
Modifier and TypeMethodDescriptionstatic javax.ws.rs.core.ResponseconflictJson(com.entwinemedia.fn.data.json.JValue json) Create an CONFLICT (409) response with the given JSON as bodygetFromAndToDateRange(String fromToDateRange) Parse the UTC format date range string to two Date objects to represent a range of dates.static StringgetJsonString(com.entwinemedia.fn.data.json.JValue json) static StringgetJsonStringSilent(com.entwinemedia.fn.data.json.JValue json) Get aStringvalue from aJValueignoring errors.static javax.ws.rs.core.ResponseCreate a NOT FOUND (404) response with the given messages and argumentsstatic javax.ws.rs.core.ResponsenotFoundJson(com.entwinemedia.fn.data.json.JValue json) Create a NOT FOUND (404) response with the given JSON as bodystatic javax.ws.rs.core.ResponseokJson(com.entwinemedia.fn.data.json.JValue json) Create an OK (200) response with the given JSON as bodystatic javax.ws.rs.core.ResponseokJsonList(List<com.entwinemedia.fn.data.json.JValue> jsonList, int offset, int limit, long total) Return the given list of value with the standard format for JSON list value with offset, limit and total information.static javax.ws.rs.core.ResponseokJsonList(List<com.entwinemedia.fn.data.json.JValue> jsonList, Optional<Integer> optOffset, Optional<Integer> optLimit, long total) Return the given list of value with the standard format for JSON list value with offset, limit and total information.parseFilter(String filter) Parse the filter to aMapstatic ArrayList<SortCriterion> Parse a sort query parameter to a set ofSortCriterion.static javax.ws.rs.core.ResponseserverErrorJson(com.entwinemedia.fn.data.json.JValue json) Create an INTERNAL SERVER ERROR (500) response with the given JSON as bodystatic javax.ws.rs.core.StreamingOutputstream(com.entwinemedia.fn.Fx<OutputStream> out) Create a streaming response entity.
-
Method Details
-
okJson
public static javax.ws.rs.core.Response okJson(com.entwinemedia.fn.data.json.JValue json) Create an OK (200) response with the given JSON as body- Parameters:
json- the JSON string to add to the response body.- Returns:
- an OK response
-
conflictJson
public static javax.ws.rs.core.Response conflictJson(com.entwinemedia.fn.data.json.JValue json) Create an CONFLICT (409) response with the given JSON as body- Parameters:
json- the JSON string to add to the response body.- Returns:
- an OK response
-
notFound
Create a NOT FOUND (404) response with the given messages and arguments- Parameters:
msg-args-- Returns:
- a NOT FOUND response
-
notFoundJson
public static javax.ws.rs.core.Response notFoundJson(com.entwinemedia.fn.data.json.JValue json) Create a NOT FOUND (404) response with the given JSON as body- Parameters:
json- the JSON string to add to the response body.- Returns:
- a NOT FOUND response
-
serverErrorJson
public static javax.ws.rs.core.Response serverErrorJson(com.entwinemedia.fn.data.json.JValue json) Create an INTERNAL SERVER ERROR (500) response with the given JSON as body- Parameters:
json- the JSON string to add to the response body.- Returns:
- an INTERNAL SERVER ERROR response
-
okJsonList
public static javax.ws.rs.core.Response okJsonList(List<com.entwinemedia.fn.data.json.JValue> jsonList, int offset, int limit, long total) Return the given list of value with the standard format for JSON list value with offset, limit and total information. See alsookJsonList(List, Optional, Optional, long).- Parameters:
jsonList- The list of value to returnoffset- The result offsetlimit- The maximal list sizetotal- The amount of available items in the system- Returns:
- a
Responsewith an JSON object formatted like above as body. - Throws:
IllegalArgumentException- if the value list is null
-
okJsonList
public static javax.ws.rs.core.Response okJsonList(List<com.entwinemedia.fn.data.json.JValue> jsonList, Optional<Integer> optOffset, Optional<Integer> optLimit, long total) Return the given list of value with the standard format for JSON list value with offset, limit and total information. The JSON object in the response body has the following format:{ results: [ // array containing all the object from the given list ], count: 12, // The number of item returned (size of the given list) offset: 2, // The result offset (given parameter) limit: 12, // The maximal size of the list (given parameter) total: 123 // The total number of items available in the system (given parameter) }Limit and offset are optional.- Parameters:
jsonList- The list of value to returnoptOffset- The result offset (optional)optLimit- The maximal list size (optional)total- The amount of available items in the system- Returns:
- a
Responsewith an JSON object formatted like above as body. - Throws:
IllegalArgumentException- if the value list is null
-
stream
Create a streaming response entity. Pass it as an entity parameter to one of the response builder methods likeRestUtil.R.ok(Object). -
parseSortQueryParameter
public static ArrayList<SortCriterion> parseSortQueryParameter(String sort) throws javax.ws.rs.WebApplicationException Parse a sort query parameter to a set ofSortCriterion. The parameter has to be of the following form:<field name>:ASC|DESC- Parameters:
sort- the parameter string to parse (will be checked if blank)- Returns:
- a set of sort criterion, never
null - Throws:
javax.ws.rs.WebApplicationException
-
getFromAndToDateRange
Parse the UTC format date range string to two Date objects to represent a range of dates.Sample UTC date range format string:
i.e. yyyy-MM-ddTHH:mm:ssZ/yyyy-MM-ddTHH:mm:ssZ e.g. 2014-09-27T16:25Z/2014-09-27T17:55Z- Parameters:
fromToDateRange- The string that represents the UTC formed date range.- Returns:
- A Tuple with the two Dates
- Throws:
IllegalArgumentException- Thrown if the input string is malformed
-
parseFilter
Parse the filter to aMap- Parameters:
filter- the filters- Returns:
- the map of filter name and values
-
getJsonString
public static String getJsonString(com.entwinemedia.fn.data.json.JValue json) throws javax.ws.rs.WebApplicationException, IOException - Throws:
javax.ws.rs.WebApplicationExceptionIOException
-
getJsonStringSilent
Get aStringvalue from aJValueignoring errors.
-