Many Records Strategy (Array)
There use cases, when a client sends many records in a single request.
For example, when a client posts multiple purchase orders as JSON array:
In such case, you must expect that not all purchase orders will be processes properly, for example, when the client wants to update a purchase order which does not exist in the target system.
Imagine, PO_03
is invalid and cannot be processed - updated. How can we inform te client about that problem?
Implementation Pattern
The API Process
The API process represents the deployable component. It does not implement any logic, because we might want to run the logic in a Unit-Test as well.
The split and merge process
One request document that contains an array of items it split into n documents.
The
createPurchaseOrder()
logic is executed for n documents, andn Documents of type
j.Errors.RES
are returned
n Documents are merged into on response document,
using a script to count error and ok records.
The business logic for each purchase order
The business logic for each document is wrapped into a try/catch handler.
Exceptions - per document - are turned into an j.Errors.RES
The
[0]
tag is used to signal that it is a single record in an array profile (j.Errors.RES)
Validation Pattern
It is good practice to check, before you execute a target system request, whether you have got appropriate data to perform this request. With other words, you will want to validate your data first, using the validation pattern which throws an exception in case of an error.
This is probably my favourite example to demo how exception handling works: the sub-validation-process validates and it recognizes that something's wrong. Easy as that, the process aborts execution to tell its parent: I got an exception and I could not do what you expected.
The sub-process is not interested in exception handling or so, neither does it know that it runs as part of an API request, neither does it know that the request contained many items etc. etc.
See also: Pre-Condition Check
Last updated