diff --git a/pom.xml b/pom.xml index d5976f7..09eb63f 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.faforever faf-moderator-client - 0.2.0 + 0.2.1 jar faf-moderator-client @@ -23,7 +23,15 @@ UTF-8 1.8 + 6a78e08 + 1.1 + 1.6 + 0.8 1.2.0.Final + 4.5.3 + 2.8.8 + 13.0 + 1 @@ -37,7 +45,7 @@ org.jetbrains annotations - 13.0 + ${org.jetbrains.annotations.version} org.springframework.boot @@ -50,37 +58,42 @@ javax.inject javax.inject - 1 + ${javax.inject.version} com.fasterxml.jackson.datatype jackson-datatype-jsr310 - 2.8.8 + ${com.fasterxml.jackson.datatype.version} com.github.jasminb jsonapi-converter - 0.8 + ${jitpack.jasminb.jsonapi-converter.version} - com.github.FAForever - faf-java-commons - a53e12e + com.github.FAForever.faf-java-commons + faf-commons-data + ${jitpack.faf-java-commons.version} + + + com.github.FAForever.faf-java-commons + faf-commons-api + ${jitpack.faf-java-commons.version} com.github.micheljung nocatch - 1.1 + ${jitpack.nocatch.version} org.apache.httpcomponents httpclient - 4.5.3 + ${org.apache.httpcomponents.httpclient.version} com.github.rutledgepaulv q-builders - 1.6 + ${jitpack.q-builders.version} diff --git a/src/main/java/com/faforever/moderatorclient/api/rest/ElideRouteBuilder.java b/src/main/java/com/faforever/moderatorclient/api/ElideRouteBuilder.java similarity index 98% rename from src/main/java/com/faforever/moderatorclient/api/rest/ElideRouteBuilder.java rename to src/main/java/com/faforever/moderatorclient/api/ElideRouteBuilder.java index f53c343..3d1afd9 100644 --- a/src/main/java/com/faforever/moderatorclient/api/rest/ElideRouteBuilder.java +++ b/src/main/java/com/faforever/moderatorclient/api/ElideRouteBuilder.java @@ -1,4 +1,4 @@ -package com.faforever.moderatorclient.api.rest; +package com.faforever.moderatorclient.api; import com.github.jasminb.jsonapi.annotations.Type; import com.github.rutledgepaulv.qbuilders.builders.QBuilder; diff --git a/src/main/java/com/faforever/moderatorclient/api/rest/FafApiCommunicationService.java b/src/main/java/com/faforever/moderatorclient/api/FafApiCommunicationService.java similarity index 91% rename from src/main/java/com/faforever/moderatorclient/api/rest/FafApiCommunicationService.java rename to src/main/java/com/faforever/moderatorclient/api/FafApiCommunicationService.java index 8486bbe..44764c0 100644 --- a/src/main/java/com/faforever/moderatorclient/api/rest/FafApiCommunicationService.java +++ b/src/main/java/com/faforever/moderatorclient/api/FafApiCommunicationService.java @@ -1,7 +1,8 @@ -package com.faforever.moderatorclient.api.rest; +package com.faforever.moderatorclient.api; -import com.faforever.moderatorclient.api.dto.LegacyAccessLevel; -import com.faforever.moderatorclient.api.dto.Player; +import com.faforever.commons.api.dto.LegacyAccessLevel; +import com.faforever.commons.api.dto.Player; +import com.faforever.moderatorclient.mapstruct.CycleAvoidingMappingContext; import com.github.jasminb.jsonapi.JSONAPIDocument; import com.github.jasminb.jsonapi.ResourceConverter; import lombok.Getter; @@ -34,6 +35,7 @@ public class FafApiCommunicationService { private final ResourceConverter resourceConverter; @Getter private Player selfPlayer; + private final CycleAvoidingMappingContext cycleAvoidingMappingContext; private final RestTemplateBuilder restTemplateBuilder; private final HttpComponentsClientHttpRequestFactory requestFactory; private final String apiClientId; @@ -44,7 +46,7 @@ public class FafApiCommunicationService { private RestOperations restOperations; - public FafApiCommunicationService(ResourceConverter resourceConverter, RestTemplateBuilder restTemplateBuilder, + public FafApiCommunicationService(ResourceConverter resourceConverter, CycleAvoidingMappingContext cycleAvoidingMappingContext, RestTemplateBuilder restTemplateBuilder, JsonApiMessageConverter jsonApiMessageConverter, JsonApiErrorHandler jsonApiErrorHandler, @Value("${faforever.api.base-url}") @@ -60,6 +62,7 @@ public FafApiCommunicationService(ResourceConverter resourceConverter, RestTempl ) { this.resourceConverter = resourceConverter; + this.cycleAvoidingMappingContext = cycleAvoidingMappingContext; this.apiClientId = apiClientId; this.apiClientSecret = apiClientSecret; this.apiAccessTokenUrl = apiAccessTokenUrl; @@ -105,25 +108,15 @@ public LegacyAccessLevel login(String username, String password) { } } - @SneakyThrows - public void post(ElideRouteBuilder routeBuilder, Object request, boolean bufferRequestBody) { - authorizedLatch.await(); - requestFactory.setBufferRequestBody(bufferRequestBody); - - try { - // Don't use Void.class here, otherwise Spring won't even try to deserialize error messages in the body - restOperations.postForEntity(routeBuilder.build(), request, String.class); - } finally { - requestFactory.setBufferRequestBody(true); - } - } - @SneakyThrows public T post(ElideRouteBuilder routeBuilder, T object) { authorizedLatch.await(); JSONAPIDocument data = new JSONAPIDocument<>(object); String dataString = new String(resourceConverter.writeDocument(data)); ResponseEntity entity = restOperations.postForEntity(routeBuilder.build(), dataString, routeBuilder.getDtoClass()); + + cycleAvoidingMappingContext.clearCache(); + return entity.getBody(); } @@ -133,12 +126,16 @@ public Object postRelationship(ElideRouteBuilder routeBuilder, Object object) JSONAPIDocument data = new JSONAPIDocument<>(object); String dataString = new String(resourceConverter.writeDocument(data)); ResponseEntity entity = restOperations.postForEntity(routeBuilder.build(), dataString, routeBuilder.getDtoClass()); + + cycleAvoidingMappingContext.clearCache(); + return entity.getBody(); } @SneakyThrows public T patch(ElideRouteBuilder routeBuilder, T object) { authorizedLatch.await(); + cycleAvoidingMappingContext.clearCache(); return restOperations.patchForObject(routeBuilder.build(), object, routeBuilder.getDtoClass()); } @@ -161,6 +158,7 @@ public T getOne(String endpointPath, Class type) { @SuppressWarnings("unchecked") @SneakyThrows public T getOne(String endpointPath, Class type, java.util.Map params) { + cycleAvoidingMappingContext.clearCache(); return restOperations.getForObject(endpointPath, type, params); } @@ -199,6 +197,7 @@ public List getPage(ElideRouteBuilder routeBuilder, int pageSize, int .pageSize(pageSize) .pageNumber(page) .build(); + cycleAvoidingMappingContext.clearCache(); log.debug("Sending API request: {}", route); return (List) restOperations.getForObject( route, diff --git a/src/main/java/com/faforever/moderatorclient/api/rest/JsonApiErrorHandler.java b/src/main/java/com/faforever/moderatorclient/api/JsonApiErrorHandler.java similarity index 91% rename from src/main/java/com/faforever/moderatorclient/api/rest/JsonApiErrorHandler.java rename to src/main/java/com/faforever/moderatorclient/api/JsonApiErrorHandler.java index 8f161a5..8cc56ab 100644 --- a/src/main/java/com/faforever/moderatorclient/api/rest/JsonApiErrorHandler.java +++ b/src/main/java/com/faforever/moderatorclient/api/JsonApiErrorHandler.java @@ -1,7 +1,7 @@ -package com.faforever.moderatorclient.api.rest; +package com.faforever.moderatorclient.api; -import com.faforever.moderatorclient.api.dto.ApiException; +import com.faforever.commons.api.dto.ApiException; import com.github.jasminb.jsonapi.exceptions.ResourceParseException; import com.github.jasminb.jsonapi.models.errors.Errors; import org.springframework.http.HttpStatus; diff --git a/src/main/java/com/faforever/moderatorclient/api/rest/JsonApiMessageConverter.java b/src/main/java/com/faforever/moderatorclient/api/JsonApiMessageConverter.java similarity index 97% rename from src/main/java/com/faforever/moderatorclient/api/rest/JsonApiMessageConverter.java rename to src/main/java/com/faforever/moderatorclient/api/JsonApiMessageConverter.java index c0e54cc..470856a 100644 --- a/src/main/java/com/faforever/moderatorclient/api/rest/JsonApiMessageConverter.java +++ b/src/main/java/com/faforever/moderatorclient/api/JsonApiMessageConverter.java @@ -1,4 +1,4 @@ -package com.faforever.moderatorclient.api.rest; +package com.faforever.moderatorclient.api; import com.github.jasminb.jsonapi.JSONAPIDocument; import com.github.jasminb.jsonapi.ReflectionUtils; diff --git a/src/main/java/com/faforever/moderatorclient/api/rest/domain/AvatarService.java b/src/main/java/com/faforever/moderatorclient/api/domain/AvatarService.java similarity index 89% rename from src/main/java/com/faforever/moderatorclient/api/rest/domain/AvatarService.java rename to src/main/java/com/faforever/moderatorclient/api/domain/AvatarService.java index 50c6796..52f9aa8 100644 --- a/src/main/java/com/faforever/moderatorclient/api/rest/domain/AvatarService.java +++ b/src/main/java/com/faforever/moderatorclient/api/domain/AvatarService.java @@ -1,8 +1,8 @@ -package com.faforever.moderatorclient.api.rest.domain; +package com.faforever.moderatorclient.api.domain; -import com.faforever.moderatorclient.api.dto.Avatar; -import com.faforever.moderatorclient.api.rest.ElideRouteBuilder; -import com.faforever.moderatorclient.api.rest.FafApiCommunicationService; +import com.faforever.commons.api.dto.Avatar; +import com.faforever.moderatorclient.api.ElideRouteBuilder; +import com.faforever.moderatorclient.api.FafApiCommunicationService; import lombok.extern.slf4j.Slf4j; import org.jetbrains.annotations.NotNull; import org.springframework.stereotype.Service; diff --git a/src/main/java/com/faforever/moderatorclient/api/rest/domain/DomainBlacklistService.java b/src/main/java/com/faforever/moderatorclient/api/domain/DomainBlacklistService.java similarity index 79% rename from src/main/java/com/faforever/moderatorclient/api/rest/domain/DomainBlacklistService.java rename to src/main/java/com/faforever/moderatorclient/api/domain/DomainBlacklistService.java index 05ac6a0..e373ea4 100644 --- a/src/main/java/com/faforever/moderatorclient/api/rest/domain/DomainBlacklistService.java +++ b/src/main/java/com/faforever/moderatorclient/api/domain/DomainBlacklistService.java @@ -1,8 +1,8 @@ -package com.faforever.moderatorclient.api.rest.domain; +package com.faforever.moderatorclient.api.domain; -import com.faforever.moderatorclient.api.dto.DomainBlacklist; -import com.faforever.moderatorclient.api.rest.ElideRouteBuilder; -import com.faforever.moderatorclient.api.rest.FafApiCommunicationService; +import com.faforever.commons.api.dto.DomainBlacklist; +import com.faforever.moderatorclient.api.ElideRouteBuilder; +import com.faforever.moderatorclient.api.FafApiCommunicationService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; diff --git a/src/main/java/com/faforever/moderatorclient/api/rest/domain/MapService.java b/src/main/java/com/faforever/moderatorclient/api/domain/MapService.java similarity index 92% rename from src/main/java/com/faforever/moderatorclient/api/rest/domain/MapService.java rename to src/main/java/com/faforever/moderatorclient/api/domain/MapService.java index ef2e3c4..291101c 100644 --- a/src/main/java/com/faforever/moderatorclient/api/rest/domain/MapService.java +++ b/src/main/java/com/faforever/moderatorclient/api/domain/MapService.java @@ -1,10 +1,10 @@ -package com.faforever.moderatorclient.api.rest.domain; +package com.faforever.moderatorclient.api.domain; -import com.faforever.moderatorclient.api.dto.Ladder1v1Map; -import com.faforever.moderatorclient.api.dto.Map; -import com.faforever.moderatorclient.api.dto.MapVersion; -import com.faforever.moderatorclient.api.rest.ElideRouteBuilder; -import com.faforever.moderatorclient.api.rest.FafApiCommunicationService; +import com.faforever.commons.api.dto.Ladder1v1Map; +import com.faforever.commons.api.dto.Map; +import com.faforever.commons.api.dto.MapVersion; +import com.faforever.moderatorclient.api.ElideRouteBuilder; +import com.faforever.moderatorclient.api.FafApiCommunicationService; import lombok.extern.slf4j.Slf4j; import org.jetbrains.annotations.NotNull; import org.springframework.stereotype.Service; diff --git a/src/main/java/com/faforever/moderatorclient/api/rest/domain/UserService.java b/src/main/java/com/faforever/moderatorclient/api/domain/UserService.java similarity index 72% rename from src/main/java/com/faforever/moderatorclient/api/rest/domain/UserService.java rename to src/main/java/com/faforever/moderatorclient/api/domain/UserService.java index 09beb69..c605b34 100644 --- a/src/main/java/com/faforever/moderatorclient/api/rest/domain/UserService.java +++ b/src/main/java/com/faforever/moderatorclient/api/domain/UserService.java @@ -1,18 +1,14 @@ -package com.faforever.moderatorclient.api.rest.domain; - -import com.faforever.moderatorclient.api.dto.*; -import com.faforever.moderatorclient.api.rest.ElideRouteBuilder; -import com.faforever.moderatorclient.api.rest.FafApiCommunicationService; -import com.faforever.moderatorclient.mapstruct.FeaturedModMapper; -import com.faforever.moderatorclient.mapstruct.GamePlayerStatsMapper; -import com.faforever.moderatorclient.mapstruct.UserNoteMapper; -import com.faforever.moderatorclient.ui.domain.FeaturedModFX; -import com.faforever.moderatorclient.ui.domain.UserNoteFX; +package com.faforever.moderatorclient.api.domain; + +import com.faforever.commons.api.dto.*; +import com.faforever.moderatorclient.api.ElideRouteBuilder; +import com.faforever.moderatorclient.api.FafApiCommunicationService; +import com.faforever.moderatorclient.mapstruct.*; +import com.faforever.moderatorclient.ui.domain.*; import lombok.extern.slf4j.Slf4j; import org.jetbrains.annotations.NotNull; import org.springframework.stereotype.Service; -import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -21,16 +17,24 @@ @Slf4j public class UserService { private final FafApiCommunicationService fafApi; + private final PlayerMapper playerMapper; + private final BanInfoMapper banInfoMapper; + private final BanRevokeDataMapper banRevokeDataMapper; private final GamePlayerStatsMapper gamePlayerStatsMapper; private final FeaturedModMapper featuredModMapper; private final UserNoteMapper userNoteMapper; + private final TeamkillMapper teamkillMapper; - public UserService(FafApiCommunicationService fafApi, GamePlayerStatsMapper gamePlayerStatsMapper, FeaturedModMapper featuredModMapper, UserNoteMapper userNoteMapper) { + public UserService(FafApiCommunicationService fafApi, PlayerMapper playerMapper, BanInfoMapper banInfoMapper, BanRevokeDataMapper banRevokeDataMapper, GamePlayerStatsMapper gamePlayerStatsMapper, FeaturedModMapper featuredModMapper, UserNoteMapper userNoteMapper, TeamkillMapper teamkillMapper) { this.fafApi = fafApi; + this.playerMapper = playerMapper; + this.banInfoMapper = banInfoMapper; + this.banRevokeDataMapper = banRevokeDataMapper; this.gamePlayerStatsMapper = gamePlayerStatsMapper; this.featuredModMapper = featuredModMapper; this.userNoteMapper = userNoteMapper; + this.teamkillMapper = teamkillMapper; } private ElideRouteBuilder addModeratorIncludes(@NotNull ElideRouteBuilder builder) { @@ -52,10 +56,12 @@ private ElideRouteBuilder addModeratorIncludes(@NotNull ElideRouteBuilder builde .addInclude(variablePrefix + "avatarAssignments") .addInclude(variablePrefix + "avatarAssignments.avatar") .addInclude(variablePrefix + "bans") - .addInclude(variablePrefix + "bans.banRevokeData"); + .addInclude(variablePrefix + "bans.author") + .addInclude(variablePrefix + "bans.banRevokeData") + .addInclude(variablePrefix + "bans.banRevokeData.author"); } - public List findLatestRegistrations() { + public List findLatestRegistrations() { log.debug("Searching for latest registrations"); ElideRouteBuilder routeBuilder = ElideRouteBuilder.of(Player.class) .sort("id", false) @@ -64,10 +70,10 @@ public List findLatestRegistrations() { List result = fafApi.getPage(routeBuilder, 100, 1, Collections.emptyMap()); log.trace("found {} users", result.size()); - return result; + return playerMapper.mapToFx(result); } - private List findUsersByAttribute(@NotNull String attribute, @NotNull String pattern) { + private List findUsersByAttribute(@NotNull String attribute, @NotNull String pattern) { log.debug("Searching for player by attribute '{}' with pattern: {}", attribute, pattern); ElideRouteBuilder routeBuilder = ElideRouteBuilder.of(Player.class) .filter(ElideRouteBuilder.qBuilder().string(attribute).eq(pattern)); @@ -75,30 +81,30 @@ private List findUsersByAttribute(@NotNull String attribute, @NotNull St List result = fafApi.getAll(routeBuilder); log.trace("found {} users", result.size()); - return result; + return playerMapper.mapToFx(result); } - public List findUserById(@NotNull String pattern) { + public List findUserById(@NotNull String pattern) { return findUsersByAttribute("id", pattern); } - public List findUserByName(@NotNull String pattern) { + public List findUserByName(@NotNull String pattern) { return findUsersByAttribute("login", pattern); } - public List findUserByEmail(@NotNull String pattern) { + public List findUserByEmail(@NotNull String pattern) { return findUsersByAttribute("email", pattern); } - public List findUserBySteamId(@NotNull String pattern) { + public List findUserBySteamId(@NotNull String pattern) { return findUsersByAttribute("steamId", pattern); } - public List findUserByIP(@NotNull String pattern) { + public List findUserByIP(@NotNull String pattern) { return findUsersByAttribute("recentIpAddress", pattern); } - public Collection findUsersByPreviousName(@NotNull String pattern) { + public List findUsersByPreviousName(@NotNull String pattern) { log.debug("Searching for player by previous name with pattern: {}", pattern); ElideRouteBuilder routeBuilder = ElideRouteBuilder.of(NameRecord.class) .addInclude("player") @@ -109,10 +115,12 @@ public Collection findUsersByPreviousName(@NotNull String pattern) { log.trace("found {} name records", result.size()); return result.stream() .map(NameRecord::getPlayer) - .collect(Collectors.toSet()); + .distinct() + .map(playerMapper::map) + .collect(Collectors.toList()); } - public List findLatestTeamkills() { + public List findLatestTeamkills() { log.debug("Searching for latest teamkills "); ElideRouteBuilder routeBuilder = ElideRouteBuilder.of(Teamkill.class) .addInclude("teamkiller") @@ -121,10 +129,10 @@ public List findLatestTeamkills() { List result = fafApi.getPage(routeBuilder, 100, 1, Collections.emptyMap()); log.trace("found {} teamkills", result.size()); - return result; + return teamkillMapper.map(result); } - public List findTeamkillsByUserId(@NotNull String userId) { + public List findTeamkillsByUserId(@NotNull String userId) { log.debug("Searching for teamkills invoked by player id: {}", userId); ElideRouteBuilder routeBuilder = ElideRouteBuilder.of(Teamkill.class) .addInclude("teamkiller") @@ -133,15 +141,17 @@ public List findTeamkillsByUserId(@NotNull String userId) { List result = fafApi.getAll(routeBuilder); log.trace("found {} teamkills", result.size()); - return result; + return teamkillMapper.map(result); } - public BanInfo patchBanInfo(@NotNull BanInfo banInfo) { + public BanInfo patchBanInfo(@NotNull BanInfoFX banInfoFX) { + BanInfo banInfo = banInfoMapper.map(banInfoFX); log.debug("Patching BanInfo of id: ", banInfo.getId()); return fafApi.patch(ElideRouteBuilder.of(BanInfo.class).id(banInfo.getId()), banInfo); } - public BanRevokeData revokeBan(@NotNull BanRevokeData banRevokeData) { + public BanRevokeData revokeBan(@NotNull BanRevokeDataFX banRevokeDataFX) { + BanRevokeData banRevokeData = banRevokeDataMapper.map(banRevokeDataFX); log.debug("Revoking ban with id: ", banRevokeData.getBan().getId()); banRevokeData.setAuthor(fafApi.getSelfPlayer()); ElideRouteBuilder routeBuilder = ElideRouteBuilder.of(Player.class) @@ -151,10 +161,11 @@ public BanRevokeData revokeBan(@NotNull BanRevokeData banRevokeData) { return (BanRevokeData) fafApi.postRelationship(routeBuilder, banRevokeData); } - public BanInfo createBan(@NotNull BanInfo banInfo) { + public String createBan(@NotNull BanInfoFX banInfoFX) { + BanInfo banInfo = banInfoMapper.map(banInfoFX); log.debug("Creating ban"); banInfo.setAuthor(fafApi.getSelfPlayer()); - return fafApi.post(ElideRouteBuilder.of(BanInfo.class), banInfo); + return fafApi.post(ElideRouteBuilder.of(BanInfo.class), banInfo).getId(); } public List getLastHundredPlayedGamesByFeaturedMod(@NotNull String userId, int page, FeaturedModFX featuredModFX) { @@ -213,4 +224,13 @@ public UserNoteFX patchUserNote(UserNote userNote) { log.debug("Patching UserNote of id: ", userNote.getId()); return userNoteMapper.map(fafApi.patch(ElideRouteBuilder.of(UserNote.class).id(userNote.getId()), userNote)); } + + public BanInfoFX getBanInfoById(String banInfoId) { + log.debug("Search for ban id: " + banInfoId); + ElideRouteBuilder routeBuilder = ElideRouteBuilder.of(BanInfo.class) + .id(banInfoId) + .addInclude("player") + .addInclude("author"); + return banInfoMapper.map(fafApi.getOne(routeBuilder)); + } } diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/AbstractEntity.java b/src/main/java/com/faforever/moderatorclient/api/dto/AbstractEntity.java deleted file mode 100644 index fee1a55..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/AbstractEntity.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.github.jasminb.jsonapi.annotations.Id; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; - -import java.time.OffsetDateTime; - -@Getter -@Setter -@EqualsAndHashCode(of = "id") -public abstract class AbstractEntity { - @Id - protected String id; - protected OffsetDateTime createTime; - protected OffsetDateTime updateTime; -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/AchievementDefinition.java b/src/main/java/com/faforever/moderatorclient/api/dto/AchievementDefinition.java deleted file mode 100644 index ef684f7..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/AchievementDefinition.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.github.jasminb.jsonapi.annotations.Id; -import com.github.jasminb.jsonapi.annotations.Type; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@EqualsAndHashCode(of = "id") -@Type("achievement") -public class AchievementDefinition { - - @Id - private String id; - private String description; - private int experiencePoints; - private AchievementState initialState; - private String name; - private String revealedIconUrl; - private Integer totalSteps; - private AchievementType type; - private String unlockedIconUrl; - private int order; -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/AchievementState.java b/src/main/java/com/faforever/moderatorclient/api/dto/AchievementState.java deleted file mode 100644 index 149a2d2..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/AchievementState.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - - -public enum AchievementState { - HIDDEN, - REVEALED, - UNLOCKED -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/AchievementType.java b/src/main/java/com/faforever/moderatorclient/api/dto/AchievementType.java deleted file mode 100644 index f97f5ed..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/AchievementType.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -public enum AchievementType { - STANDARD, - INCREMENTAL -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/ApiException.java b/src/main/java/com/faforever/moderatorclient/api/dto/ApiException.java deleted file mode 100644 index 80f39ea..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/ApiException.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - - -import com.github.jasminb.jsonapi.models.errors.Error; - -import java.util.List; -import java.util.stream.Collectors; - -public class ApiException extends RuntimeException { - - private final List errors; - - public ApiException(List errors) { - this.errors = errors; - } - - @Override - public String getLocalizedMessage() { - // TODO localize - return errors.stream() - .map(Error::getDetail) - .collect(Collectors.joining("\n")); - } -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/Avatar.java b/src/main/java/com/faforever/moderatorclient/api/dto/Avatar.java deleted file mode 100644 index f659ccb..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/Avatar.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.github.jasminb.jsonapi.annotations.Relationship; -import com.github.jasminb.jsonapi.annotations.Type; -import lombok.Getter; -import lombok.Setter; - -import java.util.List; - -@Type("avatar") -@Getter -@Setter -public class Avatar extends AbstractEntity { - private String url; - private String tooltip; - @Relationship("assignments") - @JsonIgnore - private List assignments; -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/AvatarAssignment.java b/src/main/java/com/faforever/moderatorclient/api/dto/AvatarAssignment.java deleted file mode 100644 index ffe6932..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/AvatarAssignment.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.github.jasminb.jsonapi.annotations.Relationship; -import com.github.jasminb.jsonapi.annotations.Type; -import lombok.Getter; -import lombok.Setter; - -import java.time.OffsetDateTime; - -@Type("avatarAssignment") -@Getter -@Setter -public class AvatarAssignment extends AbstractEntity { - private boolean selected; - private OffsetDateTime expiresAt; - @Relationship("player") - @JsonIgnore - private Player player; - @Relationship("avatar") - @JsonIgnore - private Avatar avatar; -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/BanDurationType.java b/src/main/java/com/faforever/moderatorclient/api/dto/BanDurationType.java deleted file mode 100644 index cf215ac..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/BanDurationType.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -public enum BanDurationType { - PERMANENT, TEMPORARY -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/BanInfo.java b/src/main/java/com/faforever/moderatorclient/api/dto/BanInfo.java deleted file mode 100644 index 4a96ad2..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/BanInfo.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.github.jasminb.jsonapi.annotations.Relationship; -import com.github.jasminb.jsonapi.annotations.Type; -import lombok.Getter; -import lombok.Setter; - -import java.time.OffsetDateTime; - -@Type("banInfo") -@RestrictedVisibility("HasBanRead") -@Getter -@Setter -public class BanInfo extends AbstractEntity { - @Relationship("player") - @JsonIgnore - private Player player; - @Relationship("author") - @JsonIgnore - private Player author; - private String reason; - private OffsetDateTime expiresAt; - private BanLevel level; - @Relationship("banRevokeData") - @JsonIgnore - private BanRevokeData banRevokeData; - - @JsonIgnore - public BanDurationType getDuration() { - return expiresAt == null ? BanDurationType.PERMANENT : BanDurationType.TEMPORARY; - } - - @JsonIgnore - public BanStatus getBanStatus() { - if (banRevokeData != null) { - return BanStatus.DISABLED; - } - if (getDuration() == BanDurationType.PERMANENT) { - return BanStatus.BANNED; - } - return expiresAt.isAfter(OffsetDateTime.now()) - ? BanStatus.BANNED - : BanStatus.EXPIRED; - } -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/BanLevel.java b/src/main/java/com/faforever/moderatorclient/api/dto/BanLevel.java deleted file mode 100644 index 83bead0..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/BanLevel.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -public enum BanLevel { - CHAT, GLOBAL -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/BanRevokeData.java b/src/main/java/com/faforever/moderatorclient/api/dto/BanRevokeData.java deleted file mode 100644 index e17435e..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/BanRevokeData.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.github.jasminb.jsonapi.annotations.Relationship; -import com.github.jasminb.jsonapi.annotations.Type; -import lombok.Getter; -import lombok.Setter; - -@Type("banRevokeData") -@Getter -@Setter -@RestrictedVisibility("HasBanRead") -public class BanRevokeData extends AbstractEntity { - @Relationship("ban") - @JsonIgnore - private BanInfo ban; - private String reason; - @Relationship("author") - @JsonIgnore - private Player author; -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/BanStatus.java b/src/main/java/com/faforever/moderatorclient/api/dto/BanStatus.java deleted file mode 100644 index 52d2e0a..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/BanStatus.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -public enum BanStatus { - BANNED, DISABLED, EXPIRED -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/Clan.java b/src/main/java/com/faforever/moderatorclient/api/dto/Clan.java deleted file mode 100644 index 9cd642b..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/Clan.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.github.jasminb.jsonapi.annotations.Id; -import com.github.jasminb.jsonapi.annotations.Relationship; -import com.github.jasminb.jsonapi.annotations.Type; -import lombok.Data; - -import java.time.OffsetDateTime; -import java.util.List; - -@Data -@Type("clan") -public class Clan { - @Id - private String id; - private String name; - private String tag; - private String description; - private String tagColor; - private String websiteUrl; - private OffsetDateTime createTime; - private OffsetDateTime updateTime; - - @Relationship("founder") - private Player founder; - - @Relationship("leader") - private Player leader; - - @Relationship("memberships") - private List memberships; -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/ClanMembership.java b/src/main/java/com/faforever/moderatorclient/api/dto/ClanMembership.java deleted file mode 100644 index bc797bb..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/ClanMembership.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.github.jasminb.jsonapi.annotations.Id; -import com.github.jasminb.jsonapi.annotations.Relationship; -import com.github.jasminb.jsonapi.annotations.Type; -import lombok.Data; - -import java.time.OffsetDateTime; - -@Data -@Type("clanMembership") -public class ClanMembership { - @Id - private String id; - private OffsetDateTime createTime; - private OffsetDateTime updateTime; - - @Relationship("clan") - private Clan clan; - - @Relationship("player") - private Player player; -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/CoopMission.java b/src/main/java/com/faforever/moderatorclient/api/dto/CoopMission.java deleted file mode 100644 index 43daf8d..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/CoopMission.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.github.jasminb.jsonapi.annotations.Id; -import com.github.jasminb.jsonapi.annotations.Type; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@EqualsAndHashCode(of = "id") -@Type("coopMission") -public class CoopMission { - @Id - private String id; - private String name; - private int version; - private String category; - private String thumbnailUrlSmall; - private String thumbnailUrlLarge; - private String description; - private String downloadUrl; - private String folderName; -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/CoopResult.java b/src/main/java/com/faforever/moderatorclient/api/dto/CoopResult.java deleted file mode 100644 index 0043837..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/CoopResult.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.github.jasminb.jsonapi.annotations.Id; -import com.github.jasminb.jsonapi.annotations.Type; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; - -import java.time.Duration; - -@Getter -@Setter -@EqualsAndHashCode(of = "id") -@Type("coopResult") -public class CoopResult { - @Id - private String id; - private Duration duration; - private String playerNames; - private boolean secondaryObjectives; - private int ranking; - private int playerCount; -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/DomainBlacklist.java b/src/main/java/com/faforever/moderatorclient/api/dto/DomainBlacklist.java deleted file mode 100644 index ac21d4e..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/DomainBlacklist.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.github.jasminb.jsonapi.annotations.Id; -import com.github.jasminb.jsonapi.annotations.Type; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; - -@RestrictedVisibility("IsModerator") -@Getter -@Setter -@EqualsAndHashCode(of = "domain") -@Type("domainBlacklist") -public class DomainBlacklist { - @Id - String domain; -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/Event.java b/src/main/java/com/faforever/moderatorclient/api/dto/Event.java deleted file mode 100644 index aaebe76..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/Event.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.github.jasminb.jsonapi.annotations.Id; -import com.github.jasminb.jsonapi.annotations.Type; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@EqualsAndHashCode(of = "id") -@Type("event") -public class Event { - - @Id - private String id; - private String name; - private String imageUrl; - private Type type; - - public enum Type { - NUMERIC, TIME - } -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/Faction.java b/src/main/java/com/faforever/moderatorclient/api/dto/Faction.java deleted file mode 100644 index baad1dc..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/Faction.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.extern.slf4j.Slf4j; - -import java.util.HashMap; -import java.util.Map; - -@Slf4j -@Getter -@AllArgsConstructor -public enum Faction { - // Order is crucial - AEON("aeon"), - CYBRAN("cybran"), - UEF("uef"), - SERAPHIM("seraphim"), - NOMAD("nomad"), - CIVILIAN("civilian"); - - private static final Map fromString; - - static { - fromString = new HashMap<>(); - for (Faction faction : values()) { - fromString.put(faction.string, faction); - } - } - - private final String string; - - @JsonCreator - public static Faction fromFaValue(int value) { - return Faction.values()[value - 1]; - } - - public static Faction fromString(String string) { - return fromString.get(string); - } - - /** - * Returns the faction value used as in "Forged Alliance Forever". - */ - @JsonValue - public int toFaValue() { - return ordinal() + 1; - } -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/FeaturedMod.java b/src/main/java/com/faforever/moderatorclient/api/dto/FeaturedMod.java deleted file mode 100644 index 36d881a..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/FeaturedMod.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.github.jasminb.jsonapi.annotations.Id; -import com.github.jasminb.jsonapi.annotations.Type; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@EqualsAndHashCode(of = "id") -@Type("featuredMod") -public class FeaturedMod { - @Id - private String id; - private String description; - private String displayName; - private int order; - private String gitBranch; - private String gitUrl; - private String bireusUrl; - private String technicalName; - private boolean visible; -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/FeaturedModFile.java b/src/main/java/com/faforever/moderatorclient/api/dto/FeaturedModFile.java deleted file mode 100644 index 14bdd13..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/FeaturedModFile.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.github.jasminb.jsonapi.annotations.Id; -import com.github.jasminb.jsonapi.annotations.Type; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@EqualsAndHashCode(of = "id") -@Type("featuredModFile") -public class FeaturedModFile { - @Id - private String id; - private String version; - private String group; - private String name; - private String md5; - private String url; -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/Game.java b/src/main/java/com/faforever/moderatorclient/api/dto/Game.java deleted file mode 100644 index d955fc9..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/Game.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.github.jasminb.jsonapi.annotations.Id; -import com.github.jasminb.jsonapi.annotations.Relationship; -import com.github.jasminb.jsonapi.annotations.Type; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; - -import java.time.OffsetDateTime; -import java.util.List; - -@Getter -@Setter -@EqualsAndHashCode(of = "id") -@Type("game") -public class Game { - @Id - private String id; - private String name; - private OffsetDateTime startTime; - private OffsetDateTime endTime; - private Validity validity; - private VictoryCondition victoryCondition; - - @Relationship("reviews") - private List reviews; - - @Relationship("playerStats") - private List playerStats; - - @Relationship("host") - private Player host; - - @Relationship("featuredMod") - private FeaturedMod featuredMod; - - @Relationship("mapVersion") - private MapVersion mapVersion; -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/GamePlayerStats.java b/src/main/java/com/faforever/moderatorclient/api/dto/GamePlayerStats.java deleted file mode 100644 index 4636794..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/GamePlayerStats.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.github.jasminb.jsonapi.annotations.Id; -import com.github.jasminb.jsonapi.annotations.Relationship; -import com.github.jasminb.jsonapi.annotations.Type; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; -import org.jetbrains.annotations.Nullable; - -import java.time.OffsetDateTime; - -@Getter -@Setter -@EqualsAndHashCode(of = "id") -@Type("gamePlayerStats") -public class GamePlayerStats { - @Id - private String id; - private boolean ai; - private Faction faction; - private byte color; - private byte team; - private byte startSpot; - private Float beforeMean; - private Float beforeDeviation; - private Float afterMean; - private Float afterDeviation; - private byte score; - @Nullable - private OffsetDateTime scoreTime; - - @Relationship("game") - private Game game; - - @Relationship("player") - private Player player; -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/GameReview.java b/src/main/java/com/faforever/moderatorclient/api/dto/GameReview.java deleted file mode 100644 index c9264a9..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/GameReview.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.github.jasminb.jsonapi.annotations.Relationship; -import com.github.jasminb.jsonapi.annotations.Type; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@Type("gameReview") -public class GameReview extends Review { - - @Relationship("game") - private Game game; -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/GlobalLeaderboardEntry.java b/src/main/java/com/faforever/moderatorclient/api/dto/GlobalLeaderboardEntry.java deleted file mode 100644 index 40c7b24..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/GlobalLeaderboardEntry.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.github.jasminb.jsonapi.annotations.Id; -import com.github.jasminb.jsonapi.annotations.Type; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@EqualsAndHashCode(of = "id") -@Type("globalLeaderboardEntry") -public class GlobalLeaderboardEntry { - @Id - private String id; - private String name; - private int rank; - private Double mean; - private Double deviation; - private Integer numGames; - private Boolean isActive; - private Double rating; -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/GlobalRating.java b/src/main/java/com/faforever/moderatorclient/api/dto/GlobalRating.java deleted file mode 100644 index ad51d21..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/GlobalRating.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.github.jasminb.jsonapi.annotations.Type; - -@Type("globalRating") -public class GlobalRating extends Rating { -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/Ladder1v1LeaderboardEntry.java b/src/main/java/com/faforever/moderatorclient/api/dto/Ladder1v1LeaderboardEntry.java deleted file mode 100644 index 5596855..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/Ladder1v1LeaderboardEntry.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.github.jasminb.jsonapi.annotations.Id; -import com.github.jasminb.jsonapi.annotations.Type; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@EqualsAndHashCode(of = "id") -@Type("ladder1v1LeaderboardEntry") -public class Ladder1v1LeaderboardEntry { - @Id - private String id; - private int rank; - private String name; - private Double mean; - private Double deviation; - private Integer numGames; - private Integer wonGames; - private Boolean isActive; - private Double rating; -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/Ladder1v1Map.java b/src/main/java/com/faforever/moderatorclient/api/dto/Ladder1v1Map.java deleted file mode 100644 index a927dfd..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/Ladder1v1Map.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.github.jasminb.jsonapi.annotations.Id; -import com.github.jasminb.jsonapi.annotations.Relationship; -import com.github.jasminb.jsonapi.annotations.Type; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@EqualsAndHashCode(of = "id") -@Type("ladder1v1Map") -public class Ladder1v1Map { - @Id - private String id; - @Relationship("mapVersion") - private MapVersion mapVersion; -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/Ladder1v1Rating.java b/src/main/java/com/faforever/moderatorclient/api/dto/Ladder1v1Rating.java deleted file mode 100644 index cfd76df..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/Ladder1v1Rating.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.github.jasminb.jsonapi.annotations.Type; - -@Type("ladder1v1Rating") -public class Ladder1v1Rating extends Rating { -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/LegacyAccessLevel.java b/src/main/java/com/faforever/moderatorclient/api/dto/LegacyAccessLevel.java deleted file mode 100644 index 3621307..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/LegacyAccessLevel.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import lombok.Getter; - -/** - * @deprecated AccessLevel are going to be replaced with role based security - */ -@Getter -@Deprecated -public enum LegacyAccessLevel { - ROLE_USER, - ROLE_MODERATOR, - ROLE_ADMINISTRATOR -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/LobbyGroup.java b/src/main/java/com/faforever/moderatorclient/api/dto/LobbyGroup.java deleted file mode 100644 index 18aa330..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/LobbyGroup.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.github.jasminb.jsonapi.annotations.Id; -import com.github.jasminb.jsonapi.annotations.Type; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; - -/** - * @deprecated LobbyGroups are supposed to be replaced with role based security - */ -@Getter -@Deprecated -@NoArgsConstructor -@AllArgsConstructor -@Type("lobbyGroup") -public class LobbyGroup { - @Id - private String userId; - private LegacyAccessLevel accessLevel; -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/Map.java b/src/main/java/com/faforever/moderatorclient/api/dto/Map.java deleted file mode 100644 index bc27fd1..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/Map.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.github.jasminb.jsonapi.annotations.Id; -import com.github.jasminb.jsonapi.annotations.Relationship; -import com.github.jasminb.jsonapi.annotations.Type; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; - -import java.time.OffsetDateTime; -import java.util.List; - -@Getter -@Setter -@EqualsAndHashCode(of = "id") -@Type("map") -public class Map { - - @Id - private String id; - private String battleType; - private OffsetDateTime createTime; - private OffsetDateTime updateTime; - private String displayName; - private String mapType; - - @Relationship("author") - private Player author; - - @Relationship("statistics") - private MapStatistics statistics; - - @Relationship("latestVersion") - @JsonIgnore - private MapVersion latestVersion; - - @Relationship("versions") - @JsonIgnore - private List versions; -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/MapStatistics.java b/src/main/java/com/faforever/moderatorclient/api/dto/MapStatistics.java deleted file mode 100644 index 61e6426..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/MapStatistics.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.github.jasminb.jsonapi.annotations.Id; -import com.github.jasminb.jsonapi.annotations.Relationship; -import com.github.jasminb.jsonapi.annotations.Type; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@EqualsAndHashCode(of = "id") -@Type("mapStatistics") -public class MapStatistics { - @Id - private String id; - private int downloads; - private int draws; - private int plays; - - @Relationship("map") - private Map map; -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/MapVersion.java b/src/main/java/com/faforever/moderatorclient/api/dto/MapVersion.java deleted file mode 100644 index 6c29034..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/MapVersion.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.github.jasminb.jsonapi.annotations.Relationship; -import com.github.jasminb.jsonapi.annotations.Type; -import lombok.Getter; -import lombok.Setter; -import org.apache.maven.artifact.versioning.ComparableVersion; -import org.jetbrains.annotations.Nullable; - -import java.net.URL; -import java.util.List; - -@Getter -@Setter -@Type("mapVersion") -public class MapVersion extends AbstractEntity { - private String description; - private Integer maxPlayers; - private Integer width; - private Integer height; - private ComparableVersion version; - private String folderName; - // TODO name consistently with folderName - private String filename; - private boolean ranked; - private boolean hidden; - private URL thumbnailUrlSmall; - private URL thumbnailUrlLarge; - private URL downloadUrl; - - @Relationship("map") - private Map map; - - @Relationship("statistics") - private MapVersionStatistics statistics; - - @Nullable - @Relationship("ladder1v1Map") - private Ladder1v1Map ladder1v1Map; - - @Relationship("reviews") - private List reviews; -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/MapVersionReview.java b/src/main/java/com/faforever/moderatorclient/api/dto/MapVersionReview.java deleted file mode 100644 index 450aca8..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/MapVersionReview.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.github.jasminb.jsonapi.annotations.Relationship; -import com.github.jasminb.jsonapi.annotations.Type; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@Type("mapVersionReview") -public class MapVersionReview extends Review { - - @Relationship("mapVersion") - private MapVersion mapVersion; -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/MapVersionStatistics.java b/src/main/java/com/faforever/moderatorclient/api/dto/MapVersionStatistics.java deleted file mode 100644 index bd60217..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/MapVersionStatistics.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.github.jasminb.jsonapi.annotations.Id; -import com.github.jasminb.jsonapi.annotations.Relationship; -import com.github.jasminb.jsonapi.annotations.Type; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@EqualsAndHashCode(of = "id") -@Type("mapVersionStatistics") -public class MapVersionStatistics { - @Id - private String id; - private int downloads; - private int draws; - private int plays; - - @Relationship("mapVersion") - private MapVersion mapVersion; -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/Mod.java b/src/main/java/com/faforever/moderatorclient/api/dto/Mod.java deleted file mode 100644 index 1519c8c..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/Mod.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.github.jasminb.jsonapi.annotations.Id; -import com.github.jasminb.jsonapi.annotations.Relationship; -import com.github.jasminb.jsonapi.annotations.Type; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -import java.time.OffsetDateTime; -import java.util.List; - -@Getter -@Setter -@EqualsAndHashCode(of = "id") -@Type("mod") -@NoArgsConstructor -public class Mod { - - @Id - private String id; - private String displayName; - private String author; - private OffsetDateTime createTime; - - @Relationship("versions") - private List versions; - - @Relationship("latestVersion") - private ModVersion latestVersion; - - public Mod(String id, String displayName, String author, OffsetDateTime createTime) { - this.id = id; - this.displayName = displayName; - this.author = author; - this.createTime = createTime; - } -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/ModType.java b/src/main/java/com/faforever/moderatorclient/api/dto/ModType.java deleted file mode 100644 index 1fafccf..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/ModType.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -public enum ModType { - UI, SIM -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/ModVersion.java b/src/main/java/com/faforever/moderatorclient/api/dto/ModVersion.java deleted file mode 100644 index 5954762..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/ModVersion.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.github.jasminb.jsonapi.annotations.Id; -import com.github.jasminb.jsonapi.annotations.Relationship; -import com.github.jasminb.jsonapi.annotations.Type; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; - -import java.net.URL; -import java.time.OffsetDateTime; - -@Getter -@Setter -@EqualsAndHashCode(of = "id") -@Type("modVersion") -public class ModVersion { - - @Id - private String id; - private String uid; - private ModType type; - private String description; - private short version; - private String filename; - private String icon; - private boolean ranked; - private boolean hidden; - private OffsetDateTime createTime; - private OffsetDateTime updateTime; - private URL thumbnailUrl; - private URL downloadUrl; - - @Relationship("mod") - private Mod mod; -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/ModVersionReview.java b/src/main/java/com/faforever/moderatorclient/api/dto/ModVersionReview.java deleted file mode 100644 index 224a5f5..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/ModVersionReview.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.github.jasminb.jsonapi.annotations.Relationship; -import com.github.jasminb.jsonapi.annotations.Type; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@Type("modVersionReview") -public class ModVersionReview extends Review { - - @Relationship("modVersion") - private ModVersion modVersion; -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/NameRecord.java b/src/main/java/com/faforever/moderatorclient/api/dto/NameRecord.java deleted file mode 100644 index a8eff32..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/NameRecord.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.github.jasminb.jsonapi.annotations.Id; -import com.github.jasminb.jsonapi.annotations.Relationship; -import com.github.jasminb.jsonapi.annotations.Type; -import lombok.Getter; - -import java.time.OffsetDateTime; - -@Getter -@Type("nameRecord") -public class NameRecord { - @Id - private String id; - private OffsetDateTime changeTime; - @Relationship("player") - private Player player; - private String name; -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/Player.java b/src/main/java/com/faforever/moderatorclient/api/dto/Player.java deleted file mode 100644 index aa666ba..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/Player.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.github.jasminb.jsonapi.annotations.Relationship; -import com.github.jasminb.jsonapi.annotations.Type; -import lombok.Getter; -import lombok.Setter; - -import java.util.List; - -@Getter -@Setter -@Type("player") -public class Player extends AbstractEntity { - private String login; - @Relationship("names") - List names; - @RestrictedVisibility("IsModerator") - private String email; - private String userAgent; - @RestrictedVisibility("IsModerator") - private String steamId; - @RestrictedVisibility("IsModerator") - private String recentIpAddress; - - @Relationship("globalRating") - private GlobalRating globalRating; - - @Relationship("ladder1v1Rating") - private Ladder1v1Rating ladder1v1Rating; - - @Relationship("lobbyGroup") - private LobbyGroup lobbyGroup; - - @Relationship("bans") - private List bans; - - @Relationship("avatarAssignments") - @JsonIgnore - private List avatarAssignments; - - @Override - public String toString() { - return String.format("%s [id %s]", login, id); - } -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/PlayerAchievement.java b/src/main/java/com/faforever/moderatorclient/api/dto/PlayerAchievement.java deleted file mode 100644 index 9b43a26..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/PlayerAchievement.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - - -import com.github.jasminb.jsonapi.annotations.Id; -import com.github.jasminb.jsonapi.annotations.Relationship; -import com.github.jasminb.jsonapi.annotations.Type; -import lombok.Data; - -import java.time.Instant; - -@Data -@Type("playerAchievement") -public class PlayerAchievement { - - @Id - private String id; - private AchievementState state; - private Integer currentSteps; - private Instant createTime; - private Instant updateTime; - - @Relationship("achievement") - private AchievementDefinition achievement; -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/PlayerEvent.java b/src/main/java/com/faforever/moderatorclient/api/dto/PlayerEvent.java deleted file mode 100644 index 1abeb11..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/PlayerEvent.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.github.jasminb.jsonapi.annotations.Id; -import com.github.jasminb.jsonapi.annotations.Relationship; -import com.github.jasminb.jsonapi.annotations.Type; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@EqualsAndHashCode(of = "id") -@Type("playerEvent") -public class PlayerEvent { - - @Id - private String id; - private int count; - - @Relationship("event") - private Event event; -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/Rating.java b/src/main/java/com/faforever/moderatorclient/api/dto/Rating.java deleted file mode 100644 index d58f49c..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/Rating.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - - -import com.github.jasminb.jsonapi.annotations.Id; -import com.github.jasminb.jsonapi.annotations.Relationship; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@EqualsAndHashCode(of = "id") -public class Rating { - @Id - private String id; - private double mean; - private double deviation; - private double rating; - - @Relationship("player") - private Player player; -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/RestrictedVisibility.java b/src/main/java/com/faforever/moderatorclient/api/dto/RestrictedVisibility.java deleted file mode 100644 index 9e44ec2..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/RestrictedVisibility.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Indicates that a class or class field is only visible for users with additional permissions - */ -@Target({ElementType.TYPE, ElementType.FIELD}) -@Retention(RetentionPolicy.SOURCE) -public @interface RestrictedVisibility { - /** - * @return an array of API permissions which are allowed to query this field - */ - String[] value(); -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/Review.java b/src/main/java/com/faforever/moderatorclient/api/dto/Review.java deleted file mode 100644 index 78d8e38..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/Review.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.github.jasminb.jsonapi.annotations.Id; -import com.github.jasminb.jsonapi.annotations.Relationship; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; - -import java.sql.Timestamp; - -@Getter -@Setter -@EqualsAndHashCode(of = "id") -public class Review { - @Id - private String id; - private String text; - private Byte score; - private Timestamp createTime; - private Timestamp updateTime; - - @Relationship("player") - private Player player; -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/Teamkill.java b/src/main/java/com/faforever/moderatorclient/api/dto/Teamkill.java deleted file mode 100644 index e852ec6..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/Teamkill.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.github.jasminb.jsonapi.annotations.Id; -import com.github.jasminb.jsonapi.annotations.Relationship; -import com.github.jasminb.jsonapi.annotations.Type; -import lombok.Getter; - -import java.time.OffsetDateTime; - -@Getter -@Type("teamkill") -@RestrictedVisibility("IsModerator") -public class Teamkill { - @Id - private String id; - @Relationship("teamkiller") - private Player teamkiller; - @Relationship("victim") - private Player victim; - @Relationship("game") - private Game game; - private long gameTime; - private OffsetDateTime reportedAt; -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/UserNote.java b/src/main/java/com/faforever/moderatorclient/api/dto/UserNote.java deleted file mode 100644 index dbbf110..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/UserNote.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import com.github.jasminb.jsonapi.annotations.Relationship; -import com.github.jasminb.jsonapi.annotations.Type; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@Type("userNote") -@RestrictedVisibility("IsModerator") -public class UserNote extends AbstractEntity { - @Relationship("player") - private Player player; - @Relationship("author") - private Player author; - private boolean watched; - private String note; -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/Validity.java b/src/main/java/com/faforever/moderatorclient/api/dto/Validity.java deleted file mode 100644 index f9d81f2..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/Validity.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -public enum Validity { - // Order is crucial - VALID, - TOO_MANY_DESYNCS, - WRONG_VICTORY_CONDITION, - NO_FOG_OF_WAR, - CHEATS_ENABLED, - PREBUILT_ENABLED, - NORUSH_ENABLED, - BAD_UNIT_RESTRICTIONS, - BAD_MAP, - TOO_SHORT, - BAD_MOD, - COOP_NOT_RANKED, - MUTUAL_DRAW, - SINGLE_PLAYER, - FFA_NOT_RANKED, - UNEVEN_TEAMS_NOT_RANKED, - UNKNOWN_RESULT; -} diff --git a/src/main/java/com/faforever/moderatorclient/api/dto/VictoryCondition.java b/src/main/java/com/faforever/moderatorclient/api/dto/VictoryCondition.java deleted file mode 100644 index f2bf67a..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/dto/VictoryCondition.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.faforever.moderatorclient.api.dto; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.extern.slf4j.Slf4j; - -import java.util.HashMap; -import java.util.Map; - -@Slf4j -@Getter -@AllArgsConstructor -public enum VictoryCondition { - // Order is crucial - DEMORALIZATION(0), - DOMINATION(1), - ERADICATION(2), - SANDBOX(3), - UNKNOWN("unknown"); - - private static final Map fromNumber; - - static { - fromNumber = new HashMap<>(); - for (VictoryCondition victoryCondition : values()) { - fromNumber.put(victoryCondition.value, victoryCondition); - } - } - - private final Object value; - - public static VictoryCondition fromNumber(Object number) { - VictoryCondition victoryCondition = fromNumber.get(number); - if (victoryCondition == null) { - log.warn("Unknown victory condition: {}", number); - return UNKNOWN; - } - return victoryCondition; - } -} diff --git a/src/main/java/com/faforever/moderatorclient/api/event/LoginSuccessEvent.java b/src/main/java/com/faforever/moderatorclient/api/event/LoginSuccessEvent.java deleted file mode 100644 index 3332c98..0000000 --- a/src/main/java/com/faforever/moderatorclient/api/event/LoginSuccessEvent.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.faforever.moderatorclient.api.event; - -public class LoginSuccessEvent { - private final String username; - private final String password; - private final int userId; - - public LoginSuccessEvent(String username, String password, int userId) { - this.username = username; - this.password = password; - this.userId = userId; - } - - public String getUsername() { - return username; - } - - public int getUserId() { - return userId; - } - - public String getPassword() { - return password; - } -} diff --git a/src/main/java/com/faforever/moderatorclient/config/JsonApiConfig.java b/src/main/java/com/faforever/moderatorclient/config/JsonApiConfig.java index e0e34ee..c5010ac 100644 --- a/src/main/java/com/faforever/moderatorclient/config/JsonApiConfig.java +++ b/src/main/java/com/faforever/moderatorclient/config/JsonApiConfig.java @@ -21,7 +21,7 @@ public class JsonApiConfig { @Bean public ResourceConverter resourceConverter(ObjectMapper objectMapper) { objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); - return new ResourceConverter(objectMapper, findJsonApiTypes("com.faforever.moderatorclient.api.dto")); + return new ResourceConverter(objectMapper, findJsonApiTypes("com.faforever.commons.api.dto")); } private Class[] findJsonApiTypes(String scanPackage) { diff --git a/src/main/java/com/faforever/moderatorclient/mapstruct/AvatarAssignmentMapper.java b/src/main/java/com/faforever/moderatorclient/mapstruct/AvatarAssignmentMapper.java new file mode 100644 index 0000000..0e996a7 --- /dev/null +++ b/src/main/java/com/faforever/moderatorclient/mapstruct/AvatarAssignmentMapper.java @@ -0,0 +1,18 @@ +package com.faforever.moderatorclient.mapstruct; + +import com.faforever.commons.api.dto.AvatarAssignment; +import com.faforever.moderatorclient.ui.domain.AvatarAssignmentFX; +import org.mapstruct.Mapper; + +import java.util.List; + +@Mapper(uses = {JavaFXMapper.class, AvatarMapper.class, PlayerMapper.class, CycleAvoidingMappingContext.class}) +public abstract class AvatarAssignmentMapper { + public abstract AvatarAssignmentFX map(AvatarAssignment dto); + + public abstract AvatarAssignment map(AvatarAssignmentFX fxBean); + + public abstract List mapToFX(List dtoList); + + public abstract List mapToDto(List fxBeanList); +} diff --git a/src/main/java/com/faforever/moderatorclient/mapstruct/AvatarMapper.java b/src/main/java/com/faforever/moderatorclient/mapstruct/AvatarMapper.java new file mode 100644 index 0000000..c9f5d36 --- /dev/null +++ b/src/main/java/com/faforever/moderatorclient/mapstruct/AvatarMapper.java @@ -0,0 +1,16 @@ +package com.faforever.moderatorclient.mapstruct; + +import com.faforever.commons.api.dto.Avatar; +import com.faforever.moderatorclient.ui.domain.AvatarFX; +import org.mapstruct.Mapper; + +import java.util.List; + +@Mapper(uses = {JavaFXMapper.class, AvatarAssignmentMapper.class, CycleAvoidingMappingContext.class}) +public abstract class AvatarMapper { + public abstract AvatarFX map(Avatar dto); + + public abstract Avatar map(AvatarFX fxBean); + + public abstract List map(List dtoList); +} diff --git a/src/main/java/com/faforever/moderatorclient/mapstruct/BanInfoMapper.java b/src/main/java/com/faforever/moderatorclient/mapstruct/BanInfoMapper.java new file mode 100644 index 0000000..c6a85ff --- /dev/null +++ b/src/main/java/com/faforever/moderatorclient/mapstruct/BanInfoMapper.java @@ -0,0 +1,23 @@ +package com.faforever.moderatorclient.mapstruct; + +import com.faforever.commons.api.dto.BanInfo; +import com.faforever.moderatorclient.ui.domain.BanInfoFX; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +import java.util.List; + +@Mapper(uses = {JavaFXMapper.class, BanRevokeDataMapper.class, PlayerMapper.class, CycleAvoidingMappingContext.class}) +public abstract class BanInfoMapper { + @Mapping(target = "duration", ignore = true) + @Mapping(target = "banStatus", ignore = true) + public abstract BanInfoFX map(BanInfo dto); + + @Mapping(target = "duration", ignore = true) + @Mapping(target = "banStatus", ignore = true) + public abstract BanInfo map(BanInfoFX fxBean); + + public abstract List mapToFX(List dtoList); + + public abstract List mapToDto(List fxBeanList); +} diff --git a/src/main/java/com/faforever/moderatorclient/mapstruct/BanRevokeDataMapper.java b/src/main/java/com/faforever/moderatorclient/mapstruct/BanRevokeDataMapper.java new file mode 100644 index 0000000..164648d --- /dev/null +++ b/src/main/java/com/faforever/moderatorclient/mapstruct/BanRevokeDataMapper.java @@ -0,0 +1,16 @@ +package com.faforever.moderatorclient.mapstruct; + +import com.faforever.commons.api.dto.BanRevokeData; +import com.faforever.moderatorclient.ui.domain.BanRevokeDataFX; +import org.mapstruct.Mapper; + +import java.util.List; + +@Mapper(uses = {JavaFXMapper.class, BanInfoMapper.class, PlayerMapper.class}) +public interface BanRevokeDataMapper { + BanRevokeDataFX map(BanRevokeData dto); + + BanRevokeData map(BanRevokeDataFX fxBean); + + List map(List dtoList); +} diff --git a/src/main/java/com/faforever/moderatorclient/mapstruct/CycleAvoidingMappingContext.java b/src/main/java/com/faforever/moderatorclient/mapstruct/CycleAvoidingMappingContext.java index 687fedb..8f85f6a 100644 --- a/src/main/java/com/faforever/moderatorclient/mapstruct/CycleAvoidingMappingContext.java +++ b/src/main/java/com/faforever/moderatorclient/mapstruct/CycleAvoidingMappingContext.java @@ -18,7 +18,10 @@ */ package com.faforever.moderatorclient.mapstruct; -import org.mapstruct.*; +import org.mapstruct.BeforeMapping; +import org.mapstruct.Context; +import org.mapstruct.MappingTarget; +import org.mapstruct.TargetType; import org.springframework.stereotype.Component; import java.util.IdentityHashMap; @@ -47,8 +50,7 @@ public void storeMappedInstance(Object source, @MappingTarget Object target) { knownInstances.put(source, target); } - @AfterMapping - public void cleanupKnownInstances() { -// knownInstances.clear(); + public void clearCache() { + knownInstances.clear(); } } diff --git a/src/main/java/com/faforever/moderatorclient/mapstruct/DomainBlacklistMapper.java b/src/main/java/com/faforever/moderatorclient/mapstruct/DomainBlacklistMapper.java index 2047aa4..d4c4267 100644 --- a/src/main/java/com/faforever/moderatorclient/mapstruct/DomainBlacklistMapper.java +++ b/src/main/java/com/faforever/moderatorclient/mapstruct/DomainBlacklistMapper.java @@ -1,6 +1,6 @@ package com.faforever.moderatorclient.mapstruct; -import com.faforever.moderatorclient.api.dto.DomainBlacklist; +import com.faforever.commons.api.dto.DomainBlacklist; import com.faforever.moderatorclient.ui.domain.DomainBlacklistFX; import org.mapstruct.Mapper; @@ -8,9 +8,9 @@ @Mapper(uses = JavaFXMapper.class) public interface DomainBlacklistMapper { - DomainBlacklistFX map(DomainBlacklist domainBlacklist); + DomainBlacklistFX map(DomainBlacklist dto); - DomainBlacklist map(DomainBlacklistFX domainBlacklistFX); + DomainBlacklist map(DomainBlacklistFX fxBean); - List map(List domainBlacklistList); + List map(List dtoList); } diff --git a/src/main/java/com/faforever/moderatorclient/mapstruct/FeaturedModMapper.java b/src/main/java/com/faforever/moderatorclient/mapstruct/FeaturedModMapper.java index 9a04cd6..3007f9e 100644 --- a/src/main/java/com/faforever/moderatorclient/mapstruct/FeaturedModMapper.java +++ b/src/main/java/com/faforever/moderatorclient/mapstruct/FeaturedModMapper.java @@ -1,6 +1,6 @@ package com.faforever.moderatorclient.mapstruct; -import com.faforever.moderatorclient.api.dto.FeaturedMod; +import com.faforever.commons.api.dto.FeaturedMod; import com.faforever.moderatorclient.ui.domain.FeaturedModFX; import org.mapstruct.Mapper; @@ -8,9 +8,9 @@ @Mapper(uses = JavaFXMapper.class) public interface FeaturedModMapper { - FeaturedModFX map(FeaturedMod featuredMod); + FeaturedModFX map(FeaturedMod dto); - FeaturedMod map(FeaturedModFX featuredModFX); + FeaturedMod map(FeaturedModFX fxBean); - List map(List featuredMods); + List map(List dtoList); } \ No newline at end of file diff --git a/src/main/java/com/faforever/moderatorclient/mapstruct/GameMapper.java b/src/main/java/com/faforever/moderatorclient/mapstruct/GameMapper.java index 2a280dd..ac37c37 100644 --- a/src/main/java/com/faforever/moderatorclient/mapstruct/GameMapper.java +++ b/src/main/java/com/faforever/moderatorclient/mapstruct/GameMapper.java @@ -1,6 +1,6 @@ package com.faforever.moderatorclient.mapstruct; -import com.faforever.moderatorclient.api.dto.Game; +import com.faforever.commons.api.dto.Game; import com.faforever.moderatorclient.ui.domain.GameFX; import org.mapstruct.Mapper; import org.mapstruct.Mapping; @@ -10,9 +10,9 @@ @Mapper(uses = {JavaFXMapper.class, GamePlayerStatsMapper.class, PlayerMapper.class, FeaturedModMapper.class, MapVersionMapper.class}) public abstract class GameMapper { @Mapping(target = "reviews", ignore = true) - public abstract GameFX map(Game game); + public abstract GameFX map(Game dto); - public abstract Game map(GameFX gameFX); + public abstract Game map(GameFX fxBean); - public abstract List map(List games); + public abstract List map(List dtoList); } diff --git a/src/main/java/com/faforever/moderatorclient/mapstruct/GamePlayerStatsMapper.java b/src/main/java/com/faforever/moderatorclient/mapstruct/GamePlayerStatsMapper.java index 4f14201..f44c47b 100644 --- a/src/main/java/com/faforever/moderatorclient/mapstruct/GamePlayerStatsMapper.java +++ b/src/main/java/com/faforever/moderatorclient/mapstruct/GamePlayerStatsMapper.java @@ -1,6 +1,6 @@ package com.faforever.moderatorclient.mapstruct; -import com.faforever.moderatorclient.api.dto.GamePlayerStats; +import com.faforever.commons.api.dto.GamePlayerStats; import com.faforever.moderatorclient.ui.domain.GamePlayerStatsFX; import org.mapstruct.Mapper; import org.mapstruct.Mapping; @@ -13,9 +13,9 @@ public abstract class GamePlayerStatsMapper { @Mapping(target = "beforeRating", ignore = true) @Mapping(target = "afterRating", ignore = true) @Mapping(target = "ratingChange", ignore = true) - public abstract GamePlayerStatsFX map(GamePlayerStats gamePlayerStats); + public abstract GamePlayerStatsFX map(GamePlayerStats dto); - public abstract GamePlayerStats map(GamePlayerStatsFX gamePlayerStatsFX); + public abstract GamePlayerStats map(GamePlayerStatsFX fxBean); - public abstract List map(List gamePlayerStats); + public abstract List map(List dtoList); } \ No newline at end of file diff --git a/src/main/java/com/faforever/moderatorclient/mapstruct/JavaFXMapper.java b/src/main/java/com/faforever/moderatorclient/mapstruct/JavaFXMapper.java index 15968a7..9fa5f41 100644 --- a/src/main/java/com/faforever/moderatorclient/mapstruct/JavaFXMapper.java +++ b/src/main/java/com/faforever/moderatorclient/mapstruct/JavaFXMapper.java @@ -42,7 +42,11 @@ public T map(ObjectProperty value) { } public ObservableList map(List value) { - return FXCollections.observableList(value); + if (value == null) { + return null; + } else { + return FXCollections.observableList(value); + } } // public ListProperty mapListToListProperty (List value) { diff --git a/src/main/java/com/faforever/moderatorclient/mapstruct/MapMapper.java b/src/main/java/com/faforever/moderatorclient/mapstruct/MapMapper.java index c6f7965..57883e1 100644 --- a/src/main/java/com/faforever/moderatorclient/mapstruct/MapMapper.java +++ b/src/main/java/com/faforever/moderatorclient/mapstruct/MapMapper.java @@ -1,6 +1,6 @@ package com.faforever.moderatorclient.mapstruct; -import com.faforever.moderatorclient.api.dto.Map; +import com.faforever.commons.api.dto.Map; import com.faforever.moderatorclient.ui.domain.MapFX; import org.mapstruct.Mapper; @@ -8,9 +8,9 @@ @Mapper(uses = {JavaFXMapper.class, MapVersionMapper.class, PlayerMapper.class, CycleAvoidingMappingContext.class}) public abstract class MapMapper { - public abstract MapFX map(Map map); + public abstract MapFX map(Map dto); - public abstract Map map(MapFX mapFX); + public abstract Map map(MapFX fxBean); - public abstract List map(List mapList); + public abstract List map(List dtoList); } diff --git a/src/main/java/com/faforever/moderatorclient/mapstruct/MapVersionMapper.java b/src/main/java/com/faforever/moderatorclient/mapstruct/MapVersionMapper.java index 81937e9..b6f62ef 100644 --- a/src/main/java/com/faforever/moderatorclient/mapstruct/MapVersionMapper.java +++ b/src/main/java/com/faforever/moderatorclient/mapstruct/MapVersionMapper.java @@ -1,6 +1,6 @@ package com.faforever.moderatorclient.mapstruct; -import com.faforever.moderatorclient.api.dto.MapVersion; +import com.faforever.commons.api.dto.MapVersion; import com.faforever.moderatorclient.ui.domain.MapVersionFX; import org.mapstruct.Mapper; @@ -8,11 +8,11 @@ @Mapper(uses = {JavaFXMapper.class, MapMapper.class, CycleAvoidingMappingContext.class}) public abstract class MapVersionMapper { - public abstract MapVersionFX map(MapVersion mapVersion); + public abstract MapVersionFX map(MapVersion dto); - public abstract MapVersion map(MapVersionFX mapVersionFX); + public abstract MapVersion map(MapVersionFX fxBean); - public abstract List mapToFX(List mapVersionList); + public abstract List mapToFX(List dtoList); - public abstract List mapToDTO(List mapVersionFXList); + public abstract List mapToDTO(List fxBeanList); } diff --git a/src/main/java/com/faforever/moderatorclient/mapstruct/NameRecordMapper.java b/src/main/java/com/faforever/moderatorclient/mapstruct/NameRecordMapper.java new file mode 100644 index 0000000..1ba84e3 --- /dev/null +++ b/src/main/java/com/faforever/moderatorclient/mapstruct/NameRecordMapper.java @@ -0,0 +1,18 @@ +package com.faforever.moderatorclient.mapstruct; + +import com.faforever.commons.api.dto.NameRecord; +import com.faforever.moderatorclient.ui.domain.NameRecordFX; +import org.mapstruct.Mapper; + +import java.util.List; + +@Mapper(uses = {JavaFXMapper.class, PlayerMapper.class}) +public abstract class NameRecordMapper { + public abstract NameRecordFX map(NameRecord dto); + + public abstract NameRecord map(NameRecordFX fxBean); + + public abstract List mapToFX(List dtoList); + + public abstract List mapToDto(List fxBeanList); +} diff --git a/src/main/java/com/faforever/moderatorclient/mapstruct/PlayerMapper.java b/src/main/java/com/faforever/moderatorclient/mapstruct/PlayerMapper.java index 90939cf..1d9ca88 100644 --- a/src/main/java/com/faforever/moderatorclient/mapstruct/PlayerMapper.java +++ b/src/main/java/com/faforever/moderatorclient/mapstruct/PlayerMapper.java @@ -1,16 +1,18 @@ package com.faforever.moderatorclient.mapstruct; -import com.faforever.moderatorclient.api.dto.Player; +import com.faforever.commons.api.dto.Player; import com.faforever.moderatorclient.ui.domain.PlayerFX; import org.mapstruct.Mapper; import java.util.List; -@Mapper(uses = {JavaFXMapper.class, CycleAvoidingMappingContext.class}) +@Mapper(uses = {JavaFXMapper.class, NameRecordMapper.class, BanInfoMapper.class, AvatarAssignmentMapper.class, CycleAvoidingMappingContext.class}) public abstract class PlayerMapper { - public abstract PlayerFX map(Player player); + public abstract PlayerFX map(Player dto); - public abstract Player map(PlayerFX playerFX); + public abstract Player map(PlayerFX fxBean); - public abstract List map(List playerList); + public abstract List mapToFx(List dtoList); + + public abstract List mapToDto(List fxBeanList); } diff --git a/src/main/java/com/faforever/moderatorclient/mapstruct/TeamkillMapper.java b/src/main/java/com/faforever/moderatorclient/mapstruct/TeamkillMapper.java new file mode 100644 index 0000000..266b972 --- /dev/null +++ b/src/main/java/com/faforever/moderatorclient/mapstruct/TeamkillMapper.java @@ -0,0 +1,16 @@ +package com.faforever.moderatorclient.mapstruct; + +import com.faforever.commons.api.dto.Teamkill; +import com.faforever.moderatorclient.ui.domain.TeamkillFX; +import org.mapstruct.Mapper; + +import java.util.List; + +@Mapper(uses = {JavaFXMapper.class, PlayerMapper.class, GameMapper.class}) +public abstract class TeamkillMapper { + public abstract TeamkillFX map(Teamkill dto); + + public abstract Teamkill map(TeamkillFX fxBean); + + public abstract List map(List dtoList); +} diff --git a/src/main/java/com/faforever/moderatorclient/mapstruct/UserNoteMapper.java b/src/main/java/com/faforever/moderatorclient/mapstruct/UserNoteMapper.java index 934b5cb..80ec1a5 100644 --- a/src/main/java/com/faforever/moderatorclient/mapstruct/UserNoteMapper.java +++ b/src/main/java/com/faforever/moderatorclient/mapstruct/UserNoteMapper.java @@ -1,6 +1,6 @@ package com.faforever.moderatorclient.mapstruct; -import com.faforever.moderatorclient.api.dto.UserNote; +import com.faforever.commons.api.dto.UserNote; import com.faforever.moderatorclient.ui.domain.UserNoteFX; import org.mapstruct.Mapper; @@ -8,9 +8,9 @@ @Mapper(uses = {JavaFXMapper.class, PlayerMapper.class}) public interface UserNoteMapper { - UserNoteFX map(UserNote userNote); + UserNoteFX map(UserNote dto); - UserNote map(UserNoteFX userNoteFX); + UserNote map(UserNoteFX fxBean); - List map(List userNoteList); + List map(List dtoList); } diff --git a/src/main/java/com/faforever/moderatorclient/ui/BanInfoController.java b/src/main/java/com/faforever/moderatorclient/ui/BanInfoController.java index d647d6a..76c4f32 100644 --- a/src/main/java/com/faforever/moderatorclient/ui/BanInfoController.java +++ b/src/main/java/com/faforever/moderatorclient/ui/BanInfoController.java @@ -1,11 +1,12 @@ package com.faforever.moderatorclient.ui; -import com.faforever.moderatorclient.api.dto.BanDurationType; -import com.faforever.moderatorclient.api.dto.BanInfo; -import com.faforever.moderatorclient.api.dto.BanLevel; -import com.faforever.moderatorclient.api.dto.BanRevokeData; -import com.faforever.moderatorclient.api.rest.FafApiCommunicationService; -import com.faforever.moderatorclient.api.rest.domain.UserService; +import com.faforever.commons.api.dto.BanDurationType; +import com.faforever.commons.api.dto.BanLevel; +import com.faforever.moderatorclient.api.FafApiCommunicationService; +import com.faforever.moderatorclient.api.domain.UserService; +import com.faforever.moderatorclient.mapstruct.PlayerMapper; +import com.faforever.moderatorclient.ui.domain.BanInfoFX; +import com.faforever.moderatorclient.ui.domain.BanRevokeDataFX; import javafx.fxml.FXML; import javafx.scene.control.*; import javafx.scene.layout.GridPane; @@ -27,6 +28,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; +import java.util.function.Consumer; import java.util.stream.Collectors; @@ -36,6 +38,7 @@ public class BanInfoController implements Controller { private final FafApiCommunicationService fafApi; private final UserService userService; + private final PlayerMapper playerMapper; public GridPane root; public TextField affectedUserTextField; public TextField banAuthorTextField; @@ -50,11 +53,17 @@ public class BanInfoController implements Controller { public RadioButton globalBanRadioButton; public Button revokeButton; @Getter - private BanInfo banInfo; + private BanInfoFX banInfo; + private Consumer postedListener; - public BanInfoController(FafApiCommunicationService fafApi, UserService userService) { + public BanInfoController(FafApiCommunicationService fafApi, UserService userService, PlayerMapper playerMapper) { this.fafApi = fafApi; this.userService = userService; + this.playerMapper = playerMapper; + } + + public void addPostedListener(Consumer listener) { + this.postedListener = listener; } @Override @@ -64,10 +73,9 @@ public Pane getRoot() { @FXML public void initialize() { - untilTextField.setPromptText(DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(LocalDateTime.now())); } - public void setBanInfo(BanInfo banInfo) { + public void setBanInfo(BanInfoFX banInfo) { this.banInfo = banInfo; if (banInfo.getId() != null) { @@ -108,7 +116,11 @@ public void onSave() { if (banInfo.getId() == null) { log.debug("Creating ban for player '{}' with reason: {}", banInfo.getPlayer().toString(), banReasonTextField.getText()); - userService.createBan(banInfo); + String newBanId = userService.createBan(banInfo); + BanInfoFX loadedBanInfo = userService.getBanInfoById(newBanId); + if (postedListener != null) { + postedListener.accept(loadedBanInfo); + } } else { log.debug("Updating ban id '{}'", banInfo.getId()); userService.patchBanInfo(banInfo); @@ -167,10 +179,9 @@ public void onRevoke() { log.debug("Revoking ban id '{}' with reason: {}", banInfo.getId(), revocationReason); - BanRevokeData banRevokeData = new BanRevokeData() - + BanRevokeDataFX banRevokeData = new BanRevokeDataFX() .setBan(banInfo) - .setAuthor(fafApi.getSelfPlayer()) + .setAuthor(playerMapper.map(fafApi.getSelfPlayer())) .setReason(revocationReason); userService.revokeBan(banRevokeData); diff --git a/src/main/java/com/faforever/moderatorclient/ui/LoginController.java b/src/main/java/com/faforever/moderatorclient/ui/LoginController.java index 088b50b..5ac3ce1 100644 --- a/src/main/java/com/faforever/moderatorclient/ui/LoginController.java +++ b/src/main/java/com/faforever/moderatorclient/ui/LoginController.java @@ -1,7 +1,7 @@ package com.faforever.moderatorclient.ui; -import com.faforever.moderatorclient.api.dto.LegacyAccessLevel; -import com.faforever.moderatorclient.api.rest.FafApiCommunicationService; +import com.faforever.commons.api.dto.LegacyAccessLevel; +import com.faforever.moderatorclient.api.FafApiCommunicationService; import javafx.fxml.FXML; import javafx.scene.control.DialogPane; import javafx.scene.control.Label; diff --git a/src/main/java/com/faforever/moderatorclient/ui/MapTableItemAdapter.java b/src/main/java/com/faforever/moderatorclient/ui/MapTableItemAdapter.java index 8f39832..7ea62e4 100644 --- a/src/main/java/com/faforever/moderatorclient/ui/MapTableItemAdapter.java +++ b/src/main/java/com/faforever/moderatorclient/ui/MapTableItemAdapter.java @@ -1,7 +1,7 @@ package com.faforever.moderatorclient.ui; -import com.faforever.moderatorclient.api.dto.Map; -import com.faforever.moderatorclient.api.dto.MapVersion; +import com.faforever.commons.api.dto.Map; +import com.faforever.commons.api.dto.MapVersion; import lombok.Getter; import org.apache.maven.artifact.versioning.ComparableVersion; diff --git a/src/main/java/com/faforever/moderatorclient/ui/UserNoteController.java b/src/main/java/com/faforever/moderatorclient/ui/UserNoteController.java index 7ece64e..0458d9d 100644 --- a/src/main/java/com/faforever/moderatorclient/ui/UserNoteController.java +++ b/src/main/java/com/faforever/moderatorclient/ui/UserNoteController.java @@ -1,6 +1,6 @@ package com.faforever.moderatorclient.ui; -import com.faforever.moderatorclient.api.rest.domain.UserService; +import com.faforever.moderatorclient.api.domain.UserService; import com.faforever.moderatorclient.mapstruct.UserNoteMapper; import com.faforever.moderatorclient.ui.domain.UserNoteFX; import javafx.fxml.FXML; @@ -84,7 +84,10 @@ public void onSave() { log.debug("Creating userNote for player '{}'", userNoteFX.getPlayer().representationProperty().get()); String newNoteId = userService.createUserNote(userNoteMapper.map(userNoteFX)); UserNoteFX loadedUserNote = userService.getUserNoteById(newNoteId); - postedListener.accept(loadedUserNote); + + if (postedListener != null) { + postedListener.accept(loadedUserNote); + } } else { log.debug("Updating userNote id '{}'", userNoteFX.getId()); userService.patchUserNote(userNoteMapper.map(userNoteFX)); diff --git a/src/main/java/com/faforever/moderatorclient/ui/ViewHelper.java b/src/main/java/com/faforever/moderatorclient/ui/ViewHelper.java index 6ea06d2..8790868 100644 --- a/src/main/java/com/faforever/moderatorclient/ui/ViewHelper.java +++ b/src/main/java/com/faforever/moderatorclient/ui/ViewHelper.java @@ -1,8 +1,12 @@ package com.faforever.moderatorclient.ui; -import com.faforever.moderatorclient.api.dto.*; +import com.faforever.commons.api.dto.BanDurationType; +import com.faforever.commons.api.dto.BanLevel; +import com.faforever.commons.api.dto.BanStatus; +import com.faforever.commons.api.dto.Map; import com.faforever.moderatorclient.ui.domain.*; import javafx.beans.binding.Bindings; +import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleStringProperty; import javafx.collections.ObservableList; @@ -48,44 +52,50 @@ public static void bindMapTreeViewToImageView(TreeTableView }); } - public static void buildAvatarTableView(TableView tableView) { - TableColumn idColumn = new TableColumn<>("ID"); - idColumn.setCellValueFactory(new PropertyValueFactory<>("id")); + public static void buildAvatarTableView(TableView tableView, ObservableList data) { + tableView.setItems(data); + + TableColumn idColumn = new TableColumn<>("ID"); + idColumn.setCellValueFactory(o -> o.getValue().idProperty()); idColumn.setComparator(Comparator.comparingInt(Integer::parseInt)); idColumn.setMinWidth(50); tableView.getColumns().add(idColumn); - TableColumn previewColumn = new TableColumn<>("Preview"); - previewColumn.setCellValueFactory(new PropertyValueFactory<>("url")); + TableColumn previewColumn = new TableColumn<>("Preview"); + previewColumn.setCellValueFactory(o -> o.getValue().urlProperty()); previewColumn.setCellFactory(param -> new UrlImageViewTableCell<>()); previewColumn.setMinWidth(50); tableView.getColumns().add(previewColumn); - TableColumn tooltipColumn = new TableColumn<>("Tooltip"); - tooltipColumn.setCellValueFactory(new PropertyValueFactory<>("tooltip")); + TableColumn tooltipColumn = new TableColumn<>("Tooltip"); + tooltipColumn.setCellValueFactory(o -> o.getValue().tooltipProperty()); tooltipColumn.setMinWidth(50); tableView.getColumns().add(tooltipColumn); - TableColumn changeTimeColumn = new TableColumn<>("Created"); - changeTimeColumn.setCellValueFactory(new PropertyValueFactory<>("createTime")); + TableColumn changeTimeColumn = new TableColumn<>("Created"); + changeTimeColumn.setCellValueFactory(o -> o.getValue().createTimeProperty()); changeTimeColumn.setMinWidth(180); tableView.getColumns().add(changeTimeColumn); - TableColumn urlColumn = new TableColumn<>("URL"); - urlColumn.setCellValueFactory(new PropertyValueFactory<>("url")); + TableColumn urlColumn = new TableColumn<>("URL"); + urlColumn.setCellValueFactory(o -> o.getValue().urlProperty()); urlColumn.setMinWidth(50); tableView.getColumns().add(urlColumn); } - public static void buildAvatarAssignmentTableView(TableView tableView) { - TableColumn idColumn = new TableColumn<>("ID"); - idColumn.setCellValueFactory(new PropertyValueFactory<>("id")); + public static void buildAvatarAssignmentTableView(TableView tableView, ObservableList data) { + tableView.setItems(data); + + TableColumn idColumn = new TableColumn<>("ID"); + idColumn.setCellValueFactory(o -> o.getValue().idProperty()); idColumn.setComparator(Comparator.comparingInt(Integer::parseInt)); idColumn.setMinWidth(50); tableView.getColumns().add(idColumn); - TableColumn userIdColumn = new TableColumn<>("User ID"); + TableColumn userIdColumn = new TableColumn<>("User ID"); + + userIdColumn.setCellValueFactory(param -> new SimpleObjectProperty<>( Optional.ofNullable(param.getValue()) .map(avatarAssignment -> avatarAssignment.getPlayer().getId()) @@ -95,156 +105,171 @@ public static void buildAvatarAssignmentTableView(TableView ta userIdColumn.setMinWidth(50); tableView.getColumns().add(userIdColumn); - TableColumn userNameColumn = new TableColumn<>("User name"); - userNameColumn.setCellValueFactory(param -> new SimpleObjectProperty<>( - Optional.ofNullable(param.getValue()) - .map(avatarAssignment -> avatarAssignment.getPlayer().getLogin()) - .orElse("")) - ); + TableColumn userNameColumn = new TableColumn<>("User name"); + userNameColumn.setCellValueFactory(o -> o.getValue().playerProperty().get().representationProperty()); userNameColumn.setMinWidth(150); tableView.getColumns().add(userNameColumn); - TableColumn selectedColumn = new TableColumn<>("Selected"); - selectedColumn.setCellValueFactory(new PropertyValueFactory<>("selected")); + TableColumn selectedColumn = new TableColumn<>("Selected"); + selectedColumn.setCellValueFactory(o -> o.getValue().selectedProperty()); selectedColumn.setMinWidth(50); tableView.getColumns().add(selectedColumn); - TableColumn expiresAtColumn = new TableColumn<>("Expires at"); - expiresAtColumn.setCellValueFactory(new PropertyValueFactory<>("expiresAt")); + TableColumn expiresAtColumn = new TableColumn<>("Expires at"); + expiresAtColumn.setCellValueFactory(o -> o.getValue().expiresAtProperty()); expiresAtColumn.setMinWidth(180); tableView.getColumns().add(expiresAtColumn); - TableColumn assignedAtColumn = new TableColumn<>("Assigned at"); - assignedAtColumn.setCellValueFactory(new PropertyValueFactory<>("createTime")); + TableColumn assignedAtColumn = new TableColumn<>("Assigned at"); + assignedAtColumn.setCellValueFactory(o -> o.getValue().createTimeProperty()); assignedAtColumn.setMinWidth(180); tableView.getColumns().add(assignedAtColumn); + } - public static void buildBanTableView(TableView tableView) { - TableColumn idColumn = new TableColumn<>("ID"); - idColumn.setCellValueFactory(new PropertyValueFactory<>("id")); + public static void buildBanTableView(TableView tableView, ObservableList data) { + tableView.setItems(data); + + TableColumn idColumn = new TableColumn<>("ID"); + idColumn.setCellValueFactory(o -> o.getValue().idProperty()); idColumn.setComparator(Comparator.comparingInt(Integer::parseInt)); idColumn.setMinWidth(50); tableView.getColumns().add(idColumn); - TableColumn banLevelColumn = new TableColumn<>("Level"); - banLevelColumn.setCellValueFactory(new PropertyValueFactory<>("level")); + TableColumn banLevelColumn = new TableColumn<>("Level"); + banLevelColumn.setCellValueFactory(o -> o.getValue().levelProperty()); banLevelColumn.setMinWidth(80); tableView.getColumns().add(banLevelColumn); - TableColumn banStatusColumn = new TableColumn<>("Status"); - banStatusColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getBanStatus())); + TableColumn banStatusColumn = new TableColumn<>("Status"); + banStatusColumn.setCellValueFactory(o -> o.getValue().banStatusProperty()); banStatusColumn.setMinWidth(100); tableView.getColumns().add(banStatusColumn); - TableColumn banDurationColumn = new TableColumn<>("Duration"); - banDurationColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getDuration())); + TableColumn banDurationColumn = new TableColumn<>("Duration"); + banDurationColumn.setCellValueFactory(o -> o.getValue().durationProperty()); banDurationColumn.setMinWidth(100); tableView.getColumns().add(banDurationColumn); - TableColumn expiresAtColumn = new TableColumn<>("Expires at"); - expiresAtColumn.setCellValueFactory(new PropertyValueFactory<>("expiresAt")); + TableColumn expiresAtColumn = new TableColumn<>("Expires at"); + expiresAtColumn.setCellValueFactory(o -> o.getValue().expiresAtProperty()); expiresAtColumn.setMinWidth(180); tableView.getColumns().add(expiresAtColumn); - TableColumn reasonColumn = new TableColumn<>("Reason"); - reasonColumn.setCellValueFactory(new PropertyValueFactory<>("reason")); + TableColumn reasonColumn = new TableColumn<>("Reason"); + reasonColumn.setCellValueFactory(o -> o.getValue().reasonProperty()); reasonColumn.setMinWidth(250); tableView.getColumns().add(reasonColumn); - TableColumn authorColumn = new TableColumn<>("Author"); - authorColumn.setCellValueFactory(new PropertyValueFactory<>("author")); + TableColumn authorColumn = new TableColumn<>("Author"); + authorColumn.setCellValueFactory(o -> o.getValue().authorProperty().get().representationProperty()); authorColumn.setMinWidth(150); tableView.getColumns().add(authorColumn); - TableColumn revokeReasonColumn = new TableColumn<>("Revocation Reason"); - revokeReasonColumn.setCellValueFactory(param -> new SimpleObjectProperty<>( - Optional.ofNullable(param.getValue().getBanRevokeData()) - .map(BanRevokeData::getReason) - .orElse("")) - ); + TableColumn revokeReasonColumn = new TableColumn<>("Revocation Reason"); + revokeReasonColumn.setCellValueFactory(o -> { + ObjectProperty banRevokeProperty = o.getValue().banRevokeDataProperty(); + return Bindings.createStringBinding(() -> { + if (banRevokeProperty.get() != null) { + return banRevokeProperty.get().reasonProperty().get(); + } else { + return ""; + } + }, + banRevokeProperty); + }); revokeReasonColumn.setMinWidth(250); tableView.getColumns().add(revokeReasonColumn); - TableColumn revokeAuthorColumn = new TableColumn<>("Revocation Author"); - revokeAuthorColumn.setCellValueFactory(param -> new SimpleObjectProperty<>( - Optional.ofNullable(param.getValue().getBanRevokeData()) - .map(BanRevokeData::getAuthor) - .orElse(null)) + TableColumn revokeAuthorColumn = new TableColumn<>("Revocation Author"); + revokeAuthorColumn.setCellValueFactory(o -> { + BanRevokeDataFX banRevokeData = o.getValue().getBanRevokeData(); + if (banRevokeData != null) { + return banRevokeData.getAuthor().representationProperty(); + } else { + return null; + } + } ); revokeAuthorColumn.setMinWidth(150); tableView.getColumns().add(revokeAuthorColumn); - TableColumn changeTimeColumn = new TableColumn<>("Created Time"); + TableColumn changeTimeColumn = new TableColumn<>("Created Time"); changeTimeColumn.setCellValueFactory(new PropertyValueFactory<>("createTime")); changeTimeColumn.setMinWidth(180); tableView.getColumns().add(changeTimeColumn); - TableColumn updateTimeColumn = new TableColumn<>("Update (Revoke) Time"); + TableColumn updateTimeColumn = new TableColumn<>("Update (Revoke) Time"); updateTimeColumn.setCellValueFactory(new PropertyValueFactory<>("updateTime")); updateTimeColumn.setMinWidth(180); tableView.getColumns().add(updateTimeColumn); } - public static void buildNameHistoryTableView(TableView tableView) { - TableColumn idColumn = new TableColumn<>("ID"); - idColumn.setCellValueFactory(new PropertyValueFactory<>("id")); + public static void buildNameHistoryTableView(TableView tableView, ObservableList data) { + tableView.setItems(data); + + TableColumn idColumn = new TableColumn<>("ID"); + idColumn.setCellValueFactory(o -> o.getValue().idProperty()); idColumn.setComparator(Comparator.comparingInt(Integer::parseInt)); idColumn.setMinWidth(50); tableView.getColumns().add(idColumn); - TableColumn changeTimeColumn = new TableColumn<>("Change Time"); - changeTimeColumn.setCellValueFactory(new PropertyValueFactory<>("changeTime")); + TableColumn changeTimeColumn = new TableColumn<>("Change Time"); + changeTimeColumn.setCellValueFactory(o -> o.getValue().changeTimeProperty()); changeTimeColumn.setMinWidth(180); tableView.getColumns().add(changeTimeColumn); - TableColumn nameColumn = new TableColumn<>("Previous Name"); - nameColumn.setCellValueFactory(new PropertyValueFactory<>("name")); + TableColumn nameColumn = new TableColumn<>("Previous Name"); + nameColumn.setCellValueFactory(o -> o.getValue().nameProperty()); nameColumn.setMinWidth(200); tableView.getColumns().add(nameColumn); } - public static void buildTeamkillTableView(javafx.scene.control.TableView tableView, boolean showKiller) { - TableColumn idColumn = new TableColumn<>("ID"); - idColumn.setCellValueFactory(new PropertyValueFactory<>("id")); + public static void buildTeamkillTableView(TableView tableView, ObservableList data, boolean showKiller) { + tableView.setItems(data); + + TableColumn idColumn = new TableColumn<>("ID"); + idColumn.setCellValueFactory(o -> o.getValue().idProperty()); idColumn.setComparator(Comparator.comparingInt(Integer::parseInt)); idColumn.setMinWidth(50); tableView.getColumns().add(idColumn); if (showKiller) { - TableColumn killerColumn = new TableColumn<>("Killer"); - killerColumn.setCellValueFactory(new PropertyValueFactory<>("teamkiller")); + TableColumn killerColumn = new TableColumn<>("Killer"); + killerColumn.setCellValueFactory(o -> o.getValue().teamkillerProperty().get().representationProperty()); killerColumn.setMinWidth(180); tableView.getColumns().add(killerColumn); } - TableColumn victimColumn = new TableColumn<>("Victim"); - victimColumn.setCellValueFactory(new PropertyValueFactory<>("victim")); + TableColumn victimColumn = new TableColumn<>("Victim"); + victimColumn.setCellValueFactory(o -> o.getValue().victimProperty().get().representationProperty()); victimColumn.setMinWidth(180); tableView.getColumns().add(victimColumn); - TableColumn gameIdColumn = new TableColumn<>("Game ID"); - gameIdColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getGame().getId())); + TableColumn gameIdColumn = new TableColumn<>("Game ID"); + gameIdColumn.setCellValueFactory(o -> o.getValue().gameProperty().get().idProperty()); gameIdColumn.setComparator(Comparator.comparingInt(Integer::parseInt)); gameIdColumn.setMinWidth(100); tableView.getColumns().add(gameIdColumn); - TableColumn gameTimeColumn = new TableColumn<>("Game Time"); - gameTimeColumn.setCellValueFactory(new PropertyValueFactory<>("gameTime")); + TableColumn gameTimeColumn = new TableColumn<>("Game Time"); + gameTimeColumn.setCellValueFactory(o -> o.getValue().gameTimeProperty()); gameTimeColumn.setMinWidth(100); tableView.getColumns().add(gameTimeColumn); - TableColumn reportedAtColumn = new TableColumn<>("Reported At"); - reportedAtColumn.setCellValueFactory(new PropertyValueFactory<>("reportedAt")); + TableColumn reportedAtColumn = new TableColumn<>("Reported At"); + reportedAtColumn.setCellValueFactory(o -> o.getValue().reportedAtProperty()); reportedAtColumn.setMinWidth(180); tableView.getColumns().add(reportedAtColumn); } - public static void buildUserTableView(TableView tableView) { - TableColumn idColumn = new TableColumn<>("ID"); + public static void buildUserTableView(TableView tableView, ObservableList data) { + tableView.setItems(data); + + TableColumn idColumn = new TableColumn<>("ID"); idColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue())); - idColumn.setCellFactory(param -> new TableCell() { + idColumn.setCellFactory(param -> new TableCell() { Tooltip tooltip = new Tooltip(); { @@ -253,7 +278,7 @@ public static void buildUserTableView(TableView tableView) { } @Override - protected void updateItem(Player item, boolean empty) { + protected void updateItem(PlayerFX item, boolean empty) { super.updateItem(item, empty); setTextFill(Color.BLACK); @@ -290,81 +315,76 @@ protected void updateItem(Player item, boolean empty) { idColumn.setMinWidth(70); tableView.getColumns().add(idColumn); - TableColumn nameColumn = new TableColumn<>("Name"); - nameColumn.setCellValueFactory(new PropertyValueFactory<>("login")); + TableColumn nameColumn = new TableColumn<>("Name"); + nameColumn.setCellValueFactory(o -> o.getValue().loginProperty()); nameColumn.setMinWidth(150); tableView.getColumns().add(nameColumn); - TableColumn emailColumn = new TableColumn<>("Email"); - emailColumn.setCellValueFactory(new PropertyValueFactory<>("email")); + TableColumn emailColumn = new TableColumn<>("Email"); + emailColumn.setCellValueFactory(o -> o.getValue().emailProperty()); emailColumn.setMinWidth(250); tableView.getColumns().add(emailColumn); - TableColumn steamIdColumn = new TableColumn<>("Steam ID"); - steamIdColumn.setCellValueFactory(new PropertyValueFactory<>("steamId")); + TableColumn steamIdColumn = new TableColumn<>("Steam ID"); + steamIdColumn.setCellValueFactory(o -> o.getValue().steamIdProperty()); steamIdColumn.setMinWidth(150); tableView.getColumns().add(steamIdColumn); - TableColumn ipColumn = new TableColumn<>("Recent IP Address"); - ipColumn.setCellValueFactory(new PropertyValueFactory<>("recentIpAddress")); + TableColumn ipColumn = new TableColumn<>("Recent IP Address"); + ipColumn.setCellValueFactory(o -> o.getValue().recentIpAddressProperty()); ipColumn.setMinWidth(160); tableView.getColumns().add(ipColumn); - TableColumn createTimeColumn = new TableColumn<>("Registration Date"); - createTimeColumn.setCellValueFactory(new PropertyValueFactory<>("createTime")); + TableColumn createTimeColumn = new TableColumn<>("Registration Date"); + createTimeColumn.setCellValueFactory(o -> o.getValue().createTimeProperty()); createTimeColumn.setMinWidth(160); tableView.getColumns().add(createTimeColumn); - TableColumn updateTimeColumn = new TableColumn<>("Last lobby login"); - updateTimeColumn.setCellValueFactory(new PropertyValueFactory<>("updateTime")); + TableColumn updateTimeColumn = new TableColumn<>("Last lobby login"); + updateTimeColumn.setCellValueFactory(o -> o.getValue().updateTimeProperty()); updateTimeColumn.setMinWidth(160); tableView.getColumns().add(updateTimeColumn); - TableColumn userAgentColumn = new TableColumn<>("User Agent"); - userAgentColumn.setCellValueFactory(new PropertyValueFactory<>("userAgent")); + TableColumn userAgentColumn = new TableColumn<>("User Agent"); + userAgentColumn.setCellValueFactory(o -> o.getValue().userAgentProperty()); userAgentColumn.setMinWidth(200); tableView.getColumns().add(userAgentColumn); } - public static void buildUserAvatarsTableView(TableView tableView) { - TableColumn idColumn = new TableColumn<>("Assignment ID"); + public static void buildUserAvatarsTableView(TableView tableView, ObservableList data) { + tableView.setItems(data); + + TableColumn idColumn = new TableColumn<>("Assignment ID"); idColumn.setComparator(Comparator.comparingInt(Integer::parseInt)); - idColumn.setCellValueFactory(new PropertyValueFactory<>("id")); + idColumn.setCellValueFactory(o -> o.getValue().idProperty()); idColumn.setMinWidth(140); tableView.getColumns().add(idColumn); - TableColumn avatarIdColumn = new TableColumn<>("Avatar ID"); - avatarIdColumn.setCellValueFactory(param -> new SimpleObjectProperty<>( - param.getValue().getAvatar().getId() - )); + TableColumn avatarIdColumn = new TableColumn<>("Avatar ID"); + avatarIdColumn.setCellValueFactory(o -> o.getValue().avatarProperty().get().idProperty()); avatarIdColumn.setComparator(Comparator.comparingInt(Integer::parseInt)); avatarIdColumn.setMinWidth(50); tableView.getColumns().add(avatarIdColumn); - TableColumn previewColumn = new TableColumn<>("Preview"); - previewColumn.setCellValueFactory(param -> new SimpleObjectProperty<>( - param.getValue().getAvatar().getUrl() - )); - + TableColumn previewColumn = new TableColumn<>("Preview"); + previewColumn.setCellValueFactory(o -> o.getValue().avatarProperty().get().urlProperty()); previewColumn.setCellFactory(param -> new UrlImageViewTableCell<>()); previewColumn.setMinWidth(50); tableView.getColumns().add(previewColumn); - TableColumn tooltipColumn = new TableColumn<>("Tooltip"); - tooltipColumn.setCellValueFactory(param -> new SimpleObjectProperty<>( - param.getValue().getAvatar().getTooltip() - )); + TableColumn tooltipColumn = new TableColumn<>("Tooltip"); + tooltipColumn.setCellValueFactory(o -> o.getValue().avatarProperty().get().tooltipProperty()); tooltipColumn.setMinWidth(100); tableView.getColumns().add(tooltipColumn); - TableColumn selectedColumn = new TableColumn<>("Selected"); - selectedColumn.setCellValueFactory(new PropertyValueFactory<>("selected")); -// selectedColumn.setCellFactory(CheckBoxTableCell.forTableColumn(selectedColumn)); + TableColumn selectedColumn = new TableColumn<>("Selected"); + selectedColumn.setCellValueFactory(o -> o.getValue().selectedProperty()); + selectedColumn.setCellFactory(CheckBoxTableCell.forTableColumn(selectedColumn)); selectedColumn.setMinWidth(50); tableView.getColumns().add(selectedColumn); - TableColumn expiresAtColumn = new TableColumn<>("Expires At"); - expiresAtColumn.setCellValueFactory(new PropertyValueFactory<>("expiresAt")); + TableColumn expiresAtColumn = new TableColumn<>("Expires At"); + expiresAtColumn.setCellValueFactory(o -> o.getValue().expiresAtProperty()); expiresAtColumn.setMinWidth(180); tableView.getColumns().add(expiresAtColumn); } @@ -408,7 +428,9 @@ public static void buildMapTreeView(TreeTableView mapTreeVi mapTreeView.setShowRoot(false); } - public static void buildMapTableView(TableView tableView) { + public static void buildMapTableView(TableView tableView, ObservableList data) { + tableView.setItems(data); + TableColumn idColumn = new TableColumn<>("Map ID"); idColumn.setCellValueFactory(o -> o.getValue().idProperty()); idColumn.setComparator(Comparator.comparingInt(Integer::parseInt)); @@ -502,6 +524,7 @@ public static void buildPlayersGamesTable(TableView tableView label = new Label(); setGraphic(label); } + @Override protected void updateItem(OffsetDateTime item, boolean empty) { super.updateItem(item, empty); @@ -537,7 +560,9 @@ protected void updateItem(String item, boolean empty) { tableView.getColumns().add(replayUrlColumn); } - public static void buildMapVersionTableView(TableView tableView) { + public static void buildMapVersionTableView(TableView tableView, ObservableList data) { + tableView.setItems(data); + TableColumn idColumn = new TableColumn<>("Version ID"); idColumn.setCellValueFactory(o -> o.getValue().idProperty()); idColumn.setComparator(Comparator.comparingInt(Integer::parseInt)); diff --git a/src/main/java/com/faforever/moderatorclient/ui/domain/AbstractEntityFX.java b/src/main/java/com/faforever/moderatorclient/ui/domain/AbstractEntityFX.java index 8ae71d6..e93f961 100644 --- a/src/main/java/com/faforever/moderatorclient/ui/domain/AbstractEntityFX.java +++ b/src/main/java/com/faforever/moderatorclient/ui/domain/AbstractEntityFX.java @@ -4,11 +4,12 @@ import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; +import lombok.EqualsAndHashCode; import java.time.OffsetDateTime; +@EqualsAndHashCode(of = "id") public abstract class AbstractEntityFX { - private boolean dirty; private final StringProperty id; private final ObjectProperty createTime; private final ObjectProperty updateTime; @@ -24,7 +25,6 @@ public String getId() { } public void setId(String id) { - dirty = true; this.id.set(id); } @@ -37,7 +37,6 @@ public OffsetDateTime getCreateTime() { } public void setCreateTime(OffsetDateTime createTime) { - dirty = true; this.createTime.set(createTime); } @@ -50,11 +49,18 @@ public OffsetDateTime getUpdateTime() { } public void setUpdateTime(OffsetDateTime updateTime) { - dirty = true; this.updateTime.set(updateTime); } public ObjectProperty updateTimeProperty() { return updateTime; } + + /** + * Supplement method for @EqualsAndHashCode + * overriding the default lombok implementation + */ + protected boolean canEqual(Object other) { + return other instanceof AbstractEntityFX && this.getClass() == other.getClass(); + } } diff --git a/src/main/java/com/faforever/moderatorclient/ui/domain/AvatarAssignmentFX.java b/src/main/java/com/faforever/moderatorclient/ui/domain/AvatarAssignmentFX.java new file mode 100644 index 0000000..415332c --- /dev/null +++ b/src/main/java/com/faforever/moderatorclient/ui/domain/AvatarAssignmentFX.java @@ -0,0 +1,70 @@ +package com.faforever.moderatorclient.ui.domain; + +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleObjectProperty; + +import java.time.OffsetDateTime; + +public class AvatarAssignmentFX extends AbstractEntityFX { + private final BooleanProperty selected; + private final ObjectProperty expiresAt; + private final ObjectProperty player; + private final ObjectProperty avatar; + + public AvatarAssignmentFX() { + selected = new SimpleBooleanProperty(); + expiresAt = new SimpleObjectProperty<>(); + player = new SimpleObjectProperty<>(); + avatar = new SimpleObjectProperty<>(); + } + + public boolean isSelected() { + return selected.get(); + } + + public void setSelected(boolean selected) { + this.selected.set(selected); + } + + public BooleanProperty selectedProperty() { + return selected; + } + + public OffsetDateTime getExpiresAt() { + return expiresAt.get(); + } + + public void setExpiresAt(OffsetDateTime expiresAt) { + this.expiresAt.set(expiresAt); + } + + public ObjectProperty expiresAtProperty() { + return expiresAt; + } + + public PlayerFX getPlayer() { + return player.get(); + } + + public void setPlayer(PlayerFX player) { + this.player.set(player); + } + + public ObjectProperty playerProperty() { + return player; + } + + public AvatarFX getAvatar() { + return avatar.get(); + } + + public void setAvatar(AvatarFX avatar) { + this.avatar.set(avatar); + } + + public ObjectProperty avatarProperty() { + return avatar; + } +} diff --git a/src/main/java/com/faforever/moderatorclient/ui/domain/AvatarFX.java b/src/main/java/com/faforever/moderatorclient/ui/domain/AvatarFX.java new file mode 100644 index 0000000..7b3f86a --- /dev/null +++ b/src/main/java/com/faforever/moderatorclient/ui/domain/AvatarFX.java @@ -0,0 +1,56 @@ +package com.faforever.moderatorclient.ui.domain; + +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; + +import java.util.List; + +public class AvatarFX extends AbstractEntityFX { + private final StringProperty url; + private final StringProperty tooltip; + private final ObservableList assignments; + + public AvatarFX() { + url = new SimpleStringProperty(); + tooltip = new SimpleStringProperty(); + assignments = FXCollections.observableArrayList(); + } + + public String getUrl() { + return url.get(); + } + + public void setUrl(String url) { + this.url.set(url); + } + + public StringProperty urlProperty() { + return url; + } + + public String getTooltip() { + return tooltip.get(); + } + + public void setTooltip(String tooltip) { + this.tooltip.set(tooltip); + } + + public StringProperty tooltipProperty() { + return tooltip; + } + + public List getAssignments() { + return assignments; + } + + public void setAssignments(List assignmentFXList) { + assignments.clear(); + + if (assignmentFXList != null) { + assignments.addAll(assignmentFXList); + } + } +} diff --git a/src/main/java/com/faforever/moderatorclient/ui/domain/BanInfoFX.java b/src/main/java/com/faforever/moderatorclient/ui/domain/BanInfoFX.java new file mode 100644 index 0000000..611d9fb --- /dev/null +++ b/src/main/java/com/faforever/moderatorclient/ui/domain/BanInfoFX.java @@ -0,0 +1,143 @@ +package com.faforever.moderatorclient.ui.domain; + +import com.faforever.commons.api.dto.BanDurationType; +import com.faforever.commons.api.dto.BanLevel; +import com.faforever.commons.api.dto.BanStatus; +import javafx.beans.binding.Bindings; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; + +import java.time.OffsetDateTime; + +public class BanInfoFX extends AbstractEntityFX { + private final ObjectProperty player; + private final ObjectProperty author; + private final StringProperty reason; + private final ObjectProperty expiresAt; + private final ObjectProperty level; + private final ObjectProperty duration; + private final ObjectProperty banStatus; + private final ObjectProperty banRevokeData; + + public BanInfoFX() { + player = new SimpleObjectProperty<>(); + author = new SimpleObjectProperty<>(); + reason = new SimpleStringProperty(); + expiresAt = new SimpleObjectProperty<>(); + level = new SimpleObjectProperty<>(); + banRevokeData = new SimpleObjectProperty<>(); + + duration = new SimpleObjectProperty<>(); + duration.bind(Bindings.createObjectBinding(() -> expiresAt.get() == null ? BanDurationType.PERMANENT : BanDurationType.TEMPORARY, expiresAt)); + + banStatus = new SimpleObjectProperty<>(); + banStatus.bind( + Bindings.createObjectBinding(() -> { + if (banRevokeData.get() != null) { + return BanStatus.DISABLED; + } else if (duration.get() == BanDurationType.PERMANENT) { + return BanStatus.BANNED; + } else { + return expiresAt.get().isAfter(OffsetDateTime.now()) ? BanStatus.BANNED : BanStatus.EXPIRED; + } + }, + banRevokeData, duration, expiresAt) + ); + } + + public PlayerFX getPlayer() { + return player.get(); + } + + public BanInfoFX setPlayer(PlayerFX player) { + this.player.set(player); + return this; + } + + public ObjectProperty playerProperty() { + return player; + } + + public PlayerFX getAuthor() { + return author.get(); + } + + public BanInfoFX setAuthor(PlayerFX author) { + this.author.set(author); + return this; + } + + public ObjectProperty authorProperty() { + return author; + } + + public String getReason() { + return reason.get(); + } + + public BanInfoFX setReason(String reason) { + this.reason.set(reason); + return this; + } + + public StringProperty reasonProperty() { + return reason; + } + + public OffsetDateTime getExpiresAt() { + return expiresAt.get(); + } + + public BanInfoFX setExpiresAt(OffsetDateTime expiresAt) { + this.expiresAt.set(expiresAt); + return this; + } + + public ObjectProperty expiresAtProperty() { + return expiresAt; + } + + public BanLevel getLevel() { + return level.get(); + } + + public BanInfoFX setLevel(BanLevel level) { + this.level.set(level); + return this; + } + + public ObjectProperty levelProperty() { + return level; + } + + public BanDurationType getDuration() { + return duration.get(); + } + + public ObjectProperty durationProperty() { + return duration; + } + + public BanStatus getBanStatus() { + return banStatus.get(); + } + + public ObjectProperty banStatusProperty() { + return banStatus; + } + + public BanRevokeDataFX getBanRevokeData() { + return banRevokeData.get(); + } + + public BanInfoFX setBanRevokeData(BanRevokeDataFX banRevokeData) { + this.banRevokeData.set(banRevokeData); + return this; + } + + public ObjectProperty banRevokeDataProperty() { + return banRevokeData; + } +} diff --git a/src/main/java/com/faforever/moderatorclient/ui/domain/BanRevokeDataFX.java b/src/main/java/com/faforever/moderatorclient/ui/domain/BanRevokeDataFX.java new file mode 100644 index 0000000..b325e03 --- /dev/null +++ b/src/main/java/com/faforever/moderatorclient/ui/domain/BanRevokeDataFX.java @@ -0,0 +1,57 @@ +package com.faforever.moderatorclient.ui.domain; + +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; + +public class BanRevokeDataFX extends AbstractEntityFX { + private final ObjectProperty ban; + private final StringProperty reason; + private final ObjectProperty author; + + public BanRevokeDataFX() { + ban = new SimpleObjectProperty<>(); + reason = new SimpleStringProperty(); + author = new SimpleObjectProperty<>(); + } + + public BanInfoFX getBan() { + return ban.get(); + } + + public BanRevokeDataFX setBan(BanInfoFX ban) { + this.ban.set(ban); + return this; + } + + public ObjectProperty banProperty() { + return ban; + } + + public String getReason() { + return reason.get(); + } + + public BanRevokeDataFX setReason(String reason) { + this.reason.set(reason); + return this; + } + + public StringProperty reasonProperty() { + return reason; + } + + public PlayerFX getAuthor() { + return author.get(); + } + + public BanRevokeDataFX setAuthor(PlayerFX author) { + this.author.set(author); + return this; + } + + public ObjectProperty authorProperty() { + return author; + } +} diff --git a/src/main/java/com/faforever/moderatorclient/ui/domain/GameFX.java b/src/main/java/com/faforever/moderatorclient/ui/domain/GameFX.java index 6b0b1b5..cb642c9 100644 --- a/src/main/java/com/faforever/moderatorclient/ui/domain/GameFX.java +++ b/src/main/java/com/faforever/moderatorclient/ui/domain/GameFX.java @@ -1,8 +1,8 @@ package com.faforever.moderatorclient.ui.domain; -import com.faforever.moderatorclient.api.dto.GameReview; -import com.faforever.moderatorclient.api.dto.Validity; -import com.faforever.moderatorclient.api.dto.VictoryCondition; +import com.faforever.commons.api.dto.GameReview; +import com.faforever.commons.api.dto.Validity; +import com.faforever.commons.api.dto.VictoryCondition; import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleStringProperty; @@ -27,17 +27,17 @@ public class GameFX extends AbstractEntityFX { private final ObjectProperty mapVersion; public GameFX() { - this.id = new SimpleStringProperty(); - this.name = new SimpleStringProperty(); - this.startTime = new SimpleObjectProperty<>(); - this.endTime = new SimpleObjectProperty<>(); - this.validity = new SimpleObjectProperty<>(); - this.victoryCondition = new SimpleObjectProperty<>(); - this.reviews = FXCollections.observableArrayList(); - this.playerStats = FXCollections.observableArrayList(); - this.host = new SimpleObjectProperty<>(); - this.featuredMod = new SimpleObjectProperty<>(); - this.mapVersion = new SimpleObjectProperty<>(); + id = new SimpleStringProperty(); + name = new SimpleStringProperty(); + startTime = new SimpleObjectProperty<>(); + endTime = new SimpleObjectProperty<>(); + validity = new SimpleObjectProperty<>(); + victoryCondition = new SimpleObjectProperty<>(); + reviews = FXCollections.observableArrayList(); + playerStats = FXCollections.observableArrayList(); + host = new SimpleObjectProperty<>(); + featuredMod = new SimpleObjectProperty<>(); + mapVersion = new SimpleObjectProperty<>(); } @Override @@ -124,7 +124,10 @@ public ObservableList getPlayerStats() { public void setPlayerStats(List statsFXList) { playerStats.clear(); - playerStats.addAll(statsFXList); + + if (statsFXList != null) { + playerStats.addAll(statsFXList); + } } public PlayerFX getHost() { diff --git a/src/main/java/com/faforever/moderatorclient/ui/domain/GamePlayerStatsFX.java b/src/main/java/com/faforever/moderatorclient/ui/domain/GamePlayerStatsFX.java index 76b803b..371a98c 100644 --- a/src/main/java/com/faforever/moderatorclient/ui/domain/GamePlayerStatsFX.java +++ b/src/main/java/com/faforever/moderatorclient/ui/domain/GamePlayerStatsFX.java @@ -1,6 +1,6 @@ package com.faforever.moderatorclient.ui.domain; -import com.faforever.moderatorclient.api.dto.Faction; +import com.faforever.commons.api.dto.Faction; import javafx.beans.property.*; import java.time.OffsetDateTime; diff --git a/src/main/java/com/faforever/moderatorclient/ui/domain/MapFX.java b/src/main/java/com/faforever/moderatorclient/ui/domain/MapFX.java index 2f09104..c3e6916 100644 --- a/src/main/java/com/faforever/moderatorclient/ui/domain/MapFX.java +++ b/src/main/java/com/faforever/moderatorclient/ui/domain/MapFX.java @@ -141,7 +141,10 @@ public ObservableList getVersions() { public void setVersions(List versionFXList) { versions.clear(); - versions.addAll(versionFXList); + + if (versionFXList != null) { + versions.addAll(versionFXList); + } } // @Relationship("author") diff --git a/src/main/java/com/faforever/moderatorclient/ui/domain/NameRecordFX.java b/src/main/java/com/faforever/moderatorclient/ui/domain/NameRecordFX.java new file mode 100644 index 0000000..2605693 --- /dev/null +++ b/src/main/java/com/faforever/moderatorclient/ui/domain/NameRecordFX.java @@ -0,0 +1,71 @@ +package com.faforever.moderatorclient.ui.domain; + +import com.faforever.commons.api.dto.Player; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; + +import java.time.OffsetDateTime; + +public class NameRecordFX { + private final StringProperty id; + private final ObjectProperty changeTime; + private final ObjectProperty player; + private final StringProperty name; + + public NameRecordFX() { + id = new SimpleStringProperty(); + changeTime = new SimpleObjectProperty<>(); + player = new SimpleObjectProperty<>(); + name = new SimpleStringProperty(); + } + + public String getId() { + return id.get(); + } + + public void setId(String id) { + this.id.set(id); + } + + public StringProperty idProperty() { + return id; + } + + public OffsetDateTime getChangeTime() { + return changeTime.get(); + } + + public void setChangeTime(OffsetDateTime changeTime) { + this.changeTime.set(changeTime); + } + + public ObjectProperty changeTimeProperty() { + return changeTime; + } + + public Player getPlayer() { + return player.get(); + } + + public void setPlayer(Player player) { + this.player.set(player); + } + + public ObjectProperty playerProperty() { + return player; + } + + public String getName() { + return name.get(); + } + + public void setName(String name) { + this.name.set(name); + } + + public StringProperty nameProperty() { + return name; + } +} diff --git a/src/main/java/com/faforever/moderatorclient/ui/domain/PlayerFX.java b/src/main/java/com/faforever/moderatorclient/ui/domain/PlayerFX.java index ab5d463..06d8bcf 100644 --- a/src/main/java/com/faforever/moderatorclient/ui/domain/PlayerFX.java +++ b/src/main/java/com/faforever/moderatorclient/ui/domain/PlayerFX.java @@ -1,12 +1,11 @@ package com.faforever.moderatorclient.ui.domain; -import com.faforever.moderatorclient.mapstruct.JavaFXMapper; import javafx.beans.binding.Bindings; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; -import org.mapstruct.Mapper; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; -@Mapper(uses = JavaFXMapper.class) public class PlayerFX extends AbstractEntityFX { private final StringProperty login; private final StringProperty email; @@ -14,7 +13,9 @@ public class PlayerFX extends AbstractEntityFX { private final StringProperty steamId; private final StringProperty recentIpAddress; private final StringProperty representation; -// private final ListProperty names; + private final ObservableList names; + private final ObservableList bans; + private final ObservableList avatarAssignments; public PlayerFX() { login = new SimpleStringProperty(); @@ -25,6 +26,10 @@ public PlayerFX() { representation = new SimpleStringProperty(); representation.bind(Bindings.concat(login, " [id ", idProperty(), "]")); + + names = FXCollections.observableArrayList(); + bans = FXCollections.observableArrayList(); + avatarAssignments = FXCollections.observableArrayList(); } // @Relationship("globalRating") @@ -35,13 +40,6 @@ public PlayerFX() { // // @Relationship("lobbyGroup") // private LobbyGroup lobbyGroup; -// -// @Relationship("bans") -// private List bans; -// -// @Relationship("avatarAssignments") -// @JsonIgnore -// private List avatarAssignments; public String getLogin() { @@ -107,4 +105,38 @@ public StringProperty recentIpAddressProperty() { public StringProperty representationProperty() { return representation; } + + public ObservableList getNames() { + return names; + } + + public void setNames(ObservableList nameRecordFXObservableList) { + names.clear(); + if (nameRecordFXObservableList != null) { + names.addAll(nameRecordFXObservableList); + } + } + + public ObservableList getBans() { + return bans; + } + + public void setBans(ObservableList banInfoFXObservableList) { + bans.clear(); + + if (banInfoFXObservableList != null) { + bans.addAll(banInfoFXObservableList); + } + } + + public ObservableList getAvatarAssignments() { + return avatarAssignments; + } + + public void setAvatarAssignments(ObservableList avatarAssignmentFXObservableList) { + avatarAssignments.clear(); + if (avatarAssignmentFXObservableList != null) { + avatarAssignments.addAll(avatarAssignmentFXObservableList); + } + } } diff --git a/src/main/java/com/faforever/moderatorclient/ui/domain/TeamkillFX.java b/src/main/java/com/faforever/moderatorclient/ui/domain/TeamkillFX.java new file mode 100644 index 0000000..9435360 --- /dev/null +++ b/src/main/java/com/faforever/moderatorclient/ui/domain/TeamkillFX.java @@ -0,0 +1,95 @@ +package com.faforever.moderatorclient.ui.domain; + +import javafx.beans.property.*; + +import java.time.OffsetDateTime; + +public class TeamkillFX { + private final StringProperty id; + private final ObjectProperty teamkiller; + private final ObjectProperty victim; + private final ObjectProperty game; + private final LongProperty gameTime; + private final ObjectProperty reportedAt; + + public TeamkillFX() { + id = new SimpleStringProperty(); + teamkiller = new SimpleObjectProperty<>(); + victim = new SimpleObjectProperty<>(); + game = new SimpleObjectProperty<>(); + gameTime = new SimpleLongProperty(); + reportedAt = new SimpleObjectProperty<>(); + } + + public String getId() { + return id.get(); + } + + public void setId(String id) { + this.id.set(id); + } + + public StringProperty idProperty() { + return id; + } + + public PlayerFX getTeamkiller() { + return teamkiller.get(); + } + + public void setTeamkiller(PlayerFX teamkiller) { + this.teamkiller.set(teamkiller); + } + + public ObjectProperty teamkillerProperty() { + return teamkiller; + } + + public PlayerFX getVictim() { + return victim.get(); + } + + public void setVictim(PlayerFX victim) { + this.victim.set(victim); + } + + public ObjectProperty victimProperty() { + return victim; + } + + public GameFX getGame() { + return game.get(); + } + + public void setGame(GameFX game) { + this.game.set(game); + } + + public ObjectProperty gameProperty() { + return game; + } + + public long getGameTime() { + return gameTime.get(); + } + + public void setGameTime(long gameTime) { + this.gameTime.set(gameTime); + } + + public LongProperty gameTimeProperty() { + return gameTime; + } + + public OffsetDateTime getReportedAt() { + return reportedAt.get(); + } + + public void setReportedAt(OffsetDateTime reportedAt) { + this.reportedAt.set(reportedAt); + } + + public ObjectProperty reportedAtProperty() { + return reportedAt; + } +} diff --git a/src/main/java/com/faforever/moderatorclient/ui/main_window/AvatarsController.java b/src/main/java/com/faforever/moderatorclient/ui/main_window/AvatarsController.java index 920166c..0856888 100644 --- a/src/main/java/com/faforever/moderatorclient/ui/main_window/AvatarsController.java +++ b/src/main/java/com/faforever/moderatorclient/ui/main_window/AvatarsController.java @@ -1,10 +1,14 @@ package com.faforever.moderatorclient.ui.main_window; -import com.faforever.moderatorclient.api.dto.Avatar; -import com.faforever.moderatorclient.api.dto.AvatarAssignment; -import com.faforever.moderatorclient.api.rest.domain.AvatarService; +import com.faforever.commons.api.dto.Avatar; +import com.faforever.moderatorclient.api.domain.AvatarService; +import com.faforever.moderatorclient.mapstruct.AvatarMapper; import com.faforever.moderatorclient.ui.Controller; import com.faforever.moderatorclient.ui.ViewHelper; +import com.faforever.moderatorclient.ui.domain.AvatarAssignmentFX; +import com.faforever.moderatorclient.ui.domain.AvatarFX; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import javafx.fxml.FXML; import javafx.scene.control.RadioButton; import javafx.scene.control.SplitPane; @@ -13,25 +17,32 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; -import java.util.Collection; +import java.util.List; import java.util.Optional; @Slf4j @Component public class AvatarsController implements Controller { private final AvatarService avatarService; + private final AvatarMapper avatarMapper; + public TableView avatarTableView; + public TableView avatarAssignmentTableView; public SplitPane root; - public TableView avatarTableView; - public TableView avatarAssignmentTableView; public RadioButton showAllAvatarsRadioButton; public RadioButton searchAvatarsByIdRadioButton; public RadioButton searchAvatarsByTooltipRadioButton; public RadioButton searchAvatarsByAssignedUserRadioButton; public TextField searchAvatarsTextField; + private ObservableList avatars; + private ObservableList avatarAssignments; - public AvatarsController(AvatarService avatarService) { + public AvatarsController(AvatarService avatarService, AvatarMapper avatarMapper) { this.avatarService = avatarService; + this.avatarMapper = avatarMapper; + + avatars = FXCollections.observableArrayList(); + avatarAssignments = FXCollections.observableArrayList(); } @Override @@ -41,38 +52,38 @@ public SplitPane getRoot() { @FXML public void initialize() { - ViewHelper.buildAvatarTableView(avatarTableView); - ViewHelper.buildAvatarAssignmentTableView(avatarAssignmentTableView); + ViewHelper.buildAvatarTableView(avatarTableView, avatars); + ViewHelper.buildAvatarAssignmentTableView(avatarAssignmentTableView, avatarAssignments); avatarTableView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { - avatarAssignmentTableView.getItems().clear(); - Optional.ofNullable(newValue).ifPresent(avatar -> avatarAssignmentTableView.getItems().addAll(avatar.getAssignments())); + avatarAssignments.clear(); + Optional.ofNullable(newValue).ifPresent(avatar -> avatarAssignments.addAll(avatar.getAssignments())); }); } public void refresh() { - avatarTableView.getItems().clear(); + avatars.clear(); + avatars.addAll(avatarMapper.map(avatarService.getAll())); + avatarTableView.getSortOrder().clear(); - avatarTableView.getItems().addAll( - avatarService.getAll() - ); } public void onSearchAvatars() { - avatarTableView.getItems().clear(); + avatars.clear(); avatarTableView.getSortOrder().clear(); - Collection avatars; + + List avatarSearchResult; String pattern = searchAvatarsTextField.getText(); if (searchAvatarsByIdRadioButton.isSelected()) { - avatars = avatarService.findAvatarsById(pattern); + avatarSearchResult = avatarService.findAvatarsById(pattern); } else if (searchAvatarsByTooltipRadioButton.isSelected()) { - avatars = avatarService.findAvatarsByTooltip(pattern); + avatarSearchResult = avatarService.findAvatarsByTooltip(pattern); } else if (searchAvatarsByAssignedUserRadioButton.isSelected()) { - avatars = avatarService.findAvatarsByAssignedUser(pattern); + avatarSearchResult = avatarService.findAvatarsByAssignedUser(pattern); } else { - avatars = avatarService.getAll(); + avatarSearchResult = avatarService.getAll(); } - avatarTableView.getItems().addAll(avatars); + avatars.addAll(avatarMapper.map(avatarSearchResult)); } } diff --git a/src/main/java/com/faforever/moderatorclient/ui/main_window/DomainBlacklistController.java b/src/main/java/com/faforever/moderatorclient/ui/main_window/DomainBlacklistController.java index 1268076..7c6ad4f 100644 --- a/src/main/java/com/faforever/moderatorclient/ui/main_window/DomainBlacklistController.java +++ b/src/main/java/com/faforever/moderatorclient/ui/main_window/DomainBlacklistController.java @@ -1,11 +1,13 @@ package com.faforever.moderatorclient.ui.main_window; -import com.faforever.moderatorclient.api.dto.DomainBlacklist; -import com.faforever.moderatorclient.api.rest.domain.DomainBlacklistService; +import com.faforever.commons.api.dto.DomainBlacklist; +import com.faforever.moderatorclient.api.domain.DomainBlacklistService; import com.faforever.moderatorclient.mapstruct.DomainBlacklistMapper; import com.faforever.moderatorclient.ui.Controller; import com.faforever.moderatorclient.ui.domain.DomainBlacklistFX; import com.google.common.collect.Lists; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import javafx.fxml.FXML; import javafx.scene.control.*; import javafx.util.Callback; @@ -20,6 +22,7 @@ public class DomainBlacklistController implements Controller { private final DomainBlacklistService domainBlacklistService; private final DomainBlacklistMapper domainBlacklistMapper; + private ObservableList domainBlacklist; public SplitPane root; public ListView currentDomainBlacklistListView; @@ -28,10 +31,13 @@ public class DomainBlacklistController implements Controller { public DomainBlacklistController(DomainBlacklistService domainBlacklistService, DomainBlacklistMapper domainBlacklistMapper) { this.domainBlacklistService = domainBlacklistService; this.domainBlacklistMapper = domainBlacklistMapper; + + domainBlacklist = FXCollections.observableArrayList(); } @FXML public void initialize() { + currentDomainBlacklistListView.setItems(domainBlacklist); currentDomainBlacklistListView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); currentDomainBlacklistListView.setCellFactory(new Callback, ListCell>() { @Override @@ -59,8 +65,8 @@ public SplitPane getRoot() { } public void refresh() { - currentDomainBlacklistListView.getItems().clear(); - currentDomainBlacklistListView.getItems().addAll( + domainBlacklist.clear(); + domainBlacklist.addAll( domainBlacklistMapper.map(domainBlacklistService.getAll()) ); } @@ -75,7 +81,7 @@ public void removeSelected() { public void addList() { List newDomains = Lists.newArrayList(addDomainBlacklistTextArea.getText().split("\\n")); - List currentDomains = currentDomainBlacklistListView.getItems().stream() + List currentDomains = domainBlacklist.stream() .map(DomainBlacklistFX::getDomain) .collect(Collectors.toList()); diff --git a/src/main/java/com/faforever/moderatorclient/ui/main_window/LadderMapPoolController.java b/src/main/java/com/faforever/moderatorclient/ui/main_window/LadderMapPoolController.java index fd80142..7454603 100644 --- a/src/main/java/com/faforever/moderatorclient/ui/main_window/LadderMapPoolController.java +++ b/src/main/java/com/faforever/moderatorclient/ui/main_window/LadderMapPoolController.java @@ -1,6 +1,6 @@ package com.faforever.moderatorclient.ui.main_window; -import com.faforever.moderatorclient.api.rest.domain.MapService; +import com.faforever.moderatorclient.api.domain.MapService; import com.faforever.moderatorclient.mapstruct.MapMapper; import com.faforever.moderatorclient.mapstruct.MapVersionMapper; import com.faforever.moderatorclient.ui.Controller; diff --git a/src/main/java/com/faforever/moderatorclient/ui/main_window/MapVaultController.java b/src/main/java/com/faforever/moderatorclient/ui/main_window/MapVaultController.java index 3e2de94..c6d0e45 100644 --- a/src/main/java/com/faforever/moderatorclient/ui/main_window/MapVaultController.java +++ b/src/main/java/com/faforever/moderatorclient/ui/main_window/MapVaultController.java @@ -1,13 +1,15 @@ package com.faforever.moderatorclient.ui.main_window; -import com.faforever.moderatorclient.api.dto.Map; -import com.faforever.moderatorclient.api.rest.domain.MapService; +import com.faforever.commons.api.dto.Map; +import com.faforever.moderatorclient.api.domain.MapService; import com.faforever.moderatorclient.mapstruct.MapMapper; import com.faforever.moderatorclient.mapstruct.MapVersionMapper; import com.faforever.moderatorclient.ui.Controller; import com.faforever.moderatorclient.ui.ViewHelper; import com.faforever.moderatorclient.ui.domain.MapFX; import com.faforever.moderatorclient.ui.domain.MapVersionFX; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import javafx.fxml.FXML; import javafx.scene.control.*; import javafx.scene.image.Image; @@ -26,6 +28,8 @@ public class MapVaultController implements Controller { private final MapService mapService; private final MapMapper mapMapper; private final MapVersionMapper mapVersionMapper; + private ObservableList maps; + private ObservableList mapVersions; public SplitPane root; @@ -44,6 +48,9 @@ public MapVaultController(MapService mapService, MapMapper mapMapper, MapVersion this.mapService = mapService; this.mapMapper = mapMapper; this.mapVersionMapper = mapVersionMapper; + + maps = FXCollections.observableArrayList(); + mapVersions = FXCollections.observableArrayList(); } @Override @@ -53,12 +60,12 @@ public SplitPane getRoot() { @FXML public void initialize() { - ViewHelper.buildMapTableView(mapSearchTableView); - ViewHelper.buildMapVersionTableView(mapVersionTableView); + ViewHelper.buildMapTableView(mapSearchTableView, maps); + ViewHelper.buildMapVersionTableView(mapVersionTableView, mapVersions); mapSearchTableView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { - mapVersionTableView.getItems().clear(); - Optional.ofNullable(newValue).ifPresent(map -> mapVersionTableView.getItems().addAll( + mapVersions.clear(); + Optional.ofNullable(newValue).ifPresent(map -> mapVersions.addAll( map.getVersions())); }); @@ -76,7 +83,7 @@ public void initialize() { } public void onSearchMaps() { - mapSearchTableView.getItems().clear(); + maps.clear(); mapSearchTableView.getSortOrder().clear(); List mapsFound = Collections.emptyList(); @@ -89,7 +96,7 @@ public void onSearchMaps() { mapsFound = mapService.findMapsByAuthorName(searchPattern, excludeHiddenMapVersionsCheckbox.isSelected()); } - mapSearchTableView.getItems().addAll(mapMapper.map(mapsFound)); + maps.addAll(mapMapper.map(mapsFound)); } public void onToggleMapVersionHiding() { diff --git a/src/main/java/com/faforever/moderatorclient/ui/main_window/RecentActivityController.java b/src/main/java/com/faforever/moderatorclient/ui/main_window/RecentActivityController.java index 25fb3cd..56dd523 100644 --- a/src/main/java/com/faforever/moderatorclient/ui/main_window/RecentActivityController.java +++ b/src/main/java/com/faforever/moderatorclient/ui/main_window/RecentActivityController.java @@ -1,10 +1,12 @@ package com.faforever.moderatorclient.ui.main_window; -import com.faforever.moderatorclient.api.dto.Player; -import com.faforever.moderatorclient.api.dto.Teamkill; -import com.faforever.moderatorclient.api.rest.domain.UserService; +import com.faforever.moderatorclient.api.domain.UserService; import com.faforever.moderatorclient.ui.Controller; import com.faforever.moderatorclient.ui.ViewHelper; +import com.faforever.moderatorclient.ui.domain.PlayerFX; +import com.faforever.moderatorclient.ui.domain.TeamkillFX; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import javafx.fxml.FXML; import javafx.scene.control.TableView; import javafx.scene.layout.VBox; @@ -15,13 +17,18 @@ @Component public class RecentActivityController implements Controller { private final UserService userService; + private final ObservableList users; + private final ObservableList teamkills; public VBox root; - public TableView userRegistrationFeedTableView; - public TableView teamkillFeedTableView; + public TableView userRegistrationFeedTableView; + public TableView teamkillFeedTableView; public RecentActivityController(UserService userService) { this.userService = userService; + + users = FXCollections.observableArrayList(); + teamkills = FXCollections.observableArrayList(); } @Override @@ -31,17 +38,17 @@ public VBox getRoot() { @FXML public void initialize() { - ViewHelper.buildUserTableView(userRegistrationFeedTableView); - ViewHelper.buildTeamkillTableView(teamkillFeedTableView, true); + ViewHelper.buildUserTableView(userRegistrationFeedTableView, users); + ViewHelper.buildTeamkillTableView(teamkillFeedTableView, teamkills, true); } public void refresh() { - userRegistrationFeedTableView.getItems().clear(); + users.clear(); + users.addAll(userService.findLatestRegistrations()); userRegistrationFeedTableView.getSortOrder().clear(); - userRegistrationFeedTableView.getItems().addAll(userService.findLatestRegistrations()); - teamkillFeedTableView.getItems().clear(); + teamkills.clear(); + teamkills.addAll(userService.findLatestTeamkills()); userRegistrationFeedTableView.getSortOrder().clear(); - teamkillFeedTableView.getItems().addAll(userService.findLatestTeamkills()); } } diff --git a/src/main/java/com/faforever/moderatorclient/ui/main_window/UserManagementController.java b/src/main/java/com/faforever/moderatorclient/ui/main_window/UserManagementController.java index f26c89a..e1a1f39 100644 --- a/src/main/java/com/faforever/moderatorclient/ui/main_window/UserManagementController.java +++ b/src/main/java/com/faforever/moderatorclient/ui/main_window/UserManagementController.java @@ -1,14 +1,9 @@ package com.faforever.moderatorclient.ui.main_window; -import com.faforever.moderatorclient.api.dto.*; -import com.faforever.moderatorclient.api.rest.domain.UserService; +import com.faforever.moderatorclient.api.domain.UserService; import com.faforever.moderatorclient.mapstruct.GamePlayerStatsMapper; -import com.faforever.moderatorclient.mapstruct.PlayerMapper; import com.faforever.moderatorclient.ui.*; -import com.faforever.moderatorclient.ui.domain.FeaturedModFX; -import com.faforever.moderatorclient.ui.domain.GamePlayerStatsFX; -import com.faforever.moderatorclient.ui.domain.PlayerFX; -import com.faforever.moderatorclient.ui.domain.UserNoteFX; +import com.faforever.moderatorclient.ui.domain.*; import javafx.application.Platform; import javafx.beans.binding.Bindings; import javafx.beans.value.ObservableValue; @@ -24,8 +19,8 @@ import org.springframework.stereotype.Component; import org.springframework.util.Assert; -import java.util.Collection; import java.util.Collections; +import java.util.List; import java.util.concurrent.CompletableFuture; @Slf4j @@ -34,10 +29,14 @@ public class UserManagementController implements Controller { private final UiService uiService; private final PlatformService platformService; private final UserService userService; - private final PlayerMapper playerMapper; private final GamePlayerStatsMapper gamePlayerStatsMapper; + private final ObservableList users; private final ObservableList userNotes; + private final ObservableList bans; + private final ObservableList nameRecords; + private final ObservableList teamkills; + private final ObservableList avatarAssignments; private final String replayDownLoadFormat; @@ -55,25 +54,29 @@ public class UserManagementController implements Controller { public Button editNoteButton; public Button newBanButton; public Button editBanButton; - public TableView userSearchTableView; - public TableView userNameHistoryTableView; - public TableView userBansTableView; - public TableView userTeamkillsTableView; - public TableView userAvatarsTableView; + public TableView userSearchTableView; + public TableView userNameHistoryTableView; + public TableView userBansTableView; + public TableView userTeamkillsTableView; + public TableView userAvatarsTableView; public TableView userLastGamesTable; public ChoiceBox featuredModFilterChoiceBox; public Button loadMoreGamesButton; private Runnable loadMoreGamesRunnable; private int userGamesPage = 1; - public UserManagementController(UiService uiService, PlatformService platformService, UserService userService, PlayerMapper playerMapper, GamePlayerStatsMapper gamePlayerStatsMapper, @Value("${faforever.vault.replayDownloadUrlFormat}") String replayDownLoadFormat) { + public UserManagementController(UiService uiService, PlatformService platformService, UserService userService, GamePlayerStatsMapper gamePlayerStatsMapper, @Value("${faforever.vault.replayDownloadUrlFormat}") String replayDownLoadFormat) { this.uiService = uiService; this.platformService = platformService; this.userService = userService; - this.playerMapper = playerMapper; this.gamePlayerStatsMapper = gamePlayerStatsMapper; this.replayDownLoadFormat = replayDownLoadFormat; + users = FXCollections.observableArrayList(); userNotes = FXCollections.observableArrayList(); + bans = FXCollections.observableArrayList(); + nameRecords = FXCollections.observableArrayList(); + teamkills = FXCollections.observableArrayList(); + avatarAssignments = FXCollections.observableArrayList(); } @Override @@ -83,10 +86,10 @@ public SplitPane getRoot() { @FXML public void initialize() { - ViewHelper.buildUserTableView(userSearchTableView); + ViewHelper.buildUserTableView(userSearchTableView, users); ViewHelper.buildNotesTableView(userNoteTableView, userNotes, false); - ViewHelper.buildNameHistoryTableView(userNameHistoryTableView); - ViewHelper.buildBanTableView(userBansTableView); + ViewHelper.buildNameHistoryTableView(userNameHistoryTableView, nameRecords); + ViewHelper.buildBanTableView(userBansTableView, bans); ViewHelper.buildPlayersGamesTable(userLastGamesTable, replayDownLoadFormat, platformService); addNoteButton.disableProperty().bind(userSearchTableView.getSelectionModel().selectedItemProperty().isNull()); @@ -117,35 +120,37 @@ public FeaturedModFX fromString(String string) { CompletableFuture.supplyAsync(userService::getFeaturedMods) .thenAccept(featuredMods -> Platform.runLater(() -> featuredModFilterChoiceBox.getItems().addAll(featuredMods))); - ViewHelper.buildTeamkillTableView(userTeamkillsTableView, false); - ViewHelper.buildUserAvatarsTableView(userAvatarsTableView); + ViewHelper.buildTeamkillTableView(userTeamkillsTableView, teamkills, false); + ViewHelper.buildUserAvatarsTableView(userAvatarsTableView, avatarAssignments); userSearchTableView.getSelectionModel().selectedItemProperty().addListener(this::onSelectedUser); editBanButton.disableProperty().bind(userBansTableView.getSelectionModel().selectedItemProperty().isNull()); } - private void onSelectedUser(ObservableValue observable, Player oldValue, Player newValue) { - userNoteTableView.getItems().clear(); - userNameHistoryTableView.getItems().clear(); + private void onSelectedUser(ObservableValue observable, PlayerFX oldValue, PlayerFX newValue) { + nameRecords.clear(); userNameHistoryTableView.getSortOrder().clear(); - userBansTableView.getItems().clear(); + bans.clear(); userBansTableView.getSortOrder().clear(); - userTeamkillsTableView.getItems().clear(); - userTeamkillsTableView.getSortOrder().clear(); - userAvatarsTableView.getItems().clear(); - userAvatarsTableView.getSortOrder().clear(); + userLastGamesTable.getItems().clear(); userLastGamesTable.getSortOrder().clear(); + userTeamkillsTableView.getSortOrder().clear(); + teamkills.clear(); + userNoteTableView.getSortOrder().clear(); userNotes.clear(); + avatarAssignments.clear(); + userAvatarsTableView.getSortOrder().clear(); + if (newValue != null) { userNotes.addAll(userService.getUserNotes(newValue.getId())); - userNameHistoryTableView.getItems().addAll(newValue.getNames()); - userBansTableView.getItems().addAll(newValue.getBans()); - userTeamkillsTableView.getItems().addAll(userService.findTeamkillsByUserId(newValue.getId())); - userAvatarsTableView.getItems().addAll(newValue.getAvatarAssignments()); + nameRecords.addAll(newValue.getNames()); + bans.addAll(newValue.getBans()); + teamkills.addAll(userService.findTeamkillsByUserId(newValue.getId())); + avatarAssignments.addAll(newValue.getAvatarAssignments()); userGamesPage = 1; loadMoreGamesRunnable = () -> CompletableFuture.supplyAsync(() -> gamePlayerStatsMapper.map(userService.getLastHundredPlayedGamesByFeaturedMod(newValue.getId(), userGamesPage, featuredModFilterChoiceBox.getSelectionModel().getSelectedItem()))) @@ -157,10 +162,10 @@ private void onSelectedUser(ObservableValue observable, Player } public void onUserSearch() { - userSearchTableView.getItems().clear(); + users.clear(); userSearchTableView.getSortOrder().clear(); - Collection usersFound = Collections.emptyList(); + List usersFound = Collections.emptyList(); String searchPattern = userSearchTextField.getText(); if (searchUserByIdRadioButton.isSelected()) { usersFound = userService.findUserById(searchPattern); @@ -176,70 +181,71 @@ public void onUserSearch() { usersFound = userService.findUserByIP(searchPattern); } - userSearchTableView.getItems().addAll(usersFound); + users.addAll(usersFound); } public void onNewBan() { - Player selectedPlayer = userSearchTableView.getSelectionModel().getSelectedItem(); + PlayerFX selectedPlayer = userSearchTableView.getSelectionModel().getSelectedItem(); Assert.notNull(selectedPlayer, "You need to select a player to create a ban."); - BanInfoController banInfoController = uiService.loadFxml("ui/banInfo.fxml"); - banInfoController.setBanInfo(new BanInfo() - .setPlayer(selectedPlayer) - ); + BanInfoFX banInfoFX = new BanInfoFX() + .setPlayer(selectedPlayer); - Stage banInfoDialog = new Stage(); - banInfoDialog.setTitle("Apply new ban"); - banInfoDialog.setScene(new Scene(banInfoController.getRoot())); - banInfoDialog.showAndWait(); + openBanDialog(banInfoFX, true); } public void onEditBan() { - BanInfo selectedBan = userBansTableView.getSelectionModel().getSelectedItem(); + BanInfoFX selectedBan = userBansTableView.getSelectionModel().getSelectedItem(); Assert.notNull(selectedBan, "You need to select a ban to edit it."); + openBanDialog(selectedBan, false); + } + + private void openBanDialog(BanInfoFX banInfoFX, boolean isNew) { BanInfoController banInfoController = uiService.loadFxml("ui/banInfo.fxml"); - banInfoController.setBanInfo(selectedBan); + banInfoController.setBanInfo(banInfoFX); + if (isNew) { + banInfoController.addPostedListener(bans::add); + } Stage banInfoDialog = new Stage(); - banInfoDialog.setTitle("Edit Ban"); + banInfoDialog.setTitle(isNew ? "Apply new ban" : "Edit ban"); banInfoDialog.setScene(new Scene(banInfoController.getRoot())); banInfoDialog.showAndWait(); } - public void loadMoreGames() { - userGamesPage++; - loadMoreGamesRunnable.run(); - } - public void addNote() { - PlayerFX selectedPlayer = playerMapper.map(userSearchTableView.getSelectionModel().getSelectedItem()); + PlayerFX selectedPlayer = userSearchTableView.getSelectionModel().getSelectedItem(); Assert.notNull(selectedPlayer, "You need to select a player to create a userNote."); - UserNoteController userNoteController = uiService.loadFxml("ui/userNote.fxml"); - UserNoteFX userNoteFX = new UserNoteFX(); userNoteFX.setPlayer(selectedPlayer); - userNoteController.addPostedListener(userNotes::add); - - userNoteController.setUserNoteFX(userNoteFX); - Stage userNoteDialog = new Stage(); - userNoteDialog.setTitle("Add new player note"); - userNoteDialog.setScene(new Scene(userNoteController.getRoot())); - userNoteDialog.showAndWait(); + openUserNoteDialog(userNoteFX, true); } public void editNote() { UserNoteFX selectedUserNote = userNoteTableView.getSelectionModel().getSelectedItem(); Assert.notNull(selectedUserNote, "You need to select a player note to edit it."); + openUserNoteDialog(selectedUserNote, false); + } + + private void openUserNoteDialog(UserNoteFX userNoteFX, boolean isNew) { UserNoteController userNoteController = uiService.loadFxml("ui/userNote.fxml"); - userNoteController.setUserNoteFX(selectedUserNote); + userNoteController.setUserNoteFX(userNoteFX); + if (isNew) { + userNoteController.addPostedListener(userNotes::add); + } Stage userNoteDialog = new Stage(); - userNoteDialog.setTitle("Edit player note"); + userNoteDialog.setTitle(isNew ? "Add new player note" : "Edit player note"); userNoteDialog.setScene(new Scene(userNoteController.getRoot())); userNoteDialog.showAndWait(); } + + public void loadMoreGames() { + userGamesPage++; + loadMoreGamesRunnable.run(); + } } diff --git a/src/main/resources/ui/banInfo.fxml b/src/main/resources/ui/banInfo.fxml index 0cfc5a1..4013b91 100644 --- a/src/main/resources/ui/banInfo.fxml +++ b/src/main/resources/ui/banInfo.fxml @@ -52,7 +52,7 @@ + text="temporary ban until (i.e. 2017-12-31T12:00:00)" toggleGroup="$banDuration"> diff --git a/src/main/resources/ui/main_window/avatars.fxml b/src/main/resources/ui/main_window/avatars.fxml index 3bd2d53..754e8c9 100644 --- a/src/main/resources/ui/main_window/avatars.fxml +++ b/src/main/resources/ui/main_window/avatars.fxml @@ -40,7 +40,7 @@ - + diff --git a/src/main/resources/ui/main_window/ladderMapPool.fxml b/src/main/resources/ui/main_window/ladderMapPool.fxml index 4e855e9..57e45fe 100644 --- a/src/main/resources/ui/main_window/ladderMapPool.fxml +++ b/src/main/resources/ui/main_window/ladderMapPool.fxml @@ -68,7 +68,7 @@ - + diff --git a/src/main/resources/ui/main_window/mapVault.fxml b/src/main/resources/ui/main_window/mapVault.fxml index c42d9dc..d9c8578 100644 --- a/src/main/resources/ui/main_window/mapVault.fxml +++ b/src/main/resources/ui/main_window/mapVault.fxml @@ -38,7 +38,7 @@ - + diff --git a/src/main/resources/ui/main_window/userManagement.fxml b/src/main/resources/ui/main_window/userManagement.fxml index 6b6a2ce..f439340 100644 --- a/src/main/resources/ui/main_window/userManagement.fxml +++ b/src/main/resources/ui/main_window/userManagement.fxml @@ -50,7 +50,7 @@ - + diff --git a/src/test/java/com/faforever/moderatorclient/api/ElideRouteBuilderTest.java b/src/test/java/com/faforever/moderatorclient/api/ElideRouteBuilderTest.java index 5f99491..9779dc9 100644 --- a/src/test/java/com/faforever/moderatorclient/api/ElideRouteBuilderTest.java +++ b/src/test/java/com/faforever/moderatorclient/api/ElideRouteBuilderTest.java @@ -1,7 +1,6 @@ package com.faforever.moderatorclient.api; -import com.faforever.moderatorclient.api.dto.Ladder1v1Map; -import com.faforever.moderatorclient.api.rest.ElideRouteBuilder; +import com.faforever.commons.api.dto.Ladder1v1Map; import org.junit.Test; import static org.hamcrest.CoreMatchers.is;