Skip to content

Commit 04ca187

Browse files
Sheikah45Brutus5000
authored andcommitted
Add new MapPoolAssignment
Resolve MapPool->MapVersion relation into new entity
1 parent 28128cc commit 04ca187

6 files changed

Lines changed: 105 additions & 31 deletions

File tree

‎.github/workflows/build.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Build
22
on: [push]
33
env:
44
FLYWAY_VERSION: 7.5.4
5-
FAF_DB_VERSION: v111
5+
FAF_DB_VERSION: v112
66
jobs:
77
test:
88
runs-on: ubuntu-latest

‎src/inttest/java/com/faforever/api/data/MapPoolElideTest.java‎

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,36 @@
1616
@Sql(executionPhase = ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:sql/prepDefaultData.sql")
1717
@Sql(executionPhase = ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:sql/prepMapData.sql")
1818
public class MapPoolElideTest extends AbstractIntegrationTest {
19-
private static final String NEW_LADDER_MAP_BODY = "{\"data\":[{\"type\":\"mapVersion\",\"id\":\"2\"}]}";
19+
private static final String NEW_LADDER_MAP_BODY = """
20+
{
21+
"data": {
22+
"type": "mapPoolAssignment",
23+
"attributes": {
24+
"weight": 1,
25+
"mapParams": "{\\"type\\": \\"none\\"}"
26+
},
27+
"relationships": {
28+
"mapPool": {
29+
"data": {
30+
"type": "mapPool",
31+
"id": "1"
32+
}
33+
},
34+
"mapVersion": {
35+
"data": {
36+
"type": "mapVersion",
37+
"id": "1"
38+
}
39+
}
40+
}
41+
}
42+
}""";
43+
2044

2145
@Test
2246
public void cannotCreateMapPoolItemWithoutScope() throws Exception {
2347
mockMvc.perform(
24-
post("/data/mapPool/1/relationships/mapVersions")
48+
post("/data/mapPoolAssignment")
2549
.with(getOAuthTokenWithTestUser(NO_SCOPE, GroupPermission.ROLE_WRITE_MATCHMAKER_MAP))
2650
.header(HttpHeaders.CONTENT_TYPE, JsonApiMediaType.JSON_API_MEDIA_TYPE)
2751
.content(NEW_LADDER_MAP_BODY)) // magic value from prepMapData.sql
@@ -31,7 +55,7 @@ public void cannotCreateMapPoolItemWithoutScope() throws Exception {
3155
@Test
3256
public void cannotCreateMapPoolItemWithoutRole() throws Exception {
3357
mockMvc.perform(
34-
post("/data/mapPool/1/relationships/mapVersions")
58+
post("/data/mapPoolAssignment")
3559
.with(getOAuthTokenWithTestUser(OAuthScope._ADMINISTRATIVE_ACTION, NO_AUTHORITIES))
3660
.header(HttpHeaders.CONTENT_TYPE, JsonApiMediaType.JSON_API_MEDIA_TYPE)
3761
.content(NEW_LADDER_MAP_BODY)) // magic value from prepMapData.sql
@@ -41,37 +65,34 @@ public void cannotCreateMapPoolItemWithoutRole() throws Exception {
4165
@Test
4266
public void canCreateMapPoolItemWithScopeAndRole() throws Exception {
4367
mockMvc.perform(
44-
post("/data/mapPool/1/relationships/mapVersions")
68+
post("/data/mapPoolAssignment")
4569
.with(getOAuthTokenWithTestUser(OAuthScope._ADMINISTRATIVE_ACTION, GroupPermission.ROLE_WRITE_MATCHMAKER_MAP))
4670
.header(HttpHeaders.CONTENT_TYPE, JsonApiMediaType.JSON_API_MEDIA_TYPE)
4771
.content(NEW_LADDER_MAP_BODY)) // magic value from prepMapData.sql
48-
.andExpect(status().isNoContent());
72+
.andExpect(status().isCreated());
4973
}
5074

5175
@Test
5276
public void canDeleteMapPoolItemWithScopeAndRole() throws Exception {
5377
mockMvc.perform(
54-
delete("/data/mapPool/1/relationships/mapVersions/1")
55-
.with(getOAuthTokenWithTestUser(OAuthScope._ADMINISTRATIVE_ACTION, GroupPermission.ROLE_WRITE_MATCHMAKER_MAP))
56-
.content(NEW_LADDER_MAP_BODY)) // magic value from prepMapData.sql
78+
delete("/data/mapPoolAssignment/1")
79+
.with(getOAuthTokenWithTestUser(OAuthScope._ADMINISTRATIVE_ACTION, GroupPermission.ROLE_WRITE_MATCHMAKER_MAP)))
5780
.andExpect(status().isNoContent());
5881
}
5982

6083
@Test
6184
public void cannotDeleteMapPoolItemWithoutScope() throws Exception {
6285
mockMvc.perform(
63-
delete("/data/mapPool/1/relationships/mapVersions/1")
64-
.with(getOAuthTokenWithTestUser(NO_SCOPE, GroupPermission.ROLE_WRITE_MATCHMAKER_MAP))
65-
.content(NEW_LADDER_MAP_BODY)) // magic value from prepMapData.sql
86+
delete("/data/mapPoolAssignment/1")
87+
.with(getOAuthTokenWithTestUser(NO_SCOPE, GroupPermission.ROLE_WRITE_MATCHMAKER_MAP)))
6688
.andExpect(status().isForbidden());
6789
}
6890

6991
@Test
7092
public void cannotDeleteMapPoolItemWithoutRole() throws Exception {
7193
mockMvc.perform(
72-
delete("/data/mapPool/1")
73-
.with(getOAuthTokenWithTestUser(OAuthScope._ADMINISTRATIVE_ACTION, NO_AUTHORITIES))
74-
.content(NEW_LADDER_MAP_BODY)) // magic value from prepMapData.sql
94+
delete("/data/mapPoolAssignment/1")
95+
.with(getOAuthTokenWithTestUser(OAuthScope._ADMINISTRATIVE_ACTION, NO_AUTHORITIES)))
7596
.andExpect(status().isForbidden());
7697
}
7798
}

‎src/inttest/resources/sql/prepMapData.sql‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ INSERT INTO matchmaker_queue_map_pool (matchmaker_queue_id, map_pool_id, min_rat
2323
(1, 4, 1300, 1800),
2424
(1, 5, 1800, null);
2525

26-
INSERT INTO map_pool_map_version (map_pool_id, map_version_id) VALUES
27-
(1,1),
28-
(2,2);
26+
INSERT INTO map_pool_map_version (id, map_pool_id, map_version_id, map_params, weight) VALUES
27+
(1, 1, 1, null, 1),
28+
(2, 1, null, '{"type": "neroxis", "size": 512, "spawns": 2, "version": "1.4.3"}', 1),
29+
(3, 2, 2, null, 1);

‎src/main/java/com/faforever/api/data/domain/MapPool.java‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
import com.yahoo.elide.annotation.UpdatePermission;
88
import lombok.Setter;
99

10+
import javax.persistence.CascadeType;
1011
import javax.persistence.Entity;
11-
import javax.persistence.JoinColumn;
12-
import javax.persistence.JoinTable;
13-
import javax.persistence.ManyToMany;
12+
import javax.persistence.OneToMany;
1413
import javax.persistence.OneToOne;
1514
import javax.persistence.Table;
1615
import javax.validation.constraints.NotNull;
@@ -26,7 +25,7 @@
2625
public class MapPool extends AbstractEntity {
2726
private String name;
2827
private MatchmakerQueueMapPool matchmakerQueueMapPool;
29-
private Set<MapVersion> mapVersions;
28+
private Set<MapPoolAssignment> mapPoolAssignments;
3029

3130
@NotNull
3231
public String getName() {
@@ -38,13 +37,8 @@ public MatchmakerQueueMapPool getMatchmakerQueueMapPool() {
3837
return matchmakerQueueMapPool;
3938
}
4039

41-
@ManyToMany
42-
@JoinTable(name = "map_pool_map_version",
43-
joinColumns = @JoinColumn(name = "map_pool_id"),
44-
inverseJoinColumns = @JoinColumn(name = "map_version_id")
45-
)
46-
@NotNull
47-
public Set<MapVersion> getMapVersions() {
48-
return mapVersions;
40+
@OneToMany(mappedBy = "mapPool", cascade = CascadeType.ALL, orphanRemoval = true)
41+
public Set<MapPoolAssignment> getMapPoolAssignments() {
42+
return mapPoolAssignments;
4943
}
5044
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.faforever.api.data.domain;
2+
3+
import com.faforever.api.security.elide.permission.WriteMatchmakerMapCheck;
4+
import com.yahoo.elide.annotation.CreatePermission;
5+
import com.yahoo.elide.annotation.DeletePermission;
6+
import com.yahoo.elide.annotation.Include;
7+
import com.yahoo.elide.annotation.UpdatePermission;
8+
import lombok.Setter;
9+
import org.jetbrains.annotations.NotNull;
10+
import org.json.JSONObject;
11+
12+
import javax.persistence.Column;
13+
import javax.persistence.Entity;
14+
15+
import javax.persistence.GeneratedValue;
16+
import javax.persistence.GenerationType;
17+
import javax.persistence.Id;
18+
import javax.persistence.JoinColumn;
19+
20+
import javax.persistence.OneToOne;
21+
import javax.persistence.Table;
22+
23+
24+
@Entity
25+
@Setter
26+
@Table(name = "map_pool_map_version")
27+
@Include(rootLevel = true, type = "mapPoolAssignment")
28+
@CreatePermission(expression = WriteMatchmakerMapCheck.EXPRESSION)
29+
@UpdatePermission(expression = WriteMatchmakerMapCheck.EXPRESSION)
30+
@DeletePermission(expression = WriteMatchmakerMapCheck.EXPRESSION)
31+
public class MapPoolAssignment extends AbstractEntity {
32+
private MapPool mapPool;
33+
private MapVersion mapVersion;
34+
private Integer weight;
35+
private String mapParams;
36+
37+
@OneToOne
38+
@JoinColumn(name = "map_pool_id")
39+
@NotNull
40+
public MapPool getMapPool() {
41+
return mapPool;
42+
}
43+
44+
@OneToOne
45+
@JoinColumn(name = "map_version_id")
46+
public MapVersion getMapVersion() {
47+
return mapVersion;
48+
}
49+
50+
@Column(name = "weight")
51+
@NotNull
52+
public Integer getWeight() {
53+
return weight;
54+
}
55+
56+
@Column(name = "map_params")
57+
public String getMapParams() { return mapParams; }
58+
}

‎src/main/resources/config/application.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ faf-api:
99
challonge:
1010
key: ${CHALLONGE_KEY:}
1111
database:
12-
schema-version: ${DATABASE_SCHEMA_VERSION:111}
12+
schema-version: ${DATABASE_SCHEMA_VERSION:112}
1313
mautic:
1414
base-url: ${MAUTIC_BASE_URL:false}
1515
client-id: ${MAUTIC_CLIENT_ID:false}

0 commit comments

Comments
 (0)