Search in sources :

Example 11 with UserView

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

the class BlackDuckDataSyncTask method mapBlackDuckProjectsToAlertProjects.

private Map<ProjectView, ProviderProject> mapBlackDuckProjectsToAlertProjects(List<ProjectView> projectViews, BlackDuckApiClient blackDuckApiClient) {
    Map<ProjectView, ProviderProject> projectMap = new ConcurrentHashMap<>();
    projectViews.parallelStream().forEach(projectView -> {
        String projectOwnerEmail = null;
        if (StringUtils.isNotBlank(projectView.getProjectOwner())) {
            try {
                HttpUrl projectOwnerHttpUrl = new HttpUrl(projectView.getProjectOwner());
                UserView projectOwner = blackDuckApiClient.getResponse(projectOwnerHttpUrl, UserView.class);
                projectOwnerEmail = projectOwner.getEmail();
            } catch (IntegrationException e) {
                logger.error(String.format("Could not get the project owner for Project: %s. Error: %s", projectView.getName(), e.getMessage()), e);
            }
        }
        projectMap.put(projectView, new ProviderProject(projectView.getName(), StringUtils.trimToEmpty(projectView.getDescription()), projectView.getMeta().getHref().toString(), projectOwnerEmail));
    });
    return projectMap;
}
Also used : IntegrationException(com.synopsys.integration.exception.IntegrationException) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HttpUrl(com.synopsys.integration.rest.HttpUrl)

Example 12 with UserView

use of com.synopsys.integration.blackduck.api.generated.view.UserView 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 13 with UserView

use of com.synopsys.integration.blackduck.api.generated.view.UserView 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)

Example 14 with UserView

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

the class BlackDuckProjectSyncTaskTest method testRun.

