Search in sources :

Example 6 with IssuePolicyDetails

use of com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails 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 7 with IssuePolicyDetails

use of com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails in project hub-alert by blackducksoftware.

the class JiraIssueCreator method createCustomFieldReplacementValues.

protected MessageReplacementValues createCustomFieldReplacementValues(ProjectIssueModel alertIssueSource) {
    IssueBomComponentDetails bomComponent = alertIssueSource.getBomComponentDetails();
    ComponentUpgradeGuidance upgradeGuidance = bomComponent.getComponentUpgradeGuidance();
    Optional<String> severity = Optional.empty();
    Optional<String> policyCategory = Optional.empty();
    Optional<IssuePolicyDetails> issuePolicyDetails = alertIssueSource.getPolicyDetails();
    Optional<IssueVulnerabilityDetails> vulnerabilityDetails = alertIssueSource.getVulnerabilityDetails();
    if (issuePolicyDetails.isPresent()) {
        IssuePolicyDetails policyDetails = issuePolicyDetails.get();
        severity = Optional.ofNullable(policyDetails.getSeverity().getPolicyLabel());
        policyCategory = bomComponent.getRelevantPolicies().stream().filter(policy -> policyDetails.getName().equals(policy.getPolicyName())).findAny().flatMap(ComponentPolicy::getCategory);
    }
    if (vulnerabilityDetails.isPresent()) {
        severity = vulnerabilityDetails.get().getHighestSeverityAddedOrUpdated();
    }
    return new MessageReplacementValues.Builder(alertIssueSource.getProvider().getLabel(), alertIssueSource.getProject().getValue()).projectVersionName(alertIssueSource.getProjectVersion().map(LinkableItem::getValue).orElse(MessageReplacementValues.DEFAULT_NOTIFICATION_REPLACEMENT_VALUE)).componentName(bomComponent.getComponent().getValue()).componentVersionName(bomComponent.getComponentVersion().map(LinkableItem::getValue).orElse(MessageReplacementValues.DEFAULT_NOTIFICATION_REPLACEMENT_VALUE)).componentUsage(bomComponent.getUsage()).componentLicense(bomComponent.getLicense().getValue()).severity(severity.orElse(MessageReplacementValues.DEFAULT_NOTIFICATION_REPLACEMENT_VALUE)).policyCategory(policyCategory.orElse(MessageReplacementValues.DEFAULT_NOTIFICATION_REPLACEMENT_VALUE)).shortTermUpgradeGuidance(upgradeGuidance.getShortTermUpgradeGuidance().map(LinkableItem::getValue).orElse(MessageReplacementValues.DEFAULT_NOTIFICATION_REPLACEMENT_VALUE)).longTermUpgradeGuidance(upgradeGuidance.getLongTermUpgradeGuidance().map(LinkableItem::getValue).orElse(MessageReplacementValues.DEFAULT_NOTIFICATION_REPLACEMENT_VALUE)).build();
}
Also used : IntegrationException(com.synopsys.integration.exception.IntegrationException) MessageReplacementValues(com.synopsys.integration.alert.api.channel.jira.distribution.custom.MessageReplacementValues) ComponentConcernType(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernType) ExistingIssueDetails(com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails) StringUtils(org.apache.commons.lang3.StringUtils) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) IssueResponseModel(com.synopsys.integration.jira.common.model.response.IssueResponseModel) IssueVulnerabilityDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails) JiraIssueSearchProperties(com.synopsys.integration.alert.api.channel.jira.JiraIssueSearchProperties) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) ComponentPolicy(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentPolicy) IssueCreationResponseModel(com.synopsys.integration.jira.common.model.response.IssueCreationResponseModel) IssueCategoryRetriever(com.synopsys.integration.alert.api.channel.issue.search.IssueCategoryRetriever) ComponentUpgradeGuidance(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance) IssueStatus(com.synopsys.integration.alert.api.channel.issue.search.enumeration.IssueStatus) IssueTrackerIssueCommenter(com.synopsys.integration.alert.api.channel.issue.send.IssueTrackerIssueCommenter) JiraPreconditionNotMetException(com.synopsys.integration.jira.common.exception.JiraPreconditionNotMetException) JiraIssueAlertPropertiesUrlCorrector(com.synopsys.integration.alert.api.channel.jira.distribution.search.JiraIssueAlertPropertiesUrlCorrector) JiraIssueAlertPropertiesManager(com.synopsys.integration.alert.api.channel.jira.distribution.search.JiraIssueAlertPropertiesManager) JiraErrorMessageUtility(com.synopsys.integration.alert.api.channel.jira.distribution.JiraErrorMessageUtility) IssueCategory(com.synopsys.integration.alert.api.channel.issue.search.enumeration.IssueCategory) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) IssueFieldsComponent(com.synopsys.integration.jira.common.model.components.IssueFieldsComponent) IssueCreationModel(com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) IssueTrackerIssueCreator(com.synopsys.integration.alert.api.channel.issue.send.IssueTrackerIssueCreator) IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException) Optional(java.util.Optional) JiraIssueSearchPropertyStringCompatibilityUtils(com.synopsys.integration.alert.api.channel.jira.distribution.search.JiraIssueSearchPropertyStringCompatibilityUtils) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) IssueTrackerCallbackInfoCreator(com.synopsys.integration.alert.api.channel.issue.callback.IssueTrackerCallbackInfoCreator) JiraCallbackUtils(com.synopsys.integration.alert.api.channel.jira.util.JiraCallbackUtils) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) IssueTrackerChannelKey(com.synopsys.integration.alert.descriptor.api.model.IssueTrackerChannelKey) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) IssueVulnerabilityDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails) ComponentUpgradeGuidance(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails)

