use of com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder 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.processor.api.extract.model.ProviderMessageHolder 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.processor.api.extract.model.ProviderMessageHolder in project hub-alert by blackducksoftware.
the class DistributionChannelMessageTestAction method testConfig.
@Override
public final MessageResult testConfig(DistributionJobModel testJobModel, String jobName, @Nullable String customTopic, @Nullable String customMessage) throws AlertException {
String topicString = Optional.ofNullable(customTopic).orElse(DEFAULT_TOPIC);
String messageString = Optional.ofNullable(customMessage).orElse(DEFAULT_MESSAGE);
D distributionJobDetails = resolveTestDistributionDetails(testJobModel);
ProviderMessageHolder messages = createTestMessageHolder(testJobModel, topicString, messageString);
return distributionChannel.distributeMessages(distributionJobDetails, messages, jobName);
}
use of com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder in project hub-alert by blackducksoftware.
the class DistributionChannelMessageTestAction method createTestMessageHolder.
private ProviderMessageHolder createTestMessageHolder(DistributionJobModel testJobModel, String summary, String message) {
// TODO determine if it's worth it to make a DB call to resolve the provider
LinkableItem providerItem = new LinkableItem("Provider Label", "Provider Config Name");
ProviderDetails providerDetails = new ProviderDetails(testJobModel.getBlackDuckGlobalConfigId(), providerItem);
SimpleMessage testMessage = SimpleMessage.original(providerDetails, summary, message, List.of());
return new ProviderMessageHolder(List.of(), List.of(testMessage));
}
use of com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder in project hub-alert by blackducksoftware.
the class AbstractChannelMessageConverterTest method convertToChannelMessagesTest.
@Test
public void convertToChannelMessagesTest() {
MockChannelMessageFormatter mockChannelMessageFormatter = new MockChannelMessageFormatter(Integer.MAX_VALUE);
MockChannelMessageConverter mockChannelMessageConverter = new MockChannelMessageConverter(mockChannelMessageFormatter);
MockDistributionJobDetailsModel jobDetails = new MockDistributionJobDetailsModel(UUID.randomUUID());
ProviderDetails providerDetails = new ProviderDetails(0L, new LinkableItem("Provider", "Black Duck"));
ProjectMessage projectCreateMessage = ProjectMessage.projectStatusInfo(providerDetails, new LinkableItem("Project", "A project"), ProjectOperation.CREATE);
SimpleMessage simpleMessage = SimpleMessage.original(providerDetails, "Summary", "Description", List.of());
ProviderMessageHolder providerMessageHolder = new ProviderMessageHolder(List.of(projectCreateMessage), List.of(simpleMessage));
List<MockOutputModel> mockOutputModels = mockChannelMessageConverter.convertToChannelMessages(jobDetails, providerMessageHolder, "jobName");
assertEquals(2, mockOutputModels.size());
for (MockOutputModel mockOutputModel : mockOutputModels) {
assertEquals(1, mockOutputModel.getMessagePieces().size());
}
}
Aggregations