Search in sources :

Example 1 with VulnerableComponentView

use of com.blackducksoftware.integration.hub.api.generated.view.VulnerableComponentView in project hub-fortify-ssc-integration-service by blackducksoftware.

the class BlackDuckFortifyPushThread method mergeVulnerabilities.

/**
 * Iterate the hub project versions and find the vulnerabilities for Hub project version and transform the
 * vulnerability component view to CSV vulnerability view and merge all the vulnerabilities
 *
 * @param hubProjectVersions
 * @param projectVersionItems
 * @return
 * @throws IntegrationException
 * @throws IllegalArgumentException
 */
private List<Vulnerability> mergeVulnerabilities(final List<HubProjectVersion> hubProjectVersions, final List<ProjectVersionView> projectVersionItems) throws IllegalArgumentException, IntegrationException {
    int index = 0;
    List<Vulnerability> mergedVulnerabilities = new ArrayList<>();
    for (HubProjectVersion hubProjectVersion : hubProjectVersions) {
        // Get the Vulnerability information
        final List<VulnerableComponentView> vulnerableComponentViews = hubServices.getVulnerabilityComponentViews(projectVersionItems.get(index));
        index++;
        // Convert the Hub Vulnerability component view to CSV Vulnerability object
        List<Vulnerability> vulnerabilities = VulnerabilityUtil.transformMapping(vulnerableComponentViews, hubProjectVersion.getHubProject(), hubProjectVersion.getHubProjectVersion(), maxBomUpdatedDate, propertyConstants);
        // Add the vulnerabilities to the main list
        mergedVulnerabilities.addAll(vulnerabilities);
    }
    return mergedVulnerabilities;
}
Also used : HubProjectVersion(com.blackducksoftware.integration.fortify.batch.model.HubProjectVersion) ArrayList(java.util.ArrayList) Vulnerability(com.blackducksoftware.integration.fortify.batch.model.Vulnerability) VulnerableComponentView(com.blackducksoftware.integration.hub.api.generated.view.VulnerableComponentView)

Example 2 with VulnerableComponentView

use of com.blackducksoftware.integration.hub.api.generated.view.VulnerableComponentView in project hub-fortify-ssc-integration-service by blackducksoftware.

the class CSVUtilsTest method testWriteToCSV.

@Test
public void testWriteToCSV() {
    System.out.println("Executing testWriteToCSV");
    ProjectVersionView projectVersionItem = null;
    List<VulnerableComponentView> vulnerableComponentViews;
    try {
        projectVersionItem = hubServices.getProjectVersion(PROJECT_NAME, VERSION_NAME);
        vulnerableComponentViews = hubServices.getVulnerabilityComponentViews(projectVersionItem);
        bomUpdatedValueAt = hubServices.getBomLastUpdatedAt(projectVersionItem);
    } catch (final IllegalArgumentException e1) {
        e1.printStackTrace();
        throw new RuntimeException(e1);
    } catch (final IntegrationException e1) {
        e1.printStackTrace();
        throw new RuntimeException(e1);
    }
    System.out.println("vulnerableComponentViews size::" + vulnerableComponentViews.size());
    assertNotNull(vulnerableComponentViews);
    assertNotNull(bomUpdatedValueAt);
    final List<Vulnerability> vulnerabilities = VulnerabilityUtil.transformMapping(vulnerableComponentViews, PROJECT_NAME, VERSION_NAME, bomUpdatedValueAt, propertyConstants);
    System.out.println("vulnerabilities size::" + vulnerabilities.size());
    assertEquals(vulnerableComponentViews.size(), vulnerabilities.size());
    try {
        // csvUtils.writeToCSV(vulnerabilities, PROJECT_NAME + "_" + VERSION_NAME + new Date(), ',');
        CSVUtils.writeToCSV(vulnerabilities, "sample.csv", ',');
    } catch (final Exception e) {
        e.printStackTrace();
    }
}
Also used : IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) ProjectVersionView(com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView) Vulnerability(com.blackducksoftware.integration.fortify.batch.model.Vulnerability) VulnerableComponentView(com.blackducksoftware.integration.hub.api.generated.view.VulnerableComponentView) IOException(java.io.IOException) JsonIOException(com.google.gson.JsonIOException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with VulnerableComponentView

use of com.blackducksoftware.integration.hub.api.generated.view.VulnerableComponentView in project hub-fortify-ssc-integration-service by blackducksoftware.

the class HubServicesTest method getVulnerability.

@Test
public void getVulnerability() throws Exception {
    System.out.println("Executing getVulnerability");
    ProjectVersionView projectVersionItem = null;
    try {
        projectVersionItem = hubServices.getProjectVersion(PROJECT_NAME, VERSION_NAME);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IntegrationException e) {
        e.printStackTrace();
    }
    List<VulnerableComponentView> vulnerableComponentViews = hubServices.getVulnerabilityComponentViews(projectVersionItem);
    System.out.println("vulnerableComponentViews size::" + vulnerableComponentViews.size() + ", vulnerableComponentViews::" + vulnerableComponentViews);
    assertNotNull(vulnerableComponentViews);
}
Also used : IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) ProjectVersionView(com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView) VulnerableComponentView(com.blackducksoftware.integration.hub.api.generated.view.VulnerableComponentView) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

VulnerableComponentView (com.blackducksoftware.integration.hub.api.generated.view.VulnerableComponentView)3 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)2 Vulnerability (com.blackducksoftware.integration.fortify.batch.model.Vulnerability)2 ProjectVersionView (com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView)2 Test (org.junit.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 HubProjectVersion (com.blackducksoftware.integration.fortify.batch.model.HubProjectVersion)1 JsonIOException (com.google.gson.JsonIOException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1