Skip to content

Commit 4ea3228

Browse files
committed
Describe support type in generations endpoint
This commit provides the support for a particular generation. Besides, the default support policy, a generation can be in extended support mode (previously lastMinor), or with no support at all. Closes gh-32
1 parent 930de65 commit 4ea3228

File tree

9 files changed

+94
-56
lines changed

9 files changed

+94
-56
lines changed

src/main/java/io/spring/projectapi/github/ProjectGeneration.java

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.fasterxml.jackson.annotation.JsonCreator.Mode;
2525
import com.fasterxml.jackson.annotation.JsonFormat;
2626
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
27+
import com.fasterxml.jackson.annotation.JsonProperty;
2728

2829
/**
2930
* Java representation of the {@code project generation} type as defined in
@@ -54,22 +55,22 @@ public static class Generation {
5455
@JsonFormat(pattern = "yyyy-MM")
5556
private final YearMonth initialRelease;
5657

58+
private final SupportType support;
59+
5760
@JsonFormat(pattern = "yyyy-MM")
5861
private final YearMonth ossSupportEnd;
5962

6063
@JsonFormat(pattern = "yyyy-MM")
6164
private final YearMonth enterpriseSupportEnd;
6265

63-
private final boolean lastMinor;
64-
6566
@JsonCreator(mode = Mode.PROPERTIES)
66-
public Generation(String generation, YearMonth initialRelease, YearMonth ossSupportEnd,
67-
YearMonth enterpriseSupportEnd, boolean lastMinor) {
67+
public Generation(String generation, YearMonth initialRelease, SupportType support, YearMonth ossSupportEnd,
68+
YearMonth enterpriseSupportEnd) {
6869
this.generation = generation;
6970
this.initialRelease = initialRelease;
71+
this.support = (support != null) ? support : SupportType.DEFAULT;
7072
this.ossSupportEnd = ossSupportEnd;
7173
this.enterpriseSupportEnd = enterpriseSupportEnd;
72-
this.lastMinor = lastMinor;
7374
}
7475

7576
/**
@@ -88,6 +89,14 @@ public YearMonth getInitialRelease() {
8889
return this.initialRelease;
8990
}
9091

92+
/**
93+
* Return the {@link SupportType}.
94+
* @return the type of support
95+
*/
96+
public SupportType getSupport() {
97+
return this.support;
98+
}
99+
91100
/**
92101
* Return the end of the Open Source support or {@code null} if this generation
93102
* has no support.
@@ -106,9 +115,30 @@ public YearMonth getEnterpriseSupportEnd() {
106115
return this.enterpriseSupportEnd;
107116
}
108117

109-
public boolean isLastMinor() {
110-
return this.lastMinor;
111-
}
118+
}
119+
120+
/**
121+
* Describe the type of support.
122+
*/
123+
public enum SupportType {
124+
125+
/**
126+
* Not supported.
127+
*/
128+
@JsonProperty("none")
129+
NONE,
130+
131+
/**
132+
* Default support.
133+
*/
134+
@JsonProperty("default")
135+
DEFAULT,
136+
137+
/**
138+
* Extended support.
139+
*/
140+
@JsonProperty("extended")
141+
EXTENDED
112142

113143
}
114144

