uk.gov.di.ipv.cri.common.library.service.AuditService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cri-common-lib Show documentation
Show all versions of cri-common-lib Show documentation
Digital Identity Credential Issuer common libraries
The newest version!
package uk.gov.di.ipv.cri.common.library.service;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import software.amazon.awssdk.services.sqs.SqsClient;
import software.amazon.awssdk.services.sqs.model.SendMessageRequest;
import software.amazon.awssdk.utils.StringUtils;
import uk.gov.di.ipv.cri.common.library.domain.AuditEvent;
import uk.gov.di.ipv.cri.common.library.domain.AuditEventContext;
import uk.gov.di.ipv.cri.common.library.domain.AuditEventType;
import uk.gov.di.ipv.cri.common.library.exception.SqsException;
public class AuditService {
private final SqsClient sqs;
private final String queueUrl;
private final ObjectMapper objectMapper;
private final AuditEventFactory auditEventFactory;
public AuditService(
SqsClient sqs,
ConfigurationService configurationService,
ObjectMapper objectMapper,
AuditEventFactory auditEventFactory) {
this.sqs = sqs;
this.objectMapper = objectMapper.registerModule(new JavaTimeModule());
this.auditEventFactory = auditEventFactory;
this.queueUrl = configurationService.getSqsAuditEventQueueUrl();
requireNonBlankQueueUrl();
}
private void requireNonBlankQueueUrl() {
if (StringUtils.isBlank(this.queueUrl)) {
throw new IllegalStateException(
"Null or empty queue url provided by configuration service");
}
}
public void sendAuditEvent(AuditEventType eventType) throws SqsException {
sendAuditEvent(eventType.toString(), null, null);
}
public void sendAuditEvent(String eventType) throws SqsException {
sendAuditEvent(eventType, null, null);
}
public void sendAuditEvent(AuditEventType eventType, AuditEventContext context)
throws SqsException {
sendAuditEvent(eventType.toString(), context, null);
}
public void sendAuditEvent(String eventType, AuditEventContext context) throws SqsException {
AuditEvent
© 2015 - 2024 Weber Informatics LLC | Privacy Policy