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:
- 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.
- 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.createAndAddVehicleto create personal vehicles. If possible, reuse these existing methods. Doing so ensures that the code performs additional logic, such as auto-numbering objects. - 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
PolicyDriverwho is not a contact on the target account, your code must create both an accountDriverand anAccountContact. - 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
copyand KeyableBean.shallowCopy methods ofGWKeyableBeanEnhancement, 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. - Copy
child entities – Copy child entities where the
ShouldCopyandShouldCopyAllBoolean properties aretrue. You can provide this functionality in yourCopiersubclass or in a helper class. Control over whether these children are copied can be delegated to child copier classes by overriding the CollectCopiersWhere method ingw.api.copy.CompositeCopier. For example, you can configure thePersonalVehiclecopier to automatically copy all of its coverages or just selected coverages.
