Skip to content

Commit

Permalink
Create Abstract Vault Controller
Browse files Browse the repository at this point in the history
Fixes #1814 
Fixes #1765
Fixes #1799 
Fixes #1660
  • Loading branch information
Sheikah45 committed Aug 18, 2020
1 parent d06b045 commit c832e87
Show file tree
Hide file tree
Showing 39 changed files with 1,691 additions and 2,134 deletions.
16 changes: 8 additions & 8 deletions src/main/java/com/faforever/client/api/FafApiAccessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ public interface FafApiAccessor {

List<GamePlayerStats> getGamePlayerStats(int playerId, KnownFeaturedMod knownFeaturedMod);

List<Map> getMapsById(List<Integer> mapIdList, int count, int page);
Tuple<List<Map>, java.util.Map<String, ?>> getMapsByIdWithMeta(List<Integer> mapIdList, int count, int page);

List<Map> getMostPlayedMaps(int count, int page);
Tuple<List<Map>, java.util.Map<String, ?>> getMostPlayedMapsWithMeta(int count, int page);

List<Map> getHighestRatedMaps(int count, int page);
Tuple<List<Map>, java.util.Map<String, ?>> getHighestRatedMapsWithMeta(int count, int page);

List<Map> getNewestMaps(int count, int page);
Tuple<List<Map>, java.util.Map<String, ?>> getNewestMapsWithMeta(int count, int page);

List<Game> getLastGamesOnMap(int playerId, String mapVersionId, int count);

Expand Down Expand Up @@ -116,7 +116,7 @@ public interface FafApiAccessor {

Optional<Clan> getClanByTag(String tag);

List<Map> findMapsByQuery(SearchConfig searchConfig, int page, int count);
Tuple<List<Map>, java.util.Map<String, ?>> findMapsByQueryWithMeta(SearchConfig searchConfig, int count, int page);

Optional<MapVersion> findMapVersionById(String id);

Expand All @@ -126,13 +126,13 @@ public interface FafApiAccessor {

Optional<Game> findReplayById(int id);

List<Mod> findModsByQuery(SearchConfig query, int page, int maxResults);
Tuple<List<Mod>, java.util.Map<String, ?>> findModsByQueryWithMeta(SearchConfig query, int maxResults, int page);

List<Ladder1v1Map> getLadder1v1Maps(int count, int page);
Tuple<List<Ladder1v1Map>, java.util.Map<String, ?>> getLadder1v1MapsWithMeta(int count, int page);

List<Tournament> getAllTournaments();

List<MapVersion> getOwnedMaps(int playerId, int loadMoreCount, int page);
Tuple<List<MapVersion>, java.util.Map<String, ?>> getOwnedMapsWithMeta(int playerId, int loadMoreCount, int page);

void updateMapVersion(String id, MapVersion mapVersion);

Expand Down
48 changes: 26 additions & 22 deletions src/main/java/com/faforever/client/api/FafApiAccessorImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,43 +219,43 @@ public List<GamePlayerStats> getGamePlayerStats(int playerId, KnownFeaturedMod k

@Override
@Cacheable(CacheNames.MAPS)
public List<Map> getMostPlayedMaps(int count, int page) {
return this.<MapStatistics>getPage("/data/mapStatistics", count, page, ImmutableMap.of(
public Tuple<List<Map>, java.util.Map<String, ?>> getMostPlayedMapsWithMeta(int count, int page) {
JSONAPIDocument<List<MapStatistics>> jsonApiDoc = getPageWithMeta("/data/mapStatistics", count, page, ImmutableMap.of(
"include", "map,map.statistics,map.latestVersion,map.author,map.versions.reviews,map.versions.reviews.player",
"sort", "-plays")).stream()
.map(MapStatistics::getMap)
.collect(Collectors.toList());
"sort", "-plays"));
return new Tuple<>(jsonApiDoc.get().stream().map(MapStatistics::getMap).collect(Collectors.toList()), jsonApiDoc.getMeta());
}

@Override
public List<Map> getHighestRatedMaps(int count, int page) {
return this.<MapStatistics>getPage("/data/mapStatistics", count, page, ImmutableMap.of(
public Tuple<List<Map>, java.util.Map<String, ?>> getHighestRatedMapsWithMeta(int count, int page) {
JSONAPIDocument<List<MapStatistics>> jsonApiDoc = getPageWithMeta("/data/mapStatistics", count, page, ImmutableMap.of(
"include", "map.statistics,map,map.latestVersion,map.author,map.versions.reviews,map.versions.reviews.player,map.latestVersion.reviewsSummary",
"sort", "-map.latestVersion.reviewsSummary.lowerBound")).stream()
.map(MapStatistics::getMap)
.collect(Collectors.toList());
"sort", "-map.latestVersion.reviewsSummary.lowerBound"));
return new Tuple<>(jsonApiDoc.get().stream().map(MapStatistics::getMap).collect(Collectors.toList()), jsonApiDoc.getMeta());
}

@Override
public List<Map> getNewestMaps(int count, int page) {
return getPage(MAP_ENDPOINT, count, page, ImmutableMap.of(
public Tuple<List<Map>, java.util.Map<String, ?>> getNewestMapsWithMeta(int count, int page) {
JSONAPIDocument<List<Map>> jsonApiDoc = getPageWithMeta(MAP_ENDPOINT, count, page, ImmutableMap.of(
"include", "statistics,latestVersion,author,versions.reviews,versions.reviews.player",
"sort", "-updateTime",
"filter", "latestVersion.hidden==\"false\""
));
return new Tuple<>(jsonApiDoc.get(), jsonApiDoc.getMeta());
}

@Override
public List<Map> getMapsById(List<Integer> mapIdList, int count, int page) {
public Tuple<List<Map>, java.util.Map<String, ?>> getMapsByIdWithMeta(List<Integer> mapIdList, int count, int page) {
String filterCriteria = mapIdList.stream()
.map(Object::toString)
.collect(Collectors.joining(",", "latestVersion.map.id=in=(", ")"));

return getPage(MAP_ENDPOINT, count, page, ImmutableMap.of(
JSONAPIDocument<List<Map>> jsonApiDoc = getPageWithMeta(MAP_ENDPOINT, count, page, ImmutableMap.of(
"include", "statistics,latestVersion,author,versions.reviews,versions.reviews.player",
"sort", "-updateTime",
"filter", filterCriteria
));
return new Tuple<>(jsonApiDoc.get(), jsonApiDoc.getMeta());
}

@Override
Expand Down Expand Up @@ -408,14 +408,15 @@ public void deleteMapVersionReview(String id) {
}

@Override
public List<Mod> findModsByQuery(SearchConfig searchConfig, int page, int count) {
public Tuple<List<Mod>, java.util.Map<String, ?>> findModsByQueryWithMeta(SearchConfig searchConfig, int count, int page) {
MultiValueMap<String, String> parameterMap = new LinkedMultiValueMap<>();
if (searchConfig.hasQuery()) {
parameterMap.add("filter", searchConfig.getSearchQuery() + ";latestVersion.hidden==\"false\"");
}
parameterMap.add("include", "latestVersion,latestVersion.reviews,latestVersion.reviews.player,latestVersion.reviewsSummary");
parameterMap.add("sort", searchConfig.getSortConfig().toQuery());
return getPage(MOD_ENDPOINT, count, page, parameterMap);
JSONAPIDocument<List<Mod>> jsonApiDoc = getPageWithMeta(MOD_ENDPOINT, count, page, parameterMap);
return new Tuple<>(jsonApiDoc.get(), jsonApiDoc.getMeta());
}

@Override
Expand All @@ -429,9 +430,10 @@ public Optional<Game> findReplayById(int id) {
}

@Override
public List<Ladder1v1Map> getLadder1v1Maps(int count, int page) {
return getPage("/data/ladder1v1Map", count, page, ImmutableMap.of(
public Tuple<List<Ladder1v1Map>, java.util.Map<String, ?>> getLadder1v1MapsWithMeta(int count, int page) {
JSONAPIDocument<List<Ladder1v1Map>> jsonApiDoc = getPageWithMeta("/data/ladder1v1Map", count, page, ImmutableMap.of(
"include", "mapVersion,mapVersion.map,mapVersion.map.latestVersion,mapVersion.map.latestVersion.reviews,mapVersion.map.author,mapVersion.map.statistics"));
return new Tuple<>(jsonApiDoc.get(), jsonApiDoc.getMeta());
}

@Override
Expand All @@ -441,11 +443,12 @@ public List<TutorialCategory> getTutorialCategories() {
}

@Override
public List<MapVersion> getOwnedMaps(int playerId, int loadMoreCount, int page) {
return getPage("/data/mapVersion", loadMoreCount, page, ImmutableMap.of(
public Tuple<List<MapVersion>, java.util.Map<String, ?>> getOwnedMapsWithMeta(int playerId, int loadMoreCount, int page) {
JSONAPIDocument<List<MapVersion>> jsonApiDoc = getPageWithMeta("/data/mapVersion", loadMoreCount, page, ImmutableMap.of(
"include", "map,map.latestVersion,map.latestVersion.reviews,map.author,map.statistics",
"filter", rsql(qBuilder().string("map.author.id").eq(String.valueOf(playerId)))
));
return new Tuple<>(jsonApiDoc.get(), jsonApiDoc.getMeta());
}

@Override
Expand All @@ -467,14 +470,15 @@ public Optional<Clan> getClanByTag(String tag) {
}

@Override
public List<Map> findMapsByQuery(SearchConfig searchConfig, int page, int count) {
public Tuple<List<Map>, java.util.Map<String, ?>> findMapsByQueryWithMeta(SearchConfig searchConfig, int count, int page) {
MultiValueMap<String, String> parameterMap = new LinkedMultiValueMap<>();
if (searchConfig.hasQuery()) {
parameterMap.add("filter", searchConfig.getSearchQuery() + ";latestVersion.hidden==\"false\"");
}
parameterMap.add("include", "latestVersion,latestVersion.reviews,latestVersion.reviews.player,author,statistics,latestVersion.reviewsSummary");
parameterMap.add("sort", searchConfig.getSortConfig().toQuery());
return getPage(MAP_ENDPOINT, count, page, parameterMap);
JSONAPIDocument<List<Map>> jsonApiDoc = getPageWithMeta(MAP_ENDPOINT, count, page, parameterMap);
return new Tuple<>(jsonApiDoc.get(), jsonApiDoc.getMeta());
}

@Override
Expand Down
32 changes: 16 additions & 16 deletions src/main/java/com/faforever/client/api/MockFafApiAccessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,23 +129,23 @@ public List<GamePlayerStats> getGamePlayerStats(int playerId, KnownFeaturedMod k
}

@Override
public List<Map> getMapsById(List<Integer> mapIdList, int count, int page) {
return Collections.emptyList();
public Tuple<List<Map>, java.util.Map<String, ?>> getMapsByIdWithMeta(List<Integer> mapIdList, int count, int page) {
return new Tuple(Collections.emptyList(), Collections.emptyMap());
}

@Override
public List<Map> getMostPlayedMaps(int count, int page) {
return Collections.emptyList();
public Tuple<List<Map>, java.util.Map<String, ?>> getMostPlayedMapsWithMeta(int count, int page) {
return new Tuple(Collections.emptyList(), Collections.emptyMap());
}

@Override
public List<Map> getHighestRatedMaps(int count, int page) {
return Collections.emptyList();
public Tuple<List<Map>, java.util.Map<String, ?>> getHighestRatedMapsWithMeta(int count, int page) {
return new Tuple(Collections.emptyList(), Collections.emptyMap());
}

@Override
public List<Map> getNewestMaps(int count, int page) {
return Collections.emptyList();
public Tuple<List<Map>, java.util.Map<String, ?>> getNewestMapsWithMeta(int count, int page) {
return new Tuple(Collections.emptyList(), Collections.emptyMap());
}

@Override
Expand Down Expand Up @@ -249,8 +249,8 @@ public Optional<Clan> getClanByTag(String tag) {
}

@Override
public List<Map> findMapsByQuery(SearchConfig searchConfig, int page, int count) {
return Collections.emptyList();
public Tuple<List<Map>, java.util.Map<String, ?>> findMapsByQueryWithMeta(SearchConfig searchConfig, int page, int count) {
return new Tuple(Collections.emptyList(), Collections.emptyMap());
}

@Override
Expand All @@ -274,13 +274,13 @@ public Optional<Game> findReplayById(int id) {
}

@Override
public List<Mod> findModsByQuery(SearchConfig query, int page, int maxResults) {
return Collections.emptyList();
public Tuple<List<Mod>, java.util.Map<String, ?>> findModsByQueryWithMeta(SearchConfig query, int maxResults, int page) {
return new Tuple(Collections.emptyList(), Collections.emptyMap());
}

@Override
public List<Ladder1v1Map> getLadder1v1Maps(int count, int page) {
return Collections.emptyList();
public Tuple<List<Ladder1v1Map>, java.util.Map<String, ?>> getLadder1v1MapsWithMeta(int count, int page) {
return new Tuple(Collections.emptyList(), Collections.emptyMap());
}

@Override
Expand All @@ -289,8 +289,8 @@ public List<Tournament> getAllTournaments() {
}

@Override
public List<MapVersion> getOwnedMaps(int playerId, int loadMoreCount, int page) {
return Collections.emptyList();
public Tuple<List<MapVersion>, java.util.Map<String, ?>> getOwnedMapsWithMeta(int playerId, int loadMoreCount, int page) {
return new Tuple(Collections.emptyList(), Collections.emptyMap());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class MapCardController implements Controller<Node> {
private MapBean map;
private Consumer<MapBean> onOpenDetailListener;
private ListChangeListener<MapBean> installedMapsChangeListener;
private InvalidationListener reviewsChangedListener = observable -> populateReviews();
private final InvalidationListener reviewsChangedListener = observable -> populateReviews();
private JFXRippler jfxRippler;

public void initialize() {
Expand Down
40 changes: 24 additions & 16 deletions src/main/java/com/faforever/client/map/MapService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.faforever.client.map.MapBean.Type;
import com.faforever.client.map.generator.MapGeneratedEvent;
import com.faforever.client.map.generator.MapGeneratorService;
import com.faforever.client.player.Player;
import com.faforever.client.player.PlayerService;
import com.faforever.client.preferences.ForgedAlliancePrefs;
import com.faforever.client.preferences.PreferencesService;
import com.faforever.client.remote.AssetService;
Expand All @@ -18,6 +20,7 @@
import com.faforever.client.task.TaskService;
import com.faforever.client.theme.UiService;
import com.faforever.client.util.ProgrammingError;
import com.faforever.client.util.Tuple;
import com.faforever.client.vault.search.SearchController.SearchConfig;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableSet;
Expand Down Expand Up @@ -91,6 +94,7 @@ public class MapService implements InitializingBean, DisposableBean {
private final ClientProperties clientProperties;
private final EventBus eventBus;
private final ForgedAlliancePrefs forgedAlliancePreferences;
private final PlayerService playerService;

private final String mapDownloadUrlFormat;
private final String mapPreviewUrlFormat;
Expand All @@ -109,7 +113,7 @@ public MapService(PreferencesService preferencesService,
UiService uiService,
MapGeneratorService mapGeneratorService,
ClientProperties clientProperties,
EventBus eventBus) {
EventBus eventBus, PlayerService playerService) {
this.preferencesService = preferencesService;
this.taskService = taskService;
this.applicationContext = applicationContext;
Expand All @@ -121,6 +125,7 @@ public MapService(PreferencesService preferencesService,
this.clientProperties = clientProperties;
this.eventBus = eventBus;
forgedAlliancePreferences = preferencesService.getPreferences().getForgedAlliance();
this.playerService = playerService;
Vault vault = clientProperties.getVault();
this.mapDownloadUrlFormat = vault.getMapDownloadUrlFormat();
this.mapPreviewUrlFormat = vault.getMapPreviewUrlFormat();
Expand All @@ -144,7 +149,7 @@ public MapService(PreferencesService preferencesService,
"SCMP_023", "SCMP_024", "SCMP_025", "SCMP_026", "SCMP_027", "SCMP_028", "SCMP_029", "SCMP_030", "SCMP_031", "SCMP_032", "SCMP_033",
"SCMP_034", "SCMP_035", "SCMP_036", "SCMP_037", "SCMP_038", "SCMP_039", "SCMP_040", "X1MP_001", "X1MP_002", "X1MP_003", "X1MP_004",
"X1MP_005", "X1MP_006", "X1MP_007", "X1MP_008", "X1MP_009", "X1MP_010", "X1MP_011", "X1MP_012", "X1MP_014", "X1MP_017"
);
);

private static URL getDownloadUrl(String mapName, String baseUrl) {
return noCatch(() -> new URL(format(baseUrl, urlFragmentEscaper().escape(mapName).toLowerCase(Locale.US))));
Expand Down Expand Up @@ -339,27 +344,27 @@ public CompletableFuture<Void> downloadAndInstallMap(MapBean map, @Nullable Doub
return downloadAndInstallMap(map.getFolderName(), map.getDownloadUrl(), progressProperty, titleProperty);
}

public CompletableFuture<List<MapBean>> getRecommendedMaps(int count, int page) {
public CompletableFuture<Tuple<List<MapBean>, Integer>> getRecommendedMapsWithPageCount(int count, int page) {
return preferencesService.getRemotePreferencesAsync()
.thenCompose(
clientConfiguration -> {
List<Integer> recommendedMapIds = clientConfiguration.getRecommendedMaps();
return fafService.getMapsById(recommendedMapIds, count, page);
return fafService.getMapsByIdWithPageCount(recommendedMapIds, count, page);
}
);
}

public CompletableFuture<List<MapBean>> getHighestRatedMaps(int count, int page) {
return fafService.getHighestRatedMaps(count, page);
public CompletableFuture<Tuple<List<MapBean>, Integer>> getHighestRatedMapsWithPageCount(int count, int page) {
return fafService.getHighestRatedMapsWithPageCount(count, page);
}

public CompletableFuture<List<MapBean>> getNewestMaps(int count, int page) {
return fafService.getNewestMaps(count, page);
public CompletableFuture<Tuple<List<MapBean>, Integer>> getNewestMapsWithPageCount(int count, int page) {
return fafService.getNewestMapsWithPageCount(count, page);
}


public CompletableFuture<List<MapBean>> getMostPlayedMaps(int count, int page) {
return fafService.getMostPlayedMaps(count, page);
public CompletableFuture<Tuple<List<MapBean>, Integer>> getMostPlayedMapsWithPageCount(int count, int page) {
return fafService.getMostPlayedMapsWithPageCount(count, page);
}

/**
Expand Down Expand Up @@ -467,8 +472,8 @@ public CompletableFuture<Integer> getFileSize(URL downloadUrl) {
}


public CompletableFuture<List<MapBean>> findByQuery(SearchConfig searchConfig, int page, int count) {
return fafService.findMapsByQuery(searchConfig, page, count);
public CompletableFuture<Tuple<List<MapBean>, Integer>> findByQueryWithPageCount(SearchConfig searchConfig, int count, int page) {
return fafService.findMapsByQueryWithPageCount(searchConfig, count, page);
}


Expand All @@ -477,8 +482,8 @@ public Optional<MapBean> findMap(String id) {
}


public CompletableFuture<List<MapBean>> getLadderMaps(int loadMoreCount, int page) {
return fafService.getLadder1v1Maps(loadMoreCount, page);
public CompletableFuture<Tuple<List<MapBean>, Integer>> getLadderMapsWithPageCount(int loadMoreCount, int page) {
return fafService.getLadder1v1MapsWithPageCount(loadMoreCount, page);
}

private CompletableFuture<Void> downloadAndInstallMap(String folderName, URL downloadUrl, @Nullable DoubleProperty progressProperty, @Nullable StringProperty titleProperty) {
Expand All @@ -502,8 +507,11 @@ private CompletableFuture<Void> downloadAndInstallMap(String folderName, URL dow
.thenAccept(aVoid -> noCatch(() -> addInstalledMap(getPathForMapInsensitive(folderName))));
}

public CompletableFuture<List<MapBean>> getOwnedMaps(int playerId, int loadMoreCount, int page) {
return fafService.getOwnedMaps(playerId, loadMoreCount, page);
public CompletableFuture<Tuple<List<MapBean>, Integer>> getOwnedMapsWithPageCount(int loadMoreCount, int page) {
Player player = playerService.getCurrentPlayer()
.orElseThrow(() -> new IllegalStateException("Current player not set"));
int playerId = player.getId();
return fafService.getOwnedMapsWithPageCount(playerId, loadMoreCount, page);
}

public CompletableFuture<Void> hideMapVersion(MapBean map) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public Region getRoot() {
return mapUploadRoot;
}

void setOnCancelButtonClickedListener(Runnable cancelButtonClickedListener) {
public void setOnCancelButtonClickedListener(Runnable cancelButtonClickedListener) {
this.cancelButtonClickedListener = cancelButtonClickedListener;
}

Expand Down

0 comments on commit c832e87

Please sign in to comment.