Search in sources :

Example 11 with Match

use of org.eclipse.sw360.cvesearch.datasource.matcher.Match in project sw360portal by sw360.

the class ComponentPortlet method updateVulnerabilityVerification.

private void updateVulnerabilityVerification(ResourceRequest request, ResourceResponse response) throws IOException {
    String[] releaseIds = request.getParameterValues(PortalConstants.RELEASE_IDS + "[]");
    String[] vulnerabilityIds = request.getParameterValues(PortalConstants.VULNERABILITY_IDS + "[]");
    User user = UserCacheHolder.getUserFromRequest(request);
    VulnerabilityService.Iface vulClient = thriftClients.makeVulnerabilityClient();
    RequestStatus requestStatus = RequestStatus.SUCCESS;
    try {
        if (vulnerabilityIds.length != releaseIds.length) {
            throw new SW360Exception("Length of vulnerabilities (" + vulnerabilityIds.length + ") does not match the length of releases (" + releaseIds.length + ")!");
        }
        for (int i = 0; i < vulnerabilityIds.length; i++) {
            String vulnerabilityId = vulnerabilityIds[i];
            String releaseId = releaseIds[i];
            Vulnerability dbVulnerability = vulClient.getVulnerabilityByExternalId(vulnerabilityId, user);
            ReleaseVulnerabilityRelation dbRelation = vulClient.getRelationByIds(releaseId, dbVulnerability.getId(), user);
            ReleaseVulnerabilityRelation resultRelation = ComponentPortletUtils.updateReleaseVulnerabilityRelationFromRequest(dbRelation, request);
            requestStatus = vulClient.updateReleaseVulnerabilityRelation(resultRelation, user);
            if (requestStatus != RequestStatus.SUCCESS) {
                break;
            }
        }
    } catch (TException e) {
        log.error("Error updating vulnerability verification in backend.", e);
        requestStatus = RequestStatus.FAILURE;
    }
    JSONObject responseData = JSONFactoryUtil.createJSONObject();
    responseData.put(PortalConstants.REQUEST_STATUS, requestStatus.toString());
    PrintWriter writer = response.getWriter();
    writer.write(responseData.toString());
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) VulnerabilityService(org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityService) Vulnerability(org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability) JSONObject(com.liferay.portal.kernel.json.JSONObject) ReleaseVulnerabilityRelation(org.eclipse.sw360.datahandler.thrift.vulnerabilities.ReleaseVulnerabilityRelation) PrintWriter(java.io.PrintWriter)

Example 12 with Match

use of org.eclipse.sw360.cvesearch.datasource.matcher.Match in project sw360portal by sw360.

the class ProjectPortletUtils method updateProjectVulnerabilityRatingFromRequest.

public static ProjectVulnerabilityRating updateProjectVulnerabilityRatingFromRequest(Optional<ProjectVulnerabilityRating> projectVulnerabilityRatings, ResourceRequest request) throws SW360Exception {
    String projectId = request.getParameter(PortalConstants.PROJECT_ID);
    ProjectVulnerabilityRating projectVulnerabilityRating = projectVulnerabilityRatings.orElse(new ProjectVulnerabilityRating().setProjectId(projectId).setVulnerabilityIdToReleaseIdToStatus(new HashMap<>()));
    if (!projectVulnerabilityRating.isSetVulnerabilityIdToReleaseIdToStatus()) {
        projectVulnerabilityRating.setVulnerabilityIdToReleaseIdToStatus(new HashMap<>());
    }
    Map<String, Map<String, List<VulnerabilityCheckStatus>>> vulnerabilityIdToReleaseIdToStatus = projectVulnerabilityRating.getVulnerabilityIdToReleaseIdToStatus();
    String[] vulnerabilityIds = request.getParameterValues(PortalConstants.VULNERABILITY_IDS + "[]");
    String[] releaseIds = request.getParameterValues(PortalConstants.RELEASE_IDS + "[]");
    if (vulnerabilityIds.length != releaseIds.length) {
        String message = "Length of vulnerabilities (" + vulnerabilityIds.length + ") does not match the length of releases (" + releaseIds.length + ")!";
        log.error(message);
        throw new SW360Exception(message);
    }
    for (int i = 0; i < vulnerabilityIds.length; i++) {
        String vulnerabilityId = vulnerabilityIds[i];
        String releaseId = releaseIds[i];
        Map<String, List<VulnerabilityCheckStatus>> releaseIdToStatus = vulnerabilityIdToReleaseIdToStatus.computeIfAbsent(vulnerabilityId, k -> new HashMap<>());
        List<VulnerabilityCheckStatus> vulnerabilityCheckStatusHistory = releaseIdToStatus.computeIfAbsent(releaseId, k -> new ArrayList<>());
        VulnerabilityCheckStatus vulnerabilityCheckStatus = newVulnerabilityCheckStatusFromRequest(request);
        vulnerabilityCheckStatusHistory.add(vulnerabilityCheckStatus);
    }
    return projectVulnerabilityRating;
}
Also used : ProjectVulnerabilityRating(org.eclipse.sw360.datahandler.thrift.vulnerabilities.ProjectVulnerabilityRating) ImmutableMap(com.google.common.collect.ImmutableMap) VulnerabilityCheckStatus(org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityCheckStatus)

Example 13 with Match

use of org.eclipse.sw360.cvesearch.datasource.matcher.Match in project sw360portal by sw360.

the class DatabaseConnectorTest method testUpdateDocument.

@Test
public void testUpdateDocument() throws Exception {
    // Change something in the object
    object.setText("Some new text");
    // Update the document
    connector.update(object);
    // Checkt that the object's revision was updated
    assertNotEquals(rev, object.getRevision());
    // Fetch it again to check it was updated in the database
    TestObject object1 = connector.get(TestObject.class, id);
    assertEquals("Test", object1.getName());
    assertEquals("Some new text", object1.getText());
    // Check that both revision match
    assertEquals(object.getRevision(), object1.getRevision());
    // Check that revision has changed
    assertNotEquals(rev, object1.getRevision());
    rev = object1.getRevision();
}
Also used : TestObject(org.eclipse.sw360.testthrift.TestObject) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 ModifiedLevenshteinDistance.levenshteinMatch (org.eclipse.sw360.cvesearch.datasource.matcher.ModifiedLevenshteinDistance.levenshteinMatch)7 Match (org.eclipse.sw360.cvesearch.datasource.matcher.Match)3 IOException (java.io.IOException)2 Collectors (java.util.stream.Collectors)2 Logger (org.apache.log4j.Logger)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 JSONObject (com.liferay.portal.kernel.json.JSONObject)1 PrintWriter (java.io.PrintWriter)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 Properties (java.util.Properties)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 Stream (java.util.stream.Stream)1 TException (org.apache.thrift.TException)1 CveSearchApi (org.eclipse.sw360.cvesearch.datasource.CveSearchApi)1