-
Notifications
You must be signed in to change notification settings - Fork 1
Nested Documents
webMethods supports nested documents. wmboost-data makes it easier to manipulate them compared to the alternative of using IData and other classes - using IDataCursors is particularly inconvenient.
Let's assume we want to represent a simplified invoice. The invoice is linked to a client, which is a nested document.
- id: A654
- date: 2017-02-12
- totalAmount: 340.00
- client
- id: AC880
- businessName: ACME
- email: acme@example.org
Let's populate the document in code
Document invoice = Documents.create();
invoice.entry("id").put("A654");
invoice.entry("date").put("2017-02-12");
invoice.bigDecimalEntry("totalAmount").putConverted("340.00");
Document client = invoice.docEntry("client").putNew();
client.entry("id").put("AC880");
client.entry("businessName").put("ACME");
client.entry("email").put("acme@example.org");
The most important part is the use of docEntry
and putNew
. This allows us to put and create a nested document in one go.
An alternative would've been to create the client first and link it to the invoice at the end:
Document client = Documents.create();
// Set client values
// Init all invoice values but client
invoice.docEntry("client").put(client);
It's possible to use
entry
instead ofdocEntry
, resulting in code likeinvoice.entry("client").put(client)
. Still, the usedocEntry
may be preferred due to its compilation safety.
If we wanted to get an attribute from the nested document in another service, we could do this:
Document pipeDoc = Documents.wrap(pipeline);
Document invoiceDoc = pipelineDoc.docEntry("invoice").getNonNullVal();
Document clientDoc = invoiceDoc.docEntry("client").getNonNullVal();
String businessName = clientDoc.stringEntry("businessName").getVal();
// do something with the business name