Skip to content

Commit

Permalink
secureCodeBox#121 Extract Method to Generate Base URL
Browse files Browse the repository at this point in the history
Signed-off-by: Sven Strittmatter <[email protected]>
  • Loading branch information
Weltraumschaf committed Jul 3, 2024
1 parent 4f2ee00 commit e5368d6
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public final T get(long id) {
var restTemplate = this.getRestTemplate();
HttpEntity<String> payload = new HttpEntity<>(getDefectDojoAuthorizationHeaders());

final var url = this.clientConfig.getUrl() + API_PREFIX + this.getUrlPath() + "/" + id;
final var url = createBaseUrl() + id;
log.debug("Requesting URL: {}", url);
ResponseEntity<T> response = restTemplate.exchange(
url,
Expand Down Expand Up @@ -132,7 +132,7 @@ public final T create(@NonNull T object) {
var restTemplate = this.getRestTemplate();
HttpEntity<T> payload = new HttpEntity<>(object, getDefectDojoAuthorizationHeaders());

ResponseEntity<T> response = restTemplate.exchange(this.clientConfig.getUrl() + API_PREFIX + getUrlPath() + "/", HttpMethod.POST, payload, getModelClass());
ResponseEntity<T> response = restTemplate.exchange(createBaseUrl(), HttpMethod.POST, payload, getModelClass());
return response.getBody();
}

Expand All @@ -141,15 +141,15 @@ public final void delete(long id) {
var restTemplate = this.getRestTemplate();
HttpEntity<String> payload = new HttpEntity<>(getDefectDojoAuthorizationHeaders());

restTemplate.exchange(this.clientConfig.getUrl() + API_PREFIX + getUrlPath() + "/" + id + "/", HttpMethod.DELETE, payload, String.class);
restTemplate.exchange(createBaseUrl() + id + "/", HttpMethod.DELETE, payload, String.class);
}

@Override
public final T update(@NonNull T object, long id) {
var restTemplate = this.getRestTemplate();
HttpEntity<T> payload = new HttpEntity<>(object, getDefectDojoAuthorizationHeaders());

ResponseEntity<T> response = restTemplate.exchange(this.clientConfig.getUrl() + API_PREFIX + getUrlPath() + "/" + id + "/", HttpMethod.PUT, payload, getModelClass());
ResponseEntity<T> response = restTemplate.exchange(createBaseUrl() + id + "/", HttpMethod.PUT, payload, getModelClass());
return response.getBody();
}

Expand All @@ -175,6 +175,10 @@ public final T update(@NonNull T object, long id) {
*/
protected abstract PaginatedResult<T> deserializeList(@NonNull String response);

private String createBaseUrl() {
return this.clientConfig.getUrl() + API_PREFIX + getUrlPath() + "/";
}

/**
* @return The DefectDojo Authentication Header
*/
Expand Down Expand Up @@ -211,7 +215,7 @@ protected PaginatedResult<T> internalSearch(Map<String, Object> queryParams, lon
multiValueMap.set(entry.getKey(), String.valueOf(entry.getValue()));
}

final var url = this.clientConfig.getUrl() + API_PREFIX + this.getUrlPath() + "/";
final var url = createBaseUrl();
final UriComponentsBuilder builder;
try {
builder = UriComponentsBuilder
Expand Down

0 comments on commit e5368d6

Please sign in to comment.