Search in sources :

Example 71 with AlertNotificationModel

use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.

the class RuleViolationClearedNotificationContentDetailExtractorTest method extractDetailedContentTest.

@Test
public void extractDetailedContentTest() throws IOException {
    String jsonContent = TestResourceUtils.readFileToString(NOTIFICATION_JSON_PATH);
    RuleViolationClearedNotificationView notificationView = gson.fromJson(jsonContent, RuleViolationClearedNotificationView.class);
    RuleViolationClearedNotificationContent notificationContent = notificationView.getContent();
    AlertNotificationModel notification = new AlertNotificationModel(0L, 0L, "BlackDuck", "Config 1", null, null, null, null, false);
    RuleViolationClearedNotificationDetailExtractor extractor = new RuleViolationClearedNotificationDetailExtractor();
    List<DetailedNotificationContent> detailedNotificationContents = extractor.extractDetailedContent(notification, notificationView);
    assertEquals(2, detailedNotificationContents.size());
    for (DetailedNotificationContent detailedContent : detailedNotificationContents) {
        Optional<String> optionalProjectName = detailedContent.getProjectName();
        assertTrue(optionalProjectName.isPresent(), "Expect project name to be present");
        assertEquals(notificationContent.getProjectName(), optionalProjectName.get());
        Optional<String> optionalPolicyName = detailedContent.getPolicyName();
        assertTrue(optionalPolicyName.isPresent(), "Expected policy name to be present");
        boolean containsPolicy = notificationContent.getPolicyInfos().stream().map(PolicyInfo::getPolicyName).anyMatch(policyName -> policyName.equals(optionalPolicyName.get()));
        assertTrue(containsPolicy, "Expected policy name to be present in original notification");
        assertEquals(0, detailedContent.getVulnerabilitySeverities().size());
    }
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) RuleViolationClearedNotificationView(com.synopsys.integration.blackduck.api.manual.view.RuleViolationClearedNotificationView) DetailedNotificationContent(com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent) RuleViolationClearedNotificationContent(com.synopsys.integration.blackduck.api.manual.component.RuleViolationClearedNotificationContent) Test(org.junit.jupiter.api.Test)

Example 72 with AlertNotificationModel

use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.

the class BlackDuckAccumulator method computeLatestNotificationCreatedAtDate.

// Expects that the notifications are sorted oldest to newest
private Optional<OffsetDateTime> computeLatestNotificationCreatedAtDate(List<AlertNotificationModel> sortedNotifications) {
    if (!sortedNotifications.isEmpty()) {
        int lastIndex = sortedNotifications.size() - 1;
        AlertNotificationModel lastNotification = sortedNotifications.get(lastIndex);
        return Optional.of(lastNotification.getProviderCreationTime());
    }
    return Optional.empty();
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)

Example 73 with AlertNotificationModel

use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.

the class BlackDuckAccumulator method write.

private void write(List<AlertNotificationModel> contentList) {
    logger.info("Writing {} notifications...", contentList.size());
    List<AlertNotificationModel> savedNotifications = notificationAccessor.saveAllNotifications(contentList);
    if (logger.isDebugEnabled()) {
        List<Long> notificationIds = savedNotifications.stream().map(AlertNotificationModel::getId).collect(Collectors.toList());
        String joinedIds = StringUtils.join(notificationIds, ", ");
        notificationLogger.debug("Saved notifications: {}", joinedIds);
    }
    eventManager.sendEvent(new NotificationReceivedEvent());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) NotificationReceivedEvent(com.synopsys.integration.alert.api.event.NotificationReceivedEvent)

Example 74 with AlertNotificationModel

use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.

the class AuditEntryActions method resendNotification.

public ActionResponse<AuditEntryPageModel> resendNotification(Long notificationId, @Nullable UUID requestedJobId) {
    if (!authorizationManager.hasExecutePermission(ConfigContextEnum.GLOBAL, descriptorKey)) {
        return new ActionResponse<>(HttpStatus.FORBIDDEN, ActionResponse.FORBIDDEN_MESSAGE);
    }
    Optional<AlertNotificationModel> notification = notificationAccessor.findById(notificationId);
    if (notification.isEmpty()) {
        return new ActionResponse<>(HttpStatus.GONE, "No notification with this id exists.");
    }
    AlertNotificationModel notificationContent = notification.get();
    if (null != requestedJobId) {
        Optional<DistributionJobModel> optionalDistributionJob = jobAccessor.getJobById(requestedJobId);
        if (optionalDistributionJob.isEmpty()) {
            String message = String.format("The Distribution Job with this id could not be found. %s", requestedJobId.toString());
            return new ActionResponse<>(HttpStatus.GONE, message);
        }
        DistributionJobModel distributionJob = optionalDistributionJob.get();
        if (distributionJob.isEnabled()) {
            ProcessedNotificationDetails processedNotificationDetails = ProcessedNotificationDetails.fromDistributionJob(distributionJob);
            jobNotificationProcessor.processNotificationForJob(processedNotificationDetails, distributionJob.getProcessingType(), List.of(notificationContent));
        } else {
            UUID jobConfigId = distributionJob.getJobId();
            logger.warn("The Distribution Job with Id {} was disabled. This notification could not be sent", jobConfigId);
            String message = String.format("The Distribution Job is currently disabled. %s", jobConfigId);
            return new ActionResponse<>(HttpStatus.BAD_REQUEST, message);
        }
    } else {
        notificationProcessor.processNotifications(List.of(notificationContent), List.of(FrequencyType.DAILY, FrequencyType.REAL_TIME));
    }
    return get();
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) ProcessedNotificationDetails(com.synopsys.integration.alert.processor.api.distribute.ProcessedNotificationDetails) UUID(java.util.UUID) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)

Example 75 with AlertNotificationModel

use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.

the class NotificationAccessorTestIT method testFindAllWithSearchByFieldValue.

@Test
public void testFindAllWithSearchByFieldValue() {
    NotificationEntity notificationContent = createNotificationContent();
    notificationContent = notificationContentRepository.save(notificationContent);
    OffsetDateTime currentTime = DateUtils.createCurrentDateTimestamp();
    DistributionJobEntity distributionJobEntity = new DistributionJobEntity(null, "job_name", true, FrequencyType.REAL_TIME.name(), ProcessingType.DEFAULT.name(), ChannelKeys.EMAIL.getUniversalKey(), UUID.randomUUID(), currentTime, null);
    DistributionJobEntity savedJob = distributionJobRepository.save(distributionJobEntity);
    final String auditStatus = "audit status thing";
    AuditEntryEntity auditEntryEntity = new AuditEntryEntity(savedJob.getJobId(), DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp(), auditStatus, "", "");
    auditEntryEntity = auditEntryRepository.save(auditEntryEntity);
    AuditNotificationRelation auditNotificationRelation = new AuditNotificationRelation(auditEntryEntity.getId(), notificationContent.getId());
    auditNotificationRepository.save(auditNotificationRelation);
    PageRequest pageRequest = PageRequest.of(0, 10);
    Page<AlertNotificationModel> all = notificationManager.findAllWithSearch(ChannelKeys.EMAIL.getUniversalKey(), pageRequest, false);
    // Search term should match the channel name
    assertFalse(all.isEmpty());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) PageRequest(org.springframework.data.domain.PageRequest) DistributionJobEntity(com.synopsys.integration.alert.database.job.DistributionJobEntity) OffsetDateTime(java.time.OffsetDateTime) AuditNotificationRelation(com.synopsys.integration.alert.database.audit.AuditNotificationRelation) AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity) NotificationEntity(com.synopsys.integration.alert.database.notification.NotificationEntity) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)94 Test (org.junit.jupiter.api.Test)62 DetailedNotificationContent (com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent)21 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)20 NotificationEntity (com.synopsys.integration.alert.database.notification.NotificationEntity)16 PageRequest (org.springframework.data.domain.PageRequest)16 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)14 NotificationContentRepository (com.synopsys.integration.alert.database.notification.NotificationContentRepository)14 OffsetDateTime (java.time.OffsetDateTime)13 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)11 ArrayList (java.util.ArrayList)10 NotificationProcessor (com.synopsys.integration.alert.processor.api.NotificationProcessor)9 NotificationReceivedEvent (com.synopsys.integration.alert.api.event.NotificationReceivedEvent)7 FilteredDistributionJobResponseModel (com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel)7 DefaultNotificationAccessor (com.synopsys.integration.alert.database.api.DefaultNotificationAccessor)6 NotificationDetailExtractionDelegator (com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractionDelegator)6 NotificationContentComponent (com.synopsys.integration.blackduck.api.manual.component.NotificationContentComponent)5 PageImpl (org.springframework.data.domain.PageImpl)5 TaskManager (com.synopsys.integration.alert.api.task.TaskManager)4 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)4