use of com.synopsys.integration.blackduck.api.generated.view.UserView in project hub-alert by blackducksoftware.
the class BlackDuckProviderDataAccessor method createProviderProject.
private ProviderProject createProviderProject(ProjectView projectView, BlackDuckApiClient blackDuckService) {
String projectOwnerEmail = null;
if (StringUtils.isNotBlank(projectView.getProjectOwner())) {
try {
HttpUrl projectOwnerHttpUrl = new HttpUrl(projectView.getProjectOwner());
UserView projectOwner = blackDuckService.getResponse(projectOwnerHttpUrl, UserView.class);
projectOwnerEmail = projectOwner.getEmail();
} catch (IntegrationException e) {
logger.errorAndDebug(createProjectOwnerNotFoundString(projectView.getName(), e.getMessage()), e);
}
}
String truncatedDescription = truncateDescription(projectView.getDescription());
return new ProviderProject(projectView.getName(), truncatedDescription, projectView.getMeta().getHref().toString(), projectOwnerEmail);
}
use of com.synopsys.integration.blackduck.api.generated.view.UserView in project hub-alert by blackducksoftware.
the class BlackDuckProviderDataAccessor method findFirstUserByEmailAddress.
@Override
public Optional<ProviderUserModel> findFirstUserByEmailAddress(Long providerConfigId, String emailAddress) {
Optional<ConfigurationModel> providerConfigOptional = configurationModelConfigurationAccessor.getConfigurationById(providerConfigId);
if (providerConfigOptional.isPresent()) {
try {
BlackDuckServicesFactory blackDuckServicesFactory = createBlackDuckServicesFactory(providerConfigOptional.get());
UserService userService = blackDuckServicesFactory.createUserService();
return userService.findUsersByEmail(emailAddress, new BlackDuckPageDefinition(1, 0)).getItems().stream().map(userView -> new ProviderUserModel(userView.getEmail(), false)).findFirst();
} catch (IntegrationException e) {
logger.errorAndDebug(createProjectNotFoundString(providerConfigId, e.getMessage()), e);
}
}
return Optional.empty();
}
use of com.synopsys.integration.blackduck.api.generated.view.UserView 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.api.generated.view.UserView in project hub-alert by blackducksoftware.
the class BlackDuckProviderDataAccessor method getProviderConfigUserById.
@Override
public ProviderUserModel getProviderConfigUserById(Long providerConfigId) throws AlertConfigurationException {
try {
Optional<ConfigurationModel> providerConfigOptional = configurationModelConfigurationAccessor.getConfigurationById(providerConfigId);
if (providerConfigOptional.isPresent()) {
BlackDuckServicesFactory blackDuckServicesFactory = createBlackDuckServicesFactory(providerConfigOptional.get());
UserService userService = blackDuckServicesFactory.createUserService();
UserView providerConfigUser = userService.findCurrentUser();
return new ProviderUserModel(providerConfigUser.getEmail(), false);
}
} catch (IntegrationException e) {
throw new AlertConfigurationException(createUserNotFoundString(providerConfigId, e.getMessage()), e);
}
throw new AlertConfigurationException(String.format("The provider config with id '%s' is invalid", providerConfigId));
}
use of com.synopsys.integration.blackduck.api.generated.view.UserView in project hub-alert by blackducksoftware.
the class BlackDuckProviderDataAccessor method retrieveUsersForProvider.
private AlertPagedModel<ProviderUserModel> retrieveUsersForProvider(ConfigurationModel blackDuckConfigurationModel, int pageNumber, int pageSize, String searchTerm) throws IntegrationException {
BlackDuckServicesFactory blackDuckServicesFactory = createBlackDuckServicesFactory(blackDuckConfigurationModel);
Predicate<UserView> searchFilter = userView -> StringUtils.isNotBlank(userView.getEmail());
if (StringUtils.isNotBlank(searchTerm)) {
searchFilter = searchFilter.and(userView -> StringUtils.containsIgnoreCase(userView.getEmail(), searchTerm));
}
ApiDiscovery apiDiscovery = blackDuckServicesFactory.getApiDiscovery();
BlackDuckPageResponse<UserView> pageOfUsers = retrieveBlackDuckPageResponse(blackDuckServicesFactory, apiDiscovery.metaUsersLink(), pageNumber, pageSize, searchFilter);
List<ProviderUserModel> foundUsers = pageOfUsers.getItems().stream().map(UserView::getEmail).map(email -> new ProviderUserModel(email, false)).collect(Collectors.toList());
// Due to a limitation in the blackduck-common library, the totalCount in the BlackDuckPageResponse does not represent the count the matches the searchFilter. It is the totalCount from Black Duck
int totalPageCount = computeTotalCount(pageOfUsers, pageSize);
return new AlertPagedModel<>(totalPageCount, pageNumber, pageSize, foundUsers);
}
Aggregations