TrasparenteBustaBuilder.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.trasparente.builder;

  21. import java.util.Date;

  22. import org.openspcoop2.core.id.IDSoggetto;
  23. import org.openspcoop2.message.OpenSPCoop2Message;
  24. import org.openspcoop2.protocol.basic.BasicEmptyRawContent;
  25. import org.openspcoop2.protocol.basic.builder.BustaBuilder;
  26. import org.openspcoop2.protocol.sdk.Busta;
  27. import org.openspcoop2.protocol.sdk.Context;
  28. import org.openspcoop2.protocol.sdk.IProtocolFactory;
  29. import org.openspcoop2.protocol.sdk.ProtocolException;
  30. import org.openspcoop2.protocol.sdk.ProtocolMessage;
  31. import org.openspcoop2.protocol.sdk.builder.ProprietaManifestAttachments;
  32. import org.openspcoop2.protocol.sdk.constants.FaseImbustamento;
  33. import org.openspcoop2.protocol.sdk.constants.RuoloMessaggio;
  34. import org.openspcoop2.protocol.sdk.state.IState;
  35. import org.openspcoop2.protocol.trasparente.config.TrasparenteProperties;

  36. /**
  37.  * Classe che implementa, in base al protocollo Trasparente, l'interfaccia {@link org.openspcoop2.protocol.sdk.builder.IBustaBuilder}
  38.  *
  39.  * @author Poli Andrea (apoli@link.it)
  40.  * @author $Author$
  41.  * @version $Rev$, $Date$
  42.  */
  43. public class TrasparenteBustaBuilder extends BustaBuilder<BasicEmptyRawContent> {


  44.     private TrasparenteProperties trasparenteProperties;
  45.     public TrasparenteBustaBuilder(IProtocolFactory<?> factory,IState state) throws ProtocolException {
  46.         super(factory,state);
  47.         this.trasparenteProperties = TrasparenteProperties.getInstance();
  48.     }

  49.     @Override
  50.     public ProtocolMessage imbustamento(OpenSPCoop2Message msg, Context context,
  51.             Busta busta, Busta bustaRichiesta,
  52.             RuoloMessaggio ruoloMessaggio,
  53.             ProprietaManifestAttachments proprietaManifestAttachments,
  54.             FaseImbustamento faseImbustamento)
  55.             throws ProtocolException {
  56.        
  57.         if(FaseImbustamento.DOPO_SICUREZZA_MESSAGGIO.equals(faseImbustamento)) {
  58.             ProtocolMessage protocolMessage = new ProtocolMessage();
  59.             protocolMessage.setPhaseUnsupported(true);
  60.             return protocolMessage;
  61.         }
  62.        
  63.         ProtocolMessage protocolMessage = super.imbustamento(msg, context,
  64.                 busta, bustaRichiesta,
  65.                 ruoloMessaggio, proprietaManifestAttachments, faseImbustamento);
  66.                
  67.         if(RuoloMessaggio.RISPOSTA.equals(ruoloMessaggio) && busta.sizeListaEccezioni()>0 ){
  68.             // le eccezioni vengono tornate anche per gli errori di processamento poiche' in TrasparenteProtocolVersionManager
  69.             // e' stato cablato il metodo isGenerazioneListaEccezioniErroreProcessamento al valore 'true'
  70.            
  71.             // Per quanto riguarda la generazione dei codici SOAPFault personalizzati e/o la generazione dell'elemento errore-applicativo
  72.             // la scelta e' delegata a due proprieta' nel file di proprieta'.
  73.             //
  74.             // Infine la scelta della presenza o meno dell'elemento OpenSPCoop2Details lo stesso viene pilotata dalle proprieta' presenti nel file di proprieta'
  75.        
  76.             boolean ignoraEccezioniNonGravi = this.protocolFactory.createProtocolManager().isIgnoraEccezioniNonGravi();
  77.             if(ignoraEccezioniNonGravi){
  78.                 if(busta.containsEccezioniGravi() ){
  79.                     this.enrichFault(msg, busta, ignoraEccezioniNonGravi,
  80.                             this.trasparenteProperties.isPortaApplicativaBustaErrore_personalizzaElementiFault(),
  81.                             this.trasparenteProperties.isPortaApplicativaBustaErrore_aggiungiErroreApplicativo());
  82.                 }  
  83.             }
  84.             else{
  85.                 this.enrichFault(msg, busta, ignoraEccezioniNonGravi,
  86.                         this.trasparenteProperties.isPortaApplicativaBustaErrore_personalizzaElementiFault(),
  87.                         this.trasparenteProperties.isPortaApplicativaBustaErrore_aggiungiErroreApplicativo());
  88.             }

  89.         }
  90.            
  91.         return protocolMessage;
  92.     }
  93.    
  94.    
  95.     @Override
  96.     public String newID(IDSoggetto idSoggetto, String idTransazione, RuoloMessaggio ruoloMessaggio) throws ProtocolException {
  97.         return super.newID( idSoggetto, idTransazione, ruoloMessaggio, this.trasparenteProperties.generateIDasUUID());
  98.     }
  99.    
  100.    
  101.     @Override
  102.     public Date extractDateFromID(String id) throws ProtocolException {
  103.         return extractDateFromID(id, this.trasparenteProperties.generateIDasUUID());
  104.        
  105.     }
  106.    
  107. }