public VulnerabilityUpdateStatus updateForRelease(Release release) { Optional<List<CveSearchData>> cveSearchDatas = cveSearchWrapper.searchForRelease(release); if (!cveSearchDatas.isPresent()) { return new VulnerabilityUpdateStatus().setRequestStatus(RequestStatus.FAILURE); } CveSearchDataTranslator cveSearchDataTranslator = new CveSearchDataTranslator(); List<CveSearchDataTranslator.VulnerabilityWithRelation> translated = cveSearchDatas .get() .stream() .map(cveSearchData -> cveSearchDataTranslator.apply(cveSearchData)) .map( vulnerabilityWithRelation -> { vulnerabilityWithRelation.relation.setReleaseId(release.getId()); return vulnerabilityWithRelation; }) .collect(Collectors.toList()); VulnerabilityUpdateStatus updateStatus = getEmptyVulnerabilityUpdateStatus(); for (CveSearchDataTranslator.VulnerabilityWithRelation vulnerabilityWithRelation : translated) { updateStatus = vulnerabilityConnector.addOrUpdate( vulnerabilityWithRelation.vulnerability, vulnerabilityWithRelation.relation, updateStatus); } return updateStatus; }
@Override public VulnerabilityUpdateStatus fullUpdate() throws TException { List<Release> allReleases = vulnerabilityConnector.getAllReleases(); return allReleases .stream() .map(this::updateForRelease) .reduce( getEmptyVulnerabilityUpdateStatus(), (r1, r2) -> reduceVulnerabilityUpdateStatus(r1, r2)); }
@Override public VulnerabilityUpdateStatus updateForComponent(String componentId) throws TException { Optional<Component> component = vulnerabilityConnector.getComponent(componentId); return component .map( c -> c.isSetReleaseIds() ? c.getReleaseIds() .stream() .map(this::updateForRelease) .reduce( getEmptyVulnerabilityUpdateStatus(), (r1, r2) -> reduceVulnerabilityUpdateStatus(r1, r2)) : getEmptyVulnerabilityUpdateStatus()) .orElse(getEmptyVulnerabilityUpdateStatus(RequestStatus.FAILURE)); }
@Override public VulnerabilityUpdateStatus updateForProject(String projectId) throws TException { Optional<Project> project = vulnerabilityConnector.getProject(projectId); return project .map( r -> r.isSetReleaseIdToUsage() ? r.getReleaseIdToUsage() .keySet() .stream() .map(this::updateForRelease) .reduce( getEmptyVulnerabilityUpdateStatus(), (r1, r2) -> reduceVulnerabilityUpdateStatus(r1, r2)) : getEmptyVulnerabilityUpdateStatus()) .orElse(getEmptyVulnerabilityUpdateStatus(RequestStatus.FAILURE)); }
@Override public VulnerabilityUpdateStatus updateForRelease(String releaseId) { Optional<Release> release = vulnerabilityConnector.getRelease(releaseId); Optional<VulnerabilityUpdateStatus> updateStatus = release.map(this::updateForRelease); return updateStatus.orElse(getEmptyVulnerabilityUpdateStatus(RequestStatus.FAILURE)); }