Search in sources :

Example 6 with UpdateType

use of org.eclipse.sw360.datahandler.thrift.cvesearch.UpdateType in project sw360portal by sw360.

the class VulnerabilityConnector method addOrUpdateVulnerabilityAndSetId.

public Map<UpdateType, List<Vulnerability>> addOrUpdateVulnerabilityAndSetId(Vulnerability vulnerability, Map<UpdateType, List<Vulnerability>> statusToVulnerabilities) {
    Vulnerability dbVulnerability = vulnerabilityDatabaseHandler.getByExternalId(Vulnerability.class, vulnerability.getExternalId());
    if (dbVulnerability != null) {
        if (!isMoreRecent(vulnerability, dbVulnerability)) {
            statusToVulnerabilities.get(UpdateType.OLD).add(dbVulnerability);
            return statusToVulnerabilities;
        } else {
            dbVulnerability = VulnerabilityMapper.updateFromVulnerability(dbVulnerability, vulnerability);
            RequestStatus requestStatus = vulnerabilityDatabaseHandler.update(dbVulnerability);
            if (RequestStatus.SUCCESS.equals(requestStatus)) {
                statusToVulnerabilities.get(UpdateType.UPDATED).add(dbVulnerability);
                return statusToVulnerabilities;
            }
        }
    } else {
        RequestStatus requestStatus = vulnerabilityDatabaseHandler.add(vulnerability);
        if (RequestStatus.SUCCESS.equals(requestStatus)) {
            statusToVulnerabilities.get(UpdateType.NEW).add(vulnerability);
            return statusToVulnerabilities;
        }
    }
    statusToVulnerabilities.get(UpdateType.FAILED).add(vulnerability);
    return statusToVulnerabilities;
}
Also used : Vulnerability(org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability) RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus)

Example 7 with UpdateType

use of org.eclipse.sw360.datahandler.thrift.cvesearch.UpdateType in project sw360portal by sw360.

the class VulnerabilityConnectorTest method testAddOrUpdateVulnerabilityAndSetIdNewVulnerability.

@Test
public void testAddOrUpdateVulnerabilityAndSetIdNewVulnerability() throws Exception {
    Vulnerability v1 = new Vulnerability().setId("idv1").setExternalId("eid");
    when(vulnerabilityDatabaseHandler.getByExternalId(Vulnerability.class, "eid")).thenReturn(null);
    when(vulnerabilityDatabaseHandler.add(v1)).thenReturn(RequestStatus.SUCCESS);
    Map<UpdateType, List<Vulnerability>> resultMap = vulnerabilityConnector.addOrUpdateVulnerabilityAndSetId(v1, statusToVulnerabilityMap);
    assertThat(resultMap.get(UpdateType.NEW).get(0).getId(), is("idv1"));
    assertThat(resultMap.get(UpdateType.OLD), is(Collections.EMPTY_LIST));
    assertThat(resultMap.get(UpdateType.UPDATED), is(Collections.EMPTY_LIST));
    assertThat(resultMap.get(UpdateType.FAILED), is(Collections.EMPTY_LIST));
}
Also used : Vulnerability(org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability) UpdateType(org.eclipse.sw360.datahandler.thrift.cvesearch.UpdateType) Test(org.junit.Test)

Example 8 with UpdateType

use of org.eclipse.sw360.datahandler.thrift.cvesearch.UpdateType in project sw360portal by sw360.

the class VulnerabilityConnectorTest method testAddOrUpdateVulnerabilityAndSetIdFailUpdate.

