use of com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper 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();
}
use of com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper 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.service.model.ProjectVersionWrapper in project hub-alert by blackducksoftware.
the class BlackDuckProviderService method triggerBlackDuckNotification.
public void triggerBlackDuckNotification(Supplier<ExternalId> externalIdSupplier, Predicate<ProjectVersionComponentVersionView> componentFilter) throws IntegrationException {
setupBlackDuckServicesFactory();
BlackDuckApiClient blackDuckService = blackDuckServicesFactory.getBlackDuckApiClient();
ProjectService projectService = blackDuckServicesFactory.createProjectService();
ProjectVersionWrapper projectVersion = projectService.getProjectVersion(blackDuckProjectName, blackDuckProjectVersion).orElseThrow(() -> new IntegrationException(String.format("Could not find the Black Duck project '%s' version '%s'", blackDuckProjectName, blackDuckProjectVersion)));
ProjectVersionView projectVersionView = projectVersion.getProjectVersionView();
List<ProjectVersionComponentVersionView> bomComponents = blackDuckService.getAllResponses(projectVersionView.metaComponentsLink());
Optional<ProjectVersionComponentVersionView> apacheCommonsFileUpload = bomComponents.stream().filter(componentFilter).findFirst();
if (apacheCommonsFileUpload.isPresent()) {
blackDuckService.delete(apacheCommonsFileUpload.get());
// Thread.currentThread().wait(1000);
}
ExternalId externalId = externalIdSupplier.get();
ProjectBomService projectBomService = blackDuckServicesFactory.createProjectBomService();
projectBomService.addComponentToProjectVersion(externalId, projectVersionView);
}
Aggregations