Package utils.common
Class Helpers
- java.lang.Object
-
- utils.common.Helpers
-
public class Helpers extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description Helpers()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.RunnabledeleteFile(java.nio.file.Path file)static java.lang.StringgetDateTimeYyyyMMddHHmmss()static java.util.Map<java.lang.String,java.lang.String>getJatosConfig()static java.util.Map<java.lang.String,java.lang.String>getJVMInfo()static java.lang.StringgetLocalIpAddress()static java.util.Map<java.lang.String,java.lang.String>getOSInfo()static java.lang.StringgetQueryParameter(play.mvc.Http.Request request, java.lang.String parameter)Gets the value of to the given parameter in request's query string and trims whitespace.static java.lang.StringgetQueryString(play.mvc.Http.Request request)Returns the whole query string of the given Request including '?'.static intgetStringSize(java.lang.String str)Gets the number of bytes in UTF-8 the given string hasstatic java.lang.StringhumanReadableByteCount(long bytes)static java.lang.StringhumanReadableDuration(java.time.Duration duration)static voidinitializeAndUnproxy(java.lang.Object... objs)Initialize all given objects that are loaded lazily in a Hibernate objectstatic <T> TinitializeAndUnproxy(T obj)Initialize an object that is loaded lazily in a Hibernate objectstatic java.lang.BooleanisAjax()Check if the request was made via Ajax or not.static booleanisAllowedSuperuser(User user)static booleanisApiRequest(play.mvc.Http.Request request)Checks if the HTTP request has an "Authorization: Bearer" header.static booleanisHtmlRequest(play.mvc.Http.RequestHeader request)static booleanisSessionCookieRequest(play.mvc.Http.Request request)Checks if the session has a field 'username'static akka.stream.javadsl.Source<akka.util.ByteString,java.util.concurrent.CompletionStage<akka.stream.IOResult>>okFileStreamed(java.nio.file.Path file, java.lang.Runnable handler)Helper function to allow an action after a file was sent (e.g.static java.util.Optional<java.lang.Long>parseLong(java.lang.String str)static java.lang.StringurlDecode(java.lang.String str)static java.lang.StringurlEncode(java.lang.String str)
-
-
-
Method Detail
-
isAjax
public static java.lang.Boolean isAjax()
Check if the request was made via Ajax or not.
-
isHtmlRequest
public static boolean isHtmlRequest(play.mvc.Http.RequestHeader request)
-
isSessionCookieRequest
public static boolean isSessionCookieRequest(play.mvc.Http.Request request)
Checks if the session has a field 'username'
-
isApiRequest
public static boolean isApiRequest(play.mvc.Http.Request request)
Checks if the HTTP request has an "Authorization: Bearer" header. This does not check any authentication.
-
getLocalIpAddress
public static java.lang.String getLocalIpAddress()
-
urlEncode
public static java.lang.String urlEncode(java.lang.String str)
-
urlDecode
public static java.lang.String urlDecode(java.lang.String str)
-
getQueryParameter
public static java.lang.String getQueryParameter(play.mvc.Http.Request request, java.lang.String parameter)Gets the value of to the given parameter in request's query string and trims whitespace.
-
getQueryString
public static java.lang.String getQueryString(play.mvc.Http.Request request)
Returns the whole query string of the given Request including '?'. Checks for HTML tags to prevent XSS attacks.
-
humanReadableByteCount
public static java.lang.String humanReadableByteCount(long bytes)
-
getJVMInfo
public static java.util.Map<java.lang.String,java.lang.String> getJVMInfo()
-
getOSInfo
public static java.util.Map<java.lang.String,java.lang.String> getOSInfo()
-
getJatosConfig
public static java.util.Map<java.lang.String,java.lang.String> getJatosConfig()
-
humanReadableDuration
public static java.lang.String humanReadableDuration(java.time.Duration duration)
-
getDateTimeYyyyMMddHHmmss
public static java.lang.String getDateTimeYyyyMMddHHmmss()
-
initializeAndUnproxy
public static void initializeAndUnproxy(java.lang.Object... objs)
Initialize all given objects that are loaded lazily in a Hibernate object
-
initializeAndUnproxy
public static <T> T initializeAndUnproxy(T obj)
Initialize an object that is loaded lazily in a Hibernate object
-
isAllowedSuperuser
public static boolean isAllowedSuperuser(User user)
-
okFileStreamed
public static akka.stream.javadsl.Source<akka.util.ByteString,java.util.concurrent.CompletionStage<akka.stream.IOResult>> okFileStreamed(java.nio.file.Path file, java.lang.Runnable handler)Helper function to allow an action after a file was sent (e.g. delete the file)
-
deleteFile
public static java.lang.Runnable deleteFile(java.nio.file.Path file)
-
parseLong
public static java.util.Optional<java.lang.Long> parseLong(java.lang.String str)
-
getStringSize
public static int getStringSize(java.lang.String str)
Gets the number of bytes in UTF-8 the given string has
-
-