use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.
the class LicenseLimitNotificationMessageExtractor method extract.
@Override
protected ProviderMessageHolder extract(NotificationContentWrapper notificationContentWrapper, LicenseLimitNotificationContent notificationContent) {
AlertNotificationModel alertNotificationModel = notificationContentWrapper.getAlertNotificationModel();
LinkableItem providerItem = new LinkableItem(blackDuckProviderKey.getDisplayName(), alertNotificationModel.getProviderConfigName());
ProviderDetails providerDetails = new ProviderDetails(alertNotificationModel.getProviderConfigId(), providerItem);
String summary = "License Limit Event";
List<LinkableItem> details = new LinkedList<>();
String marketingPageUrl = notificationContent.getMarketingPageUrl();
if (StringUtils.isNotBlank(marketingPageUrl)) {
LinkableItem marketingDetail = new LinkableItem("Marketing Page", "Visit", marketingPageUrl);
details.add(marketingDetail);
}
Long usedCodeSize = notificationContent.getUsedCodeSize();
if (null != usedCodeSize) {
LinkableItem usedCodeSizeDetail = new LinkableItem("Used Code Size", usedCodeSize.toString());
details.add(usedCodeSizeDetail);
}
Long hardLimit = notificationContent.getHardLimit();
if (null != hardLimit) {
LinkableItem hardLimitDetail = new LinkableItem("Hard Limit", hardLimit.toString());
details.add(hardLimitDetail);
}
Long softLimit = notificationContent.getSoftLimit();
if (null != softLimit) {
LinkableItem softLimitDetail = new LinkableItem("Soft Limit", softLimit.toString());
details.add(softLimitDetail);
}
SimpleMessage licenseLimitMessage = SimpleMessage.original(providerDetails, summary, notificationContent.getMessage(), details);
return new ProviderMessageHolder(List.of(), List.of(licenseLimitMessage));
}
use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.
the class AbstractBlackDuckComponentConcernMessageExtractor method extract.
@Override
protected final ProviderMessageHolder extract(NotificationContentWrapper notificationContentWrapper, T notificationContent) {
AlertNotificationModel notificationModel = notificationContentWrapper.getAlertNotificationModel();
Long providerConfigId = notificationModel.getProviderConfigId();
String providerUrl;
List<BomComponentDetails> bomComponentDetails;
try {
BlackDuckServicesFactory blackDuckServicesFactory = servicesFactoryCache.retrieveBlackDuckServicesFactory(providerConfigId);
providerUrl = blackDuckServicesFactory.getBlackDuckHttpClient().getBlackDuckUrl().string();
bomComponentDetails = createBomComponentDetails(notificationContent, blackDuckServicesFactory);
} catch (AlertConfigurationException e) {
logger.warn("Invalid BlackDuck configuration for notification. ID: {}. Name: {}", providerConfigId, notificationModel.getProviderConfigName(), e);
return ProviderMessageHolder.empty();
} catch (IntegrationException e) {
logger.warn("Failed to retrieve BOM Component(s) from BlackDuck", e);
return ProviderMessageHolder.empty();
}
LinkableItem providerItem = new LinkableItem(blackDuckProviderKey.getDisplayName(), notificationModel.getProviderConfigName(), providerUrl);
ProviderDetails providerDetails = new ProviderDetails(notificationModel.getProviderConfigId(), providerItem);
Optional<String> projectUrl = extractProjectUrl(notificationContent.getProjectVersionUrl());
LinkableItem project = new LinkableItem(BlackDuckMessageLabels.LABEL_PROJECT, notificationContent.getProjectName(), projectUrl.orElse(null));
LinkableItem projectVersion = new LinkableItem(BlackDuckMessageLabels.LABEL_PROJECT_VERSION, notificationContent.getProjectVersionName(), notificationContent.getProjectVersionUrl());
// FIXME this is where I should put the additional info
ProjectMessage projectMessage = createProjectMessage(providerDetails, project, projectVersion, bomComponentDetails);
return new ProviderMessageHolder(List.of(projectMessage), List.of());
}
use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.
the class LicenseLimitNotificationDetailExtractorTest method extractDetailedContentTest.
@Test
public void extractDetailedContentTest() {
LicenseLimitNotificationDetailExtractor extractor = new LicenseLimitNotificationDetailExtractor();
LicenseLimitNotificationView notificationView = new LicenseLimitNotificationView();
LicenseLimitNotificationContent notificationContent = new LicenseLimitNotificationContent();
notificationView.setContent(notificationContent);
AlertNotificationModel notification = new AlertNotificationModel(0L, 0L, "BlackDuck", "Config 1", null, null, null, null, false);
List<DetailedNotificationContent> detailedNotificationContents = extractor.extractDetailedContent(notification, notificationView);
assertEquals(1, detailedNotificationContents.size());
DetailedNotificationContent detailedNotificationContent = detailedNotificationContents.get(0);
assertTrue(detailedNotificationContent.getProjectName().isEmpty(), "Expected no project name to be present");
assertTrue(detailedNotificationContent.getPolicyName().isEmpty(), "Expected no policy name to be present");
assertEquals(0, detailedNotificationContent.getVulnerabilitySeverities().size());
}
use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.
the class ProjectNotificationDetailExtractorTest method extractDetailedContentTest.
@Test
public void extractDetailedContentTest() throws IOException {
String jsonContent = TestResourceUtils.readFileToString(NOTIFICATION_JSON_PATH);
ProjectNotificationView projectNotificationView = gson.fromJson(jsonContent, ProjectNotificationView.class);
ProjectNotificationContent projectNotificationContent = projectNotificationView.getContent();
AlertNotificationModel notification = new AlertNotificationModel(0L, 0L, "BlackDuck", "Config 1", null, null, null, null, false);
ProjectNotificationDetailExtractor extractor = new ProjectNotificationDetailExtractor();
List<DetailedNotificationContent> detailedNotificationContents = extractor.extractDetailedContent(notification, projectNotificationView);
assertEquals(1, detailedNotificationContents.size());
DetailedNotificationContent detailedNotificationContent = detailedNotificationContents.get(0);
Optional<String> optionalProjectName = detailedNotificationContent.getProjectName();
assertTrue(optionalProjectName.isPresent(), "Expect project name to be present");
assertEquals(projectNotificationContent.getProjectName(), optionalProjectName.get());
assertTrue(detailedNotificationContent.getPolicyName().isEmpty(), "Expected no policy name to be present");
assertEquals(0, detailedNotificationContent.getVulnerabilitySeverities().size());
}
use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.
the class VulnerabilityNotificationDetailExtractorTest method verifyExtraction.
@Test
public void verifyExtraction() throws IOException {
VulnerabilityNotificationView vulnerabilityNotificationView = getVulnerabilityNotificationView(VULNERABILITY_COMPLEX_JSON_PATH);
VulnerabilityNotificationContent content = vulnerabilityNotificationView.getContent();
VulnerabilityNotificationDetailExtractor vulnerabilityNotificationDetailExtractor = new VulnerabilityNotificationDetailExtractor();
AlertNotificationModel alertNotificationModel = createAlertNotificationModel();
List<DetailedNotificationContent> filterableNotificationWrappers = vulnerabilityNotificationDetailExtractor.extractDetailedContent(alertNotificationModel, vulnerabilityNotificationView);
assertEquals(3, filterableNotificationWrappers.size());
for (DetailedNotificationContent filterableNotificationWrapper : filterableNotificationWrappers) {
NotificationContentWrapper notificationContentWrapper = filterableNotificationWrapper.getNotificationContentWrapper();
assertEquals(NotificationType.VULNERABILITY.name(), notificationContentWrapper.extractNotificationType());
// The Vuln extractor should return a different object structure
assertNotEquals(content, notificationContentWrapper.getNotificationContent());
assertEquals(3, filterableNotificationWrapper.getVulnerabilitySeverities().size());
assertFalse(filterableNotificationWrapper.getVulnerabilitySeverities().contains(VulnerabilitySeverityType.CRITICAL.name()));
assertTrue(filterableNotificationWrapper.getPolicyName().isEmpty(), "Expected no policy name to be present");
}
}
Aggregations