Search in sources :

Example 16 with IssueBomComponentDetails

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

the class AzureBoardsAlertIssuePropertiesManagerTest method verifyValidPolicyIssuesAreCreated.

@Test
public void verifyValidPolicyIssuesAreCreated() {
    AzureBoardsAlertIssuePropertiesManager azureBoardsAlertIssuePropertiesManager = new AzureBoardsAlertIssuePropertiesManager();
    LinkableItem providerConfig = new LinkableItem("providerConfigLabel", "providerConfigValue");
    ProviderDetails providerDetails = new ProviderDetails(1L, providerConfig);
    LinkableItem project = new LinkableItem("projectLabel", "projectValue");
    LinkableItem projectVersion = new LinkableItem("projectVersionLabel", "projectVersionValue");
    LinkableItem component = new LinkableItem("componentLabel", "componentValue");
    LinkableItem componentVersion = new LinkableItem("componentVersionLabel", "componentVersionValue");
    IssueBomComponentDetails issueBomComponentDetails = IssueBomComponentDetails.fromSearchResults(component, componentVersion);
    IssuePolicyDetails issuePolicyDetails = new IssuePolicyDetails("policy", ItemOperation.ADD, ComponentConcernSeverity.CRITICAL);
    ProjectIssueModel policy = ProjectIssueModel.policy(providerDetails, project, projectVersion, issueBomComponentDetails, issuePolicyDetails);
    List<WorkItemElementOperationModel> workItemRequestCustomFieldOperations = azureBoardsAlertIssuePropertiesManager.createWorkItemRequestCustomFieldOperations(policy);
    LinkableItem provider = providerDetails.getProvider();
    String providerKey = AzureBoardsSearchPropertiesUtils.createProviderKey(provider.getLabel(), provider.getUrl().orElse(null));
    assertValidContents(workItemRequestCustomFieldOperations, AzureCustomFieldManager.ALERT_PROVIDER_KEY_FIELD_REFERENCE_NAME, providerKey);
    String additionalInfo = AzureBoardsAlertIssuePropertiesManager.POLICY_ADDITIONAL_KEY_COMPATIBILITY_LABEL + issuePolicyDetails.getName();
    assertValidContents(workItemRequestCustomFieldOperations, AzureCustomFieldManager.ALERT_ADDITIONAL_INFO_KEY_FIELD_REFERENCE_NAME, additionalInfo);
    assertValidContents(workItemRequestCustomFieldOperations, AzureCustomFieldManager.ALERT_CATEGORY_KEY_FIELD_REFERENCE_NAME, AzureBoardsAlertIssuePropertiesManager.CATEGORY_TYPE_POLICY_COMPATIBILITY_LABEL);
    String subTopicKey = AzureBoardsSearchPropertiesUtils.createNullableLinkableItemKey(policy.getProjectVersion().orElse(null));
    assertValidContents(workItemRequestCustomFieldOperations, AzureCustomFieldManager.ALERT_SUB_TOPIC_KEY_FIELD_REFERENCE_NAME, subTopicKey);
}
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) ProviderDetails(com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) WorkItemElementOperationModel(com.synopsys.integration.azure.boards.common.service.workitem.request.WorkItemElementOperationModel) Test(org.junit.jupiter.api.Test)

Example 17 with IssueBomComponentDetails

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

the class ProjectIssueModelConverter method createProjectIssueModelConcernSectionPieces.

