Search in sources :

Example 31 with LinkableItem

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

the class IssueVulnerabilityDetailsTest method getVulnerabilitiesTest.

@Test
public void getVulnerabilitiesTest() {
    IssueVulnerabilityModel vuln1 = new IssueVulnerabilityModel(ComponentConcernSeverity.MINOR_MEDIUM, new LinkableItem("", ""));
    IssueVulnerabilityModel vuln2 = new IssueVulnerabilityModel(ComponentConcernSeverity.MAJOR_HIGH, new LinkableItem("", ""));
    IssueVulnerabilityModel vuln3 = new IssueVulnerabilityModel(ComponentConcernSeverity.BLOCKER, new LinkableItem("", ""));
    IssueVulnerabilityModel vuln4 = new IssueVulnerabilityModel(ComponentConcernSeverity.UNSPECIFIED_UNKNOWN, new LinkableItem("", ""));
    List<IssueVulnerabilityModel> vulnerabilityModelsAdded = List.of(vuln1);
    List<IssueVulnerabilityModel> vulnerabilityModelsUpdated = List.of(vuln2, vuln3);
    List<IssueVulnerabilityModel> vulnerabilityModelsDeleted = List.of(vuln4);
    IssueVulnerabilityDetails issueVulnerabilityDetails = new IssueVulnerabilityDetails(false, vulnerabilityModelsAdded, vulnerabilityModelsUpdated, vulnerabilityModelsDeleted);
    assertEquals(1, issueVulnerabilityDetails.getVulnerabilitiesAdded().size());
    assertEquals(2, issueVulnerabilityDetails.getVulnerabilitiesUpdated().size());
    assertEquals(1, issueVulnerabilityDetails.getVulnerabilitiesDeleted().size());
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) Test(org.junit.jupiter.api.Test)

Example 32 with LinkableItem

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

the class IssueVulnerabilityDetailsConverter method createIssueVulnerabilityCollectionSectionPieces.

private List<String> createIssueVulnerabilityCollectionSectionPieces(String operationParticiple, Collection<IssueVulnerabilityModel> vulnerabilities) {
    List<String> vulnDetailsSectionPieces = new LinkedList<>();
    vulnDetailsSectionPieces.add(formatter.getLineSeparator());
    vulnDetailsSectionPieces.add(formatter.encode(operationParticiple));
    String encodedSeverityPrefix = formatter.encode(LABEL_SEVERITY);
    ComponentConcernSeverity currentSeverity = ComponentConcernSeverity.UNSPECIFIED_UNKNOWN;
    for (IssueVulnerabilityModel vulnerability : vulnerabilities) {
        ComponentConcernSeverity vulnerabilitySeverity = vulnerability.getSeverity();
        if (!currentSeverity.equals(vulnerabilitySeverity)) {
            currentSeverity = vulnerabilitySeverity;
            vulnDetailsSectionPieces.add(formatter.getLineSeparator());
            vulnDetailsSectionPieces.add(encodedSeverityPrefix);
            vulnDetailsSectionPieces.add(formatter.encode(currentSeverity.getVulnerabilityLabel()));
            vulnDetailsSectionPieces.add(formatter.getLineSeparator());
        }
        LinkableItem vulnerabilityItem = vulnerability.getVulnerability();
        Optional<String> optionalUrl = vulnerabilityItem.getUrl().map(formatter::encode);
        String encodedValue = formatter.encode(vulnerabilityItem.getValue());
        String vulnerabilityDetail;
        if (optionalUrl.isPresent()) {
            vulnerabilityDetail = formatter.createLink(encodedValue, optionalUrl.get());
        } else {
            vulnerabilityDetail = encodedValue;
        }
        vulnerabilityDetail = String.format("[%s%s%s]", formatter.getNonBreakingSpace(), vulnerabilityDetail, formatter.getNonBreakingSpace());
        vulnDetailsSectionPieces.add(vulnerabilityDetail);
        vulnDetailsSectionPieces.add(formatter.getNonBreakingSpace());
    }
    return vulnDetailsSectionPieces;
}
Also used : ComponentConcernSeverity(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernSeverity) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) IssueVulnerabilityModel(com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityModel) LinkedList(java.util.LinkedList)

Example 33 with LinkableItem

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

the class IssueTrackerSimpleMessageConverter method convertToIssueCreationModel.

public IssueCreationModel convertToIssueCreationModel(SimpleMessage simpleMessage, String jobName) {
    LinkableItem provider = simpleMessage.getProvider();
    String rawTitle = String.format("%s[%s] | %s", provider.getLabel(), provider.getValue(), simpleMessage.getSummary());
    String truncatedTitle = StringUtils.truncate(rawTitle, formatter.getMaxTitleLength());
    List<String> descriptionChunks = simpleMessageConverter.convertToFormattedMessageChunks(simpleMessage, jobName);
    RechunkedModel rechunkedDescription = ChunkedStringBuilderRechunker.rechunk(descriptionChunks, "No description", formatter.getMaxDescriptionLength(), formatter.getMaxCommentLength());
    return IssueCreationModel.simple(truncatedTitle, rechunkedDescription.getFirstChunk(), rechunkedDescription.getRemainingChunks(), simpleMessage.getProvider());
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) RechunkedModel(com.synopsys.integration.alert.common.channel.message.RechunkedModel)

Example 34 with LinkableItem

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

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

the class PolicyOverrideNotificationMessageExtractor method createBomComponentDetails.

@Override
protected List<BomComponentDetails> createBomComponentDetails(PolicyOverrideUniquePolicyNotificationContent notificationContent, BlackDuckServicesFactory blackDuckServicesFactory) throws IntegrationException {
    BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
    BlackDuckMessageBomComponentDetailsCreator bomComponentDetailsCreator = detailsCreatorFactory.createBomComponentDetailsCreator(blackDuckServicesFactory);
    ComponentConcern policyConcern = policyComponentConcernCreator.fromPolicyInfo(notificationContent.getPolicyInfo(), ItemOperation.DELETE);
    String overriderName = String.format("%s %s", notificationContent.getFirstName(), notificationContent.getLastName());
    LinkableItem overrider = new LinkableItem(BlackDuckMessageLabels.LABEL_OVERRIDER, overriderName);
    BomComponentDetails bomComponentDetails;
    try {
        ProjectVersionComponentVersionView bomComponent = blackDuckApiClient.getResponse(new HttpUrl(notificationContent.getBomComponent()), ProjectVersionComponentVersionView.class);
        bomComponentDetails = bomComponentDetailsCreator.createBomComponentDetails(bomComponent, policyConcern, ComponentUpgradeGuidance.none(), List.of(overrider));
    } catch (IntegrationRestException e) {
        bomComponent404Handler.logIf404OrThrow(e, notificationContent.getComponentName(), notificationContent.getComponentVersionName());
        bomComponentDetails = bomComponentDetailsCreator.createMissingBomComponentDetails(notificationContent.getComponentName(), notificationContent.getBomComponent(), notificationContent.getComponentVersionName(), notificationContent.getBomComponent(), List.of(policyConcern), ComponentUpgradeGuidance.none(), List.of(overrider));
    }
    return List.of(bomComponentDetails);
}
Also used : IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) BlackDuckMessageBomComponentDetailsCreator(com.synopsys.integration.alert.provider.blackduck.processor.message.service.BlackDuckMessageBomComponentDetailsCreator) ComponentConcern(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern) HttpUrl(com.synopsys.integration.rest.HttpUrl) BomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)

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