Search in sources :

Example 1 with ComponentConcernType

use of com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernType in project hub-alert by blackducksoftware.

the class JiraIssueCreator method createSearchProperties.

private JiraIssueSearchProperties createSearchProperties(ProjectIssueModel alertIssueSource) {
    LinkableItem provider = alertIssueSource.getProvider();
    LinkableItem project = alertIssueSource.getProject();
    LinkableItem projectVersion = alertIssueSource.getProjectVersion().orElseThrow(() -> new AlertRuntimeException("Missing project version"));
    IssueBomComponentDetails bomComponent = alertIssueSource.getBomComponentDetails();
    LinkableItem component = bomComponent.getComponent();
    String componentVersionLabel = bomComponent.getComponentVersion().map(LinkableItem::getLabel).orElse(null);
    String componentVersionName = bomComponent.getComponentVersion().map(LinkableItem::getValue).orElse(null);
    String additionalKey = null;
    ComponentConcernType concernType = ComponentConcernType.VULNERABILITY;
    Optional<String> optionalPolicyName = alertIssueSource.getPolicyDetails().map(IssuePolicyDetails::getName);
    if (optionalPolicyName.isPresent()) {
        concernType = ComponentConcernType.POLICY;
        additionalKey = JiraIssueSearchPropertyStringCompatibilityUtils.createPolicyAdditionalKey(optionalPolicyName.get());
    }
    if (alertIssueSource.getComponentUnknownVersionDetails().isPresent()) {
        concernType = ComponentConcernType.UNKNOWN_VERSION;
    }
    String category = JiraIssueSearchPropertyStringCompatibilityUtils.createCategory(concernType);
    return new JiraIssueSearchProperties(provider.getLabel(), provider.getUrl().flatMap(JiraIssueAlertPropertiesUrlCorrector::correctUrl).orElse(null), project.getLabel(), project.getValue(), projectVersion.getLabel(), projectVersion.getValue(), category, component.getLabel(), component.getValue(), componentVersionLabel, componentVersionName, additionalKey);
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ComponentConcernType(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernType) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) JiraIssueSearchProperties(com.synopsys.integration.alert.api.channel.jira.JiraIssueSearchProperties) JiraIssueAlertPropertiesUrlCorrector(com.synopsys.integration.alert.api.channel.jira.distribution.search.JiraIssueAlertPropertiesUrlCorrector) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)

Example 2 with ComponentConcernType

use of com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernType in project hub-alert by blackducksoftware.

the class JiraExactIssueFinder method findExistingIssuesByProjectIssueModel.

@Override
public List<ExistingIssueDetails<String>> findExistingIssuesByProjectIssueModel(ProjectIssueModel projectIssueModel) throws AlertException {
    LinkableItem provider = projectIssueModel.getProvider();
    LinkableItem project = projectIssueModel.getProject();
    IssueBomComponentDetails bomComponent = projectIssueModel.getBomComponentDetails();
    ComponentConcernType concernType = ComponentConcernType.VULNERABILITY;
    String policyName = null;
    Optional<IssuePolicyDetails> policyDetails = projectIssueModel.getPolicyDetails();
    Optional<String> optionalPolicyName = policyDetails.map(IssuePolicyDetails::getName);
    if (optionalPolicyName.isPresent()) {
        concernType = ComponentConcernType.POLICY;
        policyName = optionalPolicyName.get();
    }
    if (projectIssueModel.getComponentUnknownVersionDetails().isPresent()) {
        concernType = ComponentConcernType.UNKNOWN_VERSION;
    }
    String jqlString = JqlStringCreator.createBlackDuckComponentConcernIssuesSearchString(jiraProjectKey, provider, project, projectIssueModel.getProjectVersion().orElse(null), bomComponent.getComponent(), bomComponent.getComponentVersion().orElse(null), concernType, policyName);
    logger.debug("Searching for Jira issues with this Query: {}", jqlString);
    IssueCategory issueCategory = issueCategoryRetriever.retrieveIssueCategoryFromComponentConcernType(concernType);
    return jqlQueryExecutor.executeQuery(jqlString).stream().map(jiraSearcherResponseModel -> searchResultCreator.createExistingIssueDetails(jiraSearcherResponseModel, issueCategory)).collect(Collectors.toList());
}
Also used : Logger(org.slf4j.Logger) ExactIssueFinder(com.synopsys.integration.alert.api.channel.issue.search.ExactIssueFinder) ComponentConcernType(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernType) LoggerFactory(org.slf4j.LoggerFactory) IssueCategory(com.synopsys.integration.alert.api.channel.issue.search.enumeration.IssueCategory) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ExistingIssueDetails(com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails) Collectors(java.util.stream.Collectors) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) List(java.util.List) Optional(java.util.Optional) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) IssueCategoryRetriever(com.synopsys.integration.alert.api.channel.issue.search.IssueCategoryRetriever) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ComponentConcernType(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernType) IssueCategory(com.synopsys.integration.alert.api.channel.issue.search.enumeration.IssueCategory) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails)

Example 3 with ComponentConcernType

use of com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernType 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

LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)3 ComponentConcernType (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernType)3 IssueBomComponentDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails)2 IssuePolicyDetails (com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails)2 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)2 ProjectIssueModel (com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel)1 ExactIssueFinder (com.synopsys.integration.alert.api.channel.issue.search.ExactIssueFinder)1 ExistingIssueDetails (com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails)1 IssueCategoryRetriever (com.synopsys.integration.alert.api.channel.issue.search.IssueCategoryRetriever)1 IssueCategory (com.synopsys.integration.alert.api.channel.issue.search.enumeration.IssueCategory)1 JiraIssueSearchProperties (com.synopsys.integration.alert.api.channel.jira.JiraIssueSearchProperties)1 JiraIssueAlertPropertiesUrlCorrector (com.synopsys.integration.alert.api.channel.jira.distribution.search.JiraIssueAlertPropertiesUrlCorrector)1 AlertRuntimeException (com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)1 ComponentItem (com.synopsys.integration.alert.channel.email.attachment.compatibility.ComponentItem)1 ComponentConcern (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern)1 ComponentUpgradeGuidance (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1