use of com.synopsys.integration.alert.common.persistence.model.ProviderUserModel in project blackduck-alert by blackducksoftware.
the class ProviderDataAccessorTest method getProviderConfigUserByIdTest.
@Test
void getProviderConfigUserByIdTest() throws IntegrationException {
UserService userService = Mockito.mock(UserService.class);
Mockito.when(blackDuckServicesFactory.createUserService()).thenReturn(userService);
String emailAddress = "fake@email.address";
UserView userView1 = new UserView();
userView1.setActive(true);
userView1.setEmail(emailAddress);
Mockito.when(userService.findCurrentUser()).thenReturn(userView1);
BlackDuckProviderDataAccessor blackDuckProviderDataAccessor = new BlackDuckProviderDataAccessor(configurationModelConfigurationAccessor, blackDuckPropertiesFactory);
ProviderUserModel providerConfigUser = blackDuckProviderDataAccessor.getProviderConfigUserById(1L);
assertNotNull(providerConfigUser);
assertEquals(emailAddress, providerConfigUser.getEmailAddress());
}
use of com.synopsys.integration.alert.common.persistence.model.ProviderUserModel in project blackduck-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.alert.common.persistence.model.ProviderUserModel in project blackduck-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);
}
use of com.synopsys.integration.alert.common.persistence.model.ProviderUserModel in project blackduck-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());
}
Aggregations