Skip to content

Commit 33f26cb

Browse files
committed
Use constant for repeated API URL prefix
Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
1 parent 62376ef commit 33f26cb

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/main/java/io/securecodebox/persistence/defectdojo/service/GenericDefectDojoService.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636

3737
// FIXME: Should be package private bc implementation detail.
3838
public abstract class GenericDefectDojoService<T extends Model> {
39-
protected Config config;
39+
private static final String API_PREFIX = "/api/v2/";
40+
protected Config config;
4041

4142
protected ObjectMapper objectMapper;
4243
protected ObjectMapper searchStringMapper;
@@ -94,7 +95,7 @@ public T get(long id) {
9495
HttpEntity<String> payload = new HttpEntity<>(getDefectDojoAuthorizationHeaders());
9596

9697
ResponseEntity<T> response = restTemplate.exchange(
97-
this.config.getUrl() + "/api/v2/" + this.getUrlPath() + "/" + id,
98+
this.config.getUrl() + API_PREFIX + this.getUrlPath() + "/" + id,
9899
HttpMethod.GET,
99100
payload,
100101
getModelClass()
@@ -117,7 +118,7 @@ protected Response<T> internalSearch(Map<String, Object> queryParams, long limit
117118
multiValueMap.set(entry.getKey(), String.valueOf(entry.getValue()));
118119
}
119120

120-
var url = new URI(this.config.getUrl() + "/api/v2/" + this.getUrlPath() + "/");
121+
var url = new URI(this.config.getUrl() + API_PREFIX + this.getUrlPath() + "/");
121122
var uriBuilder = UriComponentsBuilder.fromUri(url).queryParams(multiValueMap);
122123

123124
ResponseEntity<String> responseString = restTemplate.exchange(
@@ -175,22 +176,22 @@ public T create(T object) {
175176
var restTemplate = this.getRestTemplate();
176177
HttpEntity<T> payload = new HttpEntity<>(object, getDefectDojoAuthorizationHeaders());
177178

178-
ResponseEntity<T> response = restTemplate.exchange(this.config.getUrl() + "/api/v2/" + getUrlPath() + "/", HttpMethod.POST, payload, getModelClass());
179+
ResponseEntity<T> response = restTemplate.exchange(this.config.getUrl() + API_PREFIX + getUrlPath() + "/", HttpMethod.POST, payload, getModelClass());
179180
return response.getBody();
180181
}
181182

182183
public void delete(long id) {
183184
var restTemplate = this.getRestTemplate();
184185
HttpEntity<String> payload = new HttpEntity<>(getDefectDojoAuthorizationHeaders());
185186

186-
restTemplate.exchange(this.config.getUrl() + "/api/v2/" + getUrlPath() + "/" + id + "/", HttpMethod.DELETE, payload, String.class);
187+
restTemplate.exchange(this.config.getUrl() + API_PREFIX + getUrlPath() + "/" + id + "/", HttpMethod.DELETE, payload, String.class);
187188
}
188189

189190
public T update(T object, long objectId) {
190191
var restTemplate = this.getRestTemplate();
191192
HttpEntity<T> payload = new HttpEntity<>(object, getDefectDojoAuthorizationHeaders());
192193

193-
ResponseEntity<T> response = restTemplate.exchange(this.config.getUrl() + "/api/v2/" + getUrlPath() + "/" + objectId + "/", HttpMethod.PUT, payload, getModelClass());
194+
ResponseEntity<T> response = restTemplate.exchange(this.config.getUrl() + API_PREFIX + getUrlPath() + "/" + objectId + "/", HttpMethod.PUT, payload, getModelClass());
194195
return response.getBody();
195196
}
196197
}

0 commit comments

Comments
 (0)