|
1 | 1 | package it.pagopa.selfcare.pagopa.backoffice.service; |
2 | 2 |
|
| 3 | +import it.pagopa.selfcare.pagopa.backoffice.audit.AuditLogger; |
3 | 4 | import it.pagopa.selfcare.pagopa.backoffice.client.ExternalApiClient; |
4 | 5 | import it.pagopa.selfcare.pagopa.backoffice.config.InstitutionServicesConfig; |
5 | 6 | import it.pagopa.selfcare.pagopa.backoffice.entity.InstitutionRTPServiceEntity; |
6 | 7 | import it.pagopa.selfcare.pagopa.backoffice.exception.AppError; |
7 | 8 | import it.pagopa.selfcare.pagopa.backoffice.exception.AppException; |
8 | 9 | import it.pagopa.selfcare.pagopa.backoffice.model.institutions.*; |
9 | 10 | import it.pagopa.selfcare.pagopa.backoffice.model.institutions.client.Institution; |
| 11 | +import it.pagopa.selfcare.pagopa.backoffice.util.Utility; |
| 12 | +import lombok.extern.slf4j.Slf4j; |
10 | 13 | import org.springframework.beans.factory.annotation.Autowired; |
11 | 14 | import org.springframework.data.mongodb.repository.MongoRepository; |
| 15 | +import org.springframework.security.core.context.SecurityContextHolder; |
12 | 16 | import org.springframework.stereotype.Service; |
13 | 17 |
|
14 | 18 | import java.time.Instant; |
15 | 19 | import java.time.ZoneId; |
16 | 20 | import java.util.List; |
17 | 21 |
|
18 | 22 | @Service |
| 23 | +@Slf4j |
19 | 24 | public class InstitutionServicesService { |
20 | 25 | private final MongoRepository<InstitutionRTPServiceEntity, String> rtpServiceRepository; |
21 | 26 | private final ExternalApiClient externalApiClient; |
22 | 27 | private final InstitutionServicesConfig servicesConfig; |
| 28 | + private final AuditLogger auditLogger; |
23 | 29 | private static final String ORIGIN_IPA = "IPA"; |
24 | 30 |
|
25 | 31 | @Autowired |
26 | 32 | public InstitutionServicesService(MongoRepository<InstitutionRTPServiceEntity, String> rtpServiceRepository, |
27 | | - ExternalApiClient externalApiClient, InstitutionServicesConfig servicesConfig){ |
| 33 | + ExternalApiClient externalApiClient, InstitutionServicesConfig servicesConfig, |
| 34 | + AuditLogger auditLogger){ |
28 | 35 | this.rtpServiceRepository = rtpServiceRepository; |
29 | 36 | this.externalApiClient = externalApiClient; |
30 | 37 | this.servicesConfig = servicesConfig; |
| 38 | + this.auditLogger = auditLogger; |
31 | 39 | } |
32 | 40 |
|
33 | 41 | public ServiceConsentResponse saveServiceConsent(ServiceConsentRequest serviceConsentRequest, |
@@ -55,6 +63,13 @@ public ServiceConsentResponse saveServiceConsent(ServiceConsentRequest serviceCo |
55 | 63 | .consentDate(Instant.now()) |
56 | 64 | .build(); |
57 | 65 | rtpServiceRepository.save(entity); |
| 66 | + auditLogger.info(log, |
| 67 | + "event=CONSENT_UPDATE institutionId={} serviceId={} userId={} institutionTaxCode={} consent={}", |
| 68 | + institutionId, |
| 69 | + serviceId, |
| 70 | + Utility.extractUserIdFromAuth(SecurityContextHolder.getContext().getAuthentication()), |
| 71 | + institution.getTaxCode(), |
| 72 | + serviceConsentRequest.getConsent()); |
58 | 73 | response = new ServiceConsentResponse(serviceConsentRequest.getConsent(), |
59 | 74 | entity.getConsentDate().atZone(ZoneId.of("Europe/Rome")).toOffsetDateTime()); |
60 | 75 | break; |
|
0 commit comments