@KwrkImmutable @CompileStatic class ViolationCode extends Object implements PostMapConstructorCheckable
Immutable data structure describing violation's code and the corresponding non-localized code's message.
There are also optionalresolvableMessageKey
and resolvableMessageParameters
properties used for easier resolving of localized messages outside the domain's boundary.
When resolving DomainException
for display rendering, the corresponding rendered should honor the intended overriding order between ViolationCode.codeMessage
, domain exception
message, and ViolationCode.resolvableMessageKey
. For example:
ViolationCode.resolvableMessageKey
is available, the exception renderer should use is for resolving a message through resource bundle.DomainException
message exists and is not blank string, the exception renderer should use it directly.ViolationCode.codeMessage
directly.Type | Name and description |
---|---|
static ViolationCode |
BAD_REQUEST |
static String |
BAD_REQUEST_CODE |
static String |
BAD_REQUEST_CODE_MESSAGE |
static String |
BAD_REQUEST_RESOLVABLE_MESSAGE_KEY |
static ViolationCode |
NOT_FOUND |
static String |
NOT_FOUND_CODE |
static String |
NOT_FOUND_CODE_MESSAGE |
static String |
NOT_FOUND_RESOLVABLE_MESSAGE_KEY |
static String |
RESOLVABLE_MESSAGE_KEY_UNAVAILABLE |
static ViolationCode |
UNKNOWN |
static String |
UNKNOWN_CODE |
static String |
UNKNOWN_CODE_MESSAGE |
static String |
UNKNOWN_RESOLVABLE_MESSAGE_KEY |
String |
code The primary code describing the main category of the violation. |
String |
codeMessage A short hardcoded human-readable message written in English describing the problem identified by this ViolationCode .
|
String |
resolvableMessageKey A key for resolving an internationalized message corresponding to this ViolationCode , i.e., through the resource bundle.
|
List<String> |
resolvableMessageParameters A list of strings containing parameters for resolving internationalized message corresponding to this ViolationCode . |
Constructor and description |
---|
ViolationCode() |
Type Params | Return Type | Name and description |
---|---|---|
|
boolean |
isResolvable() Whether or not this violation code contains a resolvable message key. |
|
static ViolationCode |
make(String code, String codeMessage, String resolvableMessageKey, List<String> resolvableMessageParameters) The factory method for creating ViolationCode instances.
|
|
void |
postMapConstructorCheck(Map<String, ?> constructorArguments) |
The primary code describing the main category of the violation.
In general, it does not have to be designed to be human-readable, but rather it should be in the form of some primary violation/error identifier. For example, the categorization of HTTP response statuses (200, 400, 404, 500, etc.), or database error code categorizations, are good examples of the kind of information that should go in here. Since the authors find HTTP error codes quite a good high-level categorization of errors, we are using them in klokwrk. However, any other custom categorization can be employed instead. A short hardcoded human-readable message written in English describing the problem identified by this ViolationCode
.
A key for resolving an internationalized message corresponding to this ViolationCode
, i.e., through the resource bundle.
code
as a key for resolving internationalized messages. However, code
can be very technical and often expressed as a stringified number, which makes it
hard to recognize for developers or other human translators.
Therefore, resolvableMessageKey
is a resolvable alias for code
that is much more appealing to use for writing localized resource bundles at the inbound/outbound channel level.
For example, when maintaining resource bundles, it should be much easier for a developer to deduct the meaning of
bookingOfferQueryWebController.bookingOfferSummaryQuery.failure.other.badRequest
resource bundle key instead the meaning of
bookingOfferQueryWebController.bookingOfferSummaryQuery.failure.other.400
key. And this is exactly the intention behind this property.
If we need some further categorization inside resolvableMessageKey
, it is recommended to use dot character for that purpose. For example, like in notFound.personSummary
.
Whether or not this violation code contains a resolvable message key.
The factory method for creating ViolationCode
instances.
resolvableMessageKey
and resolvableMessageParameters
are optional. If not specified, they are resolved to RESOLVABLE_MESSAGE_KEY_UNAVAILABLE
constant and empty
list, respectively.
Groovy Documentation