Search in sources :

Example 6 with ProjectView

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

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

the class BlackDuckDataSyncTask method getEmailsPerProject.

private Map<ProviderProject, Set<String>> getEmailsPerProject(Map<ProjectView, ProviderProject> blackDuckToAlertProjects, ProjectUsersService projectUsersService) {
    Map<ProviderProject, Set<String>> projectToEmailAddresses = new ConcurrentHashMap<>();
    blackDuckToAlertProjects.entrySet().parallelStream().forEach(entry -> {
        try {
            ProjectView blackDuckProjectView = entry.getKey();
            ProviderProject alertProject = entry.getValue();
            Set<String> projectUserEmailAddresses = projectUsersService.getAllActiveUsersForProject(blackDuckProjectView).stream().filter(UserView::getActive).map(UserView::getEmail).filter(StringUtils::isNotBlank).collect(Collectors.toSet());
            if (StringUtils.isNotBlank(alertProject.getProjectOwnerEmail())) {
                projectUserEmailAddresses.add(alertProject.getProjectOwnerEmail());
            }
            projectToEmailAddresses.put(alertProject, projectUserEmailAddresses);
        } catch (IntegrationException e) {
            // We do this to break out of the stream
            throw new AlertRuntimeException(e.getMessage(), e);
        }
    });
    return projectToEmailAddresses;
}
Also used : Set(java.util.Set) IntegrationException(com.synopsys.integration.exception.IntegrationException) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 8 with ProjectView

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

the class BlackDuckProviderDataAccessor method getProjectsForProvider.

private List<ProviderProject> getProjectsForProvider(ConfigurationModel blackDuckConfigurationModel) throws IntegrationException {
    BlackDuckServicesFactory blackDuckServicesFactory = createBlackDuckServicesFactory(blackDuckConfigurationModel);
    ProjectService projectService = blackDuckServicesFactory.createProjectService();
    List<ProjectView> allProjects = projectService.getAllProjects();
    return convertBlackDuckProjects(allProjects, blackDuckServicesFactory.getBlackDuckApiClient());
}
Also used : ProjectService(com.synopsys.integration.blackduck.service.dataservice.ProjectService) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView)

Example 9 with ProjectView

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

the class BlackDuckProviderDataAccessor method getEmailAddressesForProjectHref.

@Override
public Set<String> getEmailAddressesForProjectHref(Long providerConfigId, String projectHref) {
    Optional<ConfigurationModel> providerConfigOptional = configurationModelConfigurationAccessor.getConfigurationById(providerConfigId);
    if (providerConfigOptional.isPresent()) {
        try {
            BlackDuckServicesFactory blackDuckServicesFactory = createBlackDuckServicesFactory(providerConfigOptional.get());
            BlackDuckApiClient blackDuckService = blackDuckServicesFactory.getBlackDuckApiClient();
            ProjectView projectView = blackDuckService.getResponse(new HttpUrl(projectHref), ProjectView.class);
            return getEmailAddressesForProject(projectView, blackDuckServicesFactory.createProjectUsersService());
        } catch (IntegrationException e) {
            logger.errorAndDebug(createProjectNotFoundString(providerConfigId, e.getMessage()), e);
        }
    }
    return Set.of();
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) IntegrationException(com.synopsys.integration.exception.IntegrationException) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) HttpUrl(com.synopsys.integration.rest.HttpUrl)

Example 10 with ProjectView

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

the class BlackDuckProviderDataAccessor method getProjectByHref.

@Override
public Optional<ProviderProject> getProjectByHref(Long providerConfigId, String projectHref) {
    try {
        Optional<ConfigurationModel> providerConfigOptional = configurationModelConfigurationAccessor.getConfigurationById(providerConfigId);
        if (providerConfigOptional.isPresent()) {
            BlackDuckServicesFactory blackDuckServicesFactory = createBlackDuckServicesFactory(providerConfigOptional.get());
            BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
            ProjectView foundProject = blackDuckApiClient.getResponse(new HttpUrl(projectHref), ProjectView.class);
            return convertBlackDuckProjects(List.of(foundProject), blackDuckApiClient).stream().findFirst();
        }
    } catch (IntegrationException e) {
        logger.errorAndDebug(createProjectNotFoundString(providerConfigId, e.getMessage()), e);
    }
    return Optional.empty();
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) IntegrationException(com.synopsys.integration.exception.IntegrationException) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) HttpUrl(com.synopsys.integration.rest.HttpUrl)

Aggregations

ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)21 HttpUrl (com.synopsys.integration.rest.HttpUrl)15 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)9 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)8 IntegrationException (com.synopsys.integration.exception.IntegrationException)7 ProviderProject (com.synopsys.integration.alert.common.persistence.model.ProviderProject)6 ProjectVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView)6 Test (org.junit.jupiter.api.Test)5 ResourceMetadata (com.synopsys.integration.blackduck.api.core.ResourceMetadata)4 UserView (com.synopsys.integration.blackduck.api.generated.view.UserView)4 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)3 ApiDiscovery (com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery)3 AlertRuntimeException (com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)2 BlackDuckProperties (com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties)2 ResourceLink (com.synopsys.integration.blackduck.api.core.ResourceLink)2 BlackDuckPageDefinition (com.synopsys.integration.blackduck.http.BlackDuckPageDefinition)2 BlackDuckPageResponse (com.synopsys.integration.blackduck.http.BlackDuckPageResponse)2 BlackDuckRequestBuilder (com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder)2 ProjectUsersService (com.synopsys.integration.blackduck.service.dataservice.ProjectUsersService)2 ProjectVersionWrapper (com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)2