Class CitizenServiceImpl
java.lang.Object
it.gov.pagopa.onboarding.citizen.service.CitizenServiceImpl
- All Implemented Interfaces:
CitizenService
Implementation of CitizenService.
-
Constructor Summary
ConstructorsConstructorDescriptionCitizenServiceImpl(CitizenRepository citizenRepository, CitizenConsentObjectToDTOMapper mapperToDTO, ExceptionMap exceptionMap, TppConnectorImpl tppConnector, BloomFilterServiceImpl bloomFilterService) -
Method Summary
Modifier and TypeMethodDescriptionreactor.core.publisher.Mono<CitizenConsentDTO> createCitizenConsent(String fiscalCode, String tppId) Creates or reuses a consent for the given fiscal code and TPP id.reactor.core.publisher.Mono<CitizenConsentDTO> deleteCitizenConsent(String fiscalCode) Deletes the citizen consent aggregate by fiscal code.reactor.core.publisher.Mono<CitizenConsentDTO> getCitizenConsentsList(String fiscalCode) Retrieves all consents for a fiscal code.reactor.core.publisher.Mono<CitizenConsentDTO> getCitizenConsentsListEnabled(String fiscalCode) Retrieves only enabled consents for a fiscal code.reactor.core.publisher.Mono<CitizenConsentDTO> getCitizenConsentStatus(String fiscalCode, String tppId) Retrieves consent status for a fiscal code and TPP id.reactor.core.publisher.Mono<List<CitizenConsentDTO>> getCitizenEnabled(String tppId) Retrieves citizens with an enabled consent for a TPP id.reactor.core.publisher.Mono<Boolean> getCitizenInBloomFilter(String fiscalCode) Checks if a fiscal code is in the Bloom filter and has at least one enabled consent with an active TPP.getTppEnabledList(String fiscalCode) Retrieves enabled TPP ids for a fiscal code (empty if citizen missing).reactor.core.publisher.Mono<CitizenConsentDTO> switchState(String fiscalCode, String tppId) Toggles the consent state for the specified TPP.
-
Constructor Details
-
CitizenServiceImpl
public CitizenServiceImpl(CitizenRepository citizenRepository, CitizenConsentObjectToDTOMapper mapperToDTO, ExceptionMap exceptionMap, TppConnectorImpl tppConnector, BloomFilterServiceImpl bloomFilterService)
-
-
Method Details
-
createCitizenConsent
public reactor.core.publisher.Mono<CitizenConsentDTO> createCitizenConsent(String fiscalCode, String tppId) Creates or reuses a consent for the given fiscal code and TPP id.
Flow:
- Log input (hashed fiscal code, tppId).
- Validate TPP existence (remote call).
- Load existing citizen aggregate.
- If present and missing the consent, add enabled consent and persist.
- If absent, create aggregate, persist, add to Bloom filter.
- Reduce map to the requested TPP and return DTO.
Errors:
TPP_NOT_FOUNDif remote TPP is missing.- Repository errors propagate.
- Specified by:
createCitizenConsentin interfaceCitizenService- Parameters:
fiscalCode- plain fiscal code (hashed only in logs)tppId- TPP identifier- Returns:
Mono<CitizenConsentDTO>DTO limited to the requested consent
-
switchState
Toggles the consent state for the specified TPP.
Flow:
- Log input.
- Load aggregate or error.
- Validate consent presence.
- Flip state, update timestamp, persist.
- Return DTO with only toggled consent.
Errors:
CITIZEN_NOT_ONBOARDEDif aggregate or consent is missing.
- Specified by:
switchStatein interfaceCitizenService- Parameters:
fiscalCode- plain fiscal codetppId- TPP identifier- Returns:
Mono<CitizenConsentDTO>DTO containing toggled consent
-
getCitizenConsentStatus
public reactor.core.publisher.Mono<CitizenConsentDTO> getCitizenConsentStatus(String fiscalCode, String tppId) Retrieves consent status for a fiscal code and TPP id.
Errors:
CITIZEN_NOT_ONBOARDEDif consent is missing.
- Specified by:
getCitizenConsentStatusin interfaceCitizenService- Parameters:
fiscalCode- plain fiscal codetppId- TPP identifier- Returns:
Mono<CitizenConsentDTO>consent DTO
-
getTppEnabledList
Retrieves enabled TPP ids for a fiscal code (empty if citizen missing).
Flow:
- Log start.
- Fetch aggregate (empty completion if absent).
- Filter enabled consents.
- Collect TPP ids.
Errors:
- No mapped errors; missing citizen -> empty.
- Specified by:
getTppEnabledListin interfaceCitizenService- Parameters:
fiscalCode- plain fiscal code- Returns:
Mono<List<String>>list of enabled TPP ids (may be empty)
-
getCitizenConsentsList
Retrieves all consents for a fiscal code.
Flow:
- Log start.
- Fetch aggregate; if absent -> error.
- Map to DTO.
Errors:
- Missing citizen -
CITIZEN_NOT_ONBOARDED.
- Specified by:
getCitizenConsentsListin interfaceCitizenService- Parameters:
fiscalCode- plain fiscal code- Returns:
Mono<CitizenConsentDTO>full consent DTO
-
getCitizenConsentsListEnabled
public reactor.core.publisher.Mono<CitizenConsentDTO> getCitizenConsentsListEnabled(String fiscalCode) Retrieves only enabled consents for a fiscal code.
Flow:
- Log start.
- Fetch aggregate; if absent -> error.
- Filter enabled consents.
- Map to DTO.
Errors:
- Missing citizen -
CITIZEN_NOT_ONBOARDED.
- Specified by:
getCitizenConsentsListEnabledin interfaceCitizenService- Parameters:
fiscalCode- plain fiscal code- Returns:
Mono<CitizenConsentDTO>DTO with only enabled consents
-
getCitizenEnabled
Retrieves citizens with an enabled consent for a TPP id.
Flow:
- Stream citizens with enabled consent for tppId.
- Map each to DTO.
- Collect into list.
Errors:
- Repository errors propagate.
- Specified by:
getCitizenEnabledin interfaceCitizenService- Parameters:
tppId- TPP identifier- Returns:
Mono<List<CitizenConsentDTO>>list (possibly empty)
-
deleteCitizenConsent
Deletes the citizen consent aggregate by fiscal code.
Flow:
- Fetch aggregate; if absent -> error.
- Delete by id.
- Return DTO snapshot.
Errors:
- Missing citizen -
CITIZEN_NOT_ONBOARDED.
- Specified by:
deleteCitizenConsentin interfaceCitizenService- Parameters:
fiscalCode- plain fiscal code- Returns:
Mono<CitizenConsentDTO>deleted consent DTO
-
getCitizenInBloomFilter
Checks if a fiscal code is in the Bloom filter and has at least one enabled consent with an active TPP.
Flow:
- Check Bloom filter membership (false if absent).
- If present, query DB for citizen consents.
- Filter consents with tppState = true.
- Call TPP service to verify which TPPs are still active.
- Return true if at least one active TPP or not active with a whitelistRecipient not empty exists.
Errors:
- Repository and TPP connector errors propagate.
- Specified by:
getCitizenInBloomFilterin interfaceCitizenService- Parameters:
fiscalCode- plain fiscal code- Returns:
Mono<Boolean>trueif present in Bloom filter and at least one enabled consent with active TPP exists
-