Package com.alpaca.mapper.impl
Class RoleMapperImpl
java.lang.Object
com.alpaca.mapper.impl.RoleMapperImpl
- All Implemented Interfaces:
GenericMapper<Role,
,RoleResponseDTO, RoleRequestDTO> IRoleMapper
Implementation of the
IRoleMapper
interface responsible for mapping between Role
entities and their corresponding request and response DTOs.
This mapper uses:
IPermissionMapper
to handle nested permission mappings.IPermissionService
to resolve permission entities from IDs provided in request DTOs.
Key responsibilities:
- Convert
Role
entities intoRoleResponseDTO
objects. - Convert
RoleRequestDTO
objects intoRole
entities. - Transform collections of roles into lists of response DTOs.
- Handle null and empty inputs gracefully by returning safe defaults.
This class is annotated with Component
to enable Spring's dependency injection and
uses Lombok's RequiredArgsConstructor
for constructor-based injection (if required in
future).
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final IPermissionMapper
private final IPermissionService
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiontoEntity
(RoleRequestDTO requestDTO) Converts aRoleRequestDTO
into aRole
entity.toListResponseDTO
(Collection<Role> entities) Converts a collection ofRole
entities into a list ofRoleResponseDTO
.toResponseDTO
(Role entity) Converts aRole
entity into aRoleResponseDTO
.Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.alpaca.mapper.GenericMapper
toPageResponseDTO
-
Field Details
-
permissionMapper
-
permissionService
-
-
Constructor Details
-
RoleMapperImpl
public RoleMapperImpl()
-
-
Method Details
-
toResponseDTO
Converts aRole
entity into aRoleResponseDTO
.- Specified by:
toResponseDTO
in interfaceGenericMapper<Role,
RoleResponseDTO, RoleRequestDTO> - Parameters:
entity
- the role entity to convert, may benull
.- Returns:
- the corresponding response DTO, or
null
if the input isnull
.
-
toEntity
Converts aRoleRequestDTO
into aRole
entity.Permissions are resolved using the
IPermissionService
to fetch the corresponding entities.- Specified by:
toEntity
in interfaceGenericMapper<Role,
RoleResponseDTO, RoleRequestDTO> - Parameters:
requestDTO
- the request DTO containing role data, may benull
.- Returns:
- the corresponding
Role
entity, ornull
if the input isnull
.
-
toListResponseDTO
Converts a collection ofRole
entities into a list ofRoleResponseDTO
.If the collection contains only one element, it is processed without iteration for optimization purposes.
- Specified by:
toListResponseDTO
in interfaceGenericMapper<Role,
RoleResponseDTO, RoleRequestDTO> - Parameters:
entities
- the collection of role entities, may benull
or empty.- Returns:
- a list of response DTOs, or an empty list if the input is
null
or empty.
-