Search in sources :

Example 46 with BlackDuckApiClient

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

the class JobNotificationProcessorTest method createRuleViolationNotificationMessageExtractor.

private RuleViolationNotificationMessageExtractor createRuleViolationNotificationMessageExtractor() throws IntegrationException {
    BlackDuckProviderKey providerKey = new BlackDuckProviderKey();
    NotificationExtractorBlackDuckServicesFactoryCache servicesFactoryCache = Mockito.mock(NotificationExtractorBlackDuckServicesFactoryCache.class);
    BlackDuckPolicySeverityConverter blackDuckPolicySeverityConverter = new BlackDuckPolicySeverityConverter();
    BlackDuckPolicyComponentConcernCreator blackDuckPolicyComponentConcernCreator = new BlackDuckPolicyComponentConcernCreator(blackDuckPolicySeverityConverter);
    BlackDuckComponentVulnerabilityDetailsCreator vulnerabilityDetailsCreator = new BlackDuckComponentVulnerabilityDetailsCreator();
    BlackDuckComponentPolicyDetailsCreatorFactory blackDuckComponentPolicyDetailsCreatorFactory = new BlackDuckComponentPolicyDetailsCreatorFactory(blackDuckPolicySeverityConverter);
    BlackDuckMessageBomComponentDetailsCreatorFactory detailsCreatorFactory = new BlackDuckMessageBomComponentDetailsCreatorFactory(vulnerabilityDetailsCreator, blackDuckComponentPolicyDetailsCreatorFactory);
    // Mocks for AbstractRuleViolationNotificationMessageExtractor
    BlackDuckServicesFactory blackDuckServicesFactory = Mockito.mock(BlackDuckServicesFactory.class);
    BlackDuckHttpClient blackDuckHttpClient = Mockito.mock(BlackDuckHttpClient.class);
    Mockito.when(servicesFactoryCache.retrieveBlackDuckServicesFactory(Mockito.any())).thenReturn(blackDuckServicesFactory);
    Mockito.when(blackDuckServicesFactory.getBlackDuckHttpClient()).thenReturn(blackDuckHttpClient);
    Mockito.when(blackDuckHttpClient.getBlackDuckUrl()).thenReturn(new HttpUrl(PROVIDER_DETAILS.getProvider().getUrl().get()));
    BlackDuckApiClient blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
    Mockito.when(blackDuckServicesFactory.getBlackDuckApiClient()).thenReturn(blackDuckApiClient);
    ProjectVersionComponentVersionView projectVersionComponentVersionView = blackDuckResponseTestUtility.createProjectVersionComponentVersionView();
    Mockito.when(blackDuckApiClient.getResponse(Mockito.any(), Mockito.eq(ProjectVersionComponentVersionView.class))).thenReturn(projectVersionComponentVersionView);
    BomComponent404Handler bomComponent404Handler = new BomComponent404Handler();
    return new RuleViolationNotificationMessageExtractor(providerKey, servicesFactoryCache, blackDuckPolicyComponentConcernCreator, detailsCreatorFactory, bomComponent404Handler);
}
Also used : BlackDuckProviderKey(com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey) BlackDuckPolicyComponentConcernCreator(com.synopsys.integration.alert.provider.blackduck.processor.message.service.policy.BlackDuckPolicyComponentConcernCreator) BlackDuckComponentPolicyDetailsCreatorFactory(com.synopsys.integration.alert.provider.blackduck.processor.message.service.policy.BlackDuckComponentPolicyDetailsCreatorFactory) BomComponent404Handler(com.synopsys.integration.alert.provider.blackduck.processor.message.service.BomComponent404Handler) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) NotificationExtractorBlackDuckServicesFactoryCache(com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) HttpUrl(com.synopsys.integration.rest.HttpUrl) BlackDuckMessageBomComponentDetailsCreatorFactory(com.synopsys.integration.alert.provider.blackduck.processor.message.service.BlackDuckMessageBomComponentDetailsCreatorFactory) BlackDuckComponentVulnerabilityDetailsCreator(com.synopsys.integration.alert.provider.blackduck.processor.message.service.BlackDuckComponentVulnerabilityDetailsCreator) BlackDuckPolicySeverityConverter(com.synopsys.integration.alert.provider.blackduck.processor.message.service.policy.BlackDuckPolicySeverityConverter) RuleViolationNotificationMessageExtractor(com.synopsys.integration.alert.provider.blackduck.processor.message.RuleViolationNotificationMessageExtractor) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)

Example 47 with BlackDuckApiClient

use of com.synopsys.integration.blackduck.service.BlackDuckApiClient 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

BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)47 HttpUrl (com.synopsys.integration.rest.HttpUrl)36 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)28 Test (org.junit.jupiter.api.Test)24 ProjectVersionComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)21 BomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)19 ComponentUpgradeGuidance (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance)14 IntegrationRestException (com.synopsys.integration.rest.exception.IntegrationRestException)13 IntegrationException (com.synopsys.integration.exception.IntegrationException)10 ApiDiscovery (com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery)9 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)9 ResourceMetadata (com.synopsys.integration.blackduck.api.core.ResourceMetadata)7 UrlSingleResponse (com.synopsys.integration.blackduck.api.core.response.UrlSingleResponse)7 PolicyRuleView (com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView)7 ComponentPolicy (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentPolicy)6 ComponentVersionUpgradeGuidanceView (com.synopsys.integration.blackduck.api.generated.response.ComponentVersionUpgradeGuidanceView)6 ComponentPolicyRulesView (com.synopsys.integration.blackduck.api.generated.view.ComponentPolicyRulesView)6 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)5 BlackDuckMessageBomComponentDetailsCreator (com.synopsys.integration.alert.provider.blackduck.processor.message.service.BlackDuckMessageBomComponentDetailsCreator)5 ProjectVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView)5