use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityCheckStatus in project sw360portal by sw360.
the class ProjectPortletUtils method updateProjectVulnerabilityRatingFromRequest.
public static ProjectVulnerabilityRating updateProjectVulnerabilityRatingFromRequest(Optional<ProjectVulnerabilityRating> projectVulnerabilityRatings, ResourceRequest request) throws SW360Exception {
String projectId = request.getParameter(PortalConstants.PROJECT_ID);
ProjectVulnerabilityRating projectVulnerabilityRating = projectVulnerabilityRatings.orElse(new ProjectVulnerabilityRating().setProjectId(projectId).setVulnerabilityIdToReleaseIdToStatus(new HashMap<>()));
if (!projectVulnerabilityRating.isSetVulnerabilityIdToReleaseIdToStatus()) {
projectVulnerabilityRating.setVulnerabilityIdToReleaseIdToStatus(new HashMap<>());
}
Map<String, Map<String, List<VulnerabilityCheckStatus>>> vulnerabilityIdToReleaseIdToStatus = projectVulnerabilityRating.getVulnerabilityIdToReleaseIdToStatus();
String[] vulnerabilityIds = request.getParameterValues(PortalConstants.VULNERABILITY_IDS + "[]");
String[] releaseIds = request.getParameterValues(PortalConstants.RELEASE_IDS + "[]");
if (vulnerabilityIds.length != releaseIds.length) {
String message = "Length of vulnerabilities (" + vulnerabilityIds.length + ") does not match the length of releases (" + releaseIds.length + ")!";
log.error(message);
throw new SW360Exception(message);
}
for (int i = 0; i < vulnerabilityIds.length; i++) {
String vulnerabilityId = vulnerabilityIds[i];
String releaseId = releaseIds[i];
Map<String, List<VulnerabilityCheckStatus>> releaseIdToStatus = vulnerabilityIdToReleaseIdToStatus.computeIfAbsent(vulnerabilityId, k -> new HashMap<>());
List<VulnerabilityCheckStatus> vulnerabilityCheckStatusHistory = releaseIdToStatus.computeIfAbsent(releaseId, k -> new ArrayList<>());
VulnerabilityCheckStatus vulnerabilityCheckStatus = newVulnerabilityCheckStatusFromRequest(request);
vulnerabilityCheckStatusHistory.add(vulnerabilityCheckStatus);
}
return projectVulnerabilityRating;
}
Aggregations