# Class CACommandContext<E extends CAProtocolMessageType>

java.lang.Object
com.io7m.cardant.server.controller.command_exec.CACommandContext<E>

Type Parameters:
  `E` - The type of error messages

Direct Known Subclasses:
  `CAICommandContext`

public abstract class CACommandContext<E extends CAProtocolMessageType> extends Object
The context for execution of a command (or set of commands in a transaction).

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `CACommandContext(com.io7m.repetoir.core.RPServiceDirectoryType inServices, UUID inRequestId, CADatabaseTransactionType inTransaction, CASession inSession, String inRemoteHost, String inRemoteUserAgent)`
  The context for execution of a command (or set of commands in a transaction).

- ## Method Summary

  Modifier and Type
  Method
  Description
  `final Map<CAStringConstantType,String>`
  `attributes()`
  `final CACommandExecutionFailure`
  `fail(int statusCode, CAErrorCode errorCode, String message, Map<CAStringConstantType,String> errorAttributes)`
  Produce an exception indicating an error, with a string constant message.
  `final CACommandExecutionFailure`
  `failDatabase(CADatabaseException e)`
  Produce an exception indicating a database error.
  `final CACommandExecutionFailure`
  `failFormatted(int statusCode, CAErrorCode errorCode, Map<CAStringConstantType,String> errorAttributes, CAStringConstantType messageId, Object... args)`
  Produce an exception indicating an error, with a formatted error message.
  `final CACommandExecutionFailure`
  `failFormatted(Exception exception, int statusCode, CAErrorCode errorCode, Map<CAStringConstantType,String> errorAttributes, CAStringConstantType messageId, Object... args)`
  Produce an exception indicating an error, with a formatted error message.
  `CACommandExecutionFailure`
  `failProtocol(CAProtocolException e)`
  Produce an exception indicating a protocol error.
  `CACommandExecutionFailure`
  `failSecurity(CASecurityException e)`
  Produce an exception indicating a security policy error.
  `CACommandExecutionFailure`
  `failValidity(CAValidityException e)`
  Produce an exception indicating a validation error.
  `final CACommandExecutionFailure`
  `failWithCause(Exception cause, int statusCode, CAErrorCode errorCode, String message, Map<String,String> errorAttributes)`
  Produce an exception indicating an error, with a string constant message.
  `final String`
  `local(CAStringConstantType constant, Object... objects)`
  Localize the given string.
  `final OffsetDateTime`
  `now()`
  `final String`
  `remoteHost()`
  `final String`
  `remoteUserAgent()`
  `final UUID`
  `requestId()`
  `final com.io7m.repetoir.core.RPServiceDirectoryType`
  `services()`
  `final CASession`
  `session()`
  `final void`
  `setAttribute(CAStringConstantType key, String value)`
  Set an attribute for error reporting.
  `final io.opentelemetry.api.trace.Tracer`
  `tracer()`
  `final CADatabaseTransactionType`
  `transaction()`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### CACommandContext

    public CACommandContext(com.io7m.repetoir.core.RPServiceDirectoryType inServices, UUID inRequestId, CADatabaseTransactionType inTransaction, CASession inSession, String inRemoteHost, String inRemoteUserAgent)
    The context for execution of a command (or set of commands in a transaction).
    Parameters:
      `inServices` - The service directory
      `inRequestId` - The request ID
      `inTransaction` - The transaction
      `inSession` - The user session
      `inRemoteHost` - The remote host
      `inRemoteUserAgent` - The remote user agent

- ## Method Details

  - ### attributes

    public final Map<CAStringConstantType,String> attributes()
    Returns:
      The attributes as an immutable map

  - ### setAttribute

    public final void setAttribute(CAStringConstantType key, String value)
    Set an attribute for error reporting.
    Parameters:
      `key` - The key string constant
      `value` - The value

  - ### session

    public final CASession session()
    Returns:
      The user session

  - ### remoteHost

    public final String remoteHost()
    Returns:
      The remote host

  - ### remoteUserAgent

    public final String remoteUserAgent()
    Returns:
      The remote user agent

  - ### services

    public final com.io7m.repetoir.core.RPServiceDirectoryType services()
    Returns:
      The service directory used during execution

  - ### requestId

    public final UUID requestId()
    Returns:
      The ID of the incoming request

  - ### transaction

    public final CADatabaseTransactionType transaction()
    Returns:
      The database transaction

  - ### local

    public final String local(CAStringConstantType constant, Object... objects)
    Localize the given string.
    Parameters:
      `constant` - The string
      `objects` - The object arguments
    Returns:
      The localized string

  - ### tracer

    public final io.opentelemetry.api.trace.Tracer tracer()
    Returns:
      The OpenTelemetry tracer

  - ### now

    public final OffsetDateTime now()
    Returns:
      The current time

  - ### failFormatted

    public final CACommandExecutionFailure failFormatted(int statusCode, CAErrorCode errorCode, Map<CAStringConstantType,String> errorAttributes, CAStringConstantType messageId, Object... args)
    Produce an exception indicating an error, with a formatted error message.
    Parameters:
      `statusCode` - The HTTP status kind
      `errorCode` - The error kind
      `errorAttributes` - The error attributes
      `messageId` - The string resource message ID
      `args` - The string resource format arguments
    Returns:
      An execution failure

  - ### failFormatted

    public final CACommandExecutionFailure failFormatted(Exception exception, int statusCode, CAErrorCode errorCode, Map<CAStringConstantType,String> errorAttributes, CAStringConstantType messageId, Object... args)
    Produce an exception indicating an error, with a formatted error message.
    Parameters:
      `exception` - The exception
      `statusCode` - The HTTP status kind
      `errorCode` - The error kind
      `errorAttributes` - The error attributes
      `messageId` - The string resource message ID
      `args` - The string resource format arguments
    Returns:
      An execution failure

  - ### fail

    public final CACommandExecutionFailure fail(int statusCode, CAErrorCode errorCode, String message, Map<CAStringConstantType,String> errorAttributes)
    Produce an exception indicating an error, with a string constant message.
    Parameters:
      `statusCode` - The HTTP status kind
      `errorCode` - The error kind
      `message` - The string message
      `errorAttributes` - The error attributes
    Returns:
      An execution failure

  - ### failWithCause

    public final CACommandExecutionFailure failWithCause(Exception cause, int statusCode, CAErrorCode errorCode, String message, Map<String,String> errorAttributes)
    Produce an exception indicating an error, with a string constant message.
    Parameters:
      `cause` - The cause
      `statusCode` - The HTTP status kind
      `errorCode` - The error kind
      `message` - The string message
      `errorAttributes` - The error attributes
    Returns:
      An execution failure

  - ### failDatabase

    public final CACommandExecutionFailure failDatabase(CADatabaseException e)
    Produce an exception indicating a database error.
    Parameters:
      `e` - The database exception
    Returns:
      An execution failure

  - ### failSecurity

    public CACommandExecutionFailure failSecurity(CASecurityException e)
    Produce an exception indicating a security policy error.
    Parameters:
      `e` - The security exception
    Returns:
      An execution failure

  - ### failProtocol

    public CACommandExecutionFailure failProtocol(CAProtocolException e)
    Produce an exception indicating a protocol error.
    Parameters:
      `e` - The exception
    Returns:
      An execution failure

  - ### failValidity

    public CACommandExecutionFailure failValidity(CAValidityException e)
    Produce an exception indicating a validation error.
    Parameters:
      `e` - The exception
    Returns:
      An execution failure