SudokuFX
Loading...
Searching...
No Matches
fr.softsf.sudokufx.service.business.PlayerService Class Reference

Service for managing Player entities. More...

Collaboration diagram for fr.softsf.sudokufx.service.business.PlayerService:

Public Member Functions

 PlayerService (PlayerRepository playerRepository, PlayerLanguageRepository playerLanguageRepository, OptionsRepository optionsRepository, MenuRepository menuRepository, GameRepository gameRepository, GridRepository gridRepository, IPlayerMapper playerMapper, OptionsService optionsService, GridService gridService, GameLevelService gameLevelService, JakartaValidator jakartaValidator)
 Constructs a new PlayerService with the required infrastructure, service, and mapping dependencies.
void createNewPlayerWithCurrent (PlayerDto dto, String newName)
 Creates a new player by duplicating the configuration and current game state of the source player.
void deletePlayer (long playerIdToDelete)
 Deletes a player entity and ensures the system remains in a valid state.
PlayerDto getPlayer ()
 Retrieves and validates the first player with a selected game.
Collection< PlayerDto > getPlayers ()
 Retrieves and validates all unselected players with a selected game.
void switchAndSelectNewPlayer (long oldPlayerId, long newPlayerId)
 Atomically switches the selected player status.
PlayerDto updatePlayer (PlayerDto dto)
 Updates an existing player and its associated nested entities (language, options, menu, and game state).

Static Public Attributes

static final String PLAYER_NOT_FOUND = "Player not found: "

Package Functions

private< T, K > T findOrThrow (CrudRepository< T, K > repo, K k, String entityName)
 Retrieves an entity by its identifier from the provided repository or throws an exception if not found.

Private Member Functions

void updatePlayerSelection (long playerId, boolean selected)
 Internal utility to update player selection state and persist changes.

Private Attributes

final GameLevelService gameLevelService
final GameRepository gameRepository
final GridRepository gridRepository
final GridService gridService
final JakartaValidator jakartaValidator
final MenuRepository menuRepository
final OptionsRepository optionsRepository
final OptionsService optionsService
final PlayerLanguageRepository playerLanguageRepository
final IPlayerMapper playerMapper
final PlayerRepository playerRepository

Detailed Description

Service for managing Player entities.

Provides retrieval and update operations on players, mapping entities to PlayerDto and validating DTOs with JakartaValidator before and after persistence.

Methods:

  • getPlayer(): retrieves the first selected player with a selected game, read-only transactional.
  • updatePlayer(PlayerDto): updates an existing player, validates input and output DTOs, fully transactional.

Throws NullPointerException for null DTOs, IllegalArgumentException if entities are missing, and jakarta.validation.ConstraintViolationException on validation failures.

Constructor & Destructor Documentation

◆ PlayerService()

fr.softsf.sudokufx.service.business.PlayerService.PlayerService ( PlayerRepository playerRepository,
PlayerLanguageRepository playerLanguageRepository,
OptionsRepository optionsRepository,
MenuRepository menuRepository,
GameRepository gameRepository,
GridRepository gridRepository,
IPlayerMapper playerMapper,
OptionsService optionsService,
GridService gridService,
GameLevelService gameLevelService,
JakartaValidator jakartaValidator )

Constructs a new PlayerService with the required infrastructure, service, and mapping dependencies.

Parameters
playerRepositorythe repository for Player entities
playerLanguageRepositorythe repository for PlayerLanguage entities
optionsRepositorythe repository for Options entities
menuRepositorythe repository for Menu entities
gameRepositorythe repository for Game entities
gridRepositorythe repository for Grid entities
playerMapperthe mapper used to convert Player entities to PlayerDto
optionsServicethe service providing Options duplication logic
gridServicethe service providing Grid duplication logic
gameLevelServicethe service providing GameLevel duplication logic
jakartaValidatorthe validator used to ensure data integrity of processed DTOs

Member Function Documentation

◆ createNewPlayerWithCurrent()

void fr.softsf.sudokufx.service.business.PlayerService.createNewPlayerWithCurrent ( PlayerDto dto,
String newName )

Creates a new player by duplicating the configuration and current game state of the source player.

The process clones Options and Grid resources, creates a new Player instance, and initializes a new Game linked to the original game level. The source player is then marked as unselected.

Business operations performed:

This method is fully transactional: all operations succeed or fail as a unit.

Parameters
dtothe source player DTO; must not be null
newNamethe name for the new player; must not be null or blank
Exceptions
IllegalArgumentExceptionif newName is null/blank, or if required entities are not found in the database
jakarta.validation.ConstraintViolationExceptionif validation fails on the resulting entities
Here is the call graph for this function:

◆ deletePlayer()

void fr.softsf.sudokufx.service.business.PlayerService.deletePlayer ( long playerIdToDelete)

Deletes a player entity and ensures the system remains in a valid state.

If the player being deleted is the currently selected player, the system automatically switches the selection to the anonymous player. Anonymized player accounts cannot be deleted.

