A - the aggregate root typeD - the dto typepublic abstract class BaseAssembler<A extends AggregateRoot<?>,D> extends AbstractBaseAssembler<A,D>
User must implements
doAssembleDtoFromAggregate(Object, org.seedstack.business.domain.AggregateRoot) and
doMergeAggregateWithDto(org.seedstack.business.domain.AggregateRoot, Object) to provide
implementation of the copy.
public class ProductAssembler extends BaseAssembler<Product,ProductRepresentation> {
@Override
protected void doAssembleDtoFromAggregate(ProductRepresentation targetDto, Product sourceAggregate) {
targetDto.fillProductId(sourceAggregate.getEntityId().getStoreId(),
sourceAggregate.getEntityId().getProductCode());
targetDto.setName(sourceAggregate.getName());
targetDto.setDescription(sourceAggregate.getDescription());
}
@Override
protected void doMergeAggregateWithDto(Product targetAggregate, ProductRepresentation sourceDto) {
targetAggregate.setName(sourceDto.getName());
targetAggregate.setDescription(sourceDto.getDescription());
}
}
Then the assembler can be used via:
@Inject ProductAssembler productAssembler;And used like this:
ProductRepresentation productRepresentation = productAssembler.assembleDtoFromAggregate(productFromRepo);or
productAssembler.mergeAggregateWithDto(productToMerge, productRepresentationSource);
dtoClass| Constructor and Description |
|---|
BaseAssembler() |
| Modifier and Type | Method and Description |
|---|---|
D |
assembleDtoFromAggregate(A sourceAggregate)
This method is used by developers or by the DSL to assemble a new DTO from the given aggregate.
|
void |
assembleDtoFromAggregate(D targetDto,
A sourceAggregate)
Updates an existing DTO with a source aggregate root.
|
protected abstract void |
doAssembleDtoFromAggregate(D targetDto,
A sourceAggregate)
This method has to be overridden by users to actually assemble the DTO from the aggregate.
|
protected abstract void |
doMergeAggregateWithDto(A targetAggregate,
D sourceDto)
This method has to be overridden by users to actually merge an aggregate with the DTO.
|
void |
mergeAggregateWithDto(A targetAggregate,
D sourceDto)
This method is used by developers or by the DSL to actually merge the aggregate.
|
getDtoClass, newDtopublic D assembleDtoFromAggregate(A sourceAggregate)
AbstractBaseAssembler.newDto() for the DTO creation
doAssembleDtoFromAggregate(Object, org.seedstack.business.domain.AggregateRoot)
for the assembly algorithm.
sourceAggregate - The aggregate from which create the DTO.Assembler.assembleDtoFromAggregate(Object)public void assembleDtoFromAggregate(D targetDto, A sourceAggregate)
AssemblertargetDto - The target dtosourceAggregate - The source aggregateprotected abstract void doAssembleDtoFromAggregate(D targetDto, A sourceAggregate)
targetDto.fillProductId(sourceAggregate.getEntityId().getStoreId(),
sourceAggregate.getEntityId().getProductCode());
targetDto.setName(sourceAggregate.getName());
targetDto.setDescription(sourceAggregate.getDescription());
This method will be called by the public method
assembleDtoFromAggregate(org.seedstack.business.domain.AggregateRoot)targetDto - the target dtosourceAggregate - the source aggregatepublic void mergeAggregateWithDto(A targetAggregate, D sourceDto)
It will call doMergeAggregateWithDto(org.seedstack.business.domain.AggregateRoot, Object), which
is overridden by developers.
targetAggregate - the target aggregatesourceDto - the source dtoAssembler.mergeAggregateWithDto(Object, Object)protected abstract void doMergeAggregateWithDto(A targetAggregate, D sourceDto)
... targetAggregate.setName(sourceDto.getName()); targetAggregate.setDescription(sourceDto.getDescription()); ...This method will be called by the public method
mergeAggregateWithDto(org.seedstack.business.domain.AggregateRoot, Object).sourceDto - the source dtotargetAggregate - the target aggregateCopyright © 2013-2016–2016 SeedStack. All rights reserved.