| package org.eclipse.osbp.authentication.account.dtos.mapper; |
| |
| import org.eclipse.osbp.authentication.account.dtos.UserAccountDto; |
| import org.eclipse.osbp.authentication.account.dtos.UserAccountFilterDto; |
| import org.eclipse.osbp.authentication.account.entities.UserAccount; |
| import org.eclipse.osbp.authentication.account.entities.UserAccountFilter; |
| import org.eclipse.osbp.dsl.dto.lib.IMapper; |
| import org.eclipse.osbp.dsl.dto.lib.IMapperAccess; |
| import org.eclipse.osbp.dsl.dto.lib.MappingContext; |
| |
| /** |
| * This class maps the dto {@link UserAccountFilterDto} to and from the entity {@link UserAccountFilter}. |
| * |
| */ |
| @SuppressWarnings("all") |
| public class UserAccountFilterDtoMapper<DTO extends UserAccountFilterDto, ENTITY extends UserAccountFilter> implements IMapper<DTO, ENTITY> { |
| private IMapperAccess mapperAccess; |
| |
| /** |
| * Returns the mapper instance that may map between the given dto and entity. Or <code>null</code> if no mapper is available. |
| * |
| * @param dtoClass - the class of the dto that should be mapped |
| * @param entityClass - the class of the entity that should be mapped |
| * @return the mapper instance or <code>null</code> |
| */ |
| protected <D, E> IMapper<D, E> getToDtoMapper(final Class<D> dtoClass, final Class<E> entityClass) { |
| return mapperAccess.getToDtoMapper(dtoClass, entityClass); |
| } |
| |
| /** |
| * Returns the mapper instance that may map between the given dto and entity. Or <code>null</code> if no mapper is available. |
| * |
| * @param dtoClass - the class of the dto that should be mapped |
| * @param entityClass - the class of the entity that should be mapped |
| * @return the mapper instance or <code>null</code> |
| */ |
| protected <D, E> IMapper<D, E> getToEntityMapper(final Class<D> dtoClass, final Class<E> entityClass) { |
| return mapperAccess.getToEntityMapper(dtoClass, entityClass); |
| } |
| |
| /** |
| * Called by OSGi-DS. Binds the mapper access service. |
| * |
| * @param service - The mapper access service |
| * |
| */ |
| protected void bindMapperAccess(final IMapperAccess mapperAccess) { |
| this.mapperAccess = mapperAccess; |
| } |
| |
| /** |
| * Called by OSGi-DS. Binds the mapper access service. |
| * |
| * @param service - The mapper access service |
| * |
| */ |
| protected void unbindMapperAccess(final IMapperAccess mapperAccess) { |
| this.mapperAccess = null; |
| } |
| |
| /** |
| * Creates a new instance of the entity |
| */ |
| public UserAccountFilter createEntity() { |
| return new UserAccountFilter(); |
| } |
| |
| /** |
| * Creates a new instance of the dto |
| */ |
| public UserAccountFilterDto createDto() { |
| return new UserAccountFilterDto(); |
| } |
| |
| /** |
| * Maps the entity {@link UserAccountFilter} to the dto {@link UserAccountFilterDto}. |
| * |
| * @param dto - The target dto |
| * @param entity - The source entity |
| * @param context - The context to get information about depth,... |
| * |
| */ |
| public void mapToDTO(final UserAccountFilterDto dto, final UserAccountFilter entity, final MappingContext context) { |
| if(context == null){ |
| throw new IllegalArgumentException("Please pass a context!"); |
| } |
| context.register(createDtoHash(entity), dto); |
| |
| dto.setId(toDto_id(entity, context)); |
| dto.setFilter(toDto_filter(entity, context)); |
| dto.setInvers(toDto_invers(entity, context)); |
| dto.setUserAccount(toDto_userAccount(entity, context)); |
| } |
| |
| /** |
| * Maps the dto {@link UserAccountFilterDto} to the entity {@link UserAccountFilter}. |
| * |
| * @param dto - The source dto |
| * @param entity - The target entity |
| * @param context - The context to get information about depth,... |
| * |
| */ |
| public void mapToEntity(final UserAccountFilterDto dto, final UserAccountFilter entity, final MappingContext context) { |
| if(context == null){ |
| throw new IllegalArgumentException("Please pass a context!"); |
| } |
| |
| context.register(createEntityHash(dto), entity); |
| context.registerMappingRoot(createEntityHash(dto), dto); |
| |
| entity.setId(toEntity_id(dto, entity, context)); |
| entity.setFilter(toEntity_filter(dto, entity, context)); |
| entity.setInvers(toEntity_invers(dto, entity, context)); |
| entity.setUserAccount(toEntity_userAccount(dto, entity, context)); |
| } |
| |
| /** |
| * Maps the property id 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_id(final UserAccountFilter in, final MappingContext context) { |
| return in.getId(); |
| } |
| |
| /** |
| * Maps the property id 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_id(final UserAccountFilterDto in, final UserAccountFilter parentEntity, final MappingContext context) { |
| return in.getId(); |
| } |
| |
| /** |
| * Maps the property filter 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_filter(final UserAccountFilter in, final MappingContext context) { |
| return in.getFilter(); |
| } |
| |
| /** |
| * Maps the property filter 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_filter(final UserAccountFilterDto in, final UserAccountFilter parentEntity, final MappingContext context) { |
| return in.getFilter(); |
| } |
| |
| /** |
| * Maps the property invers 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 boolean toDto_invers(final UserAccountFilter in, final MappingContext context) { |
| return in.getInvers(); |
| } |
| |
| /** |
| * Maps the property invers 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 boolean toEntity_invers(final UserAccountFilterDto in, final UserAccountFilter parentEntity, final MappingContext context) { |
| return in.getInvers(); |
| } |
| |
| /** |
| * Maps the property userAccount from the given entity to the dto. |
| * |
| * @param in - The source entity |
| * @param context - The context to get information about depth,... |
| * @return the mapped dto |
| * |
| */ |
| protected UserAccountDto toDto_userAccount(final UserAccountFilter in, final MappingContext context) { |
| if(in.getUserAccount() != null) { |
| // find a mapper that knows how to map the concrete input type. |
| org.eclipse.osbp.dsl.dto.lib.IMapper<UserAccountDto, UserAccount> mapper = (org.eclipse.osbp.dsl.dto.lib.IMapper<UserAccountDto, UserAccount>) getToDtoMapper(UserAccountDto.class, in.getUserAccount().getClass()); |
| if(mapper == null) { |
| throw new IllegalStateException("Mapper must not be null!"); |
| } |
| UserAccountDto dto = null; |
| dto = context.get(mapper.createDtoHash(in.getUserAccount())); |
| if(dto != null) { |
| if(context.isRefresh()){ |
| mapper.mapToDTO(dto, in.getUserAccount(), context); |
| } |
| return dto; |
| } |
| |
| context.increaseLevel(); |
| dto = mapper.createDto(); |
| mapper.mapToDTO(dto, in.getUserAccount(), context); |
| context.decreaseLevel(); |
| return dto; |
| } else { |
| return null; |
| } |
| } |
| |
| /** |
| * Maps the property userAccount from the given dto to the entity. |
| * |
| * @param in - The source dto |
| * @param parentEntity - The parent entity |
| * @param context - The context to get information about depth,... |
| * @return the mapped entity |
| * |
| */ |
| protected UserAccount toEntity_userAccount(final UserAccountFilterDto in, final UserAccountFilter parentEntity, final MappingContext context) { |
| if(in.getUserAccount() != null) { |
| // find a mapper that knows how to map the concrete input type. |
| org.eclipse.osbp.dsl.dto.lib.IMapper<UserAccountDto, UserAccount> mapper = (org.eclipse.osbp.dsl.dto.lib.IMapper<UserAccountDto, UserAccount>) getToEntityMapper(in.getUserAccount().getClass(), UserAccount.class); |
| if(mapper == null) { |
| throw new IllegalStateException("Mapper must not be null!"); |
| } |
| |
| UserAccount entity = null; |
| entity = context.get(mapper.createEntityHash(in.getUserAccount())); |
| if(entity != null) { |
| return entity; |
| } else { |
| entity = (UserAccount) context |
| .findEntityByEntityManager(UserAccount.class, in.getUserAccount().getId()); |
| if (entity != null) { |
| context.register(mapper.createEntityHash(in.getUserAccount()), entity); |
| return entity; |
| } |
| } |
| |
| entity = mapper.createEntity(); |
| mapper.mapToEntity(in.getUserAccount(), entity, context); |
| return entity; |
| } else { |
| return null; |
| } |
| } |
| |
| public String createDtoHash(final Object in) { |
| return org.eclipse.osbp.runtime.common.hash.HashUtil.createObjectWithIdHash(UserAccountFilterDto.class, in); |
| } |
| |
| public String createEntityHash(final Object in) { |
| return org.eclipse.osbp.runtime.common.hash.HashUtil.createObjectWithIdHash(UserAccountFilter.class, in); |
| } |
| } |