backend: handle corda errors as HTTP_BAD_REQ (#46)

Reviewed-on: http://192.168.8.55:3000/HQLAx/CordaCheckers/pulls/46
This commit is contained in:
djmil 2023-11-30 11:48:57 +01:00
parent 77eb2d0013
commit 3bcf5ced76
10 changed files with 189 additions and 144 deletions

View File

@ -4,6 +4,7 @@ import java.util.List;
import java.util.UUID; import java.util.UUID;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@ -12,14 +13,15 @@ import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ResponseStatusException;
import djmil.cordacheckers.cordaclient.CordaClient; import djmil.cordacheckers.cordaclient.CordaClient;
import djmil.cordacheckers.cordaclient.dao.GameView; import djmil.cordacheckers.cordaclient.dao.GameView;
import djmil.cordacheckers.cordaclient.dao.flow.arguments.ReqGameBoardMove; import djmil.cordacheckers.cordaclient.dao.flow.arguments.ReqGameBoardMove;
import djmil.cordacheckers.cordaclient.dao.flow.arguments.RspFailureException;
import djmil.cordacheckers.user.HoldingIdentityResolver; import djmil.cordacheckers.user.HoldingIdentityResolver;
import djmil.cordacheckers.user.User; import djmil.cordacheckers.user.User;
@RestController @RestController
@RequestMapping("api/game") @RequestMapping("api/game")
public class GameController { public class GameController {
@ -32,83 +34,95 @@ public class GameController {
@GetMapping @GetMapping
public ResponseEntity<List<GameView>> list( public ResponseEntity<List<GameView>> list(
@AuthenticationPrincipal User player @AuthenticationPrincipal User player) {
) { try {
final List<GameView> gsList = cordaClient.gameStateList(player.getHoldingIdentity()); final List<GameView> gsList = cordaClient.gameStateList(
player.getHoldingIdentity());
return ResponseEntity.ok(gsList); return ResponseEntity.ok(gsList);
} catch (RspFailureException e) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
}
} }
@PutMapping("/{uuid}/surrender") @PutMapping("/{uuid}/surrender")
public ResponseEntity<GameView> surrender( public ResponseEntity<GameView> surrender(
@AuthenticationPrincipal User issuer, @AuthenticationPrincipal User issuer,
@PathVariable UUID uuid @PathVariable UUID uuid) {
) { try {
final GameView finishedGame = cordaClient.gameBoardSurrender( final GameView finishedGame = cordaClient.gameBoardSurrender(
issuer.getHoldingIdentity(), issuer.getHoldingIdentity(),
uuid uuid);
);
return ResponseEntity return ResponseEntity.ok(finishedGame);
.ok(finishedGame);
} catch (RspFailureException e) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
}
} }
@PutMapping("/{uuid}/drawreq") @PutMapping("/{uuid}/drawreq")
public ResponseEntity<GameView> drawRequest( public ResponseEntity<GameView> drawRequest(
@AuthenticationPrincipal User issuer, @AuthenticationPrincipal User issuer,
@PathVariable UUID uuid @PathVariable UUID uuid) {
) { try {
final GameView drawReqGame = cordaClient.gameDrawRequest( final GameView drawReqGame = cordaClient.gameDrawRequest(
issuer.getHoldingIdentity(), issuer.getHoldingIdentity(),
uuid uuid);
);
return ResponseEntity return ResponseEntity.ok(drawReqGame);
.ok(drawReqGame); } catch (RspFailureException e) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
}
} }
@PutMapping("/{uuid}/drawacc") @PutMapping("/{uuid}/drawacc")
public ResponseEntity<GameView> drawAccept( public ResponseEntity<GameView> drawAccept(
@AuthenticationPrincipal User issuer, @AuthenticationPrincipal User issuer,
@PathVariable UUID uuid @PathVariable UUID uuid) {
) { try {
final GameView drawAccGame = cordaClient.gameDrawAccept( final GameView drawAccGame = cordaClient.gameDrawAccept(
issuer.getHoldingIdentity(), issuer.getHoldingIdentity(),
uuid uuid);
);
return ResponseEntity return ResponseEntity.ok(drawAccGame);
.ok(drawAccGame); } catch (RspFailureException e) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
}
} }
@PutMapping("/{uuid}/drawrej") @PutMapping("/{uuid}/drawrej")
public ResponseEntity<GameView> drawReject( public ResponseEntity<GameView> drawReject(
@AuthenticationPrincipal User issuer, @AuthenticationPrincipal User issuer,
@PathVariable UUID uuid @PathVariable UUID uuid) {
) { try {
final GameView drawRejGame = cordaClient.gameDrawReject( final GameView drawRejGame = cordaClient.gameDrawReject(
issuer.getHoldingIdentity(), issuer.getHoldingIdentity(),
uuid uuid);
);
return ResponseEntity return ResponseEntity
.ok(drawRejGame); .ok(drawRejGame);
} catch (RspFailureException e) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
}
} }
@PutMapping("/{uuid}/move") @PutMapping("/{uuid}/move")
public ResponseEntity<GameView> move( public ResponseEntity<GameView> move(
@AuthenticationPrincipal User issuer, @AuthenticationPrincipal User issuer,
@PathVariable UUID uuid, @PathVariable UUID uuid,
@RequestBody ReqGameBoardMove request @RequestBody ReqGameBoardMove request) {
) { try {
final GameView movedGame = cordaClient.gameBoardMove( final GameView movedGame = cordaClient.gameBoardMove(
issuer.getHoldingIdentity(), issuer.getHoldingIdentity(),
uuid, uuid,
request.move(), request.move(),
request.message() request.message());
);
return ResponseEntity return ResponseEntity
.ok(movedGame); .ok(movedGame);
} catch (RspFailureException e) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
}
} }
} }

View File

@ -4,6 +4,7 @@ import java.net.URI;
import java.util.UUID; import java.util.UUID;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
@ -12,6 +13,7 @@ import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ResponseStatusException;
import org.springframework.web.util.UriComponentsBuilder; import org.springframework.web.util.UriComponentsBuilder;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
@ -22,6 +24,7 @@ import djmil.cordacheckers.cordaclient.dao.GameView;
import djmil.cordacheckers.cordaclient.dao.HoldingIdentity; import djmil.cordacheckers.cordaclient.dao.HoldingIdentity;
import djmil.cordacheckers.cordaclient.dao.Stone; import djmil.cordacheckers.cordaclient.dao.Stone;
import djmil.cordacheckers.cordaclient.dao.flow.arguments.ReqGameProposalCreate; import djmil.cordacheckers.cordaclient.dao.flow.arguments.ReqGameProposalCreate;
import djmil.cordacheckers.cordaclient.dao.flow.arguments.RspFailureException;
import djmil.cordacheckers.user.HoldingIdentityResolver; import djmil.cordacheckers.user.HoldingIdentityResolver;
import djmil.cordacheckers.user.User; import djmil.cordacheckers.user.User;
@ -39,69 +42,78 @@ public class GameProposalController {
public ResponseEntity<GameView> create( public ResponseEntity<GameView> create(
@AuthenticationPrincipal User sender, @AuthenticationPrincipal User sender,
@RequestBody ReqGameProposalCreate gpRequest, @RequestBody ReqGameProposalCreate gpRequest,
UriComponentsBuilder ucb) throws JsonMappingException, JsonProcessingException UriComponentsBuilder ucb) throws JsonMappingException, JsonProcessingException {
{ try {
final HoldingIdentity gpSender = sender.getHoldingIdentity(); final HoldingIdentity gpSender = sender.getHoldingIdentity();
final HoldingIdentity gpReceiver = holdingIdentityResolver.getByUsername(gpRequest.opponentName()); final HoldingIdentity gpReceiver = holdingIdentityResolver.getByUsername(gpRequest.opponentName());
final Stone.Color gpReceiverColor = gpRequest.opponentColor(); final Stone.Color gpReceiverColor = gpRequest.opponentColor();
// GiteaIssue #4: Exception handling // GiteaIssue #4: Exception handling
GameView gameStateView = cordaClient.gameProposalCreate( GameView gameStateView = cordaClient.gameProposalCreate(
gpSender, gpSender,
gpReceiver, gpReceiver,
gpReceiverColor, gpReceiverColor,
gpRequest.board(), gpRequest.board(),
gpRequest.message()); gpRequest.message());
URI locationOfNewGameProposal = ucb URI locationOfNewGameProposal = ucb
.path("api/gameproposal/{id}") .path("api/gameproposal/{id}")
.buildAndExpand(gameStateView.uuid()) .buildAndExpand(gameStateView.uuid())
.toUri(); .toUri();
return ResponseEntity return ResponseEntity
.created(locationOfNewGameProposal) .created(locationOfNewGameProposal)
.body(gameStateView); .body(gameStateView);
} catch (RspFailureException e) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
}
} }
@PutMapping("/{uuid}/cancel") @PutMapping("/{uuid}/cancel")
public ResponseEntity<GameView> cancel( public ResponseEntity<GameView> cancel(
@AuthenticationPrincipal User issuer, @AuthenticationPrincipal User issuer,
@PathVariable UUID uuid @PathVariable UUID uuid) {
) { try {
final GameView canceledGameView = cordaClient.gameProposalCancel( final GameView canceledGameView = cordaClient.gameProposalCancel(
issuer.getHoldingIdentity(), issuer.getHoldingIdentity(),
uuid uuid);
);
return ResponseEntity return ResponseEntity
.ok(canceledGameView); .ok(canceledGameView);
} catch (RspFailureException e) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
}
} }
@PutMapping("/{uuid}/reject") @PutMapping("/{uuid}/reject")
public ResponseEntity<GameView> reject( public ResponseEntity<GameView> reject(
@AuthenticationPrincipal User issuer, @AuthenticationPrincipal User issuer,
@PathVariable UUID uuid @PathVariable UUID uuid) {
) { try {
final GameView rejectedGameView = cordaClient.gameProposalReject( final GameView rejectedGameView = cordaClient.gameProposalReject(
issuer.getHoldingIdentity(), issuer.getHoldingIdentity(),
uuid uuid);
);
return ResponseEntity return ResponseEntity
.ok(rejectedGameView); .ok(rejectedGameView);
} catch (RspFailureException e) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
}
} }
@PutMapping("/{uuid}/accept") @PutMapping("/{uuid}/accept")
public ResponseEntity<GameView> accept( public ResponseEntity<GameView> accept(
@AuthenticationPrincipal User issuer, @AuthenticationPrincipal User issuer,
@PathVariable UUID uuid @PathVariable UUID uuid) {
) { try {
final GameView acceptedGameView = cordaClient.gameProposalAccept( final GameView acceptedGameView = cordaClient.gameProposalAccept(
issuer.getHoldingIdentity(), issuer.getHoldingIdentity(),
uuid uuid);
);
return ResponseEntity return ResponseEntity
.ok(acceptedGameView); .ok(acceptedGameView);
} catch (RspFailureException e) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
}
} }
} }

View File

@ -3,13 +3,17 @@ package djmil.cordacheckers.api;
import java.util.Map; import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ResponseStatusException;
import djmil.cordacheckers.cordaclient.CordaClient; import djmil.cordacheckers.cordaclient.CordaClient;
import djmil.cordacheckers.cordaclient.dao.Rank; import djmil.cordacheckers.cordaclient.dao.Rank;
import djmil.cordacheckers.cordaclient.dao.flow.arguments.RspFailureException;
import djmil.cordacheckers.user.HoldingIdentityResolver; import djmil.cordacheckers.user.HoldingIdentityResolver;
@ -25,10 +29,14 @@ public class LeaderboardController {
@GetMapping @GetMapping
public ResponseEntity<Map<String, Rank>> getLeaderboard() { public ResponseEntity<Map<String, Rank>> getLeaderboard() {
final var hiCustodian = holdingIdentityResolver.getCustodian(); try {
final Map<String, Rank> leaderboard = cordaClient.fetchRanking(hiCustodian); final var hiCustodian = holdingIdentityResolver.getCustodian();
final Map<String, Rank> leaderboard = cordaClient.fetchRanking(hiCustodian);
return ResponseEntity.ok(leaderboard); return ResponseEntity.ok(leaderboard);
} catch (RspFailureException e) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
}
} }
} }

View File

@ -28,6 +28,7 @@ import djmil.cordacheckers.cordaclient.dao.flow.RequestBody;
import djmil.cordacheckers.cordaclient.dao.flow.ResponseBody; import djmil.cordacheckers.cordaclient.dao.flow.ResponseBody;
import djmil.cordacheckers.cordaclient.dao.flow.arguments.Req; import djmil.cordacheckers.cordaclient.dao.flow.arguments.Req;
import djmil.cordacheckers.cordaclient.dao.flow.arguments.Rsp; import djmil.cordacheckers.cordaclient.dao.flow.arguments.Rsp;
import djmil.cordacheckers.cordaclient.dao.flow.arguments.RspFailureException;
import djmil.cordacheckers.cordaclient.dao.flow.arguments.ReqGameBoardMove; import djmil.cordacheckers.cordaclient.dao.flow.arguments.ReqGameBoardMove;
import djmil.cordacheckers.cordaclient.dao.flow.arguments.ReqGameProposalCreate; import djmil.cordacheckers.cordaclient.dao.flow.arguments.ReqGameProposalCreate;
import djmil.cordacheckers.cordaclient.dao.flow.arguments.RspGameState; import djmil.cordacheckers.cordaclient.dao.flow.arguments.RspGameState;
@ -67,7 +68,7 @@ public class CordaClient {
} }
// use custodian holding identity to get ranking table of all players // use custodian holding identity to get ranking table of all players
public Map<String, Rank> fetchRanking(HoldingIdentity holdingIdentity) { public Map<String, Rank> fetchRanking(HoldingIdentity holdingIdentity) throws RspFailureException {
final RequestBody requestBody = new RequestBody( final RequestBody requestBody = new RequestBody(
"ranking-" +UUID.randomUUID(), "ranking-" +UUID.randomUUID(),
"djmil.cordacheckers.gameresult.RankingFlow", "djmil.cordacheckers.gameresult.RankingFlow",
@ -81,7 +82,7 @@ public class CordaClient {
* @param holdingIdentity * @param holdingIdentity
* @return list of unconsumed (active) GameStateViews * @return list of unconsumed (active) GameStateViews
*/ */
public List<GameView> gameStateList(HoldingIdentity holdingIdentity) { public List<GameView> gameStateList(HoldingIdentity holdingIdentity) throws RspFailureException {
final RequestBody requestBody = new RequestBody( final RequestBody requestBody = new RequestBody(
"gs.list-" + UUID.randomUUID(), "gs.list-" + UUID.randomUUID(),
"djmil.cordacheckers.gamestate.ListFlow", "djmil.cordacheckers.gamestate.ListFlow",
@ -91,7 +92,7 @@ public class CordaClient {
.getResponce(requestBody); .getResponce(requestBody);
} }
public GameView gameStateGet(HoldingIdentity holdingIdentity, UUID gameUuid) { public GameView gameStateGet(HoldingIdentity holdingIdentity, UUID gameUuid) throws RspFailureException {
final RequestBody requestBody = new RequestBody( final RequestBody requestBody = new RequestBody(
"gs.get-" + UUID.randomUUID(), "gs.get-" + UUID.randomUUID(),
"djmil.cordacheckers.gamestate.GetFlow", "djmil.cordacheckers.gamestate.GetFlow",
@ -102,13 +103,13 @@ public class CordaClient {
} }
public GameView gameProposalCreate(HoldingIdentity issuer, HoldingIdentity acquier, Stone.Color acquierColor, public GameView gameProposalCreate(HoldingIdentity issuer, HoldingIdentity acquier, Stone.Color acquierColor,
String message) { String message) throws RspFailureException {
return gameProposalCreate(issuer, acquier, acquierColor, GameView.defaultGameBoard, message); return gameProposalCreate(issuer, acquier, acquierColor, GameView.defaultGameBoard, message);
} }
public GameView gameProposalCreate(HoldingIdentity issuer, HoldingIdentity acquier, Stone.Color acquierColor, public GameView gameProposalCreate(HoldingIdentity issuer, HoldingIdentity acquier, Stone.Color acquierColor,
Map<Integer, Stone> board, String message) { Map<Integer, Stone> board, String message) throws RspFailureException {
final RequestBody requestBody = new RequestBody( final RequestBody requestBody = new RequestBody(
"gp.create-" + UUID.randomUUID(), "gp.create-" + UUID.randomUUID(),
"djmil.cordacheckers.gameproposal.CreateFlow", "djmil.cordacheckers.gameproposal.CreateFlow",
@ -122,7 +123,7 @@ public class CordaClient {
.getResponce(requestBody); .getResponce(requestBody);
} }
public GameView gameProposalReject(HoldingIdentity holdingIdentity, UUID gameUuid) { public GameView gameProposalReject(HoldingIdentity holdingIdentity, UUID gameUuid) throws RspFailureException {
final RequestBody requestBody = new RequestBody( final RequestBody requestBody = new RequestBody(
"gp.reject-" +UUID.randomUUID(), "gp.reject-" +UUID.randomUUID(),
"djmil.cordacheckers.gameproposal.RejectFlow", "djmil.cordacheckers.gameproposal.RejectFlow",
@ -132,7 +133,7 @@ public class CordaClient {
.getResponce(requestBody); .getResponce(requestBody);
} }
public GameView gameProposalCancel(HoldingIdentity holdingIdentity, UUID gameUuid) { public GameView gameProposalCancel(HoldingIdentity holdingIdentity, UUID gameUuid) throws RspFailureException {
final RequestBody requestBody = new RequestBody( final RequestBody requestBody = new RequestBody(
"gp.cancel-" +UUID.randomUUID(), "gp.cancel-" +UUID.randomUUID(),
"djmil.cordacheckers.gameproposal.CancelFlow", "djmil.cordacheckers.gameproposal.CancelFlow",
@ -142,7 +143,7 @@ public class CordaClient {
.getResponce(requestBody); .getResponce(requestBody);
} }
public GameView gameProposalAccept(HoldingIdentity holdingIdentity, UUID gameUuid) { public GameView gameProposalAccept(HoldingIdentity holdingIdentity, UUID gameUuid) throws RspFailureException {
final RequestBody requestBody = new RequestBody( final RequestBody requestBody = new RequestBody(
"gp.accept-" +UUID.randomUUID(), "gp.accept-" +UUID.randomUUID(),
"djmil.cordacheckers.gameproposal.AcceptFlow", "djmil.cordacheckers.gameproposal.AcceptFlow",
@ -152,7 +153,7 @@ public class CordaClient {
.getResponce(requestBody); .getResponce(requestBody);
} }
public GameView gameBoardSurrender(HoldingIdentity holdingIdentity, UUID gameUuid) { public GameView gameBoardSurrender(HoldingIdentity holdingIdentity, UUID gameUuid) throws RspFailureException {
final RequestBody requestBody = new RequestBody( final RequestBody requestBody = new RequestBody(
"gb.surrender-" +UUID.randomUUID(), "gb.surrender-" +UUID.randomUUID(),
"djmil.cordacheckers.gameboard.SurrenderFlow", "djmil.cordacheckers.gameboard.SurrenderFlow",
@ -163,7 +164,7 @@ public class CordaClient {
} }
public GameView gameBoardMove(HoldingIdentity holdingIdentity, UUID gameUuid, List<Integer> move, public GameView gameBoardMove(HoldingIdentity holdingIdentity, UUID gameUuid, List<Integer> move,
String message) { String message) throws RspFailureException {
final RequestBody requestBody = new RequestBody( final RequestBody requestBody = new RequestBody(
"gb.move-" +UUID.randomUUID(), "gb.move-" +UUID.randomUUID(),
"djmil.cordacheckers.gameboard.MoveFlow", "djmil.cordacheckers.gameboard.MoveFlow",
@ -174,7 +175,7 @@ public class CordaClient {
.getResponce(requestBody); .getResponce(requestBody);
} }
public GameView gameDrawRequest(HoldingIdentity holdingIdentity, UUID gameUuid) { public GameView gameDrawRequest(HoldingIdentity holdingIdentity, UUID gameUuid) throws RspFailureException {
final RequestBody requestBody = new RequestBody( final RequestBody requestBody = new RequestBody(
"gd.request-" +UUID.randomUUID(), "gd.request-" +UUID.randomUUID(),
"djmil.cordacheckers.gameboard.DrawRequestFlow", "djmil.cordacheckers.gameboard.DrawRequestFlow",
@ -184,7 +185,7 @@ public class CordaClient {
.getResponce(requestBody); .getResponce(requestBody);
} }
public GameView gameDrawAccept(HoldingIdentity holdingIdentity, UUID gameUuid) { public GameView gameDrawAccept(HoldingIdentity holdingIdentity, UUID gameUuid) throws RspFailureException {
final RequestBody requestBody = new RequestBody( final RequestBody requestBody = new RequestBody(
"gd.accept-" +UUID.randomUUID(), "gd.accept-" +UUID.randomUUID(),
"djmil.cordacheckers.gameboard.DrawAcceptFlow", "djmil.cordacheckers.gameboard.DrawAcceptFlow",
@ -194,7 +195,7 @@ public class CordaClient {
.getResponce(requestBody); .getResponce(requestBody);
} }
public GameView gameDrawReject(HoldingIdentity holdingIdentity, UUID gameUuid) { public GameView gameDrawReject(HoldingIdentity holdingIdentity, UUID gameUuid) throws RspFailureException {
final RequestBody requestBody = new RequestBody( final RequestBody requestBody = new RequestBody(
"gd.reject-" +UUID.randomUUID(), "gd.reject-" +UUID.randomUUID(),
"djmil.cordacheckers.gameboard.DrawRejectFlow", "djmil.cordacheckers.gameboard.DrawRejectFlow",

View File

@ -7,7 +7,7 @@ public interface Rsp <T> {
public T successStatus(); public T successStatus();
public String failureStatus(); public String failureStatus();
public default T getResponce(RequestBody requestBody) { public default T getResponce(RequestBody requestBody) throws RspFailureException {
if (failureStatus() == null) { if (failureStatus() == null) {
final var responce = successStatus(); final var responce = successStatus();
final String gameUuid = (responce instanceof GameView) final String gameUuid = (responce instanceof GameView)
@ -15,12 +15,11 @@ public interface Rsp <T> {
: ""; : "";
System.out.println(requestBody.clientRequestId() +" [OK] " +gameUuid); System.out.println(requestBody.clientRequestId() +" [OK] " +gameUuid);
return responce; return responce;
} }
System.err.println(requestBody.clientRequestId() +" has failed: " +failureStatus()); System.err.println(requestBody.clientRequestId() +" has failed: " +failureStatus());
throw new RuntimeException(failureStatus()); throw new RspFailureException(failureStatus());
} }
} }

View File

@ -0,0 +1,7 @@
package djmil.cordacheckers.cordaclient.dao.flow.arguments;
public class RspFailureException extends Exception {
public RspFailureException(String what) {
super(what);
}
}

View File

@ -13,6 +13,7 @@ import org.springframework.boot.test.context.SpringBootTest;
import djmil.cordacheckers.cordaclient.dao.GameView; import djmil.cordacheckers.cordaclient.dao.GameView;
import djmil.cordacheckers.cordaclient.dao.GameView.Status; import djmil.cordacheckers.cordaclient.dao.GameView.Status;
import djmil.cordacheckers.cordaclient.dao.flow.arguments.RspFailureException;
import djmil.cordacheckers.cordaclient.dao.Stone; import djmil.cordacheckers.cordaclient.dao.Stone;
import djmil.cordacheckers.user.HoldingIdentityResolver; import djmil.cordacheckers.user.HoldingIdentityResolver;
@ -44,7 +45,7 @@ public class GameBoardTests {
); );
@Test @Test
void testSurrender() { void testSurrender() throws RspFailureException {
final var hiWhite = holdingIdentityResolver.getByUsername(whitePlayerName); final var hiWhite = holdingIdentityResolver.getByUsername(whitePlayerName);
final var hiBlack = holdingIdentityResolver.getByUsername(blackPlayerName); final var hiBlack = holdingIdentityResolver.getByUsername(blackPlayerName);
@ -81,7 +82,7 @@ public class GameBoardTests {
} }
@Test @Test
void testMove() { void testMove() throws RspFailureException {
final var hiWhite = holdingIdentityResolver.getByUsername(whitePlayerName); final var hiWhite = holdingIdentityResolver.getByUsername(whitePlayerName);
final var hiBlack = holdingIdentityResolver.getByUsername(blackPlayerName); final var hiBlack = holdingIdentityResolver.getByUsername(blackPlayerName);
@ -193,7 +194,7 @@ public class GameBoardTests {
} }
@Test @Test
void testVictory_NoStones() { void testVictory_NoStones() throws RspFailureException {
final var hiWhite = holdingIdentityResolver.getByUsername(whitePlayerName); final var hiWhite = holdingIdentityResolver.getByUsername(whitePlayerName);
final var hiBlack = holdingIdentityResolver.getByUsername(blackPlayerName); final var hiBlack = holdingIdentityResolver.getByUsername(blackPlayerName);
@ -217,7 +218,7 @@ public class GameBoardTests {
} }
@Test @Test
void testVictory_StonesBlocked() { void testVictory_StonesBlocked() throws RspFailureException {
final var hiWhite = holdingIdentityResolver.getByUsername(whitePlayerName); final var hiWhite = holdingIdentityResolver.getByUsername(whitePlayerName);
final var hiBlack = holdingIdentityResolver.getByUsername(blackPlayerName); final var hiBlack = holdingIdentityResolver.getByUsername(blackPlayerName);
@ -241,7 +242,7 @@ public class GameBoardTests {
} }
@Test @Test
void testDrawRequest() { void testDrawRequest() throws RspFailureException {
final var hiWhite = holdingIdentityResolver.getByUsername(whitePlayerName); final var hiWhite = holdingIdentityResolver.getByUsername(whitePlayerName);
final var hiBlack = holdingIdentityResolver.getByUsername(blackPlayerName); final var hiBlack = holdingIdentityResolver.getByUsername(blackPlayerName);
@ -275,7 +276,7 @@ public class GameBoardTests {
} }
@Test @Test
void testDrawAccept() { void testDrawAccept() throws RspFailureException {
final var hiWhite = holdingIdentityResolver.getByUsername(whitePlayerName); final var hiWhite = holdingIdentityResolver.getByUsername(whitePlayerName);
final var hiBlack = holdingIdentityResolver.getByUsername(blackPlayerName); final var hiBlack = holdingIdentityResolver.getByUsername(blackPlayerName);
@ -311,7 +312,7 @@ public class GameBoardTests {
} }
@Test @Test
void testDrawReject() { void testDrawReject() throws RspFailureException {
final var hiWhite = holdingIdentityResolver.getByUsername(whitePlayerName); final var hiWhite = holdingIdentityResolver.getByUsername(whitePlayerName);
final var hiBlack = holdingIdentityResolver.getByUsername(blackPlayerName); final var hiBlack = holdingIdentityResolver.getByUsername(blackPlayerName);

View File

@ -10,6 +10,7 @@ import org.springframework.boot.test.context.SpringBootTest;
import djmil.cordacheckers.cordaclient.dao.GameView; import djmil.cordacheckers.cordaclient.dao.GameView;
import djmil.cordacheckers.cordaclient.dao.GameView.Status; import djmil.cordacheckers.cordaclient.dao.GameView.Status;
import djmil.cordacheckers.cordaclient.dao.flow.arguments.RspFailureException;
import djmil.cordacheckers.cordaclient.dao.Stone; import djmil.cordacheckers.cordaclient.dao.Stone;
import djmil.cordacheckers.user.HoldingIdentityResolver; import djmil.cordacheckers.user.HoldingIdentityResolver;
@ -26,7 +27,7 @@ public class GameProposalTests {
final Stone.Color acquierColor = Stone.Color.WHITE; final Stone.Color acquierColor = Stone.Color.WHITE;
@Test @Test
void testCreate() { void testCreate() throws RspFailureException {
final var hiIssuer = holdingIdentityResolver.getByUsername(issuer); final var hiIssuer = holdingIdentityResolver.getByUsername(issuer);
final var hiAcquier = holdingIdentityResolver.getByUsername(acquier); final var hiAcquier = holdingIdentityResolver.getByUsername(acquier);
final String message = "GameProposal CREATE test"; final String message = "GameProposal CREATE test";
@ -68,7 +69,7 @@ public class GameProposalTests {
} }
@Test @Test
void testReject() { void testReject() throws RspFailureException {
final var hiIssuer = holdingIdentityResolver.getByUsername(issuer); final var hiIssuer = holdingIdentityResolver.getByUsername(issuer);
final var hiAcquier = holdingIdentityResolver.getByUsername(acquier); final var hiAcquier = holdingIdentityResolver.getByUsername(acquier);
@ -97,7 +98,7 @@ public class GameProposalTests {
} }
@Test @Test
void testCancel() { void testCancel() throws RspFailureException {
final var hiIssuer = holdingIdentityResolver.getByUsername(issuer); final var hiIssuer = holdingIdentityResolver.getByUsername(issuer);
final var hiAcquier = holdingIdentityResolver.getByUsername(acquier); final var hiAcquier = holdingIdentityResolver.getByUsername(acquier);
@ -126,7 +127,7 @@ public class GameProposalTests {
} }
@Test @Test
void testAccept() { void testAccept() throws RspFailureException {
final var hiIssuer = holdingIdentityResolver.getByUsername(issuer); final var hiIssuer = holdingIdentityResolver.getByUsername(issuer);
final var hiAcquier = holdingIdentityResolver.getByUsername(acquier); final var hiAcquier = holdingIdentityResolver.getByUsername(acquier);

View File

@ -12,6 +12,7 @@ import org.springframework.boot.test.context.SpringBootTest;
import djmil.cordacheckers.cordaclient.dao.GameView; import djmil.cordacheckers.cordaclient.dao.GameView;
import djmil.cordacheckers.cordaclient.dao.Stone.Color; import djmil.cordacheckers.cordaclient.dao.Stone.Color;
import djmil.cordacheckers.cordaclient.dao.flow.arguments.RspFailureException;
import djmil.cordacheckers.user.HoldingIdentityResolver; import djmil.cordacheckers.user.HoldingIdentityResolver;
@SpringBootTest @SpringBootTest
@ -26,7 +27,7 @@ public class GameStateTests {
final String player2 = "bobik"; final String player2 = "bobik";
@Test @Test
void testList() { void testList() throws RspFailureException {
final var hiPlayer1 = holdingIdentityResolver.getByUsername(player1); final var hiPlayer1 = holdingIdentityResolver.getByUsername(player1);
final var hiPlayer2 = holdingIdentityResolver.getByUsername(player2); final var hiPlayer2 = holdingIdentityResolver.getByUsername(player2);
@ -46,7 +47,7 @@ public class GameStateTests {
} }
@Test @Test
void testGet() { void testGet() throws RspFailureException {
final var hiPlayer1 = holdingIdentityResolver.getByUsername(player1); final var hiPlayer1 = holdingIdentityResolver.getByUsername(player1);
final var hiPlayer2 = holdingIdentityResolver.getByUsername(player2); final var hiPlayer2 = holdingIdentityResolver.getByUsername(player2);

View File

@ -15,6 +15,7 @@ import org.springframework.boot.test.context.SpringBootTest;
import djmil.cordacheckers.cordaclient.dao.GameView; import djmil.cordacheckers.cordaclient.dao.GameView;
import djmil.cordacheckers.cordaclient.dao.Rank; import djmil.cordacheckers.cordaclient.dao.Rank;
import djmil.cordacheckers.cordaclient.dao.Stone; import djmil.cordacheckers.cordaclient.dao.Stone;
import djmil.cordacheckers.cordaclient.dao.flow.arguments.RspFailureException;
import djmil.cordacheckers.user.HoldingIdentityResolver; import djmil.cordacheckers.user.HoldingIdentityResolver;
@SpringBootTest @SpringBootTest
@ -39,7 +40,7 @@ public class RankingTests {
); );
@Test @Test
void testSurrender() throws InvalidNameException { void testSurrender() throws InvalidNameException, RspFailureException {
final var hiCustodian = holdingIdentityResolver.getCustodian(); final var hiCustodian = holdingIdentityResolver.getCustodian();
assertThat(hiCustodian).isNotNull(); assertThat(hiCustodian).isNotNull();
@ -68,7 +69,7 @@ public class RankingTests {
} }
@Test @Test
void testVictory() throws InvalidNameException { void testVictory() throws InvalidNameException, RspFailureException {
final var hiCustodian = holdingIdentityResolver.getCustodian(); final var hiCustodian = holdingIdentityResolver.getCustodian();
assertThat(hiCustodian).isNotNull(); assertThat(hiCustodian).isNotNull();
@ -97,7 +98,7 @@ public class RankingTests {
} }
@Test @Test
void testDraw() throws InvalidNameException { void testDraw() throws InvalidNameException, RspFailureException {
final var hiCustodian = holdingIdentityResolver.getCustodian(); final var hiCustodian = holdingIdentityResolver.getCustodian();
assertThat(hiCustodian).isNotNull(); assertThat(hiCustodian).isNotNull();