Search in sources :

Example 6 with ProjectVersionView

use of com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView in project hub-alert by blackducksoftware.

the class BomEditNotificationDetailExtractorTest method createCache.

private NotificationExtractorBlackDuckServicesFactoryCache createCache(Long blackDuckConfigId, String projectName, String projectVersionName) throws IntegrationException {
    ProjectView projectView = Mockito.mock(ProjectView.class);
    Mockito.when(projectView.getName()).thenReturn(projectName);
    ProjectVersionView projectVersionView = Mockito.mock(ProjectVersionView.class);
    Mockito.when(projectVersionView.getVersionName()).thenReturn(projectVersionName);
    BlackDuckApiClient blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
    Mockito.when(blackDuckApiClient.getResponse(Mockito.any(HttpUrl.class), Mockito.eq(ProjectVersionView.class))).thenReturn(projectVersionView);
    Mockito.when(blackDuckApiClient.getResponse(Mockito.eq(projectVersionView.metaProjectLink()))).thenReturn(projectView);
    BlackDuckServicesFactory blackDuckServicesFactory = Mockito.mock(BlackDuckServicesFactory.class);
    Mockito.when(blackDuckServicesFactory.getBlackDuckApiClient()).thenReturn(blackDuckApiClient);
    NotificationExtractorBlackDuckServicesFactoryCache cache = Mockito.mock(NotificationExtractorBlackDuckServicesFactoryCache.class);
    Mockito.when(cache.retrieveBlackDuckServicesFactory(Mockito.eq(blackDuckConfigId))).thenReturn(blackDuckServicesFactory);
    return cache;
}
Also used : ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) NotificationExtractorBlackDuckServicesFactoryCache(com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) HttpUrl(com.synopsys.integration.rest.HttpUrl)

Example 7 with ProjectVersionView

use of com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView 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 8 with ProjectVersionView

use of com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView 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)8 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)6 HttpUrl (com.synopsys.integration.rest.HttpUrl)6 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)5 IntegrationException (com.synopsys.integration.exception.IntegrationException)4 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)3 ProjectVersionWrapper (com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)3 BlackDuckPageResponse (com.synopsys.integration.blackduck.http.BlackDuckPageResponse)2 BlackDuckRequestBuilder (com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder)2 Test (org.junit.jupiter.api.Test)2 Gson (com.google.gson.Gson)1 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)1 DetailedNotificationContent (com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent)1 NotificationExtractorBlackDuckServicesFactoryCache (com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache)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 ProjectVersionIssuesView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionIssuesView)1 BomEditNotificationContent (com.synopsys.integration.blackduck.api.manual.component.BomEditNotificationContent)1 IssueRequest (com.synopsys.integration.blackduck.api.manual.temporary.component.IssueRequest)1