Fix: Checkstyle Line length for MR Pipeline
This commit is contained in:
+16
-26
@@ -14,20 +14,13 @@ import java.util.Optional;
|
|||||||
/**
|
/**
|
||||||
* Handler for the `RAISE` command.
|
* Handler for the `RAISE` command.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>This handler validates the request (amount >= 0), resolves the user and target lobby (by
|
||||||
* This handler validates the request (amount >= 0), resolves the user and
|
* `GAME_ID` when provided or by session username otherwise), checks that a game is running and then
|
||||||
* target lobby (by
|
|
||||||
* `GAME_ID` when provided or by session username otherwise), checks that a game
|
|
||||||
* is running and then
|
|
||||||
* forwards the action to the {@code GameController}.
|
* forwards the action to the {@code GameController}.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>On failure the handler dispatches an {@link ErrorResponse} with an appropriate error code
|
||||||
* On failure the handler dispatches an {@link ErrorResponse} with an
|
* (e.g. {@code INVALID_AMOUNT}, {@code NOT_IN_LOBBY}, {@code LOBBY_NOT_FOUND}, {@code
|
||||||
* appropriate error code
|
* GAME_NOT_STARTED}, {@code GAME_ACTION_FAILED}). On success it dispatches an {@link OkResponse}.
|
||||||
* (e.g. {@code INVALID_AMOUNT}, {@code NOT_IN_LOBBY}, {@code LOBBY_NOT_FOUND},
|
|
||||||
* {@code
|
|
||||||
* GAME_NOT_STARTED}, {@code GAME_ACTION_FAILED}). On success it dispatches an
|
|
||||||
* {@link OkResponse}.
|
|
||||||
*/
|
*/
|
||||||
public class PlayerRaiseHandler extends CommandHandler<PlayerRaiseRequest> {
|
public class PlayerRaiseHandler extends CommandHandler<PlayerRaiseRequest> {
|
||||||
private final UserRegistry userRegistry;
|
private final UserRegistry userRegistry;
|
||||||
@@ -36,11 +29,9 @@ public class PlayerRaiseHandler extends CommandHandler<PlayerRaiseRequest> {
|
|||||||
/**
|
/**
|
||||||
* Creates a new {@code PlayerRaiseHandler}.
|
* Creates a new {@code PlayerRaiseHandler}.
|
||||||
*
|
*
|
||||||
* @param responseDispatcher dispatcher used to send responses back to the
|
* @param responseDispatcher dispatcher used to send responses back to the client
|
||||||
* client
|
* @param userRegistry registry to resolve users from session ids
|
||||||
* @param userRegistry registry to resolve users from session ids
|
* @param lobbyManager manager used to lookup lobbies and their game controllers
|
||||||
* @param lobbyManager manager used to lookup lobbies and their game
|
|
||||||
* controllers
|
|
||||||
*/
|
*/
|
||||||
public PlayerRaiseHandler(
|
public PlayerRaiseHandler(
|
||||||
ResponseDispatcher responseDispatcher,
|
ResponseDispatcher responseDispatcher,
|
||||||
@@ -52,10 +43,8 @@ public class PlayerRaiseHandler extends CommandHandler<PlayerRaiseRequest> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the raise request: validate parameters, resolve lobby and game, and
|
* Execute the raise request: validate parameters, resolve lobby and game, and forward the raise
|
||||||
* forward the raise
|
* action to the game controller. Sends an {@link ErrorResponse} on failure or an {@link
|
||||||
* action to the game controller. Sends an {@link ErrorResponse} on failure or
|
|
||||||
* an {@link
|
|
||||||
* OkResponse} on success.
|
* OkResponse} on success.
|
||||||
*
|
*
|
||||||
* @param request the parsed {@link PlayerRaiseRequest}
|
* @param request the parsed {@link PlayerRaiseRequest}
|
||||||
@@ -71,8 +60,8 @@ public class PlayerRaiseHandler extends CommandHandler<PlayerRaiseRequest> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<ch.unibas.dmi.dbis.cs108.casono.server.domain.user.User> opt = userRegistry
|
Optional<ch.unibas.dmi.dbis.cs108.casono.server.domain.user.User> opt =
|
||||||
.getBySessionId(request.getSessionId());
|
userRegistry.getBySessionId(request.getSessionId());
|
||||||
if (opt.isEmpty()) {
|
if (opt.isEmpty()) {
|
||||||
responseDispatcher.dispatch(
|
responseDispatcher.dispatch(
|
||||||
new ErrorResponse(request.getContext(), "NOT_LOGGED_IN", "User not logged in"));
|
new ErrorResponse(request.getContext(), "NOT_LOGGED_IN", "User not logged in"));
|
||||||
@@ -82,9 +71,10 @@ public class PlayerRaiseHandler extends CommandHandler<PlayerRaiseRequest> {
|
|||||||
String username = opt.get().getName();
|
String username = opt.get().getName();
|
||||||
|
|
||||||
Integer gameId = request.getGameId();
|
Integer gameId = request.getGameId();
|
||||||
var lobby = (gameId != null)
|
var lobby =
|
||||||
? lobbyManager.getLobby(LobbyId.of(gameId))
|
(gameId != null)
|
||||||
: lobbyManager.getLobbyByUsername(username);
|
? lobbyManager.getLobby(LobbyId.of(gameId))
|
||||||
|
: lobbyManager.getLobbyByUsername(username);
|
||||||
|
|
||||||
if (lobby == null) {
|
if (lobby == null) {
|
||||||
if (gameId != null) {
|
if (gameId != null) {
|
||||||
|
|||||||
+5
-6
@@ -7,19 +7,18 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.accessor.
|
|||||||
/**
|
/**
|
||||||
* Parser for the `RAISE` command.
|
* Parser for the `RAISE` command.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>Parses the request parameters and builds a {@link PlayerRaiseRequest}. Expected parameters:
|
||||||
* Parses the request parameters and builds a {@link PlayerRaiseRequest}.
|
|
||||||
* Expected parameters:
|
|
||||||
*
|
*
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>`GAME_ID` (optional) - numeric id of the lobby/game to target
|
* <li>`GAME_ID` (optional) - numeric id of the lobby/game to target
|
||||||
* <li>`AMOUNT` (required) - amount to raise
|
* <li>`AMOUNT` (required) - amount to raise
|
||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
public class PlayerRaiseParser implements CommandParser<PlayerRaiseRequest> {
|
public class PlayerRaiseParser implements CommandParser<PlayerRaiseRequest> {
|
||||||
@Override
|
@Override
|
||||||
public PlayerRaiseRequest parse(PrimitiveRequest primitiveRequest) {
|
public PlayerRaiseRequest parse(PrimitiveRequest primitiveRequest) {
|
||||||
RequestParameterAccessor accessor = new RequestParameterAccessor(primitiveRequest.parameters());
|
RequestParameterAccessor accessor =
|
||||||
|
new RequestParameterAccessor(primitiveRequest.parameters());
|
||||||
|
|
||||||
Integer gameId = null;
|
Integer gameId = null;
|
||||||
try {
|
try {
|
||||||
|
|||||||
+3
-5
@@ -6,9 +6,7 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.RequestCo
|
|||||||
/**
|
/**
|
||||||
* Request for the `RAISE` command.
|
* Request for the `RAISE` command.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>Contains the optional target `gameId` and the `amount` the player wants to raise.
|
||||||
* Contains the optional target `gameId` and the `amount` the player wants to
|
|
||||||
* raise.
|
|
||||||
*/
|
*/
|
||||||
public class PlayerRaiseRequest extends Request {
|
public class PlayerRaiseRequest extends Request {
|
||||||
private final Integer gameId;
|
private final Integer gameId;
|
||||||
@@ -18,8 +16,8 @@ public class PlayerRaiseRequest extends Request {
|
|||||||
* Creates a new {@code PlayerRaiseRequest}.
|
* Creates a new {@code PlayerRaiseRequest}.
|
||||||
*
|
*
|
||||||
* @param context the request context
|
* @param context the request context
|
||||||
* @param gameId optional game id of the targeted lobby (may be {@code null})
|
* @param gameId optional game id of the targeted lobby (may be {@code null})
|
||||||
* @param amount the raise amount (non-negative)
|
* @param amount the raise amount (non-negative)
|
||||||
*/
|
*/
|
||||||
public PlayerRaiseRequest(RequestContext context, Integer gameId, int amount) {
|
public PlayerRaiseRequest(RequestContext context, Integer gameId, int amount) {
|
||||||
super(context);
|
super(context);
|
||||||
|
|||||||
Reference in New Issue
Block a user