use of com.synopsys.integration.blackduck.service.dataservice.UserService 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.service.dataservice.UserService 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.service.dataservice.UserService in project hub-alert by blackducksoftware.
the class ProviderDataAccessorTest method getProviderConfigUserByIdNotFoundTest.
@Test
void getProviderConfigUserByIdNotFoundTest() 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);
long nonExistentConfig = 999L;
try {
ProviderUserModel providerConfigUser = blackDuckProviderDataAccessor.getProviderConfigUserById(nonExistentConfig);
fail();
} catch (AlertConfigurationException exception) {
assertTrue(exception.getMessage().contains(String.valueOf(nonExistentConfig)));
}
}
use of com.synopsys.integration.blackduck.service.dataservice.UserService in project hub-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());
}
Aggregations