Understanding copiers

The gw.api.copy.Copier abstract class provides base functionality for copying data from a source to a target. In the same package, the CompositeCopier abstract class extends Copier. The CompositeCopier wraps a collection of copiers of one or more types, creating a tree of copiers that reflects the structure of the data to be copied.

You can create concrete implementations of these abstract copier classes. The concrete implementation of the Copier class is responsible for copying the data on an entity. The concrete implementation of the CompositeCopier class is responsible for copying data on an entity and its child entities.

In your concrete subclass of the Copier class, define the copyInto method to perform the following actions:

  1. Check for an existing matching entity – Check for a matching entity in the destination period, such as a vehicle with the same VIN. If a matching entity already exists in the destination period, you can configure your code to throw an exception or you can copy source fields over the existing entity.
  2. Create a new entity – Create a new entity if a matching entity does not exist. To create a new entity, examine existing domain methods, such as PersonalAutoLine.createAndAddVehicle to create personal vehicles. If possible, reuse these existing methods. Doing so ensures that the code performs additional logic, such as auto-numbering objects.
  3. Create additional entities – When you create a new entity, also create any additional entities needed for the copy data operation. For example, if you copy a PolicyDriver who is not a contact on the target account, your code must create both an account Driver and an AccountContact.
  4. Copy entity fields – Copy all relevant fields and child elements. The simplest implementation uses a sequence of assignment statements. To automate copying, use utilities such as the copy and KeyableBean.shallowCopy methods of GWKeyableBeanEnhancement, or use code from side-by-side quoting that copies entities. If you use one of these utilities, the copyInto method must remove the fields that are not part of the copied data.
  5. Copy child entities – Copy child entities where the ShouldCopy and ShouldCopyAll Boolean properties are true. You can provide this functionality in your Copier subclass or in a helper class. Control over whether these children are copied can be delegated to child copier classes by overriding the CollectCopiersWhere method in gw.api.copy.CompositeCopier. For example, you can configure the PersonalVehicle copier to automatically copy all of its coverages or just selected coverages.