Class RestUtils

java.lang.Object
org.opencastproject.index.service.util.RestUtils

public final class RestUtils extends Object
Utils method for the Rest Endpoint implementation
  • Method Summary

    Modifier and Type
    Method
    Description
    static javax.ws.rs.core.Response
    conflictJson(com.google.gson.JsonElement json)
    Create an CONFLICT (409) response with the given JSON as body
    static org.opencastproject.util.data.Tuple<Date,Date>
    getFromAndToDateRange(String fromToDateRange)
    Parse the UTC format date range string to two Date objects to represent a range of dates.
    static String
    getJsonString(Object jsonObject)
     
    static String
    getJsonStringSilent(com.google.gson.JsonArray json)
    Get a String value from a JsonArray ignoring errors.
    static javax.ws.rs.core.Response
    notFound(String msg, Object... args)
    Create a NOT FOUND (404) response with the given messages and arguments
    static javax.ws.rs.core.Response
    notFoundJson(com.google.gson.JsonElement json)
    Create a NOT FOUND (404) response with the given JSON as body
    static javax.ws.rs.core.Response
    okJson(com.google.gson.JsonElement json)
    Create an OK (200) response with the given JSON as body
    static javax.ws.rs.core.Response
    okJsonList(List<com.google.gson.JsonObject> 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.Response
    okJsonList(List<com.google.gson.JsonObject> 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.
    static Map<String,String>
    Parse the filter to a Map
    static ArrayList<org.opencastproject.util.requests.SortCriterion>
    Parse a sort query parameter to a set of SortCriterion.
    static javax.ws.rs.core.Response
    serverErrorJson(com.google.gson.JsonElement json)
    Create an INTERNAL SERVER ERROR (500) response with the given JSON as body

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • okJson

      public static javax.ws.rs.core.Response okJson(com.google.gson.JsonElement 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.google.gson.JsonElement 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

      public static javax.ws.rs.core.Response notFound(String msg, Object... args)
      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.google.gson.JsonElement 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.google.gson.JsonElement 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.google.gson.JsonObject> 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 also okJsonList(List, Optional, Optional, long).
      Parameters:
      jsonList - The list of value to return
      offset - The result offset
      limit - The maximal list size
      total - The amount of available items in the system
      Returns:
      a Response with 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.google.gson.JsonObject> 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 return
      optOffset - The result offset (optional)
      optLimit - The maximal list size (optional)
      total - The amount of available items in the system
      Returns:
      a Response with an JSON object formatted like above as body.
      Throws:
      IllegalArgumentException - if the value list is null
    • parseSortQueryParameter

      public static ArrayList<org.opencastproject.util.requests.SortCriterion> parseSortQueryParameter(String sort) throws javax.ws.rs.WebApplicationException
      Parse a sort query parameter to a set of SortCriterion. 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

      public static org.opencastproject.util.data.Tuple<Date,Date> getFromAndToDateRange(String fromToDateRange)
      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

      public static Map<String,String> parseFilter(String filter)
      Parse the filter to a Map
      Parameters:
      filter - the filters
      Returns:
      the map of filter name and values
    • getJsonString

      public static String getJsonString(Object jsonObject)
    • getJsonStringSilent

      public static String getJsonStringSilent(com.google.gson.JsonArray json)
      Get a String value from a JsonArray ignoring errors.
      Parameters:
      json - The JsonArray to convert to a String
      Returns:
      The String representation of the JsonArray or an empty string if there was an error.