Search in sources :

Example 31 with ProjectIssueModel

use of com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel in project hub-alert by blackducksoftware.

the class ProjectIssueModelConverter method createVulnerabilitySeverityStatusSectionPieces.

private List<String> createVulnerabilitySeverityStatusSectionPieces(ProjectIssueModel projectIssueModel) {
    List<String> severityStatusSectionPieces = new LinkedList<>();
    String encodedSeverityStatus = formatter.encode(LABEL_SEVERITY_STATUS);
    IssueBomComponentDetails bomComponentDetails = projectIssueModel.getBomComponentDetails();
    Optional<IssueVulnerabilityDetails> vulnerabilityDetails = projectIssueModel.getVulnerabilityDetails();
    if (vulnerabilityDetails.isPresent()) {
        ComponentVulnerabilities componentVulnerabilities = bomComponentDetails.getComponentVulnerabilities();
        componentVulnerabilities.computeHighestSeverity().map(ComponentConcernSeverity::getVulnerabilityLabel).map(formatter::encode).map(severity -> encodedSeverityStatus + severity).ifPresentOrElse(severityStatusSectionPieces::add, () -> severityStatusSectionPieces.add(encodedSeverityStatus + "None"));
        severityStatusSectionPieces.add(formatter.getLineSeparator());
        severityStatusSectionPieces.add(formatter.getSectionSeparator());
        severityStatusSectionPieces.add(formatter.getLineSeparator());
    }
    return severityStatusSectionPieces;
}
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) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) IssueVulnerabilityDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails) LinkedList(java.util.LinkedList) ComponentVulnerabilities(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentVulnerabilities)

Example 32 with ProjectIssueModel

use of com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel 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 33 with ProjectIssueModel

use of com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel in project hub-alert by blackducksoftware.

the class IssueTrackerTestAction method testConfig.

