Skip to content

Commit 3cdcf94

Browse files
committed
More cleanup
1 parent 6402dac commit 3cdcf94

15 files changed

Lines changed: 71 additions & 113 deletions

File tree

src/inttest/java/com/faforever/api/event/EventControllerTest.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.faforever.api.AbstractIntegrationTest;
44
import com.faforever.api.data.JsonApiMediaType;
55
import com.faforever.api.security.OAuthScope;
6-
import com.google.common.collect.Lists;
76
import org.hamcrest.Matchers;
87
import org.junit.jupiter.api.Test;
98
import org.springframework.http.HttpHeaders;
@@ -24,7 +23,7 @@ public class EventControllerTest extends AbstractIntegrationTest {
2423

2524
@Test
2625
public void singleExistingPlayerEventCanBeUpdated() throws Exception {
27-
List<EventUpdateRequest> updatedEvents = Lists.newArrayList(new EventUpdateRequest(1, "15b6c19a-6084-4e82-ada9-6c30e282191f", 10));
26+
List<EventUpdateRequest> updatedEvents = List.of(new EventUpdateRequest(1, "15b6c19a-6084-4e82-ada9-6c30e282191f", 10));
2827
mockMvc.perform(
2928
patch("/events/update")
3029
.header(HttpHeaders.CONTENT_TYPE, JsonApiMediaType.JSON_API_MEDIA_TYPE)
@@ -38,7 +37,7 @@ public void singleExistingPlayerEventCanBeUpdated() throws Exception {
3837

3938
@Test
4039
public void singleNonExistingPlayerEventCanBeCreated() throws Exception {
41-
List<EventUpdateRequest> updatedEvents = Lists.newArrayList(new EventUpdateRequest(1, "cc791f00-343c-48d4-b5b3-8900b83209c0", 10));
40+
List<EventUpdateRequest> updatedEvents = List.of(new EventUpdateRequest(1, "cc791f00-343c-48d4-b5b3-8900b83209c0", 10));
4241
mockMvc.perform(
4342
patch("/events/update")
4443
.header(HttpHeaders.CONTENT_TYPE, JsonApiMediaType.JSON_API_MEDIA_TYPE)
@@ -52,7 +51,7 @@ public void singleNonExistingPlayerEventCanBeCreated() throws Exception {
5251

5352
@Test
5453
public void multipleExistingPlayerEventsCanBeUpdated() throws Exception {
55-
List<EventUpdateRequest> updatedEvents = Lists.newArrayList(
54+
List<EventUpdateRequest> updatedEvents = List.of(
5655
new EventUpdateRequest(1, "15b6c19a-6084-4e82-ada9-6c30e282191f", 10),
5756
new EventUpdateRequest(1, "225e9b2e-ae09-4ae1-a198-eca8780b0fcd", 10)
5857
);
@@ -69,7 +68,7 @@ public void multipleExistingPlayerEventsCanBeUpdated() throws Exception {
6968

7069
@Test
7170
public void authWithoutCorrectScopeShouldFail() throws Exception {
72-
List<EventUpdateRequest> updatedEvents = Lists.newArrayList(new EventUpdateRequest(1, "15b6c19a-6084-4e82-ada9-6c30e282191f", 10));
71+
List<EventUpdateRequest> updatedEvents = List.of(new EventUpdateRequest(1, "15b6c19a-6084-4e82-ada9-6c30e282191f", 10));
7372
mockMvc.perform(
7473
patch("/events/update")
7574
.header(HttpHeaders.CONTENT_TYPE, JsonApiMediaType.JSON_API_MEDIA_TYPE)
@@ -79,7 +78,7 @@ public void authWithoutCorrectScopeShouldFail() throws Exception {
7978

8079
@Test
8180
public void nonExistingEventShouldFail() throws Exception {
82-
List<EventUpdateRequest> updatedEvents = Lists.newArrayList(new EventUpdateRequest(1, "non-existing-event-id", 10));
81+
List<EventUpdateRequest> updatedEvents = List.of(new EventUpdateRequest(1, "non-existing-event-id", 10));
8382
mockMvc.perform(
8483
patch("/events/update")
8584
.header(HttpHeaders.CONTENT_TYPE, JsonApiMediaType.JSON_API_MEDIA_TYPE)
@@ -90,7 +89,7 @@ public void nonExistingEventShouldFail() throws Exception {
9089

9190
@Test
9291
public void nonExistingPlayerShouldFail() throws Exception {
93-
List<EventUpdateRequest> updatedEvents = Lists.newArrayList(new EventUpdateRequest(-1, "15b6c19a-6084-4e82-ada9-6c30e282191f", 10));
92+
List<EventUpdateRequest> updatedEvents = List.of(new EventUpdateRequest(-1, "15b6c19a-6084-4e82-ada9-6c30e282191f", 10));
9493
mockMvc.perform(
9594
patch("/events/update")
9695
.header(HttpHeaders.CONTENT_TYPE, JsonApiMediaType.JSON_API_MEDIA_TYPE)
@@ -101,7 +100,7 @@ public void nonExistingPlayerShouldFail() throws Exception {
101100

102101
@Test
103102
public void negativeCountShouldFail() throws Exception {
104-
List<EventUpdateRequest> updatedEvents = Lists.newArrayList(new EventUpdateRequest(1, "15b6c19a-6084-4e82-ada9-6c30e282191f", -10));
103+
List<EventUpdateRequest> updatedEvents = List.of(new EventUpdateRequest(1, "15b6c19a-6084-4e82-ada9-6c30e282191f", -10));
105104
mockMvc.perform(
106105
patch("/events/update")
107106
.header(HttpHeaders.CONTENT_TYPE, JsonApiMediaType.JSON_API_MEDIA_TYPE)

src/main/java/com/faforever/api/clan/ClanService.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import java.time.Instant;
2525
import java.time.temporal.ChronoUnit;
26+
import java.util.Objects;
2627
import java.util.Set;
2728

2829
@Service
@@ -100,16 +101,16 @@ void acceptPlayerInvitationToken(String stringToken, Authentication authenticati
100101
throw new ApiException(new Error(ErrorCode.CLAN_ACCEPT_TOKEN_EXPIRE));
101102
}
102103

103-
final Integer clanId = invitation.getClan().getId();
104+
final Integer clanId = invitation.clan().id();
104105
Player player = playerService.getPlayer(authentication);
105106
Clan clan = clanRepository.findById(clanId)
106107
.orElseThrow(() -> new ApiException(new Error(ErrorCode.CLAN_NOT_EXISTS, clanId)));
107108

108-
Player newMember = playerRepository.findById(invitation.getNewMember().getId())
109-
.orElseThrow(() -> new ProgrammingError("ClanMember does not exist: " + invitation.getNewMember().getId()));
109+
Player newMember = playerRepository.findById(invitation.newMember().id())
110+
.orElseThrow(() -> new ProgrammingError("ClanMember does not exist: " + invitation.newMember().id()));
110111

111112

112-
if (player.getId() != newMember.getId()) {
113+
if (!Objects.equals(player.getId(), newMember.getId())) {
113114
throw new ApiException(new Error(ErrorCode.CLAN_ACCEPT_WRONG_PLAYER));
114115
}
115116
if (newMember.getClan() != null) {

src/main/java/com/faforever/api/clan/result/ClanResult.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
package com.faforever.api.clan.result;
22

33
import com.faforever.api.data.domain.Clan;
4-
import lombok.Data;
5-
6-
@Data
7-
public class ClanResult {
8-
private final Integer id;
9-
private final String tag;
10-
private final String name;
114

5+
public record ClanResult(Integer id, String tag, String name) {
126
public static ClanResult of(Clan clan) {
137
return new ClanResult(clan.getId(), clan.getTag(), clan.getName());
148
}

src/main/java/com/faforever/api/clan/result/InvitationResult.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
package com.faforever.api.clan.result;
22

3-
import lombok.Data;
4-
5-
@Data
6-
public class InvitationResult {
7-
private final long expire;
8-
private final ClanResult clan;
9-
private final PlayerResult newMember;
10-
3+
public record InvitationResult(
4+
long expire,
5+
ClanResult clan,
6+
PlayerResult newMember
7+
) {
118
public boolean isExpired() {
129
return expire < System.currentTimeMillis();
1310
}
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package com.faforever.api.clan.result;
22

3-
import lombok.Data;
4-
5-
@Data
6-
public class MeResult {
7-
private final PlayerResult player;
8-
private final ClanResult clan;
3+
public record MeResult(
4+
PlayerResult player,
5+
ClanResult clan
6+
) {
97
}
108

src/main/java/com/faforever/api/clan/result/PlayerResult.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
package com.faforever.api.clan.result;
22

33
import com.faforever.api.data.domain.Player;
4-
import lombok.Data;
5-
6-
@Data
7-
public class PlayerResult {
8-
private final Integer id;
9-
private final String login;
104

5+
public record PlayerResult(Integer id, String login) {
116
public static PlayerResult of(Player newMember) {
127
return new PlayerResult(newMember.getId(), newMember.getLogin());
138
}

src/main/java/com/faforever/api/deployment/LegacyFeaturedModDeploymentTask.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import com.faforever.commons.fa.ForgedAllianceExePatcher;
1111
import com.faforever.commons.mod.ModReader;
1212
import com.google.common.io.ByteStreams;
13-
import lombok.Data;
1413
import lombok.Setter;
1514
import lombok.SneakyThrows;
1615
import lombok.extern.slf4j.Slf4j;
@@ -190,9 +189,9 @@ private void updateDatabase(List<StagedFile> files, short version, String modNam
190189
updateStatus("Updating database");
191190
List<FeaturedModFile> featuredModFiles = files.stream()
192191
.map(file -> new FeaturedModFile()
193-
.setMd5(noCatch(() -> hash(file.getTargetFile().toFile(), md5())).toString())
194-
.setFileId(file.getFileId())
195-
.setName(file.getTargetFile().getFileName().toString())
192+
.setMd5(noCatch(() -> hash(file.targetFile().toFile(), md5())).toString())
193+
.setFileId(file.fileId())
194+
.setName(file.targetFile().getFileName().toString())
196195
.setVersion(version)
197196
)
198197
.toList();
@@ -234,8 +233,8 @@ private List<StagedFile> packageFiles(Path repositoryDirectory, short version, M
234233
* complete, and makes the file readable for everyone.
235234
*/
236235
private StagedFile finalizeFile(StagedFile file) {
237-
Path source = file.getTmpFile();
238-
Path target = file.getTargetFile();
236+
Path source = file.tmpFile();
237+
Path target = file.targetFile();
239238

240239
log.trace("Setting default file permission of '{}'", source);
241240
FilePermissionUtil.setDefaultFilePermission(source);
@@ -358,23 +357,23 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
358357
* Describes a file that is ready to be deployed. All files should be staged as temporary files first so they can be
359358
* renamed to their target file name in one go, thus minimizing the time of inconsistent file system state.
360359
*/
361-
@Data
362-
private class StagedFile {
360+
private record StagedFile(
363361
/**
364362
* ID of the file as stored in the database.
365363
*/
366-
private final short fileId;
364+
short fileId,
367365
/**
368366
* The staged file, already in the correct location, that is ready to be renamed.
369367
*/
370-
private final Path tmpFile;
368+
Path tmpFile,
371369
/**
372370
* The final file name and location.
373371
*/
374-
private final Path targetFile;
372+
Path targetFile,
375373
/**
376374
* Name of the file as the client will know it.
377375
*/
378-
private final String clientFileName;
376+
String clientFileName
377+
) {
379378
}
380379
}
Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
11
package com.faforever.api.event;
22

3-
import lombok.AllArgsConstructor;
4-
import lombok.Getter;
5-
import lombok.NoArgsConstructor;
6-
import lombok.Setter;
3+
import org.springframework.validation.annotation.Validated;
74

85
import javax.validation.constraints.Min;
96

10-
@Getter
11-
@Setter
12-
@NoArgsConstructor
13-
@AllArgsConstructor
14-
class EventUpdateRequest {
15-
16-
private int playerId;
17-
private String eventId;
7+
@Validated
8+
record EventUpdateRequest(
9+
int playerId,
10+
String eventId,
1811
@Min(0)
19-
private int count;
20-
12+
int count
13+
) {
2114
}

src/main/java/com/faforever/api/event/EventsController.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@ public class EventsController {
3131
@RequestMapping(value = "/update", method = RequestMethod.PATCH, produces = JsonApiMediaType.JSON_API_MEDIA_TYPE)
3232
public JsonApiDocument update(@RequestBody List<@Valid EventUpdateRequest> updateRequests) {
3333
return new JsonApiDocument(new Data<>(updateRequests.stream()
34-
.map(request -> eventsService.increment(request.getPlayerId(), request.getEventId(), request.getCount()))
34+
.map(request -> eventsService.increment(request.playerId(), request.eventId(), request.count()))
3535
.map(this::toResource)
3636
.toList()));
3737
}
3838

3939
private Resource toResource(UpdatedEventResponse updatedEventResponse) {
4040
Map<String, Object> attributes = Map.of(
41-
"eventId", updatedEventResponse.getEventId(),
42-
"currentCount", updatedEventResponse.getCurrentCount()
41+
"eventId", updatedEventResponse.eventId(),
42+
"currentCount", updatedEventResponse.currentCount()
4343
);
4444

45-
return new Resource("updatedEvent", String.valueOf(updatedEventResponse.getId()),
45+
return new Resource("updatedEvent", String.valueOf(updatedEventResponse.id()),
4646
attributes, null, null, null);
4747
}
4848
}
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
package com.faforever.api.event;
22

3-
import lombok.Data;
4-
5-
@Data
6-
class UpdatedEventResponse {
7-
8-
private final int id;
9-
private final String eventId;
10-
private final Integer currentCount;
113

4+
record UpdatedEventResponse(
5+
int id,
6+
String eventId,
7+
Integer currentCount
8+
) {
129
}

0 commit comments

Comments
 (0)