@Test public void setAuditEntryFailureCatchExceptionTest() { DefaultAuditAccessor auditUtility = new DefaultAuditAccessor(null, null, null, null, null); auditUtility.setAuditEntryFailure(Collections.singletonList(1L), null, null); }
@Override @Transactional public void setAuditEntryFailure(Collection<Long> auditEntryIds, String errorMessage, Throwable t) { for (Long auditEntryId : auditEntryIds) { try { Optional<AuditEntryEntity> auditEntryEntityOptional = auditEntryRepository.findById(auditEntryId); if (auditEntryEntityOptional.isEmpty()) { logger.error("Could not find the audit entry {} to set the failure status. Error: {}", auditEntryId, errorMessage); } AuditEntryEntity auditEntryEntity = auditEntryEntityOptional.orElse(new AuditEntryEntity()); auditEntryEntity.setId(auditEntryId); auditEntryEntity.setStatus(AuditEntryStatus.FAILURE.toString()); auditEntryEntity.setErrorMessage(errorMessage); String[] rootCause = ExceptionUtils.getRootCauseStackTrace(t); String exceptionStackTrace = ""; for (String line : rootCause) { if (exceptionStackTrace.length() + line.length() < AuditEntryEntity.STACK_TRACE_CHAR_LIMIT) { exceptionStackTrace = String.format("%s%s%s", exceptionStackTrace, line, System.lineSeparator()); } else { break; } } auditEntryEntity.setErrorStackTrace(exceptionStackTrace); auditEntryEntity.setTimeLastSent(DateUtils.createCurrentDateTimestamp()); auditEntryRepository.save(auditEntryEntity); } catch (Exception e) { logger.error(e.getMessage(), e); } } }
DefaultAuditAccessor implements AuditAccessor { @Override @Transactional public void setAuditEntryFailure(Collection<Long> auditEntryIds, String errorMessage, Throwable t) { for (Long auditEntryId : auditEntryIds) { try { Optional<AuditEntryEntity> auditEntryEntityOptional = auditEntryRepository.findById(auditEntryId); if (auditEntryEntityOptional.isEmpty()) { logger.error("Could not find the audit entry {} to set the failure status. Error: {}", auditEntryId, errorMessage); } AuditEntryEntity auditEntryEntity = auditEntryEntityOptional.orElse(new AuditEntryEntity()); auditEntryEntity.setId(auditEntryId); auditEntryEntity.setStatus(AuditEntryStatus.FAILURE.toString()); auditEntryEntity.setErrorMessage(errorMessage); String[] rootCause = ExceptionUtils.getRootCauseStackTrace(t); String exceptionStackTrace = ""; for (String line : rootCause) { if (exceptionStackTrace.length() + line.length() < AuditEntryEntity.STACK_TRACE_CHAR_LIMIT) { exceptionStackTrace = String.format("%s%s%s", exceptionStackTrace, line, System.lineSeparator()); } else { break; } } auditEntryEntity.setErrorStackTrace(exceptionStackTrace); auditEntryEntity.setTimeLastSent(DateUtils.createCurrentDateTimestamp()); auditEntryRepository.save(auditEntryEntity); } catch (Exception e) { logger.error(e.getMessage(), e); } } } }
DefaultAuditAccessor implements AuditAccessor { @Override @Transactional public void setAuditEntryFailure(Collection<Long> auditEntryIds, String errorMessage, Throwable t) { for (Long auditEntryId : auditEntryIds) { try { Optional<AuditEntryEntity> auditEntryEntityOptional = auditEntryRepository.findById(auditEntryId); if (auditEntryEntityOptional.isEmpty()) { logger.error("Could not find the audit entry {} to set the failure status. Error: {}", auditEntryId, errorMessage); } AuditEntryEntity auditEntryEntity = auditEntryEntityOptional.orElse(new AuditEntryEntity()); auditEntryEntity.setId(auditEntryId); auditEntryEntity.setStatus(AuditEntryStatus.FAILURE.toString()); auditEntryEntity.setErrorMessage(errorMessage); String[] rootCause = ExceptionUtils.getRootCauseStackTrace(t); String exceptionStackTrace = ""; for (String line : rootCause) { if (exceptionStackTrace.length() + line.length() < AuditEntryEntity.STACK_TRACE_CHAR_LIMIT) { exceptionStackTrace = String.format("%s%s%s", exceptionStackTrace, line, System.lineSeparator()); } else { break; } } auditEntryEntity.setErrorStackTrace(exceptionStackTrace); auditEntryEntity.setTimeLastSent(DateUtils.createCurrentDateTimestamp()); auditEntryRepository.save(auditEntryEntity); } catch (Exception e) { logger.error(e.getMessage(), e); } } } @Autowired  DefaultAuditAccessor(AuditEntryRepository auditEntryRepository, AuditNotificationRepository auditNotificationRepository, ConfigurationAccessor configurationAccessor,
        DefaultNotificationAccessor notificationAccessor, ContentConverter contentConverter); }