@Test
public void testAddOrUpdateVulnerabilityAndSetIdFailUpdate() throws Exception {
    Vulnerability v2 = new Vulnerability().setLastExternalUpdate("2000-01-01").setId("idv2").setExternalId("eid");
    when(vulnerabilityDatabaseHandler.getByExternalId(Vulnerability.class, "eid")).thenReturn(null);
    when(vulnerabilityDatabaseHandler.add(v2)).thenReturn(RequestStatus.FAILURE);
    Map<UpdateType, List<Vulnerability>> resultMap = vulnerabilityConnector.addOrUpdateVulnerabilityAndSetId(v2, statusToVulnerabilityMap);
    assertThat(resultMap.get(UpdateType.FAILED).get(0).getId(), is("idv2"));
    assertThat(resultMap.get(UpdateType.NEW), is(Collections.EMPTY_LIST));
    assertThat(resultMap.get(UpdateType.OLD), is(Collections.EMPTY_LIST));
    assertThat(resultMap.get(UpdateType.UPDATED), is(Collections.EMPTY_LIST));
}
Also used : Vulnerability(org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability) UpdateType(org.eclipse.sw360.datahandler.thrift.cvesearch.UpdateType) Test(org.junit.Test)

Example 9 with UpdateType

use of org.eclipse.sw360.datahandler.thrift.cvesearch.UpdateType in project sw360portal by sw360.

the class VulnerabilityConnectorTest method testAddOrUpdateVulnerabilityAndSetIdOldVulnerability.

@Test
public void testAddOrUpdateVulnerabilityAndSetIdOldVulnerability() throws Exception {
    Vulnerability v1 = new Vulnerability().setLastExternalUpdate("2000-01-01").setId("idv1").setExternalId("eid");
    Vulnerability v2 = new Vulnerability().setLastExternalUpdate("2000-01-01").setId("idv2").setExternalId("eid");
    when(vulnerabilityDatabaseHandler.getByExternalId(Vulnerability.class, "eid")).thenReturn(v1);
    Map<UpdateType, List<Vulnerability>> resultMap = vulnerabilityConnector.addOrUpdateVulnerabilityAndSetId(v2, statusToVulnerabilityMap);
    assertThat(resultMap.get(UpdateType.OLD).get(0).getId(), is("idv1"));
    assertThat(resultMap.get(UpdateType.NEW), is(Collections.EMPTY_LIST));
    assertThat(resultMap.get(UpdateType.UPDATED), is(Collections.EMPTY_LIST));
    assertThat(resultMap.get(UpdateType.FAILED), is(Collections.EMPTY_LIST));
}
Also used : Vulnerability(org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability) UpdateType(org.eclipse.sw360.datahandler.thrift.cvesearch.UpdateType) Test(org.junit.Test)

Example 10 with UpdateType

use of org.eclipse.sw360.datahandler.thrift.cvesearch.UpdateType in project sw360portal by sw360.

the class VulnerabilityConnectorTest method testAddOrUpdateVulnerabilityAndSetIdFailAdd.

@Test
public void testAddOrUpdateVulnerabilityAndSetIdFailAdd() 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.FAILURE);
    Map<UpdateType, List<Vulnerability>> resultMap = vulnerabilityConnector.addOrUpdateVulnerabilityAndSetId(v2, statusToVulnerabilityMap);
    assertThat(resultMap.get(UpdateType.FAILED).get(0).getId(), is("idv2"));
    assertThat(resultMap.get(UpdateType.NEW), is(Collections.EMPTY_LIST));
    assertThat(resultMap.get(UpdateType.OLD), is(Collections.EMPTY_LIST));
    assertThat(resultMap.get(UpdateType.UPDATED), is(Collections.EMPTY_LIST));
}
Also used : Vulnerability(org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability) UpdateType(org.eclipse.sw360.datahandler.thrift.cvesearch.UpdateType) Test(org.junit.Test)

Aggregations

UpdateType (org.eclipse.sw360.datahandler.thrift.cvesearch.UpdateType)11 Vulnerability (org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability)9 Test (org.junit.Test)6 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)3 VulnerabilityUpdateStatus (org.eclipse.sw360.datahandler.thrift.cvesearch.VulnerabilityUpdateStatus)2 CommonUtils (org.eclipse.sw360.datahandler.common.CommonUtils)1 Before (org.junit.Before)1