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);
}
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;
}
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();
}
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;
}
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);
}
}
Aggregations