From f6e492c9b37bff9483f69ff6bb19a1b97a060456 Mon Sep 17 00:00:00 2001 From: Giuliano Pintori Date: Tue, 26 Nov 2024 17:27:51 +0100 Subject: [PATCH] Issue #758 Aggiunta nuova operazione POST /ricevute allo schema API-Backoffice. --- ...GiornaleEventiCollectorOutInterceptor.java | 59 +++++++++++-------- .../eventi/GiornaleEventiOutInterceptor.java | 3 +- .../rs/eventi/GiornaleEventiUtilities.java | 5 +- .../recaptcha/beans/CaptchaResponse.java | 38 ++++++------ .../deserializer/BooleanDeserializer.java | 3 +- .../webapp/v1/govpay-api-backoffice-v1.yaml | 41 ++++++++++++- 6 files changed, 96 insertions(+), 53 deletions(-) diff --git a/jars/api-commons/src/main/java/it/govpay/rs/eventi/GiornaleEventiCollectorOutInterceptor.java b/jars/api-commons/src/main/java/it/govpay/rs/eventi/GiornaleEventiCollectorOutInterceptor.java index ca43dfb890..accd59f29f 100644 --- a/jars/api-commons/src/main/java/it/govpay/rs/eventi/GiornaleEventiCollectorOutInterceptor.java +++ b/jars/api-commons/src/main/java/it/govpay/rs/eventi/GiornaleEventiCollectorOutInterceptor.java @@ -35,6 +35,7 @@ import org.apache.cxf.io.CachedOutputStreamCallback; import org.apache.cxf.message.Exchange; import org.apache.cxf.message.Message; +import org.openspcoop2.generic_project.exception.ServiceException; import org.openspcoop2.utils.LoggerWrapperFactory; import org.openspcoop2.utils.service.context.ContextThreadLocal; import org.openspcoop2.utils.service.context.IContext; @@ -45,6 +46,7 @@ import it.govpay.core.dao.configurazione.ConfigurazioneDAO; import it.govpay.core.utils.GovpayConfig; import it.govpay.core.utils.GpContext; +import it.govpay.core.utils.LogUtils; import it.govpay.core.utils.client.HttpMethod; import it.govpay.core.utils.rawutils.ConverterUtils; import it.govpay.model.configurazione.GdeInterfaccia; @@ -89,7 +91,7 @@ public void handleMessage(Message message) throws Fault { HttpMethod httpMethod = GiornaleEventiUtilities.getHttpMethod(httpMethodS); esito = eventoCtx.getEsito() != null ? eventoCtx.getEsito() : Esito.KO; - this.log.debug("Log Evento API: [{}] Method [{}], Url [{}], Esito [{}]", apiName, httpMethodS, url, esito); + LogUtils.logDebug(this.log, "Log Evento API: [{}] Method [{}], Url [{}], Esito [{}]", apiName, httpMethodS, url, esito); GdeInterfaccia configurazioneInterfaccia = GiornaleEventiUtilities.getConfigurazioneGiornaleEventi(context, this.configurazioneDAO, this.giornaleEventiConfig); @@ -99,18 +101,18 @@ public void handleMessage(Message message) throws Fault { return; } - this.log.debug("Configurazione Giornale Eventi API: [{}]: {}", apiName, ConverterUtils.toJSON(configurazioneInterfaccia)); + LogUtils.logDebug(this.log, "Configurazione Giornale Eventi API: [{}]: {}", apiName, ConverterUtils.toJSON(configurazioneInterfaccia)); if(GiornaleEventiUtilities.isRequestLettura(httpMethod, this.giornaleEventiConfig.getApiNameEnum(), eventoCtx.getTipoEvento())) { logEvento = GiornaleEventiUtilities.logEvento(configurazioneInterfaccia.getLetture(), esito); dumpEvento = GiornaleEventiUtilities.dumpEvento(configurazioneInterfaccia.getLetture(), esito); - this.log.debug("Tipo Operazione ''Lettura'', Log [{}], Dump [{}].", logEvento, dumpEvento); + LogUtils.logDebug(this.log, "Tipo Operazione ''Lettura'', Log [{}], Dump [{}].", logEvento, dumpEvento); } else if(GiornaleEventiUtilities.isRequestScrittura(httpMethod, this.giornaleEventiConfig.getApiNameEnum(), eventoCtx.getTipoEvento())) { logEvento = GiornaleEventiUtilities.logEvento(configurazioneInterfaccia.getScritture(), esito); dumpEvento = GiornaleEventiUtilities.dumpEvento(configurazioneInterfaccia.getScritture(), esito); - this.log.debug("Tipo Operazione ''Scrittura'', Log [{}], Dump [{}].", logEvento, dumpEvento); + LogUtils.logDebug(this.log, "Tipo Operazione ''Scrittura'', Log [{}], Dump [{}].", logEvento, dumpEvento); } else { - this.log.debug("Tipo Operazione non riconosciuta, l'evento non verra' salvato."); + LogUtils.logDebug(this.log, "Tipo Operazione non riconosciuta, l'evento non verra' salvato."); } eventoCtx.setRegistraEvento(logEvento); @@ -148,31 +150,36 @@ public void handleMessage(Message message) throws Fault { eventoCtx.setClusterId(clusterId); if(dumpEvento) { - // dump richiesta - if (shouldLogContent(eventRequest)) { - GiornaleEventiUtilities.addContent(inMessage, eventRequest, this.giornaleEventiConfig); - } else { - eventRequest.setPayload(AbstractLoggingInterceptor.CONTENT_SUPPRESSED); - } - if(eventRequest.getPayload() != null) - dettaglioRichiesta.setPayload(Base64.getEncoder().encodeToString(eventRequest.getPayload().getBytes())); - - // dump risposta - final OutputStream os = message.getContent(OutputStream.class); - if (os != null) { - LoggingCallback callback = new LoggingCallback(this.sender, message, eventoCtx, os, this.limit); - message.setContent(OutputStream.class, createCacheAndWriteOutputStream(message, os, callback)); - } + dumpEvento(message, eventoCtx, inMessage, eventRequest, dettaglioRichiesta); } } - } catch (Throwable e) { + } catch (it.govpay.core.exceptions.IOException | ServiceException e) { this.log.error(e.getMessage(),e); } finally { //donothing } } - private OutputStream createCacheAndWriteOutputStream(Message message, final OutputStream os, CachedOutputStreamCallback callback) { + private void dumpEvento(Message message, EventoContext eventoCtx, Message inMessage, final LogEvent eventRequest, + DettaglioRichiesta dettaglioRichiesta) { + // dump richiesta + if (shouldLogContent(eventRequest)) { + GiornaleEventiUtilities.addContent(inMessage, eventRequest, this.giornaleEventiConfig); + } else { + eventRequest.setPayload(AbstractLoggingInterceptor.CONTENT_SUPPRESSED); + } + if(eventRequest.getPayload() != null) + dettaglioRichiesta.setPayload(Base64.getEncoder().encodeToString(eventRequest.getPayload().getBytes())); + + // dump risposta + final OutputStream os = message.getContent(OutputStream.class); + if (os != null) { + LoggingCallback callback = new LoggingCallback(this.sender, message, eventoCtx, os, this.limit); + message.setContent(OutputStream.class, createCacheAndWriteOutputStream(os, callback)); + } + } + + private OutputStream createCacheAndWriteOutputStream(final OutputStream os, CachedOutputStreamCallback callback) { final CacheAndWriteOutputStream newOut = new CacheAndWriteOutputStream(os); if (this.threshold > 0) { newOut.setThreshold(this.threshold); @@ -238,8 +245,8 @@ public void onClose(CachedOutputStream cos) { // ignore } this.message.setContent(OutputStream.class, this.origStream); - } catch (Throwable e) { - LoggerWrapperFactory.getLogger(GiornaleEventiCollectorOutInterceptor.class).error(e.getMessage(),e); + } catch (Exception e) { + LogUtils.logError(LoggerWrapperFactory.getLogger(GiornaleEventiCollectorOutInterceptor.class),e.getMessage(),e); throw new Fault(e); } } @@ -248,7 +255,7 @@ private void copyPayload(CachedOutputStream cos, final LogEvent event) { try { String encoding = (String) this.message.get(Message.ENCODING); StringBuilder payload = new StringBuilder(); - writePayload(payload, cos, encoding, event.getContentType()); + writePayload(payload, cos, encoding); event.setPayload(payload.toString()); boolean isTruncated = cos.size() > this.lim && this.lim != -1; event.setTruncated(isTruncated); @@ -257,7 +264,7 @@ private void copyPayload(CachedOutputStream cos, final LogEvent event) { } } - protected void writePayload(StringBuilder builder, CachedOutputStream cos, String encoding, String contentType) + protected void writePayload(StringBuilder builder, CachedOutputStream cos, String encoding) throws IOException { if (StringUtils.isEmpty(encoding)) { cos.writeCacheTo(builder, this.lim); diff --git a/jars/api-commons/src/main/java/it/govpay/rs/eventi/GiornaleEventiOutInterceptor.java b/jars/api-commons/src/main/java/it/govpay/rs/eventi/GiornaleEventiOutInterceptor.java index f071ae8758..b25b4df1cb 100644 --- a/jars/api-commons/src/main/java/it/govpay/rs/eventi/GiornaleEventiOutInterceptor.java +++ b/jars/api-commons/src/main/java/it/govpay/rs/eventi/GiornaleEventiOutInterceptor.java @@ -31,6 +31,7 @@ import org.apache.cxf.message.Message; import org.apache.cxf.phase.AbstractPhaseInterceptor; import org.apache.cxf.phase.Phase; +import org.openspcoop2.generic_project.exception.ServiceException; import org.openspcoop2.utils.LoggerWrapperFactory; import org.openspcoop2.utils.service.context.ContextThreadLocal; import org.openspcoop2.utils.service.context.IContext; @@ -109,7 +110,7 @@ public void handleMessage(Message message) throws Fault { PutEventoDTO putEventoDTO = new PutEventoDTO(context.getAuthentication()); putEventoDTO.setEvento(eventoCtx); this.eventiDAO.inserisciEvento(putEventoDTO); - } catch (Throwable e) { + } catch (ServiceException e) { this.log.error(e.getMessage(),e); } finally { // donothing diff --git a/jars/api-commons/src/main/java/it/govpay/rs/eventi/GiornaleEventiUtilities.java b/jars/api-commons/src/main/java/it/govpay/rs/eventi/GiornaleEventiUtilities.java index 9f1228008c..6c01cce141 100644 --- a/jars/api-commons/src/main/java/it/govpay/rs/eventi/GiornaleEventiUtilities.java +++ b/jars/api-commons/src/main/java/it/govpay/rs/eventi/GiornaleEventiUtilities.java @@ -36,9 +36,6 @@ import it.govpay.core.dao.configurazione.ConfigurazioneDAO; import it.govpay.core.dao.configurazione.dto.LeggiConfigurazioneDTO; import it.govpay.core.dao.configurazione.dto.LeggiConfigurazioneDTOResponse; -import it.govpay.core.dao.configurazione.exception.ConfigurazioneNonTrovataException; -import it.govpay.core.exceptions.NotAuthenticatedException; -import it.govpay.core.exceptions.NotAuthorizedException; import it.govpay.core.utils.client.HttpMethod; import it.govpay.core.utils.eventi.EventiUtils; import it.govpay.model.configurazione.GdeEvento; @@ -49,7 +46,7 @@ public class GiornaleEventiUtilities { private GiornaleEventiUtilities() {} - public static GdeInterfaccia getConfigurazioneGiornaleEventi (IContext context, ConfigurazioneDAO configurazioneDAO, GiornaleEventiConfig giornaleEventiConfig) throws ConfigurazioneNonTrovataException, NotAuthorizedException, NotAuthenticatedException, ServiceException, it.govpay.core.exceptions.IOException { + public static GdeInterfaccia getConfigurazioneGiornaleEventi (IContext context, ConfigurazioneDAO configurazioneDAO, GiornaleEventiConfig giornaleEventiConfig) throws ServiceException, it.govpay.core.exceptions.IOException { LeggiConfigurazioneDTO leggiConfigurazioneDTO = new LeggiConfigurazioneDTO(context.getAuthentication()); LeggiConfigurazioneDTOResponse configurazione = configurazioneDAO.getConfigurazione(leggiConfigurazioneDTO); Giornale giornale = configurazione.getConfigurazione().getGiornale(); diff --git a/jars/api-commons/src/main/java/it/govpay/rs/v1/authentication/recaptcha/beans/CaptchaResponse.java b/jars/api-commons/src/main/java/it/govpay/rs/v1/authentication/recaptcha/beans/CaptchaResponse.java index b7aec4cd28..73c0390376 100644 --- a/jars/api-commons/src/main/java/it/govpay/rs/v1/authentication/recaptcha/beans/CaptchaResponse.java +++ b/jars/api-commons/src/main/java/it/govpay/rs/v1/authentication/recaptcha/beans/CaptchaResponse.java @@ -71,8 +71,8 @@ public boolean hasClientError() { } for(ErrorCode error : errors) { switch(error) { - case InvalidResponse: - case MissingResponse: + case INVALID_RESPONSE: + case MISSING_RESPONSE: return true; default: return false; @@ -81,26 +81,26 @@ public boolean hasClientError() { return false; } - static enum ErrorCode { - MissingSecret, InvalidSecret, - MissingResponse, InvalidResponse, - BadRequest, TimeoutOrDuplicate; + enum ErrorCode { + MISSING_SECRET, INVALID_SECRET, + MISSING_RESPONSE, INVALID_RESPONSE, + BAD_REQUEST, TIMEOUT_OR_DUPLICATE; - private static Map errorsMap = new HashMap<>(4); + private static Map errorsMap = new HashMap<>(4); - static { - errorsMap.put("missing-input-secret", MissingSecret); - errorsMap.put("invalid-input-secret", InvalidSecret); - errorsMap.put("missing-input-response", MissingResponse); - errorsMap.put("invalid-input-response", InvalidResponse); - errorsMap.put("bad-request", BadRequest); - errorsMap.put("timeout-or-duplicate", TimeoutOrDuplicate); - } + static { + errorsMap.put("missing-input-secret", MISSING_SECRET); + errorsMap.put("invalid-input-secret", INVALID_SECRET); + errorsMap.put("missing-input-response", MISSING_RESPONSE); + errorsMap.put("invalid-input-response", INVALID_RESPONSE); + errorsMap.put("bad-request", BAD_REQUEST); + errorsMap.put("timeout-or-duplicate", TIMEOUT_OR_DUPLICATE); + } - @JsonCreator - public static ErrorCode forValue(String value) { - return errorsMap.get(value.toLowerCase()); - } + @JsonCreator + public static ErrorCode forValue(String value) { + return errorsMap.get(value.toLowerCase()); + } } public boolean isSuccess() { diff --git a/jars/api-commons/src/main/java/it/govpay/rs/v1/beans/deserializer/BooleanDeserializer.java b/jars/api-commons/src/main/java/it/govpay/rs/v1/beans/deserializer/BooleanDeserializer.java index a1c0178d43..c01ebf6723 100644 --- a/jars/api-commons/src/main/java/it/govpay/rs/v1/beans/deserializer/BooleanDeserializer.java +++ b/jars/api-commons/src/main/java/it/govpay/rs/v1/beans/deserializer/BooleanDeserializer.java @@ -23,7 +23,6 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.ObjectCodec; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; @@ -34,7 +33,7 @@ public class BooleanDeserializer extends JsonDeserializer { @Override - public Boolean deserialize(JsonParser jsonParser, DeserializationContext ctxt) throws IOException, JsonProcessingException { + public Boolean deserialize(JsonParser jsonParser, DeserializationContext ctxt) throws IOException { ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); diff --git a/wars/api-backoffice/src/main/webapp/v1/govpay-api-backoffice-v1.yaml b/wars/api-backoffice/src/main/webapp/v1/govpay-api-backoffice-v1.yaml index 30a52c14eb..24f7b42ddf 100644 --- a/wars/api-backoffice/src/main/webapp/v1/govpay-api-backoffice-v1.yaml +++ b/wars/api-backoffice/src/main/webapp/v1/govpay-api-backoffice-v1.yaml @@ -1,6 +1,6 @@ openapi: 3.0.0 info: - version: "1.43.0" + version: "1.44.0" title: GovPay - API Backoffice contact: name: GitHub Project Page @@ -23,6 +23,8 @@ tags: description: Pagamenti gestiti dalla piattaforma - name: Pendenze description: Pagamenti in attesa e spontanei + - name: Ricevute + description: Gestione delle ricevute telematiche pagoPA - name: Riconciliazioni description: Movimenti in tesoreria riconciliati - name: Rendicontazioni @@ -2908,6 +2910,43 @@ paths: $ref: '#/components/responses/404' '500': $ref: '#/components/responses/500' + '/ricevute': + post: + tags: + - Ricevute + summary: Acquisizione di una RT in formato xml + operationId: addRicevuta + requestBody: + content: + text/xml: + schema: + type: object + multipart/form-data: + schema: + type: object + properties: + fileName: + type: string + format: binary + description: RT in formato XML + required: true + responses: + '201': + description: RT acquisita con successo + content: + application/json: + schema: + $ref: '#/components/schemas/rppIndex' + '400': + $ref: '#/components/responses/400' + '401': + $ref: '#/components/responses/401' + '403': + $ref: '#/components/responses/403' + '415': + $ref: '#/components/responses/415' + '500': + $ref: '#/components/responses/500' '/riscossioni': get: summary: Elenco dei pagamenti riscossi