Search in sources :

Example 1 with MessageReplacementValues

use of com.synopsys.integration.alert.api.channel.jira.distribution.custom.MessageReplacementValues in project hub-alert by blackducksoftware.

the class JiraIssueCreator method createCustomFieldReplacementValues.

protected MessageReplacementValues createCustomFieldReplacementValues(ProjectIssueModel alertIssueSource) {
    IssueBomComponentDetails bomComponent = alertIssueSource.getBomComponentDetails();
    ComponentUpgradeGuidance upgradeGuidance = bomComponent.getComponentUpgradeGuidance();
    Optional<String> severity = Optional.empty();
    Optional<String> policyCategory = Optional.empty();
    Optional<IssuePolicyDetails> issuePolicyDetails = alertIssueSource.getPolicyDetails();
    Optional<IssueVulnerabilityDetails> vulnerabilityDetails = alertIssueSource.getVulnerabilityDetails();
    if (issuePolicyDetails.isPresent()) {
        IssuePolicyDetails policyDetails = issuePolicyDetails.get();
        severity = Optional.ofNullable(policyDetails.getSeverity().getPolicyLabel());
        policyCategory = bomComponent.getRelevantPolicies().stream().filter(policy -> policyDetails.getName().equals(policy.getPolicyName())).findAny().flatMap(ComponentPolicy::getCategory);
    }
    if (vulnerabilityDetails.isPresent()) {
        severity = vulnerabilityDetails.get().getHighestSeverityAddedOrUpdated();
    }
    return new MessageReplacementValues.Builder(alertIssueSource.getProvider().getLabel(), alertIssueSource.getProject().getValue()).projectVersionName(alertIssueSource.getProjectVersion().map(LinkableItem::getValue).orElse(MessageReplacementValues.DEFAULT_NOTIFICATION_REPLACEMENT_VALUE)).componentName(bomComponent.getComponent().getValue()).componentVersionName(bomComponent.getComponentVersion().map(LinkableItem::getValue).orElse(MessageReplacementValues.DEFAULT_NOTIFICATION_REPLACEMENT_VALUE)).componentUsage(bomComponent.getUsage()).componentLicense(bomComponent.getLicense().getValue()).severity(severity.orElse(MessageReplacementValues.DEFAULT_NOTIFICATION_REPLACEMENT_VALUE)).policyCategory(policyCategory.orElse(MessageReplacementValues.DEFAULT_NOTIFICATION_REPLACEMENT_VALUE)).shortTermUpgradeGuidance(upgradeGuidance.getShortTermUpgradeGuidance().map(LinkableItem::getValue).orElse(MessageReplacementValues.DEFAULT_NOTIFICATION_REPLACEMENT_VALUE)).longTermUpgradeGuidance(upgradeGuidance.getLongTermUpgradeGuidance().map(LinkableItem::getValue).orElse(MessageReplacementValues.DEFAULT_NOTIFICATION_REPLACEMENT_VALUE)).build();
}
Also used : IntegrationException(com.synopsys.integration.exception.IntegrationException) MessageReplacementValues(com.synopsys.integration.alert.api.channel.jira.distribution.custom.MessageReplacementValues) ComponentConcernType(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernType) ExistingIssueDetails(com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails) StringUtils(org.apache.commons.lang3.StringUtils) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) IssueResponseModel(com.synopsys.integration.jira.common.model.response.IssueResponseModel) IssueVulnerabilityDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails) JiraIssueSearchProperties(com.synopsys.integration.alert.api.channel.jira.JiraIssueSearchProperties) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) ComponentPolicy(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentPolicy) IssueCreationResponseModel(com.synopsys.integration.jira.common.model.response.IssueCreationResponseModel) IssueCategoryRetriever(com.synopsys.integration.alert.api.channel.issue.search.IssueCategoryRetriever) ComponentUpgradeGuidance(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance) IssueStatus(com.synopsys.integration.alert.api.channel.issue.search.enumeration.IssueStatus) IssueTrackerIssueCommenter(com.synopsys.integration.alert.api.channel.issue.send.IssueTrackerIssueCommenter) JiraPreconditionNotMetException(com.synopsys.integration.jira.common.exception.JiraPreconditionNotMetException) JiraIssueAlertPropertiesUrlCorrector(com.synopsys.integration.alert.api.channel.jira.distribution.search.JiraIssueAlertPropertiesUrlCorrector) JiraIssueAlertPropertiesManager(com.synopsys.integration.alert.api.channel.jira.distribution.search.JiraIssueAlertPropertiesManager) JiraErrorMessageUtility(com.synopsys.integration.alert.api.channel.jira.distribution.JiraErrorMessageUtility) IssueCategory(com.synopsys.integration.alert.api.channel.issue.search.enumeration.IssueCategory) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) IssueFieldsComponent(com.synopsys.integration.jira.common.model.components.IssueFieldsComponent) IssueCreationModel(com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) IssueTrackerIssueCreator(com.synopsys.integration.alert.api.channel.issue.send.IssueTrackerIssueCreator) IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException) Optional(java.util.Optional) JiraIssueSearchPropertyStringCompatibilityUtils(com.synopsys.integration.alert.api.channel.jira.distribution.search.JiraIssueSearchPropertyStringCompatibilityUtils) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) IssueTrackerCallbackInfoCreator(com.synopsys.integration.alert.api.channel.issue.callback.IssueTrackerCallbackInfoCreator) JiraCallbackUtils(com.synopsys.integration.alert.api.channel.jira.util.JiraCallbackUtils) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) IssueTrackerChannelKey(com.synopsys.integration.alert.descriptor.api.model.IssueTrackerChannelKey) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) IssueVulnerabilityDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails) ComponentUpgradeGuidance(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails)

