Search in sources :

Example 1 with RealTimeEvent

use of com.blackducksoftware.integration.hub.alert.event.RealTimeEvent in project hub-alert by blackducksoftware.

the class RealTimeListenerTest method testReceiveMessageException.

@SuppressWarnings("unchecked")
@Test
public void testReceiveMessageException() throws IOException, Exception {
    try (OutputLogger outputLogger = new OutputLogger()) {
        final Gson gson = new Gson();
        final MockNotificationEntity notificationEntity = new MockNotificationEntity();
        final NotificationModel model = new NotificationModel(notificationEntity.createEntity(), Collections.emptyList());
        final ChannelTemplateManager channelTemplateManager = Mockito.mock(ChannelTemplateManager.class);
        final ProjectDataFactory projectDataFactory = Mockito.mock(ProjectDataFactory.class);
        final NotificationEventManager eventManager = Mockito.mock(NotificationEventManager.class);
        Mockito.doNothing().when(channelTemplateManager).sendEvents(Mockito.any());
        Mockito.doThrow(new NullPointerException("null error")).when(projectDataFactory).createProjectDataCollection(Mockito.anyCollection(), Mockito.any());
        final RealTimeListener realTimeListener = new RealTimeListener(gson, channelTemplateManager, projectDataFactory, eventManager);
        final RealTimeEvent realTimeEvent = new RealTimeEvent(Arrays.asList(model));
        final String realTimeEventString = gson.toJson(realTimeEvent);
        realTimeListener.receiveMessage(realTimeEventString);
        assertTrue(outputLogger.isLineContainingText("null"));
    }
}
Also used : MockNotificationEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockNotificationEntity) ChannelTemplateManager(com.blackducksoftware.integration.hub.alert.channel.ChannelTemplateManager) NotificationEventManager(com.blackducksoftware.integration.hub.alert.digest.filter.NotificationEventManager) OutputLogger(com.blackducksoftware.integration.hub.alert.OutputLogger) Gson(com.google.gson.Gson) RealTimeEvent(com.blackducksoftware.integration.hub.alert.event.RealTimeEvent) NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) ProjectDataFactory(com.blackducksoftware.integration.hub.alert.digest.model.ProjectDataFactory) Test(org.junit.Test)

Example 2 with RealTimeEvent

use of com.blackducksoftware.integration.hub.alert.event.RealTimeEvent in project hub-alert by blackducksoftware.

the class AccumulatorWriter method write.

@Override
public void write(final List<? extends DBStoreEvent> itemList) throws Exception {
    try {
        if (itemList != null && !itemList.isEmpty()) {
            logger.info("Writing {} notifications", itemList.size());
            itemList.forEach(item -> {
                final List<NotificationEvent> notificationList = item.getNotificationList();
                final List<NotificationModel> entityList = new ArrayList<>();
                notificationList.forEach(notification -> {
                    final String eventKey = notification.getEventKey();
                    final NotificationContentItem content = (NotificationContentItem) notification.getDataSet().get(NotificationEvent.DATA_SET_KEY_NOTIFICATION_CONTENT);
                    final Date createdAt = content.getCreatedAt();
                    final NotificationCategoryEnum notificationType = notification.getCategoryType();
                    final String projectName = content.getProjectVersion().getProjectName();
                    final String projectUrl = content.getProjectVersion().getProjectLink();
                    final String projectVersion = content.getProjectVersion().getProjectVersionName();
                    final String projectVersionUrl = content.getProjectVersion().getUrl();
                    final String componentName = content.getComponentName();
                    final String componentVersion = content.getComponentVersion().versionName;
                    final String policyRuleName = getPolicyRule(notification);
                    final String person = getPerson(notification);
                    final NotificationEntity entity = new NotificationEntity(eventKey, createdAt, notificationType, projectName, projectUrl, projectVersion, projectVersionUrl, componentName, componentVersion, policyRuleName, person);
                    final Collection<VulnerabilityEntity> vulnerabilityList = getVulnerabilities(notification, entity);
                    NotificationModel model = new NotificationModel(entity, vulnerabilityList);
                    model = notificationManager.saveNotification(model);
                    entityList.add(model);
                });
                final RealTimeEvent realTimeEvent = new RealTimeEvent(entityList);
                channelTemplateManager.sendEvent(realTimeEvent);
            });
        } else {
            logger.info("No notifications to write");
        }
    } catch (final Exception ex) {
        logger.error("Error occurred writing notification data", ex);
    }
}
Also used : ArrayList(java.util.ArrayList) NotificationEvent(com.blackducksoftware.integration.hub.notification.NotificationEvent) RealTimeEvent(com.blackducksoftware.integration.hub.alert.event.RealTimeEvent) NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) VulnerabilityEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity) Date(java.util.Date) NotificationContentItem(com.blackducksoftware.integration.hub.notification.NotificationContentItem) NotificationCategoryEnum(com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity)

