use of com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage in project hub-alert by blackducksoftware.
the class ProjectNotificationMessageExtractor method extract.
@Override
protected ProviderMessageHolder extract(NotificationContentWrapper notificationContentWrapper, ProjectNotificationContent notificationContent) {
AlertNotificationModel alertNotificationModel = notificationContentWrapper.getAlertNotificationModel();
Long providerConfigId = alertNotificationModel.getProviderConfigId();
String providerUrl;
try {
BlackDuckServicesFactory blackDuckServicesFactory = servicesFactoryCache.retrieveBlackDuckServicesFactory(providerConfigId);
providerUrl = blackDuckServicesFactory.getBlackDuckHttpClient().getBlackDuckUrl().string();
} catch (AlertConfigurationException e) {
logger.warn("Invalid BlackDuck configuration for notification. ID: {}. Name: {}", providerConfigId, alertNotificationModel.getProviderConfigName(), e);
return ProviderMessageHolder.empty();
}
LinkableItem providerItem = new LinkableItem(blackDuckProviderKey.getDisplayName(), alertNotificationModel.getProviderConfigName(), providerUrl);
ProviderDetails providerDetails = new ProviderDetails(alertNotificationModel.getProviderConfigId(), providerItem);
LinkableItem project = new LinkableItem(BlackDuckMessageLabels.LABEL_PROJECT, notificationContent.getProjectName(), notificationContent.getProject());
ProjectOperation operation = ProjectOperation.fromOperationType(notificationContent.getOperationType());
ProjectMessage projectMessage = ProjectMessage.projectStatusInfo(providerDetails, project, operation);
return new ProviderMessageHolder(List.of(projectMessage), List.of());
}
use of com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage 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.project.ProjectMessage in project hub-alert by blackducksoftware.
the class ProjectMessageConverter method convertToFormattedMessageChunks.
@Override
public List<String> convertToFormattedMessageChunks(ProjectMessage projectMessage, String jobName) {
ChunkedStringBuilder chunkedStringBuilder = new ChunkedStringBuilder(messageFormatter.getMaxMessageLength());
String projectString;
Optional<String> optionalProjectVersionString;
Optional<LinkableItem> optionalProjectVersion = projectMessage.getProjectVersion();
if (optionalProjectVersion.isPresent()) {
projectString = linkableItemConverter.convertToStringWithoutLink(projectMessage.getProject(), true);
optionalProjectVersionString = optionalProjectVersion.map(projectVersion -> linkableItemConverter.convertToString(projectVersion, true));
} else {
projectString = linkableItemConverter.convertToString(projectMessage.getProject(), true);
optionalProjectVersionString = Optional.empty();
}
String nonBreakingSpace = messageFormatter.getNonBreakingSpace();
String jobLine = String.format("Job%sname:%s%s", nonBreakingSpace, nonBreakingSpace, jobName);
String boldJobName = messageFormatter.emphasize(jobLine);
chunkedStringBuilder.append(boldJobName);
chunkedStringBuilder.append(messageFormatter.getLineSeparator());
chunkedStringBuilder.append(projectString);
chunkedStringBuilder.append(messageFormatter.getLineSeparator());
optionalProjectVersionString.ifPresent(projectVersionString -> {
chunkedStringBuilder.append(projectVersionString);
chunkedStringBuilder.append(messageFormatter.getLineSeparator());
});
MessageReason messageReason = projectMessage.getMessageReason();
if (MessageReason.PROJECT_STATUS.equals(messageReason) || MessageReason.PROJECT_VERSION_STATUS.equals(messageReason)) {
projectMessage.getOperation().map(operation -> String.format("Project%sAction:%s%s", nonBreakingSpace, nonBreakingSpace, operation.name())).map(messageFormatter::encode).ifPresent(chunkedStringBuilder::append);
return chunkedStringBuilder.collectCurrentChunks();
}
List<BomComponentDetails> bomComponents = projectMessage.getBomComponents();
if (!bomComponents.isEmpty()) {
chunkedStringBuilder.append(messageFormatter.getSectionSeparator());
chunkedStringBuilder.append(messageFormatter.getLineSeparator());
}
for (BomComponentDetails bomComponentDetails : bomComponents) {
List<String> bomComponentMessagePieces = gatherBomComponentAndConcernSectionPieces(bomComponentDetails);
bomComponentMessagePieces.forEach(chunkedStringBuilder::append);
chunkedStringBuilder.append(messageFormatter.getSectionSeparator());
chunkedStringBuilder.append(messageFormatter.getLineSeparator());
}
return chunkedStringBuilder.collectCurrentChunks();
}
use of com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage in project hub-alert by blackducksoftware.
the class NotificationContentProcessorTest method processNotificationContentSummaryTest.
@Test
public void processNotificationContentSummaryTest() {
AlertNotificationModel notificationModel = createNotification(NotificationType.RULE_VIOLATION.name());
RuleViolationUniquePolicyNotificationContent notificationContent = blackDuckResponseTestUtility.createRuleViolationUniquePolicyNotificationContent(projectName, projectVersionName);
NotificationContentWrapper notificationContentWrapper1 = new NotificationContentWrapper(notificationModel, notificationContent, RuleViolationUniquePolicyNotificationContent.class);
// When set to summary, project messages will be summarized into a SimpleMessage rather than ProjectMessage
ProcessedProviderMessageHolder processedProviderMessageHolder = notificationContentProcessor.processNotificationContent(ProcessingType.SUMMARY, List.of(notificationContentWrapper1));
List<ProcessedProviderMessage<ProjectMessage>> processedProviderMessages = processedProviderMessageHolder.getProcessedProjectMessages();
List<ProcessedProviderMessage<SimpleMessage>> processedSimpleMessages = processedProviderMessageHolder.getProcessedSimpleMessages();
assertTrue(processedProviderMessages.isEmpty());
assertEquals(1, processedSimpleMessages.size());
ProcessedProviderMessage<SimpleMessage> processedSimpleMessage = processedSimpleMessages.get(0);
assertEquals(1, processedSimpleMessage.getNotificationIds().size());
assertTrue(processedSimpleMessage.getNotificationIds().contains(notificationId));
SimpleMessage simpleMessage = processedSimpleMessage.getProviderMessage();
assertEquals(PROVIDER_DETAILS, simpleMessage.getProviderDetails());
assertTrue(simpleMessage.getSource().isPresent());
ProjectMessage sourceProjectMessage = simpleMessage.getSource().get();
assertEquals(projectName, sourceProjectMessage.getProject().getValue());
assertTrue(sourceProjectMessage.getProjectVersion().isPresent());
assertEquals(projectVersionName, sourceProjectMessage.getProjectVersion().get().getValue());
}
use of com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage in project hub-alert by blackducksoftware.
the class NotificationContentProcessorTest method runProjectMessageAssertions.
private void runProjectMessageAssertions(ProcessedProviderMessageHolder processedProviderMessageHolder, String projectName, String projectVersionName) {
List<ProcessedProviderMessage<ProjectMessage>> processedProjectMessages = processedProviderMessageHolder.getProcessedProjectMessages();
List<ProcessedProviderMessage<SimpleMessage>> processedSimpleMessages = processedProviderMessageHolder.getProcessedSimpleMessages();
assertTrue(processedSimpleMessages.isEmpty());
assertEquals(1, processedProjectMessages.size());
ProcessedProviderMessage<ProjectMessage> processedProjectMessage = processedProjectMessages.get(0);
assertEquals(1, processedProjectMessage.getNotificationIds().size());
assertTrue(processedProjectMessage.getNotificationIds().contains(notificationId));
ProjectMessage projectMessage = processedProjectMessage.getProviderMessage();
assertEquals(projectName, projectMessage.getProject().getValue());
assertTrue(projectMessage.getProjectVersion().isPresent());
assertEquals(projectVersionName, projectMessage.getProjectVersion().get().getValue());
assertEquals(PROVIDER_DETAILS, projectMessage.getProviderDetails());
}
Aggregations