DefaultAuditAccessor implements AuditAccessor { @Override @Transactional public void setAuditEntryFailure(Collection<Long> auditEntryIds, String errorMessage, Throwable t) { for (Long auditEntryId : auditEntryIds) { try { Optional<AuditEntryEntity> auditEntryEntityOptional = auditEntryRepository.findById(auditEntryId); if (auditEntryEntityOptional.isEmpty()) { logger.error("Could not find the audit entry {} to set the failure status. Error: {}", auditEntryId, errorMessage); } AuditEntryEntity auditEntryEntity = auditEntryEntityOptional.orElse(new AuditEntryEntity()); auditEntryEntity.setId(auditEntryId); auditEntryEntity.setStatus(AuditEntryStatus.FAILURE.toString()); auditEntryEntity.setErrorMessage(errorMessage); String[] rootCause = ExceptionUtils.getRootCauseStackTrace(t); String exceptionStackTrace = ""; for (String line : rootCause) { if (exceptionStackTrace.length() + line.length() < AuditEntryEntity.STACK_TRACE_CHAR_LIMIT) { exceptionStackTrace = String.format("%s%s%s", exceptionStackTrace, line, System.lineSeparator()); } else { break; } } auditEntryEntity.setErrorStackTrace(exceptionStackTrace); auditEntryEntity.setTimeLastSent(DateUtils.createCurrentDateTimestamp()); auditEntryRepository.save(auditEntryEntity); } catch (Exception e) { logger.error(e.getMessage(), e); } } } @Autowired  DefaultAuditAccessor(AuditEntryRepository auditEntryRepository, AuditNotificationRepository auditNotificationRepository, ConfigurationAccessor configurationAccessor,
        DefaultNotificationAccessor notificationAccessor, ContentConverter contentConverter); @Override Optional<Long> findMatchingAuditId(Long notificationId, UUID commonDistributionId); @Override @Transactional Optional<AuditJobStatusModel> findFirstByJobId(UUID jobId); @Override @Transactional AuditEntryPageModel getPageOfAuditEntries(Integer pageNumber, Integer pageSize, String searchTerm, String sortField, String sortOrder, boolean onlyShowSentNotifications,
        Function<AlertNotificationModel, AuditEntryModel> notificationToAuditEntryConverter); @Override @Transactional Map<Long, Long> createAuditEntry(Map<Long, Long> existingNotificationIdToAuditId, UUID jobId, MessageContentGroup contentGroup); @Override @Transactional void setAuditEntrySuccess(Collection<Long> auditEntryIds); @Override @Transactional void setAuditEntryFailure(Collection<Long> auditEntryIds, String errorMessage, Throwable t); @Override @Transactional AuditEntryModel convertToAuditEntryModelFromNotification(AlertNotificationModel notificationContentEntry); }
DefaultAuditAccessor implements AuditAccessor { @Override @Transactional public void setAuditEntryFailure(Collection<Long> auditEntryIds, String errorMessage, Throwable t) { for (Long auditEntryId : auditEntryIds) { try { Optional<AuditEntryEntity> auditEntryEntityOptional = auditEntryRepository.findById(auditEntryId); if (auditEntryEntityOptional.isEmpty()) { logger.error("Could not find the audit entry {} to set the failure status. Error: {}", auditEntryId, errorMessage); } AuditEntryEntity auditEntryEntity = auditEntryEntityOptional.orElse(new AuditEntryEntity()); auditEntryEntity.setId(auditEntryId); auditEntryEntity.setStatus(AuditEntryStatus.FAILURE.toString()); auditEntryEntity.setErrorMessage(errorMessage); String[] rootCause = ExceptionUtils.getRootCauseStackTrace(t); String exceptionStackTrace = ""; for (String line : rootCause) { if (exceptionStackTrace.length() + line.length() < AuditEntryEntity.STACK_TRACE_CHAR_LIMIT) { exceptionStackTrace = String.format("%s%s%s", exceptionStackTrace, line, System.lineSeparator()); } else { break; } } auditEntryEntity.setErrorStackTrace(exceptionStackTrace); auditEntryEntity.setTimeLastSent(DateUtils.createCurrentDateTimestamp()); auditEntryRepository.save(auditEntryEntity); } catch (Exception e) { logger.error(e.getMessage(), e); } } } @Autowired  DefaultAuditAccessor(AuditEntryRepository auditEntryRepository, AuditNotificationRepository auditNotificationRepository, ConfigurationAccessor configurationAccessor,
        DefaultNotificationAccessor notificationAccessor, ContentConverter contentConverter); @Override Optional<Long> findMatchingAuditId(Long notificationId, UUID commonDistributionId); @Override @Transactional Optional<AuditJobStatusModel> findFirstByJobId(UUID jobId); @Override @Transactional AuditEntryPageModel getPageOfAuditEntries(Integer pageNumber, Integer pageSize, String searchTerm, String sortField, String sortOrder, boolean onlyShowSentNotifications,
        Function<AlertNotificationModel, AuditEntryModel> notificationToAuditEntryConverter); @Override @Transactional Map<Long, Long> createAuditEntry(Map<Long, Long> existingNotificationIdToAuditId, UUID jobId, MessageContentGroup contentGroup); @Override @Transactional void setAuditEntrySuccess(Collection<Long> auditEntryIds); @Override @Transactional void setAuditEntryFailure(Collection<Long> auditEntryIds, String errorMessage, Throwable t); @Override @Transactional AuditEntryModel convertToAuditEntryModelFromNotification(AlertNotificationModel notificationContentEntry);  }