AGGREGATE_ROOT - the aggregate root typeDTO - the dto typepublic abstract class BaseAssembler<AGGREGATE_ROOT extends AggregateRoot<?>,DTO> extends AbstractBaseAssembler<AGGREGATE_ROOT,DTO>
doAssembleDtoFromAggregate(Object, org.seedstack.business.api.domain.AggregateRoot) and
doMergeAggregateWithDto(org.seedstack.business.api.domain.AggregateRoot, Object) to provide
implementation of the copy.
For instance:
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);Note that
Assemblers will automatically have a reference of ProductAssembler and the following will
be respectively equivalent to the previous use.
@Inject Assemblers assemblers; ... ProductRepresentation productRepresentation = assemblers.assembleDtoFromAggregate(ProductRepresentation.class, productFromRepo); ... assemblers.mergeAggregateWithDto(productToMerge, productRepresentationSource);
dtoClass| Constructor and Description |
|---|
BaseAssembler()
Default needed constructor.
|
| Modifier and Type | Method and Description |
|---|---|
DTO |
assembleDtoFromAggregate(AGGREGATE_ROOT sourceAggregate)
This method is used by developers or by the DSL to assemble a new DTO from the given aggregate.
|
protected abstract void |
doAssembleDtoFromAggregate(DTO targetDto,
AGGREGATE_ROOT sourceAggregate)
This method has to be overridden by users to actually assemble the DTO from the aggregate.
|
protected abstract void |
doMergeAggregateWithDto(AGGREGATE_ROOT targetAggregate,
DTO sourceDto)
This method has to be overridden by users to actually merge an aggregate with the DTO.
|
void |
mergeAggregateWithDto(AGGREGATE_ROOT targetAggregate,
DTO sourceDto)
This method is used by developers or by the DSL to actually merge the aggregate.
|
void |
updateDtoFromAggregate(DTO sourceDto,
AGGREGATE_ROOT sourceAggregate)
Updates the given DTO from the aggregate.
|
getDtoClass, newDtopublic DTO assembleDtoFromAggregate(AGGREGATE_ROOT sourceAggregate)
AbstractBaseAssembler.newDto() for the DTO creation
doAssembleDtoFromAggregate(Object, org.seedstack.business.api.domain.AggregateRoot)
for the assembly algorithm.
org.seedstack.seed.security.api.data.DataSecurityService.sourceAggregate - The aggregate from which create the DTO.Assembler.assembleDtoFromAggregate(Object)public void updateDtoFromAggregate(DTO sourceDto, AGGREGATE_ROOT sourceAggregate)
AssemblersourceDto - The dto to update.sourceAggregate - The aggregate to copy data from.protected abstract void doAssembleDtoFromAggregate(DTO targetDto, AGGREGATE_ROOT 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.api.domain.AggregateRoot)targetDto - the target dtosourceAggregate - the source aggregatepublic void mergeAggregateWithDto(AGGREGATE_ROOT targetAggregate, DTO sourceDto)
doMergeAggregateWithDto(org.seedstack.business.api.domain.AggregateRoot, Object), which
is overridden by developers.targetAggregate - the target aggregatesourceDto - the source dtoAssembler.mergeAggregateWithDto(Object, Object)protected abstract void doMergeAggregateWithDto(AGGREGATE_ROOT targetAggregate, DTO sourceDto)
... targetAggregate.setName(sourceDto.getName()); targetAggregate.setDescription(sourceDto.getDescription()); ...This method will be called by the public method
mergeAggregateWithDto(org.seedstack.business.api.domain.AggregateRoot, Object).sourceDto - the source dtotargetAggregate - the target aggregateCopyright © 2013-2015–2015. All rights reserved.