OpenSPCoopStateless.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.pdd.core.state;

  21. import java.io.Serializable;

  22. import org.openspcoop2.message.OpenSPCoop2Message;
  23. import org.openspcoop2.pdd.core.DimensioneMessaggiAttraversamentoPdD;
  24. import org.openspcoop2.pdd.core.PdDContext;
  25. import org.openspcoop2.pdd.core.TempiAttraversamentoPDD;
  26. import org.openspcoop2.protocol.sdk.Busta;
  27. import org.openspcoop2.protocol.sdk.state.StateMap;
  28. import org.openspcoop2.protocol.sdk.state.StatelessMessage;
  29. import org.openspcoop2.utils.UtilsException;

  30. /**
  31.  * Oggetto che rappresenta lo stato di una richiesta/risposta all'interno della PdD
  32.  *
  33.  * @author Poli Andrea (apoli@link.it)
  34.  * @author Fabio Tronci (tronci@link.it)
  35.  * @author $Author$
  36.  * @version $Rev$, $Date$
  37.  */
  38. public class OpenSPCoopStateless extends OpenSPCoopState implements Serializable {

  39.     /**
  40.      *
  41.      */
  42.     private static final long serialVersionUID = 1L;
  43.    
  44.     /* ---------- Messaggi  ----------*/
  45.     private OpenSPCoop2Message richiestaMsg = null;
  46.     private OpenSPCoop2Message rispostaMsg = null;
  47.    
  48.     /* ---------- Contiene i proprietari dei messaggi  ----------*/
  49.     private String destinatarioRequestMsgLib;
  50.     private String destinatarioResponseMsgLib;
  51.    
  52.     /* ---------- Contiene i tempi di attraversamento  ----------*/
  53.     private TempiAttraversamentoPDD tempiAttraversamentoPDD = null;
  54.    
  55.     /* ---------- Contiene la dimensione dei messaggi  ----------*/
  56.     private DimensioneMessaggiAttraversamentoPdD dimensioneMessaggiAttraversamentoPDD = null;

  57.     /* ---------- ID di Correlazione Applicativa ------------ */
  58.     private String idCorrelazioneApplicativa = null;
  59.     private String idCorrelazioneApplicativaRisposta = null;

  60.     /* ---------- PdDContext -------------*/
  61.     private PdDContext pddContext = null;
  62.    
  63.    
  64.    
  65.    
  66.     /* ---------- Costruttori  ----------*/
  67.     public OpenSPCoopStateless(StatelessMessage richiesta,OpenSPCoop2Message richiestaMsg,
  68.             StatelessMessage risposta,OpenSPCoop2Message rispostaMsg){
  69.         this.richiestaStato = richiesta;
  70.         this.richiestaMsg = richiestaMsg;
  71.         this.rispostaStato = risposta;
  72.         this.rispostaMsg = rispostaMsg;
  73.         this.useConnection = false;
  74.         this.tempiAttraversamentoPDD = new TempiAttraversamentoPDD();
  75.         this.dimensioneMessaggiAttraversamentoPDD = new DimensioneMessaggiAttraversamentoPdD();
  76.     }
  77.    
  78.     public OpenSPCoopStateless(StatelessMessage richiesta,OpenSPCoop2Message richiestaMsg){
  79.         this.richiestaStato = richiesta;
  80.         this.richiestaMsg = richiestaMsg;
  81.         this.useConnection = false;
  82.         this.tempiAttraversamentoPDD = new TempiAttraversamentoPDD();
  83.         this.dimensioneMessaggiAttraversamentoPDD = new DimensioneMessaggiAttraversamentoPdD();
  84.     }
  85.    
  86.     public OpenSPCoopStateless(){
  87.         this.useConnection = false;
  88.         this.tempiAttraversamentoPDD = new TempiAttraversamentoPDD();
  89.         this.dimensioneMessaggiAttraversamentoPDD = new DimensioneMessaggiAttraversamentoPdD();
  90.     }

  91.    
  92.    
  93.    
  94.    
  95.    
  96.     /* ----------- Init resource ------------*/
  97.     @Override
  98.     public void updateStatoRichiesta() throws UtilsException{
  99.        
  100.         StateMap pstmt = null;
  101.         Busta bustaTmp = null;
  102.         Busta bustaCorrelataTmp = null;
  103.         if(this.richiestaStato!=null){
  104.             if(this.richiestaStato.getPreparedStatement()!=null)
  105.                 pstmt = this.richiestaStato.getPreparedStatement();
  106.             StatelessMessage statelessMessage = (StatelessMessage) this.richiestaStato;
  107.             bustaTmp = statelessMessage.getBusta();
  108.             bustaCorrelataTmp = statelessMessage.getBustaCorrelata();
  109.         }
  110.        
  111.         this.richiestaStato = new StatelessMessage(this.connectionDB,this.logger);
  112.         if(pstmt!=null){
  113.             this.richiestaStato.addPreparedStatement(pstmt.getPreparedStatement());
  114.         }
  115.         if(bustaTmp!=null){
  116.             ((StatelessMessage) this.richiestaStato).setBusta(bustaTmp);
  117.         }
  118.         if(bustaCorrelataTmp!=null){
  119.             ((StatelessMessage) this.richiestaStato).setBustaCorrelata(bustaCorrelataTmp);
  120.         }
  121.        
  122.     }
  123.     @Override
  124.     public void updateStatoRisposta() throws UtilsException{
  125.        
  126.         StateMap pstmt = null;
  127.         Busta bustaTmp = null;
  128.         Busta bustaCorrelataTmp = null;
  129.         if(this.rispostaStato!=null){
  130.             if(this.rispostaStato.getPreparedStatement()!=null)
  131.                 pstmt = this.rispostaStato.getPreparedStatement();
  132.             StatelessMessage statelessMessage = (StatelessMessage) this.rispostaStato;
  133.             bustaTmp = statelessMessage.getBusta();
  134.             bustaCorrelataTmp = statelessMessage.getBustaCorrelata();
  135.         }
  136.        
  137.         this.rispostaStato = new StatelessMessage(this.connectionDB,this.logger);
  138.         if(pstmt!=null){
  139.             this.rispostaStato.addPreparedStatement(pstmt.getPreparedStatement());
  140.         }
  141.         if(bustaTmp!=null){
  142.             ((StatelessMessage) this.rispostaStato).setBusta(bustaTmp);
  143.         }
  144.         if(bustaCorrelataTmp!=null){
  145.             ((StatelessMessage) this.rispostaStato).setBustaCorrelata(bustaCorrelataTmp);
  146.         }

  147.     }
  148.    
  149.    
  150.    
  151.    

  152.    
  153.    

  154.    
  155.    
  156.    
  157.    
  158.     /* ----------- Serializzazione ------------*/

  159.     public OpenSPCoopStateless rendiSerializzabile() {
  160.         OpenSPCoopStateless stato = new OpenSPCoopStateless();
  161.         StatelessMessage statoRichiesta = new StatelessMessage(null, null);
  162.         StatelessMessage statoRisposta = new StatelessMessage(null, null);
  163.         statoRichiesta.setBusta(((StatelessMessage)this.richiestaStato).getBusta());
  164.         statoRisposta.setBusta(((StatelessMessage)this.rispostaStato).getBusta());
  165.         stato.setStatoRichiesta(statoRichiesta);
  166.         stato.setStatoRisposta(statoRisposta);
  167.         stato.setTempiAttraversamentoPDD(this.getTempiAttraversamentoPDD());
  168.         stato.setDimensioneMessaggiAttraversamentoPDD(this.getDimensioneMessaggiAttraversamentoPDD());
  169.         return stato;
  170.     }
  171.    
  172.    
  173.    
  174.    
  175.    
  176.    
  177.    
  178.    
  179.     /* ----------- GET / SET ------------*/
  180.    
  181.     public void setDestinatarioRequestMsgLib(String nextLib) {
  182.         this.destinatarioRequestMsgLib = nextLib;
  183.     }

  184.     public String getDestinatarioRequestMsgLib(){
  185.         return this.destinatarioRequestMsgLib;
  186.     }

  187.     public String getDestinatarioResponseMsgLib() {
  188.         return this.destinatarioResponseMsgLib;
  189.     }

  190.     public void setDestinatarioResponseMsgLib(String destinatarioResponseMsgLib) {
  191.         this.destinatarioResponseMsgLib = destinatarioResponseMsgLib;
  192.     }
  193.    
  194.     public void setRichiestaMsg(OpenSPCoop2Message richiestaMsg) {
  195.         this.richiestaMsg = richiestaMsg;
  196.     }
  197.    
  198.     public OpenSPCoop2Message getRichiestaMsg() {
  199.         return this.richiestaMsg;
  200.     }

  201.     public void setRispostaMsg(OpenSPCoop2Message rispostaMsg) {
  202.         this.rispostaMsg = rispostaMsg;
  203.     }
  204.    
  205.     public OpenSPCoop2Message getRispostaMsg() {
  206.         return this.rispostaMsg;
  207.     }
  208.    
  209.     public TempiAttraversamentoPDD getTempiAttraversamentoPDD() {
  210.         return this.tempiAttraversamentoPDD;
  211.     }
  212.    
  213.     public void setTempiAttraversamentoPDD(TempiAttraversamentoPDD tempiAttraversamentoPDD) {
  214.         this.tempiAttraversamentoPDD = tempiAttraversamentoPDD;
  215.     }
  216.    
  217.     public DimensioneMessaggiAttraversamentoPdD getDimensioneMessaggiAttraversamentoPDD() {
  218.         return this.dimensioneMessaggiAttraversamentoPDD;
  219.     }

  220.     public void setDimensioneMessaggiAttraversamentoPDD(
  221.             DimensioneMessaggiAttraversamentoPdD dimensioneMessaggiAttraversamentoPDD) {
  222.         this.dimensioneMessaggiAttraversamentoPDD = dimensioneMessaggiAttraversamentoPDD;
  223.     }
  224.    
  225.     public String getIDCorrelazioneApplicativa() {
  226.         return this.idCorrelazioneApplicativa;
  227.     }

  228.     public void setIDCorrelazioneApplicativa(String idCorrelazioneApplicativa) {
  229.         this.idCorrelazioneApplicativa = idCorrelazioneApplicativa;
  230.     }

  231.     public PdDContext getPddContext() {
  232.         return this.pddContext;
  233.     }

  234.     public void setPddContext(PdDContext pddContext) {
  235.         this.pddContext = pddContext;
  236.     }

  237.     public String getIDCorrelazioneApplicativaRisposta() {
  238.         return this.idCorrelazioneApplicativaRisposta;
  239.     }

  240.     public void setIDCorrelazioneApplicativaRisposta(
  241.             String idCorrelazioneApplicativaRisposta) {
  242.         this.idCorrelazioneApplicativaRisposta = idCorrelazioneApplicativaRisposta;
  243.     }

  244. }