Skip to content

Commit 4c532fa

Browse files
committedMar 15, 2024
Add Missing Interface Doc and Null Checks
Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
1 parent 8109543 commit 4c532fa

File tree

2 files changed

+83
-10
lines changed

2 files changed

+83
-10
lines changed
 

‎src/main/java/io/securecodebox/persistence/defectdojo/service/DefectDojoService.java

+78-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import com.fasterxml.jackson.core.JsonProcessingException;
77
import io.securecodebox.persistence.defectdojo.model.Model;
8+
import lombok.NonNull;
89

910
import java.net.URISyntaxException;
1011
import java.util.List;
@@ -13,21 +14,93 @@
1314

1415
/**
1516
* Basic CRUD interface for DefectDojo REST API
17+
*
18+
* @param <T> Type of model the implementation deals with
1619
*/
1720
public interface DefectDojoService<T extends Model> {
21+
/**
22+
* Get a single model object by its id from DefectDojo
23+
* <p>
24+
* TODO: Use Optional here instead of null as return value
25+
*
26+
* @param id must not be less than 1
27+
* @return maybe {@code null}
28+
*/
1829
T get(long id);
1930

20-
List<T> search(Map<String, Object> queryParams) throws URISyntaxException, JsonProcessingException;
31+
/**
32+
* Search for model objects by query parameters (name value pairs) in DefectDojo
33+
*
34+
* @param queryParams not {@code null}
35+
* @return not {@code null}, maybe empty
36+
* @throws URISyntaxException
37+
* @throws JsonProcessingException
38+
*/
39+
List<T> search(@NonNull Map<String, Object> queryParams) throws URISyntaxException, JsonProcessingException;
2140

41+
/**
42+
* Get list of all model objects in DefectDojo
43+
*
44+
* @return never {@code null}, maybe empty
45+
* @throws URISyntaxException
46+
* @throws JsonProcessingException
47+
*/
2248
List<T> search() throws URISyntaxException, JsonProcessingException;
2349

24-
Optional<T> searchUnique(T searchObject) throws URISyntaxException, JsonProcessingException;
50+
/**
51+
* Search for a single model object in DefectDojo
52+
* <p>
53+
* If multiple objects were found the first one will be returned.
54+
* </p>
55+
*
56+
* @param searchObject not {@code null}
57+
* @return never {@code null}
58+
* @throws URISyntaxException
59+
* @throws JsonProcessingException
60+
*/
61+
Optional<T> searchUnique(@NonNull T searchObject) throws URISyntaxException, JsonProcessingException;
2562

26-
Optional<T> searchUnique(Map<String, Object> queryParams) throws URISyntaxException, JsonProcessingException;
63+
/**
64+
* Search for a single model object in DefectDojo
65+
* <p>
66+
* If multiple objects were found the first one will be returned.
67+
* </p>
68+
*
69+
* @param queryParams not {@code null}
70+
* @return never {@code null}
71+
* @throws URISyntaxException
72+
* @throws JsonProcessingException
73+
*/
74+
Optional<T> searchUnique(@NonNull Map<String, Object> queryParams) throws URISyntaxException, JsonProcessingException;
2775

28-
T create(T object);
76+
/**
77+
* Create the given model object in DefectDojo
78+
* <p>
79+
* Use the returned object for further processing because DefectDojo may alter it (e.g. the id).
80+
* </p>
81+
*
82+
* @param object not {@code null}
83+
* @return never {@code null}
84+
*/
85+
T create(@NonNull T object);
2986

87+
/**
88+
* Delete the given model object in DefectDojo identified by its id
89+
*
90+
* @param id must not be less than 1
91+
*/
3092
void delete(long id);
3193

32-
T update(T object, long objectId);
94+
/**
95+
* Update the given model object in DefectDojo identified by its id
96+
*
97+
* <p>
98+
* Use the returned object for further processing because DefectDojo may alter it (e.g. the id).
99+
* </p>
100+
*
101+
* @param object not {@code null}
102+
* @param id must not be less than 1
103+
* @return never {@code null}
104+
*/
105+
T update(@NonNull T object, long id);
33106
}

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public final T get(long id) {
8484
}
8585

8686
@Override
87-
public final List<T> search(Map<String, Object> queryParams) throws URISyntaxException, JsonProcessingException {
87+
public final List<T> search(@NonNull Map<String, Object> queryParams) throws URISyntaxException, JsonProcessingException {
8888
List<T> objects = new LinkedList<>();
8989

9090
boolean hasNext;
@@ -120,7 +120,7 @@ public final Optional<T> searchUnique(T searchObject) throws URISyntaxException,
120120
}
121121

122122
@Override
123-
public final Optional<T> searchUnique(Map<String, Object> queryParams) throws URISyntaxException, JsonProcessingException {
123+
public final Optional<T> searchUnique(@NonNull Map<String, Object> queryParams) throws URISyntaxException, JsonProcessingException {
124124
var objects = search(queryParams);
125125

126126
return objects.stream()
@@ -129,7 +129,7 @@ public final Optional<T> searchUnique(Map<String, Object> queryParams) throws UR
129129
}
130130

131131
@Override
132-
public final T create(T object) {
132+
public final T create(@NonNull T object) {
133133
var restTemplate = this.getRestTemplate();
134134
HttpEntity<T> payload = new HttpEntity<>(object, getDefectDojoAuthorizationHeaders());
135135

@@ -146,11 +146,11 @@ public final void delete(long id) {
146146
}
147147

148148
@Override
149-
public final T update(T object, long objectId) {
149+
public final T update(@NonNull T object, long id) {
150150
var restTemplate = this.getRestTemplate();
151151
HttpEntity<T> payload = new HttpEntity<>(object, getDefectDojoAuthorizationHeaders());
152152

153-
ResponseEntity<T> response = restTemplate.exchange(this.config.getUrl() + API_PREFIX + getUrlPath() + "/" + objectId + "/", HttpMethod.PUT, payload, getModelClass());
153+
ResponseEntity<T> response = restTemplate.exchange(this.config.getUrl() + API_PREFIX + getUrlPath() + "/" + id + "/", HttpMethod.PUT, payload, getModelClass());
154154
return response.getBody();
155155
}
156156

0 commit comments

Comments
 (0)