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:
IPermissionMapperto handle nested permission mappings.IPermissionServiceto resolve permission entities from IDs provided in request DTOs.
Key responsibilities:
- Convert
Roleentities intoRoleResponseDTOobjects. - Convert
RoleRequestDTOobjects intoRoleentities. - 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 IPermissionMapperprivate final IPermissionService -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiontoEntity(RoleRequestDTO requestDTO) Converts aRoleRequestDTOinto aRoleentity.toListResponseDTO(Collection<Role> entities) Converts a collection ofRoleentities into a list ofRoleResponseDTO.toResponseDTO(Role entity) Converts aRoleentity into aRoleResponseDTO.Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.alpaca.mapper.GenericMapper
toPageResponseDTO
-
Field Details
-
permissionMapper
-
permissionService
-
-
Constructor Details
-
RoleMapperImpl
public RoleMapperImpl()
-
-
Method Details
-
toResponseDTO
Converts aRoleentity into aRoleResponseDTO.- Specified by:
toResponseDTOin interfaceGenericMapper<Role,RoleResponseDTO, RoleRequestDTO> - Parameters:
entity- the role entity to convert, may benull.- Returns:
- the corresponding response DTO, or
nullif the input isnull.
-
toEntity
Converts aRoleRequestDTOinto aRoleentity.Permissions are resolved using the
IPermissionServiceto fetch the corresponding entities.- Specified by:
toEntityin interfaceGenericMapper<Role,RoleResponseDTO, RoleRequestDTO> - Parameters:
requestDTO- the request DTO containing role data, may benull.- Returns:
- the corresponding
Roleentity, ornullif the input isnull.
-
toListResponseDTO
Converts a collection ofRoleentities into a list ofRoleResponseDTO.If the collection contains only one element, it is processed without iteration for optimization purposes.
- Specified by:
toListResponseDTOin interfaceGenericMapper<Role,RoleResponseDTO, RoleRequestDTO> - Parameters:
entities- the collection of role entities, may benullor empty.- Returns:
- a list of response DTOs, or an empty list if the input is
nullor empty.
-