Example 2 with MessageReplacementValues

use of com.synopsys.integration.alert.api.channel.jira.distribution.custom.MessageReplacementValues in project hub-alert by blackducksoftware.

the class JiraCloudIssueCreatorTest method verifySummaryReplacingValues.

@Test
public void verifySummaryReplacingValues() throws IntegrationException {
    String projectNameOrKey = "FakeProject";
    JiraCloudJobDetailsModel jiraCloudJobDetailsModel = new JiraCloudJobDetailsModel(UUID.randomUUID(), false, "my@email.com", projectNameOrKey, "Task", null, null, List.of(), "testSummary {{providerName}}");
    TestJiraCloudIssueCreator jiraCloudIssueCreator = createTestJiraCloudIssueCreator(projectNameOrKey, jiraCloudJobDetailsModel);
    IssueCreationModel issueCreationModel = createIssueCreationModel();
    String testProviderName = "providerName";
    MessageReplacementValues messageReplacementValues = new MessageReplacementValues.Builder(testProviderName, "projectName").projectVersionName("projectVersionName").componentName("componentName").componentVersionName("componentVersionName").severity("severity").policyCategory("UNCATEGORIZED").build();
    IssueCreationRequestModel issueCreationRequest = jiraCloudIssueCreator.createIssueCreationRequest(issueCreationModel, messageReplacementValues);
    String summaryText = getSummary(issueCreationRequest);
    assertEquals("testSummary " + testProviderName, summaryText);
}
Also used : MessageReplacementValues(com.synopsys.integration.alert.api.channel.jira.distribution.custom.MessageReplacementValues) IssueCreationModel(com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel) IssueCreationRequestModel(com.synopsys.integration.jira.common.cloud.model.IssueCreationRequestModel) IssueRequestModelFieldsBuilder(com.synopsys.integration.jira.common.cloud.builder.IssueRequestModelFieldsBuilder) JiraCloudJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.JiraCloudJobDetailsModel) Test(org.junit.jupiter.api.Test)

Example 3 with MessageReplacementValues

use of com.synopsys.integration.alert.api.channel.jira.distribution.custom.MessageReplacementValues in project hub-alert by blackducksoftware.

the class JiraCloudIssueCreatorTest method verifyIssueSummaryReplacement.

@Test
public void verifyIssueSummaryReplacement() throws IntegrationException {
    String testSummary = "testSummary";
    String projectNameOrKey = "FakeProject";
    JiraCloudJobDetailsModel jiraCloudJobDetailsModel = new JiraCloudJobDetailsModel(UUID.randomUUID(), false, "my@email.com", projectNameOrKey, "Task", null, null, List.of(), testSummary);
    TestJiraCloudIssueCreator jiraCloudIssueCreator = createTestJiraCloudIssueCreator(projectNameOrKey, jiraCloudJobDetailsModel);
    IssueCreationModel issueCreationModel = createIssueCreationModel();
    MessageReplacementValues messageReplacementValues = new MessageReplacementValues.Builder("providerName", "projectName").projectVersionName("projectVersionName").componentName("componentName").componentVersionName("componentVersionName").severity("severity").policyCategory("UNCATEGORIZED").build();
    IssueCreationRequestModel issueCreationRequest = jiraCloudIssueCreator.createIssueCreationRequest(issueCreationModel, messageReplacementValues);
    String summaryText = getSummary(issueCreationRequest);
    assertEquals(testSummary, summaryText);
}
Also used : MessageReplacementValues(com.synopsys.integration.alert.api.channel.jira.distribution.custom.MessageReplacementValues) IssueCreationModel(com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel) IssueCreationRequestModel(com.synopsys.integration.jira.common.cloud.model.IssueCreationRequestModel) IssueRequestModelFieldsBuilder(com.synopsys.integration.jira.common.cloud.builder.IssueRequestModelFieldsBuilder) JiraCloudJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.JiraCloudJobDetailsModel) Test(org.junit.jupiter.api.Test)

