Klasse DUUIRequestHelper
java.lang.Object
org.texttechnologylab.duui.api.routes.DUUIRequestHelper
A utility class to handle common operations on 
Request and Response objects.- Autor:
- Cedric Borkowski
- 
KonstruktorübersichtKonstruktoren
- 
MethodenübersichtModifizierer und TypMethodeBeschreibungstatic org.bson.Documentauthenticate(String authorization) Check if the provided authorization is valid and corresponds to a user.static StringbadRequest(spark.Response response, String message) Return a 400 - Bad Request Response.static intgetLimit(spark.Request request) static intgetOrder(spark.Request request, int defaultValue) static intgetSkip(spark.Request request) static Stringstatic StringgetUserId(spark.Request request) At this stage user should never be null.static org.bson.DocumentgetUserProps(spark.Request request, Set<String> included) At this stage user should never be null.static booleanisAuthorized(spark.Request request) Check if the Authorization header contains a valid API key or session.static booleanisNullOrEmpty(String text) Checks if the given text is the empty string or null.static booleanisNullOrEmpty(List<?> list) Checks if the given list is of length 0 or null.static booleanisNullOrEmpty(org.bson.Document document) Checks if the given document has no keys or is null.static StringmissingField(spark.Response response, String field) Return a bad request response (400) to indicate a missing field.static StringnotFound(spark.Response response) Return a default 404 - Not Found Response.static StringtoTitleCase(String input) Convert each word in a string to title case.static Stringunauthorized(spark.Response response) Return a 401 - Unauthorized Response.static booleanvalidateApiKey(String key) Check if a user with the specified API key exists.static booleanvalidateSession(String session) Check if a user with the specified session exists.
- 
Konstruktordetails- 
DUUIRequestHelperpublic DUUIRequestHelper()
 
- 
- 
Methodendetails- 
getUserIdAt 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.
 
- 
getUserPropsAt 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.
 
- 
notFoundReturn a default 404 - Not Found Response.- Parameter:
- response- The Spark Response object.
- Gibt zurück:
- A 404 - Not Found message.
 
- 
badRequestReturn a 400 - Bad Request Response.- Parameter:
- response- The Spark Response object.
- Gibt zurück:
- A 400 - Bad Request with a hopefully helpful message.
 
- 
isAuthorizedpublic 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.
 
- 
unauthorizedReturn 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.
 
- 
validateSessionCheck 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.
 
- 
validateApiKeyCheck 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.
 
- 
toTitleCaseConvert each word in a string to title case.- Parameter:
- input- The string to be transformed
- Gibt zurück:
- A new string in title case
 
- 
getLimitpublic static int getLimit(spark.Request request) - Parameter:
- request- A spark requests object.
- Gibt zurück:
- the Integervalue of the `limit` query parameter or 0
 
- 
getSkippublic static int getSkip(spark.Request request) - Parameter:
- request- A spark requests object.
- Gibt zurück:
- the Integervalue of the `skip` query parameter or 0
 
- 
getSort- 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.
 
- 
getOrderpublic 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.
 
- 
isNullOrEmptyChecks 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.
 
- 
isNullOrEmptypublic static boolean isNullOrEmpty(org.bson.Document document) Checks if the given document has no keys or is null.- Parameter:
- document- The- Documentto check.
- Gibt zurück:
- if the document is empty or null.
 
- 
isNullOrEmptyChecks if the given list is of length 0 or null.- Parameter:
- list- The- Listto check.
- Gibt zurück:
- if the list is empty or null.
 
- 
missingFieldReturn 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.
 
- 
authenticateCheck 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.
 
 
-