Skip to content

Commit

Permalink
Merge branch 'release/0.2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Brutus5000 committed May 17, 2018
2 parents 8cf264c + 5dc753a commit 088193d
Show file tree
Hide file tree
Showing 13 changed files with 428 additions and 84 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.faforever</groupId>
<artifactId>faf-moderator-client</artifactId>
<version>0.2.1</version>
<version>0.2.2</version>
<packaging>jar</packaging>

<name>faf-moderator-client</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.faforever.moderatorclient.api.domain;

import com.faforever.commons.api.dto.BanInfo;
import com.faforever.commons.api.dto.BanRevokeData;
import com.faforever.commons.api.dto.Player;
import com.faforever.moderatorclient.api.ElideRouteBuilder;
import com.faforever.moderatorclient.api.FafApiCommunicationService;
import com.faforever.moderatorclient.mapstruct.BanInfoMapper;
import com.faforever.moderatorclient.mapstruct.BanRevokeDataMapper;
import com.faforever.moderatorclient.ui.domain.BanInfoFX;
import com.faforever.moderatorclient.ui.domain.BanRevokeDataFX;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;

@Service
@Slf4j
public class BanService {

private final BanInfoMapper banInfoMapper;
private final BanRevokeDataMapper banRevokeDataMapper;
private final FafApiCommunicationService fafApi;

public BanService(BanInfoMapper banInfoMapper, BanRevokeDataMapper banRevokeDataMapper, FafApiCommunicationService fafApi) {
this.banInfoMapper = banInfoMapper;
this.banRevokeDataMapper = banRevokeDataMapper;
this.fafApi = fafApi;
}

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 BanRevokeDataFX banRevokeDataFX) {
BanRevokeData banRevokeData = banRevokeDataMapper.map(banRevokeDataFX);
log.debug("Revoking ban with id: ", banRevokeData.getBan().getId());
banRevokeData.setAuthor(fafApi.getSelfPlayer());
ElideRouteBuilder<Player> routeBuilder = ElideRouteBuilder.of(Player.class)
.id(banRevokeData.getBan().getId())
.relationship("banRevokeData");

return (BanRevokeData) fafApi.postRelationship(routeBuilder, banRevokeData);
}

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).getId();
}

public CompletableFuture<List<BanInfoFX>> getAllBans() {
return CompletableFuture.supplyAsync(() -> {
List<BanInfo> banInfos = fafApi.getAll(ElideRouteBuilder.of(BanInfo.class)
.addInclude("player")
.addInclude("author")
.addInclude("banRevokeData")
.addInclude("banRevokeData.author")
);
return banInfos.stream().map(banInfoMapper::map).collect(Collectors.toList());
});
}

