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();
}
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);
}
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);
}
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);
}
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();
}
Aggregations