Skip to content

Commit

Permalink
Issue #758
Browse files Browse the repository at this point in the history
Aggiunta nuova operazione POST /ricevute allo schema API-Backoffice.
  • Loading branch information
pintorig committed Nov 26, 2024
1 parent c7ed5e3 commit f6e492c
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String, ErrorCode> errorsMap = new HashMap<>(4);
private static Map<String, ErrorCode> 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,7 +33,7 @@ public class BooleanDeserializer extends JsonDeserializer<Boolean> {


@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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f6e492c

Please sign in to comment.