Search in sources :

Example 1 with MessageReason

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;
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ProviderDetails(com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails) MessageReason(com.synopsys.integration.alert.processor.api.extract.model.project.MessageReason) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) LinkedList(java.util.LinkedList) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) ProjectOperation(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectOperation)

Example 2 with MessageReason

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();
}
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 3 with MessageReason

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.");
    }
}
Also used : MessageReason(com.synopsys.integration.alert.processor.api.extract.model.project.MessageReason)

Aggregations

MessageReason (com.synopsys.integration.alert.processor.api.extract.model.project.MessageReason)3 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)2 LinkedList (java.util.LinkedList)2 ProjectIssueModel (com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel)1 AlertRuntimeException (com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)1 ChunkedStringBuilder (com.synopsys.integration.alert.common.channel.message.ChunkedStringBuilder)1 ProviderDetails (com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails)1 BomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)1 ProjectMessage (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage)1 ProjectOperation (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectOperation)1 List (java.util.List)1 Optional (java.util.Optional)1