Search in sources :

Example 1 with ProjectView

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

the class ProviderDataAccessorTest method getProjectVersionsByHrefTest.

@Test
void getProjectVersionsByHrefTest() throws IntegrationException {
    ProjectView projectView = createProjectViewWithVersionsLink();
    Mockito.when(blackDuckApiClient.getResponse(Mockito.any(HttpUrl.class), Mockito.eq(ProjectView.class))).thenReturn(projectView);
    ProjectVersionView projectVersionView = new ProjectVersionView();
    String versionName = "versionName";
    int totalPages = 1;
    projectVersionView.setVersionName(versionName);
    BlackDuckPageResponse blackDuckPageResponse = new BlackDuckPageResponse(totalPages, List.of(projectVersionView));
    Mockito.when(blackDuckApiClient.getPageResponse(Mockito.any())).thenReturn(blackDuckPageResponse);
    BlackDuckProviderDataAccessor blackDuckProviderDataAccessor = new BlackDuckProviderDataAccessor(configurationModelConfigurationAccessor, blackDuckPropertiesFactory);
    AlertPagedModel<String> projectVersionNamesByHref = blackDuckProviderDataAccessor.getProjectVersionNamesByHref(1L, HREF_1, 1);
    assertNotNull(projectVersionNamesByHref);
    assertEquals(totalPages, projectVersionNamesByHref.getTotalPages());
    Optional<String> firstFoundProjectVersion = projectVersionNamesByHref.getModels().stream().findFirst();
    assertTrue(firstFoundProjectVersion.isPresent());
    String foundVersionName = firstFoundProjectVersion.get();
    assertEquals(versionName, foundVersionName);
}
Also used : ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) HttpUrl(com.synopsys.integration.rest.HttpUrl) BlackDuckPageResponse(com.synopsys.integration.blackduck.http.BlackDuckPageResponse) Test(org.junit.jupiter.api.Test)

Example 2 with ProjectView

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

the class ProviderDataAccessorTest method getProjectVersionsByHrefWithNoConfigTest.

@Test
void getProjectVersionsByHrefWithNoConfigTest() throws IntegrationException {
    ProjectView projectView = createProjectViewWithVersionsLink();
    Mockito.when(blackDuckApiClient.getResponse(Mockito.any(HttpUrl.class), Mockito.eq(ProjectView.class))).thenReturn(projectView);
    ProjectVersionView projectVersionView = new ProjectVersionView();
    String versionName = "versionName";
    int totalPages = 1;
    projectVersionView.setVersionName(versionName);
    BlackDuckPageResponse blackDuckPageResponse = new BlackDuckPageResponse(totalPages, List.of(projectVersionView));
    Mockito.when(blackDuckApiClient.getPageResponse(Mockito.any())).thenReturn(blackDuckPageResponse);
    BlackDuckProviderDataAccessor blackDuckProviderDataAccessor = new BlackDuckProviderDataAccessor(configurationModelConfigurationAccessor, blackDuckPropertiesFactory);
    AlertPagedModel<String> projectVersionNamesByHref = blackDuckProviderDataAccessor.getProjectVersionNamesByHref(999L, HREF_1, 1);
    assertNotNull(projectVersionNamesByHref);
    assertEquals(0, projectVersionNamesByHref.getTotalPages());
}
Also used : ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) HttpUrl(com.synopsys.integration.rest.HttpUrl) BlackDuckPageResponse(com.synopsys.integration.blackduck.http.BlackDuckPageResponse) Test(org.junit.jupiter.api.Test)

Example 3 with ProjectView

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

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

the class BomEditNotificationDetailExtractor method extractDetailedContent.

