Skip to main content

How to manage nested objects

Nested objects

Financial instruments often have lengthy and complicated structures. For example, a Swap Trade has multiple Legs, each with multiple Cashflows; and each Cashflow can have multiple Fixings.

Nested objects are a common method of incorporating this complexity into financial applications.

To show you how to create these nested objects, we shall use the example of a Counterparty Group, which can contain one or more Subsidiaries. Each Subsidiary can contain one or more Contacts.

Atomic updates

It is often necessary to modify a nested object as an atomic action, rather than changing the individual objects separately. Genesis supports this capability.

From applications generated using Genesis Create, you can modify the individual objects. You need to change this to allow an atomic change of the nested object.

To do this, simply declare a Data Access Object (DAO). You can then pass this DAO to events and allow it to be served via a Request Response (reqrep).

Optionally, you probably want to remove the events relating to the individual objects from projects created by Genesis Create.

Creating the DAO

To create a DAO representation, define a file in your application's /src/main/kotlin folder. For example, here is a file called Message.kt:

data class CounterpartyDAO(
val counterpartyId: String? = null,
val counterparty: String,
val subsidiaries: List<SubsidiaryDao>? = null
)

data class SubsidiaryDao(
val subsidiaryId: String? = null,
val subsidiaryName: String,
val contacts: List<SubsidiaryContactDao>? = null
)

data class SubsidiaryContactDao(
val contactId: String? = null,
val contactName: String,
val contactPhone: String
)

Passing the DAO to an Event Handler

The DAOs you create can then be passed into events so that they can be returned to the front end by a requestReply.

Here is an example of an eventHandler codeblock to do this:

eventHandler {
eventHandler<CounterpartyDAO>("INSERT_COUNTERPARTY", transactional = true) {
onCommit { event ->
val request = event.details
...
}
ack()
}
}

Within the event handler it is necessary to cycle through the nested object to perform appropriate checks and save all data.

The example application, here !need link!, demonstrates this.

Defining the requestReply

To eble the front end to request the data, you must define a requestReply codeblock Here is an example:

requestReplies {
requestReply<CounterpartyGroup.ById, CounterpartyDAO>("FULL_COUNTERPARTY_GROUP") {
replySingle { request ->
...
}
}
}

Within the reqrep we need to load the full nested object. The example application, here !need link!, demonstrates this.

Front-end configuration

The front end can correctly identify the event and enable editing. More Work in Progress here.

Testing

info

Go to our Testing page for details of our testing tools and the dependencies that you need to declare.

To test that nested ojects are being handled correctly:

  • Details to follow shortly. Thank you for your patience.

You can also find useful information on integration testing for back-end components in our reference documentation.

Technical details

Find more details in our in our reference documentation: