use of com.blackducksoftware.integration.hub.alert.digest.model.ProjectData 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);
}
}
use of com.blackducksoftware.integration.hub.alert.digest.model.ProjectData in project hub-alert by blackducksoftware.
the class EmailGroupChannel method sendMessage.
public void sendMessage(final List<String> emailAddresses, final EmailGroupEvent event, final String subjectLine) throws TemplateNotFoundException, MalformedTemplateNameException, ParseException, MessagingException, IOException, TemplateException {
final EmailProperties emailProperties = new EmailProperties(getGlobalConfigEntity());
final EmailMessagingService emailService = new EmailMessagingService(emailProperties);
final ProjectData data = event.getProjectData();
final HashMap<String, Object> model = new HashMap<>();
model.put(EmailProperties.TEMPLATE_KEY_SUBJECT_LINE, subjectLine);
model.put(EmailProperties.TEMPLATE_KEY_EMAIL_CATEGORY, data.getDigestType().getDisplayName());
model.put(EmailProperties.TEMPLATE_KEY_HUB_SERVER_URL, StringUtils.trimToEmpty(globalProperties.getHubUrl()));
model.put(EmailProperties.TEMPLATE_KEY_TOPIC, data);
model.put(EmailProperties.TEMPLATE_KEY_START_DATE, String.valueOf(System.currentTimeMillis()));
model.put(EmailProperties.TEMPLATE_KEY_END_DATE, String.valueOf(System.currentTimeMillis()));
for (final String emailAddress : emailAddresses) {
final EmailTarget emailTarget = new EmailTarget(emailAddress, "digest.ftl", model);
emailService.sendEmailMessage(emailTarget);
}
}
use of com.blackducksoftware.integration.hub.alert.digest.model.ProjectData 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.digest.model.ProjectData in project hub-alert by blackducksoftware.
the class ChannelTemplateManagerTest method testSendEvents.
@Test
public void testSendEvents() {
final MockAuditEntryEntity mockAuditEntryEntity = new MockAuditEntryEntity();
final AuditEntryRepositoryWrapper auditEntryRepositoryWrapper = Mockito.mock(AuditEntryRepositoryWrapper.class);
Mockito.when(auditEntryRepositoryWrapper.save(Mockito.any(AuditEntryEntity.class))).thenReturn(mockAuditEntryEntity.createEntity());
final ChannelTemplateManager channelTemplateManager = new ChannelTemplateManager(new Gson(), auditEntryRepositoryWrapper, null, null) {
@Override
public boolean hasTemplate(final String destination) {
return true;
}
@Override
public AbstractJmsTemplate getTemplate(final String destination) {
testCount++;
final AbstractJmsTemplate abstractJmsTemplate = Mockito.mock(AbstractJmsTemplate.class);
Mockito.doNothing().when(abstractJmsTemplate).convertAndSend(Mockito.anyString(), Mockito.any(Object.class));
return abstractJmsTemplate;
}
};
testCount = 0;
final ProjectData projectData = new ProjectData(DigestTypeEnum.DAILY, "test", "version", Arrays.asList(), null);
final HipChatEvent slackEvent = new HipChatEvent(projectData, 1L);
channelTemplateManager.sendEvents(Arrays.asList(slackEvent));
assertEquals(1, testCount);
}
use of com.blackducksoftware.integration.hub.alert.digest.model.ProjectData in project hub-alert by blackducksoftware.
the class HipChatChannelTest method createRequestThrowsExceptionTest.
@Test
public void createRequestThrowsExceptionTest() throws Exception {
final AuditEntryRepositoryWrapper auditEntryRepository = Mockito.mock(AuditEntryRepositoryWrapper.class);
final HipChatChannel hipChatChannel = new HipChatChannel(gson, auditEntryRepository, null, null, null, null);
final ChannelRequestHelper channelRequestHelper = new ChannelRequestHelper(null);
final HipChatDistributionConfigEntity config = new HipChatDistributionConfigEntity(12345, Boolean.FALSE, null);
final ProjectData projectData = createProjectData("HipChat IT test");
final String userDir = System.getProperties().getProperty("user.dir");
try {
System.getProperties().setProperty("user.dir", "garbage");
RuntimeException thrownException = null;
try {
hipChatChannel.createRequest(channelRequestHelper, config, projectData);
} catch (final RuntimeException e) {
thrownException = e;
}
assertNotNull(thrownException);
} finally {
System.getProperties().setProperty("user.dir", userDir);
}
}
Aggregations