Search in sources :

Example 61 with LinkableItem

use of com.synopsys.integration.alert.common.message.model.LinkableItem 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 62 with LinkableItem

use of com.synopsys.integration.alert.common.message.model.LinkableItem 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 63 with LinkableItem

use of com.synopsys.integration.alert.common.message.model.LinkableItem in project hub-alert by blackducksoftware.

the class ProjectIssueModelConverter method toIssueCreationModel.

public IssueCreationModel toIssueCreationModel(ProjectIssueModel projectIssueModel, String jobName) {
    String title = createTruncatedTitle(projectIssueModel);
    ChunkedStringBuilder descriptionBuilder = new ChunkedStringBuilder(formatter.getMaxDescriptionLength());
    String nonBreakingSpace = formatter.getNonBreakingSpace();
    String jobLine = String.format("Job%sname:%s%s", nonBreakingSpace, nonBreakingSpace, jobName);
    String formattedJobName = formatter.emphasize(jobLine);
    descriptionBuilder.append(formattedJobName);
    descriptionBuilder.append(formatter.getLineSeparator());
    String projectString = linkableItemConverter.convertToString(projectIssueModel.getProject(), true);
    descriptionBuilder.append(projectString);
    descriptionBuilder.append(formatter.getLineSeparator());
    LinkableItem projectVersion = projectIssueModel.getProjectVersion().orElse(MISSING_PROJECT_VERSION_PLACEHOLDER);
    String projectVersionString = linkableItemConverter.convertToString(projectVersion, true);
    descriptionBuilder.append(projectVersionString);
    descriptionBuilder.append(formatter.getLineSeparator());
    descriptionBuilder.append(formatter.getSectionSeparator());
    descriptionBuilder.append(formatter.getLineSeparator());
    IssueBomComponentDetails bomComponent = projectIssueModel.getBomComponentDetails();
    List<String> bomComponentPieces = bomComponentDetailConverter.gatherAbstractBomComponentSectionPieces(bomComponent);
    bomComponentPieces.forEach(descriptionBuilder::append);
    createVulnerabilitySeverityStatusSectionPieces(projectIssueModel).forEach(descriptionBuilder::append);
    descriptionBuilder.append(formatter.getLineSeparator());
    createProjectIssueModelConcernSectionPieces(projectIssueModel, false).forEach(descriptionBuilder::append);
    int newChunkSize = formatter.getMaxCommentLength() - DESCRIPTION_CONTINUED_TEXT.length() - formatter.getLineSeparator().length();
    RechunkedModel rechunkedDescription = ChunkedStringBuilderRechunker.rechunk(descriptionBuilder, "No description", newChunkSize);
    List<String> postCreateComments = rechunkedDescription.getRemainingChunks().stream().map(comment -> String.format("%s%s%s", DESCRIPTION_CONTINUED_TEXT, formatter.getLineSeparator(), comment)).collect(Collectors.toList());
    return IssueCreationModel.project(title, rechunkedDescription.getFirstChunk(), postCreateComments, projectIssueModel);
}
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) 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) RechunkedModel(com.synopsys.integration.alert.common.channel.message.RechunkedModel)

Example 64 with LinkableItem

use of com.synopsys.integration.alert.common.message.model.LinkableItem in project hub-alert by blackducksoftware.

the class IssueTrackerTestAction method createPlaceholderProjectIssueModel.

private ProjectIssueModel createPlaceholderProjectIssueModel(Long blackDuckConfigId) {
    LinkableItem providerItem = new LinkableItem("Provider Test Label", "Provider Config Test Name");
    ProviderDetails providerDetails = new ProviderDetails(blackDuckConfigId, providerItem);
    LinkableItem projectItem = new LinkableItem("Project Test Label", "Project Test Name");
    LinkableItem projectVersionItem = new LinkableItem("Project-Version Test Label", "Project-Version Test Name");
    LinkableItem componentItem = new LinkableItem("Component Test Label", "Component Test Value");
    IssueBomComponentDetails bomComponentDetails = IssueBomComponentDetails.fromSearchResults(componentItem, null);
    return ProjectIssueModel.bom(providerDetails, projectItem, projectVersionItem, bomComponentDetails);
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) ProviderDetails(com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails)

Example 65 with LinkableItem

use of com.synopsys.integration.alert.common.message.model.LinkableItem in project hub-alert by blackducksoftware.

the class BomComponentDetailConverterTest method createComponentVulnerabilities.

private static ComponentVulnerabilities createComponentVulnerabilities() {
    LinkableItem vulnerability1 = creatVulnerabilityLinkableItem("CVE-001");
    LinkableItem vulnerability2 = creatVulnerabilityLinkableItem("CVE-002");
    LinkableItem vulnerability3 = creatVulnerabilityLinkableItem("CVE-003");
    LinkableItem vulnerability4 = creatVulnerabilityLinkableItem("CVE-004");
    LinkableItem vulnerability5 = creatVulnerabilityLinkableItem("CVE-005");
    LinkableItem vulnerability6 = creatVulnerabilityLinkableItem("CVE-006");
    return new ComponentVulnerabilities(List.of(), List.of(vulnerability1), List.of(vulnerability2, vulnerability3), List.of(vulnerability4, vulnerability5, vulnerability6));
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ComponentVulnerabilities(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentVulnerabilities)

Aggregations

LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)94 Test (org.junit.jupiter.api.Test)39 ProviderDetails (com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails)26 ProjectMessage (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage)22 IssueBomComponentDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails)18 ProjectIssueModel (com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel)15 BomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)13 SimpleMessage (com.synopsys.integration.alert.processor.api.extract.model.SimpleMessage)11 ProjectOperation (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectOperation)11 ArrayList (java.util.ArrayList)11 LinkedList (java.util.LinkedList)11 IssuePolicyDetails (com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails)9 ProviderMessageHolder (com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder)9 List (java.util.List)9 ComponentVulnerabilities (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentVulnerabilities)8 Optional (java.util.Optional)7 IssueVulnerabilityDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails)6 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)6 ComponentConcern (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern)6 ComponentConcernType (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernType)6