Class UserEntity

java.lang.Object
com.app.persistence.entity.BaseEntity
com.app.persistence.entity.UserEntity

@Entity public class UserEntity extends BaseEntity
Represents a user in the system. This entity maps to the "users" table in the database. Extends BaseEntity to inherit the ID.
  • Constructor Details

    • UserEntity

      public UserEntity()
  • Method Details

    • UserEntityWithHolidays

      public UserEntity UserEntityWithHolidays(long holidaysHours)
      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

      public UserEntity withPassword(String password)
      Returns a new UserEntity instance with the specified password.
      Parameters:
      password - new password
      Returns:
      new UserEntity with updated password
    • withActivation

      public UserEntity withActivation()
      Returns a new UserEntity instance with account enabled.
      Returns:
      new UserEntity with enable = true
    • withDeactivation

      public UserEntity withDeactivation()
      Returns a new UserEntity instance with account disabled.
      Returns:
      new UserEntity with enable = false
    • withDelete

      public UserEntity 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

      public UserEntity withNewEmail(String email)
      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

      public UserEntity withNewRoleAndNewHolidaysHours(Long holidaysHours, Role role)
      Returns a new UserEntity with updated role and holiday hours, account enabled.
      Parameters:
      holidaysHours - new holiday hours
      role - new user role
      Returns:
      new UserEntity with updated role and holidaysHours
    • toUserDto

      public UserDto toUserDto()
      Converts this entity to a UserDto.
      Returns:
      UserDto with this user's data
    • toUserDetailsDto

      public UserDetailsDto toUserDetailsDto()
      Converts this entity to UserDetailsDto used for security authentication.
      Returns:
      UserDetailsDto with username, password, enable flag and role
    • toUsernamePasswordAuthenticationTokenDto

      public UsernamePasswordAuthenticationTokenDto 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