private List<String> createProjectIssueModelConcernSectionPieces(ProjectIssueModel projectIssueModel, boolean commentFormat) {
    List<String> concernSectionPieces = new LinkedList<>();
    IssueBomComponentDetails bomComponentDetails = projectIssueModel.getBomComponentDetails();
    Optional<IssuePolicyDetails> optionalPolicyDetails = projectIssueModel.getPolicyDetails();
    if (optionalPolicyDetails.isPresent()) {
        List<String> policyDetailsSectionPieces = issuePolicyDetailsConverter.createPolicyDetailsSectionPieces(bomComponentDetails, optionalPolicyDetails.get());
        concernSectionPieces.addAll(policyDetailsSectionPieces);
        concernSectionPieces.add(formatter.getLineSeparator());
        concernSectionPieces.add(formatter.getSectionSeparator());
        concernSectionPieces.add(formatter.getLineSeparator());
    }
    Optional<IssueVulnerabilityDetails> optionalVulnDetails = projectIssueModel.getVulnerabilityDetails();
    if (optionalVulnDetails.isPresent()) {
        List<String> vulnDetailsSectionPieces;
        if (commentFormat) {
            vulnDetailsSectionPieces = issueVulnerabilityDetailsConverter.createVulnerabilityDetailsSectionPieces(optionalVulnDetails.get());
        } else {
            vulnDetailsSectionPieces = componentVulnerabilitiesConverter.createComponentVulnerabilitiesSectionPieces(projectIssueModel.getBomComponentDetails().getComponentVulnerabilities());
        }
        concernSectionPieces.addAll(vulnDetailsSectionPieces);
        concernSectionPieces.add(formatter.getLineSeparator());
        concernSectionPieces.add(formatter.getSectionSeparator());
        concernSectionPieces.add(formatter.getLineSeparator());
    }
    Optional<IssueComponentUnknownVersionDetails> optionalUnknownVersionDetails = projectIssueModel.getComponentUnknownVersionDetails();
    if (optionalUnknownVersionDetails.isPresent()) {
        List<String> componentUnknownVersionDetailsSectionPieces;
        componentUnknownVersionDetailsSectionPieces = issueComponentUnknownVersionDetailsConverter.createEstimatedRiskDetailsSectionPieces(optionalUnknownVersionDetails.get());
        concernSectionPieces.addAll(componentUnknownVersionDetailsSectionPieces);
        concernSectionPieces.add(formatter.getLineSeparator());
        concernSectionPieces.add(formatter.getSectionSeparator());
        concernSectionPieces.add(formatter.getLineSeparator());
    }
    return concernSectionPieces;
}
Also used : IssueComponentUnknownVersionDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueComponentUnknownVersionDetails) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) IssueVulnerabilityDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) LinkedList(java.util.LinkedList)

Example 18 with IssueBomComponentDetails

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

the class ProjectIssueModelConverter method toIssueCommentModel.

public <T extends Serializable> IssueCommentModel<T> toIssueCommentModel(ExistingIssueDetails<T> existingIssueDetails, ProjectIssueModel projectIssueModel) {
    ChunkedStringBuilder commentBuilder = new ChunkedStringBuilder(formatter.getMaxCommentLength());
    LinkableItem provider = projectIssueModel.getProvider();
    String commentHeader = String.format("The component was updated in %s[%s]", provider.getLabel(), provider.getValue());
    commentBuilder.append(formatter.encode(commentHeader));
    commentBuilder.append(formatter.getLineSeparator());
    commentBuilder.append(formatter.getSectionSeparator());
    commentBuilder.append(formatter.getLineSeparator());
    createVulnerabilitySeverityStatusSectionPieces(projectIssueModel).forEach(commentBuilder::append);
    createProjectIssueModelConcernSectionPieces(projectIssueModel, true).forEach(commentBuilder::append);
    IssueBomComponentDetails bomComponent = projectIssueModel.getBomComponentDetails();
    List<String> attributeStrings = bomComponentDetailConverter.gatherAttributeStrings(bomComponent);
    for (String attributeString : attributeStrings) {
        commentBuilder.append(formatter.getNonBreakingSpace());
        commentBuilder.append(formatter.encode("-"));
        commentBuilder.append(formatter.getNonBreakingSpace());
        commentBuilder.append(attributeString);
        commentBuilder.append(formatter.getLineSeparator());
    }
    List<String> chunkedComments = commentBuilder.collectCurrentChunks();
    return new IssueCommentModel<>(existingIssueDetails, chunkedComments, projectIssueModel);
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) ChunkedStringBuilder(com.synopsys.integration.alert.common.channel.message.ChunkedStringBuilder) IssueCommentModel(com.synopsys.integration.alert.api.channel.issue.model.IssueCommentModel)