@Test
public void testRun() throws Exception {
    MockProviderDataAccessor providerDataAccessor = new MockProviderDataAccessor();
    ApiDiscovery apiDiscovery = new ApiDiscovery(new HttpUrl("https://someblackduckserver"));
    BlackDuckApiClient blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
    ProjectUsersService projectUsersService = Mockito.mock(ProjectUsersService.class);
    BlackDuckServicesFactory blackDuckServicesFactory = Mockito.mock(BlackDuckServicesFactory.class);
    Mockito.when(blackDuckServicesFactory.getBlackDuckApiClient()).thenReturn(blackDuckApiClient);
    Mockito.when(blackDuckServicesFactory.createProjectUsersService()).thenReturn(projectUsersService);
    Mockito.when(blackDuckServicesFactory.getApiDiscovery()).thenReturn(apiDiscovery);
    Long providerConfigId = 1000L;
    BlackDuckProperties blackDuckProperties = Mockito.mock(BlackDuckProperties.class);
    Mockito.when(blackDuckProperties.getConfigId()).thenReturn(providerConfigId);
    Mockito.when(blackDuckProperties.createBlackDuckHttpClientAndLogErrors(Mockito.any())).thenReturn(Optional.of(Mockito.mock(BlackDuckHttpClient.class)));
    Mockito.when(blackDuckProperties.createBlackDuckServicesFactory(Mockito.any(), Mockito.any())).thenReturn(blackDuckServicesFactory);
    ProjectView projectView = createProjectView("project", "description1", "https://projectUrl1");
    ProjectView projectView2 = createProjectView("project2", "description2", "https://projectUrl2");
    ProjectView projectView3 = createProjectView("project3", "description3", "https://projectUrl3");
    Mockito.when(blackDuckApiClient.getAllResponses(Mockito.eq(apiDiscovery.metaProjectsLink()))).thenReturn(List.of(projectView, projectView2, projectView3));
    Mockito.doReturn(null).when(blackDuckApiClient).getResponse(Mockito.any(BlackDuckRequest.class));
    String email1 = "user1@email.com";
    String email2 = "user2@email.com";
    String email3 = "user3@email.com";
    String email4 = "user4@email.com";
    UserView user1 = createUserView(email1, true);
    UserView user2 = createUserView(email2, true);
    UserView user3 = createUserView(email3, true);
    UserView user4 = createUserView(email4, true);
    Mockito.when(blackDuckApiClient.getAllResponses(Mockito.eq(apiDiscovery.metaUsersLink()))).thenReturn(List.of(user1, user2, user3, user4));
    Mockito.when(projectUsersService.getAllActiveUsersForProject(ArgumentMatchers.same(projectView))).thenReturn(new HashSet<>(List.of(user2, user4)));
    Mockito.when(projectUsersService.getAllActiveUsersForProject(ArgumentMatchers.same(projectView2))).thenReturn(new HashSet<>(List.of(user3)));
    Mockito.when(projectUsersService.getAllActiveUsersForProject(ArgumentMatchers.same(projectView3))).thenReturn(new HashSet<>(List.of(user1, user2, user3)));
    Mockito.doNothing().when(projectUsersService).addUserToProject(Mockito.any(), Mockito.any(UserView.class));
    BlackDuckDataSyncTask projectSyncTask = new BlackDuckDataSyncTask(new BlackDuckProviderKey(), null, providerDataAccessor, blackDuckProperties);
    projectSyncTask.run();
    assertEquals(3, providerDataAccessor.getProjectsByProviderConfigId(providerConfigId).size());
    Mockito.when(blackDuckApiClient.getAllResponses(Mockito.eq(apiDiscovery.metaProjectsLink()))).thenReturn(List.of(projectView, projectView2));
    Mockito.when(projectUsersService.getAllActiveUsersForProject(ArgumentMatchers.same(projectView))).thenReturn(new HashSet<>(List.of(user2, user4)));
    Mockito.when(projectUsersService.getAllActiveUsersForProject(ArgumentMatchers.same(projectView2))).thenReturn(new HashSet<>(List.of(user3)));
    Mockito.when(blackDuckApiClient.getAllResponses(ArgumentMatchers.same(projectView2.metaUsersLink()))).thenReturn(List.of());
    projectSyncTask = new BlackDuckDataSyncTask(new BlackDuckProviderKey(), null, providerDataAccessor, blackDuckProperties);
    projectSyncTask.run();
    assertEquals(2, providerDataAccessor.getProjectsByProviderConfigId(providerConfigId).size());
}
Also used : ProjectUsersService(com.synopsys.integration.blackduck.service.dataservice.ProjectUsersService) BlackDuckProviderKey(com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey) BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) HttpUrl(com.synopsys.integration.rest.HttpUrl) MockProviderDataAccessor(com.synopsys.integration.alert.provider.blackduck.MockProviderDataAccessor) ApiDiscovery(com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery) BlackDuckRequest(com.synopsys.integration.blackduck.service.request.BlackDuckRequest) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) Test(org.junit.jupiter.api.Test)

Example 15 with UserView

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

the class BlackDuckNotificationRetriever method createNotificationsRequest.

private BlackDuckMultipleRequest<NotificationUserView> createNotificationsRequest(DateRange dateRange, List<String> notificationTypesToInclude) throws IntegrationException {
    UserView currentUser = blackDuckApiClient.getResponse(apiDiscovery.metaCurrentUserLink());
    UrlMultipleResponses<NotificationUserView> currentUserNotificationsUrl = currentUser.metaNotificationsLink();
    NotificationEditor notificationEditor = new NotificationEditor(dateRange.getStart(), dateRange.getEnd(), notificationTypesToInclude);
    BlackDuckMultipleRequest<NotificationUserView> spec = new BlackDuckRequestBuilder().commonGet().apply(notificationEditor).addQueryParameter("sort", String.format("%s asc", PAGE_SORT_FIELD)).buildBlackDuckRequest(currentUserNotificationsUrl);
    return spec;
}
Also used : NotificationUserView(com.synopsys.integration.blackduck.api.manual.view.NotificationUserView) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) NotificationUserView(com.synopsys.integration.blackduck.api.manual.view.NotificationUserView) NotificationEditor(com.synopsys.integration.blackduck.service.request.NotificationEditor) BlackDuckRequestBuilder(com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder)

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