@Override
public MessageResult testConfig(DistributionJobModel testJobModel, String jobName, @Nullable String customTopic, @Nullable String customMessage) throws AlertException {
    D distributionDetails = (D) testJobModel.getDistributionJobDetails();
    IssueTrackerMessageSender<T> messageSender = messageSenderFactory.createMessageSender(distributionDetails);
    String topicString = Optional.ofNullable(customTopic).orElse("Alert Test Topic");
    String messageString = Optional.ofNullable(customMessage).orElse("Alert Test Message");
    // TODO determine if source should be required everywhere
    ProjectIssueModel testProjectIssueModel = createPlaceholderProjectIssueModel(testJobModel.getBlackDuckGlobalConfigId());
    String postCreateComment = String.format("Created by [ Test Configuration ] in the Alert Distribution Job: %s", testJobModel.getName());
    IssueCreationModel creationRequest = IssueCreationModel.simple(topicString, messageString, List.of(postCreateComment), testProjectIssueModel.getProvider());
    IssueTrackerModelHolder<T> creationRequestModelHolder = new IssueTrackerModelHolder<>(List.of(creationRequest), List.of(), List.of());
    IssueTrackerTestActionFieldStatusCreator fieldStatusCreator = new IssueTrackerTestActionFieldStatusCreator();
    List<IssueTrackerIssueResponseModel<T>> createdIssues;
    try {
        createdIssues = messageSender.sendMessages(creationRequestModelHolder);
    } catch (AlertFieldException e) {
        logger.error("Failed to create test issue", e);
        return new MessageResult("Failed to create issue: " + e.getMessage(), e.getFieldErrors());
    } catch (AlertException e) {
        logger.error("Failed to create test issue", e);
        return new MessageResult("Failed to create issue: " + e.getMessage(), fieldStatusCreator.createWithoutField(e.getMessage()));
    }
    int createdIssuesSize = createdIssues.size();
    if (createdIssuesSize != 1) {
        String errorMessage = String.format("Expected [1] issue to be created, but there were actually [%d]", createdIssuesSize);
        return new MessageResult(errorMessage, fieldStatusCreator.createWithoutField(errorMessage));
    }
    IssueTrackerIssueResponseModel<T> createdIssue = createdIssues.get(0);
    ExistingIssueDetails<T> existingIssueDetails = new ExistingIssueDetails<>(createdIssue.getIssueId(), createdIssue.getIssueKey(), createdIssue.getIssueTitle(), createdIssue.getIssueLink(), IssueStatus.RESOLVABLE, IssueCategory.BOM);
    if (!hasResolveTransition(distributionDetails)) {
        return createSuccessMessageResult(existingIssueDetails);
    }
    IssueTrackerTransitionTestAction<T> transitionTestAction = new IssueTrackerTransitionTestAction<>(messageSender, fieldStatusCreator);
    Optional<MessageResult> optionalResolveFailure = transitionTestAction.transitionTestIssueOrReturnFailureResult(IssueOperation.RESOLVE, existingIssueDetails, testProjectIssueModel);
    if (optionalResolveFailure.isPresent()) {
        return optionalResolveFailure.get();
    }
    if (!hasReopenTransition(distributionDetails)) {
        return createSuccessMessageResult(existingIssueDetails);
    }
    return transitionTestAction.transitionTestIssueOrReturnFailureResult(IssueOperation.OPEN, existingIssueDetails, testProjectIssueModel).orElseGet(() -> transitionTestAction.transitionTestIssueOrReturnFailureResult(IssueOperation.RESOLVE, existingIssueDetails, testProjectIssueModel).orElse(createSuccessMessageResult(existingIssueDetails)));
}
Also used : IssueTrackerIssueResponseModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) AlertFieldException(com.synopsys.integration.alert.common.exception.AlertFieldException) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) IssueCreationModel(com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel) IssueTrackerModelHolder(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder) ExistingIssueDetails(com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 34 with ProjectIssueModel

use of com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel in project hub-alert by blackducksoftware.

the class IssueTrackerSearcherTest method findIssuesProjectIssueModel.

@Test
public void findIssuesProjectIssueModel() throws AlertException {
    BomComponentDetails bomComponentDetails = Mockito.mock(BomComponentDetails.class);
    ProjectMessage projectMessage = ProjectMessage.componentConcern(PROVIDER_DETAILS, PROJECT_ITEM, PROJECT_VERSION_ITEM, List.of(bomComponentDetails));
    ProjectIssueModel projectIssueModel1 = Mockito.mock(ProjectIssueModel.class);
    ExistingIssueDetails<String> issue1 = new ExistingIssueDetails<>("issue-1", "issue-1", "issue 1", "https://issue-1", IssueStatus.RESOLVABLE, IssueCategory.POLICY);
    IssuePolicyDetails policyDetails = new IssuePolicyDetails("A policy", ItemOperation.DELETE, ComponentConcernSeverity.UNSPECIFIED_UNKNOWN);
    ProjectIssueModel projectIssueModel2 = Mockito.mock(ProjectIssueModel.class);
    Mockito.when(projectIssueModel2.getPolicyDetails()).thenReturn(Optional.of(policyDetails));
    IssueVulnerabilityDetails vulnerabilityDetails = new IssueVulnerabilityDetails(true, List.of(), List.of(), List.of());
    ProjectIssueModel projectIssueModel3 = Mockito.mock(ProjectIssueModel.class);
    Mockito.when(projectIssueModel3.getVulnerabilityDetails()).thenReturn(Optional.of(vulnerabilityDetails));
    ExactIssueFinder<String> exactIssueFinder = Mockito.mock(ExactIssueFinder.class);
    Mockito.when(exactIssueFinder.findExistingIssuesByProjectIssueModel(projectIssueModel1)).thenReturn(List.of(issue1));
    Mockito.when(exactIssueFinder.findExistingIssuesByProjectIssueModel(projectIssueModel2)).thenReturn(List.of());
    ProjectMessageToIssueModelTransformer mockModelTransformer = Mockito.mock(ProjectMessageToIssueModelTransformer.class);
    Mockito.when(mockModelTransformer.convertToIssueModels(Mockito.eq(projectMessage))).thenReturn(List.of(projectIssueModel1, projectIssueModel2, projectIssueModel3));
    IssueTrackerSearcher<String> searcher = new IssueTrackerSearcher<>(null, null, null, exactIssueFinder, mockModelTransformer);
    List<ActionableIssueSearchResult<String>> foundIssues = searcher.findIssues(projectMessage);
    assertEquals(1, foundIssues.size());
    ActionableIssueSearchResult<String> foundIssue = foundIssues.get(0);
    assertEquals(issue1, foundIssue.getExistingIssueDetails().orElse(null));
}
Also used : ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) IssueVulnerabilityDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) ProjectMessageToIssueModelTransformer(com.synopsys.integration.alert.api.channel.issue.convert.ProjectMessageToIssueModelTransformer) BomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails) Test(org.junit.jupiter.api.Test)

