use of com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage in project hub-alert by blackducksoftware.
the class ProjectMessageToIssueModelTransformerTest method convertToIssueModelsForPolicyTest.
@Test
public void convertToIssueModelsForPolicyTest() {
ComponentConcern policyConcern = ComponentConcern.policy(ItemOperation.ADD, COMPONENT_POLICY_1.getPolicyName(), "https://policy");
BomComponentDetails bomComponentDetails = createBomComponentDetails(policyConcern);
ProjectMessage projectMessage = ProjectMessage.componentConcern(PROVIDER_DETAILS, PROJECT, PROJECT_VERSION, List.of(bomComponentDetails));
ProjectMessageToIssueModelTransformer modelTransformer = new ProjectMessageToIssueModelTransformer();
List<ProjectIssueModel> policyIssueModels = modelTransformer.convertToIssueModels(projectMessage);
assertEquals(1, policyIssueModels.size());
ProjectIssueModel policyIssueModel = policyIssueModels.get(0);
assertRequiredDetails(policyIssueModel);
Optional<IssuePolicyDetails> optionalPolicyDetails = policyIssueModel.getPolicyDetails();
assertTrue(optionalPolicyDetails.isPresent(), "Expected policy details to be present");
IssuePolicyDetails policyDetails = optionalPolicyDetails.get();
assertEquals(policyConcern.getName(), policyDetails.getName());
assertEquals(policyConcern.getOperation(), policyDetails.getOperation());
assertEquals(policyConcern.getSeverity(), policyDetails.getSeverity());
}
use of com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage in project hub-alert by blackducksoftware.
the class ProjectMessageToIssueModelTransformerTest method convertToIssueModelsForComponentUnknownVersionTest.
@Test
public void convertToIssueModelsForComponentUnknownVersionTest() {
ComponentConcern unknownComponentConcern = ComponentConcern.unknownComponentVersion(ItemOperation.ADD, "Component01", ComponentConcernSeverity.MAJOR_HIGH, 2, "https://synopsys.com");
BomComponentDetails bomComponentDetails = createBomComponentDetails(unknownComponentConcern);
ProjectMessage projectMessage = ProjectMessage.componentConcern(PROVIDER_DETAILS, PROJECT, PROJECT_VERSION, List.of(bomComponentDetails));
ProjectMessageToIssueModelTransformer modelTransformer = new ProjectMessageToIssueModelTransformer();
List<ProjectIssueModel> policyIssueModels = modelTransformer.convertToIssueModels(projectMessage);
assertEquals(1, policyIssueModels.size());
ProjectIssueModel unknownVersionIssueModel = policyIssueModels.get(0);
assertRequiredDetails(unknownVersionIssueModel);
Optional<IssueComponentUnknownVersionDetails> optionalDetails = unknownVersionIssueModel.getComponentUnknownVersionDetails();
assertTrue(optionalDetails.isPresent(), "Expected unknown component details to be present");
IssueComponentUnknownVersionDetails details = optionalDetails.get();
assertEquals(ItemOperation.ADD, details.getItemOperation());
assertEquals(1, details.getEstimatedRiskModelList().size());
IssueEstimatedRiskModel estimatedRiskModel = details.getEstimatedRiskModelList().get(0);
assertEquals(ComponentConcernSeverity.MAJOR_HIGH, estimatedRiskModel.getSeverity());
assertEquals("Component01", estimatedRiskModel.getName());
assertEquals(2, estimatedRiskModel.getCount());
assertTrue(estimatedRiskModel.getComponentVersionUrl().isPresent());
}
use of com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage in project hub-alert by blackducksoftware.
the class IssueTrackerSearcherTest method findIssuesProjectVersion.
@Test
public void findIssuesProjectVersion() throws AlertException {
ProjectMessage projectMessage = ProjectMessage.projectVersionStatusInfo(PROVIDER_DETAILS, PROJECT_ITEM, PROJECT_VERSION_ITEM, ProjectOperation.DELETE);
ProjectIssueModel projectIssueModel = Mockito.mock(ProjectIssueModel.class);
ProjectIssueSearchResult<String> projectIssueSearchResult = new ProjectIssueSearchResult<>(EXISTING_ISSUE_DETAILS, projectIssueModel);
ProjectVersionIssueFinder<String> projectVersionIssueFinder = Mockito.mock(ProjectVersionIssueFinder.class);
Mockito.when(projectVersionIssueFinder.findProjectVersionIssues(Mockito.eq(PROVIDER_DETAILS), Mockito.eq(PROJECT_ITEM), Mockito.eq(PROJECT_VERSION_ITEM))).thenReturn(List.of(projectIssueSearchResult));
IssueTrackerSearcher<String> searcher = new IssueTrackerSearcher<>(null, projectVersionIssueFinder, null, null, modelTransformer);
List<ActionableIssueSearchResult<String>> foundIssues = searcher.findIssues(projectMessage);
assertEquals(1, foundIssues.size());
assertSearchResult(foundIssues.get(0), projectIssueModel, ItemOperation.DELETE);
}
use of com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage in project hub-alert by blackducksoftware.
the class IssueTrackerProcessor method processMessages.
public final IssueTrackerResponse<T> processMessages(ProviderMessageHolder messages, String jobName) throws AlertException {
List<IssueTrackerIssueResponseModel<T>> issueResponseModels = new LinkedList<>();
IssueTrackerModelHolder<T> simpleMessageHolder = modelExtractor.extractSimpleMessageIssueModels(messages.getSimpleMessages(), jobName);
List<IssueTrackerIssueResponseModel<T>> simpleMessageResponseModels = messageSender.sendMessages(simpleMessageHolder);
issueResponseModels.addAll(simpleMessageResponseModels);
for (ProjectMessage projectMessage : messages.getProjectMessages()) {
IssueTrackerModelHolder<T> projectMessageHolder = modelExtractor.extractProjectMessageIssueModels(projectMessage, jobName);
List<IssueTrackerIssueResponseModel<T>> projectMessageResponseModels = messageSender.sendMessages(projectMessageHolder);
issueResponseModels.addAll(projectMessageResponseModels);
}
return new IssueTrackerResponse<>("Success", issueResponseModels);
}
use of com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage in project hub-alert by blackducksoftware.
the class ProjectVersionNotificationMessageExtractor method extract.
@Override
protected ProviderMessageHolder extract(NotificationContentWrapper notificationContentWrapper, ProjectVersionNotificationContent notificationContent) {
AlertNotificationModel alertNotificationModel = notificationContentWrapper.getAlertNotificationModel();
Long providerConfigId = alertNotificationModel.getProviderConfigId();
String providerUrl;
try {
BlackDuckServicesFactory blackDuckServicesFactory = servicesFactoryCache.retrieveBlackDuckServicesFactory(providerConfigId);
providerUrl = blackDuckServicesFactory.getBlackDuckHttpClient().getBlackDuckUrl().string();
} catch (AlertConfigurationException e) {
logger.warn("Invalid BlackDuck configuration for notification. ID: {}. Name: {}", providerConfigId, alertNotificationModel.getProviderConfigName(), e);
return ProviderMessageHolder.empty();
}
LinkableItem providerItem = new LinkableItem(blackDuckProviderKey.getDisplayName(), alertNotificationModel.getProviderConfigName(), providerUrl);
ProviderDetails providerDetails = new ProviderDetails(alertNotificationModel.getProviderConfigId(), providerItem);
LinkableItem project = new LinkableItem(BlackDuckMessageLabels.LABEL_PROJECT, notificationContent.getProjectName(), notificationContent.getProject());
LinkableItem projectVersion = new LinkableItem(BlackDuckMessageLabels.LABEL_PROJECT_VERSION, notificationContent.getProjectVersionName(), notificationContent.getProjectVersion());
ProjectOperation operation = ProjectOperation.fromOperationType(notificationContent.getOperationType());
ProjectMessage projectVersionMessage = ProjectMessage.projectVersionStatusInfo(providerDetails, project, projectVersion, operation);
return new ProviderMessageHolder(List.of(projectVersionMessage), List.of());
}
Aggregations