All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.infusers.core.audit.AuditService Maven / Gradle / Ivy

There is a newer version: 2024.12.0008
Show newest version
package com.infusers.core.audit;

import java.net.URI;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;

@Service
public class AuditService {	
	
	final Logger log = LogManager.getLogger(AuditService.class);

	@Autowired(required = true)
	private AuditRepository auditRepository;

	public ResponseEntity createAuditRecord(AuditRecord auditRecord) {
		log.debug("AuditService.createAuditRecord() Creating new audit record, audit id = ", auditRecord.getId());
		
		try {

			AuditRecord savedAuditRecord = auditRepository.save(auditRecord);
			URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(savedAuditRecord.getId())
					.toUri();
	
			return ResponseEntity.created(location).build();
		
		}
		catch(Exception e) {
			log.error("AuditService.createAuditRecord() Creating new audit record, audit id = ", auditRecord.getId()+" :: error = "+e.getMessage());
			return null;
		}
	}
}