When a register starts up, it is often necessary that some specific data exists in the database (e.g. Mongo) in order for that register to function or be usable. A good example of this is the Security application which needs a minimal set of users, permissions, permission pools & permission groups in order for a user to interact with the register. As well as seeding this data, typically it is necessary to only seed some of the data in a given set of environments, e.g. Development & Test environments but not User Acceptance or Production environments.

Verne supports the above by Service Transaction Seeding, which as the name suggests will seed the database with a set of Service Transactions.

The first step is to configure the application with the seed resources that you wish to execute and for what environments:

<application code="security">
  <seed group="dev,tst" resourceName="seed/serviceTransactions/test_users.groovy"/>
  <seed group="*" resourceName="seed/serviceTransactions/permissions.groovy"/>
  <seed group="*" resourceName="seed/serviceTransactions/permission-groups.groovy"/>
  <seed group="*" resourceName="seed/serviceTransactions/permission-pools.groovy"/>
  <seed group="perf" resourceName="seed/serviceTransactions/lots_of_users.groovy"/>
</application>

The above defines a set of seeding resources that would be executed as follows:

  • seed/serviceTransactions/test_users.groovy – this would be executed only in environments that have been set up with the seedGroup Verne property of dev or tst.
  • seed/serviceTransactions/permissions.groovy – this would be executed in all environments
  • seed/serviceTransactions/permission-groups.groovy – this would be executed in all environments
  • seed/serviceTransactions/permission-pools.groovy – this would be executed in all environments
  • seed/serviceTransactions/lots_of_users.groovy – this would be executed in the environments that have been set up with the seedGroup Verne Property of perf

Note: the infrastructure/deployment team configure the seedGroup property for each environment.

These seed resources can actually live in any location in the VFS resource tree, but best practice is to have them in the seed/serviceTransaction location.

These groovy files will then create a Service Transaction depending on requirements. They could read from a CSV file, or loop through creating a million users, or just a single one.

The security application in registry-quick-start configures a set of seeding resources and should be used as a starting point and a resource of how to seed service transactions, e.g.

import com.fostermoore.catalyst.ng.blade.context.ApplicationContext
import com.fostermoore.catalyst.ng.blade.support.SeedSupport

return SeedSupport.csvSecurityPermissions(ApplicationContext.get().application.getResource("/seed/serviceTransactions/permissions_core.csv"))

The above resource loads in the contents of the seed/serviceTransactions/permissions_core.csv a resource to create the ‘core’ Security permissions for a register.

0
0

Jump to Section