Search in sources :

Example 1 with ProjectVulnerabilityRating

use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.ProjectVulnerabilityRating in project sw360portal by sw360.

the class ProjectPortlet method updateVulnerabilityRating.

private void updateVulnerabilityRating(ResourceRequest request, ResourceResponse response) throws IOException {
    String projectId = request.getParameter(PortalConstants.PROJECT_ID);
    User user = UserCacheHolder.getUserFromRequest(request);
    VulnerabilityService.Iface vulClient = thriftClients.makeVulnerabilityClient();
    RequestStatus requestStatus = RequestStatus.FAILURE;
    try {
        Optional<ProjectVulnerabilityRating> projectVulnerabilityRatings = wrapThriftOptionalReplacement(vulClient.getProjectVulnerabilityRatingByProjectId(projectId, user));
        ProjectVulnerabilityRating link = ProjectPortletUtils.updateProjectVulnerabilityRatingFromRequest(projectVulnerabilityRatings, request);
        requestStatus = vulClient.updateProjectVulnerabilityRating(link, user);
    } catch (TException e) {
        log.error("Error updating vulnerability ratings for project in backend.", e);
    }
    JSONObject responseData = JSONFactoryUtil.createJSONObject();
    responseData.put(PortalConstants.REQUEST_STATUS, requestStatus.toString());
    PrintWriter writer = response.getWriter();
    writer.write(responseData.toString());
}
Also used : WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) JSONFactoryUtil.createJSONObject(com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONObject) JSONObject(com.liferay.portal.kernel.json.JSONObject) PrintWriter(java.io.PrintWriter)

Example 2 with ProjectVulnerabilityRating

use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.ProjectVulnerabilityRating 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)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 JSONFactoryUtil.createJSONObject (com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONObject)1 JSONObject (com.liferay.portal.kernel.json.JSONObject)1 PrintWriter (java.io.PrintWriter)1 TException (org.apache.thrift.TException)1 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)1 User (org.eclipse.sw360.datahandler.thrift.users.User)1 ProjectVulnerabilityRating (org.eclipse.sw360.datahandler.thrift.vulnerabilities.ProjectVulnerabilityRating)1 VulnerabilityCheckStatus (org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityCheckStatus)1