Trasmissione.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.sdk;

  21. import java.util.Date;

  22. import org.openspcoop2.core.tracciamento.Data;
  23. import org.openspcoop2.core.tracciamento.Soggetto;
  24. import org.openspcoop2.core.tracciamento.SoggettoIdentificativo;
  25. import org.openspcoop2.core.tracciamento.TipoData;
  26. import org.openspcoop2.core.tracciamento.constants.TipoTempo;
  27. import org.openspcoop2.protocol.sdk.constants.TipoOraRegistrazione;
  28. import org.openspcoop2.utils.date.DateManager;


  29. /**
  30.  * Classe utilizzata per rappresentare una Trasmissione.
  31.  *
  32.  *
  33.  * @author Poli Andrea (apoli@link.it)
  34.  * @author Nardi Lorenzo
  35.  * @author $Author$
  36.  * @version $Rev$, $Date$
  37.  */


  38. public class Trasmissione implements java.io.Serializable{

  39.     /**
  40.      * serialVersionUID
  41.      */
  42.     private static final long serialVersionUID = 1L;

  43.     private org.openspcoop2.core.tracciamento.Trasmissione trasmissione;

  44.        
  45.     public Trasmissione() {
  46.         this.trasmissione = new org.openspcoop2.core.tracciamento.Trasmissione();
  47.     }
  48.    
  49.     public Trasmissione(org.openspcoop2.core.tracciamento.Trasmissione trasmissione){
  50.         this.trasmissione = trasmissione;
  51.     }


  52.     // base

  53.     public org.openspcoop2.core.tracciamento.Trasmissione getTrasmissione() {
  54.         return this.trasmissione;
  55.     }
  56.     public void setTrasmissione(org.openspcoop2.core.tracciamento.Trasmissione trasmissione) {
  57.         this.trasmissione = trasmissione;
  58.     }



  59.     // id  [Wrapper]

  60.     public Long getId() {
  61.         return this.trasmissione.getId();
  62.     }
  63.     public void setId(Long id) {
  64.         this.trasmissione.setId(id);
  65.     }
  66.    
  67.    
  68.    
  69.    

  70.     // mittente [wrapper]
  71.    
  72.     public String getOrigine() {
  73.         if(this.trasmissione.getOrigine()!=null && this.trasmissione.getOrigine().getIdentificativo()!=null)
  74.             return this.trasmissione.getOrigine().getIdentificativo().getBase();
  75.         else
  76.             return null;
  77.     }
  78.     public void setOrigine(String value) {
  79.         if(value!=null){
  80.             if(this.trasmissione.getOrigine()==null){
  81.                 this.trasmissione.setOrigine(new Soggetto());
  82.             }
  83.             if(this.trasmissione.getOrigine().getIdentificativo()==null){
  84.                 this.trasmissione.getOrigine().setIdentificativo(new SoggettoIdentificativo());
  85.             }
  86.             this.trasmissione.getOrigine().getIdentificativo().setBase(value);
  87.         }
  88.         else{
  89.             if(this.trasmissione.getOrigine()!=null){
  90.                 if(this.trasmissione.getOrigine().getIdentificativo()!=null){
  91.                     if(this.trasmissione.getOrigine().getIdentificativo().getTipo()==null){
  92.                         this.trasmissione.getOrigine().setIdentificativo(null);
  93.                     }
  94.                     else{
  95.                         this.trasmissione.getOrigine().getIdentificativo().setBase(null);
  96.                     }  
  97.                 }
  98.                 if(this.trasmissione.getOrigine().getIdentificativo()==null &&
  99.                         this.trasmissione.getOrigine().getIdentificativoPorta()==null &&
  100.                         this.trasmissione.getOrigine().getIndirizzo()==null){
  101.                     this.trasmissione.setOrigine(null);
  102.                 }
  103.             }
  104.         }
  105.     }
  106.    
  107.     public String getTipoOrigine() {
  108.         if(this.trasmissione.getOrigine()!=null && this.trasmissione.getOrigine().getIdentificativo()!=null)
  109.             return this.trasmissione.getOrigine().getIdentificativo().getTipo();
  110.         else
  111.             return null;
  112.     }
  113.     public void setTipoOrigine(String value) {
  114.         if(value!=null){
  115.             if(this.trasmissione.getOrigine()==null){
  116.                 this.trasmissione.setOrigine(new Soggetto());
  117.             }
  118.             if(this.trasmissione.getOrigine().getIdentificativo()==null){
  119.                 this.trasmissione.getOrigine().setIdentificativo(new SoggettoIdentificativo());
  120.             }
  121.             this.trasmissione.getOrigine().getIdentificativo().setTipo(value);
  122.         }
  123.         else{
  124.             if(this.trasmissione.getOrigine()!=null){
  125.                 if(this.trasmissione.getOrigine().getIdentificativo()!=null){
  126.                     if(this.trasmissione.getOrigine().getIdentificativo().getBase()==null){
  127.                         this.trasmissione.getOrigine().setIdentificativo(null);
  128.                     }
  129.                     else{
  130.                         this.trasmissione.getOrigine().getIdentificativo().setTipo(null);
  131.                     }  
  132.                 }
  133.                 if(this.trasmissione.getOrigine().getIdentificativo()==null &&
  134.                         this.trasmissione.getOrigine().getIdentificativoPorta()==null &&
  135.                         this.trasmissione.getOrigine().getIndirizzo()==null){
  136.                     this.trasmissione.setOrigine(null);
  137.                 }
  138.             }
  139.         }
  140.     }
  141.    
  142.     public String getIdentificativoPortaOrigine() {
  143.         if(this.trasmissione.getOrigine()!=null)
  144.             return this.trasmissione.getOrigine().getIdentificativoPorta();
  145.         else
  146.             return null;
  147.     }
  148.     public void setIdentificativoPortaOrigine(String identificativoPortaOrigine) {
  149.         if(identificativoPortaOrigine!=null){
  150.             if(this.trasmissione.getOrigine()==null){
  151.                 this.trasmissione.setOrigine(new Soggetto());
  152.             }
  153.             this.trasmissione.getOrigine().setIdentificativoPorta(identificativoPortaOrigine);
  154.         }
  155.         else{
  156.             if(this.trasmissione.getOrigine()!=null){
  157.                 this.trasmissione.getOrigine().setIdentificativoPorta(null);
  158.                 if(this.trasmissione.getOrigine().getIdentificativo()==null &&
  159.                         this.trasmissione.getOrigine().getIdentificativoPorta()==null &&
  160.                         this.trasmissione.getOrigine().getIndirizzo()==null){
  161.                     this.trasmissione.setOrigine(null);
  162.                 }
  163.             }
  164.         }
  165.     }
  166.    
  167.     public String getIndirizzoOrigine() {
  168.         if(this.trasmissione.getOrigine()!=null)
  169.             return this.trasmissione.getOrigine().getIndirizzo();
  170.         else
  171.             return null;
  172.     }
  173.     public void setIndirizzoOrigine(String value) {
  174.         if(value!=null){
  175.             if(this.trasmissione.getOrigine()==null){
  176.                 this.trasmissione.setOrigine(new Soggetto());
  177.             }
  178.             this.trasmissione.getOrigine().setIndirizzo(value);
  179.         }
  180.         else{
  181.             if(this.trasmissione.getOrigine()!=null){
  182.                 this.trasmissione.getOrigine().setIndirizzo(null);
  183.                 if(this.trasmissione.getOrigine().getIdentificativo()==null &&
  184.                         this.trasmissione.getOrigine().getIdentificativoPorta()==null &&
  185.                         this.trasmissione.getOrigine().getIndirizzo()==null){
  186.                     this.trasmissione.setOrigine(null);
  187.                 }
  188.             }
  189.         }
  190.     }
  191.    
  192.    
  193.    
  194.     // destinatario [wrapper]
  195.    
  196.     public String getDestinazione() {
  197.         if(this.trasmissione.getDestinazione()!=null && this.trasmissione.getDestinazione().getIdentificativo()!=null)
  198.             return this.trasmissione.getDestinazione().getIdentificativo().getBase();
  199.         else
  200.             return null;
  201.     }
  202.     public void setDestinazione(String value) {
  203.         if(value!=null){
  204.             if(this.trasmissione.getDestinazione()==null){
  205.                 this.trasmissione.setDestinazione(new Soggetto());
  206.             }
  207.             if(this.trasmissione.getDestinazione().getIdentificativo()==null){
  208.                 this.trasmissione.getDestinazione().setIdentificativo(new SoggettoIdentificativo());
  209.             }
  210.             this.trasmissione.getDestinazione().getIdentificativo().setBase(value);
  211.         }
  212.         else{
  213.             if(this.trasmissione.getDestinazione()!=null){
  214.                 if(this.trasmissione.getDestinazione().getIdentificativo()!=null){
  215.                     if(this.trasmissione.getDestinazione().getIdentificativo().getTipo()==null){
  216.                         this.trasmissione.getDestinazione().setIdentificativo(null);
  217.                     }
  218.                     else{
  219.                         this.trasmissione.getDestinazione().getIdentificativo().setBase(null);
  220.                     }
  221.                 }
  222.                 if(this.trasmissione.getDestinazione().getIdentificativo()==null &&
  223.                         this.trasmissione.getDestinazione().getIdentificativoPorta()==null &&
  224.                         this.trasmissione.getDestinazione().getIndirizzo()==null){
  225.                     this.trasmissione.setDestinazione(null);
  226.                 }
  227.             }
  228.         }
  229.     }
  230.    
  231.     public String getTipoDestinazione() {
  232.         if(this.trasmissione.getDestinazione()!=null && this.trasmissione.getDestinazione().getIdentificativo()!=null)
  233.             return this.trasmissione.getDestinazione().getIdentificativo().getTipo();
  234.         else
  235.             return null;
  236.     }
  237.     public void setTipoDestinazione(String value) {
  238.         if(value!=null){
  239.             if(this.trasmissione.getDestinazione()==null){
  240.                 this.trasmissione.setDestinazione(new Soggetto());
  241.             }
  242.             if(this.trasmissione.getDestinazione().getIdentificativo()==null){
  243.                 this.trasmissione.getDestinazione().setIdentificativo(new SoggettoIdentificativo());
  244.             }
  245.             this.trasmissione.getDestinazione().getIdentificativo().setTipo(value);
  246.         }
  247.         else{
  248.             if(this.trasmissione.getDestinazione()!=null){
  249.                 if(this.trasmissione.getDestinazione().getIdentificativo()!=null){
  250.                     if(this.trasmissione.getDestinazione().getIdentificativo().getBase()==null){
  251.                         this.trasmissione.getDestinazione().setIdentificativo(null);
  252.                     }
  253.                     else{
  254.                         this.trasmissione.getDestinazione().getIdentificativo().setTipo(null);
  255.                     }
  256.                 }
  257.                 if(this.trasmissione.getDestinazione().getIdentificativo()==null &&
  258.                         this.trasmissione.getDestinazione().getIdentificativoPorta()==null &&
  259.                         this.trasmissione.getDestinazione().getIndirizzo()==null){
  260.                     this.trasmissione.setDestinazione(null);
  261.                 }
  262.             }
  263.         }
  264.     }
  265.    
  266.     public String getIdentificativoPortaDestinazione() {
  267.         if(this.trasmissione.getDestinazione()!=null)
  268.             return this.trasmissione.getDestinazione().getIdentificativoPorta();
  269.         else
  270.             return null;
  271.     }
  272.     public void setIdentificativoPortaDestinazione(String identificativoPortaDestinazione) {
  273.         if(identificativoPortaDestinazione!=null){
  274.             if(this.trasmissione.getDestinazione()==null){
  275.                 this.trasmissione.setDestinazione(new Soggetto());
  276.             }
  277.             this.trasmissione.getDestinazione().setIdentificativoPorta(identificativoPortaDestinazione);
  278.         }
  279.         else{
  280.             if(this.trasmissione.getDestinazione()!=null){
  281.                 this.trasmissione.getDestinazione().setIdentificativoPorta(null);
  282.                 if(this.trasmissione.getDestinazione().getIdentificativo()==null &&
  283.                         this.trasmissione.getDestinazione().getIdentificativoPorta()==null &&
  284.                         this.trasmissione.getDestinazione().getIndirizzo()==null){
  285.                     this.trasmissione.setDestinazione(null);
  286.                 }
  287.             }
  288.         }
  289.     }
  290.    
  291.     public String getIndirizzoDestinazione() {
  292.         if(this.trasmissione.getDestinazione()!=null)
  293.             return this.trasmissione.getDestinazione().getIndirizzo();
  294.         else
  295.             return null;
  296.     }
  297.     public void setIndirizzoDestinazione(String value) {
  298.         if(value!=null){
  299.             if(this.trasmissione.getDestinazione()==null){
  300.                 this.trasmissione.setDestinazione(new Soggetto());
  301.             }
  302.             this.trasmissione.getDestinazione().setIndirizzo(value);
  303.         }
  304.         else{
  305.             if(this.trasmissione.getDestinazione()!=null){
  306.                 this.trasmissione.getDestinazione().setIndirizzo(null);
  307.                 if(this.trasmissione.getDestinazione().getIdentificativo()==null &&
  308.                         this.trasmissione.getDestinazione().getIdentificativoPorta()==null &&
  309.                         this.trasmissione.getDestinazione().getIndirizzo()==null){
  310.                     this.trasmissione.setDestinazione(null);
  311.                 }
  312.             }
  313.         }
  314.     }
  315.    
  316.      
  317.  
  318.    
  319.     // date
  320.    
  321.     public TipoOraRegistrazione getTempo() {
  322.         if(this.trasmissione.getOraRegistrazione()!=null &&
  323.                 this.trasmissione.getOraRegistrazione().getSorgente()!=null &&
  324.                 this.trasmissione.getOraRegistrazione().getSorgente().getTipo()!=null){
  325.             switch (this.trasmissione.getOraRegistrazione().getSorgente().getTipo()) {
  326.             case LOCALE:
  327.                 return TipoOraRegistrazione.LOCALE;
  328.             case SINCRONIZZATO:
  329.                 return TipoOraRegistrazione.SINCRONIZZATO;
  330.             case SCONOSCIUTO:
  331.                 return TipoOraRegistrazione.UNKNOWN;
  332.             }
  333.         }
  334.         return null;
  335.     }
  336.     public void setTempo(TipoOraRegistrazione tipoOraRegistrazione) {
  337.         if(tipoOraRegistrazione!=null){
  338.             if(this.trasmissione.getOraRegistrazione()==null){
  339.                 this.trasmissione.setOraRegistrazione(new Data());
  340.             }
  341.             if(this.trasmissione.getOraRegistrazione().getSorgente()==null){
  342.                 this.trasmissione.getOraRegistrazione().setSorgente(new TipoData());
  343.             }
  344.             switch (tipoOraRegistrazione) {
  345.             case LOCALE:
  346.                 this.trasmissione.getOraRegistrazione().getSorgente().setTipo(TipoTempo.LOCALE);
  347.                 break;
  348.             case SINCRONIZZATO:
  349.                 this.trasmissione.getOraRegistrazione().getSorgente().setTipo(TipoTempo.SINCRONIZZATO);
  350.                 break;
  351.             case UNKNOWN:
  352.                 this.trasmissione.getOraRegistrazione().getSorgente().setTipo(TipoTempo.SCONOSCIUTO);
  353.                 break;
  354.             }
  355.         }
  356.         else {
  357.             if(this.trasmissione.getOraRegistrazione()!=null){
  358.                 if(this.trasmissione.getOraRegistrazione().getSorgente()!=null){
  359.                     if(this.trasmissione.getOraRegistrazione().getSorgente().getBase()==null){
  360.                         this.trasmissione.getOraRegistrazione().setSorgente(null);
  361.                     }
  362.                     else{
  363.                         this.trasmissione.getOraRegistrazione().getSorgente().setTipo(null);
  364.                     }  
  365.                 }
  366.                 if(this.trasmissione.getOraRegistrazione().getSorgente()==null && this.trasmissione.getOraRegistrazione().getDateTime()==null){
  367.                     this.trasmissione.setOraRegistrazione(null);
  368.                 }
  369.             }
  370.         }
  371.     }

  372.     public void setTempo(TipoOraRegistrazione tipo, String value) {
  373.         this.setTempo(tipo);
  374.         this.setTempoValue(value);
  375.     }

  376.     public String getTempoValue(IProtocolFactory<?> protocolFactory) throws ProtocolException {
  377.         String tipoOraRegistrazioneValue = null;
  378.         if(this.trasmissione.getOraRegistrazione()!=null && this.trasmissione.getOraRegistrazione().getSorgente()!=null){
  379.             tipoOraRegistrazioneValue = this.trasmissione.getOraRegistrazione().getSorgente().getBase();
  380.         }
  381.         return tipoOraRegistrazioneValue == null ? protocolFactory.createTraduttore().toString(this.getTempo()) : tipoOraRegistrazioneValue;
  382.     }
  383.     public void setTempoValue(String tipoOraRegistrazioneValue) {
  384.         if(tipoOraRegistrazioneValue!=null){
  385.             if(this.trasmissione.getOraRegistrazione()==null){
  386.                 this.trasmissione.setOraRegistrazione(new Data());
  387.             }
  388.             if(this.trasmissione.getOraRegistrazione().getSorgente()==null){
  389.                 this.trasmissione.getOraRegistrazione().setSorgente(new TipoData());
  390.             }
  391.             this.trasmissione.getOraRegistrazione().getSorgente().setBase(tipoOraRegistrazioneValue);
  392.         }
  393.         else {
  394.             if(this.trasmissione.getOraRegistrazione()!=null){
  395.                 if(this.trasmissione.getOraRegistrazione().getSorgente()!=null){
  396.                     if(this.trasmissione.getOraRegistrazione().getSorgente().getTipo()==null){
  397.                         this.trasmissione.getOraRegistrazione().setSorgente(null);
  398.                     }
  399.                     else{
  400.                         this.trasmissione.getOraRegistrazione().getSorgente().setBase(null);
  401.                     }  
  402.                 }
  403.                 if(this.trasmissione.getOraRegistrazione().getSorgente()==null && this.trasmissione.getOraRegistrazione().getDateTime()==null){
  404.                     this.trasmissione.setOraRegistrazione(null);
  405.                 }
  406.             }
  407.         }
  408.     }

  409.     public Date getOraRegistrazione() {
  410.         if(this.trasmissione.getOraRegistrazione()!=null){
  411.             return this.trasmissione.getOraRegistrazione().getDateTime();
  412.         }
  413.         return null;
  414.     }
  415.     public void setOraRegistrazione(Date value) {
  416.         if(value!=null){
  417.             if(this.trasmissione.getOraRegistrazione()==null){
  418.                 this.trasmissione.setOraRegistrazione(new Data());
  419.             }
  420.             this.trasmissione.getOraRegistrazione().setDateTime(value);
  421.         }
  422.         else {
  423.             if(this.trasmissione.getOraRegistrazione()!=null){
  424.                 if(this.trasmissione.getOraRegistrazione().getSorgente()==null){
  425.                     this.trasmissione.setOraRegistrazione(null);
  426.                 }
  427.                 else{
  428.                     this.trasmissione.getOraRegistrazione().setDateTime(null);
  429.                 }
  430.             }
  431.         }
  432.     }
  433.    
  434.    


  435.    

  436.     public Trasmissione newInstance(){
  437.        
  438.         Trasmissione clone = new Trasmissione();
  439.        
  440.         // id
  441.         clone.setId(this.getId()!=null ? Long.valueOf(this.getId()+"") : null);
  442.        
  443.         // origine
  444.         clone.setOrigine(this.getOrigine()!=null ? new String(this.getOrigine()) : null);
  445.         clone.setTipoOrigine(this.getTipoOrigine()!=null ? new String(this.getTipoOrigine()) : null);
  446.         clone.setIndirizzoOrigine(this.getIndirizzoOrigine()!=null ? new String(this.getIndirizzoOrigine()) : null);
  447.         clone.setIdentificativoPortaOrigine(this.getIdentificativoPortaOrigine()!=null ? new String(this.getIdentificativoPortaOrigine()) : null);
  448.        
  449.         // destinazione
  450.         clone.setDestinazione(this.getDestinazione()!=null ? new String(this.getDestinazione()) : null);
  451.         clone.setTipoDestinazione(this.getTipoDestinazione()!=null ? new String(this.getTipoDestinazione()) : null);
  452.         clone.setIndirizzoDestinazione(this.getIndirizzoDestinazione()!=null ? new String(this.getIndirizzoDestinazione()) : null);
  453.         clone.setIdentificativoPortaDestinazione(this.getIdentificativoPortaDestinazione()!=null ? new String(this.getIdentificativoPortaDestinazione()) : null);

  454.         // date
  455.         clone.setOraRegistrazione(this.getOraRegistrazione()!=null ? new Date(this.getOraRegistrazione().getTime()) : null);
  456.         clone.setTempo(this.getTempo());
  457.         clone.setTempoValue(this.trasmissione.getOraRegistrazione()!=null &&
  458.                 this.trasmissione.getOraRegistrazione().getSorgente()!=null &&
  459.                 this.trasmissione.getOraRegistrazione().getSorgente().getBase()!=null ? new String(this.trasmissione.getOraRegistrazione().getSorgente().getBase()) : null);

  460.         return clone;
  461.     }

  462.    
  463.     public Trasmissione invertiTrasmissione(TipoOraRegistrazione tipoOraRegistrazione, String tipoTempo){
  464.        
  465.         Trasmissione inverti = new Trasmissione();
  466.                
  467.         // origine
  468.         inverti.setOrigine(this.getDestinazione()!=null ? new String(this.getDestinazione()) : null);
  469.         inverti.setTipoOrigine(this.getTipoDestinazione()!=null ? new String(this.getTipoDestinazione()) : null);
  470.         inverti.setIndirizzoOrigine(this.getIndirizzoDestinazione()!=null ? new String(this.getIndirizzoDestinazione()) : null);
  471.         inverti.setIdentificativoPortaOrigine(this.getIdentificativoPortaDestinazione()!=null ? new String(this.getIdentificativoPortaDestinazione()) : null);
  472.        
  473.         // destinazione
  474.         inverti.setDestinazione(this.getOrigine()!=null ? new String(this.getOrigine()) : null);
  475.         inverti.setTipoDestinazione(this.getTipoOrigine()!=null ? new String(this.getTipoOrigine()) : null);
  476.         inverti.setIndirizzoDestinazione(this.getIndirizzoOrigine()!=null ? new String(this.getIndirizzoOrigine()) : null);
  477.         inverti.setIdentificativoPortaDestinazione(this.getIdentificativoPortaOrigine()!=null ? new String(this.getIdentificativoPortaOrigine()) : null);

  478.         // date
  479.         Date oraRegistrazione = DateManager.getDate();
  480.         inverti.setOraRegistrazione(oraRegistrazione);
  481.         inverti.setTempo(tipoOraRegistrazione);
  482.         inverti.setTempoValue(tipoTempo);

  483.         return inverti;
  484.     }
  485. }