Search in sources :

Example 1 with UserView

use of com.synopsys.integration.blackduck.api.generated.view.UserView in project hub-alert by blackducksoftware.

the class BlackDuckProjectSyncTaskTest method createUserView.

private UserView createUserView(String email, Boolean active) {
    UserView userView = new UserView();
    userView.setEmail(email);
    userView.setActive(active);
    return userView;
}
Also used : UserView(com.synopsys.integration.blackduck.api.generated.view.UserView)

Example 2 with UserView

use of com.synopsys.integration.blackduck.api.generated.view.UserView in project hub-alert by blackducksoftware.

the class ProviderDataAccessorTest method createUserViews.

private Set<UserView> createUserViews() {
    String emailAddress1 = "someone@gmail.com";
    String emailAddress2 = "someoneelse@gmail.com";
    String emailAddress3 = "other@gmail.com";
    UserView userView1 = new UserView();
    userView1.setActive(true);
    userView1.setEmail(emailAddress1);
    UserView userView2 = new UserView();
    userView2.setActive(true);
    userView2.setEmail(emailAddress2);
    UserView userView3 = new UserView();
    userView3.setActive(true);
    userView3.setEmail(emailAddress3);
    UserView userView4 = new UserView();
    userView4.setActive(false);
    userView4.setEmail(emailAddress1);
    UserView userView5 = new UserView();
    userView5.setActive(true);
    userView5.setEmail(emailAddress2);
    Set<UserView> userViews = new HashSet<>();
    userViews.add(userView1);
    userViews.add(userView2);
    userViews.add(userView3);
    userViews.add(userView4);
    userViews.add(userView5);
    return userViews;
}
Also used : UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) HashSet(java.util.HashSet)

Example 3 with UserView

use of com.synopsys.integration.blackduck.api.generated.view.UserView in project hub-alert by blackducksoftware.

the class ProviderDataAccessorTest method init.

@BeforeEach
void init() throws Exception {
    blackDuckPropertiesFactory = Mockito.mock(BlackDuckPropertiesFactory.class);
    BlackDuckProperties blackDuckProperties = Mockito.mock(BlackDuckProperties.class);
    Mockito.when(blackDuckPropertiesFactory.createProperties(Mockito.any(ConfigurationModel.class))).thenReturn(blackDuckProperties);
    BlackDuckHttpClient blackDuckHttpClient = Mockito.mock(BlackDuckHttpClient.class);
    Mockito.when(blackDuckProperties.createBlackDuckHttpClient(Mockito.any(IntLogger.class))).thenReturn(blackDuckHttpClient);
    blackDuckServicesFactory = Mockito.mock(BlackDuckServicesFactory.class);
    Mockito.when(blackDuckProperties.createBlackDuckServicesFactory(Mockito.any(BlackDuckHttpClient.class), Mockito.any(IntLogger.class))).thenReturn(blackDuckServicesFactory);
    projectService = Mockito.mock(ProjectService.class);
    Mockito.when(blackDuckServicesFactory.createProjectService()).thenReturn(projectService);
    blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
    Mockito.when(blackDuckServicesFactory.getBlackDuckApiClient()).thenReturn(blackDuckApiClient);
    projectUsersService = Mockito.mock(ProjectUsersService.class);
    Mockito.when(blackDuckServicesFactory.createProjectUsersService()).thenReturn(projectUsersService);
    apiDiscovery = Mockito.mock(ApiDiscovery.class);
    UrlMultipleResponses<UserView> usersLink = Mockito.mock(UrlMultipleResponses.class);
    Mockito.when(apiDiscovery.metaUsersLink()).thenReturn(usersLink);
    Mockito.when(blackDuckServicesFactory.getApiDiscovery()).thenReturn(apiDiscovery);
    ConfigurationFieldModel configurationFieldModel = ConfigurationFieldModel.create(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME);
    configurationFieldModel.setFieldValue(PROVIDER_CONFIG_NAME);
    configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    providerConfiguration = new ConfigurationModel(1L, 1L, "createdAt", "lastModified", ConfigContextEnum.GLOBAL, Map.of(PROVIDER_CONFIG_NAME, configurationFieldModel));
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationById(1L)).thenReturn(Optional.of(providerConfiguration));
    Mockito.when(configurationModelConfigurationAccessor.getProviderConfigurationByName(Mockito.anyString())).thenReturn(Optional.of(providerConfiguration));
}
Also used : ProjectUsersService(com.synopsys.integration.blackduck.service.dataservice.ProjectUsersService) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) ProjectService(com.synopsys.integration.blackduck.service.dataservice.ProjectService) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) BlackDuckPropertiesFactory(com.synopsys.integration.alert.provider.blackduck.factory.BlackDuckPropertiesFactory) IntLogger(com.synopsys.integration.log.IntLogger) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) ApiDiscovery(com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with UserView

use of com.synopsys.integration.blackduck.api.generated.view.UserView in project hub-alert by blackducksoftware.

the class ProviderDataAccessorTest method getEmailAddressesForProjectHrefTest.

@Test
void getEmailAddressesForProjectHrefTest() throws Exception {
    Long providerConfigId = providerConfiguration.getConfigurationId();
    ProjectView projectView = createProjectView1();
    Mockito.when(blackDuckApiClient.getResponse(Mockito.any(HttpUrl.class), Mockito.eq(ProjectView.class))).thenReturn(projectView);
    Set<UserView> userViews = createUserViews();
    Mockito.when(projectUsersService.getAllActiveUsersForProject(Mockito.any(ProjectView.class))).thenReturn(userViews);
    BlackDuckProviderDataAccessor providerDataAccessor = new BlackDuckProviderDataAccessor(configurationModelConfigurationAccessor, blackDuckPropertiesFactory);
    Set<String> foundEmailAddresses = providerDataAccessor.getEmailAddressesForProjectHref(providerConfigId, HREF_1);
    assertEquals(3, foundEmailAddresses.size());
}
Also used : UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) HttpUrl(com.synopsys.integration.rest.HttpUrl) Test(org.junit.jupiter.api.Test)

