Completing logic for retrieving latest scan date for a full scan
@@ -169,19 +169,24 @@ public class CxService {
try {
ResponseEntity<String> response = restTemplate.exchange(cxProperties.getUrl().concat(SCAN)
.concat("?projectId=").concat(projectId.toString().concat("&scanStatus=").concat(SCAN_STATUS_FINISHED.toString())
- .concat("&last=1")), HttpMethod.GET, requestEntity, String.class);
+ .concat("&last=").concat(cxProperties.getIncrementalNumScans().toString())),
+ HttpMethod.GET, requestEntity, String.class);
JSONArray arr = new JSONArray(response.getBody());
- if(arr.length() < 1){
- return null;
- }
- JSONObject obj = arr.getJSONObject(0);
- JSONObject dateAndTime = obj.getJSONObject("dateAndTime");
+ for (int i = 0; i < arr.length(); i++) {
+ JSONObject scan = arr.getJSONObject(i);
+ if (!scan.getBoolean("isIncremental")) {
+ JSONObject dateAndTime = scan.getJSONObject("dateAndTime");
+ log.debug("Last full scan was {}", dateAndTime);
//example: "finishedOn": "2018-06-18T01:09:12.707"
return LocalDateTime.parse(dateAndTime.getString("finishedOn"), formatter);
+ }
+ }
} catch (HttpStatusCodeException e) {
log.error("Error occurred while creating Scan for project {}, http error {}", projectId, e.getStatusCode());
e.printStackTrace();
+ } catch (NullPointerException e){
+ log.error("Error parsing JSON response for dateAndTime status. {}");
}
return null;
}
