SPCoopBustaBuilder.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.spcoop.builder;

  21. import java.text.SimpleDateFormat;
  22. import java.util.Date;

  23. import javax.xml.soap.SOAPHeaderElement;

  24. import org.openspcoop2.core.id.IDSoggetto;
  25. import org.openspcoop2.message.OpenSPCoop2Message;
  26. import org.openspcoop2.message.config.ServiceBindingConfiguration;
  27. import org.openspcoop2.message.constants.ServiceBinding;
  28. import org.openspcoop2.protocol.basic.BasicStateComponentFactory;
  29. import org.openspcoop2.protocol.sdk.Busta;
  30. import org.openspcoop2.protocol.sdk.Context;
  31. import org.openspcoop2.protocol.sdk.IProtocolFactory;
  32. import org.openspcoop2.protocol.sdk.ProtocolException;
  33. import org.openspcoop2.protocol.sdk.ProtocolMessage;
  34. import org.openspcoop2.protocol.sdk.Trasmissione;
  35. import org.openspcoop2.protocol.sdk.builder.ProprietaManifestAttachments;
  36. import org.openspcoop2.protocol.sdk.constants.FaseImbustamento;
  37. import org.openspcoop2.protocol.sdk.constants.FaseSbustamento;
  38. import org.openspcoop2.protocol.sdk.constants.RuoloMessaggio;
  39. import org.openspcoop2.protocol.sdk.state.IState;
  40. import org.openspcoop2.protocol.spcoop.SPCoopBustaRawContent;
  41. import org.openspcoop2.utils.date.DateUtils;

  42. /**
  43.  * Classe che implementa, in base al protocollo SPCoop, l'interfaccia {@link org.openspcoop2.protocol.sdk.builder.IBustaBuilder}
  44.  *
  45.  * @author Poli Andrea (apoli@link.it)
  46.  * @author $Author$
  47.  * @version $Rev$, $Date$
  48.  */
  49. public class SPCoopBustaBuilder extends BasicStateComponentFactory implements org.openspcoop2.protocol.sdk.builder.IBustaBuilder<SOAPHeaderElement> {

  50.     private SPCoopImbustamento spcoopImbustamento = null;
  51.     private SPCoopSbustamento spcoopSbustamento = null;
  52.    
  53.     public SPCoopBustaBuilder(IProtocolFactory<SOAPHeaderElement> factory, IState state) throws ProtocolException{
  54.         super(factory,state);
  55.         this.spcoopImbustamento = new SPCoopImbustamento(factory, this.state);
  56.         this.spcoopSbustamento = new SPCoopSbustamento(factory, this.state);
  57.         this.log = factory.getLogger();
  58.     }
  59.    

  60.     @Override
  61.     public String newID(IDSoggetto idSoggetto, String idTransazione,
  62.             RuoloMessaggio ruoloMessaggio)
  63.             throws ProtocolException {
  64.         return this.spcoopImbustamento.buildID(idSoggetto, idTransazione, ruoloMessaggio);
  65.     }

  66.     @Override
  67.     public Date extractDateFromID(String id) throws ProtocolException {
  68.         try{
  69.            
  70.             // es. MinisteroErogatore_MinisteroErogatoreSPCoopIT_0000215_2011-08-04_09:43
  71.            
  72.             if(id==null){
  73.                 return null;
  74.             }
  75.             String [] split = id.split("_");
  76.             if(split.length!=5){
  77.                 return null;
  78.             }
  79.            
  80.             SimpleDateFormat dateformat = DateUtils.getSimpleDateFormatMinute();
  81.             String tmp = split[3]+"_"+split[4];
  82.             Date d = dateformat.parse(tmp);
  83.             return d;
  84.            
  85.         }catch(Exception e){
  86.             throw new ProtocolException("Errore durante l'estrazione della data dall'identificativo ["+id+"]: "+ e.getMessage(),e);
  87.         }
  88.     }
  89.    
  90.     @Override
  91.     public ProtocolMessage imbustamento(OpenSPCoop2Message msg, Context context,
  92.             Busta busta, Busta bustaRichiesta,
  93.             RuoloMessaggio ruoloMessaggio,
  94.             ProprietaManifestAttachments proprietaManifestAttachments,
  95.             FaseImbustamento faseImbustamento)
  96.             throws ProtocolException {
  97.        
  98.         if(FaseImbustamento.DOPO_SICUREZZA_MESSAGGIO.equals(faseImbustamento)) {
  99.             ProtocolMessage protocolMessage = new ProtocolMessage();
  100.             protocolMessage.setPhaseUnsupported(true);
  101.             return protocolMessage;
  102.         }
  103.        
  104.         SOAPHeaderElement element =  this.spcoopImbustamento.imbustamento(msg, busta,
  105.                 ruoloMessaggio,
  106.                 proprietaManifestAttachments);
  107.         ProtocolMessage protocolMessage = new ProtocolMessage();
  108.         protocolMessage.setBustaRawContent(new SPCoopBustaRawContent(element));
  109.         protocolMessage.setMessage(msg);
  110.         return protocolMessage;
  111.     }

  112.     @Override
  113.     public ProtocolMessage addTrasmissione(OpenSPCoop2Message message,
  114.             Trasmissione trasmissione,
  115.             FaseImbustamento faseImbustamento) throws ProtocolException {
  116.        
  117.         if(FaseImbustamento.DOPO_SICUREZZA_MESSAGGIO.equals(faseImbustamento)) {
  118.             ProtocolMessage protocolMessage = new ProtocolMessage();
  119.             protocolMessage.setPhaseUnsupported(true);
  120.             return protocolMessage;
  121.         }
  122.        
  123.         SOAPHeaderElement element =  this.spcoopImbustamento.addTrasmissione(message, trasmissione);
  124.         ProtocolMessage protocolMessage = new ProtocolMessage();
  125.         protocolMessage.setBustaRawContent(new SPCoopBustaRawContent(element));
  126.         protocolMessage.setMessage(message);
  127.         return protocolMessage;
  128.     }

  129.     @Override
  130.     public ProtocolMessage sbustamento(OpenSPCoop2Message msg, Context context,
  131.             Busta busta,
  132.             RuoloMessaggio ruoloMessaggio, ProprietaManifestAttachments proprietaManifestAttachments,
  133.             FaseSbustamento faseSbustamento, ServiceBinding integrationServiceBinding, ServiceBindingConfiguration serviceBindingConfiguration) throws ProtocolException {
  134.        
  135.         ProtocolMessage protocolMessage = new ProtocolMessage();
  136.         protocolMessage.setMessage(msg);
  137.        
  138.         if(FaseSbustamento.POST_VALIDAZIONE_SEMANTICA_RICHIESTA.equals(faseSbustamento) == false &&
  139.                 FaseSbustamento.POST_VALIDAZIONE_SEMANTICA_RISPOSTA.equals(faseSbustamento) == false){
  140.            
  141.             // Lo sbustamento effettivo in spcoop viene ritardato fino alla consegna del servizio applicativo
  142.             // il servizio applicativo può richiederlo di non effettuarlo
  143.             SOAPHeaderElement element =  this.spcoopSbustamento.sbustamento(msg, proprietaManifestAttachments);
  144.             protocolMessage.setBustaRawContent(new SPCoopBustaRawContent(element));
  145.             protocolMessage.setMessage(msg);
  146.         }
  147.        
  148.         protocolMessage.setUseBustaRawContentReadByValidation(true);
  149.         return protocolMessage;
  150.     }

  151. }