use of org.eclipse.sw360.datahandler.thrift.cvesearch.UpdateType in project sw360portal by sw360.
the class VulnerabilityConnectorTest method testaddOrUpdateVulnerabilitiesAndSetIds.
@Test
public void testaddOrUpdateVulnerabilitiesAndSetIds() {
Vulnerability v1 = new Vulnerability().setLastExternalUpdate("1999-12-31").setId("idv1").setExternalId("eid1");
Vulnerability v2 = new Vulnerability().setLastExternalUpdate("2000-01-01").setId("idv2").setExternalId("eid2");
Vulnerability v3 = new Vulnerability().setLastExternalUpdate("2000-01-01").setId("idv3").setExternalId("eid1");
Vulnerability v4 = new Vulnerability().setLastExternalUpdate("2000-01-01").setId("idv4").setExternalId("eid2");
Vulnerability v5 = new Vulnerability().setLastExternalUpdate("1999-12-31").setId("idv5").setExternalId("eid5");
List<Vulnerability> vulnerabilityList = Arrays.asList(v3, v4, v5);
when(vulnerabilityDatabaseHandler.getByExternalId(Vulnerability.class, "eid1")).thenReturn(v1);
when(vulnerabilityDatabaseHandler.getByExternalId(Vulnerability.class, "eid2")).thenReturn(v2);
when(vulnerabilityDatabaseHandler.getByExternalId(Vulnerability.class, "eid5")).thenReturn(null);
when(vulnerabilityDatabaseHandler.add(v5)).thenReturn(RequestStatus.SUCCESS);
when(vulnerabilityDatabaseHandler.update(v1)).thenReturn(RequestStatus.SUCCESS);
Map<UpdateType, List<Vulnerability>> resultMap = vulnerabilityConnector.addOrUpdateVulnerabilitiesAndSetIds(vulnerabilityList);
assertThat(resultMap.get(UpdateType.UPDATED).get(0).getId(), is("idv1"));
assertThat(resultMap.get(UpdateType.NEW).get(0).getId(), is("idv5"));
assertThat(resultMap.get(UpdateType.OLD).get(0).getId(), is("idv2"));
assertThat(resultMap.get(UpdateType.FAILED), is(Collections.EMPTY_LIST));
}
use of org.eclipse.sw360.datahandler.thrift.cvesearch.UpdateType in project sw360portal by sw360.
the class VulnerabilityConnectorTest method testAddOrUpdateVulnerabilityAndSetIdUpdateVulnerability.
@Test
public void testAddOrUpdateVulnerabilityAndSetIdUpdateVulnerability() throws Exception {
Vulnerability v1 = new Vulnerability().setLastExternalUpdate("1999-12-31").setId("idv1").setExternalId("eid");
Vulnerability v2 = new Vulnerability().setLastExternalUpdate("2000-01-01").setId("idv2").setExternalId("eid");
when(vulnerabilityDatabaseHandler.getByExternalId(Vulnerability.class, "eid")).thenReturn(v1);
when(vulnerabilityDatabaseHandler.update(v1)).thenReturn(RequestStatus.SUCCESS);
Map<UpdateType, List<Vulnerability>> resultMap = vulnerabilityConnector.addOrUpdateVulnerabilityAndSetId(v2, statusToVulnerabilityMap);
assertThat(resultMap.get(UpdateType.UPDATED).get(0).getId(), is("idv1"));
assertThat(resultMap.get(UpdateType.UPDATED).get(0).getLastExternalUpdate(), is("2000-01-01"));
assertThat(resultMap.get(UpdateType.NEW), is(Collections.EMPTY_LIST));
assertThat(resultMap.get(UpdateType.OLD), is(Collections.EMPTY_LIST));
assertThat(resultMap.get(UpdateType.FAILED), is(Collections.EMPTY_LIST));
}
use of org.eclipse.sw360.datahandler.thrift.cvesearch.UpdateType 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.cvesearch.UpdateType 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.cvesearch.UpdateType 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;
}
Aggregations