Search in sources :

Example 6 with VulnerabilityUpdateStatus

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

the class VulnerabilityUtils method getUpdateStatusFromUpdateMap.

public static VulnerabilityUpdateStatus getUpdateStatusFromUpdateMap(Map<UpdateType, List<Vulnerability>> statusToVulnerabilities) {
    VulnerabilityUpdateStatus status = getEmptyVulnerabilityUpdateStatus();
    status.requestStatus = nullToEmptyList(statusToVulnerabilities.get(UpdateType.FAILED)).size() > 0 ? RequestStatus.FAILURE : RequestStatus.SUCCESS;
    for (UpdateType updateType : UpdateType.values()) {
        List<String> idList = nullToEmptyList(statusToVulnerabilities.get(updateType)).stream().map(Vulnerability::getExternalId).collect(Collectors.toList());
        status.statusToVulnerabilityIds.get(updateType).addAll(idList);
    }
    return status;
}
Also used : VulnerabilityUpdateStatus(org.eclipse.sw360.datahandler.thrift.cvesearch.VulnerabilityUpdateStatus) UpdateType(org.eclipse.sw360.datahandler.thrift.cvesearch.UpdateType)

Example 7 with VulnerabilityUpdateStatus

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

the class VulnerabilityUtilsTest method getUpdateStatusFromUpdateMapFailure.

@Test
public void getUpdateStatusFromUpdateMapFailure() throws Exception {
    VulnerabilityUpdateStatus result = getUpdateStatusFromUpdateMap(failedUpdateMap);
    assertThat(result.getRequestStatus(), is(RequestStatus.FAILURE));
    assertThat(result.statusToVulnerabilityIds.get(UpdateType.UPDATED), containsInAnyOrder("ue1", "ue2", "ue3"));
    assertThat(result.statusToVulnerabilityIds.get(UpdateType.NEW), containsInAnyOrder("ne1", "ne2"));
    assertThat(result.statusToVulnerabilityIds.get(UpdateType.OLD), containsInAnyOrder("oe1", "oe2", "oe3"));
    assertThat(result.statusToVulnerabilityIds.get(UpdateType.FAILED), containsInAnyOrder("fe1", "fe2", "fe3"));
}
Also used : VulnerabilityUpdateStatus(org.eclipse.sw360.datahandler.thrift.cvesearch.VulnerabilityUpdateStatus) Test(org.junit.Test)

Example 8 with VulnerabilityUpdateStatus

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

the class VulnerabilityUtilsTest method getUpdateStatusFromUpdateMapSuccess.

@Test
public void getUpdateStatusFromUpdateMapSuccess() throws Exception {
    VulnerabilityUpdateStatus result = getUpdateStatusFromUpdateMap(updateMap);
    assertThat(result.getRequestStatus(), is(RequestStatus.SUCCESS));
    assertThat(result.statusToVulnerabilityIds.get(UpdateType.UPDATED), containsInAnyOrder("ue1", "ue2", "ue3"));
    assertThat(result.statusToVulnerabilityIds.get(UpdateType.NEW), containsInAnyOrder("ne1", "ne2"));
}
Also used : VulnerabilityUpdateStatus(org.eclipse.sw360.datahandler.thrift.cvesearch.VulnerabilityUpdateStatus) Test(org.junit.Test)

Example 9 with VulnerabilityUpdateStatus

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

the class VulnerabilityUtilsTest method getUpdateStatusFromUpdateMapEmpty.

@Test
public void getUpdateStatusFromUpdateMapEmpty() throws Exception {
    VulnerabilityUpdateStatus result = getUpdateStatusFromUpdateMap(new HashMap<>());
    assertThat(result.getRequestStatus(), is(RequestStatus.SUCCESS));
    assertThat(result.statusToVulnerabilityIds.get(UpdateType.UPDATED), is(Collections.EMPTY_LIST));
    assertThat(result.statusToVulnerabilityIds.get(UpdateType.NEW), is(Collections.EMPTY_LIST));
}
Also used : VulnerabilityUpdateStatus(org.eclipse.sw360.datahandler.thrift.cvesearch.VulnerabilityUpdateStatus) Test(org.junit.Test)

Example 10 with VulnerabilityUpdateStatus

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

the class ComponentPortlet method updateVulnerabilitiesRelease.

private void updateVulnerabilitiesRelease(ResourceRequest request, ResourceResponse response) throws PortletException, IOException {
    String releaseId = request.getParameter(PortalConstants.RELEASE_ID);
    CveSearchService.Iface cveClient = thriftClients.makeCvesearchClient();
    try {
        VulnerabilityUpdateStatus importStatus = cveClient.updateForRelease(releaseId);
        JSONObject responseData = PortletUtils.importStatusToJSON(importStatus);
        PrintWriter writer = response.getWriter();
        writer.write(responseData.toString());
    } catch (TException e) {
        log.error("Error updating CVEs for release in backend.", e);
    }
}
Also used : CveSearchService(org.eclipse.sw360.datahandler.thrift.cvesearch.CveSearchService) TException(org.apache.thrift.TException) JSONObject(com.liferay.portal.kernel.json.JSONObject) VulnerabilityUpdateStatus(org.eclipse.sw360.datahandler.thrift.cvesearch.VulnerabilityUpdateStatus) PrintWriter(java.io.PrintWriter)

Aggregations

VulnerabilityUpdateStatus (org.eclipse.sw360.datahandler.thrift.cvesearch.VulnerabilityUpdateStatus)11 TException (org.apache.thrift.TException)5 CveSearchService (org.eclipse.sw360.datahandler.thrift.cvesearch.CveSearchService)5 JSONObject (com.liferay.portal.kernel.json.JSONObject)4 PrintWriter (java.io.PrintWriter)4 UpdateType (org.eclipse.sw360.datahandler.thrift.cvesearch.UpdateType)4 Test (org.junit.Test)3 CommonUtils (org.eclipse.sw360.datahandler.common.CommonUtils)2 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)2 JSONFactoryUtil.createJSONObject (com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONObject)1 IOException (java.io.IOException)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 Logger (org.apache.log4j.Logger)1 VulnerabilityConnector (org.eclipse.sw360.cvesearch.datasink.VulnerabilityConnector)1 CveSearchApiImpl (org.eclipse.sw360.cvesearch.datasource.CveSearchApiImpl)1 CveSearchData (org.eclipse.sw360.cvesearch.datasource.CveSearchData)1 CveSearchWrapper (org.eclipse.sw360.cvesearch.datasource.CveSearchWrapper)1 CveSearchDataTranslator (org.eclipse.sw360.cvesearch.entitytranslation.CveSearchDataTranslator)1 VulnerabilityUtils (org.eclipse.sw360.cvesearch.helper.VulnerabilityUtils)1