Skip to content

Commit

Permalink
Remove unneeded CycleAvoidingMappingContext.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheikah45 committed Mar 2, 2024
1 parent 433854c commit fee3c0a
Show file tree
Hide file tree
Showing 72 changed files with 519 additions and 824 deletions.
10 changes: 5 additions & 5 deletions src/main/java/com/faforever/client/api/FafApiAccessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,19 @@ public class FafApiAccessor implements InitializingBean {
static final java.util.Map<Class<? extends ElideEntity>, List<String>> INCLUDES = java.util.Map.ofEntries(
java.util.Map.entry(CoopResult.class, List.of("game.playerStats.player")),
java.util.Map.entry(Clan.class, List.of("leader", "founder", "memberships", "memberships.player")),
java.util.Map.entry(LeaderboardEntry.class, List.of("player", "leagueLeaderboard")),
java.util.Map.entry(LeaderboardEntry.class, List.of("player", "leaderboard")),
java.util.Map.entry(LeaderboardRatingJournal.class, List.of("gamePlayerStats")),
java.util.Map.entry(GameReviewsSummary.class,
List.of("game", "game.featuredMod", "game.playerStats", "game.playerStats.player", "game.playerStats.ratingChanges",
"game.reviews", "game.reviews.player", "game.mapVersion", "game.mapVersion.map", "game.mapVersion.map")),
java.util.Map.entry(Game.class,
List.of("featuredMod", "playerStats", "playerStats.player", "playerStats.ratingChanges",
"mapVersion", "mapVersion.map", "mapVersion.map", "reviewsSummary")),
java.util.Map.entry(LeagueSeason.class, List.of("leagueLeaderboard", "league")),
java.util.Map.entry(LeagueSeason.class, List.of("leaderboard", "league")),
java.util.Map.entry(LeagueSeasonScore.class,
List.of("leagueSeason", "leagueSeason.leagueLeaderboard", "leagueSeason.league",
List.of("leagueSeason", "leagueSeason.leaderboard", "leagueSeason.league",
"leagueSeasonDivisionSubdivision", "leagueSeasonDivisionSubdivision.leagueSeasonDivision")),
java.util.Map.entry(LeagueSeasonDivisionSubdivision.class, List.of("leagueSeasonDivision", "leagueSeasonDivision.leagueSeason")),
java.util.Map.entry(LeagueSeasonDivisionSubdivision.class, List.of("leagueSeasonDivision")),
java.util.Map.entry(MapVersion.class, List.of("map", "map.reviewsSummary", "map.author")),
java.util.Map.entry(MapReviewsSummary.class, List.of("map.latestVersion", "map.author", "map.reviewsSummary")),
java.util.Map.entry(Map.class, List.of("latestVersion", "author", "reviewsSummary")),
Expand All @@ -105,7 +105,7 @@ public class FafApiAccessor implements InitializingBean {
java.util.Map.entry(ModReviewsSummary.class, List.of("mod.latestVersion", "mod.reviewsSummary", "mod.uploader")),
java.util.Map.entry(Mod.class, List.of("latestVersion", "reviewsSummary", "uploader")),
java.util.Map.entry(ModerationReport.class, List.of("reporter", "lastModerator", "reportedUsers", "game", "game.playerStats", "game.playerStats.player")),
java.util.Map.entry(MatchmakerQueue.class, List.of("leagueLeaderboard")),
java.util.Map.entry(MatchmakerQueue.class, List.of("leaderboard")),
java.util.Map.entry(TutorialCategory.class, List.of("tutorials", "tutorials.mapVersion.map", "tutorials.mapVersion.map.latestVersion",
"tutorials.mapVersion.map.author"))
);
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/faforever/client/avatar/AvatarService.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.faforever.client.avatar;

import com.faforever.client.mapstruct.AvatarMapper;
import com.faforever.client.mapstruct.CycleAvoidingMappingContext;
import com.faforever.client.player.PlayerService;
import com.faforever.client.remote.AssetService;
import com.faforever.client.remote.FafServerAccessor;
Expand Down Expand Up @@ -36,8 +35,7 @@ public Image loadAvatar(Avatar avatar) {
}

public CompletableFuture<List<Avatar>> getAvailableAvatars() {
return fafServerAccessor.getAvailableAvatars()
.thenApply(dto -> avatarMapper.mapDtos(dto, new CycleAvoidingMappingContext()));
return fafServerAccessor.getAvailableAvatars().thenApply(avatarMapper::mapDtos);
}

public void changeAvatar(Avatar avatar) {
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/faforever/client/clan/ClanService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.faforever.client.config.CacheNames;
import com.faforever.client.domain.api.Clan;
import com.faforever.client.mapstruct.ClanMapper;
import com.faforever.client.mapstruct.CycleAvoidingMappingContext;
import com.faforever.commons.api.elide.ElideNavigator;
import com.faforever.commons.api.elide.ElideNavigatorOnCollection;
import lombok.RequiredArgsConstructor;
Expand All @@ -31,8 +30,7 @@ public Mono<Clan> getClanByTag(String tag) {

ElideNavigatorOnCollection<com.faforever.commons.api.dto.Clan> navigator = ElideNavigator.of(
com.faforever.commons.api.dto.Clan.class).collection().setFilter(qBuilder().string("tag").eq(tag)).pageSize(1);
return fafApiAccessor.getMany(navigator)
.next().map(dto -> clanMapper.map(dto, new CycleAvoidingMappingContext())).cache();
return fafApiAccessor.getMany(navigator).next().map(clanMapper::map).cache();
}
}

Expand Down
32 changes: 17 additions & 15 deletions src/main/java/com/faforever/client/coop/CoopController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.faforever.client.domain.api.CoopMission;
import com.faforever.client.domain.api.CoopResult;
import com.faforever.client.domain.api.GamePlayerStats;
import com.faforever.client.domain.server.GameInfo;
import com.faforever.client.domain.server.PlayerInfo;
import com.faforever.client.fx.ControllerTableCell;
import com.faforever.client.fx.FxApplicationThreadExecutor;
import com.faforever.client.fx.ImageViewHelper;
Expand Down Expand Up @@ -132,10 +134,13 @@ protected void onInitialize() {
if (newValue.isEmpty()) {
return true;
}
return coopResultBean.replay().teams()
return coopResultBean.replay()
.teamPlayerStats()
.values()
.stream()
.flatMap(Collection::stream)
.map(GamePlayerStats::player)
.map(PlayerInfo::getUsername)
.anyMatch(
name -> name.toLowerCase().contains(newValue.toLowerCase()));
}));
Expand All @@ -147,11 +152,16 @@ protected void onInitialize() {
playerCountColumn.setCellValueFactory(param -> ObservableConstant.valueOf((param.getValue().playerCount())));
playerCountColumn.setCellFactory(param -> new StringCell<>(String::valueOf));

playerNamesColumn.setCellValueFactory(param -> ObservableConstant.valueOf(param.getValue().replay().teams().values()
.stream()
.flatMap(Collection::stream)
.collect(Collectors.joining(
i18n.get("textSeparator")))));
playerNamesColumn.setCellValueFactory(param -> ObservableConstant.valueOf(param.getValue()
.replay()
.teamPlayerStats()
.values()
.stream()
.flatMap(Collection::stream)
.map(GamePlayerStats::player)
.map(PlayerInfo::getUsername)
.collect(Collectors.joining(
i18n.get("textSeparator")))));

playerNamesColumn.setCellFactory(param -> new StringCell<>(Function.identity()));

Expand Down Expand Up @@ -261,19 +271,11 @@ private void loadLeaderboard() {
.collectList()
.publishOn(fxApplicationThreadExecutor.asScheduler())
.subscribe(leaderboardUnFilteredList::setAll, throwable -> {
log.warn("Could not load coop leagueLeaderboard", throwable);
log.warn("Could not load coop leaderboard", throwable);
notificationService.addImmediateErrorNotification(throwable, "coop.leaderboard.couldNotLoad");
});
}

private Set<String> getAllPlayerNamesFromTeams(CoopResult coopResult) {
return coopResult.replay().teams()
.values()
.stream()
.flatMap(List::stream)
.collect(Collectors.toUnmodifiableSet());
}


private CoopMission getSelectedMission() {
return missionComboBox.getSelectionModel().getSelectedItem();
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/com/faforever/client/coop/CoopService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.faforever.client.domain.api.CoopMission;
import com.faforever.client.domain.api.CoopResult;
import com.faforever.client.mapstruct.CoopMapper;
import com.faforever.client.mapstruct.CycleAvoidingMappingContext;
import com.faforever.commons.api.dto.Game;
import com.faforever.commons.api.dto.GamePlayerStats;
import com.faforever.commons.api.dto.Player;
Expand Down Expand Up @@ -37,7 +36,7 @@ public class CoopService {
public Flux<CoopMission> getMissions() {
ElideNavigatorOnCollection<com.faforever.commons.api.dto.CoopMission> navigator = ElideNavigator.of(
com.faforever.commons.api.dto.CoopMission.class).collection().pageSize(1000);
return fafApiAccessor.getMany(navigator).map(dto -> coopMapper.map(dto, new CycleAvoidingMappingContext())).cache();
return fafApiAccessor.getMany(navigator).map(coopMapper::map).cache();
}

@Cacheable(value = CacheNames.COOP_LEADERBOARD, sync = true)
Expand All @@ -56,8 +55,7 @@ public Flux<CoopResult> getLeaderboard(CoopMission mission, int numberOfPlayers)
.pageSize(1000);
return fafApiAccessor.getMany(navigator)
.distinct(this::getAllPlayerNamesFromTeams)
.index(
(index, dto) -> coopMapper.map(dto, index.intValue(), new CycleAvoidingMappingContext()))
.index((index, dto) -> coopMapper.map(dto, index.intValue()))
.cache();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.faforever.client.domain.api;

public record Division(
Integer id, String descriptionKey, int index, String nameKey, LeagueSeason leagueSeason
Integer id, String descriptionKey, int index, String nameKey
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
import com.faforever.client.domain.server.PlayerInfo;
import com.faforever.commons.api.dto.Faction;

import java.time.OffsetDateTime;
import java.util.List;

public record GamePlayerStats(
PlayerInfo player, byte score, byte team,
Faction faction,
OffsetDateTime scoreTime, Replay game, List<LeaderboardRatingJournal> leaderboardRatingJournals
Faction faction, List<LeaderboardRatingJournal> leaderboardRatingJournals
) {

public GamePlayerStats {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.faforever.client.domain.api;

import java.time.OffsetDateTime;

/**
* Represents a leaderboard rating
*/
public record LeaderboardRatingJournal(
Integer id,
Double meanAfter,
Double deviationAfter,
Double meanBefore,
Double deviationBefore, GamePlayerStats gamePlayerStats, Leaderboard leaderboard
Double meanBefore, Double deviationBefore, Leaderboard leaderboard, OffsetDateTime scoreTime
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
public record LeagueEntry(
Integer id, PlayerInfo player,
int gamesPlayed,
Integer score,
boolean returningPlayer, LeagueSeason leagueSeason, Subdivision subdivision,
Integer score, boolean returningPlayer, LeagueSeason leagueSeason, Subdivision subdivision,
Long rank
) {}
12 changes: 4 additions & 8 deletions src/main/java/com/faforever/client/domain/api/Map.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,20 @@

public record Map(
Integer id,
String displayName,
int gamesPlayed, PlayerInfo author,
boolean recommended,
MapType mapType, MapReviewsSummary mapReviewsSummary
String displayName, int gamesPlayed, PlayerInfo author,
boolean recommended, MapType mapType, ReviewsSummary reviewsSummary
) {

@RequiredArgsConstructor
@Getter
public enum MapType {
SKIRMISH("skirmish"),
COOP("campaign_coop"),
OTHER(null);
SKIRMISH("skirmish"), COOP("campaign_coop"), OTHER(null);

private static final java.util.Map<String, MapType> VALUE_MAP = Arrays.stream(values())
.filter(
type -> Objects.nonNull(type.getValue()))
.collect(Collectors.toMap(MapType::getValue,
Function.identity()));
Function.identity()));

private final String value;

Expand Down

This file was deleted.

This file was deleted.

3 changes: 1 addition & 2 deletions src/main/java/com/faforever/client/domain/api/Mod.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
public record Mod(
Integer id,
String displayName,
boolean recommended,
String author, PlayerInfo uploader, ModReviewsSummary modReviewsSummary
boolean recommended, String author, PlayerInfo uploader, ReviewsSummary reviewsSummary
) {}

This file was deleted.

This file was deleted.

15 changes: 6 additions & 9 deletions src/main/java/com/faforever/client/domain/api/Replay.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,28 @@
public record Replay(
Integer id,
String title,
boolean replayAvailable,
Map<String, List<String>> teams, Map<String, List<GamePlayerStats>> teamPlayerStats, PlayerInfo host,
boolean replayAvailable, Map<String, List<GamePlayerStats>> teamPlayerStats, PlayerInfo host,
OffsetDateTime startTime,
OffsetDateTime endTime, FeaturedMod featuredMod, MapVersion mapVersion,
Path replayFile,
Integer replayTicks,
List<ChatMessage> chatMessages,
List<GameOption> gameOptions,
Validity validity, ReplayReviewsSummary gameReviewsSummary,
List<GameOption> gameOptions, Validity validity, ReviewsSummary reviewsSummary,
boolean local
) {

public Replay {
teams = teams == null ? Map.of() : Map.copyOf(teams);
teamPlayerStats = teamPlayerStats == null ? Map.of() : Map.copyOf(teamPlayerStats);
chatMessages = chatMessages == null ? List.of() : List.copyOf(chatMessages);
gameOptions = gameOptions == null ? List.of() : List.copyOf(gameOptions);
}

public int numPlayers() {
return teams().values().stream().mapToInt(Collection::size).sum();
return teamPlayerStats().values().stream().mapToInt(Collection::size).sum();
}

public double averageRating() {
return teamPlayerStats.values()
return teamPlayerStats().values()
.stream()
.flatMap(Collection::stream).map(GamePlayerStats::leaderboardRatingJournals)
.filter(ratingJournals -> !ratingJournals.isEmpty())
Expand All @@ -52,9 +49,9 @@ public double averageRating() {
}

public Replay withReplayDetails(ReplayDetails replayDetails, Path replayFile) {
return new Replay(id(), title(), replayAvailable(), teams(), teamPlayerStats(), host(), startTime(), endTime(),
return new Replay(id(), title(), replayAvailable(), teamPlayerStats(), host(), startTime(), endTime(),
featuredMod(), replayDetails.mapVersion(), replayFile, replayTicks(),
replayDetails.chatMessages(), replayDetails.gameOptions(), validity(), gameReviewsSummary(),
replayDetails.chatMessages(), replayDetails.gameOptions(), validity(), reviewsSummary(),
local());
}

Expand Down

This file was deleted.

19 changes: 3 additions & 16 deletions src/main/java/com/faforever/client/domain/api/ReviewsSummary.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
package com.faforever.client.domain.api;

public sealed interface ReviewsSummary permits MapReviewsSummary, MapVersionReviewsSummary, ModReviewsSummary, ModVersionReviewsSummary, ReplayReviewsSummary {
Integer id();

float positive();

float negative();

float score();

float averageScore();

int numReviews();

float lowerBound();

}
public record ReviewsSummary(
Integer id, float positive, float negative, float score, float averageScore, int numReviews, float lowerBound
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ public record Subdivision(
String descriptionKey,
int index,
int highestScore,
int maxRating,
int minRating, Division division,
int maxRating, int minRating, Division division,
URL imageUrl,
URL mediumImageUrl,
URL smallImageUrl
Expand Down

0 comments on commit fee3c0a

Please sign in to comment.