Example 5 with UserView

use of com.synopsys.integration.blackduck.api.generated.view.UserView in project hub-alert by blackducksoftware.

the class BlackDuckDataSyncTask method getEmailsPerProject.

private Map<ProviderProject, Set<String>> getEmailsPerProject(Map<ProjectView, ProviderProject> blackDuckToAlertProjects, ProjectUsersService projectUsersService) {
    Map<ProviderProject, Set<String>> projectToEmailAddresses = new ConcurrentHashMap<>();
    blackDuckToAlertProjects.entrySet().parallelStream().forEach(entry -> {
        try {
            ProjectView blackDuckProjectView = entry.getKey();
            ProviderProject alertProject = entry.getValue();
            Set<String> projectUserEmailAddresses = projectUsersService.getAllActiveUsersForProject(blackDuckProjectView).stream().filter(UserView::getActive).map(UserView::getEmail).filter(StringUtils::isNotBlank).collect(Collectors.toSet());
            if (StringUtils.isNotBlank(alertProject.getProjectOwnerEmail())) {
                projectUserEmailAddresses.add(alertProject.getProjectOwnerEmail());
            }
            projectToEmailAddresses.put(alertProject, projectUserEmailAddresses);
        } catch (IntegrationException e) {
            // We do this to break out of the stream
            throw new AlertRuntimeException(e.getMessage(), e);
        }
    });
    return projectToEmailAddresses;
}
Also used : Set(java.util.Set) IntegrationException(com.synopsys.integration.exception.IntegrationException) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

UserView (com.synopsys.integration.blackduck.api.generated.view.UserView)16 IntegrationException (com.synopsys.integration.exception.IntegrationException)8 HttpUrl (com.synopsys.integration.rest.HttpUrl)7 ApiDiscovery (com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery)6 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)6 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)6 ProviderProject (com.synopsys.integration.alert.common.persistence.model.ProviderProject)5 ProviderUserModel (com.synopsys.integration.alert.common.persistence.model.ProviderUserModel)5 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)5 UserService (com.synopsys.integration.blackduck.service.dataservice.UserService)5 Test (org.junit.jupiter.api.Test)5 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)4 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)4 ProjectUsersService (com.synopsys.integration.blackduck.service.dataservice.ProjectUsersService)4 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)3 BlackDuckPropertiesFactory (com.synopsys.integration.alert.provider.blackduck.factory.BlackDuckPropertiesFactory)3 UrlMultipleResponses (com.synopsys.integration.blackduck.api.core.response.UrlMultipleResponses)3 BlackDuckPageResponse (com.synopsys.integration.blackduck.http.BlackDuckPageResponse)3 BlackDuckRequestBuilder (com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder)3 BlackDuckHttpClient (com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient)3