Search in sources :

Example 1 with ChunkedStringBuilder

use of com.synopsys.integration.alert.common.channel.message.ChunkedStringBuilder in project hub-alert by blackducksoftware.

the class ProjectMessageConverter method convertToFormattedMessageChunks.

@Override
public List<String> convertToFormattedMessageChunks(ProjectMessage projectMessage, String jobName) {
    ChunkedStringBuilder chunkedStringBuilder = new ChunkedStringBuilder(messageFormatter.getMaxMessageLength());
    String projectString;
    Optional<String> optionalProjectVersionString;
    Optional<LinkableItem> optionalProjectVersion = projectMessage.getProjectVersion();
    if (optionalProjectVersion.isPresent()) {
        projectString = linkableItemConverter.convertToStringWithoutLink(projectMessage.getProject(), true);
        optionalProjectVersionString = optionalProjectVersion.map(projectVersion -> linkableItemConverter.convertToString(projectVersion, true));
    } else {
        projectString = linkableItemConverter.convertToString(projectMessage.getProject(), true);
        optionalProjectVersionString = Optional.empty();
    }
    String nonBreakingSpace = messageFormatter.getNonBreakingSpace();
    String jobLine = String.format("Job%sname:%s%s", nonBreakingSpace, nonBreakingSpace, jobName);
    String boldJobName = messageFormatter.emphasize(jobLine);
    chunkedStringBuilder.append(boldJobName);
    chunkedStringBuilder.append(messageFormatter.getLineSeparator());
    chunkedStringBuilder.append(projectString);
    chunkedStringBuilder.append(messageFormatter.getLineSeparator());
    optionalProjectVersionString.ifPresent(projectVersionString -> {
        chunkedStringBuilder.append(projectVersionString);
        chunkedStringBuilder.append(messageFormatter.getLineSeparator());
    });
    MessageReason messageReason = projectMessage.getMessageReason();
    if (MessageReason.PROJECT_STATUS.equals(messageReason) || MessageReason.PROJECT_VERSION_STATUS.equals(messageReason)) {
        projectMessage.getOperation().map(operation -> String.format("Project%sAction:%s%s", nonBreakingSpace, nonBreakingSpace, operation.name())).map(messageFormatter::encode).ifPresent(chunkedStringBuilder::append);
        return chunkedStringBuilder.collectCurrentChunks();
    }
    List<BomComponentDetails> bomComponents = projectMessage.getBomComponents();
    if (!bomComponents.isEmpty()) {
        chunkedStringBuilder.append(messageFormatter.getSectionSeparator());
        chunkedStringBuilder.append(messageFormatter.getLineSeparator());
    }
    for (BomComponentDetails bomComponentDetails : bomComponents) {
        List<String> bomComponentMessagePieces = gatherBomComponentAndConcernSectionPieces(bomComponentDetails);
        bomComponentMessagePieces.forEach(chunkedStringBuilder::append);
        chunkedStringBuilder.append(messageFormatter.getSectionSeparator());
        chunkedStringBuilder.append(messageFormatter.getLineSeparator());
    }
    return chunkedStringBuilder.collectCurrentChunks();
}
Also used : List(java.util.List) ChunkedStringBuilder(com.synopsys.integration.alert.common.channel.message.ChunkedStringBuilder) MessageReason(com.synopsys.integration.alert.processor.api.extract.model.project.MessageReason) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) Optional(java.util.Optional) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) LinkedList(java.util.LinkedList) BomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ChunkedStringBuilder(com.synopsys.integration.alert.common.channel.message.ChunkedStringBuilder) MessageReason(com.synopsys.integration.alert.processor.api.extract.model.project.MessageReason) BomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)

Example 2 with ChunkedStringBuilder

use of com.synopsys.integration.alert.common.channel.message.ChunkedStringBuilder in project hub-alert by blackducksoftware.

the class ProjectIssueModelConverter method toIssueTransitionModel.

