Search in sources :

Example 1 with AuditSaveFailureException

use of org.cloudfoundry.credhub.exceptions.AuditSaveFailureException in project credhub by cloudfoundry-incubator.

the class EventAuditLogService method writeAuditRecords.

private void writeAuditRecords(List<EventAuditRecordParameters> eventAuditRecordParametersList, boolean success, TransactionStatus transaction) {
    try {
        if (!success) {
            transactionManager.rollback(transaction);
            transaction = transactionManager.getTransaction(new DefaultTransactionDefinition());
        }
        final UUID uuid = requestUuid.getUuid();
        final List<EventAuditRecord> eventAuditRecords = eventAuditRecordParametersList.stream().map(parameters -> AuditLogFactory.createEventAuditRecord(parameters, userContextHolder.getUserContext(), uuid, success)).collect(Collectors.toList());
        eventAuditRecordDataService.save(eventAuditRecords);
        transactionManager.commit(transaction);
    } catch (Exception e) {
        throw new AuditSaveFailureException("error.audit_save_failure", e);
    } finally {
        if (!transaction.isCompleted()) {
            transactionManager.rollback(transaction);
        }
    }
}
Also used : EventAuditRecordDataService(org.cloudfoundry.credhub.data.EventAuditRecordDataService) Autowired(org.springframework.beans.factory.annotation.Autowired) EventAuditRecord(org.cloudfoundry.credhub.entity.EventAuditRecord) UUID(java.util.UUID) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) UserContextHolder(org.cloudfoundry.credhub.auth.UserContextHolder) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Service(org.springframework.stereotype.Service) TransactionStatus(org.springframework.transaction.TransactionStatus) AuditSaveFailureException(org.cloudfoundry.credhub.exceptions.AuditSaveFailureException) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) EventAuditRecord(org.cloudfoundry.credhub.entity.EventAuditRecord) AuditSaveFailureException(org.cloudfoundry.credhub.exceptions.AuditSaveFailureException) UUID(java.util.UUID) AuditSaveFailureException(org.cloudfoundry.credhub.exceptions.AuditSaveFailureException)

Aggregations

Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 List (java.util.List)1 UUID (java.util.UUID)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 UserContextHolder (org.cloudfoundry.credhub.auth.UserContextHolder)1 EventAuditRecordDataService (org.cloudfoundry.credhub.data.EventAuditRecordDataService)1 EventAuditRecord (org.cloudfoundry.credhub.entity.EventAuditRecord)1 AuditSaveFailureException (org.cloudfoundry.credhub.exceptions.AuditSaveFailureException)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Service (org.springframework.stereotype.Service)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)1