Search in sources :

Example 1 with PolicyStatusView

use of com.synopsys.integration.blackduck.api.generated.deprecated.view.PolicyStatusView in project synopsys-detect by blackducksoftware.

the class ReportService method getRiskReportData.

public ReportData getRiskReportData(ProjectView project, ProjectVersionView version) throws IntegrationException {
    ReportData reportData = new ReportData();
    reportData.setProjectName(project.getName());
    reportData.setProjectURL(project.getHref().string());
    reportData.setProjectVersion(version.getVersionName());
    reportData.setProjectVersionURL(getReportVersionUrl(version));
    reportData.setPhase(version.getPhase().toString());
    reportData.setDistribution(version.getDistribution().toString());
    List<BomComponent> components = new ArrayList<>();
    logger.trace("Getting the Report Contents using the Aggregate Bom Rest Server");
    List<ProjectVersionComponentVersionView> bomEntries;
    try {
        bomEntries = blackDuckApiClient.getAllResponses(version.metaComponentsLink());
    } catch (NoSuchElementException e) {
        throw new BlackDuckIntegrationException("BOM could not be read.  This is likely because you lack sufficient permissions.  Please check your permissions.");
    }
    HttpUrl originalVersionUrl = version.getHref();
    boolean policyFailure = false;
    for (ProjectVersionComponentVersionView projectVersionComponentView : bomEntries) {
        String policyStatus = projectVersionComponentView.getApprovalStatus().toString();
        if (StringUtils.isBlank(policyStatus)) {
            HttpUrl componentPolicyStatusURL;
            if (!StringUtils.isBlank(projectVersionComponentView.getComponentVersion())) {
                componentPolicyStatusURL = getComponentPolicyURL(originalVersionUrl, projectVersionComponentView.getComponentVersion());
            } else {
                componentPolicyStatusURL = getComponentPolicyURL(originalVersionUrl, projectVersionComponentView.getComponent());
            }
            if (!policyFailure) {
                // FIXME if we could check if Black Duck has the policy module we could remove a lot of the mess
                try {
                    PolicyStatusView bomPolicyStatus = blackDuckApiClient.getResponse(componentPolicyStatusURL, PolicyStatusView.class);
                    policyStatus = bomPolicyStatus.getApprovalStatus().toString();
                } catch (IntegrationException e) {
                    policyFailure = true;
                    logger.debug("Could not get the component policy status, the Black Duck policy module is not enabled");
                }
            }
        }
        BomComponent component = createBomComponentFromBomComponentView(projectVersionComponentView);
        component.setPolicyStatus(policyStatus);
        populatePolicyRuleInfo(component, projectVersionComponentView);
        components.add(component);
    }
    reportData.setComponents(components);
    LocalDateTime dateTime = getDateTimeOfLatestScanForProjectVersion(version, project.getName());
    reportData.setDateTimeOfLatestScan(dateTime);
    return reportData;
}
Also used : LocalDateTime(java.time.LocalDateTime) BomComponent(com.synopsys.integration.detect.workflow.blackduck.report.BomComponent) PolicyStatusView(com.synopsys.integration.blackduck.api.generated.deprecated.view.PolicyStatusView) IntegrationException(com.synopsys.integration.exception.IntegrationException) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) ArrayList(java.util.ArrayList) HttpUrl(com.synopsys.integration.rest.HttpUrl) ReportData(com.synopsys.integration.detect.workflow.blackduck.report.ReportData) NoSuchElementException(java.util.NoSuchElementException) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)

Aggregations

PolicyStatusView (com.synopsys.integration.blackduck.api.generated.deprecated.view.PolicyStatusView)1 ProjectVersionComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)1 BlackDuckIntegrationException (com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException)1 BomComponent (com.synopsys.integration.detect.workflow.blackduck.report.BomComponent)1 ReportData (com.synopsys.integration.detect.workflow.blackduck.report.ReportData)1 IntegrationException (com.synopsys.integration.exception.IntegrationException)1 HttpUrl (com.synopsys.integration.rest.HttpUrl)1 LocalDateTime (java.time.LocalDateTime)1 ArrayList (java.util.ArrayList)1 NoSuchElementException (java.util.NoSuchElementException)1