Search in sources :

Example 1 with MessageContentGroup

use of com.synopsys.integration.alert.channel.email.attachment.compatibility.MessageContentGroup in project hub-alert by blackducksoftware.

the class MessageContentGroupCsvCreatorTest method createCsvStringTest.

@Test
public void createCsvStringTest() throws AlertException {
    MessageContentGroup messageContentGroup = new MessageContentGroup();
    ProviderMessageContent.Builder providerMessageBuilder = new ProviderMessageContent.Builder();
    providerMessageBuilder.applyProvider("Example Provider", 1L, "Example Config");
    providerMessageBuilder.applyTopic("Example Topic Name", "Example Topic Value");
    ComponentItem.Builder componentItemBuilder = new ComponentItem.Builder();
    componentItemBuilder.applyNotificationId(1L);
    componentItemBuilder.applyOperation(ItemOperation.INFO);
    componentItemBuilder.applyCategory("Example Category");
    componentItemBuilder.applyComponentData("Example Component Name", "Example Component Value", "https://google.com");
    componentItemBuilder.applySubComponent("Example SubComponent Name", "Example SubComponent Value", "https://google.com");
    componentItemBuilder.applyCategoryItem("Example Category Item Name", "Example Category Item Value");
    componentItemBuilder.applyCategoryGroupingAttribute("Example Category Grouping Attribute Name", "Example Category Grouping Attribute Value");
    providerMessageBuilder.applyComponentItem(componentItemBuilder.build());
    messageContentGroup.add(providerMessageBuilder.build());
    MessageContentGroupCsvCreator messageContentGroupCsvCreator = new MessageContentGroupCsvCreator();
    String csvString = messageContentGroupCsvCreator.createCsvString(messageContentGroup);
    assertNotNull(csvString);
}
Also used : ComponentItem(com.synopsys.integration.alert.channel.email.attachment.compatibility.ComponentItem) ProviderMessageContent(com.synopsys.integration.alert.channel.email.attachment.compatibility.ProviderMessageContent) MessageContentGroup(com.synopsys.integration.alert.channel.email.attachment.compatibility.MessageContentGroup) Test(org.junit.jupiter.api.Test)

Example 2 with MessageContentGroup

use of com.synopsys.integration.alert.channel.email.attachment.compatibility.MessageContentGroup in project hub-alert by blackducksoftware.

the class ProjectMessageToMessageContentGroupConversionUtils method toMessageContentGroup.

public static MessageContentGroup toMessageContentGroup(ProjectMessage projectMessage) {
    ProviderMessageContent.Builder providerMessageContentBuilder = new ProviderMessageContent.Builder();
    LinkableItem provider = projectMessage.getProvider();
    providerMessageContentBuilder.applyProvider(provider.getLabel(), -1L, provider.getValue(), provider.getUrl().orElse(null));
    LinkableItem project = projectMessage.getProject();
    providerMessageContentBuilder.applyTopic(project.getLabel(), project.getValue(), project.getUrl().orElse(null));
    Optional<LinkableItem> optionalProjectVersion = projectMessage.getProjectVersion();
    if (optionalProjectVersion.isPresent()) {
        LinkableItem projectVersion = optionalProjectVersion.get();
        providerMessageContentBuilder.applySubTopic(projectVersion.getLabel(), projectVersion.getValue(), projectVersion.getUrl().orElse(null));
    }
    projectMessage.getOperation().map(ProjectMessageToMessageContentGroupConversionUtils::convertToItemOperation).ifPresent(providerMessageContentBuilder::applyAction);
    MessageContentGroup messageContentGroup = new MessageContentGroup();
    List<ComponentItem> componentItems = new LinkedList<>();
    for (BomComponentDetails bomComponent : projectMessage.getBomComponents()) {
        List<ComponentItem> bomComponentItems = convertToComponentItems(bomComponent);
        componentItems.addAll(bomComponentItems);
    }
    providerMessageContentBuilder.applyAllComponentItems(componentItems);
    try {
        ProviderMessageContent providerMessageContent = providerMessageContentBuilder.build();
        messageContentGroup.add(providerMessageContent);
    } catch (AlertException e) {
    // Ignore for feature parity
    }
    return messageContentGroup;
}
Also used : ComponentItem(com.synopsys.integration.alert.channel.email.attachment.compatibility.ComponentItem) ProviderMessageContent(com.synopsys.integration.alert.channel.email.attachment.compatibility.ProviderMessageContent) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) MessageContentGroup(com.synopsys.integration.alert.channel.email.attachment.compatibility.MessageContentGroup) LinkedList(java.util.LinkedList) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) BomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)

Aggregations

ComponentItem (com.synopsys.integration.alert.channel.email.attachment.compatibility.ComponentItem)2 MessageContentGroup (com.synopsys.integration.alert.channel.email.attachment.compatibility.MessageContentGroup)2 ProviderMessageContent (com.synopsys.integration.alert.channel.email.attachment.compatibility.ProviderMessageContent)2 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)1 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)1 BomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)1 LinkedList (java.util.LinkedList)1 Test (org.junit.jupiter.api.Test)1