All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.cx.restclient.osa.dto.OSAResults Maven / Gradle / Ivy

There is a newer version: 2024.3.26
Show newest version
package com.cx.restclient.osa.dto;

import com.cx.restclient.cxArm.dto.Policy;
import com.cx.restclient.dto.Results;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.cx.restclient.common.ShragaUtils.formatDate;
import static com.cx.restclient.cxArm.utils.CxARMUtils.getPolicyList;

/**
 * Created by Galn on 07/02/2018.
 */
@JsonIgnoreProperties(ignoreUnknown = true)
public class OSAResults extends Results implements Serializable {
    private String osaScanId;
    private OSASummaryResults results;
    private List osaLibraries;
    private List osaVulnerabilities;
    private OSAScanStatus osaScanStatus;
    private String osaProjectSummaryLink;
    private boolean osaResultsReady = false;
    private List osaHighCVEReportTable = new ArrayList();
    private List osaMediumCVEReportTable = new ArrayList();
    private List osaLowCVEReportTable = new ArrayList();

    private String scanStartTime;
    private String scanEndTime;

    private List osaPolicies = new ArrayList<>();

    public OSAResults() {
    }

    public OSAResults(String osaScanId) {
        this.osaScanId = osaScanId;
    }

    public void setResults(OSASummaryResults osaSummaryResults, List osaLibraries, List osaVulnerabilities, OSAScanStatus osaScanStatus, String url, long projectId) {
        setResults(osaSummaryResults);
        setOsaLibraries(osaLibraries);
        setOsaVulnerabilities(osaVulnerabilities);
        setOsaCVEReportTable(osaVulnerabilities, osaLibraries);
        setDates(osaScanStatus);
        setOsaScanStatus(osaScanStatus);
        setOsaProjectSummaryLink(url, projectId);
        setOsaResultsReady(true);
    }

    public List getOsaLibraries() {
        return osaLibraries;
    }

    public void setOsaLibraries(List osaLibraries) {
        this.osaLibraries = osaLibraries;
    }

    public List getOsaVulnerabilities() {
        return osaVulnerabilities;
    }

    public void setOsaVulnerabilities(List osaVulnerabilities) {
        this.osaVulnerabilities = osaVulnerabilities;
    }

    public OSASummaryResults getResults() {
        return results;
    }

    public void setResults(OSASummaryResults results) {
        this.results = results;
    }

    public OSAScanStatus getOsaScanStatus() {
        return osaScanStatus;
    }

    public void setOsaScanStatus(OSAScanStatus osaScanStatus) {
        this.osaScanStatus = osaScanStatus;
    }

    public String getOsaProjectSummaryLink() {
        return osaProjectSummaryLink;
    }

    public void setOsaProjectSummaryLink(String osaProjectSummaryLink) {
        this.osaProjectSummaryLink = osaProjectSummaryLink;
    }

    public void setOsaProjectSummaryLink(String url, long projectId) {
        this.osaProjectSummaryLink = String.format(url + "/CxWebClient/SPA/#/viewer/project/%s", projectId);
    }

    public boolean isOsaResultsReady() {
        return osaResultsReady;
    }

    public void setOsaResultsReady(boolean osaResultsReady) {
        this.osaResultsReady = osaResultsReady;
    }

    public String getOsaScanId() {
        return osaScanId;
    }

    public void setOsaScanId(String osaScanId) {
        this.osaScanId = osaScanId;
    }

    public List getOsaHighCVEReportTable() {
        return osaHighCVEReportTable;
    }

    public List getOsaMediumCVEReportTable() {
        return osaMediumCVEReportTable;
    }

    public List getOsaLowCVEReportTable() {
        return osaLowCVEReportTable;
    }

    public String getScanStartTime() {
        return scanStartTime;
    }

    public String getScanEndTime() {
        return scanEndTime;
    }

    private void setOsaCVEReportTable(List osaVulnerabilities, List osaLibraries) {
        Map cveMap = new HashMap();
        Map libMap = new HashMap();

        for (Library l : osaLibraries) {
            libMap.put(l.getId(), l);
        }

        //create uniqueness by key: cve + libraryId
        for (CVE cve : osaVulnerabilities) {
            Library lib = libMap.get(cve.getLibraryId());
            String publishDate = formatDate(cve.getPublishDate(), "yyyy-MM-dd'T'HH:mm:ss", "dd/MM/yy");
            cveMap.put(cve.getCveName() + "," + cve.getLibraryId(), new CVEReportTableRow(cve.getCveName(), cve.getSeverity().getName(), publishDate, lib.getName(), cve.getState().getName()));
        }

        for (CVEReportTableRow row : cveMap.values()) {
            if ("High".equals(row.getSeverity())) {
                osaHighCVEReportTable.add(row);
            } else if ("Medium".equals(row.getSeverity())) {
                osaMediumCVEReportTable.add(row);
            } else if ("Low".equals(row.getSeverity())) {
                osaLowCVEReportTable.add(row);
            }

        }
    }

    public void setDates(OSAScanStatus status) {
        this.scanStartTime = formatDate(status.getStartAnalyzeTime(), "yyyy-MM-dd'T'HH:mm:ss.SSSSSSS", "dd/MM/yy HH:mm");
        this.scanEndTime = formatDate(status.getEndAnalyzeTime(), "yyyy-MM-dd'T'HH:mm:ss.SSSSSSS", "dd/MM/yy HH:mm");
    }

    public void setOsaHighCVEReportTable(List osaHighCVEReportTable) {
        this.osaHighCVEReportTable = osaHighCVEReportTable;
    }

    public void setOsaMediumCVEReportTable(List osaMediumCVEReportTable) {
        this.osaMediumCVEReportTable = osaMediumCVEReportTable;
    }

    public void setOsaLowCVEReportTable(List osaLowCVEReportTable) {
        this.osaLowCVEReportTable = osaLowCVEReportTable;
    }

    public void setScanStartTime(String scanStartTime) {
        this.scanStartTime = scanStartTime;
    }

    public void setScanEndTime(String scanEndTime) {
        this.scanEndTime = scanEndTime;
    }

    public void addPolicy(Policy policy) {
        this.osaPolicies.addAll(getPolicyList(policy));
    }

    public List getOsaPolicies() {
        return osaPolicies;
    }

    public void setOsaPolicies(List osaPolicies) {
        this.osaPolicies = osaPolicies;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy