Search in sources :

Example 51 with AlertNotificationModel

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

the class NotificationReceivedEventHandlerTestIT method testAlertNotificationModels.

private void testAlertNotificationModels(List<AlertNotificationModel> models) {
    PageRequest pageRequest = defaultNotificationAccessor.getPageRequestForNotifications(0, models.size(), null, null);
    List<AlertNotificationModel> alertNotificationModels = defaultNotificationAccessor.findAll(pageRequest, false).getContent();
    assertModelsAreProcessed(alertNotificationModels);
    assertEquals(0, defaultNotificationAccessor.getFirstPageOfNotificationsNotProcessed(pageSize).getModels().size());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) PageRequest(org.springframework.data.domain.PageRequest)

Example 52 with AlertNotificationModel

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

the class NotificationReceivedEventHandlerTestIT method createAlertNotificationModel.

private AlertNotificationModel createAlertNotificationModel(boolean processed) {
    String bomEditContent = "{" + "\"type\":\"" + NotificationType.BOM_EDIT.name() + "\"," + "\"content\": {" + "\"projectVersion\": \"" + properties.getBlackDuckURL() + "/api/projects\"," + "\"bomComponent\": \"" + properties.getBlackDuckURL() + "\"," + "\"componentName\": \"test\"," + "\"componentVersionName\": \"test\"" + "}" + "}";
    MockNotificationContent notificationMocker = new MockNotificationContent(DateUtils.createCurrentDateTimestamp(), blackDuckProviderKey.getUniversalKey(), DateUtils.createCurrentDateTimestamp(), NotificationType.BOM_EDIT.name(), bomEditContent, null, blackDuckGlobalConfigId);
    NotificationEntity entity = notificationMocker.createEntity();
    return new AlertNotificationModel(null, entity.getProviderConfigId(), entity.getProvider(), "providerConfigName", entity.getNotificationType(), entity.getContent(), entity.getCreatedAt(), entity.getProviderCreationTime(), processed);
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) MockNotificationContent(com.synopsys.integration.alert.mock.entity.MockNotificationContent) NotificationEntity(com.synopsys.integration.alert.database.notification.NotificationEntity)

Example 53 with AlertNotificationModel

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

the class NotificationReceivedEventHandlerTestIT method testHandleEventNotProcessedNotifications.

@Test
void testHandleEventNotProcessedNotifications() {
    List<AlertNotificationModel> notificationContent = new ArrayList<>();
    notificationContent.add(createAlertNotificationModel(false));
    notificationContent.add(createAlertNotificationModel(false));
    List<AlertNotificationModel> savedModels = defaultNotificationAccessor.saveAllNotifications(notificationContent);
    assertNotNull(savedModels);
    NotificationProcessor notificationProcessor = createNotificationProcessor();
    NotificationReceivedEventHandler notificationReceivedEventHandler = new NotificationReceivedEventHandler(defaultNotificationAccessor, notificationProcessor, eventManager);
    notificationReceivedEventHandler.handle(new NotificationReceivedEvent());
    testAlertNotificationModels(savedModels);
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) ArrayList(java.util.ArrayList) NotificationProcessor(com.synopsys.integration.alert.processor.api.NotificationProcessor) NotificationReceivedEvent(com.synopsys.integration.alert.api.event.NotificationReceivedEvent) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 54 with AlertNotificationModel

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

the class DefaultNotificationAccessor method getFirstPageOfNotificationsNotProcessed.

@Override
@Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED)
public AlertPagedModel<AlertNotificationModel> getFirstPageOfNotificationsNotProcessed(int pageSize) {
    int currentPage = 0;
    Sort.Order sortingOrder = Sort.Order.asc(COLUMN_NAME_PROVIDER_CREATION_TIME);
    PageRequest pageRequest = PageRequest.of(currentPage, pageSize, Sort.by(sortingOrder));
    Page<AlertNotificationModel> pageOfNotifications = notificationContentRepository.findByProcessedFalseOrderByProviderCreationTimeAsc(pageRequest).map(this::toModel);
    List<AlertNotificationModel> alertNotificationModels = pageOfNotifications.getContent();
    return new AlertPagedModel<>(pageOfNotifications.getTotalPages(), currentPage, pageSize, alertNotificationModels);
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) PageRequest(org.springframework.data.domain.PageRequest) Sort(org.springframework.data.domain.Sort) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel) Transactional(org.springframework.transaction.annotation.Transactional)

Example 55 with AlertNotificationModel

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

the class DefaultNotificationAccessor method findByCreatedAtBetween.

@Override
@Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED)
public AlertPagedModel<AlertNotificationModel> findByCreatedAtBetween(OffsetDateTime startDate, OffsetDateTime endDate, int pageNumber, int pageSize) {
    Sort.Order sortingOrder = Sort.Order.asc(COLUMN_NAME_PROVIDER_CREATION_TIME);
    PageRequest pageRequest = PageRequest.of(pageNumber, pageSize, Sort.by(sortingOrder));
    Page<AlertNotificationModel> pageOfNotifications = notificationContentRepository.findByCreatedAtBetween(startDate, endDate, pageRequest).map(this::toModel);
    List<AlertNotificationModel> alertNotificationModels = pageOfNotifications.getContent();
    return new AlertPagedModel<>(pageOfNotifications.getTotalPages(), pageNumber, pageSize, alertNotificationModels);
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) PageRequest(org.springframework.data.domain.PageRequest) Sort(org.springframework.data.domain.Sort) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel) Transactional(org.springframework.transaction.annotation.Transactional)

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