Example 3 with RealTimeEvent

use of com.blackducksoftware.integration.hub.alert.event.RealTimeEvent in project hub-alert by blackducksoftware.

the class RealTimeListener method receiveMessage.

@JmsListener(destination = RealTimeEvent.TOPIC_NAME)
@Override
public void receiveMessage(final String message) {
    try {
        final RealTimeEvent event = getEvent(message);
        final Collection<ProjectData> projectDataCollection = projectDataFactory.createProjectDataCollection(event.getNotificationList(), DigestTypeEnum.REAL_TIME);
        final List<AbstractChannelEvent> events = eventManager.createChannelEvents(projectDataCollection);
        channelTemplateManager.sendEvents(events);
    } catch (final Exception e) {
        logger.error(e.getMessage(), e);
    }
}
Also used : RealTimeEvent(com.blackducksoftware.integration.hub.alert.event.RealTimeEvent) ProjectData(com.blackducksoftware.integration.hub.alert.digest.model.ProjectData) AbstractChannelEvent(com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent) JmsListener(org.springframework.jms.annotation.JmsListener)

Example 4 with RealTimeEvent

use of com.blackducksoftware.integration.hub.alert.event.RealTimeEvent in project hub-alert by blackducksoftware.

the class RealTimeListenerTest method testReceiveMessage.

@Test
public void testReceiveMessage() {
    final Gson gson = new Gson();
    final MockNotificationEntity notificationEntity = new MockNotificationEntity();
    final NotificationModel model = new NotificationModel(notificationEntity.createEntity(), Collections.emptyList());
    final ChannelTemplateManager channelTemplateManager = Mockito.mock(ChannelTemplateManager.class);
    final ProjectDataFactory projectDataFactory = Mockito.mock(ProjectDataFactory.class);
    final NotificationEventManager eventManager = Mockito.mock(NotificationEventManager.class);
    final RealTimeListener realTimeListener = new RealTimeListener(gson, channelTemplateManager, projectDataFactory, eventManager);
    final RealTimeEvent realTimeEvent = new RealTimeEvent(Arrays.asList(model));
    final String realTimeEventString = gson.toJson(realTimeEvent);
    realTimeListener.receiveMessage(realTimeEventString);
    Mockito.doNothing().when(channelTemplateManager).sendEvents(Mockito.any());
    Mockito.verify(channelTemplateManager).sendEvents(Mockito.any());
}
Also used : MockNotificationEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockNotificationEntity) ChannelTemplateManager(com.blackducksoftware.integration.hub.alert.channel.ChannelTemplateManager) NotificationEventManager(com.blackducksoftware.integration.hub.alert.digest.filter.NotificationEventManager) Gson(com.google.gson.Gson) RealTimeEvent(com.blackducksoftware.integration.hub.alert.event.RealTimeEvent) NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) ProjectDataFactory(com.blackducksoftware.integration.hub.alert.digest.model.ProjectDataFactory) Test(org.junit.Test)

Aggregations

RealTimeEvent (com.blackducksoftware.integration.hub.alert.event.RealTimeEvent)4 NotificationModel (com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel)3 ChannelTemplateManager (com.blackducksoftware.integration.hub.alert.channel.ChannelTemplateManager)2 NotificationEventManager (com.blackducksoftware.integration.hub.alert.digest.filter.NotificationEventManager)2 ProjectDataFactory (com.blackducksoftware.integration.hub.alert.digest.model.ProjectDataFactory)2 MockNotificationEntity (com.blackducksoftware.integration.hub.alert.mock.entity.MockNotificationEntity)2 Gson (com.google.gson.Gson)2 Test (org.junit.Test)2 OutputLogger (com.blackducksoftware.integration.hub.alert.OutputLogger)1 NotificationEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity)1 VulnerabilityEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity)1 ProjectData (com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)1 AbstractChannelEvent (com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent)1 NotificationCategoryEnum (com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum)1 NotificationContentItem (com.blackducksoftware.integration.hub.notification.NotificationContentItem)1 NotificationEvent (com.blackducksoftware.integration.hub.notification.NotificationEvent)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 JmsListener (org.springframework.jms.annotation.JmsListener)1