Parameters
playerIdToDeletethe unique identifier of the player to be removed
Exceptions
IllegalArgumentExceptionif the player is not found, or if the anonymous player is missing during a mandatory selection switch
jakarta.validation.ConstraintViolationExceptionif validation fails after switching the selection to the anonymous player
Here is the call graph for this function:

◆ findOrThrow()

private< T, K > T fr.softsf.sudokufx.service.business.PlayerService.findOrThrow ( CrudRepository< T, K > repo,
K k,
String entityName )
package

Retrieves an entity by its identifier from the provided repository or throws an exception if not found.

This utility method standardizes error handling across the service layer when resolving database dependencies. It ensures that required entities are managed within the current transaction and throws a consistent exception if they are missing.

Parameters
<T>the type of the entity
<K>the type of the entity identifier
repothe CrudRepository used to query the entity
kthe identifier of the entity to retrieve
entityNamea descriptive name of the entity, used for error message construction
Returns
the managed entity instance
Exceptions
IllegalArgumentExceptionif the entity with the specified identifier does not exist

◆ getPlayer()

PlayerDto fr.softsf.sudokufx.service.business.PlayerService.getPlayer ( )

Retrieves and validates the first player with a selected game.

The player must have a non-null selected game and pass all Jakarta Bean Validation constraints.

Returns
a validated PlayerDto
Exceptions
IllegalArgumentExceptionif no matching player is found
ConstraintViolationExceptionif validation fails on the mapped PlayerDto
Here is the call graph for this function:

◆ getPlayers()

Collection< PlayerDto > fr.softsf.sudokufx.service.business.PlayerService.getPlayers ( )

Retrieves and validates all unselected players with a selected game.

The players are sorted alphabetically by name. Each player must pass all Jakarta Bean Validation constraints.

Returns
a sorted collection of validated PlayerDto elements, or an empty collection if none found
Exceptions
ConstraintViolationExceptionif validation fails on any mapped PlayerDto
Here is the call graph for this function:

◆ switchAndSelectNewPlayer()

void fr.softsf.sudokufx.service.business.PlayerService.switchAndSelectNewPlayer ( long oldPlayerId,
long newPlayerId )

Atomically switches the selected player status.

Ensures data consistency by unselecting the previous player and selecting the new one within a single database transaction.

Parameters
oldPlayerIdthe identifier of the player to be unselected
newPlayerIdthe identifier of the player to be selected
Exceptions
IllegalArgumentExceptionif either player is not found
jakarta.validation.ConstraintViolationExceptionif validation fails
Here is the call graph for this function:

◆ updatePlayer()

PlayerDto fr.softsf.sudokufx.service.business.PlayerService.updatePlayer ( PlayerDto dto)

Updates an existing player and its associated nested entities (language, options, menu, and game state).

Performs validation on the input DTO, retrieves required associations, and applies updates to the persistent entity. Uses JPA dirty checking within a single transaction to ensure atomicity. If a selectedGame is provided, associated game, level, and grid state are also synchronized.

Parameters
dtothe player data containing updated fields and nested DTOs; must not be null
Returns
the persisted and validated PlayerDto representing the updated state
Exceptions
NullPointerExceptionif dto is null
IllegalArgumentExceptionif the player or any required nested entity is missing
ConstraintViolationExceptionif post-update validation fails
Here is the call graph for this function:

◆ updatePlayerSelection()

void fr.softsf.sudokufx.service.business.PlayerService.updatePlayerSelection ( long playerId,
boolean selected )
private

Internal utility to update player selection state and persist changes.

Parameters
playerIdthe identifier of the player to update
selectedthe new selection state
Exceptions
IllegalArgumentExceptionif the player does not exist
Here is the call graph for this function:

Member Data Documentation

◆ gameLevelService

final GameLevelService fr.softsf.sudokufx.service.business.PlayerService.gameLevelService
private

◆ gameRepository

final GameRepository fr.softsf.sudokufx.service.business.PlayerService.gameRepository
private

◆ gridRepository

final GridRepository fr.softsf.sudokufx.service.business.PlayerService.gridRepository
private

◆ gridService

final GridService fr.softsf.sudokufx.service.business.PlayerService.gridService
private

◆ jakartaValidator

final JakartaValidator fr.softsf.sudokufx.service.business.PlayerService.jakartaValidator
private

◆ menuRepository

final MenuRepository fr.softsf.sudokufx.service.business.PlayerService.menuRepository
private

◆ optionsRepository

final OptionsRepository fr.softsf.sudokufx.service.business.PlayerService.optionsRepository
private

◆ optionsService

final OptionsService fr.softsf.sudokufx.service.business.PlayerService.optionsService
private

◆ PLAYER_NOT_FOUND

final String fr.softsf.sudokufx.service.business.PlayerService.PLAYER_NOT_FOUND = "Player not found: "
static

◆ playerLanguageRepository

final PlayerLanguageRepository fr.softsf.sudokufx.service.business.PlayerService.playerLanguageRepository
private

◆ playerMapper

final IPlayerMapper fr.softsf.sudokufx.service.business.PlayerService.playerMapper
private

◆ playerRepository

final PlayerRepository fr.softsf.sudokufx.service.business.PlayerService.playerRepository
private

The documentation for this class was generated from the following file: