diff --git a/src/main/java/app/data/entity/Game.java b/src/main/java/app/data/entity/Game.java index 71c13fe..a20683c 100644 --- a/src/main/java/app/data/entity/Game.java +++ b/src/main/java/app/data/entity/Game.java @@ -66,7 +66,7 @@ public class Game { this.match = match; } - @OneToOne + @OneToOne(cascade = CascadeType.ALL) @JoinColumn(name = "info", referencedColumnName = "id") public GameInfo getGameInfo() { return gameInfo; diff --git a/src/main/java/app/data/entity/GameInfo.java b/src/main/java/app/data/entity/GameInfo.java index 0032a16..a59e669 100644 --- a/src/main/java/app/data/entity/GameInfo.java +++ b/src/main/java/app/data/entity/GameInfo.java @@ -67,7 +67,7 @@ public class GameInfo { return Objects.hash(id, chessComId, timeControl); } - @OneToOne(mappedBy = "gameInfo", cascade = CascadeType.ALL) + @OneToOne(mappedBy = "gameInfo", cascade = CascadeType.DETACH) public Game getGame() { return game; } diff --git a/src/main/java/app/data/entity/Match.java b/src/main/java/app/data/entity/Match.java index a0c9862..d788956 100644 --- a/src/main/java/app/data/entity/Match.java +++ b/src/main/java/app/data/entity/Match.java @@ -37,7 +37,7 @@ public class Match { return Objects.hash(id); } - @OneToMany(mappedBy = "match", fetch = FetchType.EAGER) + @OneToMany(mappedBy = "match", fetch = FetchType.EAGER, cascade = CascadeType.ALL) public Collection getGames() { return games; } @@ -46,7 +46,7 @@ public class Match { this.games = games; } - @ManyToOne(cascade=CascadeType.ALL) + @ManyToOne(cascade=CascadeType.DETACH) @JoinColumn(name = "player1", referencedColumnName = "id", nullable = false) public Player getPlayer1() { return player1; @@ -56,7 +56,7 @@ public class Match { this.player1 = player1; } - @ManyToOne(cascade=CascadeType.ALL) + @ManyToOne(cascade=CascadeType.DETACH) @JoinColumn(name = "player2", referencedColumnName = "id", nullable = false) public Player getPlayer2() { return player2; @@ -66,7 +66,7 @@ public class Match { this.player2 = player2; } - @ManyToOne(cascade=CascadeType.ALL) + @ManyToOne(cascade=CascadeType.DETACH) @JoinColumn(name = "matchday", referencedColumnName = "id", nullable = false) public Matchday getMatchday() { return matchday; diff --git a/src/main/java/app/data/entity/Matchday.java b/src/main/java/app/data/entity/Matchday.java index ab9bce5..29faa3f 100644 --- a/src/main/java/app/data/entity/Matchday.java +++ b/src/main/java/app/data/entity/Matchday.java @@ -46,7 +46,7 @@ public class Matchday { return Objects.hash(id, number); } - @OneToMany(mappedBy = "matchday", fetch = FetchType.EAGER) + @OneToMany(mappedBy = "matchday", fetch = FetchType.EAGER, cascade = CascadeType.ALL) public Collection getMatches() { return matches; } @@ -55,7 +55,7 @@ public class Matchday { this.matches = matches; } - @ManyToOne(cascade=CascadeType.ALL) + @ManyToOne(cascade=CascadeType.DETACH) @JoinColumn(name = "season", referencedColumnName = "id", nullable = false) public Season getSeason() { return season; diff --git a/src/main/java/app/data/entity/Player.java b/src/main/java/app/data/entity/Player.java index 5c184f4..383777a 100644 --- a/src/main/java/app/data/entity/Player.java +++ b/src/main/java/app/data/entity/Player.java @@ -58,7 +58,7 @@ public class Player { return Objects.hash(id, name, nickname); } - @OneToMany(mappedBy = "player1") + @OneToMany(mappedBy = "player1", cascade = CascadeType.DETACH) public Collection getMatchesAsPlayer1() { return matchesAsPlayer1; } @@ -67,7 +67,7 @@ public class Player { this.matchesAsPlayer1 = matchesAsPlayer1; } - @OneToMany(mappedBy = "player2") + @OneToMany(mappedBy = "player2", cascade = CascadeType.DETACH) public Collection getMatchesAsPlayer2() { return matchesAsPlayer2; } @@ -76,7 +76,7 @@ public class Player { this.matchesAsPlayer2 = matchesAsPlayer2; } - @OneToOne + @OneToOne(cascade = CascadeType.ALL) @JoinColumn(name = "info", referencedColumnName = "id") public PlayerInfo getPlayerInfo() { return playerInfo; diff --git a/src/main/java/app/data/entity/PlayerInfo.java b/src/main/java/app/data/entity/PlayerInfo.java index 45adaf4..fafe417 100644 --- a/src/main/java/app/data/entity/PlayerInfo.java +++ b/src/main/java/app/data/entity/PlayerInfo.java @@ -44,7 +44,7 @@ public class PlayerInfo { return Objects.hash(id, url); } - @OneToOne(mappedBy = "playerInfo") + @OneToOne(mappedBy = "playerInfo", cascade = CascadeType.DETACH) public Player getPlayer() { return player; } diff --git a/src/main/java/app/data/entity/Season.java b/src/main/java/app/data/entity/Season.java index 4ba0854..d5aba31 100644 --- a/src/main/java/app/data/entity/Season.java +++ b/src/main/java/app/data/entity/Season.java @@ -56,7 +56,7 @@ public class Season { return Objects.hash(id, yearStart, yearEnd); } - @OneToMany(mappedBy = "season") + @OneToMany(mappedBy = "season", cascade = CascadeType.ALL) public Collection getMatchdays() { return matchdays; } diff --git a/src/main/java/app/views/main/MainView.java b/src/main/java/app/views/main/MainView.java index 02d350e..3a81d26 100644 --- a/src/main/java/app/views/main/MainView.java +++ b/src/main/java/app/views/main/MainView.java @@ -37,8 +37,6 @@ import java.util.Optional; @Theme(value = Lumo.class, variant = Lumo.DARK) public class MainView extends AppLayout { // TODO: Add Localization - // TODO: View for each match - // TODO: View for adding match data // TODO: Handle database connection with environment variables // TODO: add light theme diff --git a/src/main/java/app/views/match/MatchView.java b/src/main/java/app/views/match/MatchView.java index fd53433..02d0bc1 100644 --- a/src/main/java/app/views/match/MatchView.java +++ b/src/main/java/app/views/match/MatchView.java @@ -43,7 +43,7 @@ public class MatchView extends NavigationViewBase { //////////// private void configureLayout() { - matchComponent = new MatchComponent(navigation, chessComService, gameService, gameInfoService, gameImageService); + matchComponent = new MatchComponent(navigation, chessComService, navigation.getMatchService(), gameService, gameInfoService, gameImageService); add(matchComponent); } diff --git a/src/main/java/app/views/match/components/MatchComponent.java b/src/main/java/app/views/match/components/MatchComponent.java index 7921956..17146cc 100644 --- a/src/main/java/app/views/match/components/MatchComponent.java +++ b/src/main/java/app/views/match/components/MatchComponent.java @@ -6,6 +6,7 @@ import app.data.entity.Match; import app.data.service.ChessComService; import app.data.service.GameInfoService; import app.data.service.GameService; +import app.data.service.MatchService; import app.gameimage.GameImageService; import app.navigation.Navigation; import app.utils.ChessComUtils; @@ -23,6 +24,7 @@ import com.vaadin.flow.component.orderedlayout.FlexComponent; import com.vaadin.flow.component.orderedlayout.FlexLayout; import com.vaadin.flow.component.orderedlayout.HorizontalLayout; import com.vaadin.flow.component.orderedlayout.VerticalLayout; +import com.vaadin.flow.component.progressbar.ProgressBar; import com.vaadin.flow.component.textfield.TextField; import com.vaadin.flow.shared.Registration; import org.springframework.beans.factory.annotation.Autowired; @@ -36,6 +38,7 @@ public class MatchComponent extends Div implements ContentConfigurable { private final Navigation navigation; private final ChessComService chessComService; + private final MatchService matchService; private final GameService gameService; private final GameInfoService gameInfoService; private final GameImageService gameImageService; @@ -53,6 +56,7 @@ public class MatchComponent extends Div implements ContentConfigurable { // TODO: autocorrect "/live/game" to "/game/live/" private final Button editSubmitButton = new Button("Submit", new Icon(VaadinIcon.CHECK)); // TODO: disable when no 6 values in form, and make sure you don't freeze forever when there are wrong entries + // TODO: use overlapping progress here private Registration editSubmitButtonRegistration; private final Button editCancelButton = new Button("Cancel", new Icon(VaadinIcon.CLOSE)); private Registration editCancelButtonRegistration; @@ -62,11 +66,13 @@ public class MatchComponent extends Div implements ContentConfigurable { public MatchComponent(Navigation navigation, @Autowired ChessComService chessComService, + @Autowired MatchService matchService, // TODO: get this stuff from navigation instead, or even better: Do it like PaussHFramework @Autowired GameService gameService, @Autowired GameInfoService gameInfoService, @Autowired GameImageService gameImageService) { this.navigation = navigation; this.chessComService = chessComService; + this.matchService = matchService; this.gameService = gameService; this.gameInfoService = gameInfoService; this.gameImageService = gameImageService; @@ -172,10 +178,14 @@ public class MatchComponent extends Div implements ContentConfigurable { if (chessComButtonButtonRegistration != null) chessComButtonButtonRegistration.remove(); chessComButtonButtonRegistration = chessComButton.addClickListener(event -> { + ProgressBar progressBar = new ProgressBar(); + progressBar.setIndeterminate(true); + editLayout.add(progressBar); List gamesBetweenPlayers = chessComService.getLatestGamesBetweenPlayers(match, 6, 2); for (int i = 0; i < Math.min(gamesBetweenPlayers.size(), 6); i++) { editTextFields.get(i).setValue(ChessComUtils.getGameURL(gamesBetweenPlayers.get(i))); } + editLayout.remove(progressBar); }); if (editSubmitButtonRegistration != null) editSubmitButtonRegistration.remove(); @@ -185,7 +195,7 @@ public class MatchComponent extends Div implements ContentConfigurable { Optional game = chessComService.getGame(textField.getValue(), match); // TODO: handle this when Optional is empty! game.ifPresent(value -> match.getGames().add(value)); } - match.getGames().forEach(game -> gameInfoService.update(game.getGameInfo())); + matchService.update(match); match.getGames().forEach(gameImageService::createImageIfNotPresent); navigation.setEditFlag(false);