Class BaseController

java.lang.Object
org.ehrbase.rest.BaseController
Direct Known Subclasses:
AdminCompositionController, AdminContributionController, AdminController, AdminDirectoryController, AdminEhrController, AdminQueryController, AdminTemplateController, ItemTagController, 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

    • 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
    • parseUUID

      protected UUID parseUUID(String uuidString, String error)
      Helper to parse an input UUID int string format.
      Parameters:
      uuidString - to parse
      error - to raise in case the given UUID string is invalid
      Returns:
      uuid parse from the input uuidString
      Throws:
      InvalidApiParameterException - when the given uuidString is invalid
    • 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
    • extractVersionedObjectUidFromVersionUid

      protected UUID extractVersionedObjectUidFromVersionUid(String versionUid)
      Extracts the UUID base from a versioned UID. Or, if
      Parameters:
      versionUid - raw versionUid in format [UUID]::[VERSION]
      Returns:
      uuid [UUID] part
    • extractVersionFromVersionUid

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

      protected org.springframework.http.MediaType resolveContentType(String acceptHeader)
      Resolves the Content-Type based on Accept header. Validates if the given acceptHeader in either application/json or application/xml. In case acceptHeader is given application/json will be selected as a default.
      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, org.springframework.http.MediaType... supportedMediaTypes)
      Resolves the Content-Type based on Accept header using the supported predicate.
      Parameters:
      acceptHeader - Accept header value
      defaultMediaType - Default Content-Type
      supportedMediaTypes - supported Content-Types
      Returns:
      Content-Type of the response
    • decodeVersionAtTime

      protected static Optional<OffsetDateTime> decodeVersionAtTime(String versionAtTimeParam)