use of com.synopsys.integration.alert.processor.api.extract.model.project.MessageReason in project hub-alert by blackducksoftware.
the class IssueTrackerSearcher method findIssues.
public final List<ActionableIssueSearchResult<T>> findIssues(ProjectMessage projectMessage) throws AlertException {
ProviderDetails providerDetails = projectMessage.getProviderDetails();
LinkableItem project = projectMessage.getProject();
MessageReason messageReason = projectMessage.getMessageReason();
boolean isEntireBomDeleted = projectMessage.getOperation().filter(ProjectOperation.DELETE::equals).isPresent();
if (MessageReason.PROJECT_STATUS.equals(messageReason)) {
return findProjectIssues(isEntireBomDeleted, () -> projectIssueFinder.findProjectIssues(providerDetails, project));
}
LinkableItem projectVersion = projectMessage.getProjectVersion().orElseThrow(() -> new AlertRuntimeException("Missing project version"));
if (MessageReason.PROJECT_VERSION_STATUS.equals(messageReason)) {
return findProjectIssues(isEntireBomDeleted, () -> projectVersionIssueFinder.findProjectVersionIssues(providerDetails, project, projectVersion));
}
if (MessageReason.COMPONENT_UPDATE.equals(messageReason)) {
return findIssuesByAllComponents(providerDetails, project, projectVersion, projectMessage.getBomComponents());
}
List<ProjectIssueModel> projectIssueModels = modelTransformer.convertToIssueModels(projectMessage);
List<ActionableIssueSearchResult<T>> projectIssueSearchResults = new LinkedList<>();
for (ProjectIssueModel projectIssueModel : projectIssueModels) {
ActionableIssueSearchResult<T> searchResult = findIssueByProjectIssueModel(projectIssueModel);
if (searchResult.getExistingIssueDetails().isEmpty() && isOnlyDeleteOperation(projectIssueModel)) {
logger.debug("Ignoring component-level notification for issue-tracker because no matching issue(s) existed and it only contained DELETE operations");
} else {
projectIssueSearchResults.add(searchResult);
}
}
return projectIssueSearchResults;
}
use of com.synopsys.integration.alert.processor.api.extract.model.project.MessageReason 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.processor.api.extract.model.project.MessageReason in project hub-alert by blackducksoftware.
the class ProjectMessageSummarizer method constructSummaryAndDescription.
private Pair<String, String> constructSummaryAndDescription(ProjectMessage projectMessage) {
String providerName = projectMessage.getProvider().getValue();
String projectName = projectMessage.getProject().getValue();
MessageReason messageReason = projectMessage.getMessageReason();
switch(messageReason) {
case PROJECT_STATUS:
case PROJECT_VERSION_STATUS:
return constructProjectVersionStatusSummaryAndDescription(providerName, projectName, projectMessage);
case COMPONENT_UPDATE:
case COMPONENT_CONCERN:
return constructComponentStatusAndDescription(providerName, projectName, messageReason, projectMessage);
default:
return Pair.of(String.format("%s had notifications in BlackDuck", projectMessage.getProject().getValue()), "Alert received an unrecognized notification from BlackDuck.");
}
}
Aggregations