-
Notifications
You must be signed in to change notification settings - Fork 0
Message validation
Table of contents
[[TOC]]
Message validation is complex feature designed to streamline internal news messages flow with strict rules imposed by directories. For example directories configured for exporting information should not confuse message language or have certain tags and properties.
Main idea borrowed from old Ribbon system specification for version a3.
Since system uses microservice architecture all data required for message validation will be placed at messenger unit and linked to existing copy entry of directory.
Proposed format is new field for directories copy table: validation
with type jsonb
mapped on Map<String, String>
. Each map entry represetns specific type of message validation rule. Map value contains arguments supplied to speicifed validation rule.
List of proposed validation rules with argument examples:
-
LANG
- forbids to create or contain any messages on directory which language not equal to language specified in argument. Argument: language code (ISO-639). Example:en
orua
; -
MIN_CONTENT_LENGTH
- forbids to create message on directory if it has less characters than specified in argument. Argument: integer. Example:10
; -
MAX_CONTENT_LENGTH
- forbids to create message on directory if it has more characters than specified in argument. Argument: integer. Example:1000
; -
MIN_HEADER_LENGTH
- forbids to create message on directory if it's header has less characters than specified in argument. Argument: integer. Example:5
; -
MAX_HEADER_LENGTH
- forbids to create message on directory if it's header has more characters than specified in argument. Argument: integer. Example:255
; -
MIN_TAG_COUNT
- forbids to create message on directory if it contans less tags than specified in argument. Argument: integer. Example:2
; -
MAX_TAG_COUNT
- forbids to create message on directory if it contans more tags than specified in argument. Argument: integer. Example:15
; -
REQ_TAG
- forbids to create message on directory if it doesn't contain specified in argument tag. Argument: string; Example:TagName
; -
REQ_COPYRIGHT
- forbids to create message on directory without copyright property. Argument: null or empty string; -
FORBID_CREATE
- forbids creating on directory for all (including admin). Argument: null or empty string; -
FORBID_UPDATE
- forbids updating on directory for all (including admin). Argument: null or empty string; -
FORBID_DELETE
- forbids posting on directory for all (including admin). Argument: null or empty string; -
MESSAGE_COUNT_LIMIT
- forbids to create new messages on directory if total count meets limit specified in argument. Argument: integer. Example:10000
;
Since creating/updating can be performed on multiple directories each set of validation rules should support merging it from several directories. In case of rules which limits amount of some parameter more restrictive rule will be applied. For example: both directories contain MIN_TAG_COUNT
validation rule but first is 3
and second is 5
. In this case 5
will be applied (max value). In case of MAX_TAG_COUNT
it's other way around: 3
will be applied. Same logic applies to MESSAGE_COUNT_LIMIT
.
Rule which require or forbid something it depends on rule type. REQ_TAG
should be apply on each other: if both directories require some tags then it's both required. REQ_COPYRIGHT
(and FORBID_CREATE
, FORBID_UPDATE
, FORBID_DELETE
) doesn't have argument so it just adds to merged rule set. But LANG
validation rule can conflict between different ruleset which gurantees a failed validation.
Merged validation rule set structure should meet two objectives: help to display list of rules for user and presense of conflict within rule set and perform validation of message not only on messenger unit but on ui too.
Validation process should not throw exceptions and return structured info about errors and maybe required actions to fix situation.
Even if validation was ran on UI it's still mandatory on messenger during creation/update of message.
System should provide several REST ednpoints for validation rules:
-
POST /api/directory/validation/:path
- create/update validation rules on directory; -
GET /api/directory/validation/:path
- get existing validation rules on directory; -
GET /api/directory/validation/merge?dir=?0&dir=?1
- get merged validation rule set on several directories for validation on client or for display purpose;
Validation rule set example:
{
"LANG": "uk-UA",
"REQ_TAG": "Випуск",
"REQ_COPYRIGHT": null,
"MAX_TAG_COUNT": "8"
}
Merged validation rule set example:
{
"rules": [
{
"type": "LANG",
"currentArgs": [],
"conflict": true,
"args": {
"Edit.UA": "uk",
"Edit.EN": "en"
}
},
{
"type": "REQ_TAG",
"currentArgs": ["Випуск", "Release"],
"conflict": false,
"args": {
"Edit.UA": "Випуск",
"Edit.EN": "Release"
}
},
{
"type": "REQ_COPYRIGHT",
"currentArgs": [],
"conflict": false,
"args": {
"Edit.UA": null,
"Edit.EN": null
}
},
{
"type": "MAX_TAG_COUNT",
"currentArgs": ["5"],
"conflict": false,
"args": {
"Edit.UA": "8",
"Edit.EN": "5"
}
},
{
"type": "MIN_TAG_COUNT",
"currentArgs": ["6"],
"conflict": false,
"args": {
"Edit.UA": "6",
"Edit.EN": "3"
}
}
],
"conflicts": [
{
"reportType": "MIN_TAG_COUNT",
"conflictType": "MAX_TAG_COUNT",
"message": "Max tags count rule value is lesser than current min limit.",
"reportValue": "{Edit.UA\u003d8,Edit.EN\u003d5}",
"conflictValue": "[6]"
},
{
"reportType": "MAX_TAG_COUNT",
"conflictType": "MIN_TAG_COUNT",
"message": "Min tags count rule value is larger than current max tags limit.",
"reportValue": "{Edit.UA\u003d6,Edit.EN\u003d3}",
"conflictValue": "[5]"
}
]
}
Validation engine implemented in core library. However full validation process can be performed only on messenger unit. Validation context using for validation process. It contains data about current operation, and validation errors. One method in particular is not implemented in core library: getMessageCount(dir)
: always returns -1
. For validation outside of messenger DummyContext
should be used with specified operation (CREATE
, UPDATE
or DELETE
). Also context instances must not be reused.
Validation call:
context = new DummyContext(Operation.CREATE);
engine.validateMessage(message, context, ruleSet);
Get errors:
Set<ValidationError> errors = context.getErrors();
Example or errors:
[
{
"type": "MIN_TAG_COUNT",
"message": "Message tags count less than rule limit",
"value": "0",
"expectedValue": "[5]"
}
]