Search in sources :

Example 41 with LinkableItem

use of com.synopsys.integration.alert.common.message.model.LinkableItem in project hub-alert by blackducksoftware.

the class BlackDuckMessageComponentVersionUpgradeGuidanceService method createUpgradeGuidanceItems.

private ComponentUpgradeGuidance createUpgradeGuidanceItems(ComponentVersionUpgradeGuidanceView upgradeGuidanceView) {
    LinkableItem shortTermGuidance = Optional.ofNullable(upgradeGuidanceView.getShortTerm()).map(CommonUpgradeGuidanceModel::fromShortTermGuidance).map(guidanceModel -> createUpgradeGuidanceItem(BlackDuckMessageLabels.LABEL_GUIDANCE_SHORT_TERM, guidanceModel)).orElse(null);
    LinkableItem longTermGuidance = Optional.ofNullable(upgradeGuidanceView.getLongTerm()).map(CommonUpgradeGuidanceModel::fromLongTermGuidance).map(guidanceModel -> createUpgradeGuidanceItem(BlackDuckMessageLabels.LABEL_GUIDANCE_LONG_TERM, guidanceModel)).orElse(null);
    return new ComponentUpgradeGuidance(shortTermGuidance, longTermGuidance);
}
Also used : ComponentUpgradeGuidance(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance) LinkSingleResponse(com.synopsys.integration.blackduck.api.core.response.LinkSingleResponse) UrlSingleResponse(com.synopsys.integration.blackduck.api.core.response.UrlSingleResponse) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView) IntegrationException(com.synopsys.integration.exception.IntegrationException) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) StringUtils(org.apache.commons.lang3.StringUtils) ComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ComponentVersionView) HttpUrl(com.synopsys.integration.rest.HttpUrl) ArrayList(java.util.ArrayList) List(java.util.List) ResourceMetadata(com.synopsys.integration.blackduck.api.core.ResourceMetadata) ComponentVersionUpgradeGuidanceView(com.synopsys.integration.blackduck.api.generated.response.ComponentVersionUpgradeGuidanceView) Optional(java.util.Optional) BlackDuckMessageLabels(com.synopsys.integration.alert.provider.blackduck.processor.message.BlackDuckMessageLabels) ResourceLink(com.synopsys.integration.blackduck.api.core.ResourceLink) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ComponentUpgradeGuidance(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance)

Example 42 with LinkableItem

use of com.synopsys.integration.alert.common.message.model.LinkableItem in project hub-alert by blackducksoftware.

the class JiraIssueCreator method createSearchProperties.

private JiraIssueSearchProperties createSearchProperties(ProjectIssueModel alertIssueSource) {
    LinkableItem provider = alertIssueSource.getProvider();
    LinkableItem project = alertIssueSource.getProject();
    LinkableItem projectVersion = alertIssueSource.getProjectVersion().orElseThrow(() -> new AlertRuntimeException("Missing project version"));
    IssueBomComponentDetails bomComponent = alertIssueSource.getBomComponentDetails();
    LinkableItem component = bomComponent.getComponent();
    String componentVersionLabel = bomComponent.getComponentVersion().map(LinkableItem::getLabel).orElse(null);
    String componentVersionName = bomComponent.getComponentVersion().map(LinkableItem::getValue).orElse(null);
    String additionalKey = null;
    ComponentConcernType concernType = ComponentConcernType.VULNERABILITY;
    Optional<String> optionalPolicyName = alertIssueSource.getPolicyDetails().map(IssuePolicyDetails::getName);
    if (optionalPolicyName.isPresent()) {
        concernType = ComponentConcernType.POLICY;
        additionalKey = JiraIssueSearchPropertyStringCompatibilityUtils.createPolicyAdditionalKey(optionalPolicyName.get());
    }
    if (alertIssueSource.getComponentUnknownVersionDetails().isPresent()) {
        concernType = ComponentConcernType.UNKNOWN_VERSION;
    }
    String category = JiraIssueSearchPropertyStringCompatibilityUtils.createCategory(concernType);
    return new JiraIssueSearchProperties(provider.getLabel(), provider.getUrl().flatMap(JiraIssueAlertPropertiesUrlCorrector::correctUrl).orElse(null), project.getLabel(), project.getValue(), projectVersion.getLabel(), projectVersion.getValue(), category, component.getLabel(), component.getValue(), componentVersionLabel, componentVersionName, additionalKey);
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ComponentConcernType(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernType) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) JiraIssueSearchProperties(com.synopsys.integration.alert.api.channel.jira.JiraIssueSearchProperties) JiraIssueAlertPropertiesUrlCorrector(com.synopsys.integration.alert.api.channel.jira.distribution.search.JiraIssueAlertPropertiesUrlCorrector) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)

Example 43 with LinkableItem

use of com.synopsys.integration.alert.common.message.model.LinkableItem 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 44 with LinkableItem

use of com.synopsys.integration.alert.common.message.model.LinkableItem in project hub-alert by blackducksoftware.

the class JiraComponentIssueFinder method findIssuesByComponent.

@Override
public List<ProjectIssueSearchResult<String>> findIssuesByComponent(ProviderDetails providerDetails, LinkableItem project, LinkableItem projectVersion, BomComponentDetails originalBomComponent) throws AlertException {
    LinkableItem component = originalBomComponent.getComponent();
    LinkableItem nullableComponentVersion = originalBomComponent.getComponentVersion().orElse(null);
    String jqlString = JqlStringCreator.createBlackDuckComponentIssuesSearchString(jiraProjectKey, providerDetails.getProvider(), project, projectVersion, component, nullableComponentVersion);
    List<JiraSearcherResponseModel> issueResponseModels = jqlQueryExecutor.executeQuery(jqlString);
    List<ProjectIssueSearchResult<String>> searchResults = new ArrayList<>();
    for (JiraSearcherResponseModel model : issueResponseModels) {
        IssueBomComponentDetails issueBomComponentDetails = IssueBomComponentDetails.fromBomComponentDetails(originalBomComponent);
        ProjectIssueModel projectIssueModel = ProjectIssueModel.bom(providerDetails, project, projectVersion, issueBomComponentDetails);
        ProjectIssueSearchResult<String> resultFromExistingIssue = searchResultCreator.createIssueResult(model, projectIssueModel);
        searchResults.add(resultFromExistingIssue);
    }
    return searchResults;
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) ProjectIssueSearchResult(com.synopsys.integration.alert.api.channel.issue.search.ProjectIssueSearchResult) ArrayList(java.util.ArrayList) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel)

Example 45 with LinkableItem

use of com.synopsys.integration.alert.common.message.model.LinkableItem 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)

Aggregations

LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)94 Test (org.junit.jupiter.api.Test)39 ProviderDetails (com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails)26 ProjectMessage (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage)22 IssueBomComponentDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails)18 ProjectIssueModel (com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel)15 BomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)13 SimpleMessage (com.synopsys.integration.alert.processor.api.extract.model.SimpleMessage)11 ProjectOperation (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectOperation)11 ArrayList (java.util.ArrayList)11 LinkedList (java.util.LinkedList)11 IssuePolicyDetails (com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails)9 ProviderMessageHolder (com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder)9 List (java.util.List)9 ComponentVulnerabilities (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentVulnerabilities)8 Optional (java.util.Optional)7 IssueVulnerabilityDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails)6 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)6 ComponentConcern (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern)6 ComponentConcernType (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernType)6