Klasse DUUIRequestHelper

java.lang.Object
org.texttechnologylab.duui.api.routes.DUUIRequestHelper

public class DUUIRequestHelper extends Object
A utility class to handle common operations on Request and Response objects.
Autor:
Cedric Borkowski
  • Konstruktorübersicht

    Konstruktoren
    Konstruktor
    Beschreibung
     
  • Methodenübersicht

    Modifizierer und Typ
    Methode
    Beschreibung
    static org.bson.Document
    authenticate(String authorization)
    Check if the provided authorization is valid and corresponds to a user.
    static String
    badRequest(spark.Response response, String message)
    Return a 400 - Bad Request Response.
    static int
    getLimit(spark.Request request)
     
    static int
    getOrder(spark.Request request, int defaultValue)
     
    static int
    getSkip(spark.Request request)
     
    static String
    getSort(spark.Request request, String defaultValue)
     
    static String
    getUserId(spark.Request request)
    At this stage user should never be null.
    static org.bson.Document
    getUserProps(spark.Request request, Set<String> included)
    At this stage user should never be null.
    static boolean
    isAuthorized(spark.Request request)
    Check if the Authorization header contains a valid API key or session.
    static boolean
    Checks if the given text is the empty string or null.
    static boolean
    Checks if the given list is of length 0 or null.
    static boolean
    isNullOrEmpty(org.bson.Document document)
    Checks if the given document has no keys or is null.
    static String
    missingField(spark.Response response, String field)
    Return a bad request response (400) to indicate a missing field.
    static String
    notFound(spark.Response response)
    Return a default 404 - Not Found Response.
    static String
    Convert each word in a string to title case.
    static String
    unauthorized(spark.Response response)
    Return a 401 - Unauthorized Response.
    static boolean
    Check if a user with the specified API key exists.
    static boolean
    Check if a user with the specified session exists.

    Von Klasse geerbte Methoden java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Konstruktordetails

    • DUUIRequestHelper

      public DUUIRequestHelper()
  • Methodendetails

    • getUserId

      public static String getUserId(spark.Request request)
      At this stage user should never be null. Get the user's ID by authentication.
      Parameter:
      request - The Spark Request object.
      Gibt zurück:
      The userID as a String.
    • getUserProps

      public static org.bson.Document getUserProps(spark.Request request, Set<String> included)
      At this stage user should never be null. Get the specified properties of the user.
      Parameter:
      request - The Spark Request object.
      Gibt zurück:
      A Document containing the requested user data.
    • notFound

      public static String notFound(spark.Response response)
      Return a default 404 - Not Found Response.
      Parameter:
      response - The Spark Response object.
      Gibt zurück:
      A 404 - Not Found message.
    • badRequest

      public static String badRequest(spark.Response response, String message)
      Return a 400 - Bad Request Response.
      Parameter:
      response - The Spark Response object.
      Gibt zurück:
      A 400 - Bad Request with a hopefully helpful message.
    • isAuthorized

      public static boolean isAuthorized(spark.Request request)
      Check if the Authorization header contains a valid API key or session.
      Parameter:
      request - The request object.
      Gibt zurück:
      if the user is authorized.
    • unauthorized

      public static String unauthorized(spark.Response response)
      Return a 401 - Unauthorized Response.
      Parameter:
      response - The response object.
      Gibt zurück:
      a message telling the request origin it's unauthorized to perform the action.
    • validateSession

      public static boolean validateSession(String session)
      Check if a user with the specified session exists.
      Parameter:
      session - The sessionId a user receives after logging in.
      Gibt zurück:
      if the sessionId is valid.
    • validateApiKey

      public static boolean validateApiKey(String key)
      Check if a user with the specified API key exists.
      Parameter:
      key - The API key a user that can be generated on the account page.
      Gibt zurück:
      if the API key is valid.
    • toTitleCase

      public static String toTitleCase(String input)
      Convert each word in a string to title case.
      Parameter:
      input - The string to be transformed
      Gibt zurück:
      A new string in title case
    • getLimit

      public static int getLimit(spark.Request request)
      Parameter:
      request - A spark requests object.
      Gibt zurück:
      the Integer value of the `limit` query parameter or 0
    • getSkip

      public static int getSkip(spark.Request request)
      Parameter:
      request - A spark requests object.
      Gibt zurück:
      the Integer value of the `skip` query parameter or 0
    • getSort

      public static String getSort(spark.Request request, String defaultValue)
      Parameter:
      request - A spark requests object.
      defaultValue - The default field name to sort by.
      Gibt zurück:
      the value of the `sort` query parameter or the default value.
    • getOrder

      public static int getOrder(spark.Request request, int defaultValue)
      Parameter:
      request - A spark requests object.
      defaultValue - The default sort order (1 = ascending, -1 = descending).
      Gibt zurück:
      the value of the `order` query parameter or the default value.
    • isNullOrEmpty

      public static boolean isNullOrEmpty(String text)
      Checks if the given text is the empty string or null.
      Parameter:
      text - The text to check.
      Gibt zurück:
      if the text is empty or null.
    • isNullOrEmpty

      public static boolean isNullOrEmpty(org.bson.Document document)
      Checks if the given document has no keys or is null.
      Parameter:
      document - The Document to check.
      Gibt zurück:
      if the document is empty or null.
    • isNullOrEmpty

      public static boolean isNullOrEmpty(List<?> list)
      Checks if the given list is of length 0 or null.
      Parameter:
      list - The List to check.
      Gibt zurück:
      if the list is empty or null.
    • missingField

      public static String missingField(spark.Response response, String field)
      Return a bad request response (400) to indicate a missing field.
      Parameter:
      response - The response object.
      field - The missing field.
      Gibt zurück:
      a standard 400 bad request response.
    • authenticate

      public static org.bson.Document authenticate(String authorization)
      Check if the provided authorization is valid and corresponds to a user.
      Parameter:
      authorization - a session id or API key.
      Gibt zurück:
      The potential user corresponding to the authorization String.