SDIProtocolManager.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */


  20. package org.openspcoop2.protocol.sdi.config;

  21. import java.util.Map;

  22. import org.slf4j.Logger;
  23. import org.openspcoop2.message.OpenSPCoop2Message;
  24. import org.openspcoop2.message.OpenSPCoop2MessageFactory;
  25. import org.openspcoop2.message.constants.MessageRole;
  26. import org.openspcoop2.message.constants.MessageType;
  27. import org.openspcoop2.protocol.basic.config.BasicManager;
  28. import org.openspcoop2.protocol.sdi.constants.SDICostanti;
  29. import org.openspcoop2.protocol.sdi.constants.SDICostantiServizioRiceviFile;
  30. import org.openspcoop2.protocol.sdi.constants.SDICostantiServizioRiceviNotifica;
  31. import org.openspcoop2.protocol.sdi.constants.SDICostantiServizioRicezioneFatture;
  32. import org.openspcoop2.protocol.sdi.constants.SDICostantiServizioTrasmissioneFatture;
  33. import org.openspcoop2.protocol.sdk.Busta;
  34. import org.openspcoop2.protocol.sdk.IProtocolFactory;
  35. import org.openspcoop2.protocol.sdk.ProtocolException;
  36. import org.openspcoop2.protocol.sdk.constants.FaultIntegrationGenericInfoMode;
  37. import org.openspcoop2.protocol.sdk.constants.TipoIntegrazione;
  38. import org.openspcoop2.protocol.sdk.registry.IRegistryReader;
  39. import org.openspcoop2.utils.BooleanNullable;
  40. import org.openspcoop2.utils.io.notifier.NotifierInputStreamParams;
  41. import org.openspcoop2.utils.transport.TransportRequestContext;
  42. import org.openspcoop2.utils.transport.TransportResponseContext;

  43. /**
  44.  * Classe che implementa, in base al protocollo SdI, l'interfaccia {@link org.openspcoop2.protocol.sdk.config.IProtocolManager}
  45.  *
  46.  * @author Poli Andrea (apoli@link.it)
  47.  * @author $Author$
  48.  * @version $Rev$, $Date$
  49.  */
  50. public class SDIProtocolManager extends BasicManager {
  51.    


  52.     protected SDIProperties sdiProperties = null;
  53.     protected Logger logger = null;
  54.     public SDIProtocolManager(IProtocolFactory<?> protocolFactory) throws ProtocolException{
  55.         super(protocolFactory);
  56.         this.logger = this.getProtocolFactory().getLogger();
  57.         this.sdiProperties = SDIProperties.getInstance(this.logger);
  58.     }
  59.    
  60.    
  61.     /* *********** VALIDAZIONE/GENERAZIONE BUSTE ******************* */
  62.    
  63.     @Override
  64.     public boolean isIgnoraEccezioniNonGravi(){
  65.         return true;
  66.     }
  67.    
  68.     @Override
  69.     public boolean isGenerazioneListaEccezioniErroreProcessamento(){
  70.         return true; // l'eccezione viene utilizzata per produrre un errore applicativo e/o per impostare un codice nel soap fault
  71.     }
  72.    
  73.    
  74.    
  75.    
  76.    
  77.     /* *********** Fault della Porta (Protocollo, Porta Applicativa) ******************* */
  78.    
  79.     @Override
  80.     public boolean isGenerazioneDetailsFaultProtocollo_EccezioneValidazione(){
  81.         return this.sdiProperties.isGenerazioneDetailsSOAPFaultProtocolValidazione();
  82.     }
  83.    
  84.     @Override
  85.     public boolean isGenerazioneDetailsFaultProtocollo_EccezioneProcessamento(){
  86.         return this.sdiProperties.isGenerazioneDetailsSOAPFaultProtocolProcessamento();
  87.     }
  88.        
  89.     @Override
  90.     public boolean isGenerazioneDetailsFaultProtocolloConStackTrace(){
  91.         return this.sdiProperties.isGenerazioneDetailsSOAPFaultProtocolWithStackTrace();
  92.     }
  93.    
  94.     @Override
  95.     public boolean isGenerazioneDetailsFaultProtocolloConInformazioniGeneriche(){
  96.         return this.sdiProperties.isGenerazioneDetailsSOAPFaultProtocolConInformazioniGeneriche();
  97.     }
  98.    
  99.    
  100.    
  101.     /* *********** Fault della Porta (Integrazione, Porta Delegata) ******************* */
  102.    
  103.     @Override
  104.     public boolean isGenerazioneDetailsFaultIntegratione_erroreServer(){
  105.         return this.sdiProperties.isGenerazioneDetailsSOAPFaultIntegrationServerError();
  106.     }
  107.    
  108.     @Override
  109.     public boolean isGenerazioneDetailsFaultIntegratione_erroreClient(){
  110.         return this.sdiProperties.isGenerazioneDetailsSOAPFaultIntegrationClientError();
  111.     }
  112.    
  113.     @Override
  114.     public boolean isGenerazioneDetailsFaultIntegrationeConStackTrace(){
  115.         return this.sdiProperties.isGenerazioneDetailsSOAPFaultIntegrationWithStackTrace();
  116.     }
  117.    
  118.     @Override
  119.     public FaultIntegrationGenericInfoMode getModalitaGenerazioneInformazioniGeneriche_DetailsFaultIntegrazione(){
  120.         Boolean value = this.sdiProperties.isGenerazioneDetailsSOAPFaultIntegrazionConInformazioniGeneriche();
  121.         if(value==null){
  122.             return FaultIntegrationGenericInfoMode.SERVIZIO_APPLICATIVO;
  123.         }
  124.         else if(value){
  125.             return FaultIntegrationGenericInfoMode.ABILITATO;
  126.         }else{
  127.             return FaultIntegrationGenericInfoMode.DISABILITATO;
  128.         }
  129.     }
  130.    
  131.    
  132.    
  133.     /* *********** Fault della Porta (Generati dagli attori esterni) ******************* */
  134.    
  135.     @Override
  136.     public BooleanNullable isAggiungiDetailErroreApplicativo_FaultApplicativo() {
  137.         return this.sdiProperties.isAggiungiDetailErroreApplicativo_SoapFaultApplicativo();
  138.     }

  139.     @Override
  140.     public BooleanNullable isAggiungiDetailErroreApplicativo_FaultPdD() {
  141.         return this.sdiProperties.isAggiungiDetailErroreApplicativo_SoapFaultPdD();
  142.     }
  143.    
  144.    
  145.    
  146.    
  147.    
  148.    
  149.     /* *********** INTEGRAZIONE ******************* */
  150.    
  151.     @Override
  152.     public Map<String, String> buildIntegrationProperties(Busta busta,
  153.             boolean isRichiesta, TipoIntegrazione tipoIntegrazione)
  154.             throws ProtocolException {
  155.        
  156.         if(busta==null){
  157.             return null;
  158.         }
  159.        
  160.         boolean buildInfo = false;
  161.        
  162.         if(busta!=null && busta.sizeProperties()>0){
  163.             busta.removeProperty(SDICostanti.SDI_BUSTA_EXT_ESITO_COMMITTENTE);
  164.             busta.removeProperty(SDICostanti.SDI_BUSTA_EXT_ERRORI);
  165.         }
  166.        
  167.         if(isRichiesta){
  168.            
  169.             // Servizio
  170.             if(SDICostantiServizioTrasmissioneFatture.TRASMISSIONE_SERVIZIO_TRASMISSIONE_FATTURE.equals(busta.getServizio())){
  171.                 if(SDICostantiServizioTrasmissioneFatture.TRASMISSIONE_SERVIZIO_TRASMISSIONE_FATTURE_AZIONE_RICEVUTA_CONSEGNA.equals(busta.getAzione())){
  172.                     buildInfo = true;
  173.                 }
  174.                 else if(SDICostantiServizioTrasmissioneFatture.TRASMISSIONE_SERVIZIO_TRASMISSIONE_FATTURE_AZIONE_NOTIFICA_MANCATA_CONSEGNA.equals(busta.getAzione())){
  175.                     buildInfo = true;
  176.                 }
  177.                 else if(SDICostantiServizioTrasmissioneFatture.TRASMISSIONE_SERVIZIO_TRASMISSIONE_FATTURE_AZIONE_NOTIFICA_SCARTO.equals(busta.getAzione())){
  178.                     buildInfo = true;
  179.                 }
  180.                 else if(SDICostantiServizioTrasmissioneFatture.TRASMISSIONE_SERVIZIO_TRASMISSIONE_FATTURE_AZIONE_NOTIFICA_ESITO.equals(busta.getAzione())){
  181.                     buildInfo = true;
  182.                 }
  183.                 else if(SDICostantiServizioTrasmissioneFatture.TRASMISSIONE_SERVIZIO_TRASMISSIONE_FATTURE_AZIONE_NOTIFICA_DECORRENZA_TERMINI.equals(busta.getAzione())){
  184.                     buildInfo = true;
  185.                 }
  186.                 else if(SDICostantiServizioTrasmissioneFatture.TRASMISSIONE_SERVIZIO_TRASMISSIONE_FATTURE_AZIONE_ATTESTAZIONE_TRASMISSIONE_FATTURA.equals(busta.getAzione())){
  187.                     buildInfo = true;
  188.                 }
  189.                 else{
  190.                     throw new ProtocolException("Servizio["+busta.getServizio()+"] con Azione["+busta.getAzione()+"] non gestita dal protocollo durante la fase di richiesta");
  191.                 }
  192.             }
  193.             else if(SDICostantiServizioRicezioneFatture.RICEZIONE_SERVIZIO_RICEZIONE_FATTURE.equals(busta.getServizio())){
  194.                 if(SDICostantiServizioRicezioneFatture.RICEZIONE_SERVIZIO_RICEZIONE_FATTURE_AZIONE_RICEVI_FATTURE.equals(busta.getAzione())){
  195.                     buildInfo = true;
  196.                 }
  197.                 else if(SDICostantiServizioRicezioneFatture.RICEZIONE_SERVIZIO_RICEZIONE_FATTURE_AZIONE_NOTIFICA_DECORRENZA_TERMINI.equals(busta.getAzione())){
  198.                     buildInfo = true;
  199.                 }
  200.                 else{
  201.                     throw new ProtocolException("Servizio["+busta.getServizio()+"] con Azione["+busta.getAzione()+"] non gestita dal protocollo durante la fase di richiesta");
  202.                 }
  203.             }
  204.             else if(SDICostantiServizioRiceviFile.SDI_SERVIZIO_RICEVI_FILE.equals(busta.getServizio())){
  205.                 buildInfo = false;
  206.             }
  207.             else if(SDICostantiServizioRiceviNotifica.SDI_SERVIZIO_RICEVI_NOTIFICA.equals(busta.getServizio())){
  208.                 buildInfo = false;
  209.             }
  210.             else{
  211.                 boolean whiteList = false;
  212.                 if(busta.getServizio()!=null && this.sdiProperties.getServiziWhiteList().contains(busta.getServizio())){
  213.                     if(busta.getAzione()!=null && this.sdiProperties.getAzioniWhiteList().contains(busta.getAzione())){
  214.                         this.logger.debug("Servizio ["+busta.getServizio()+"] e Azione ["+busta.getAzione()+"] in white list");
  215.                         whiteList = true;
  216.                     }
  217.                 }
  218.                 if(!whiteList){
  219.                     throw new ProtocolException("Servizio["+busta.getServizio()+"] non gestite dal protocollo durante la fase di richiesta");
  220.                 }
  221.             }
  222.            
  223.         }
  224.         else{

  225.             // Servizio
  226.             if(SDICostantiServizioRiceviFile.SDI_SERVIZIO_RICEVI_FILE.equals(busta.getServizio())
  227.                     && SDICostantiServizioRiceviFile.SDI_SERVIZIO_RICEVI_FILE_AZIONE_RICEVI_FILE.equals(busta.getAzione())){
  228.                 buildInfo = true;
  229.             }
  230.             else if(SDICostantiServizioRiceviNotifica.SDI_SERVIZIO_RICEVI_NOTIFICA.equals(busta.getServizio())
  231.                     && SDICostantiServizioRiceviNotifica.SDI_SERVIZIO_NOTIFICA_ESITO_AZIONE_NOTIFICA_ESITO.equals(busta.getAzione())){
  232.                 buildInfo = true;
  233.             }
  234.             else if(SDICostantiServizioTrasmissioneFatture.TRASMISSIONE_SERVIZIO_TRASMISSIONE_FATTURE.equals(busta.getServizio())){
  235.                 buildInfo = false;
  236.             }
  237.             else if(SDICostantiServizioRicezioneFatture.RICEZIONE_SERVIZIO_RICEZIONE_FATTURE.equals(busta.getServizio())){
  238.                 buildInfo = false;
  239.             }
  240.             else{
  241.                 boolean whiteList = false;
  242.                 if(busta.getServizio()!=null && this.sdiProperties.getServiziWhiteList().contains(busta.getServizio())){
  243.                     if(busta.getAzione()!=null && this.sdiProperties.getAzioniWhiteList().contains(busta.getAzione())){
  244.                         this.logger.debug("Servizio ["+busta.getServizio()+"] e Azione ["+busta.getAzione()+"] in white list");
  245.                         whiteList = true;
  246.                     }
  247.                 }
  248.                 if(!whiteList){
  249.                     throw new ProtocolException("Servizio["+busta.getServizio()+"] e Azione["+busta.getAzione()+"] non gestite dal protocollo durante la fase di risposta");
  250.                 }
  251.             }
  252.            
  253.         }
  254.        
  255.         if(buildInfo){
  256.             return super.buildIntegrationProperties(busta, isRichiesta, tipoIntegrazione);
  257.         }
  258.         else{
  259.             return null;
  260.         }
  261.     }
  262.    
  263.     @Override
  264.     public OpenSPCoop2Message updateOpenSPCoop2MessageResponse(OpenSPCoop2Message msg, Busta busta,
  265.             NotifierInputStreamParams notifierInputStreamParams,
  266.             TransportRequestContext transportRequestContext, TransportResponseContext transportResponseContext,
  267.             IRegistryReader registryReader,
  268.             boolean integration) throws ProtocolException{
  269.                
  270.         if(SDICostantiServizioRicezioneFatture.RICEZIONE_SERVIZIO_RICEZIONE_FATTURE.equals(busta.getServizio())){
  271.             if(SDICostantiServizioRicezioneFatture.RICEZIONE_SERVIZIO_RICEZIONE_FATTURE_AZIONE_RICEVI_FATTURE.equals(busta.getAzione())){
  272.                 if(transportResponseContext==null || transportResponseContext.getErrore()==null){
  273.                     // creo un nuovo messaggio, l'imbustamento si occupera' di creare la struttura
  274.                     OpenSPCoop2MessageFactory messageFactory = msg!=null ? msg.getFactory() : OpenSPCoop2MessageFactory.getDefaultMessageFactory();
  275.                     OpenSPCoop2Message msgR = messageFactory.createEmptyMessage(MessageType.SOAP_11,MessageRole.RESPONSE,notifierInputStreamParams);
  276.                     msgR.setTransportRequestContext(transportRequestContext);
  277.                     msgR.setTransportResponseContext(transportResponseContext);
  278.                     return msgR;
  279.                 }
  280.             }
  281.         }
  282.        
  283.         return super.updateOpenSPCoop2MessageResponse(msg, busta,
  284.                 notifierInputStreamParams,transportRequestContext,transportResponseContext,registryReader,integration);
  285.     }
  286.    
  287.    
  288.    
  289.    
  290.    
  291.     /* *********** ALTRO ******************* */
  292.    
  293.     @Override
  294.     public Integer getHttpReturnCodeEmptyResponseOneWay(){
  295.         return 202;
  296.     }
  297.    
  298. }