public <T extends Serializable> IssueTransitionModel<T> toIssueTransitionModel(ExistingIssueDetails<T> existingIssueDetails, ProjectIssueModel projectIssueModel, ItemOperation requiredOperation) {
    IssueOperation issueOperation;
    if (ItemOperation.ADD.equals(requiredOperation)) {
        issueOperation = IssueOperation.OPEN;
    } else {
        issueOperation = IssueOperation.RESOLVE;
    }
    IssueCommentModel<T> commentModel = toIssueCommentModel(existingIssueDetails, projectIssueModel);
    List<String> transitionComments = new LinkedList<>(commentModel.getComments());
    LinkableItem provider = projectIssueModel.getProvider();
    ChunkedStringBuilder commentBuilder = new ChunkedStringBuilder(formatter.getMaxCommentLength());
    commentBuilder.append(String.format("The %s operation was performed on this component in %s.", requiredOperation.name(), provider.getLabel()));
    transitionComments.addAll(commentBuilder.collectCurrentChunks());
    return new IssueTransitionModel<>(existingIssueDetails, issueOperation, transitionComments, projectIssueModel);
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) IssueTransitionModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTransitionModel) ChunkedStringBuilder(com.synopsys.integration.alert.common.channel.message.ChunkedStringBuilder) IssueOperation(com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation) LinkedList(java.util.LinkedList)

Example 3 with ChunkedStringBuilder

use of com.synopsys.integration.alert.common.channel.message.ChunkedStringBuilder 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 4 with ChunkedStringBuilder

use of com.synopsys.integration.alert.common.channel.message.ChunkedStringBuilder 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 5 with ChunkedStringBuilder

use of com.synopsys.integration.alert.common.channel.message.ChunkedStringBuilder in project hub-alert by blackducksoftware.

the class SimpleMessageConverter method convertToFormattedMessageChunks.

@Override
public List<String> convertToFormattedMessageChunks(SimpleMessage simpleMessage, String jobName) {
    ChunkedStringBuilder chunkedStringBuilder = new ChunkedStringBuilder(messageFormatter.getMaxMessageLength());
    String nonBreakingSpace = messageFormatter.getNonBreakingSpace();
    String jobLine = String.format("Job%sname:%s%s", nonBreakingSpace, nonBreakingSpace, jobName);
    String formattedJob = messageFormatter.emphasize(jobLine);
    appendSection(chunkedStringBuilder, formattedJob);
    appendSection(chunkedStringBuilder, simpleMessage.getSummary());
    appendSection(chunkedStringBuilder, simpleMessage.getDescription());
    appendLinkableItem(chunkedStringBuilder, simpleMessage.getProvider(), false);
    for (LinkableItem detail : simpleMessage.getDetails()) {
        appendLinkableItem(chunkedStringBuilder, detail, false);
    }
    return chunkedStringBuilder.collectCurrentChunks();
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ChunkedStringBuilder(com.synopsys.integration.alert.common.channel.message.ChunkedStringBuilder)

Aggregations

ChunkedStringBuilder (com.synopsys.integration.alert.common.channel.message.ChunkedStringBuilder)5 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)5 LinkedList (java.util.LinkedList)3 IssueBomComponentDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails)2 IssueCommentModel (com.synopsys.integration.alert.api.channel.issue.model.IssueCommentModel)2 IssueTransitionModel (com.synopsys.integration.alert.api.channel.issue.model.IssueTransitionModel)2 IssueOperation (com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation)2 List (java.util.List)2 Optional (java.util.Optional)2 BomComponentDetailConverter (com.synopsys.integration.alert.api.channel.convert.BomComponentDetailConverter)1 LinkableItemConverter (com.synopsys.integration.alert.api.channel.convert.LinkableItemConverter)1 IssueComponentUnknownVersionDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueComponentUnknownVersionDetails)1 IssueCreationModel (com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel)1 IssuePolicyDetails (com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails)1 IssueVulnerabilityDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails)1 ProjectIssueModel (com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel)1 ExistingIssueDetails (com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails)1 ChunkedStringBuilderRechunker (com.synopsys.integration.alert.common.channel.message.ChunkedStringBuilderRechunker)1 RechunkedModel (com.synopsys.integration.alert.common.channel.message.RechunkedModel)1 ItemOperation (com.synopsys.integration.alert.common.enumeration.ItemOperation)1