| package org.eclipse.osbp.dsl.tests.carstore.dtos.mapper; |
| |
| import java.util.Date; |
| import org.eclipse.osbp.dsl.dto.lib.MappingContext; |
| import org.eclipse.osbp.dsl.tests.carstore.dtos.CarDto; |
| import org.eclipse.osbp.dsl.tests.carstore.dtos.mapper.BaseDtoMapper; |
| import org.eclipse.osbp.dsl.tests.carstore.entities.Car; |
| |
| /** |
| * This class maps the dto {@link CarDto} to and from the entity {@link Car}. |
| * |
| */ |
| @SuppressWarnings("all") |
| public class CarDtoMapper<DTO extends CarDto, ENTITY extends Car> extends BaseDtoMapper<DTO, ENTITY> { |
| /** |
| * Creates a new instance of the entity |
| */ |
| public Car createEntity() { |
| return new Car(); |
| } |
| |
| /** |
| * Creates a new instance of the dto |
| */ |
| public CarDto createDto() { |
| return new CarDto(); |
| } |
| |
| /** |
| * Maps the entity {@link Car} to the dto {@link CarDto}. |
| * |
| * @param dto - The target dto |
| * @param entity - The source entity |
| * @param context - The context to get information about depth,... |
| * |
| */ |
| public void mapToDTO(final CarDto dto, final Car entity, final MappingContext context) { |
| if(context == null){ |
| throw new IllegalArgumentException("Please pass a context!"); |
| } |
| context.register(createDtoHash(entity), dto); |
| |
| super.mapToDTO(dto, entity, context); |
| |
| dto.setNumber(toDto_number(entity, context)); |
| dto.setFinishingDate(toDto_finishingDate(entity, context)); |
| } |
| |
| /** |
| * Maps the dto {@link CarDto} to the entity {@link Car}. |
| * |
| * @param dto - The source dto |
| * @param entity - The target entity |
| * @param context - The context to get information about depth,... |
| * |
| */ |
| public void mapToEntity(final CarDto dto, final Car entity, final MappingContext context) { |
| if(context == null){ |
| throw new IllegalArgumentException("Please pass a context!"); |
| } |
| |
| context.register(createEntityHash(dto), entity); |
| context.registerMappingRoot(createEntityHash(dto), dto); |
| super.mapToEntity(dto, entity, context); |
| |
| entity.setNumber(toEntity_number(dto, entity, context)); |
| entity.setFinishingDate(toEntity_finishingDate(dto, entity, context)); |
| } |
| |
| /** |
| * Maps the property number from the given entity to dto property. |
| * |
| * @param in - The source entity |
| * @param context - The context to get information about depth,... |
| * @return the mapped value |
| * |
| */ |
| protected String toDto_number(final Car in, final MappingContext context) { |
| return in.getNumber(); |
| } |
| |
| /** |
| * Maps the property number from the given entity to dto property. |
| * |
| * @param in - The source entity |
| * @param parentEntity - The parentEntity |
| * @param context - The context to get information about depth,... |
| * @return the mapped value |
| * |
| */ |
| protected String toEntity_number(final CarDto in, final Car parentEntity, final MappingContext context) { |
| return in.getNumber(); |
| } |
| |
| /** |
| * Maps the property finishingDate from the given entity to dto property. |
| * |
| * @param in - The source entity |
| * @param context - The context to get information about depth,... |
| * @return the mapped value |
| * |
| */ |
| protected Date toDto_finishingDate(final Car in, final MappingContext context) { |
| return in.getFinishingDate(); |
| } |
| |
| /** |
| * Maps the property finishingDate from the given entity to dto property. |
| * |
| * @param in - The source entity |
| * @param parentEntity - The parentEntity |
| * @param context - The context to get information about depth,... |
| * @return the mapped value |
| * |
| */ |
| protected Date toEntity_finishingDate(final CarDto in, final Car parentEntity, final MappingContext context) { |
| return in.getFinishingDate(); |
| } |
| |
| public String createDtoHash(final Object in) { |
| return org.eclipse.osbp.runtime.common.hash.HashUtil.createObjectWithIdHash(CarDto.class, in); |
| } |
| |
| public String createEntityHash(final Object in) { |
| return org.eclipse.osbp.runtime.common.hash.HashUtil.createObjectWithIdHash(Car.class, in); |
| } |
| } |