use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.ReleaseVulnerabilityRelation in project sw360portal by sw360.
the class CveSearchDataTranslator method apply.
@Override
public VulnerabilityWithRelation apply(CveSearchData cveSearchData) {
Vulnerability vulnerability = new CveSearchDataToVulnerabilityTranslator().apply(cveSearchData);
ReleaseVulnerabilityRelation relation = new CveSearchDataToReleaseVulnerabilityRelationTranslator().apply(cveSearchData);
return new VulnerabilityWithRelation(vulnerability, relation);
}
use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.ReleaseVulnerabilityRelation in project sw360portal by sw360.
the class VulnerabilityConnector method addOrUpdate.
public UpdateType addOrUpdate(Vulnerability vulnerability, ReleaseVulnerabilityRelation partiallyFilledRelation) {
RequestStatus vulRequestStatus = RequestStatus.SUCCESS;
UpdateType updateType;
Vulnerability dbVulnerability = vulnerabilityDatabaseHandler.getByExternalId(Vulnerability.class, vulnerability.getExternalId());
if (dbVulnerability != null) {
if (isMoreRecent(vulnerability, dbVulnerability)) {
updateType = UpdateType.UPDATED;
dbVulnerability = VulnerabilityMapper.updateFromVulnerability(dbVulnerability, vulnerability);
vulRequestStatus = vulnerabilityDatabaseHandler.update(dbVulnerability);
} else {
updateType = UpdateType.OLD;
}
} else {
updateType = UpdateType.NEW;
vulRequestStatus = vulnerabilityDatabaseHandler.add(vulnerability);
dbVulnerability = vulnerability;
}
if (RequestStatus.FAILURE.equals(vulRequestStatus)) {
return UpdateType.FAILED;
}
partiallyFilledRelation.setVulnerabilityId(dbVulnerability.getId());
RequestStatus requestStatus = addOrUpdate(partiallyFilledRelation);
if (RequestStatus.FAILURE.equals(requestStatus)) {
return UpdateType.FAILED;
}
return updateType;
}
use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.ReleaseVulnerabilityRelation in project sw360portal by sw360.
the class VulnerabilityConnector method addOrUpdate.
public VulnerabilityUpdateStatus addOrUpdate(Vulnerability vulnerability, ReleaseVulnerabilityRelation partiallyFilledRelation, VulnerabilityUpdateStatus currentVulnerabilityUpdateStatus) {
UpdateType updateType = addOrUpdate(vulnerability, partiallyFilledRelation);
currentVulnerabilityUpdateStatus.getStatusToVulnerabilityIds().get(updateType).add(vulnerability.getExternalId());
return currentVulnerabilityUpdateStatus;
}
use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.ReleaseVulnerabilityRelation in project sw360portal by sw360.
the class ComponentPortlet method updateVulnerabilityVerification.
private void updateVulnerabilityVerification(ResourceRequest request, ResourceResponse response) throws IOException {
String[] releaseIds = request.getParameterValues(PortalConstants.RELEASE_IDS + "[]");
String[] vulnerabilityIds = request.getParameterValues(PortalConstants.VULNERABILITY_IDS + "[]");
User user = UserCacheHolder.getUserFromRequest(request);
VulnerabilityService.Iface vulClient = thriftClients.makeVulnerabilityClient();
RequestStatus requestStatus = RequestStatus.SUCCESS;
try {
if (vulnerabilityIds.length != releaseIds.length) {
throw new SW360Exception("Length of vulnerabilities (" + vulnerabilityIds.length + ") does not match the length of releases (" + releaseIds.length + ")!");
}
for (int i = 0; i < vulnerabilityIds.length; i++) {
String vulnerabilityId = vulnerabilityIds[i];
String releaseId = releaseIds[i];
Vulnerability dbVulnerability = vulClient.getVulnerabilityByExternalId(vulnerabilityId, user);
ReleaseVulnerabilityRelation dbRelation = vulClient.getRelationByIds(releaseId, dbVulnerability.getId(), user);
ReleaseVulnerabilityRelation resultRelation = ComponentPortletUtils.updateReleaseVulnerabilityRelationFromRequest(dbRelation, request);
requestStatus = vulClient.updateReleaseVulnerabilityRelation(resultRelation, user);
if (requestStatus != RequestStatus.SUCCESS) {
break;
}
}
} catch (TException e) {
log.error("Error updating vulnerability verification in backend.", e);
requestStatus = RequestStatus.FAILURE;
}
JSONObject responseData = JSONFactoryUtil.createJSONObject();
responseData.put(PortalConstants.REQUEST_STATUS, requestStatus.toString());
PrintWriter writer = response.getWriter();
writer.write(responseData.toString());
}
use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.ReleaseVulnerabilityRelation 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));
}
}
Aggregations