use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability in project sw360portal by sw360.
the class VulnerabilityConnectorTest method testIsMoreRecentFirstOlder.
@Test
public void testIsMoreRecentFirstOlder() throws Exception {
Vulnerability v1 = new Vulnerability().setLastExternalUpdate("2015");
Vulnerability v2 = new Vulnerability().setLastExternalUpdate("2016");
assertThat(vulnerabilityConnector.isMoreRecent(v1, v2), is(false));
}
use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability 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.Vulnerability in project sw360portal by sw360.
the class VulnerabilityUtilsTest method setUp.
@Before
public void setUp() throws Exception {
emptyVus = getEmptyVulnerabilityUpdateStatus(RequestStatus.SUCCESS);
vus1 = getEmptyVulnerabilityUpdateStatus(RequestStatus.SUCCESS);
for (UpdateType updateType : UpdateType.values()) {
vus1.statusToVulnerabilityIds.get(updateType).addAll(Arrays.asList("id0", "id1", "id2"));
}
vus2 = getEmptyVulnerabilityUpdateStatus(RequestStatus.SUCCESS);
for (UpdateType updateType : UpdateType.values()) {
vus2.statusToVulnerabilityIds.get(updateType).addAll(Arrays.asList("id3", "id4", "id5"));
}
vus3 = getEmptyVulnerabilityUpdateStatus(RequestStatus.FAILURE);
for (UpdateType updateType : UpdateType.values()) {
vus3.statusToVulnerabilityIds.get(updateType).addAll(Arrays.asList("id6", "id7", "id8"));
}
List<Vulnerability> nlist = Arrays.asList(new Vulnerability().setId("n1").setExternalId("ne1"), new Vulnerability().setId("n2").setExternalId("ne2"));
List<Vulnerability> ulist = Arrays.asList(new Vulnerability().setId("u1").setExternalId("ue1"), new Vulnerability().setId("u2").setExternalId("ue2"), new Vulnerability().setId("u3").setExternalId("ue3"));
List<Vulnerability> olist = Arrays.asList(new Vulnerability().setId("o1").setExternalId("oe1"), new Vulnerability().setId("o2").setExternalId("oe2"), new Vulnerability().setId("o3").setExternalId("oe3"));
List<Vulnerability> flist = Arrays.asList(new Vulnerability().setId("f1").setExternalId("fe1"), new Vulnerability().setId("f2").setExternalId("fe2"), new Vulnerability().setId("f3").setExternalId("fe3"));
updateMap = new HashMap<>();
updateMap.put(UpdateType.NEW, nlist);
updateMap.put(UpdateType.UPDATED, ulist);
failedUpdateMap = new HashMap<>();
failedUpdateMap.put(UpdateType.NEW, nlist);
failedUpdateMap.put(UpdateType.UPDATED, ulist);
failedUpdateMap.put(UpdateType.OLD, olist);
failedUpdateMap.put(UpdateType.FAILED, flist);
}
use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability in project sw360portal by sw360.
the class CveSearchDataTranslatorTest method testIdTranslation.
@Test
public void testIdTranslation() {
Vulnerability v = cveSearchDataTranslator.apply(cveSearchData).vulnerability;
Set<CVEReference> cveReferences = v.getCveReferences();
assert (cveReferences.size() == 1);
CVEReference cveReference = cveReferences.stream().findAny().get();
assert (CVEYEAR.equals(cveReference.getYear()));
assert ((CVENUMBER + ID).equals(cveReference.getNumber()));
}
use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability 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;
}
Aggregations