Example 19 with IssueBomComponentDetails

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

the class ProjectIssueModelConverter method createTruncatedTitle.

private String createTruncatedTitle(ProjectIssueModel projectIssueModel) {
    LinkableItem provider = projectIssueModel.getProvider();
    LinkableItem project = projectIssueModel.getProject();
    LinkableItem projectVersion = projectIssueModel.getProjectVersion().orElse(MISSING_PROJECT_VERSION_PLACEHOLDER);
    IssueBomComponentDetails bomComponent = projectIssueModel.getBomComponentDetails();
    LinkableItem component = bomComponent.getComponent();
    Optional<String> optionalComponentVersionValue = bomComponent.getComponentVersion().map(LinkableItem::getValue);
    boolean isComponentVersionUnknown = projectIssueModel.getComponentUnknownVersionDetails().isPresent();
    StringBuilder componentPieceBuilder = new StringBuilder();
    componentPieceBuilder.append(component.getValue());
    if (optionalComponentVersionValue.isPresent() && !isComponentVersionUnknown) {
        componentPieceBuilder.append('[');
        componentPieceBuilder.append(optionalComponentVersionValue.get());
        componentPieceBuilder.append(']');
    }
    StringBuilder componentConcernPieceBuilder = new StringBuilder();
    Optional<String> optionalPolicyName = projectIssueModel.getPolicyDetails().map(IssuePolicyDetails::getName);
    if (optionalPolicyName.isPresent()) {
        componentConcernPieceBuilder.append(COMMA_SPACE);
        componentConcernPieceBuilder.append(ComponentConcernType.POLICY.getDisplayName());
        componentConcernPieceBuilder.append('[');
        componentConcernPieceBuilder.append(optionalPolicyName.get());
        componentConcernPieceBuilder.append(']');
    } else if (isComponentVersionUnknown) {
        componentConcernPieceBuilder.append(COMMA_SPACE);
        componentConcernPieceBuilder.append(ComponentConcernType.UNKNOWN_VERSION.getDisplayName());
    } else {
        componentConcernPieceBuilder.append(COMMA_SPACE);
        componentConcernPieceBuilder.append(ComponentConcernType.VULNERABILITY.getDisplayName());
    }
    String componentConcernPiece = componentConcernPieceBuilder.toString();
    String preConcernTitle = String.format("Alert - %s[%s], %s[%s], %s", provider.getLabel(), provider.getValue(), project.getValue(), projectVersion.getValue(), componentPieceBuilder);
    if (preConcernTitle.length() + componentConcernPieceBuilder.length() > formatter.getMaxTitleLength()) {
        if (formatter.getMaxTitleLength() > COMPONENT_CONCERN_TITLE_SECTION_CHAR_COUNT) {
            preConcernTitle = StringUtils.truncate(preConcernTitle, formatter.getMaxTitleLength() - COMPONENT_CONCERN_TITLE_SECTION_CHAR_COUNT);
            componentConcernPiece = StringUtils.truncate(componentConcernPieceBuilder.toString(), COMPONENT_CONCERN_TITLE_SECTION_CHAR_COUNT);
        } else {
            // If max title length is less than 3, then there are bigger concerns than an IllegalArgumentException
            preConcernTitle = StringUtils.truncate(preConcernTitle, formatter.getMaxTitleLength() - 3);
            componentConcernPiece = "...";
        }
    }
    return preConcernTitle + componentConcernPiece;
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) ChunkedStringBuilder(com.synopsys.integration.alert.common.channel.message.ChunkedStringBuilder) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails)

Example 20 with IssueBomComponentDetails

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

the class ProjectIssueModelConverter method createVulnerabilitySeverityStatusSectionPieces.

