Package services.gui

Class ApiService


  • @Singleton
    public class ApiService
    extends java.lang.Object
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.nio.file.Path extractFile​(play.mvc.Http.Request request, java.lang.String filePartName, java.util.List<java.lang.String> allowedRawTypes)
      Extracts a file from the request body.
      boolean getActiveFlagFromJson​(com.fasterxml.jackson.databind.JsonNode json)  
      java.nio.file.Path getAssetsFilePath​(java.lang.String filepath, java.lang.String filename, Study study)
      Get a Path to a file in a study assets directory.
      <T> T getFieldFromJson​(com.fasterxml.jackson.databind.JsonNode json, java.lang.String fieldName, java.lang.Class<T> fieldType)  
      <T> T getFieldFromJson​(com.fasterxml.jackson.databind.JsonNode json, java.lang.String fieldName, java.lang.Class<T> fieldType, T defaultValue)  
      com.fasterxml.jackson.databind.JsonNode getJsonFromBody​(play.mvc.Http.Request request)
      Controller method needs to be annotated with @BodyParser.Of(BodyParser.Raw.class) for this method to work properly
      java.lang.String getSessionDataFromBody​(play.mvc.Http.Request request)
      Controller method needs to be annotated with @BodyParser.Of(BodyParser.Raw.class) for this method to work properly
      com.fasterxml.jackson.databind.node.ObjectNode getSessionNode​(java.lang.String sessionData, java.lang.Long version, boolean asText)  
      com.fasterxml.jackson.databind.node.ObjectNode normalizeJsonInputField​(com.fasterxml.jackson.databind.JsonNode json, java.lang.String fieldName)
      Normalizes the field with the name 'fieldName' within a JSON object by converting it to a serialized JSON string if the field is an object or an array.
      void validateProps​(play.data.validation.Constraints.Validatable<java.util.List<play.data.validation.ValidationError>> props)  
      • Methods inherited from class java.lang.Object

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

      • validateProps

        public void validateProps​(play.data.validation.Constraints.Validatable<java.util.List<play.data.validation.ValidationError>> props)
                           throws BadRequestException
        Throws:
        BadRequestException
      • getFieldFromJson

        public <T> T getFieldFromJson​(com.fasterxml.jackson.databind.JsonNode json,
                                      java.lang.String fieldName,
                                      java.lang.Class<T> fieldType)
                               throws BadRequestException
        Throws:
        BadRequestException
      • getFieldFromJson

        public <T> T getFieldFromJson​(com.fasterxml.jackson.databind.JsonNode json,
                                      java.lang.String fieldName,
                                      java.lang.Class<T> fieldType,
                                      T defaultValue)
                               throws BadRequestException
        Throws:
        BadRequestException
      • getJsonFromBody

        public com.fasterxml.jackson.databind.JsonNode getJsonFromBody​(play.mvc.Http.Request request)
                                                                throws BadRequestException,
                                                                       com.fasterxml.jackson.core.JsonProcessingException
        Controller method needs to be annotated with @BodyParser.Of(BodyParser.Raw.class) for this method to work properly
        Throws:
        BadRequestException
        com.fasterxml.jackson.core.JsonProcessingException
      • getSessionDataFromBody

        public java.lang.String getSessionDataFromBody​(play.mvc.Http.Request request)
                                                throws com.fasterxml.jackson.core.JsonProcessingException
        Controller method needs to be annotated with @BodyParser.Of(BodyParser.Raw.class) for this method to work properly
        Throws:
        com.fasterxml.jackson.core.JsonProcessingException
      • normalizeJsonInputField

        public com.fasterxml.jackson.databind.node.ObjectNode normalizeJsonInputField​(com.fasterxml.jackson.databind.JsonNode json,
                                                                                      java.lang.String fieldName)
                                                                               throws BadRequestException,
                                                                                      com.fasterxml.jackson.core.JsonProcessingException
        Normalizes the field with the name 'fieldName' within a JSON object by converting it to a serialized JSON string if the field is an object or an array. If the JSON object has a field 'jsonData' (deprecated name), this is used instead. If the field is missing or already a string, no changes are made.
        Throws:
        BadRequestException
        com.fasterxml.jackson.core.JsonProcessingException
      • extractFile

        public java.nio.file.Path extractFile​(play.mvc.Http.Request request,
                                              java.lang.String filePartName,
                                              java.util.List<java.lang.String> allowedRawTypes)
                                       throws BadRequestException,
                                              java.io.IOException
        Extracts a file from the request body. It can handle different content type headers. It always tries "multipart/form-data". Additionally, it tries all content types in the list "allowedRawTypes".
        Throws:
        BadRequestException
        java.io.IOException
      • getSessionNode

        public com.fasterxml.jackson.databind.node.ObjectNode getSessionNode​(java.lang.String sessionData,
                                                                             java.lang.Long version,
                                                                             boolean asText)
                                                                      throws com.fasterxml.jackson.core.JsonProcessingException
        Throws:
        com.fasterxml.jackson.core.JsonProcessingException
      • getAssetsFilePath

        public java.nio.file.Path getAssetsFilePath​(java.lang.String filepath,
                                                    java.lang.String filename,
                                                    Study study)
                                             throws BadRequestException
        Get a Path to a file in a study assets directory.
        Parameters:
        filepath - Filepath to the file. If it points to a directory (indicated by a trailing '/'), the returned Path consists of filepath + filename. If it does not point to a directory, it is treated as a path to a file and returned without taken the filename parameter into account. This can be used to rename a file. This parameter is optional and can be null to signal the path to the file is supposed to be in the root of the study assets directory. Another option to signal the root is a single '/'. A leading '/' gets removed. It can be URL encoded but doesn't have to be.
        filename - Filename of the file (without a path).
        study - Study where the study assets belong to
        Returns:
        Path to the file in the study assets
        Throws:
        BadRequestException