Example 8 with IssuePolicyDetails

use of com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails 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 9 with IssuePolicyDetails

use of com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails in project hub-alert by blackducksoftware.

the class IssueTrackerSearcher method isOnlyDeleteOperation.

private boolean isOnlyDeleteOperation(ProjectIssueModel projectIssueModel) {
    boolean isPolicyDelete = projectIssueModel.getPolicyDetails().map(IssuePolicyDetails::getOperation).filter(ItemOperation.DELETE::equals).isPresent();
    boolean isEstimatedRiskDelete = projectIssueModel.getComponentUnknownVersionDetails().map(IssueComponentUnknownVersionDetails::getItemOperation).filter(ItemOperation.DELETE::equals).isPresent();
    boolean isVulnerabilityDelete = false;
    Optional<IssueVulnerabilityDetails> optionalVulnDetails = projectIssueModel.getVulnerabilityDetails();
    if (optionalVulnDetails.isPresent()) {
        IssueVulnerabilityDetails vulnDetails = optionalVulnDetails.get();
        boolean allVulnsRemediated = vulnDetails.areAllComponentVulnerabilitiesRemediated();
        boolean hasDeletions = !vulnDetails.getVulnerabilitiesDeleted().isEmpty();
        boolean doesNotHaveAdditions = vulnDetails.getVulnerabilitiesAdded().isEmpty();
        boolean doesNotHaveUpdates = vulnDetails.getVulnerabilitiesUpdated().isEmpty();
        isVulnerabilityDelete = allVulnsRemediated || (hasDeletions && doesNotHaveAdditions && doesNotHaveUpdates);
    }
    return isPolicyDelete || isVulnerabilityDelete || isEstimatedRiskDelete;
}
Also used : IssueComponentUnknownVersionDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueComponentUnknownVersionDetails) IssueVulnerabilityDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) ItemOperation(com.synopsys.integration.alert.common.enumeration.ItemOperation)

Example 10 with IssuePolicyDetails

use of com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails in project hub-alert by blackducksoftware.

the class AzureBoardsAlertIssuePropertiesManager method createWorkItemRequestCustomFieldOperations.

public List<WorkItemElementOperationModel> createWorkItemRequestCustomFieldOperations(ProjectIssueModel alertIssueSource) {
    LinkableItem provider = alertIssueSource.getProvider();
    String providerKey = AzureBoardsSearchPropertiesUtils.createProviderKey(provider.getLabel(), provider.getUrl().orElse(null));
    String topicKey = AzureBoardsSearchPropertiesUtils.createNullableLinkableItemKey(alertIssueSource.getProject());
    String subTopicKey = AzureBoardsSearchPropertiesUtils.createNullableLinkableItemKey(alertIssueSource.getProjectVersion().orElse(null));
    IssueBomComponentDetails bomComponentDetails = alertIssueSource.getBomComponentDetails();
    String componentKey = AzureBoardsSearchPropertiesUtils.createNullableLinkableItemKey(bomComponentDetails.getComponent());
    String subComponentKey = AzureBoardsSearchPropertiesUtils.createNullableLinkableItemKey(bomComponentDetails.getComponentVersion().orElse(null));
    AzureSearchFieldBuilder azureSearchFieldBuilder = AzureSearchFieldBuilder.create().addProviderKey(providerKey).addTopicKey(topicKey).addSubTopicKey(subTopicKey).addComponentKey(componentKey).addSubComponentKey(subComponentKey);
    String categoryKey = CATEGORY_TYPE_VULNERABILITY_COMPATIBILITY_LABEL;
    Optional<String> optionalPolicyName = alertIssueSource.getPolicyDetails().map(IssuePolicyDetails::getName);
    if (optionalPolicyName.isPresent()) {
        String additionalInfoKey = POLICY_ADDITIONAL_KEY_COMPATIBILITY_LABEL + optionalPolicyName.get();
        azureSearchFieldBuilder.addAdditionalInfoKey(additionalInfoKey);
        categoryKey = CATEGORY_TYPE_POLICY_COMPATIBILITY_LABEL;
    }
    boolean unknownVersionCategory = alertIssueSource.getComponentUnknownVersionDetails().isPresent();
    if (unknownVersionCategory) {
        categoryKey = CATEGORY_TYPE_COMPONENT_UNKNOWN_VERSION_COMPATIBILITY_LABEL;
    }
    azureSearchFieldBuilder.addCategoryKey(categoryKey);
    return azureSearchFieldBuilder.build();
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails)

Aggregations

IssuePolicyDetails (com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails)20 ProjectIssueModel (com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel)14 Test (org.junit.jupiter.api.Test)11 IssueBomComponentDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails)10 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)8 ExistingIssueDetails (com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails)7 IssueVulnerabilityDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails)5 ProjectMessage (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage)5 IssueComponentUnknownVersionDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueComponentUnknownVersionDetails)4 IssueCategoryRetriever (com.synopsys.integration.alert.api.channel.issue.search.IssueCategoryRetriever)4 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)4 Gson (com.google.gson.Gson)3 MockIssueTrackerMessageFormatter (com.synopsys.integration.alert.api.channel.issue.convert.mock.MockIssueTrackerMessageFormatter)3 IssueCreationModel (com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel)3 ActionableIssueSearchResult (com.synopsys.integration.alert.api.channel.issue.search.ActionableIssueSearchResult)3 IssueCategory (com.synopsys.integration.alert.api.channel.issue.search.enumeration.IssueCategory)3 AlertRuntimeException (com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)3 ItemOperation (com.synopsys.integration.alert.common.enumeration.ItemOperation)3 ProviderDetails (com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails)3 BomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)3