use of com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity in project hub-alert by blackducksoftware.
the class ChannelTemplateManager method sendEvent.
public boolean sendEvent(final AbstractEvent event) {
final String destination = event.getTopic();
if (hasTemplate(destination)) {
if (event instanceof AbstractChannelEvent) {
final AbstractChannelEvent channelEvent = (AbstractChannelEvent) event;
AuditEntryEntity auditEntryEntity = null;
if (channelEvent.getAuditEntryId() == null) {
auditEntryEntity = new AuditEntryEntity(channelEvent.getCommonDistributionConfigId(), new Date(System.currentTimeMillis()), null, null, null, null);
} else {
auditEntryEntity = auditEntryRepository.findOne(channelEvent.getAuditEntryId());
}
auditEntryEntity.setStatus(StatusEnum.PENDING);
final AuditEntryEntity savedAuditEntryEntity = auditEntryRepository.save(auditEntryEntity);
channelEvent.setAuditEntryId(savedAuditEntryEntity.getId());
for (final Long notificationId : channelEvent.getProjectData().getNotificationIds()) {
final AuditNotificationRelation auditNotificationRelation = new AuditNotificationRelation(savedAuditEntryEntity.getId(), notificationId);
auditNotificationRepository.save(auditNotificationRelation);
}
final String jsonMessage = gson.toJson(channelEvent);
final AbstractJmsTemplate template = getTemplate(destination);
template.convertAndSend(destination, jsonMessage);
} else {
final String jsonMessage = gson.toJson(event);
final AbstractJmsTemplate template = getTemplate(destination);
template.convertAndSend(destination, jsonMessage);
}
return true;
} else {
return false;
}
}
use of com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity 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.audit.repository.AuditEntryEntity in project hub-alert by blackducksoftware.
the class DistributionChannelTest method setAuditEntrySuccessTest.
@Test
public void setAuditEntrySuccessTest() {
final AuditEntryRepositoryWrapper auditEntryRepository = Mockito.mock(AuditEntryRepositoryWrapper.class);
final EmailGroupChannel channel = new EmailGroupChannel(null, null, auditEntryRepository, null, null, null);
final AuditEntryEntity entity = new AuditEntryEntity(1L, new Date(System.currentTimeMillis() - 1000), new Date(System.currentTimeMillis()), StatusEnum.SUCCESS, null, null);
entity.setId(1L);
Mockito.when(auditEntryRepository.findOne(Mockito.anyLong())).thenReturn(entity);
Mockito.when(auditEntryRepository.save(entity)).thenReturn(entity);
channel.setAuditEntrySuccess(null);
channel.setAuditEntrySuccess(entity.getId());
}
use of com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity in project hub-alert by blackducksoftware.
the class DistributionChannel method setAuditEntryFailure.
public void setAuditEntryFailure(final Long auditEntryId, final String errorMessage, final Throwable t) {
if (auditEntryId != null) {
try {
final AuditEntryEntity auditEntryEntity = getAuditEntryRepository().findOne(auditEntryId);
if (auditEntryEntity != null) {
auditEntryEntity.setStatus(StatusEnum.FAILURE);
auditEntryEntity.setErrorMessage(errorMessage);
final String[] rootCause = ExceptionUtils.getRootCauseStackTrace(t);
String exceptionStackTrace = "";
for (final String line : rootCause) {
if (exceptionStackTrace.length() + line.length() < AuditEntryEntity.STACK_TRACE_CHAR_LIMIT) {
exceptionStackTrace = exceptionStackTrace + line + System.lineSeparator();
} else {
break;
}
}
auditEntryEntity.setErrorStackTrace(exceptionStackTrace);
auditEntryEntity.setTimeLastSent(new Date(System.currentTimeMillis()));
getAuditEntryRepository().save(auditEntryEntity);
}
} catch (final Exception e) {
logger.error(e.getMessage(), e);
}
}
}
Aggregations