Search in sources :

Example 16 with BlackDuckServicesFactory

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

the class BlackDuckIssueTrackerCallbackEventHandler method handle.

@Override
public void handle(IssueTrackerCallbackEvent event) {
    String eventId = event.getEventId();
    logger.debug("Handling issue-tracker callback event with id '{}'", eventId);
    IssueTrackerCallbackInfo callbackInfo = event.getCallbackInfo();
    Optional<BlackDuckServicesFactory> optionalBlackDuckServicesFactory = createBlackDuckProperties(callbackInfo.getProviderConfigId()).flatMap(this::createBlackDuckServicesFactory);
    if (optionalBlackDuckServicesFactory.isPresent()) {
        BlackDuckServicesFactory blackDuckServicesFactory = optionalBlackDuckServicesFactory.get();
        BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
        IssueService blackDuckIssueService = blackDuckServicesFactory.createIssueService();
        BlackDuckProviderIssueHandler blackDuckProviderIssueHandler = new BlackDuckProviderIssueHandler(gson, blackDuckApiClient, blackDuckIssueService);
        BlackDuckProviderIssueModel issueModel = createBlackDuckIssueModel(event);
        createOrUpdateBlackDuckIssue(blackDuckProviderIssueHandler, issueModel, callbackInfo);
    }
    logger.debug("Finished handling issue-tracker callback event with id '{}'", eventId);
}
Also used : IssueService(com.synopsys.integration.blackduck.service.dataservice.IssueService) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) IssueTrackerCallbackInfo(com.synopsys.integration.alert.common.channel.issuetracker.message.IssueTrackerCallbackInfo) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)

Example 17 with BlackDuckServicesFactory

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

the class AbstractBlackDuckComponentConcernMessageExtractor method extract.

@Override
protected final ProviderMessageHolder extract(NotificationContentWrapper notificationContentWrapper, T notificationContent) {
    AlertNotificationModel notificationModel = notificationContentWrapper.getAlertNotificationModel();
    Long providerConfigId = notificationModel.getProviderConfigId();
    String providerUrl;
    List<BomComponentDetails> bomComponentDetails;
    try {
        BlackDuckServicesFactory blackDuckServicesFactory = servicesFactoryCache.retrieveBlackDuckServicesFactory(providerConfigId);
        providerUrl = blackDuckServicesFactory.getBlackDuckHttpClient().getBlackDuckUrl().string();
        bomComponentDetails = createBomComponentDetails(notificationContent, blackDuckServicesFactory);
    } catch (AlertConfigurationException e) {
        logger.warn("Invalid BlackDuck configuration for notification. ID: {}. Name: {}", providerConfigId, notificationModel.getProviderConfigName(), e);
        return ProviderMessageHolder.empty();
    } catch (IntegrationException e) {
        logger.warn("Failed to retrieve BOM Component(s) from BlackDuck", e);
        return ProviderMessageHolder.empty();
    }
    LinkableItem providerItem = new LinkableItem(blackDuckProviderKey.getDisplayName(), notificationModel.getProviderConfigName(), providerUrl);
    ProviderDetails providerDetails = new ProviderDetails(notificationModel.getProviderConfigId(), providerItem);
    Optional<String> projectUrl = extractProjectUrl(notificationContent.getProjectVersionUrl());
    LinkableItem project = new LinkableItem(BlackDuckMessageLabels.LABEL_PROJECT, notificationContent.getProjectName(), projectUrl.orElse(null));
    LinkableItem projectVersion = new LinkableItem(BlackDuckMessageLabels.LABEL_PROJECT_VERSION, notificationContent.getProjectVersionName(), notificationContent.getProjectVersionUrl());
    // FIXME this is where I should put the additional info
    ProjectMessage projectMessage = createProjectMessage(providerDetails, project, projectVersion, bomComponentDetails);
    return new ProviderMessageHolder(List.of(projectMessage), List.of());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) IntegrationException(com.synopsys.integration.exception.IntegrationException) ProviderDetails(com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) ProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder) BomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)

Example 18 with BlackDuckServicesFactory

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

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

the class BlackDuckSSOConfigRetriever method fromProperties.

public static BlackDuckSSOConfigRetriever fromProperties(BlackDuckProperties blackDuckProperties) throws AlertException {
    Logger logger = LoggerFactory.getLogger(BlackDuckSSOConfigRetriever.class);
    Slf4jIntLogger intLogger = new Slf4jIntLogger(logger);
    BlackDuckHttpClient blackDuckHttpClient = blackDuckProperties.createBlackDuckHttpClient(intLogger);
    BlackDuckServicesFactory blackDuckServicesFactory = blackDuckProperties.createBlackDuckServicesFactory(blackDuckHttpClient, intLogger);
    return new BlackDuckSSOConfigRetriever(blackDuckServicesFactory.getApiDiscovery(), blackDuckServicesFactory.getBlackDuckApiClient());
}
Also used : Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) Logger(org.slf4j.Logger)

Example 20 with BlackDuckServicesFactory

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

the class BlackDuckProjectExistencePopulator method createBlackDuckApiClient.

private BlackDuckApiClient createBlackDuckApiClient(ConfigurationModel providerGlobalConfig) throws AlertException {
    StatefulProvider statefulProvider = blackDuckProvider.createStatefulProvider(providerGlobalConfig);
    BlackDuckProperties blackDuckProperties = (BlackDuckProperties) statefulProvider.getProperties();
    IntLogger intLogger = new Slf4jIntLogger(logger);
    BlackDuckHttpClient blackDuckHttpClient = blackDuckProperties.createBlackDuckHttpClient(intLogger);
    BlackDuckServicesFactory blackDuckServicesFactory = blackDuckProperties.createBlackDuckServicesFactory(blackDuckHttpClient, intLogger);
    return blackDuckServicesFactory.getBlackDuckApiClient();
}
Also used : Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) IntLogger(com.synopsys.integration.log.IntLogger) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) StatefulProvider(com.synopsys.integration.alert.api.provider.state.StatefulProvider)

Aggregations

BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)47 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)30 HttpUrl (com.synopsys.integration.rest.HttpUrl)27 Test (org.junit.jupiter.api.Test)20 BomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)16 BlackDuckHttpClient (com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient)15 ProjectVersionComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)12 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)12 IntegrationException (com.synopsys.integration.exception.IntegrationException)12 ComponentUpgradeGuidance (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance)11 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)10 Slf4jIntLogger (com.synopsys.integration.log.Slf4jIntLogger)9 IntegrationRestException (com.synopsys.integration.rest.exception.IntegrationRestException)8 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)7 ApiDiscovery (com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery)7 ProjectVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView)6 UserView (com.synopsys.integration.blackduck.api.generated.view.UserView)6 ProjectUsersService (com.synopsys.integration.blackduck.service.dataservice.ProjectUsersService)6 IntLogger (com.synopsys.integration.log.IntLogger)6 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)5