Search in sources :

Example 1 with VulnerabilityUpdateStatus

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

the class ComponentPortlet method updateAllVulnerabilities.

private void updateAllVulnerabilities(ResourceRequest request, ResourceResponse response) throws PortletException, IOException {
    CveSearchService.Iface cveClient = thriftClients.makeCvesearchClient();
    try {
        VulnerabilityUpdateStatus importStatus = cveClient.fullUpdate();
        JSONObject responseData = PortletUtils.importStatusToJSON(importStatus);
        PrintWriter writer = response.getWriter();
        writer.write(responseData.toString());
    } catch (TException e) {
        log.error("Error occurred with full update of CVEs 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)

Example 2 with VulnerabilityUpdateStatus

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

the class CveSearchHandler method update.

@Override
public RequestStatus update() throws TException {
    log.info("Starting CveSearch update...");
    VulnerabilityUpdateStatus vulnerabilityUpdateStatus = fullUpdate();
    log.info("CveSearch update finished with status:" + vulnerabilityUpdateStatus.getRequestStatus());
    log.info("The following vulnerability/ies could not be imported:" + vulnerabilityUpdateStatus.getStatusToVulnerabilityIds().get(UpdateType.FAILED) + "\n" + "The following vulnerability/ies were updated:" + vulnerabilityUpdateStatus.getStatusToVulnerabilityIds().get(UpdateType.UPDATED) + "\n" + "The following vulnerability/ies were added:" + vulnerabilityUpdateStatus.getStatusToVulnerabilityIds().get(UpdateType.NEW));
    return vulnerabilityUpdateStatus.getRequestStatus();
}
Also used : VulnerabilityUpdateStatus(org.eclipse.sw360.datahandler.thrift.cvesearch.VulnerabilityUpdateStatus)

Example 3 with VulnerabilityUpdateStatus

use of org.eclipse.sw360.datahandler.thrift.cvesearch.VulnerabilityUpdateStatus 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;
}
Also used : UpdateType(org.eclipse.sw360.datahandler.thrift.cvesearch.UpdateType)

Example 4 with VulnerabilityUpdateStatus

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

the class CveSearchHandler method updateForRelease.

private VulnerabilityUpdateStatus updateForRelease(Release release) {
    Optional<List<CveSearchData>> cveSearchDatas = cveSearchWrapper.searchForRelease(release);
    if (!cveSearchDatas.isPresent()) {
        return new VulnerabilityUpdateStatus().setRequestStatus(RequestStatus.FAILURE);
    }
    CveSearchDataTranslator cveSearchDataTranslator = new CveSearchDataTranslator();
    List<CveSearchDataTranslator.VulnerabilityWithRelation> translated = cveSearchDatas.get().stream().map(cveSearchDataTranslator).map(vulnerabilityWithRelation -> {
        vulnerabilityWithRelation.relation.setReleaseId(release.getId());
        return vulnerabilityWithRelation;
    }).collect(Collectors.toList());
    VulnerabilityUpdateStatus updateStatus = getEmptyVulnerabilityUpdateStatus();
    for (CveSearchDataTranslator.VulnerabilityWithRelation vulnerabilityWithRelation : translated) {
        updateStatus = vulnerabilityConnector.addOrUpdate(vulnerabilityWithRelation.vulnerability, vulnerabilityWithRelation.relation, updateStatus);
    }
    return updateStatus;
}
Also used : VulnerabilityConnector(org.eclipse.sw360.cvesearch.datasink.VulnerabilityConnector) java.util(java.util) CveSearchData(org.eclipse.sw360.cvesearch.datasource.CveSearchData) CveSearchService(org.eclipse.sw360.datahandler.thrift.cvesearch.CveSearchService) Component(org.eclipse.sw360.datahandler.thrift.components.Component) Release(org.eclipse.sw360.datahandler.thrift.components.Release) CveSearchWrapper(org.eclipse.sw360.cvesearch.datasource.CveSearchWrapper) TException(org.apache.thrift.TException) IOException(java.io.IOException) VulnerabilityUpdateStatus(org.eclipse.sw360.datahandler.thrift.cvesearch.VulnerabilityUpdateStatus) Collectors(java.util.stream.Collectors) RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus) UpdateType(org.eclipse.sw360.datahandler.thrift.cvesearch.UpdateType) CommonUtils(org.eclipse.sw360.datahandler.common.CommonUtils) Logger(org.apache.log4j.Logger) CveSearchDataTranslator(org.eclipse.sw360.cvesearch.entitytranslation.CveSearchDataTranslator) VulnerabilityUtils(org.eclipse.sw360.cvesearch.helper.VulnerabilityUtils) CveSearchApiImpl(org.eclipse.sw360.cvesearch.datasource.CveSearchApiImpl) Project(org.eclipse.sw360.datahandler.thrift.projects.Project) VulnerabilityUpdateStatus(org.eclipse.sw360.datahandler.thrift.cvesearch.VulnerabilityUpdateStatus) CveSearchDataTranslator(org.eclipse.sw360.cvesearch.entitytranslation.CveSearchDataTranslator)

Example 5 with VulnerabilityUpdateStatus

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

the class VulnerabilityUtils method reduceVulnerabilityUpdateStatus.

public static VulnerabilityUpdateStatus reduceVulnerabilityUpdateStatus(VulnerabilityUpdateStatus... statuses) {
    VulnerabilityUpdateStatus resultStatus = getEmptyVulnerabilityUpdateStatus();
    RequestStatus requestStatus = Arrays.stream(statuses).map(VulnerabilityUpdateStatus::getRequestStatus).reduce(RequestStatus.SUCCESS, CommonUtils::reduceRequestStatus);
    resultStatus.setRequestStatus(requestStatus);
    for (UpdateType updateType : UpdateType.values()) {
        for (VulnerabilityUpdateStatus status : statuses) {
            if (status.isSetStatusToVulnerabilityIds()) {
                resultStatus.statusToVulnerabilityIds.get(updateType).addAll(nullToEmptyList(status.statusToVulnerabilityIds.get(updateType)));
            }
        }
    }
    return resultStatus;
}
Also used : CommonUtils(org.eclipse.sw360.datahandler.common.CommonUtils) VulnerabilityUpdateStatus(org.eclipse.sw360.datahandler.thrift.cvesearch.VulnerabilityUpdateStatus) UpdateType(org.eclipse.sw360.datahandler.thrift.cvesearch.UpdateType) RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus)

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