Skip to content

Commit

Permalink
[NOD-781] feat: completed debt positions mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-deri committed Apr 4, 2024
1 parent 70f5dbf commit da62d1d
Show file tree
Hide file tree
Showing 14 changed files with 258 additions and 147 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package it.gov.pagopa.wispconverter.client.gpd;

import feign.FeignException;
import it.gov.pagopa.wispconverter.client.gpd.model.PaymentPosition;
import it.gov.pagopa.wispconverter.client.gpd.model.MultiplePaymentPosition;
import it.gov.pagopa.wispconverter.config.client.GPDFeignConfig;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
Expand All @@ -19,8 +19,8 @@ public interface GPDClient {
maxAttemptsExpression = "${client.retry.max-attempts}",
backoff = @Backoff(delayExpression = "${client.retry.max-delay}"))
@PostMapping(
value = "${client.gpd.api.insert.path}",
value = "${client.gpd.api.bulk-insert.path}",
consumes = MediaType.APPLICATION_JSON_VALUE)
void executeCreation(@PathVariable("organization-fiscal-code") String organizationFiscalCode,
@RequestBody PaymentPosition body);
void executeBulkCreation(@PathVariable("organization-fiscal-code") String organizationFiscalCode,
@RequestBody MultiplePaymentPosition body);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package it.gov.pagopa.wispconverter.client.gpd.model;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

@Data
@NoArgsConstructor
public class MultiplePaymentPosition implements Serializable {

private List<PaymentPosition> paymentPositions;

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {

private final MessageSource messageSource;

@Value("${wisp-converter.error-code.uri}")
@Value("${exception.error-code.uri}")
private String errorCodeUri;

@ExceptionHandler(AppException.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ public enum AppErrorCodeMessageEnum {
PARSING_INVALID_XML_NODES(1004, "XML parsing error", "Error while parsing payload. The list of nodes extracted from document must be greater than zero, but currently it is zero.", HttpStatus.BAD_REQUEST),
PARSING_INVALID_ZIPPED_PAYLOAD(1005, "ZIP extraction error", "Error while parsing payload. Cannot unzip payload correctly.", HttpStatus.BAD_REQUEST),
PARSING_PRIMITIVE_NOT_VALID(1006, "Primitive not valid", "Error while checking primitive. Primitive [{0}] not valid.", HttpStatus.NOT_ACCEPTABLE),
VALIDATION_INVALID_IBANS(1100, "IBANs not valid", "Error while generating debt position for GPD service. The IBAN field must be set if digital stamp is not defined for the transfer.", HttpStatus.BAD_REQUEST),
VALIDATION_INVALID_MULTIBENEFICIARY_CART(1100, "RPTs not valid", "Error while generating debt position for GPD service. The cart is defined as multi-beneficiary but there are a number of RPTs lower than 2.", HttpStatus.BAD_REQUEST),
VALIDATION_INVALID_IBANS(1101, "IBANs not valid", "Error while generating debt position for GPD service. The IBAN field must be set if digital stamp is not defined for the transfer.", HttpStatus.BAD_REQUEST),
VALIDATION_INVALID_DEBTOR(1102, "Debtor subject not valid", "Error while generating debt position for GPD service. The debtor subject information is different between the various RPT of the cart.", HttpStatus.BAD_REQUEST),
VALIDATION_INVALID_CREDITOR_INSTITUTION(1103, "Creditor institution not valid", "Error while generating debt position for GPD service. The creditor institution information is different between the various RPT of the cart.", HttpStatus.BAD_REQUEST),
CONFIGURATION_INVALID_STATION(1200, "Station not valid", "Error while generating cart for Checkout service. No valid station found with code [{0}].", HttpStatus.NOT_FOUND),
// --- DB and storage interaction errors ---
PERSISTENCE_RPT_NOT_FOUND(2000, "RPT not found", "Error while retrieving RPT. RPT with sessionId [{0}] not found.", HttpStatus.NOT_FOUND),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import it.gov.pagopa.wispconverter.exception.AppException;
import it.gov.pagopa.wispconverter.repository.CacheRepository;
import it.gov.pagopa.wispconverter.service.model.CommonRPTFieldsDTO;
import it.gov.pagopa.wispconverter.service.model.PaymentNoticeContentDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
Expand Down Expand Up @@ -36,16 +37,23 @@ public void storeRequestMappingInCache(CommonRPTFieldsDTO commonRPTFieldsDTO, St
try {

String idIntermediarioPA = commonRPTFieldsDTO.getCreditorInstitutionBrokerId();
String noticeNumber = commonRPTFieldsDTO.getNav();
List<String> noticeNumbers = commonRPTFieldsDTO.getPaymentNotices().stream()
.map(PaymentNoticeContentDTO::getNoticeNumber)
.toList();

// communicating with APIM policy for caching data for decoupler
DecouplerCachingKeys decouplerCachingKeys = DecouplerCachingKeys.builder()
.keys(List.of(String.format(COMPOSITE_TWOVALUES_KEY_TEMPLATE, idIntermediarioPA, noticeNumber)))
.keys(noticeNumbers.stream()
.map(noticeNumber -> String.format(COMPOSITE_TWOVALUES_KEY_TEMPLATE, idIntermediarioPA, noticeNumber))
.toList())
.build();
this.decouplerCachingClient.storeKeyInCacheByAPIM(decouplerCachingKeys);

// save in Redis cache the mapping of the request identifier needed for RT generation in next steps
String requestIDForRTHandling = String.format(CACHING_KEY_TEMPLATE, idIntermediarioPA, noticeNumber);
this.cacheRepository.insert(requestIDForRTHandling, sessionId, this.requestIDMappingTTL);
for (String noticeNumber : noticeNumbers) {
String requestIDForRTHandling = String.format(CACHING_KEY_TEMPLATE, idIntermediarioPA, noticeNumber);
this.cacheRepository.insert(requestIDForRTHandling, sessionId, this.requestIDMappingTTL);
}

} catch (FeignException e) {
throw new AppException(e, AppErrorCodeMessageEnum.CLIENT_DECOUPLER_CACHING, e.status(), e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.Optional;

@Service
Expand All @@ -28,7 +27,7 @@ public class ConverterService {
private final RPTRequestRepository rptRequestRepository;


public String convert(String sessionId) throws IOException {
public String convert(String sessionId) {

// get RPT request entity from database
RPTRequestEntity rptRequestEntity = getRPTRequestEntity(sessionId);
Expand Down
Loading

0 comments on commit da62d1d

Please sign in to comment.