Service for managing Player entities.
More...
|
| | 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).
|
|
| 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.
|
|
| void | updatePlayerSelection (long playerId, boolean selected) |
| | Internal utility to update player selection state and persist changes.
|
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.
◆ 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
-
| playerRepository | the repository for Player entities |
| playerLanguageRepository | the repository for PlayerLanguage entities |
| optionsRepository | the repository for Options entities |
| menuRepository | the repository for Menu entities |
| gameRepository | the repository for Game entities |
| gridRepository | the repository for Grid entities |
| playerMapper | the mapper used to convert Player entities to PlayerDto |
| optionsService | the service providing Options duplication logic |
| gridService | the service providing Grid duplication logic |
| gameLevelService | the service providing GameLevel duplication logic |
| jakartaValidator | the validator used to ensure data integrity of processed DTOs |
◆ 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
-
| dto | the source player DTO; must not be null |
| newName | the name for the new player; must not be null or blank |
- Exceptions
-
| IllegalArgumentException | if newName is null/blank, or if required entities are not found in the database |
| jakarta.validation.ConstraintViolationException | if validation fails on the resulting entities |
◆ 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
-
| playerIdToDelete | the unique identifier of the player to be removed |
- Exceptions
-
| IllegalArgumentException | if the player is not found, or if the anonymous player is missing during a mandatory selection switch |
| jakarta.validation.ConstraintViolationException | if validation fails after switching the selection to the anonymous player |
◆ 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 |
| repo | the CrudRepository used to query the entity |
| k | the identifier of the entity to retrieve |
| entityName | a descriptive name of the entity, used for error message construction |
- Returns
- the managed entity instance
- Exceptions
-
| IllegalArgumentException | if 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
-
| IllegalArgumentException | if no matching player is found |
| ConstraintViolationException | if validation fails on the mapped PlayerDto |
◆ 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
-
| ConstraintViolationException | if validation fails on any mapped PlayerDto |
◆ 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
-
| oldPlayerId | the identifier of the player to be unselected |
| newPlayerId | the identifier of the player to be selected |
- Exceptions
-
| IllegalArgumentException | if either player is not found |
| jakarta.validation.ConstraintViolationException | if validation fails |
◆ 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
-
| dto | the player data containing updated fields and nested DTOs; must not be null |
- Returns
- the persisted and validated
PlayerDto representing the updated state
- Exceptions
-
| NullPointerException | if dto is null |
| IllegalArgumentException | if the player or any required nested entity is missing |
| ConstraintViolationException | if post-update validation fails |
◆ 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
-
| playerId | the identifier of the player to update |
| selected | the new selection state |
- Exceptions
-
| IllegalArgumentException | if the player does not exist |
◆ 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
◆ 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: