Skip to content

Commit

Permalink
fix: get receipt model
Browse files Browse the repository at this point in the history
  • Loading branch information
alessio-cialini committed Dec 18, 2024
1 parent 1ae155e commit 1d5bd68
Show file tree
Hide file tree
Showing 18 changed files with 2,093 additions and 403 deletions.
711 changes: 336 additions & 375 deletions openapi/openapi.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@
</executions>
<configuration>
<sources>
<source>${project.basedir}/src/main/resources/service.xsd</source>
<!-- <source>${project.basedir}/src/main/resources/service.xsd</source>-->
<!-- <source>${project.basedir}/src/main/resources/nodo-for-psp.xsd</source>-->
<!-- <source>${project.basedir}/src/main/resources/nodo-for-pa.xsd</source>-->
<source>${project.basedir}/src/main/resources/nodo-for-pa.xsd</source>
<!-- <source>${project.basedir}/src/main/resources/MarcaDaBollo.xsd</source>-->
</sources>
</configuration>
Expand Down
31 changes: 26 additions & 5 deletions src/main/java/it/gov/pagopa/mbd/service/client/ReactiveClient.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
package it.gov.pagopa.mbd.service.client;

import com.fasterxml.jackson.databind.ObjectMapper;
import it.gov.pagopa.mbd.service.exception.WebClientException;
import it.gov.pagopa.mbd.service.model.carts.GetCartRequest;
import it.gov.pagopa.mbd.service.model.carts.GetCartResponse;
import it.gov.pagopa.mbd.service.model.xml.node.nodeforpsp.DemandPaymentNoticeRequest;
import it.gov.pagopa.mbd.service.model.xml.node.nodeforpsp.DemandPaymentNoticeResponse;
import it.gov.pagopa.mbd.service.model.xml.node.soap.envelope.Envelope;
import it.gov.pagopa.mbd.service.model.xml.node.pafornode.CtReceiptV2;
import it.gov.pagopa.mbd.service.model.xml.node.pafornode.CtTransferListPAReceiptV2;
import it.gov.pagopa.mbd.service.model.xml.node.pafornode.CtTransferPAReceiptV2;
import it.gov.pagopa.mbd.service.model.xml.node.pafornode.PaSendRTV2Request;
import it.gov.pagopa.mbd.service.model.xml.node.soap.envelope.Envelope;
import it.gov.pagopa.mbd.service.model.xml.xsd.common_types.v1_0.StOutcome;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.WebClientResponseException;
import reactor.core.publisher.Mono;

import java.util.List;

import static org.hibernate.validator.internal.util.Contracts.assertNotNull;
import static org.hibernate.validator.internal.util.Contracts.assertTrue;

@Component
public class ReactiveClient {

Expand Down Expand Up @@ -80,14 +88,27 @@ public Mono<GetCartResponse> getCart(GetCartRequest getCartRequest) {

}

public Mono<CtTransferPAReceiptV2> getPaymentReceipt(String fiscalCode, String iuv) {
public Mono<PaSendRTV2Request> getPaymentReceipt(String fiscalCode, String iuv) {

return webClient.get()
.uri(String.format(clientDataConfig.getGetPaymentReceiptEndpoint(), fiscalCode, iuv))
.header(OCP_SUBSCRIPTION_KEY, clientDataConfig.getGetPaymentReceiptSubscriptionKey())
.retrieve()
.bodyToMono(CtTransferPAReceiptV2.class)
.onErrorMap(e -> new WebClientException(e.getMessage(), e));
.bodyToMono(PaSendRTV2Request.class).map(
item -> {
assertNotNull(item);
CtReceiptV2 ctReceiptV2 = item.getReceipt();
assertNotNull(ctReceiptV2);
CtTransferListPAReceiptV2 ctTransferListPAReceiptV2 = ctReceiptV2.getTransferList();
assertNotNull(ctTransferListPAReceiptV2);
List<CtTransferPAReceiptV2> ctTransferPAReceiptV2 = ctTransferListPAReceiptV2.getTransfer();
assertTrue(!ctTransferPAReceiptV2.isEmpty(), "Missing ctTransferPAReceiptV2");
assertNotNull(ctTransferPAReceiptV2.get(0).getMBDAttachment());
return item;
}
)
.onErrorMap(IllegalArgumentException.class, e -> e)
.onErrorMap(WebClientResponseException.class, e -> new WebClientException(e.getMessage(), e));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public Mono<ResponseEntity> getMdb(@PathVariable("fiscalCodeEC") String fiscalCo
@GetMapping(value = "/organizations/{fiscalCode}/receipt/{nav}", produces = MediaType.APPLICATION_XML_VALUE)
public Mono<ResponseEntity> getPaymentReceipts(@PathVariable("fiscalCode") String fiscalCode,
@PathVariable("nav") String nav) {
return mdbService.getPaymentReceipts(fiscalCode, nav);
}
return mdbService.getPaymentReceipts(fiscalCode, nav).onErrorResume(Mono::error);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected Mono<ResponseEntity<Object>> handleMethodArgumentNotValid(MethodArgume
}

@ExceptionHandler({ConstraintViolationException.class})
public Mono<ResponseEntity<ProblemJson>> handleMyException(ConstraintViolationException ex, ServerWebExchange exchange) {
public Mono<ResponseEntity<ProblemJson>> handleConstraintException(ConstraintViolationException ex, ServerWebExchange exchange) {
log.warn("Validation Error raised:", ex);
var errorResponse =
ProblemJson.builder()
Expand All @@ -141,6 +141,18 @@ public Mono<ResponseEntity<ProblemJson>> handleMyException(ConstraintViolationEx
return Mono.just(new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST));
}

@ExceptionHandler({WebClientException.class})
public Mono<ResponseEntity<ProblemJson>> handleWebClientException(WebClientException ex, ServerWebExchange exchange) {
log.warn("Validation Error raised:", ex);
var errorResponse =
ProblemJson.builder()
.status(HttpStatus.BAD_REQUEST.value())
.title(AppError.INTERNAL_SERVER_ERROR.getTitle())
.detail(ex.getMessage())
.build();
return Mono.just(new ResponseEntity<>(errorResponse, HttpStatus.INTERNAL_SERVER_ERROR));
}

/**
* Handle if a {@link FeignException} is raised
*
Expand Down Expand Up @@ -186,8 +198,8 @@ public Mono<ResponseEntity<ProblemJson>> handleFeignException(
* @return a {@link ProblemJson} as response with the cause and with an appropriated HTTP status
*/
@ExceptionHandler({AppException.class})
public ResponseEntity<ProblemJson> handleAppException(
final AppException ex, final WebRequest request) {
public Mono<ResponseEntity<ProblemJson>> handleAppException(
final AppException ex, final ServerWebExchange request) {
if (ex.getCause() != null) {
log.warn(
"App Exception raised: " + ex.getMessage() + "\nCause of the App Exception: ",
Expand All @@ -201,7 +213,7 @@ public ResponseEntity<ProblemJson> handleAppException(
.title(ex.getTitle())
.detail(ex.getMessage())
.build();
return new ResponseEntity<>(errorResponse, ex.getHttpStatus());
return Mono.just(new ResponseEntity<>(errorResponse, ex.getHttpStatus()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
//
// Questo file è stato generato dall'Eclipse Implementation of JAXB, v3.0.0
// Vedere https://eclipse-ee4j.github.io/jaxb-ri
// Qualsiasi modifica a questo file andrà persa durante la ricompilazione dello schema di origine.
// Generato il: 2024.12.18 alle 10:59:02 AM CET
//


package it.gov.pagopa.mbd.service.model.xml.node.pafornode;

import jakarta.xml.bind.annotation.*;


/**
* <p>Classe Java per ctEntityUniqueIdentifier complex type.
*
* <p>Il seguente frammento di schema specifica il contenuto previsto contenuto in questa classe.
*
* <pre>
* &lt;complexType name="ctEntityUniqueIdentifier"&gt;
* &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;sequence&gt;
* &lt;element name="entityUniqueIdentifierType" type="{http://pagopa-api.pagopa.gov.it/pa/paForNode.xsd}stEntityUniqueIdentifierType"/&gt;
* &lt;element name="entityUniqueIdentifierValue" type="{http://pagopa-api.pagopa.gov.it/pa/paForNode.xsd}stEntityUniqueIdentifierValue"/&gt;
* &lt;/sequence&gt;
* &lt;/restriction&gt;
* &lt;/complexContent&gt;
* &lt;/complexType&gt;
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ctEntityUniqueIdentifier", propOrder = {
"entityUniqueIdentifierType",
"entityUniqueIdentifierValue"
})
public class CtEntityUniqueIdentifier {

@XmlElement(required = true)
@XmlSchemaType(name = "string")
protected StEntityUniqueIdentifierType entityUniqueIdentifierType;
@XmlElement(required = true)
protected String entityUniqueIdentifierValue;

/**
* Recupera il valore della proprietà entityUniqueIdentifierType.
*
* @return
* possible object is
* {@link StEntityUniqueIdentifierType }
*
*/
public StEntityUniqueIdentifierType getEntityUniqueIdentifierType() {
return entityUniqueIdentifierType;
}

/**
* Imposta il valore della proprietà entityUniqueIdentifierType.
*
* @param value
* allowed object is
* {@link StEntityUniqueIdentifierType }
*
*/
public void setEntityUniqueIdentifierType(StEntityUniqueIdentifierType value) {
this.entityUniqueIdentifierType = value;
}

/**
* Recupera il valore della proprietà entityUniqueIdentifierValue.
*
* @return
* possible object is
* {@link String }
*
*/
public String getEntityUniqueIdentifierValue() {
return entityUniqueIdentifierValue;
}

/**
* Imposta il valore della proprietà entityUniqueIdentifierValue.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setEntityUniqueIdentifierValue(String value) {
this.entityUniqueIdentifierValue = value;
}

}
Loading

0 comments on commit 1d5bd68

Please sign in to comment.