Search in sources :

Example 1 with ProjectVersionWrapper

use of com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper in project hub-alert by blackducksoftware.

the class BomEditNotificationDetailExtractor method extractDetailedContent.

@Override
public List<DetailedNotificationContent> extractDetailedContent(AlertNotificationModel alertNotificationModel, BomEditNotificationView notificationView) {
    BomEditNotificationContent notificationContent = notificationView.getContent();
    Optional<ProjectVersionWrapper> optionalProjectAndVersion = retrieveProjectAndVersion(alertNotificationModel.getProviderConfigId(), notificationContent.getProjectVersion());
    if (optionalProjectAndVersion.isPresent()) {
        ProjectVersionWrapper projectAndVersion = optionalProjectAndVersion.get();
        ProjectView project = projectAndVersion.getProjectView();
        ProjectVersionView projectVersion = projectAndVersion.getProjectVersionView();
        String projectName = project.getName();
        BomEditWithProjectNameNotificationContent updatedNotificationContent = new BomEditWithProjectNameNotificationContent(notificationContent, projectName, projectVersion.getVersionName());
        DetailedNotificationContent detailedContent = DetailedNotificationContent.project(alertNotificationModel, updatedNotificationContent, projectName, projectVersion.getVersionName());
        return List.of(detailedContent);
    }
    return List.of();
}
Also used : BomEditNotificationContent(com.synopsys.integration.blackduck.api.manual.component.BomEditNotificationContent) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) DetailedNotificationContent(com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) BomEditWithProjectNameNotificationContent(com.synopsys.integration.alert.provider.blackduck.processor.model.BomEditWithProjectNameNotificationContent) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)

Example 2 with ProjectVersionWrapper

use of com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper in project hub-alert by blackducksoftware.

the class BomEditNotificationDetailExtractor method retrieveProjectAndVersion.

private Optional<ProjectVersionWrapper> retrieveProjectAndVersion(Long blackDuckConfigId, String projectVersionUrl) {
    try {
        BlackDuckServicesFactory blackDuckServicesFactory = servicesFactoryCache.retrieveBlackDuckServicesFactory(blackDuckConfigId);
        BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
        ProjectVersionView projectVersion = blackDuckApiClient.getResponse(new HttpUrl(projectVersionUrl), ProjectVersionView.class);
        ProjectView projectView = blackDuckApiClient.getResponse(projectVersion.metaProjectLink());
        return Optional.of(new ProjectVersionWrapper(projectView, projectVersion));
    } catch (IntegrationException e) {
        logger.error("Failed to connect to BlackDuck. Config ID: {}", blackDuckConfigId, e);
    }
    return Optional.empty();
}
Also used : IntegrationException(com.synopsys.integration.exception.IntegrationException) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) HttpUrl(com.synopsys.integration.rest.HttpUrl)

Example 3 with ProjectVersionWrapper

use of com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper in project hub-alert by blackducksoftware.

the class BlackDuckProviderService method triggerBlackDuckNotification.

public void triggerBlackDuckNotification(Supplier<ExternalId> externalIdSupplier, Predicate<ProjectVersionComponentVersionView> componentFilter) throws IntegrationException {
    setupBlackDuckServicesFactory();
    BlackDuckApiClient blackDuckService = blackDuckServicesFactory.getBlackDuckApiClient();
    ProjectService projectService = blackDuckServicesFactory.createProjectService();
    ProjectVersionWrapper projectVersion = projectService.getProjectVersion(blackDuckProjectName, blackDuckProjectVersion).orElseThrow(() -> new IntegrationException(String.format("Could not find the Black Duck project '%s' version '%s'", blackDuckProjectName, blackDuckProjectVersion)));
    ProjectVersionView projectVersionView = projectVersion.getProjectVersionView();
    List<ProjectVersionComponentVersionView> bomComponents = blackDuckService.getAllResponses(projectVersionView.metaComponentsLink());
    Optional<ProjectVersionComponentVersionView> apacheCommonsFileUpload = bomComponents.stream().filter(componentFilter).findFirst();
    if (apacheCommonsFileUpload.isPresent()) {
        blackDuckService.delete(apacheCommonsFileUpload.get());
    // Thread.currentThread().wait(1000);
    }
    ExternalId externalId = externalIdSupplier.get();
    ProjectBomService projectBomService = blackDuckServicesFactory.createProjectBomService();
    projectBomService.addComponentToProjectVersion(externalId, projectVersionView);
}
Also used : IntegrationException(com.synopsys.integration.exception.IntegrationException) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) ProjectService(com.synopsys.integration.blackduck.service.dataservice.ProjectService) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) ProjectBomService(com.synopsys.integration.blackduck.service.dataservice.ProjectBomService) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)

Aggregations

ProjectVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView)3 ProjectVersionWrapper (com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)3 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)2 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)2 IntegrationException (com.synopsys.integration.exception.IntegrationException)2 DetailedNotificationContent (com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent)1 BomEditWithProjectNameNotificationContent (com.synopsys.integration.alert.provider.blackduck.processor.model.BomEditWithProjectNameNotificationContent)1 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)1 ProjectVersionComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)1 BomEditNotificationContent (com.synopsys.integration.blackduck.api.manual.component.BomEditNotificationContent)1 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)1 ProjectBomService (com.synopsys.integration.blackduck.service.dataservice.ProjectBomService)1 ProjectService (com.synopsys.integration.blackduck.service.dataservice.ProjectService)1 HttpUrl (com.synopsys.integration.rest.HttpUrl)1