Search in sources :

Example 1 with UserService

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();
}
Also used : BlackDuckPageDefinition(com.synopsys.integration.blackduck.http.BlackDuckPageDefinition) ProviderDataAccessor(com.synopsys.integration.alert.common.persistence.accessor.ProviderDataAccessor) IntegrationException(com.synopsys.integration.exception.IntegrationException) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) BlackDuckResponse(com.synopsys.integration.blackduck.api.core.BlackDuckResponse) BlackDuckPageDefinition(com.synopsys.integration.blackduck.http.BlackDuckPageDefinition) LoggerFactory(org.slf4j.LoggerFactory) ProviderUserModel(com.synopsys.integration.alert.common.persistence.model.ProviderUserModel) Autowired(org.springframework.beans.factory.annotation.Autowired) ApiDiscovery(com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery) StringUtils(org.apache.commons.lang3.StringUtils) BlackDuckMultipleRequest(com.synopsys.integration.blackduck.service.request.BlackDuckMultipleRequest) IntLogger(com.synopsys.integration.log.IntLogger) HttpUrl(com.synopsys.integration.rest.HttpUrl) ArrayList(java.util.ArrayList) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) ProjectService(com.synopsys.integration.blackduck.service.dataservice.ProjectService) Map(java.util.Map) UrlMultipleResponses(com.synopsys.integration.blackduck.api.core.response.UrlMultipleResponses) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) BlackDuckPageResponse(com.synopsys.integration.blackduck.http.BlackDuckPageResponse) BlackDuckPropertiesFactory(com.synopsys.integration.alert.provider.blackduck.factory.BlackDuckPropertiesFactory) BlackDuckQuery(com.synopsys.integration.blackduck.http.BlackDuckQuery) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) BlackDuckRequestBuilder(com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) Collectors(java.util.stream.Collectors) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) BlackDuckResponsesTransformer(com.synopsys.integration.blackduck.http.transform.BlackDuckResponsesTransformer) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) Nullable(org.jetbrains.annotations.Nullable) ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject) List(java.util.List) Component(org.springframework.stereotype.Component) ProjectUsersService(com.synopsys.integration.blackduck.service.dataservice.ProjectUsersService) ThrowingSupplier(com.synopsys.integration.function.ThrowingSupplier) Optional(java.util.Optional) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) UserService(com.synopsys.integration.blackduck.service.dataservice.UserService) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) IntegrationException(com.synopsys.integration.exception.IntegrationException) UserService(com.synopsys.integration.blackduck.service.dataservice.UserService) ProviderUserModel(com.synopsys.integration.alert.common.persistence.model.ProviderUserModel) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)

Example 2 with UserService

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));
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) IntegrationException(com.synopsys.integration.exception.IntegrationException) UserService(com.synopsys.integration.blackduck.service.dataservice.UserService) ProviderUserModel(com.synopsys.integration.alert.common.persistence.model.ProviderUserModel) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)

Example 3 with UserService

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)));
    }
}
Also used : UserService(com.synopsys.integration.blackduck.service.dataservice.UserService) ProviderUserModel(com.synopsys.integration.alert.common.persistence.model.ProviderUserModel) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) Test(org.junit.jupiter.api.Test)

Example 4 with UserService

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());
}
Also used : UserService(com.synopsys.integration.blackduck.service.dataservice.UserService) ProviderUserModel(com.synopsys.integration.alert.common.persistence.model.ProviderUserModel) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) Test(org.junit.jupiter.api.Test)

Aggregations

ProviderUserModel (com.synopsys.integration.alert.common.persistence.model.ProviderUserModel)4 UserView (com.synopsys.integration.blackduck.api.generated.view.UserView)4 UserService (com.synopsys.integration.blackduck.service.dataservice.UserService)4 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)3 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)2 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)2 IntegrationException (com.synopsys.integration.exception.IntegrationException)2 Test (org.junit.jupiter.api.Test)2 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)1 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)1 ProviderDataAccessor (com.synopsys.integration.alert.common.persistence.accessor.ProviderDataAccessor)1 ProviderProject (com.synopsys.integration.alert.common.persistence.model.ProviderProject)1 AlertPagedModel (com.synopsys.integration.alert.common.rest.model.AlertPagedModel)1 BlackDuckPropertiesFactory (com.synopsys.integration.alert.provider.blackduck.factory.BlackDuckPropertiesFactory)1 BlackDuckResponse (com.synopsys.integration.blackduck.api.core.BlackDuckResponse)1 UrlMultipleResponses (com.synopsys.integration.blackduck.api.core.response.UrlMultipleResponses)1 ApiDiscovery (com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery)1 ProjectVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView)1 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)1 BlackDuckPageDefinition (com.synopsys.integration.blackduck.http.BlackDuckPageDefinition)1