Search in sources :

Example 1 with ProjectVersionReportView

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

the class ReportService method isReportFinishedGenerating.

/**
 * Checks the report URL every 5 seconds until the report has a finished time available, then we know it is done being generated. Throws BlackDuckIntegrationException after 30 minutes if the report has not been generated yet.
 */
public ProjectVersionReportView isReportFinishedGenerating(HttpUrl reportUrl) throws InterruptedException, IntegrationException {
    long startTime = System.currentTimeMillis();
    long elapsedTime = 0;
    Date timeFinished = null;
    ProjectVersionReportView reportInfo = null;
    while (timeFinished == null) {
        reportInfo = blackDuckApiClient.getResponse(reportUrl, ProjectVersionReportView.class);
        timeFinished = reportInfo.getFinishedAt();
        if (timeFinished != null) {
            break;
        }
        if (elapsedTime >= timeoutInMilliseconds) {
            String formattedTime = String.format("%d minutes", TimeUnit.MILLISECONDS.toMinutes(timeoutInMilliseconds));
            throw new BlackDuckIntegrationException("The Report has not finished generating in : " + formattedTime);
        }
        // Retry every 5 seconds
        Thread.sleep(5000);
        elapsedTime = System.currentTimeMillis() - startTime;
    }
    return reportInfo;
}
Also used : ProjectVersionReportView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionReportView) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) Date(java.util.Date)

Example 2 with ProjectVersionReportView

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

the class ReportService method generateBlackDuckNoticesReport.

/**
 * Assumes the BOM has already been updated
 */
public String generateBlackDuckNoticesReport(ProjectVersionView version, ReportFormatType reportFormat) throws InterruptedException, IntegrationException {
    if (version.hasLink(ProjectVersionView.LICENSE_REPORTS_LINK)) {
        try {
            logger.debug("Starting the Notices Report generation.");
            HttpUrl reportUrl = startGeneratingBlackDuckNoticesReport(version, reportFormat);
            logger.debug("Waiting for the Notices Report to complete.");
            ProjectVersionReportView reportInfo = isReportFinishedGenerating(reportUrl);
            HttpUrl contentUrl = reportInfo.getFirstLink(ReportView.CONTENT_LINK);
            if (contentUrl == null) {
                throw new BlackDuckIntegrationException("Could not find content link for the report at : " + reportUrl);
            }
            logger.debug("Getting the Notices Report content.");
            String noticesReport = getNoticesReportContent(contentUrl);
            logger.debug("Finished retrieving the Notices Report.");
            logger.debug("Cleaning up the Notices Report on the server.");
            deleteBlackDuckReport(reportUrl);
            return noticesReport;
        } catch (IntegrationRestException e) {
            if (e.getHttpStatusCode() == 402) {
                // unlike the policy module, the licenseReports link is still present when the module is not enabled
                logger.warn("Can not create the notice report, the Black Duck notice module is not enabled.");
            } else {
                throw e;
            }
        }
    } else {
        logger.warn("Can not create the notice report, the Black Duck notice module is not enabled.");
    }
    return null;
}
Also used : IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException) ProjectVersionReportView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionReportView) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) HttpUrl(com.synopsys.integration.rest.HttpUrl)

Aggregations

ProjectVersionReportView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionReportView)2 BlackDuckIntegrationException (com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException)2 HttpUrl (com.synopsys.integration.rest.HttpUrl)1 IntegrationRestException (com.synopsys.integration.rest.exception.IntegrationRestException)1 Date (java.util.Date)1