Search in sources :

Example 11 with ProjectView

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

Example 12 with ProjectView

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

the class BlackDuckProviderDataAccessor method convertBlackDuckProjects.

private List<ProviderProject> convertBlackDuckProjects(List<ProjectView> projectViews, BlackDuckApiClient blackDuckService) {
    List<ProviderProject> providerProjects = new ArrayList<>();
    for (ProjectView projectView : projectViews) {
        ProviderProject providerProject = createProviderProject(projectView, blackDuckService);
        providerProjects.add(providerProject);
    }
    return providerProjects;
}
Also used : ArrayList(java.util.ArrayList) ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView)

Example 13 with ProjectView

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

the class BomEditNotificationDetailExtractor method retrieveProjectAndVersion.

private Optional<ProjectVersionWrapper> retrieveProjectAndVersion(Long blackDuckConfigId, String projectVersionUrl) {
    try {
        BlackDuckServicesFactory blackDuckServicesFactory = servicesFactoryCache.retrieveBlackDuckServicesFactory(blackDuckConfigId);
        BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
        ProjectVersionView projectVersion = blackDuckApiClient.getResponse(new HttpUrl(projectVersionUrl), ProjectVersionView.class);
        ProjectView projectView = blackDuckApiClient.getResponse(projectVersion.metaProjectLink());
        return Optional.of(new ProjectVersionWrapper(projectView, projectVersion));
    } catch (IntegrationException e) {
        logger.error("Failed to connect to BlackDuck. Config ID: {}", blackDuckConfigId, e);
    }
    return Optional.empty();
}
Also used : IntegrationException(com.synopsys.integration.exception.IntegrationException) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) HttpUrl(com.synopsys.integration.rest.HttpUrl)

Example 14 with ProjectView

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

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

the class BlackDuckDataSyncTask method runProviderTask.

@Override
public void runProviderTask() {
    try {
        BlackDuckProperties providerProperties = getProviderProperties();
        Optional<BlackDuckHttpClient> optionalBlackDuckHttpClient = providerProperties.createBlackDuckHttpClientAndLogErrors(logger);
        if (optionalBlackDuckHttpClient.isPresent()) {
            BlackDuckHttpClient blackDuckHttpClient = optionalBlackDuckHttpClient.get();
            BlackDuckServicesFactory blackDuckServicesFactory = providerProperties.createBlackDuckServicesFactory(blackDuckHttpClient, new Slf4jIntLogger(logger));
            ProjectUsersService projectUsersService = blackDuckServicesFactory.createProjectUsersService();
            BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
            ApiDiscovery apiDiscovery = blackDuckServicesFactory.getApiDiscovery();
            List<ProjectView> projectViews = blackDuckApiClient.getAllResponses(apiDiscovery.metaProjectsLink());
            Map<ProjectView, ProviderProject> blackDuckToAlertProjects = mapBlackDuckProjectsToAlertProjects(projectViews, blackDuckApiClient);
            Map<ProviderProject, Set<String>> projectToEmailAddresses = getEmailsPerProject(blackDuckToAlertProjects, projectUsersService);
            Set<String> allRelevantBlackDuckUsers = getAllActiveBlackDuckUserEmailAddresses(blackDuckApiClient, apiDiscovery);
            blackDuckDataAccessor.updateProjectAndUserData(providerProperties.getConfigId(), projectToEmailAddresses, allRelevantBlackDuckUsers);
        } else {
            logger.error("Missing BlackDuck global configuration.");
        }
    } catch (IntegrationException | AlertRuntimeException e) {
        logger.error(String.format("Could not retrieve the current data from the BlackDuck server: %s", e.getMessage()), e);
    }
}
Also used : ProjectUsersService(com.synopsys.integration.blackduck.service.dataservice.ProjectUsersService) BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) Set(java.util.Set) IntegrationException(com.synopsys.integration.exception.IntegrationException) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) ApiDiscovery(com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) 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)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