26
26
import io .spring .initializr .metadata .InitializrMetadata ;
27
27
import io .spring .initializr .metadata .InitializrMetadataProvider ;
28
28
import io .spring .initializr .metadata .InvalidInitializrMetadataException ;
29
+ import io .spring .initializr .web .mapper .DependencyMetadataJsonMapper ;
29
30
import io .spring .initializr .web .mapper .DependencyMetadataV21JsonMapper ;
30
31
import io .spring .initializr .web .mapper .InitializrMetadataJsonMapper ;
31
32
import io .spring .initializr .web .mapper .InitializrMetadataV21JsonMapper ;
48
49
* {@link RestController} that exposes metadata and service configuration.
49
50
*
50
51
* @author Stephane Nicoll
52
+ * @author Moritz Halbritter
51
53
*/
52
54
@ RestController
53
55
public class ProjectMetadataController extends AbstractMetadataController {
@@ -124,32 +126,47 @@ protected CacheControl determineCacheControlFor(InitializrMetadata metadata) {
124
126
return CacheControl .maxAge (2 , TimeUnit .HOURS );
125
127
}
126
128
127
- private ResponseEntity <String > dependenciesFor (InitializrMetadataVersion version , String bootVersion ) {
129
+ /**
130
+ * Create the dependencies {@link ResponseEntity} for the given version and Spring
131
+ * Boot version.
132
+ * @param metadataVersion the metadata version
133
+ * @param bootVersion the Spring Boot version.
134
+ * @return the {@link ResponseEntity}
135
+ */
136
+ protected ResponseEntity <String > dependenciesFor (InitializrMetadataVersion metadataVersion , String bootVersion ) {
128
137
InitializrMetadata metadata = this .metadataProvider .get ();
129
- Version v = (bootVersion != null ) ? Version .parse (bootVersion )
138
+ Version effectiveBootVersion = (bootVersion != null ) ? Version .parse (bootVersion )
130
139
: Version .parse (metadata .getBootVersions ().getDefault ().getId ());
131
140
Platform platform = metadata .getConfiguration ().getEnv ().getPlatform ();
132
- if (!platform .isCompatibleVersion (v )) {
141
+ if (!platform .isCompatibleVersion (effectiveBootVersion )) {
133
142
throw new InvalidProjectRequestException ("Invalid Spring Boot version '" + bootVersion
134
143
+ "', Spring Boot compatibility range is " + platform .determineCompatibilityRangeRequirement ());
135
144
}
136
- DependencyMetadata dependencyMetadata = this .dependencyMetadataProvider .get (metadata , v );
137
- String content = new DependencyMetadataV21JsonMapper ( ).write (dependencyMetadata );
145
+ DependencyMetadata dependencyMetadata = this .dependencyMetadataProvider .get (metadata , effectiveBootVersion );
146
+ String content = createDependencyJsonMapper ( metadataVersion ).write (dependencyMetadata );
138
147
return ResponseEntity .ok ()
139
- .contentType (version .getMediaType ())
148
+ .contentType (metadataVersion .getMediaType ())
140
149
.eTag (createUniqueId (content ))
141
150
.cacheControl (determineCacheControlFor (metadata ))
142
151
.body (content );
143
152
}
144
153
145
- private ResponseEntity <String > serviceCapabilitiesFor (InitializrMetadataVersion version ) {
146
- return serviceCapabilitiesFor (version , version .getMediaType ());
154
+ private ResponseEntity <String > serviceCapabilitiesFor (InitializrMetadataVersion metadataVersion ) {
155
+ return serviceCapabilitiesFor (metadataVersion , metadataVersion .getMediaType ());
147
156
}
148
157
149
- private ResponseEntity <String > serviceCapabilitiesFor (InitializrMetadataVersion version , MediaType contentType ) {
158
+ /**
159
+ * Create the service capabilities {@link ResponseEntity} for the given metadata
160
+ * version and content type.
161
+ * @param metadataVersion the metadata version
162
+ * @param contentType the content type
163
+ * @return the {@link ResponseEntity}
164
+ */
165
+ protected ResponseEntity <String > serviceCapabilitiesFor (InitializrMetadataVersion metadataVersion ,
166
+ MediaType contentType ) {
150
167
String appUrl = generateAppUrl ();
151
168
InitializrMetadata metadata = this .metadataProvider .get ();
152
- String content = getJsonMapper ( version ).write (metadata , appUrl );
169
+ String content = createMetadataJsonMapper ( metadataVersion ).write (metadata , appUrl );
153
170
return ResponseEntity .ok ()
154
171
.contentType (contentType )
155
172
.eTag (createUniqueId (content ))
@@ -158,12 +175,28 @@ private ResponseEntity<String> serviceCapabilitiesFor(InitializrMetadataVersion
158
175
.body (content );
159
176
}
160
177
161
- private static InitializrMetadataJsonMapper getJsonMapper (InitializrMetadataVersion version ) {
162
- return switch (version ) {
163
- case V2 -> new InitializrMetadataV2JsonMapper ();
164
- case V2_1 -> new InitializrMetadataV21JsonMapper ();
165
- default -> new InitializrMetadataV22JsonMapper ();
166
- };
178
+ /**
179
+ * Create the {@link InitializrMetadataJsonMapper JSON mapper} for the given metadata
180
+ * version.
181
+ * @param metadataVersion the metadata version
182
+ * @return the JSON mapper
183
+ */
184
+ protected InitializrMetadataJsonMapper createMetadataJsonMapper (InitializrMetadataVersion metadataVersion ) {
185
+ return switch (metadataVersion ) {
186
+ case V2 -> new InitializrMetadataV2JsonMapper ();
187
+ case V2_1 -> new InitializrMetadataV21JsonMapper ();
188
+ default -> new InitializrMetadataV22JsonMapper ();
189
+ };
190
+ }
191
+
192
+ /**
193
+ * Create the {@link DependencyMetadataJsonMapper JSON mapper} for the given metadata
194
+ * version.
195
+ * @param metadataVersion the metadata version
196
+ * @return the JSON mapper
197
+ */
198
+ protected DependencyMetadataJsonMapper createDependencyJsonMapper (InitializrMetadataVersion metadataVersion ) {
199
+ return new DependencyMetadataV21JsonMapper ();
167
200
}
168
201
169
202
}
0 commit comments