Search in sources :

Example 1 with ProjectVersionView

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

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

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

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

Example 5 with ProjectVersionView

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

the class BlackDuckProviderIssueHandler method retrieveExistingIssue.

private Optional<ProjectVersionIssuesView> retrieveExistingIssue(String projectVersionUrl, String blackDuckIssueId) throws IntegrationException {
    HttpUrl projectVersionHttpUrl = new HttpUrl(projectVersionUrl);
    ProjectVersionView projectVersion = blackDuckApiClient.getResponse(projectVersionHttpUrl, ProjectVersionView.class);
    List<ProjectVersionIssuesView> bomComponentIssues = issueService.getIssuesForProjectVersion(projectVersion);
    return bomComponentIssues.stream().filter(issue -> issue.getIssueId().equals(blackDuckIssueId)).findAny();
}
Also used : IntegrationException(com.synopsys.integration.exception.IntegrationException) BlackDuckRequestBuilder(com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder) IssueRequest(com.synopsys.integration.blackduck.api.manual.temporary.component.IssueRequest) Date(java.util.Date) StringBodyContent(com.synopsys.integration.rest.body.StringBodyContent) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) Instant(java.time.Instant) HttpUrl(com.synopsys.integration.rest.HttpUrl) Nullable(org.jetbrains.annotations.Nullable) ProjectVersionIssuesView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionIssuesView) List(java.util.List) HttpMethod(com.synopsys.integration.rest.HttpMethod) Gson(com.google.gson.Gson) Optional(java.util.Optional) IssueService(com.synopsys.integration.blackduck.service.dataservice.IssueService) BlackDuckResponseRequest(com.synopsys.integration.blackduck.service.request.BlackDuckResponseRequest) BodyContentConverter(com.synopsys.integration.rest.body.BodyContentConverter) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) ProjectVersionIssuesView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionIssuesView) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) HttpUrl(com.synopsys.integration.rest.HttpUrl)

Aggregations

ProjectVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView)8 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)6 HttpUrl (com.synopsys.integration.rest.HttpUrl)6 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)5 IntegrationException (com.synopsys.integration.exception.IntegrationException)4 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)3 ProjectVersionWrapper (com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)3 BlackDuckPageResponse (com.synopsys.integration.blackduck.http.BlackDuckPageResponse)2 BlackDuckRequestBuilder (com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder)2 Test (org.junit.jupiter.api.Test)2 Gson (com.google.gson.Gson)1 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)1 DetailedNotificationContent (com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent)1 NotificationExtractorBlackDuckServicesFactoryCache (com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache)1 BomEditWithProjectNameNotificationContent (com.synopsys.integration.alert.provider.blackduck.processor.model.BomEditWithProjectNameNotificationContent)1 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)1 ProjectVersionComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)1 ProjectVersionIssuesView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionIssuesView)1 BomEditNotificationContent (com.synopsys.integration.blackduck.api.manual.component.BomEditNotificationContent)1 IssueRequest (com.synopsys.integration.blackduck.api.manual.temporary.component.IssueRequest)1