@Override
public List<DetailedNotificationContent> extractDetailedContent(AlertNotificationModel alertNotificationModel, BomEditNotificationView notificationView) {
    BomEditNotificationContent notificationContent = notificationView.getContent();
    Optional<ProjectVersionWrapper> optionalProjectAndVersion = retrieveProjectAndVersion(alertNotificationModel.getProviderConfigId(), notificationContent.getProjectVersion());
    if (optionalProjectAndVersion.isPresent()) {
        ProjectVersionWrapper projectAndVersion = optionalProjectAndVersion.get();
        ProjectView project = projectAndVersion.getProjectView();
        ProjectVersionView projectVersion = projectAndVersion.getProjectVersionView();
        String projectName = project.getName();
        BomEditWithProjectNameNotificationContent updatedNotificationContent = new BomEditWithProjectNameNotificationContent(notificationContent, projectName, projectVersion.getVersionName());
        DetailedNotificationContent detailedContent = DetailedNotificationContent.project(alertNotificationModel, updatedNotificationContent, projectName, projectVersion.getVersionName());
        return List.of(detailedContent);
    }
    return List.of();
}
Also used : BomEditNotificationContent(com.synopsys.integration.blackduck.api.manual.component.BomEditNotificationContent) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) DetailedNotificationContent(com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) BomEditWithProjectNameNotificationContent(com.synopsys.integration.alert.provider.blackduck.processor.model.BomEditWithProjectNameNotificationContent) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)

Example 5 with ProjectView

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

the class BlackDuckProviderDataAccessor method getProjectVersionNamesByHref.

@Override
public AlertPagedModel<String> getProjectVersionNamesByHref(Long providerConfigId, String projectHref, int pageNumber) {
    Optional<ConfigurationModel> providerConfigOptional = configurationModelConfigurationAccessor.getConfigurationById(providerConfigId);
    if (providerConfigOptional.isPresent()) {
        try {
            BlackDuckServicesFactory blackDuckServicesFactory = createBlackDuckServicesFactory(providerConfigOptional.get());
            BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
            ProjectView foundProject = blackDuckApiClient.getResponse(new HttpUrl(projectHref), ProjectView.class);
            BlackDuckPageDefinition blackDuckPageDefinition = new BlackDuckPageDefinition(BlackDuckRequestBuilder.DEFAULT_LIMIT, pageNumber * BlackDuckRequestBuilder.DEFAULT_LIMIT);
            BlackDuckMultipleRequest<ProjectVersionView> projectVersionSpec = new BlackDuckRequestBuilder().commonGet().setBlackDuckPageDefinition(blackDuckPageDefinition).buildBlackDuckRequest(foundProject.metaVersionsLink());
            BlackDuckPageResponse<ProjectVersionView> pageResponse = blackDuckApiClient.getPageResponse(projectVersionSpec);
            return new AlertPagedModel<>(pageResponse.getTotalCount(), pageNumber, BlackDuckRequestBuilder.DEFAULT_LIMIT, pageResponse.getItems()).transformContent(ProjectVersionView::getVersionName);
        } catch (IntegrationException e) {
            logger.errorAndDebug(createProjectNotFoundString(providerConfigId, e.getMessage()), e);
        }
    }
    return AlertPagedModel.empty(pageNumber, BlackDuckRequestBuilder.DEFAULT_LIMIT);
}
Also used : BlackDuckPageDefinition(com.synopsys.integration.blackduck.http.BlackDuckPageDefinition) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) IntegrationException(com.synopsys.integration.exception.IntegrationException) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) HttpUrl(com.synopsys.integration.rest.HttpUrl) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) BlackDuckRequestBuilder(com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView)

Aggregations

ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)21 HttpUrl (com.synopsys.integration.rest.HttpUrl)15 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)9 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)8 IntegrationException (com.synopsys.integration.exception.IntegrationException)7 ProviderProject (com.synopsys.integration.alert.common.persistence.model.ProviderProject)6 ProjectVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView)6 Test (org.junit.jupiter.api.Test)5 ResourceMetadata (com.synopsys.integration.blackduck.api.core.ResourceMetadata)4 UserView (com.synopsys.integration.blackduck.api.generated.view.UserView)4 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)3 ApiDiscovery (com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery)3 AlertRuntimeException (com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)2 BlackDuckProperties (com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties)2 ResourceLink (com.synopsys.integration.blackduck.api.core.ResourceLink)2 BlackDuckPageDefinition (com.synopsys.integration.blackduck.http.BlackDuckPageDefinition)2 BlackDuckPageResponse (com.synopsys.integration.blackduck.http.BlackDuckPageResponse)2 BlackDuckRequestBuilder (com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder)2 ProjectUsersService (com.synopsys.integration.blackduck.service.dataservice.ProjectUsersService)2 ProjectVersionWrapper (com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)2