src/main/java/io/spring/projectapi/web/generation/Generation.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,20 @@ public class Generation {
4141
@JsonFormat(pattern = "yyyy-MM-dd")
4242
private final LocalDate initialReleaseDate;
4343

44+
private String support;
45+
4446
@JsonFormat(pattern = "yyyy-MM-dd")
4547
private final LocalDate ossSupportEndDate;
4648

4749
@JsonFormat(pattern = "yyyy-MM-dd")
4850
private final LocalDate commercialSupportEndDate;
4951

5052
@JsonCreator
51-
public Generation(String name, YearMonth initialReleaseDate, YearMonth ossSupportEndDate,
53+
public Generation(String name, YearMonth initialReleaseDate, String support, YearMonth ossSupportEndDate,
5254
YearMonth commercialSupportEndDate) {
5355
this.name = name;
5456
this.initialReleaseDate = initialReleaseDate.atEndOfMonth();
57+
this.support = support;
5558
this.ossSupportEndDate = (ossSupportEndDate != null) ? ossSupportEndDate.atEndOfMonth() : null;
5659
this.commercialSupportEndDate = (commercialSupportEndDate != null) ? commercialSupportEndDate.atEndOfMonth()
5760
: null;
@@ -65,6 +68,10 @@ public LocalDate getInitialReleaseDate() {
6568
return this.initialReleaseDate;
6669
}
6770

71+
public String getSupport() {
72+
return this.support;
73+
}
74+
6875
public LocalDate getOssSupportEndDate() {
6976
return this.ossSupportEndDate;
7077
}

src/main/java/io/spring/projectapi/web/generation/GenerationsController.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package io.spring.projectapi.web.generation;
1818

1919
import java.util.List;
20+
import java.util.Locale;
2021

2122
import io.spring.projectapi.ProjectRepository;
2223
import io.spring.projectapi.github.ProjectGeneration;
@@ -56,11 +57,7 @@ public GenerationsController(ProjectRepository projectRepository) {
5657
@GetMapping
5758
public CollectionModel<EntityModel<Generation>> generations(@PathVariable String id) {
5859
ProjectGeneration projectGeneration = this.projectRepository.getProjectGenerations(id);
59-
String supportPolicy = this.projectRepository.getProjectSupportPolicy(id);
60-
List<Generation> generations = projectGeneration.getGenerations()
61-
.stream()
62-
.map((generation) -> asGeneration(generation, supportPolicy))
63-
.toList();
60+
List<Generation> generations = projectGeneration.getGenerations().stream().map(this::asGeneration).toList();
6461
CollectionModel<EntityModel<Generation>> model = CollectionModel
6562
.of(generations.stream().map((generation) -> asModel(id, generation)).toList());
6663
model.add(linkToProject(id));
@@ -70,11 +67,7 @@ public CollectionModel<EntityModel<Generation>> generations(@PathVariable String
7067
@GetMapping("/{name}")
7168
public EntityModel<Generation> generation(@PathVariable String id, @PathVariable String name) {
7269
ProjectGeneration projectGeneration = this.projectRepository.getProjectGenerations(id);
73-
String supportPolicy = this.projectRepository.getProjectSupportPolicy(id);
74-
List<Generation> generations = projectGeneration.getGenerations()
75-
.stream()
76-
.map((generation) -> asGeneration(generation, supportPolicy))
77-
.toList();
70+
List<Generation> generations = projectGeneration.getGenerations().stream().map(this::asGeneration).toList();
7871
Generation generation = generations.stream()
7972
.filter((candidate) -> candidate.getName().equals(name))
8073
.findFirst()
@@ -83,8 +76,9 @@ public EntityModel<Generation> generation(@PathVariable String id, @PathVariable
8376
return asModel(id, generation);
8477
}
8578

86-
private Generation asGeneration(ProjectGeneration.Generation generation, String supportPolicy) {
87-
return new Generation(generation.getGeneration(), generation.getInitialRelease(), generation.getOssSupportEnd(),
79+
private Generation asGeneration(ProjectGeneration.Generation generation) {
80+
return new Generation(generation.getGeneration(), generation.getInitialRelease(),
81+
generation.getSupport().name().toLowerCase(Locale.ROOT), generation.getOssSupportEnd(),
8882
generation.getEnterpriseSupportEnd());
8983
}
9084

src/test/java/io/spring/projectapi/github/GithubProjectRepositoryTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.Map;
2323

2424
import io.spring.projectapi.github.Project.Status;
25+
import io.spring.projectapi.github.ProjectGeneration.SupportType;
2526
import org.junit.jupiter.api.BeforeEach;
2627
import org.junit.jupiter.api.Test;
2728

@@ -150,9 +151,9 @@ private Map<String, Project> getProjects(String project) {
150151

151152
private Map<String, ProjectGeneration> getProjectSupports(String project) {
152153
ProjectGeneration.Generation generation1 = new ProjectGeneration.Generation("2.2.x", YearMonth.parse("2020-02"),
153-
null, null, false);
154+
SupportType.NONE, null, null);
154155
ProjectGeneration.Generation generation2 = new ProjectGeneration.Generation("2.3.x", YearMonth.parse("2021-02"),
155-
null, null, false);
156+
SupportType.NONE, null, null);
156157
ProjectGeneration support = new ProjectGeneration(List.of(generation1, generation2));
157158
return Map.of(project, support);
158159
}

src/test/java/io/spring/projectapi/github/GithubQueriesTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
2828
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
2929
import io.spring.projectapi.github.Project.Status;
30+
import io.spring.projectapi.github.ProjectGeneration.SupportType;
3031
import org.hamcrest.text.MatchesPattern;
3132
import org.junit.jupiter.api.BeforeEach;
3233
import org.junit.jupiter.api.Test;
@@ -209,9 +210,9 @@ private Map<String, Project> getProjects() {
209210

210211
private Map<String, ProjectGeneration> getProjectSupports() {
211212
ProjectGeneration.Generation generation1 = new ProjectGeneration.Generation("2.2.x", YearMonth.parse("2020-02"),
212-
null, null, false);
213+
SupportType.NONE, null, null);
213214
ProjectGeneration.Generation generation2 = new ProjectGeneration.Generation("2.3.x", YearMonth.parse("2021-02"),
214-
null, null, false);
215+
SupportType.NONE, null, null);
215216
ProjectGeneration support = new ProjectGeneration(List.of(generation1, generation2));
216217
return Map.of("spring-boot", support);
217218
}

src/test/java/io/spring/projectapi/github/ProjectGenerationJsonTests.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.time.YearMonth;
2020

21+
import io.spring.projectapi.github.ProjectGeneration.SupportType;
2122
import org.junit.jupiter.api.Test;
2223

2324
import org.springframework.beans.factory.annotation.Autowired;
@@ -32,6 +33,7 @@
3233
*
3334
* @author Madhura Bhave
3435
* @author Phillip Webb
36+
* @author Stephane Nicoll
3537
*/
3638
@JsonTest
3739
@AutoConfigureWebClient
@@ -42,13 +44,27 @@ class ProjectGenerationJsonTests {
4244

4345
@Test
4446
void readObjectReadsJson() throws Exception {
45-
ProjectGeneration projectGeneration = this.json.readObject("project-generations.json");
46-
assertThat(projectGeneration.getGenerations().get(0).getGeneration()).isEqualTo("1.5.x");
47-
assertThat(projectGeneration.getGenerations().get(0).getInitialRelease()).isEqualTo(YearMonth.parse("2017-01"));
48-
assertThat(projectGeneration.getGenerations().get(0).getOssSupportEnd()).isEqualTo(YearMonth.parse("2019-08"));
49-
assertThat(projectGeneration.getGenerations().get(0).getEnterpriseSupportEnd())
50-
.isEqualTo(YearMonth.parse("2020-11"));
51-
assertThat(projectGeneration.getGenerations().get(0).isLastMinor()).isTrue();
47+
ProjectGeneration projectGeneration = this.json.readObject("project-generations-content.json");
48+
assertThat(projectGeneration.getGenerations()
49+
.stream()
50+
.filter((candidate) -> candidate.getGeneration().equals("1.5.x"))).singleElement()
51+
.satisfies((generation) -> {
52+
assertThat(generation.getGeneration()).isEqualTo("1.5.x");
53+
assertThat(generation.getSupport()).isEqualTo(SupportType.DEFAULT);
54+
assertThat(generation.getInitialRelease()).isEqualTo(YearMonth.parse("2017-01"));
55+
assertThat(generation.getOssSupportEnd()).isEqualTo(YearMonth.parse("2019-08"));
56+
assertThat(generation.getEnterpriseSupportEnd()).isEqualTo(YearMonth.parse("2020-11"));
57+
});
58+
assertThat(projectGeneration.getGenerations()
59+
.stream()
60+
.filter((candidate) -> candidate.getGeneration().equals("2.7.x"))).singleElement()
61+
.satisfies((generation) -> {
62+
assertThat(generation.getGeneration()).isEqualTo("2.7.x");
63+
assertThat(generation.getSupport()).isEqualTo(SupportType.EXTENDED);
64+
assertThat(generation.getInitialRelease()).isEqualTo(YearMonth.parse("2022-05"));
65+
assertThat(generation.getOssSupportEnd()).isEqualTo(YearMonth.parse("2023-06"));
66+
assertThat(generation.getEnterpriseSupportEnd()).isEqualTo(YearMonth.parse("2029-06"));
67+
});
5268
}
5369

5470
}

src/test/java/io/spring/projectapi/web/generation/GenerationsControllerTests.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import io.spring.projectapi.ProjectRepository;
2424
import io.spring.projectapi.github.NoSuchGithubProjectException;
2525
import io.spring.projectapi.github.ProjectGeneration;
26+
import io.spring.projectapi.github.ProjectGeneration.SupportType;
2627
import io.spring.projectapi.test.WebApiTests;
2728
import org.junit.jupiter.api.Test;
2829

@@ -75,6 +76,7 @@ void generationsReturnsGenerations() throws Exception {
7576
.andExpect(jsonPath("$._embedded.generations.length()").value("3"))
7677
.andExpect(generationJsonPath(0, "name").value("1.0.x"))
7778
.andExpect(generationJsonPath(0, "initialReleaseDate").value("2015-03-31"))
79+
.andExpect(generationJsonPath(0, "support").value("none"))
7880
.andExpect(generationJsonPath(0, "ossSupportEndDate").doesNotExist())
7981
.andExpect(generationJsonPath(0, "commercialSupportEndDate").doesNotExist())
8082
.andExpect(generationJsonPath(0, "_links.self.href")
@@ -83,6 +85,7 @@ void generationsReturnsGenerations() throws Exception {
8385

8486
.andExpect(generationJsonPath(1, "name").value("2.2.x"))
8587
.andExpect(generationJsonPath(1, "initialReleaseDate").value("2020-02-29"))
88+
.andExpect(generationJsonPath(1, "support").value("extended"))
8689
.andExpect(generationJsonPath(1, "ossSupportEndDate").value("2021-03-31"))
8790
.andExpect(generationJsonPath(1, "commercialSupportEndDate").value("2021-03-31"))
8891
.andExpect(generationJsonPath(1, "_links.self.href")
@@ -91,6 +94,7 @@ void generationsReturnsGenerations() throws Exception {
9194

9295
.andExpect(generationJsonPath(2, "name").value("2.1.x"))
9396
.andExpect(generationJsonPath(2, "initialReleaseDate").value("2020-01-31"))
97+
.andExpect(generationJsonPath(2, "support").value("default"))
9498
.andExpect(generationJsonPath(2, "ossSupportEndDate").value("2021-03-31"))
9599
.andExpect(generationJsonPath(2, "commercialSupportEndDate").value("2022-03-31"))
96100
.andExpect(generationJsonPath(2, "_links.self.href")
@@ -133,18 +137,20 @@ void generationWhenNotFoundReturns404() throws Exception {
133137

134138
private ProjectGeneration getProjectGenerations() {
135139
List<ProjectGeneration.Generation> generations = new ArrayList<>();
136-
generations.add(new ProjectGeneration.Generation("1.0.x", YearMonth.parse("2015-03"), null, null, false));
137-
generations.add(new ProjectGeneration.Generation("2.2.x", YearMonth.parse("2020-02"),
138-
YearMonth.parse("2021-03"), YearMonth.parse("2021-03"), true));
139-
generations.add(new ProjectGeneration.Generation("2.1.x", YearMonth.parse("2020-01"),
140-
YearMonth.parse("2021-03"), YearMonth.parse("2022-03"), false));
140+
generations
141+
.add(new ProjectGeneration.Generation("1.0.x", YearMonth.parse("2015-03"), SupportType.NONE, null, null));
142+
generations.add(new ProjectGeneration.Generation("2.2.x", YearMonth.parse("2020-02"), SupportType.EXTENDED,
143+
YearMonth.parse("2021-03"), YearMonth.parse("2021-03")));
144+
generations.add(new ProjectGeneration.Generation("2.1.x", YearMonth.parse("2020-01"), SupportType.DEFAULT,
145+
YearMonth.parse("2021-03"), YearMonth.parse("2022-03")));
141146
return new ProjectGeneration(generations);
142147
}
143148

144149
FieldDescriptor[] generationPayload() {
145150
return new FieldDescriptor[] { fieldWithPath("name").type(JsonFieldType.STRING).description("Generation Name"),
146151
fieldWithPath("initialReleaseDate").type(JsonFieldType.STRING)
147152
.description("Date of the first release for this Generation"),
153+
fieldWithPath("support").type(JsonFieldType.STRING).description("Type of support"),
148154
fieldWithPath("ossSupportEndDate").type(JsonFieldType.STRING)
149155
.optional()
150156
.description("End date of the OSS support"),

src/test/resources/io/spring/projectapi/github/project-generations-content.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
{
9393
"generation": "2.7.x",
9494
"initialRelease": "2022-05",
95-
"lastMinor": true,
95+
"support": "extended",
9696
"ossSupportEnd": "2023-06",
9797
"enterpriseSupportEnd": "2029-06",
9898
"linkedGenerations": {
@@ -159,7 +159,7 @@
159159
{
160160
"generation": "3.5.x",
161161
"initialRelease": "2025-05",
162-
"lastMinor": true,
162+
"support": "extended",
163163
"ossSupportEnd": "2026-06",
164164
"enterpriseSupportEnd": "2032-06",
165165
"linkedGenerations": {

src/test/resources/io/spring/projectapi/github/project-generations.json

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)