diff --git a/build.gradle b/build.gradle index ecae5d9b48..ddf12fe74b 100644 --- a/build.gradle +++ b/build.gradle @@ -310,7 +310,9 @@ dependencies { implementation("com.neovisionaries:nv-i18n:1.29") implementation("com.nativelibs4java:bridj:0.7.0") implementation("org.luaj:luaj-jse:3.0.1") - implementation("commons-validator:commons-validator:1.7") + implementation("commons-validator:commons-validator:1.7") { + exclude module: 'commons-logging' + } implementation("com.github.micheljung:JJsonRpc:01a7fba5f4") implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310") implementation("com.fasterxml.jackson.module:jackson-module-kotlin") @@ -337,7 +339,9 @@ dependencies { implementation("com.github.1-alex98:discord-rpc:1.6.2-jna") implementation("org.controlsfx:controlsfx:11.1.2") implementation("org.fxmisc.flowless:flowless:0.7.1") - implementation("de.codecentric.centerdevice:javafxsvg:1.3.0") + implementation("de.codecentric.centerdevice:javafxsvg:1.3.0") { + exclude module: 'commons-logging' + } implementation("org.javassist:javassist:3.29.2-GA") diff --git a/src/main/java/com/faforever/client/api/FafApiAccessor.java b/src/main/java/com/faforever/client/api/FafApiAccessor.java index f5c7db4e63..cb945f7eaa 100644 --- a/src/main/java/com/faforever/client/api/FafApiAccessor.java +++ b/src/main/java/com/faforever/client/api/FafApiAccessor.java @@ -52,6 +52,7 @@ import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.reactive.function.client.WebClient; +import org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec; import org.springframework.web.util.UriComponents; import org.springframework.web.util.UriComponentsBuilder; import reactor.core.publisher.Flux; @@ -153,19 +154,18 @@ public int getMaxPageSize() { } public Mono getMe() { - return retrieveMonoWithErrorHandling(MeResult.class, apiWebClient.get().uri("/me")) - .doOnNext(object -> log.trace("Retrieved {} from /me with type MeResult", object)); + return retrieveMonoWithErrorHandling(MeResult.class, apiWebClient.get() + .uri("/me")).doOnNext(object -> log.trace("Retrieved {} from /me with type MeResult", object)); } - public Flux getIceServers() { - return retrieveMonoWithErrorHandling(IceServerResponse.class, apiWebClient.get().uri("/ice/server")) - .flatMapIterable(IceServerResponse::servers) - .doOnNext(object -> log.trace("Retrieved {} from /ice/server with type IceServer", object)); + public Mono getApiObject(String path, Class clazz) { + RequestHeadersSpec requestSpec = apiWebClient.get().uri(path); + return retrieveMonoWithErrorHandling(clazz, requestSpec).doOnNext(object -> log.trace("Retrieved {} from {} with type {}", object, path, clazz)); } - public Mono getIceSession(int gameId) { - return retrieveMonoWithErrorHandling(IceSession.class, apiWebClient.get().uri("/ice/session/game/" + gameId)) - .doOnNext(object -> log.trace("Retrieved {} from /ice/session/game/{} with type IceSession", object, gameId)); + public Flux getApiObjects(String path, Class clazz) { + RequestHeadersSpec requestSpec = apiWebClient.get().uri(path); + return retrieveFluxWithErrorHandling(clazz, requestSpec).doOnNext(object -> log.trace("Retrieved {} from {} with type {}", object, path, clazz)); } public Mono uploadFile(String endpoint, Path file, ByteCountListener listener, diff --git a/src/main/java/com/faforever/client/api/IceServer.java b/src/main/java/com/faforever/client/api/IceServer.java index dca934cdd9..38b24c11cf 100644 --- a/src/main/java/com/faforever/client/api/IceServer.java +++ b/src/main/java/com/faforever/client/api/IceServer.java @@ -1,4 +1,4 @@ package com.faforever.client.api; -public record IceServer(String name, String region) { +public record IceServer(String id, String region) { } diff --git a/src/main/java/com/faforever/client/fa/relay/ice/CoturnService.java b/src/main/java/com/faforever/client/fa/relay/ice/CoturnService.java index 501dfadf4a..1e28fc1003 100644 --- a/src/main/java/com/faforever/client/fa/relay/ice/CoturnService.java +++ b/src/main/java/com/faforever/client/fa/relay/ice/CoturnService.java @@ -2,8 +2,8 @@ import com.faforever.client.api.FafApiAccessor; import com.faforever.client.api.IceServer; +import com.faforever.client.api.IceServerResponse; import com.faforever.client.api.IceSession; -import com.faforever.client.mapstruct.IceServerMapper; import com.faforever.client.preferences.ForgedAlliancePrefs; import com.faforever.commons.api.dto.CoturnServer; import lombok.RequiredArgsConstructor; @@ -21,18 +21,18 @@ public class CoturnService { private final FafApiAccessor fafApiAccessor; - private final IceServerMapper iceServerMapper; private final ForgedAlliancePrefs forgedAlliancePrefs; public CompletableFuture> getActiveCoturns() { - return fafApiAccessor.getIceServers() + return fafApiAccessor.getApiObject("/ice/server", IceServerResponse.class) + .flatMapIterable(IceServerResponse::servers) .switchIfEmpty(Flux.error(new IllegalStateException("No Coturn Servers Available"))) .collectList() .toFuture(); } public CompletableFuture> getSelectedCoturns(int gameId) { - Flux coturnServerFlux = fafApiAccessor.getIceSession(gameId) + Flux coturnServerFlux = fafApiAccessor.getApiObject("/ice/session/game/" + gameId, IceSession.class) .flatMapIterable(IceSession::servers); Set preferredCoturnIds = forgedAlliancePrefs.getPreferredCoturnIds(); diff --git a/src/main/java/com/faforever/client/preferences/ui/SettingsController.java b/src/main/java/com/faforever/client/preferences/ui/SettingsController.java index c1e8b3f43b..f013a3a836 100644 --- a/src/main/java/com/faforever/client/preferences/ui/SettingsController.java +++ b/src/main/java/com/faforever/client/preferences/ui/SettingsController.java @@ -181,7 +181,8 @@ public class SettingsController implements Controller { private final SimpleChangeListener selectedThemeChangeListener = this::onThemeChanged; private final SimpleChangeListener currentThemeChangeListener = newValue -> themeComboBox.getSelectionModel().select(newValue);; - private SimpleInvalidationListener availableLanguagesListener = this::setAvailableLanguages;; + private final SimpleInvalidationListener availableLanguagesListener = this::setAvailableLanguages; + ; public void initialize() { JavaFxUtil.bindManagedToVisible(vaultLocationWarningLabel); @@ -344,7 +345,7 @@ private void initPreferredCoturnListView() { .getForgedAlliance() .getPreferredCoturnIds(); Map hostPortCoturnServerMap = coturnServers.stream() - .collect(Collectors.toMap(IceServer::name, Function.identity())); + .collect(Collectors.toMap(IceServer::id, Function.identity())); preferredCoturnServers.stream() .filter(hostPortCoturnServerMap::containsKey) @@ -352,10 +353,10 @@ private void initPreferredCoturnListView() { .forEach(coturnServer -> preferredCoturnListView.getSelectionModel().select(coturnServer)); JavaFxUtil.addAndTriggerListener(preferredCoturnListView.getSelectionModel() - .getSelectedItems(), (InvalidationListener) observable -> { + .getSelectedItems(), observable -> { List selectedCoturns = preferredCoturnListView.getSelectionModel().getSelectedItems(); preferredCoturnServers.clear(); - selectedCoturns.stream().map(IceServer::name).forEach(preferredCoturnServers::add); + selectedCoturns.stream().map(IceServer::id).forEach(preferredCoturnServers::add); }); }, fxApplicationThreadExecutor); } diff --git a/src/test/java/com/faforever/client/chat/ChatUserItemControllerTest.java b/src/test/java/com/faforever/client/chat/ChatUserItemControllerTest.java index 74b5d26736..7a441a6228 100644 --- a/src/test/java/com/faforever/client/chat/ChatUserItemControllerTest.java +++ b/src/test/java/com/faforever/client/chat/ChatUserItemControllerTest.java @@ -180,9 +180,9 @@ public void testCheckChatUserGameListener() { when(uiService.getThemeImage(UiService.CHAT_LIST_STATUS_HOSTING)).thenReturn(new Image(InputStream.nullInputStream())); when(mapService.loadPreview(game.getMapFolderName(), PreviewSize.SMALL)).thenReturn(new Image(InputStream.nullInputStream())); when(mapService.getMapLocallyFromName(mapFolderName)).thenReturn(Optional.of(mapVersion)); - when(mapService.convertMapFolderNameToHumanNameIfPossible(mapFolderName)).thenReturn("map name"); + when(mapService.convertMapFolderNameToHumanNameIfPossible(mapFolderName)).thenReturn("map id"); when(i18n.get(eq("game.onMapFormat"), anyString())).thenReturn(mapVersion.getMap() - .getDisplayName(), "map name", "Neroxis Generated Map"); + .getDisplayName(), "map id", "Neroxis Generated Map"); runOnFxThreadAndWait(() -> instance.setChatUser(defaultUser)); assertNotNull(instance.gameStatusImageView.getImage()); diff --git a/src/test/java/com/faforever/client/fa/relay/ice/CoturnServiceTest.java b/src/test/java/com/faforever/client/fa/relay/ice/CoturnServiceTest.java index adcc65cb21..ea0e65e56c 100644 --- a/src/test/java/com/faforever/client/fa/relay/ice/CoturnServiceTest.java +++ b/src/test/java/com/faforever/client/fa/relay/ice/CoturnServiceTest.java @@ -5,7 +5,6 @@ import com.faforever.client.mapstruct.IceServerMapper; import com.faforever.client.mapstruct.MapperSetup; import com.faforever.client.preferences.ForgedAlliancePrefs; -import com.faforever.client.test.ElideMatchers; import com.faforever.client.test.ServiceTest; import com.faforever.commons.api.dto.CoturnServer; import org.junit.jupiter.api.BeforeEach; @@ -21,8 +20,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.ArgumentMatchers.endsWith; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -45,9 +44,9 @@ public void setUp() throws Exception { @Test public void testGetActiveCoturns() { - when(fafApiAccessor.getMany(any())).thenReturn(Flux.empty()); + when(fafApiAccessor.getApiObjects("/ice/server", IceServer.class)).thenReturn(Flux.empty()); instance.getActiveCoturns(); - verify(fafApiAccessor).getMany(argThat(ElideMatchers.hasDtoClass(CoturnServer.class))); + verify(fafApiAccessor).getApiObjects("/ice/server", IceServer.class); } @Test @@ -56,26 +55,26 @@ public void TestGetSelectedCoturnsNoActiveSelected() { CoturnServer otherServer = new CoturnServer(); otherServer.setId("0"); - when(fafApiAccessor.getIceSession(anyInt())).thenReturn(Mono.just(new IceSession("someSessionId", List.of(otherServer)))); + when(fafApiAccessor.getApiObject(any(), any())).thenReturn(Mono.just(new IceSession("someSessionId", List.of(otherServer)))); List servers = instance.getSelectedCoturns(123).join(); assertEquals(1, servers.size()); assertEquals("0", servers.get(0).getId()); - verify(fafApiAccessor).getIceSession(123); + verify(fafApiAccessor).getApiObject(endsWith("123"), eq(IceSession.class)); } @Test public void testGetSelectedCoturnsNoneSelected() { CoturnServer otherServer = new CoturnServer(); otherServer.setId("0"); - when(fafApiAccessor.getIceSession(anyInt())).thenReturn(Mono.just(new IceSession("someSessionId", List.of(otherServer)))); + when(fafApiAccessor.getApiObject(any(), any())).thenReturn(Mono.just(new IceSession("someSessionId", List.of(otherServer)))); List servers = instance.getSelectedCoturns(123).join(); assertEquals(1, servers.size()); assertEquals("0", servers.get(0).getId()); - verify(fafApiAccessor).getIceSession(123); + verify(fafApiAccessor).getApiObject(endsWith("123"), eq(IceSession.class)); } @Test @@ -86,12 +85,12 @@ public void testGetSelectedCoturnsActiveSelected() { otherServer.setId("0"); CoturnServer selectedServer = new CoturnServer(); otherServer.setId("1"); - when(fafApiAccessor.getIceSession(anyInt())).thenReturn(Mono.just(new IceSession("someSessionId", List.of(otherServer, selectedServer)))); + when(fafApiAccessor.getApiObject(any(), any())).thenReturn(Mono.just(new IceSession("someSessionId", List.of(otherServer, selectedServer)))); List servers = instance.getSelectedCoturns(123).join(); assertEquals(1, servers.size()); assertEquals("1", servers.get(0).getId()); - verify(fafApiAccessor).getIceSession(123); + verify(fafApiAccessor).getApiObject(endsWith("123"), eq(IceSession.class)); } }