data7-master/data7/src/main/java/data7/model/vulnerability/Vulnerability.java
package data7.model.vulnerability;

/*-
 * #%L
 * Data7
 * %%
 * Copyright (C) 2018 University of Luxembourg, Matthieu Jimenez
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */



import data7.importer.sources.cve.CVE;
import data7.model.change.Commit;

import java.io.Serializable;
import java.util.*;

/**
 * Vulnerability
 * class that integrate all available information on a given vulnerability
 */
public class Vulnerability implements Serializable {

    private static final long serialVersionUID = 20181011L;

    //Map that contains all commits that fixed the vulnerability
    private final Map<String,Map<String, Commit>> patchingCommits;
    //CVE number that was given to this vulnerability
    private final String cve;
    //description of the vulnerability from the cve database
    private final String description;
    //List of Bug Ids that correspond to this vulnerability and for which it was possible to retrieve the commits
    private Map<String,Set<String>> bugIds;
    //timestamp of vulnerability last modification
    private long lastModified;
    //CWE number of the vulnerability (null if not existing)
    private String cwe;
    //vulnerability severity score
    private String score;
    //first apparition of the vulnerability
    private final long creationTime;
    //list of impacted version
    private final Set<String> versions;

    /**
     * Scratch constructo
     *
     * @param cve
     * @param description
     * @param lastModified
     * @param creationTime
     * @param versions
     */
    public Vulnerability(String cve, String description, long lastModified, long creationTime, Set<String> versions) {
        this.creationTime = creationTime;
        this.patchingCommits = new HashMap<>();
        this.cve = cve;
        this.description = description;
        this.lastModified = lastModified;
        bugIds = new HashMap<>();
        cwe = null;
        score = null;
        this.versions = versions;
    }

    /**
     * Constructor from a CVE object
     *
     * @param cve object
     * @see CVE
     */
    public Vulnerability(CVE cve) {
        this.patchingCommits = new HashMap<>();
        this.cve = cve.getCVE();
        this.description = cve.getDescription();
        this.lastModified = cve.getLastModified();
        this.creationTime = cve.getCreationTime();
        bugIds = new HashMap<>();
        cwe = cve.getCWE();
        score = cve.getScore();
        versions = cve.getImpactedVersions();
    }

    /**
     * @return the type of the vulnerability according to the cwe classification
     * @see <a href="https://cwe.mitre.org">change weakness enumeration</a>
     */
    public String getCwe() {
        return cwe;
    }

    /**
     * @return the list of commit that patched the vulnerability
     * @see Commit
     */
    public Map<String,Map<String, Commit>> getPatchingCommits() {
        return patchingCommits;
    }

    /**
     * @return the cve identifier of the vulnerability
     * @see <a href="https://cve.mitre.org">change vulnerabilities and exposure</a>
     */
    public String getCve() {
        return cve;
    }

    /**
     * @return the description of the vulnerability according to the cve database
     */
    public String getDescription() {
        return description;
    }

    /**
     * @return the timestamp of the vulnerability last modification
     */
    public long getLastModified() {
        return lastModified;
    }

    /**
     * @return the severity score (cvss) of the vulnerability according to the nvd database
     * @see <a href="https://nvd.nist.gov/vuln-metrics/cvss">Common Vulnerability Scoring System (CVSS)</a>
     */
    public String getScore() {
        return score;
    }

    /**
     * Setter for the last modified field
     *
     * @param lastModified
     */
    public void setLastModified(long lastModified) {
        this.lastModified = lastModified;
    }

    /**
     * Setter for the CWE field
     *
     * @param cwe
     */
    public void setCwe(String cwe) {
        this.cwe = cwe;
    }

    /**
     * Setter for the score field
     *
     * @param score
     */
    public void setScore(String score) {
        this.score = score;
    }

    public Map<String,Set<String>> getBugIds() {
        return bugIds;
    }

    public long getCreationTime() {
        return creationTime;
    }

    public Set<String> getVersions() {
        return versions;
    }
}
