Class BaseController

java.lang.Object
org.ehrbase.rest.BaseController
Direct Known Subclasses:
AdminCompositionController, AdminContributionController, AdminController, AdminDirectoryController, AdminEhrController, 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.
Since:
1.0.0
Author:
Stefan Spiska, Jake Smolka
  • 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

      protected 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
    • extractCompositionFormat

      protected org.ehrbase.response.ehrscape.CompositionFormat extractCompositionFormat(String contentType)
      Extracts the CompositionFormat from the REST request's input MediaType style content type header string.
      Parameters:
      contentType - String representation of REST request's input MediaType style content type header
      Returns:
      CompositionFormat expressing the content type
      Throws:
      NotAcceptableException - when content type is not supported or 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 int 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
    • decodeVersionAtTime

      protected static Optional<OffsetDateTime> decodeVersionAtTime(String versionAtTimeParam)