Search in sources :

Example 1 with BlackDuckPageDefinition

use of com.synopsys.integration.blackduck.http.BlackDuckPageDefinition 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 2 with BlackDuckPageDefinition

use of com.synopsys.integration.blackduck.http.BlackDuckPageDefinition in project hub-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 3 with BlackDuckPageDefinition

use of com.synopsys.integration.blackduck.http.BlackDuckPageDefinition in project hub-alert by blackducksoftware.

the class BlackDuckProviderDataAccessor method retrieveProjectsForProvider.

private AlertPagedModel<ProviderProject> retrieveProjectsForProvider(ConfigurationModel blackDuckConfigurationModel, int pageNumber, int pageSize, String searchTerm) throws IntegrationException {
    BlackDuckServicesFactory blackDuckServicesFactory = createBlackDuckServicesFactory(blackDuckConfigurationModel);
    BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
    ApiDiscovery apiDiscovery = blackDuckServicesFactory.getApiDiscovery();
    BlackDuckQuery nameQuery = new BlackDuckQuery("name", searchTerm);
    BlackDuckPageDefinition blackDuckPageDefinition = new BlackDuckPageDefinition(pageSize, pageNumber * pageSize);
    BlackDuckMultipleRequest<ProjectView> projectSpec = new BlackDuckRequestBuilder().commonGet().addBlackDuckQuery(nameQuery).setBlackDuckPageDefinition(blackDuckPageDefinition).buildBlackDuckRequest(apiDiscovery.metaProjectsLink());
    BlackDuckPageResponse<ProjectView> pageOfProjects = blackDuckApiClient.getPageResponse(projectSpec);
    List<ProviderProject> foundProjects = convertBlackDuckProjects(pageOfProjects.getItems(), blackDuckApiClient);
    int totalPageCount = computeTotalCount(pageOfProjects, pageSize);
    return new AlertPagedModel<>(totalPageCount, pageNumber, pageSize, foundProjects);
}
Also used : BlackDuckPageDefinition(com.synopsys.integration.blackduck.http.BlackDuckPageDefinition) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) ApiDiscovery(com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery) BlackDuckQuery(com.synopsys.integration.blackduck.http.BlackDuckQuery) BlackDuckRequestBuilder(com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject)

Aggregations

ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)3 BlackDuckPageDefinition (com.synopsys.integration.blackduck.http.BlackDuckPageDefinition)3 BlackDuckRequestBuilder (com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder)3 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)3 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)3 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)2 ProviderProject (com.synopsys.integration.alert.common.persistence.model.ProviderProject)2 AlertPagedModel (com.synopsys.integration.alert.common.rest.model.AlertPagedModel)2 ApiDiscovery (com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery)2 ProjectVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView)2 BlackDuckQuery (com.synopsys.integration.blackduck.http.BlackDuckQuery)2 IntegrationException (com.synopsys.integration.exception.IntegrationException)2 HttpUrl (com.synopsys.integration.rest.HttpUrl)2 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)1 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)1 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)1 ProviderDataAccessor (com.synopsys.integration.alert.common.persistence.accessor.ProviderDataAccessor)1 ProviderUserModel (com.synopsys.integration.alert.common.persistence.model.ProviderUserModel)1 BlackDuckPropertiesFactory (com.synopsys.integration.alert.provider.blackduck.factory.BlackDuckPropertiesFactory)1 BlackDuckResponse (com.synopsys.integration.blackduck.api.core.BlackDuckResponse)1