public BanInfoFX getBanInfoById(String banInfoId) {
log.debug("Search for ban id: " + banInfoId);
ElideRouteBuilder<BanInfo> routeBuilder = ElideRouteBuilder.of(BanInfo.class)
.id(banInfoId)
.addInclude("player")
.addInclude("author");
return banInfoMapper.map(fafApi.getOne(routeBuilder));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
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 com.faforever.moderatorclient.mapstruct.FeaturedModMapper;
import com.faforever.moderatorclient.mapstruct.PlayerMapper;
import com.faforever.moderatorclient.mapstruct.TeamkillMapper;
import com.faforever.moderatorclient.mapstruct.UserNoteMapper;
import com.faforever.moderatorclient.ui.domain.FeaturedModFX;
import com.faforever.moderatorclient.ui.domain.PlayerFX;
import com.faforever.moderatorclient.ui.domain.TeamkillFX;
import com.faforever.moderatorclient.ui.domain.UserNoteFX;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Service;
Expand All @@ -18,20 +24,14 @@
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, PlayerMapper playerMapper, BanInfoMapper banInfoMapper, BanRevokeDataMapper banRevokeDataMapper, GamePlayerStatsMapper gamePlayerStatsMapper, FeaturedModMapper featuredModMapper, UserNoteMapper userNoteMapper, TeamkillMapper teamkillMapper) {
public UserService(FafApiCommunicationService fafApi, PlayerMapper playerMapper, 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;
Expand Down Expand Up @@ -64,6 +64,7 @@ private ElideRouteBuilder addModeratorIncludes(@NotNull ElideRouteBuilder builde
public List<PlayerFX> findLatestRegistrations() {
log.debug("Searching for latest registrations");
ElideRouteBuilder<Player> routeBuilder = ElideRouteBuilder.of(Player.class)
.addInclude("bans")
.sort("id", false)
.pageSize(50);
addModeratorIncludes(routeBuilder);
Expand Down Expand Up @@ -124,6 +125,7 @@ public List<TeamkillFX> findLatestTeamkills() {
log.debug("Searching for latest teamkills ");
ElideRouteBuilder<Teamkill> routeBuilder = ElideRouteBuilder.of(Teamkill.class)
.addInclude("teamkiller")
.addInclude("teamkiller.bans")
.addInclude("victim")
.sort("id", false);

Expand All @@ -144,30 +146,6 @@ public List<TeamkillFX> findTeamkillsByUserId(@NotNull String userId) {
return teamkillMapper.map(result);
}

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 BanRevokeDataFX banRevokeDataFX) {
BanRevokeData banRevokeData = banRevokeDataMapper.map(banRevokeDataFX);
log.debug("Revoking ban with id: ", banRevokeData.getBan().getId());
banRevokeData.setAuthor(fafApi.getSelfPlayer());
ElideRouteBuilder<Player> routeBuilder = ElideRouteBuilder.of(Player.class)
.id(banRevokeData.getBan().getId())
.relationship("banRevokeData");

return (BanRevokeData) fafApi.postRelationship(routeBuilder, banRevokeData);
}

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).getId();
}

public List<GamePlayerStats> getLastHundredPlayedGamesByFeaturedMod(@NotNull String userId, int page, FeaturedModFX featuredModFX) {
log.debug("Searching for games played by player id: {}", userId);
ElideRouteBuilder<GamePlayerStats> routeBuilder = ElideRouteBuilder.of(GamePlayerStats.class)
Expand Down Expand Up @@ -224,13 +202,4 @@ 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<BanInfo> routeBuilder = ElideRouteBuilder.of(BanInfo.class)
.id(banInfoId)
.addInclude("player")
.addInclude("author");
return banInfoMapper.map(fafApi.getOne(routeBuilder));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
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.api.domain.BanService;
import com.faforever.moderatorclient.mapstruct.PlayerMapper;
import com.faforever.moderatorclient.ui.domain.BanInfoFX;
import com.faforever.moderatorclient.ui.domain.BanRevokeDataFX;
import com.faforever.moderatorclient.ui.domain.PlayerFX;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
Expand Down Expand Up @@ -37,7 +38,7 @@
@Slf4j
public class BanInfoController implements Controller<Pane> {
private final FafApiCommunicationService fafApi;
private final UserService userService;
private final BanService banService;
private final PlayerMapper playerMapper;
public GridPane root;
public TextField affectedUserTextField;
Expand All @@ -52,13 +53,14 @@ public class BanInfoController implements Controller<Pane> {
public RadioButton chatOnlyBanRadioButton;
public RadioButton globalBanRadioButton;
public Button revokeButton;
public Label userLabel;
@Getter
private BanInfoFX banInfo;
private Consumer<BanInfoFX> postedListener;

public BanInfoController(FafApiCommunicationService fafApi, UserService userService, PlayerMapper playerMapper) {
public BanInfoController(FafApiCommunicationService fafApi, BanService banService, PlayerMapper playerMapper) {
this.fafApi = fafApi;
this.userService = userService;
this.banService = banService;
this.playerMapper = playerMapper;
}

Expand All @@ -79,8 +81,8 @@ public void setBanInfo(BanInfoFX banInfo) {
this.banInfo = banInfo;

if (banInfo.getId() != null) {
affectedUserTextField.setText(banInfo.getPlayer().toString());
Optional.ofNullable(banInfo.getAuthor()).ifPresent(author -> banAuthorTextField.setText(author.toString()));
affectedUserTextField.setText(banInfo.getPlayer().representationProperty().get());
Optional.ofNullable(banInfo.getAuthor()).ifPresent(author -> banAuthorTextField.setText(author.representationProperty().get()));
banReasonTextField.setText(banInfo.getReason());

revocationReasonTextField.setDisable(false);
Expand All @@ -97,7 +99,15 @@ public void setBanInfo(BanInfoFX banInfo) {

chatOnlyBanRadioButton.setSelected(banInfo.getLevel() == BanLevel.CHAT);
globalBanRadioButton.setSelected(banInfo.getLevel() == BanLevel.GLOBAL);

} else {
PlayerFX player = banInfo.getPlayer();
if (player != null) {
affectedUserTextField.setText(player.representationProperty().get());
} else {
affectedUserTextField.setEditable(true);
affectedUserTextField.setDisable(false);
userLabel.setText("Affected User ID");
}
}
}

Expand All @@ -108,6 +118,11 @@ public void onSave() {
return;
}
ZoneId zoneId = ZoneOffset.systemDefault();
if (banInfo.getPlayer() == null) {
PlayerFX playerFX = new PlayerFX();
playerFX.setId(affectedUserTextField.getText());
banInfo.setPlayer(playerFX);
}

banInfo.setReason(banReasonTextField.getText());
banInfo.setExpiresAt(temporaryBanRadioButton.isSelected() ?
Expand All @@ -116,21 +131,29 @@ public void onSave() {

if (banInfo.getId() == null) {
log.debug("Creating ban for player '{}' with reason: {}", banInfo.getPlayer().toString(), banReasonTextField.getText());
String newBanId = userService.createBan(banInfo);
BanInfoFX loadedBanInfo = userService.getBanInfoById(newBanId);
String newBanId = banService.createBan(banInfo);
BanInfoFX loadedBanInfo = banService.getBanInfoById(newBanId);
if (postedListener != null) {
postedListener.accept(loadedBanInfo);
}
} else {
log.debug("Updating ban id '{}'", banInfo.getId());
userService.patchBanInfo(banInfo);
banService.patchBanInfo(banInfo);
}
close();
}

private boolean validate() {
List<String> validationErrors = new ArrayList<>();

if (banInfo.getPlayer() == null) {
try {
Integer.parseInt(affectedUserTextField.getText());
} catch (Exception e) {
validationErrors.add("You must specify an affected user");
}
}

if (StringUtils.isBlank(banReasonTextField.getText())) {
validationErrors.add("No ban reason is given.");
}
Expand Down Expand Up @@ -184,7 +207,7 @@ public void onRevoke() {
.setAuthor(playerMapper.map(fafApi.getSelfPlayer()))
.setReason(revocationReason);

userService.revokeBan(banRevokeData);
banService.revokeBan(banRevokeData);
close();
}

Expand Down
Loading

0 comments on commit 088193d

Please sign in to comment.