Search in sources :

Example 1 with ComponentItem

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

the class MessageContentGroupCsvCreator method createRowValues.

private List<List<String>> createRowValues(LinkableItem commonProvider, LinkableItem commonTopic, List<ProviderMessageContent> contents) {
    List<List<String>> rows = new ArrayList<>();
    for (ProviderMessageContent message : contents) {
        String subTopicValue = createOptionalValueString(message.getSubTopic(), LinkableItem::getValue);
        Set<ComponentItem> componentItems = extractComponentItemsOrDefault(message);
        for (ComponentItem componentItem : componentItems) {
            List<String> columnValues = createColumnValues(commonProvider.getLabel(), commonProvider.getValue(), commonTopic.getValue(), subTopicValue, componentItem);
            rows.add(columnValues);
        }
    }
    return rows;
}
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) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with ComponentItem

use of com.synopsys.integration.alert.channel.email.attachment.compatibility.ComponentItem 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)

Example 3 with ComponentItem

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

the class ProjectMessageToMessageContentGroupConversionUtils method convertToComponentItems.

private static List<ComponentItem> convertToComponentItems(BomComponentDetails bomComponent) {
    List<ComponentItem> componentItems = new LinkedList<>();
    for (ComponentConcern componentConcern : bomComponent.getComponentConcerns()) {
        ComponentItem.Builder componentItemBuilder = new ComponentItem.Builder();
        componentItemBuilder.applyOperation(componentConcern.getOperation());
        ComponentConcernType type = componentConcern.getType();
        String category = StringUtils.capitalize(StringUtils.lowerCase(type.name()));
        componentItemBuilder.applyCategory(category);
        componentItemBuilder.applyComponentData(bomComponent.getComponent());
        bomComponent.getComponentVersion().ifPresent(componentItemBuilder::applySubComponent);
        String categoryItemLabel = convertToCategoryLabel(type);
        LinkableItem categoryItem = new LinkableItem(categoryItemLabel, componentConcern.getName(), componentConcern.getUrl().orElse(null));
        componentItemBuilder.applyCategoryItem(categoryItem);
        String severity = componentConcern.getSeverity().name();
        componentItemBuilder.applyCategoryGroupingAttribute("Severity", severity);
        boolean collapseOnCategory = ComponentConcernType.VULNERABILITY.equals(type);
        componentItemBuilder.applyCollapseOnCategory(collapseOnCategory);
        List<LinkableItem> componentAttributes = new LinkedList<>();
        componentAttributes.add(bomComponent.getLicense());
        LinkableItem usageItem = new LinkableItem("Usage", bomComponent.getUsage());
        componentAttributes.add(usageItem);
        ComponentUpgradeGuidance upgradeGuidance = bomComponent.getComponentUpgradeGuidance();
        upgradeGuidance.getLongTermUpgradeGuidance().ifPresent(componentAttributes::add);
        upgradeGuidance.getShortTermUpgradeGuidance().ifPresent(componentAttributes::add);
        componentAttributes.addAll(bomComponent.getAdditionalAttributes());
        componentItemBuilder.applyAllComponentAttributes(componentAttributes);
        try {
            componentItems.add(componentItemBuilder.build());
        } catch (AlertException e) {
        // Ignored for feature parity
        }
    }
    return componentItems;
}
Also used : ComponentItem(com.synopsys.integration.alert.channel.email.attachment.compatibility.ComponentItem) ComponentConcernType(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernType) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ComponentConcern(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern) LinkedList(java.util.LinkedList) ComponentUpgradeGuidance(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Aggregations

ComponentItem (com.synopsys.integration.alert.channel.email.attachment.compatibility.ComponentItem)3 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)3 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)2 ProviderMessageContent (com.synopsys.integration.alert.channel.email.attachment.compatibility.ProviderMessageContent)2 LinkedList (java.util.LinkedList)2 MessageContentGroup (com.synopsys.integration.alert.channel.email.attachment.compatibility.MessageContentGroup)1 BomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)1 ComponentConcern (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern)1 ComponentConcernType (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernType)1 ComponentUpgradeGuidance (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1