Search in sources :

Example 11 with NotificationModel

use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel in project hub-alert by blackducksoftware.

the class PurgeJobIT method testReaderWithData.

@Test
public void testReaderWithData() throws Exception {
    final List<NotificationEntity> entityList = new ArrayList<>();
    final String eventKey = "eventKey";
    final NotificationCategoryEnum notificationType = NotificationCategoryEnum.VULNERABILITY;
    final String projectName = "ProjectName";
    final String projectUrl = "ProjectUrl";
    final String projectVersion = "ProjectVersion";
    final String projectVersionUrl = "ProjectVersionUrl";
    final String componentName = "ComponentName";
    final String componentVersion = "ComponentVersion";
    final String policyRuleName = "PolicyRuleName";
    final String person = "PolicyPerson";
    ZonedDateTime zonedDateTime = ZonedDateTime.now().withZoneSameInstant(ZoneOffset.UTC);
    zonedDateTime = zonedDateTime.minusDays(1);
    Date createdAt = Date.from(zonedDateTime.toInstant());
    entityList.add(new NotificationEntity(eventKey, createdAt, notificationType, projectName, projectUrl, projectVersion, projectVersionUrl, componentName, componentVersion, policyRuleName, person));
    zonedDateTime = ZonedDateTime.now().withZoneSameInstant(ZoneOffset.UTC);
    zonedDateTime = zonedDateTime.minusDays(3);
    createdAt = Date.from(zonedDateTime.toInstant());
    entityList.add(new NotificationEntity(eventKey, createdAt, notificationType, projectName, projectUrl, projectVersion, projectVersionUrl, componentName, componentVersion, policyRuleName, person));
    zonedDateTime = ZonedDateTime.now().withZoneSameInstant(ZoneOffset.UTC);
    zonedDateTime = zonedDateTime.plusDays(1);
    createdAt = Date.from(zonedDateTime.toInstant());
    entityList.add(new NotificationEntity(eventKey, createdAt, notificationType, projectName, projectUrl, projectVersion, projectVersionUrl, componentName, componentVersion, policyRuleName, person));
    notificationRepository.save(entityList);
    final PurgeReader reader = purgeConfig.reader();
    final List<NotificationModel> resultList = reader.read();
    assertEquals(2, resultList.size());
}
Also used : ZonedDateTime(java.time.ZonedDateTime) ArrayList(java.util.ArrayList) NotificationCategoryEnum(com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum) NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity) Date(java.util.Date) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 12 with NotificationModel

use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel in project hub-alert by blackducksoftware.

the class PurgeJobIT method testProcessorWithData.

@Test
public void testProcessorWithData() throws Exception {
    final List<NotificationModel> entityList = new ArrayList<>();
    entityList.add(new NotificationModel(null, null));
    entityList.add(new NotificationModel(null, null));
    entityList.add(new NotificationModel(null, null));
    entityList.add(new NotificationModel(null, null));
    entityList.add(new NotificationModel(null, null));
    final PurgeProcessor processor = purgeConfig.processor();
    final List<NotificationModel> resultList = processor.process(entityList);
    assertEquals(entityList, resultList);
}
Also used : ArrayList(java.util.ArrayList) NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 13 with NotificationModel

use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel in project hub-alert by blackducksoftware.

the class DailyItemReaderTest method testReadException.

@Test
public void testReadException() throws Exception {
    final NotificationManager notificationManager = Mockito.mock(NotificationManager.class);
    Mockito.when(notificationManager.findByCreatedAtBetween(Mockito.any(), Mockito.any())).thenReturn(null);
    final DailyItemReader dailyItemReaderException = new DailyItemReader(notificationManager, globalProperties);
    final List<NotificationModel> nullNotificationList = dailyItemReaderException.read();
    assertNull(nullNotificationList);
}
Also used : NotificationManager(com.blackducksoftware.integration.hub.alert.NotificationManager) NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) Test(org.junit.Test)

Example 14 with NotificationModel

use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel in project hub-alert by blackducksoftware.

the class DailyItemReader method read.

@Override
public List<NotificationModel> read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
    List<NotificationModel> notificationList;
    PhoneHomeResponse phoneHomeResponse = null;
    try {
        notificationList = super.read();
        phoneHomeResponse = phoneHome();
    } finally {
        if (phoneHomeResponse != null) {
            phoneHomeResponse.endPhoneHome();
        }
    }
    return notificationList;
}
Also used : PhoneHomeResponse(com.blackducksoftware.integration.hub.service.model.PhoneHomeResponse) NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel)

Example 15 with NotificationModel

use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel in project hub-alert by blackducksoftware.

the class DigestItemReader method read.

@Override
public List<NotificationModel> read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
    try {
        if (hasRead) {
            return null;
        } else {
            logger.debug("{} Digest Item Reader called...", readerName);
            final DateRange dateRange = getDateRange();
            final Date startDate = dateRange.getStart();
            final Date endDate = dateRange.getEnd();
            final List<NotificationModel> entityList = notificationManager.findByCreatedAtBetween(startDate, endDate);
            hasRead = true;
            if (entityList.isEmpty()) {
                return null;
            } else {
                return entityList;
            }
        }
    } catch (final Exception ex) {
        logger.error("Error reading Digest Notification Data", ex);
    }
    return null;
}
Also used : NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) Date(java.util.Date) NonTransientResourceException(org.springframework.batch.item.NonTransientResourceException) ParseException(org.springframework.batch.item.ParseException) UnexpectedInputException(org.springframework.batch.item.UnexpectedInputException)

Aggregations

NotificationModel (com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel)39 Test (org.junit.Test)25 NotificationEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity)21 Date (java.util.Date)15 DatabaseConnectionTest (com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest)14 VulnerabilityEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity)13 ArrayList (java.util.ArrayList)10 NotificationManager (com.blackducksoftware.integration.hub.alert.NotificationManager)6 CommonDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity)5 DigestTypeEnum (com.blackducksoftware.integration.hub.alert.enumeration.DigestTypeEnum)5 AbstractChannelEvent (com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent)5 CommonDistributionConfigRestModel (com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel)5 NotificationCategoryEnum (com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum)5 ChannelTemplateManager (com.blackducksoftware.integration.hub.alert.channel.ChannelTemplateManager)4 ProjectDataFactory (com.blackducksoftware.integration.hub.alert.digest.model.ProjectDataFactory)4 LocalDateTime (java.time.LocalDateTime)4 List (java.util.List)4 AuditEntryRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper)3 AuditNotificationRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditNotificationRepositoryWrapper)3 AuditNotificationRelation (com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation)3