Package utils.common

Class 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.Runnable deleteFile​(java.nio.file.Path file)  
      static java.lang.String getDateTimeYyyyMMddHHmmss()  
      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.String getLocalIpAddress()  
      static java.util.Map<java.lang.String,​java.lang.String> getOSInfo()  
      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.
      static java.lang.String getQueryString​(play.mvc.Http.Request request)
      Returns the whole query string of the given Request including '?'.
      static int getStringSize​(java.lang.String str)
      Gets the number of bytes in UTF-8 the given string has
      static java.lang.String humanReadableByteCount​(long bytes)  
      static java.lang.String humanReadableDuration​(java.time.Duration duration)  
      static void initializeAndUnproxy​(java.lang.Object... objs)
      Initialize all given objects that are loaded lazily in a Hibernate object
      static <T> T initializeAndUnproxy​(T obj)
      Initialize an object that is loaded lazily in a Hibernate object
      static java.lang.Boolean isAjax()
      Check if the request was made via Ajax or not.
      static boolean isAllowedSuperuser​(User user)  
      static boolean isApiRequest​(play.mvc.Http.Request request)
      Checks if the HTTP request has an "Authorization: Bearer" header.
      static boolean isHtmlRequest​(play.mvc.Http.RequestHeader request)  
      static boolean isSessionCookieRequest​(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.String urlDecode​(java.lang.String str)  
      static java.lang.String urlEncode​(java.lang.String str)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Helpers

        public Helpers()
    • 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