Example 4 with MessageReplacementValues

use of com.synopsys.integration.alert.api.channel.jira.distribution.custom.MessageReplacementValues in project hub-alert by blackducksoftware.

the class JiraIssueCreator method createIssueAndExtractDetails.

@Override
protected final ExistingIssueDetails<String> createIssueAndExtractDetails(IssueCreationModel alertIssueCreationModel) throws AlertException {
    MessageReplacementValues replacementValues = alertIssueCreationModel.getSource().map(this::createCustomFieldReplacementValues).orElse(new MessageReplacementValues.Builder(alertIssueCreationModel.getProvider().getLabel(), MessageReplacementValues.DEFAULT_NOTIFICATION_REPLACEMENT_VALUE).build());
    T creationRequest = createIssueCreationRequest(alertIssueCreationModel, replacementValues);
    try {
        IssueCreationResponseModel issueCreationResponseModel = createIssue(creationRequest);
        IssueResponseModel createdIssue = fetchIssue(issueCreationResponseModel.getKey());
        IssueFieldsComponent createdIssueFields = createdIssue.getFields();
        String issueUILink = JiraCallbackUtils.createUILink(createdIssue);
        IssueCategory issueCategory = alertIssueCreationModel.getSource().map(issueCategoryRetriever::retrieveIssueCategoryFromProjectIssueModel).orElse(IssueCategory.BOM);
        return new ExistingIssueDetails<>(createdIssue.getId(), createdIssue.getKey(), createdIssueFields.getSummary(), issueUILink, IssueStatus.RESOLVABLE, issueCategory);
    } catch (IntegrationRestException restException) {
        throw jiraErrorMessageUtility.improveRestException(restException, issueCreatorDescriptorKey, extractReporter(creationRequest));
    } catch (JiraPreconditionNotMetException jiraException) {
        String message = StringUtils.join(FAILED_TO_CREATE_ISSUE_MESSAGE, jiraException.getMessage(), " ");
        throw new AlertException(message, jiraException);
    } catch (IntegrationException intException) {
        throw new AlertException(FAILED_TO_CREATE_ISSUE_MESSAGE, intException);
    }
}
Also used : IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException) IssueCreationResponseModel(com.synopsys.integration.jira.common.model.response.IssueCreationResponseModel) IssueCategory(com.synopsys.integration.alert.api.channel.issue.search.enumeration.IssueCategory) IntegrationException(com.synopsys.integration.exception.IntegrationException) IssueResponseModel(com.synopsys.integration.jira.common.model.response.IssueResponseModel) MessageReplacementValues(com.synopsys.integration.alert.api.channel.jira.distribution.custom.MessageReplacementValues) JiraPreconditionNotMetException(com.synopsys.integration.jira.common.exception.JiraPreconditionNotMetException) ExistingIssueDetails(com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails) IssueFieldsComponent(com.synopsys.integration.jira.common.model.components.IssueFieldsComponent) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Aggregations

MessageReplacementValues (com.synopsys.integration.alert.api.channel.jira.distribution.custom.MessageReplacementValues)4 IssueCreationModel (com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel)3 ExistingIssueDetails (com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails)2 IssueCategory (com.synopsys.integration.alert.api.channel.issue.search.enumeration.IssueCategory)2 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)2 JiraCloudJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.JiraCloudJobDetailsModel)2 IntegrationException (com.synopsys.integration.exception.IntegrationException)2 IssueRequestModelFieldsBuilder (com.synopsys.integration.jira.common.cloud.builder.IssueRequestModelFieldsBuilder)2 IssueCreationRequestModel (com.synopsys.integration.jira.common.cloud.model.IssueCreationRequestModel)2 JiraPreconditionNotMetException (com.synopsys.integration.jira.common.exception.JiraPreconditionNotMetException)2 IssueFieldsComponent (com.synopsys.integration.jira.common.model.components.IssueFieldsComponent)2 IssueCreationResponseModel (com.synopsys.integration.jira.common.model.response.IssueCreationResponseModel)2 IssueResponseModel (com.synopsys.integration.jira.common.model.response.IssueResponseModel)2 IntegrationRestException (com.synopsys.integration.rest.exception.IntegrationRestException)2 Test (org.junit.jupiter.api.Test)2 IssueTrackerCallbackInfoCreator (com.synopsys.integration.alert.api.channel.issue.callback.IssueTrackerCallbackInfoCreator)1 IssueBomComponentDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails)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