Class BaseController

java.lang.Object
org.ehrbase.rest.BaseController
Direct Known Subclasses:
AdminCompositionController, AdminContributionController, AdminController, AdminDirectoryController, AdminEhrController, AdminQueryController, AdminTemplateController, OpenehrCompositionController, OpenehrContributionController, OpenehrDefinitionQueryController, OpenehrDirectoryController, OpenehrEhrController, OpenehrEhrStatusController, OpenehrQueryController, OpenehrTemplateController, OpenehrVersionedCompositionController, OpenehrVersionedEhrStatusController, StatusController

public abstract class BaseController extends Object
This base controller implements the basic functionality for all specific controllers. This includes error handling and utils.
  • Field Details

  • Constructor Details

    • BaseController

      public BaseController()
  • Method Details

    • add2MetaMap

      public Map<String,Map<String,String>> add2MetaMap(Map<String,Map<String,String>> metaMap, String key, String value)
    • getContextPath

      public String getContextPath()
    • createLocationUri

      protected URI createLocationUri(String... pathSegments)
      Returns a URI for list of segments. The segments are appended to the base path and encoded to ensure safe usage in a URI.
      Parameters:
      pathSegments - List of segments to append to the base URL
      Returns:
      URI for the given base URL and segments
    • getEhrUuid

      protected UUID getEhrUuid(String ehrIdString)
      Helper to allow string UUID input from controllers, which throws an ObjectNotFound exception when no UUID representation can be created. This case is equal to no matching object.
      Parameters:
      ehrIdString - Input String representation of the ehrId
      Returns:
      UUID representation of the ehrId
      Throws:
      ObjectNotFoundException - when no UUID can't be created from input
    • getCompositionVersionedObjectUidString

      protected UUID getCompositionVersionedObjectUidString(String compositionVersionedObjectUidString)
      Helper to allow string UUID input from controllers, which throws an ObjectNotFound exception when no UUID representation can be created. This case is equal to no matching object.
      Parameters:
      compositionVersionedObjectUidString - Input String representation
      Returns:
      UUID representation
      Throws:
      ObjectNotFoundException - when no UUID can't be created from input
    • getContributionVersionedObjectUidString

      protected UUID getContributionVersionedObjectUidString(String compositionVersionedObjectUidString)
      Helper to allow string UUID input from controllers, which throws an ObjectNotFound exception when no UUID representation can be created. This case is equal to no matching object.
      Parameters:
      compositionVersionedObjectUidString - Input String representation
      Returns:
      UUID representation
      Throws:
      ObjectNotFoundException - when no UUID can't be created from input
    • extractCompositionRepresentation

      protected CompositionRepresentation extractCompositionRepresentation(String contentType, String format)
      Extracts the CompositionRepresentation from the REST request's input MediaType style content type header string and validates them against the given format as CompositionFormat.
      Parameters:
      contentType - String representation of REST request's input MediaType style content type header
      format - String representation of the REST request format parameter that is interpreted as an CompositionFormat
      Returns:
      CompositionFormat expressing the content type
      Throws:
      NotAcceptableException - when content type or composition format is not supported or the input is invalid
    • encodePath

      public String encodePath(String path)
      Convenience helper to encode path strings to URI-safe strings
      Parameters:
      path - input
      Returns:
      URI-safe escaped string
      Throws:
      InternalServerException - when encoding failed
    • extractVersionedObjectUidFromVersionUid

      protected UUID extractVersionedObjectUidFromVersionUid(String versionUid)
      Extracts the UUID base from a versioned UID. Or, if
      Parameters:
      versionUid -
      Returns:
    • extractVersionFromVersionUid

      protected Optional<Integer> extractVersionFromVersionUid(String versionUid)
    • enrichRequestAttribute

      protected void enrichRequestAttribute(String attributeName, Object value)
      Add attribute to the current request.
      Parameters:
      attributeName -
      value -
    • resolveContentType

      protected org.springframework.http.MediaType resolveContentType(String acceptHeader)
      Resolves the Content-Type based on Accept header.
      Parameters:
      acceptHeader - Accept header value
      Returns:
      Content-Type of the response
    • resolveContentType

      protected org.springframework.http.MediaType resolveContentType(String acceptHeader, org.springframework.http.MediaType defaultMediaType)
      Resolves the Content-Type based on Accept header.
      Parameters:
      acceptHeader - Accept header value
      defaultMediaType - Default Content-Type
      Returns:
      Content-Type of the response
    • resolveContentType

      protected org.springframework.http.MediaType resolveContentType(String acceptHeader, org.springframework.http.MediaType defaultMediaType, Predicate<org.springframework.http.MediaType> isSupported)
      Resolves the Content-Type based on Accept header using the supported predicate.
      Parameters:
      acceptHeader - Accept header value
      defaultMediaType - Default Content-Type
      isSupported - Filter the supported Content-Types
      Returns:
      Content-Type of the response
    • decodeVersionAtTime

      protected static Optional<OffsetDateTime> decodeVersionAtTime(String versionAtTimeParam)