use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityDTO in project sw360portal by sw360.
the class VulnerabilityDTOResourceProcessor method process.
@Override
public Resource process(Resource<VulnerabilityDTO> resource) {
VulnerabilityDTO vulnerability = resource.getContent();
Link selfLink = linkTo(VulnerabilityController.class).slash("api" + VulnerabilityController.VULNERABILITIES_URL + "/" + vulnerability.getExternalId()).withSelfRel();
resource.add(selfLink);
return resource;
}
use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityDTO in project sw360portal by sw360.
the class ProjectController method getVulnerabilitiesOfReleases.
@RequestMapping(value = PROJECTS_URL + "/{id}/vulnerabilities", method = RequestMethod.GET)
public ResponseEntity<Resources<Resource<VulnerabilityDTO>>> getVulnerabilitiesOfReleases(@PathVariable("id") String id, OAuth2Authentication oAuth2Authentication) {
final User sw360User = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
final List<VulnerabilityDTO> allVulnerabilityDTOs = vulnerabilityService.getVulnerabilitiesByProjectId(id, sw360User);
final List<Resource<VulnerabilityDTO>> vulnerabilityResources = new ArrayList<>();
for (final VulnerabilityDTO vulnerabilityDTO : allVulnerabilityDTOs) {
final Resource<VulnerabilityDTO> vulnerabilityDTOResource = new Resource<>(vulnerabilityDTO);
vulnerabilityResources.add(vulnerabilityDTOResource);
}
final Resources<Resource<VulnerabilityDTO>> resources = new Resources<>(vulnerabilityResources);
return new ResponseEntity<>(resources, HttpStatus.OK);
}
use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityDTO in project sw360portal by sw360.
the class ComponentPortlet method putVulnerabilityMetadatasInRequest.
private void putVulnerabilityMetadatasInRequest(RenderRequest request, List<VulnerabilityDTO> vuls) {
Map<String, Map<String, String>> vulnerabilityTooltips = new HashMap<>();
Map<String, Map<String, VerificationState>> vulnerabilityVerifications = new HashMap<>();
for (VulnerabilityDTO vulnerability : vuls) {
addToVulnerabilityVerifications(vulnerabilityVerifications, vulnerabilityTooltips, vulnerability);
}
long numberOfCorrectVuls = vuls.stream().filter(vul -> !VerificationState.INCORRECT.equals(getVerificationState(vul))).map(vul -> vul.getExternalId()).collect(Collectors.toSet()).size();
request.setAttribute(NUMBER_OF_CHECKED_OR_UNCHECKED_VULNERABILITIES, numberOfCorrectVuls);
if (PermissionUtils.isAdmin(UserCacheHolder.getUserFromRequest(request))) {
long numberOfIncorrectVuls = vuls.stream().filter(v -> VerificationState.INCORRECT.equals(getVerificationState(v))).map(vul -> vul.getExternalId()).collect(Collectors.toSet()).size();
request.setAttribute(NUMBER_OF_INCORRECT_VULNERABILITIES, numberOfIncorrectVuls);
}
request.setAttribute(PortalConstants.VULNERABILITY_VERIFICATIONS, vulnerabilityVerifications);
request.setAttribute(PortalConstants.VULNERABILITY_VERIFICATION_TOOLTIPS, vulnerabilityTooltips);
}
use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityDTO in project sw360portal by sw360.
the class ComponentPortlet method addToVulnerabilityVerifications.
private void addToVulnerabilityVerifications(Map<String, Map<String, VerificationState>> vulnerabilityVerifications, Map<String, Map<String, String>> vulnerabilityTooltips, VulnerabilityDTO vulnerability) {
String vulnerabilityId = vulnerability.getExternalId();
String releaseId = vulnerability.getIntReleaseId();
Map<String, VerificationState> vulnerabilityVerification = vulnerabilityVerifications.computeIfAbsent(vulnerabilityId, k -> new HashMap<>());
Map<String, String> vulnerabilityTooltip = vulnerabilityTooltips.computeIfAbsent(vulnerabilityId, k -> new HashMap<>());
ReleaseVulnerabilityRelation relation = vulnerability.getReleaseVulnerabilityRelation();
if (!relation.isSetVerificationStateInfo()) {
vulnerabilityVerification.put(releaseId, VerificationState.NOT_CHECKED);
vulnerabilityTooltip.put(releaseId, "Not checked yet.");
} else {
List<VerificationStateInfo> infoHistory = relation.getVerificationStateInfo();
VerificationStateInfo info = infoHistory.get(infoHistory.size() - 1);
vulnerabilityVerification.put(releaseId, info.getVerificationState());
vulnerabilityTooltip.put(releaseId, formatedMessageForVul(infoHistory));
}
}
use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityDTO in project sw360portal by sw360.
the class VulnerabilityHandler method enrichVulnerabilityDTO.
private VulnerabilityDTO enrichVulnerabilityDTO(VulnerabilityDTO dto, LoadingCache<String, Component> componentCache, LoadingCache<String, Release> releaseCache) {
String releaseId = dto.getIntReleaseId();
try {
Release release = releaseCache.get(releaseId);
if (release != null) {
dto.setIntComponentId(release.getComponentId());
String releaseName = "";
if (!StringUtils.isEmpty(release.getName())) {
releaseName = release.getName() + " ";
dto.setIntComponentName(release.getName());
} else {
Component component = componentCache.get(release.getComponentId());
if (component != null) {
releaseName = component.getName() + " ";
dto.setIntComponentName(component.getName());
}
}
dto.setIntReleaseName(releaseName + release.getVersion());
}
} catch (ExecutionException e) {
log.error(e);
}
return dto;
}
Aggregations