Class BaseController
- java.lang.Object
-
- org.ehrbase.rest.openehr.controller.BaseController
-
- Direct Known Subclasses:
OpenehrCompositionController,OpenehrContributionController,OpenehrDefinitionQueryController,OpenehrDirectoryController,OpenehrEhrController,OpenehrEhrStatusController,OpenehrQueryController,OpenehrTemplateController,OpenehrVersionedEhrStatusController
public abstract class BaseController extends Object
This base controller implements the basic functionality for all specific controllers. This includes error handling and utils.
-
-
Constructor Summary
Constructors Constructor Description BaseController()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Map<String,Map<String,String>>add2MetaMap(Map<String,Map<String,String>> metaMap, String key, String value)protected org.springframework.http.ResponseEntity<Map<String,String>>createErrorResponse(String message, org.springframework.http.HttpStatus status)StringencodePath(String path)Convenience helper to encode path strings to URI-safe stringsprotected CompositionFormatextractCompositionFormat(String contentType)Extracts theCompositionFormatfrom the REST request's inputMediaTypestyle content type header string.protected org.springframework.http.MediaTypeextractMediaType(String accept)protected UUIDextractVersionedObjectUidFromVersionUid(String versionUid)Extracts the UUID base from a versioned UID.protected intextractVersionFromVersionUid(String versionUid)protected StringgetBaseEnvLinkURL()protected UUIDgetCompositionVersionedObjectUidString(String compositionVersionedObjectUidString)Helper to allow string UUID input from controllers, which throws an ObjectNotFound exception when no UUID representation can be created.protected UUIDgetContributionVersionedObjectUidString(String compositionVersionedObjectUidString)Helper to allow string UUID input from controllers, which throws an ObjectNotFound exception when no UUID representation can be created.protected UUIDgetEhrUuid(String ehrIdString)Helper to allow string UUID input from controllers, which throws an ObjectNotFound exception when no UUID representation can be created.org.springframework.http.ResponseEntity<Map<String,String>>restErrorHandler(Exception e)Fallback error handler.org.springframework.http.ResponseEntity<Map<String,String>>restErrorHandler(IllegalArgumentException e)Deprecated.Throw a more specific exception.org.springframework.http.ResponseEntity<Map<String,String>>restErrorHandler(BadGatewayException e)Handler for project-custom exception.org.springframework.http.ResponseEntity<Map<String,String>>restErrorHandler(DuplicateObjectException e)Handler for project-custom exception.org.springframework.http.ResponseEntity<Map<String,String>>restErrorHandler(GeneralRequestProcessingException e)Handler for project-custom exception.org.springframework.http.ResponseEntity<Map<String,String>>restErrorHandler(InternalServerException e)Handler for less specific internal errororg.springframework.http.ResponseEntity<Map<String,String>>restErrorHandler(InvalidApiParameterException e)Handler for project-custom exception.org.springframework.http.ResponseEntity<Map<String,String>>restErrorHandler(NotAcceptableException e)Handler for project-custom exception.org.springframework.http.ResponseEntity<Map<String,String>>restErrorHandler(ObjectNotFoundException e)Handler for project-custom exception.org.springframework.http.ResponseEntity<Map<String,String>>restErrorHandler(PreconditionFailedException e)Handler for project-custom exception.org.springframework.http.ResponseEntity<Map<String,String>>restErrorHandler(StateConflictException e)Handler for project-custom exception.org.springframework.http.ResponseEntity<Map<String,String>>restErrorHandler(UnprocessableEntityException e)Handler for project-custom exception.org.springframework.http.ResponseEntity<Map<String,String>>restErrorHandler(UnsupportedMediaTypeException e)Handler for all exceptions that are caused by a payload that cannot be processed by a service or subordinated handlers.org.springframework.http.ResponseEntity<Map<String,String>>restErrorHandler(ValidationException e)Handler for validation errorsorg.springframework.http.ResponseEntity<Map<String,String>>restErrorHandler(org.springframework.http.converter.HttpMessageNotReadableException e)This handler catches the exception automatically generated and thrown by the framework, when the request's message can't be read.org.springframework.http.ResponseEntity<Map<String,String>>restErrorHandler(org.springframework.web.bind.MissingServletRequestParameterException e)This handler catches the exception automatically generated and thrown by the framework, when specified parameters are not present or matching.
-
-
-
Method Detail
-
add2MetaMap
public Map<String,Map<String,String>> add2MetaMap(Map<String,Map<String,String>> metaMap, String key, String value)
-
getBaseEnvLinkURL
protected String getBaseEnvLinkURL()
-
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 CompositionFormat extractCompositionFormat(String contentType)
Extracts theCompositionFormatfrom the REST request's inputMediaTypestyle content type header string.- Parameters:
contentType- String representation of REST request's inputMediaTypestyle content type header- Returns:
CompositionFormatexpressing the content type- Throws:
NotAcceptableException- when content type is not supported or input is invalid
-
extractMediaType
protected org.springframework.http.MediaType extractMediaType(String accept)
-
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
-
createErrorResponse
protected org.springframework.http.ResponseEntity<Map<String,String>> createErrorResponse(String message, org.springframework.http.HttpStatus status)
-
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)
-
restErrorHandler
@ExceptionHandler(org.ehrbase.api.exception.DuplicateObjectException.class) public org.springframework.http.ResponseEntity<Map<String,String>> restErrorHandler(DuplicateObjectException e)
Handler for project-custom exception.- Returns:
- ResponseEntity
-
restErrorHandler
@Deprecated @ExceptionHandler(java.lang.IllegalArgumentException.class) public org.springframework.http.ResponseEntity<Map<String,String>> restErrorHandler(IllegalArgumentException e)
Deprecated.Throw a more specific exception.Handler for broad and general Java standard exception IllegalArgumentException. Shall be replaced with a more specific exception like InvalidApiParameterException in backend code with time.- Returns:
- ResponseEntity
-
restErrorHandler
@ExceptionHandler(org.ehrbase.api.exception.GeneralRequestProcessingException.class) public org.springframework.http.ResponseEntity<Map<String,String>> restErrorHandler(GeneralRequestProcessingException e)
Handler for project-custom exception.- Returns:
- ResponseEntity
-
restErrorHandler
@ExceptionHandler(org.ehrbase.api.exception.InvalidApiParameterException.class) public org.springframework.http.ResponseEntity<Map<String,String>> restErrorHandler(InvalidApiParameterException e)
Handler for project-custom exception.- Returns:
- ResponseEntity
-
restErrorHandler
@ExceptionHandler(org.springframework.web.bind.MissingServletRequestParameterException.class) public org.springframework.http.ResponseEntity<Map<String,String>> restErrorHandler(org.springframework.web.bind.MissingServletRequestParameterException e)
This handler catches the exception automatically generated and thrown by the framework, when specified parameters are not present or matching.- Returns:
- ResponseEntity
-
restErrorHandler
@ExceptionHandler(org.springframework.http.converter.HttpMessageNotReadableException.class) public org.springframework.http.ResponseEntity<Map<String,String>> restErrorHandler(org.springframework.http.converter.HttpMessageNotReadableException e)
This handler catches the exception automatically generated and thrown by the framework, when the request's message can't be read. For example, due to missing body, while required.- Returns:
- ResponseEntity
-
restErrorHandler
@ExceptionHandler(org.ehrbase.api.exception.ObjectNotFoundException.class) public org.springframework.http.ResponseEntity<Map<String,String>> restErrorHandler(ObjectNotFoundException e)
Handler for project-custom exception.- Returns:
- ResponseEntity
-
restErrorHandler
@ExceptionHandler(org.ehrbase.api.exception.NotAcceptableException.class) public org.springframework.http.ResponseEntity<Map<String,String>> restErrorHandler(NotAcceptableException e)
Handler for project-custom exception.- Returns:
- ResponseEntity
-
restErrorHandler
@ExceptionHandler(org.ehrbase.api.exception.StateConflictException.class) public org.springframework.http.ResponseEntity<Map<String,String>> restErrorHandler(StateConflictException e)
Handler for project-custom exception.- Returns:
- ResponseEntity
-
restErrorHandler
@ExceptionHandler(org.ehrbase.api.exception.PreconditionFailedException.class) public org.springframework.http.ResponseEntity<Map<String,String>> restErrorHandler(PreconditionFailedException e)
Handler for project-custom exception.- Returns:
- ResponseEntity
-
restErrorHandler
@ExceptionHandler(org.ehrbase.api.exception.UnsupportedMediaTypeException.class) public org.springframework.http.ResponseEntity<Map<String,String>> restErrorHandler(UnsupportedMediaTypeException e)
Handler for all exceptions that are caused by a payload that cannot be processed by a service or subordinated handlers.- Parameters:
e- - UnsupportedMediaTypeException thrown at handler mechanism- Returns:
- ResponseEntity
-
restErrorHandler
@ExceptionHandler(org.ehrbase.api.exception.UnprocessableEntityException.class) public org.springframework.http.ResponseEntity<Map<String,String>> restErrorHandler(UnprocessableEntityException e)
Handler for project-custom exception.- Returns:
- ResponseEntity
-
restErrorHandler
@ExceptionHandler(org.ehrbase.api.exception.InternalServerException.class) public org.springframework.http.ResponseEntity<Map<String,String>> restErrorHandler(InternalServerException e)
Handler for less specific internal error- Returns:
- ResponseEntity
-
restErrorHandler
@ExceptionHandler(org.ehrbase.api.exception.BadGatewayException.class) public org.springframework.http.ResponseEntity<Map<String,String>> restErrorHandler(BadGatewayException e)
Handler for project-custom exception.- Returns:
- ResponseEntity
-
restErrorHandler
@ExceptionHandler(org.ehrbase.api.exception.ValidationException.class) public org.springframework.http.ResponseEntity<Map<String,String>> restErrorHandler(ValidationException e)
Handler for validation errors- Returns:
- ResponseEntity
-
restErrorHandler
@ExceptionHandler(java.lang.Exception.class) public org.springframework.http.ResponseEntity<Map<String,String>> restErrorHandler(Exception e)
Fallback error handler.- Returns:
- ResponseEntity
-
-