Example 35 with ProjectIssueModel

use of com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel in project hub-alert by blackducksoftware.

the class IssueTrackerSearcherTest method findIssuesComponentUpdate.

@Test
public void findIssuesComponentUpdate() throws AlertException {
    BomComponentDetails bomComponentDetails = Mockito.mock(BomComponentDetails.class);
    ProjectMessage projectMessage = ProjectMessage.componentUpdate(PROVIDER_DETAILS, PROJECT_ITEM, PROJECT_VERSION_ITEM, List.of(bomComponentDetails));
    ProjectIssueModel projectIssueModel = Mockito.mock(ProjectIssueModel.class);
    ProjectIssueSearchResult<String> projectIssueSearchResult = new ProjectIssueSearchResult<>(EXISTING_ISSUE_DETAILS, projectIssueModel);
    ProjectVersionComponentIssueFinder<String> componentIssueFinder = Mockito.mock(ProjectVersionComponentIssueFinder.class);
    Mockito.when(componentIssueFinder.findIssuesByComponent(Mockito.eq(PROVIDER_DETAILS), Mockito.eq(PROJECT_ITEM), Mockito.eq(PROJECT_VERSION_ITEM), Mockito.eq(bomComponentDetails))).thenReturn(List.of(projectIssueSearchResult));
    IssueTrackerSearcher<String> searcher = new IssueTrackerSearcher<>(null, null, componentIssueFinder, null, modelTransformer);
    List<ActionableIssueSearchResult<String>> foundIssues = searcher.findIssues(projectMessage);
    assertEquals(1, foundIssues.size());
    assertSearchResult(foundIssues.get(0), projectIssueModel, ItemOperation.UPDATE);
}
Also used : ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) BomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails) Test(org.junit.jupiter.api.Test)

Aggregations

ProjectIssueModel (com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel)47 Test (org.junit.jupiter.api.Test)29 IssueBomComponentDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails)19 IssuePolicyDetails (com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails)17 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)16 IssueVulnerabilityDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails)12 ExistingIssueDetails (com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails)11 ProjectMessage (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage)11 IssueCreationModel (com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel)10 MockIssueTrackerMessageFormatter (com.synopsys.integration.alert.api.channel.issue.convert.mock.MockIssueTrackerMessageFormatter)8 BomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)8 ProviderDetails (com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails)6 ComponentVulnerabilities (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentVulnerabilities)6 IssueComponentUnknownVersionDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueComponentUnknownVersionDetails)5 ComponentConcernType (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernType)5 LinkedList (java.util.LinkedList)5 Optional (java.util.Optional)5 IssueVulnerabilityModel (com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityModel)4 ProjectIssueSearchResult (com.synopsys.integration.alert.api.channel.issue.search.ProjectIssueSearchResult)4 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)4