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());
}
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;
}
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());
}
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;
}
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);
}
Aggregations