Search in sources :

Example 11 with ProviderUserModel

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());
}
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)

Example 12 with ProviderUserModel

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();
}
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 13 with ProviderUserModel

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);
}
Also used : 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) ProviderUserModel(com.synopsys.integration.alert.common.persistence.model.ProviderUserModel) ApiDiscovery(com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)

Example 14 with ProviderUserModel

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());
}
Also used : 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) ProviderUserModel(com.synopsys.integration.alert.common.persistence.model.ProviderUserModel) ApiDiscovery(com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)

Aggregations

ProviderUserModel (com.synopsys.integration.alert.common.persistence.model.ProviderUserModel)14 UserView (com.synopsys.integration.blackduck.api.generated.view.UserView)12 UserService (com.synopsys.integration.blackduck.service.dataservice.UserService)12 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)10 ProviderDataAccessor (com.synopsys.integration.alert.common.persistence.accessor.ProviderDataAccessor)8 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)8 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)8 IntegrationException (com.synopsys.integration.exception.IntegrationException)8 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)6 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)6 ProviderProject (com.synopsys.integration.alert.common.persistence.model.ProviderProject)6 AlertPagedModel (com.synopsys.integration.alert.common.rest.model.AlertPagedModel)6 BlackDuckPropertiesFactory (com.synopsys.integration.alert.provider.blackduck.factory.BlackDuckPropertiesFactory)6 BlackDuckResponse (com.synopsys.integration.blackduck.api.core.BlackDuckResponse)6 UrlMultipleResponses (com.synopsys.integration.blackduck.api.core.response.UrlMultipleResponses)6 ApiDiscovery (com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery)6 ProjectVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView)6 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)6 BlackDuckPageDefinition (com.synopsys.integration.blackduck.http.BlackDuckPageDefinition)6 BlackDuckPageResponse (com.synopsys.integration.blackduck.http.BlackDuckPageResponse)6