use of com.synopsys.integration.blackduck.service.BlackDuckApiClient in project hub-alert by blackducksoftware.
the class BlackDuckProjectExistencePopulator method populateJobProviderProjects.
private void populateJobProviderProjects(ConfigurationModel providerGlobalConfig, List<JobProviderProjectFieldModel> configuredProviderProjects) {
BlackDuckApiClient blackDuckApiClient;
try {
blackDuckApiClient = createBlackDuckApiClient(providerGlobalConfig);
} catch (AlertException e) {
logger.debug("Failed to initialize BlackDuck services", e);
return;
}
for (JobProviderProjectFieldModel project : configuredProviderProjects) {
boolean exists = doesProjectExist(blackDuckApiClient, project);
project.setMissing(!exists);
}
}
use of com.synopsys.integration.blackduck.service.BlackDuckApiClient in project hub-alert by blackducksoftware.
the class BlackDuckProviderDataAccessor method getEmailAddressesByProvider.
private List<ProviderUserModel> getEmailAddressesByProvider(ConfigurationModel blackDuckConfiguration) throws IntegrationException {
BlackDuckServicesFactory blackDuckServicesFactory = createBlackDuckServicesFactory(blackDuckConfiguration);
BlackDuckApiClient blackDuckService = blackDuckServicesFactory.getBlackDuckApiClient();
ApiDiscovery apiDiscovery = blackDuckServicesFactory.getApiDiscovery();
Set<String> allActiveBlackDuckEmailAddresses = getAllActiveBlackDuckEmailAddresses(blackDuckService, apiDiscovery);
return allActiveBlackDuckEmailAddresses.stream().map(email -> new ProviderUserModel(email, false)).collect(Collectors.toList());
}
use of com.synopsys.integration.blackduck.service.BlackDuckApiClient in project hub-alert by blackducksoftware.
the class BlackDuckNotificationRetrieverTest method retrievePageOfFilteredNotificationsTest.
@Test
public void retrievePageOfFilteredNotificationsTest() throws IntegrationException {
ProjectNotificationUserView projectNotificationView = new ProjectNotificationUserView();
BlackDuckPageResponse<NotificationUserView> pageResponse = new BlackDuckPageResponse<>(1, List.of(projectNotificationView));
UrlMultipleResponses<NotificationUserView> currentUserNotificationsUrl = new UrlMultipleResponses<>(new HttpUrl(THROWAWAY_SERVER), NotificationUserView.class);
UserView apiUser = Mockito.mock(UserView.class);
Mockito.doReturn(currentUserNotificationsUrl).when(apiUser).metaNotificationsLink();
UrlSingleResponse<UserView> currentUserUrl = new UrlSingleResponse<>(new HttpUrl(THROWAWAY_SERVER), UserView.class);
ApiDiscovery apiDiscovery = Mockito.mock(ApiDiscovery.class);
Mockito.doReturn(currentUserUrl).when(apiDiscovery).metaCurrentUserLink();
BlackDuckApiClient blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
Mockito.doReturn(pageResponse).when(blackDuckApiClient).getPageResponse(Mockito.any(BlackDuckMultipleRequest.class));
Mockito.doReturn(apiUser).when(blackDuckApiClient).getResponse(Mockito.eq(currentUserUrl));
BlackDuckAccumulatorSearchDateManager dateRangeCreator = createDateRangeCreator();
BlackDuckNotificationRetriever notificationRetriever = new BlackDuckNotificationRetriever(blackDuckApiClient, apiDiscovery);
StatefulAlertPage<NotificationUserView, IntegrationException> notificationPage = notificationRetriever.retrievePageOfFilteredNotifications(dateRangeCreator.retrieveNextSearchDateRange(), List.of());
assertEquals(pageResponse.getItems(), notificationPage.getCurrentModels());
}
use of com.synopsys.integration.blackduck.service.BlackDuckApiClient 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();
}
use of com.synopsys.integration.blackduck.service.BlackDuckApiClient 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();
}
Aggregations