private List<String> createVulnerabilitySeverityStatusSectionPieces(ProjectIssueModel projectIssueModel) {
    List<String> severityStatusSectionPieces = new LinkedList<>();
    String encodedSeverityStatus = formatter.encode(LABEL_SEVERITY_STATUS);
    IssueBomComponentDetails bomComponentDetails = projectIssueModel.getBomComponentDetails();
    Optional<IssueVulnerabilityDetails> vulnerabilityDetails = projectIssueModel.getVulnerabilityDetails();
    if (vulnerabilityDetails.isPresent()) {
        ComponentVulnerabilities componentVulnerabilities = bomComponentDetails.getComponentVulnerabilities();
        componentVulnerabilities.computeHighestSeverity().map(ComponentConcernSeverity::getVulnerabilityLabel).map(formatter::encode).map(severity -> encodedSeverityStatus + severity).ifPresentOrElse(severityStatusSectionPieces::add, () -> severityStatusSectionPieces.add(encodedSeverityStatus + "None"));
        severityStatusSectionPieces.add(formatter.getLineSeparator());
        severityStatusSectionPieces.add(formatter.getSectionSeparator());
        severityStatusSectionPieces.add(formatter.getLineSeparator());
    }
    return severityStatusSectionPieces;
}
Also used : ComponentConcernType(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernType) ComponentConcernSeverity(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernSeverity) ExistingIssueDetails(com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails) ComponentVulnerabilities(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentVulnerabilities) StringUtils(org.apache.commons.lang3.StringUtils) IssueComponentUnknownVersionDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueComponentUnknownVersionDetails) IssueTransitionModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTransitionModel) ChunkedStringBuilderRechunker(com.synopsys.integration.alert.common.channel.message.ChunkedStringBuilderRechunker) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) BomComponentDetailConverter(com.synopsys.integration.alert.api.channel.convert.BomComponentDetailConverter) IssueVulnerabilityDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails) RechunkedModel(com.synopsys.integration.alert.common.channel.message.RechunkedModel) ItemOperation(com.synopsys.integration.alert.common.enumeration.ItemOperation) LinkedList(java.util.LinkedList) IssueCommentModel(com.synopsys.integration.alert.api.channel.issue.model.IssueCommentModel) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) IssueOperation(com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation) IssueCreationModel(com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) List(java.util.List) ChunkedStringBuilder(com.synopsys.integration.alert.common.channel.message.ChunkedStringBuilder) Optional(java.util.Optional) LinkableItemConverter(com.synopsys.integration.alert.api.channel.convert.LinkableItemConverter) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) IssueVulnerabilityDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails) LinkedList(java.util.LinkedList) ComponentVulnerabilities(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentVulnerabilities)

Aggregations

IssueBomComponentDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails)24 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)17 ProjectIssueModel (com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel)15 IssuePolicyDetails (com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails)11 IssueVulnerabilityDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails)9 ComponentConcernType (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernType)6 ComponentVulnerabilities (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentVulnerabilities)6 Test (org.junit.jupiter.api.Test)6 ProviderDetails (com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails)5 LinkedList (java.util.LinkedList)5 IssueComponentUnknownVersionDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueComponentUnknownVersionDetails)4 IssueCreationModel (com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel)4 IssueVulnerabilityModel (com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityModel)4 ExistingIssueDetails (com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails)4 ChunkedStringBuilder (com.synopsys.integration.alert.common.channel.message.ChunkedStringBuilder)4 Optional (java.util.Optional)4 MockIssueTrackerMessageFormatter (com.synopsys.integration.alert.api.channel.issue.convert.mock.MockIssueTrackerMessageFormatter)3 IssueCommentModel (com.synopsys.integration.alert.api.channel.issue.model.IssueCommentModel)3 JiraIssueSearchProperties (com.synopsys.integration.alert.api.channel.jira.JiraIssueSearchProperties)3 ItemOperation (com.synopsys.integration.alert.common.enumeration.ItemOperation)3