use of com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent in project hub-alert by blackducksoftware.
the class AuditEntryActions method resendNotification.
public List<AuditEntryRestModel> resendNotification(final Long id) throws IntegrationException, IllegalArgumentException {
AuditEntryEntity auditEntryEntity = null;
auditEntryEntity = auditEntryRepository.findOne(id);
if (auditEntryEntity == null) {
throw new AlertException("No audit entry with the provided id exists.");
}
final List<AuditNotificationRelation> relations = auditNotificationRepository.findByAuditEntryId(auditEntryEntity.getId());
final List<Long> notificationIds = relations.stream().map(relation -> relation.getNotificationId()).collect(Collectors.toList());
final List<NotificationModel> notifications = notificationManager.findByIds(notificationIds);
final Long commonConfigId = auditEntryEntity.getCommonConfigId();
final CommonDistributionConfigEntity commonConfigEntity = commonDistributionRepository.findOne(commonConfigId);
if (notifications == null || notifications.isEmpty()) {
throw new IllegalArgumentException("The notification for this entry was purged. To edit the purge schedule, please see the Scheduling Configuration.");
}
if (commonConfigEntity == null) {
throw new IllegalArgumentException("The job for this entry was deleted, can not re-send this entry.");
}
final Collection<ProjectData> projectDataList = projectDataFactory.createProjectDataCollection(notifications);
for (final ProjectData projectData : projectDataList) {
final AbstractChannelEvent event = channelEventFactory.createEvent(commonConfigId, commonConfigEntity.getDistributionType(), projectData);
event.setAuditEntryId(auditEntryEntity.getId());
channelTemplateManager.sendEvent(event);
}
return get();
}
use of com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent in project hub-alert by blackducksoftware.
the class ChannelEventFactoryTest method createEventWithChannelManagerTest.
@Test
public void createEventWithChannelManagerTest() {
final DistributionChannelManager<GlobalChannelConfigEntity, DistributionChannelConfigEntity, AbstractChannelEvent, CommonDistributionConfigRestModel> manager = Mockito.mock(DistributionChannelManager.class);
final List<DistributionChannelManager<GlobalChannelConfigEntity, DistributionChannelConfigEntity, AbstractChannelEvent, CommonDistributionConfigRestModel>> managers = Arrays.asList(manager);
final ChannelEventFactory<AbstractChannelEvent, DistributionChannelConfigEntity, GlobalChannelConfigEntity, CommonDistributionConfigRestModel> factory = new ChannelEventFactory<>(managers);
final Long id = 25L;
final ProjectData projectData = new ProjectData(DigestTypeEnum.REAL_TIME, "Project Name", "Project Version", Collections.emptyList(), Collections.emptyMap());
final AbstractChannelEvent mockEvent = new AbstractChannelEvent(projectData, id) {
@Override
public String getTopic() {
return DISTRIBUTION_TYPE;
}
};
Mockito.when(manager.isApplicable(DISTRIBUTION_TYPE)).thenReturn(true);
Mockito.when(manager.createChannelEvent(Mockito.any(), Mockito.anyLong())).thenReturn(mockEvent);
final AbstractChannelEvent event = factory.createEvent(id, "TYPE", projectData);
assertEquals(mockEvent, event);
}
use of com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent in project hub-alert by blackducksoftware.
the class DigestItemWriterTest method testWriteNull.
@Test
public void testWriteNull() throws Exception {
final ChannelTemplateManager channelTemplateManager = Mockito.mock(ChannelTemplateManager.class);
Mockito.doThrow(new NullPointerException()).when(channelTemplateManager).sendEvents(Mockito.anyListOf(AbstractChannelEvent.class));
final DigestItemWriter digestItemWriter = new DigestItemWriter(channelTemplateManager);
final AbstractChannelEvent abstractChannelEvent = Mockito.mock(AbstractChannelEvent.class);
final List<AbstractChannelEvent> channelList = Arrays.asList(abstractChannelEvent);
digestItemWriter.write(Arrays.asList(channelList));
final boolean exceptionThrown = outputLogger.isLineContainingText("Error occurred writing digest notification data to channels");
assertTrue(exceptionThrown);
}
use of com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent in project hub-alert by blackducksoftware.
the class DigestNotificationProcessorIT method processNotificationDataWithSameEventKeyTestIT.
@Test
public void processNotificationDataWithSameEventKeyTestIT() {
final Long distributionConfigId = 10L;
final String distributionType = SupportedChannels.HIPCHAT;
final String name = "Config Name";
final DigestTypeEnum frequency = DigestTypeEnum.REAL_TIME;
final Boolean filterByProject = true;
final String eventKey = "event_key";
final String projectName = "Test Hub Project Name";
final String projectVersionName = "Test Hub Project Version Name";
final CommonDistributionConfigEntity commonDistributionConfigEntity = commonDistributionRepository.save(new CommonDistributionConfigEntity(distributionConfigId, distributionType, name, frequency, filterByProject));
final ConfiguredProjectEntity configuredProjectEntity = configuredProjectsRepository.save(new ConfiguredProjectEntity(projectName));
distributionProjectRepository.save(new DistributionProjectRelation(commonDistributionConfigEntity.getId(), configuredProjectEntity.getId()));
final CommonDistributionConfigRestModel restModel = new CommonDistributionConfigRestModel(null, null, null, null, null, null, null, Arrays.asList("POLICY_VIOLATION"));
notificationActions.saveNotificationTypes(commonDistributionConfigEntity, restModel);
final List<NotificationModel> notificationList = new ArrayList<>();
final NotificationEntity applicableNotification = new NotificationEntity(eventKey, new Date(System.currentTimeMillis()), NotificationCategoryEnum.POLICY_VIOLATION, projectName, "", projectVersionName, "", "Test Component", "Test Component Version", "Test Policy Rule Name", "Test Person");
final NotificationEntity otherApplicableNotification = new NotificationEntity(eventKey, new Date(System.currentTimeMillis()), NotificationCategoryEnum.POLICY_VIOLATION, projectName, "", projectVersionName, "", "Test Component", "Test Component Version", "Test Policy Rule Name", "Test Person");
notificationList.add(new NotificationModel(applicableNotification, Collections.emptyList()));
notificationList.add(new NotificationModel(otherApplicableNotification, Collections.emptyList()));
final List<AbstractChannelEvent> eventsCreated = processor.processNotifications(DigestTypeEnum.REAL_TIME, notificationList);
assertEquals(1, eventsCreated.size());
final AbstractChannelEvent event = eventsCreated.get(0);
assertTrue(event instanceof HipChatEvent);
assertEquals(commonDistributionConfigEntity.getId(), event.getCommonDistributionConfigId());
}
use of com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent in project hub-alert by blackducksoftware.
the class DigestNotificationProcessorIT method processNotificationDataWithNegatingTypesTestIT.
@Test
public void processNotificationDataWithNegatingTypesTestIT() {
final Long distributionConfigId = 10L;
final String distributionType = SupportedChannels.HIPCHAT;
final String name = "Config Name";
final DigestTypeEnum frequency = DigestTypeEnum.REAL_TIME;
final Boolean filterByProject = true;
final String eventKey = "event_key";
final String projectName = "Test Hub Project Name";
final String projectVersionName = "Test Hub Project Version Name";
final CommonDistributionConfigEntity commonDistributionConfigEntity = commonDistributionRepository.save(new CommonDistributionConfigEntity(distributionConfigId, distributionType, name, frequency, filterByProject));
final ConfiguredProjectEntity configuredProjectEntity = configuredProjectsRepository.save(new ConfiguredProjectEntity(projectName));
distributionProjectRepository.save(new DistributionProjectRelation(commonDistributionConfigEntity.getId(), configuredProjectEntity.getId()));
final CommonDistributionConfigRestModel restModel = new CommonDistributionConfigRestModel(null, null, null, null, null, null, null, Arrays.asList("POLICY_VIOLATION", "POLICY_VIOLATION_CLEARED"));
notificationActions.saveNotificationTypes(commonDistributionConfigEntity, restModel);
final List<NotificationModel> notificationList = new LinkedList<>();
final NotificationEntity applicableNotification = new NotificationEntity(eventKey, new Date(System.currentTimeMillis()), NotificationCategoryEnum.POLICY_VIOLATION, projectName, "", projectVersionName, "", "Test Component", "Test Component Version", "Test Policy Rule Name", "Test Person");
final NotificationEntity nonApplicableNotification = new NotificationEntity(eventKey, new Date(System.currentTimeMillis()), NotificationCategoryEnum.POLICY_VIOLATION_CLEARED, projectName, "", projectVersionName, "", "Test Component", "Test Component Version", "Test Policy Rule Name", "Test Person");
notificationList.add(new NotificationModel(applicableNotification, Collections.emptyList()));
notificationList.add(new NotificationModel(nonApplicableNotification, Collections.emptyList()));
final List<AbstractChannelEvent> eventsCreated = processor.processNotifications(DigestTypeEnum.REAL_TIME, notificationList);
assertEquals(0, eventsCreated.size());
}
Aggregations