Class UserEntity
java.lang.Object
com.app.persistence.entity.BaseEntity
com.app.persistence.entity.UserEntity
Represents a user in the system.
This entity maps to the "users" table in the database.
Extends
BaseEntity
to inherit the ID.-
Field Summary
Fields inherited from class com.app.persistence.entity.BaseEntity
id
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
isAdmin()
Checks if the user has the admin role.Converts this entity to UserDetailsDto used for security authentication.Converts this entity to a UserDto.Converts this entity to UsernamePasswordAuthenticationTokenDto, which contains the username and role string.UserEntityWithHolidays
(long holidaysHours) Returns a new UserEntity instance with updated holiday hours (incremented).Returns a new UserEntity instance with account enabled.Returns a new UserEntity instance with account disabled.Returns a new UserEntity instance representing a deleted user.withNewEmail
(String email) Returns a new UserEntity instance with a new email and account enabled.withNewRoleAndNewHolidaysHours
(Long holidaysHours, Role role) Returns a new UserEntity with updated role and holiday hours, account enabled.withPassword
(String password) Returns a new UserEntity instance with the specified password.Methods inherited from class com.app.persistence.entity.BaseEntity
equals, hashCode
-
Constructor Details
-
UserEntity
public UserEntity()
-
-
Method Details
-
UserEntityWithHolidays
Returns a new UserEntity instance with updated holiday hours (incremented). Copies all other fields from the current instance.- Parameters:
holidaysHours
- the amount of holiday hours to add- Returns:
- a new UserEntity with updated holidaysHours
-
withPassword
Returns a new UserEntity instance with the specified password.- Parameters:
password
- new password- Returns:
- new UserEntity with updated password
-
withActivation
Returns a new UserEntity instance with account enabled.- Returns:
- new UserEntity with enable = true
-
withDeactivation
Returns a new UserEntity instance with account disabled.- Returns:
- new UserEntity with enable = false
-
withDelete
Returns a new UserEntity instance representing a deleted user. Email is suffixed with "-delete" and account is disabled.- Returns:
- new UserEntity marked as deleted
-
withNewEmail
Returns a new UserEntity instance with a new email and account enabled.- Parameters:
email
- new email address- Returns:
- new UserEntity with updated email and enabled
-
withNewRoleAndNewHolidaysHours
Returns a new UserEntity with updated role and holiday hours, account enabled.- Parameters:
holidaysHours
- new holiday hoursrole
- new user role- Returns:
- new UserEntity with updated role and holidaysHours
-
toUserDto
Converts this entity to a UserDto.- Returns:
- UserDto with this user's data
-
toUserDetailsDto
Converts this entity to UserDetailsDto used for security authentication.- Returns:
- UserDetailsDto with username, password, enable flag and role
-
toUsernamePasswordAuthenticationTokenDto
Converts this entity to UsernamePasswordAuthenticationTokenDto, which contains the username and role string.- Returns:
- UsernamePasswordAuthenticationTokenDto with username and role
-
isAdmin
public boolean isAdmin()Checks if the user has the admin role.- Returns:
- true if user role is ROLE_ADMIN, false otherwise
-