18
18
import io .securecodebox .persistence .defectdojo .model .Model ;
19
19
import io .securecodebox .persistence .defectdojo .model .PaginatedResult ;
20
20
import lombok .Getter ;
21
+ import lombok .NonNull ;
21
22
import lombok .extern .slf4j .Slf4j ;
22
23
import org .springframework .http .HttpEntity ;
23
24
import org .springframework .http .HttpHeaders ;
35
36
import java .net .URISyntaxException ;
36
37
import java .util .*;
37
38
38
- // FIXME: Should be package private bc implementation detail.
39
39
// TODO: Remove JsonProcessingException, URISyntaxException from public API and use a own runtime exception type bc these checked exceptions clutter the client coe.
40
40
@ Slf4j
41
- public abstract class GenericDefectDojoService <T extends Model > {
41
+ abstract class GenericDefectDojoService <T extends Model > implements DefectDojoService < T > {
42
42
private static final String API_PREFIX = "/api/v2/" ;
43
43
private static final long DEFECT_DOJO_OBJET_LIMIT = 100L ;
44
44
protected Config config ;
@@ -49,7 +49,8 @@ public abstract class GenericDefectDojoService<T extends Model> {
49
49
@ Getter
50
50
protected RestTemplate restTemplate ;
51
51
52
- public GenericDefectDojoService (Config config ) {
52
+ public GenericDefectDojoService (@ NonNull Config config ) {
53
+ super ();
53
54
this .config = config ;
54
55
55
56
this .objectMapper = new ObjectMapper ();
@@ -92,7 +93,8 @@ private RestTemplate setupRestTemplate() {
92
93
93
94
protected abstract PaginatedResult <T > deserializeList (String response ) throws JsonProcessingException ;
94
95
95
- public T get (long id ) {
96
+ @ Override
97
+ public final T get (long id ) {
96
98
var restTemplate = this .getRestTemplate ();
97
99
HttpEntity <String > payload = new HttpEntity <>(getDefectDojoAuthorizationHeaders ());
98
100
@@ -136,7 +138,8 @@ protected PaginatedResult<T> internalSearch(Map<String, Object> queryParams, lon
136
138
return deserializeList (responseString .getBody ());
137
139
}
138
140
139
- public List <T > search (Map <String , Object > queryParams ) throws URISyntaxException , JsonProcessingException {
141
+ @ Override
142
+ public final List <T > search (Map <String , Object > queryParams ) throws URISyntaxException , JsonProcessingException {
140
143
List <T > objects = new LinkedList <>();
141
144
142
145
boolean hasNext ;
@@ -154,12 +157,14 @@ public List<T> search(Map<String, Object> queryParams) throws URISyntaxException
154
157
return objects ;
155
158
}
156
159
157
- public List <T > search () throws URISyntaxException , JsonProcessingException {
160
+ @ Override
161
+ public final List <T > search () throws URISyntaxException , JsonProcessingException {
158
162
return search (new LinkedHashMap <>());
159
163
}
160
164
165
+ @ Override
161
166
@ SuppressWarnings ("unchecked" )
162
- public Optional <T > searchUnique (T searchObject ) throws URISyntaxException , JsonProcessingException {
167
+ public final Optional <T > searchUnique (T searchObject ) throws URISyntaxException , JsonProcessingException {
163
168
Map <String , Object > queryParams = searchStringMapper .convertValue (searchObject , Map .class );
164
169
165
170
var objects = search (queryParams );
@@ -169,30 +174,34 @@ public Optional<T> searchUnique(T searchObject) throws URISyntaxException, JsonP
169
174
.findFirst ();
170
175
}
171
176
172
- public Optional <T > searchUnique (Map <String , Object > queryParams ) throws URISyntaxException , JsonProcessingException {
177
+ @ Override
178
+ public final Optional <T > searchUnique (Map <String , Object > queryParams ) throws URISyntaxException , JsonProcessingException {
173
179
var objects = search (queryParams );
174
180
175
181
return objects .stream ()
176
182
.filter (object -> object .equalsQueryString (queryParams ))
177
183
.findFirst ();
178
184
}
179
185
180
- public T create (T object ) {
186
+ @ Override
187
+ public final T create (T object ) {
181
188
var restTemplate = this .getRestTemplate ();
182
189
HttpEntity <T > payload = new HttpEntity <>(object , getDefectDojoAuthorizationHeaders ());
183
190
184
191
ResponseEntity <T > response = restTemplate .exchange (this .config .getUrl () + API_PREFIX + getUrlPath () + "/" , HttpMethod .POST , payload , getModelClass ());
185
192
return response .getBody ();
186
193
}
187
194
188
- public void delete (long id ) {
195
+ @ Override
196
+ public final void delete (long id ) {
189
197
var restTemplate = this .getRestTemplate ();
190
198
HttpEntity <String > payload = new HttpEntity <>(getDefectDojoAuthorizationHeaders ());
191
199
192
200
restTemplate .exchange (this .config .getUrl () + API_PREFIX + getUrlPath () + "/" + id + "/" , HttpMethod .DELETE , payload , String .class );
193
201
}
194
202
195
- public T update (T object , long objectId ) {
203
+ @ Override
204
+ public final T update (T object , long objectId ) {
196
205
var restTemplate = this .getRestTemplate ();
197
206
HttpEntity <T > payload = new HttpEntity <>(object , getDefectDojoAuthorizationHeaders ());
198
207
0 commit comments