Riscontro.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.TipoData;
  24. import org.openspcoop2.core.tracciamento.constants.TipoTempo;
  25. import org.openspcoop2.protocol.sdk.constants.TipoOraRegistrazione;


  26. /**
  27.  * Classe utilizzata per rappresentare un Riscontro.
  28.  *
  29.  *
  30.  * @author Poli Andrea (apoli@link.it)
  31.  * @author Nardi Lorenzo
  32.  * @author $Author$
  33.  * @version $Rev$, $Date$
  34.  */

  35. public class Riscontro implements java.io.Serializable {

  36.     /**
  37.      * serialVersionUID
  38.      */
  39.     private static final long serialVersionUID = 1L;

  40.     private org.openspcoop2.core.tracciamento.Riscontro riscontro;


  41.     /* ********  C O S T R U T T O R E  ******** */

  42.     /**
  43.      * Costruttore.
  44.      *
  45.      *
  46.      */
  47.     public Riscontro(){
  48.         this.riscontro = new org.openspcoop2.core.tracciamento.Riscontro();
  49.     }

  50.     public Riscontro(org.openspcoop2.core.tracciamento.Riscontro riscontro){
  51.         this.riscontro = riscontro;
  52.     }


  53.     // base

  54.     public org.openspcoop2.core.tracciamento.Riscontro getRiscontro() {
  55.         return this.riscontro;
  56.     }
  57.     public void setRiscontro(org.openspcoop2.core.tracciamento.Riscontro riscontro) {
  58.         this.riscontro = riscontro;
  59.     }



  60.     // id  [Wrapper]

  61.     public Long getId() {
  62.         return this.riscontro.getId();
  63.     }
  64.     public void setId(Long id) {
  65.         this.riscontro.setId(id);
  66.     }



  67.     // identificativo riscontro [wrapper]
  68.     public void setID(String id ){
  69.         this.riscontro.setIdentificativo(id);
  70.     }
  71.     public String getID(){
  72.         return this.riscontro.getIdentificativo();
  73.     }
  74.    
  75.    
  76.    
  77.     // ricevuta [wrapper]
  78.     public void setRicevuta(String ricevuta ){
  79.         this.riscontro.setRicevuta(ricevuta);
  80.     }
  81.     public String getRicevuta(){
  82.         return this.riscontro.getRicevuta();
  83.     }



  84.     // date [wrapped]

  85.     public TipoOraRegistrazione getTipoOraRegistrazione() {
  86.         if(this.riscontro.getOraRegistrazione()!=null &&
  87.                 this.riscontro.getOraRegistrazione().getSorgente()!=null &&
  88.                 this.riscontro.getOraRegistrazione().getSorgente().getTipo()!=null){
  89.             switch (this.riscontro.getOraRegistrazione().getSorgente().getTipo()) {
  90.             case LOCALE:
  91.                 return TipoOraRegistrazione.LOCALE;
  92.             case SINCRONIZZATO:
  93.                 return TipoOraRegistrazione.SINCRONIZZATO;
  94.             case SCONOSCIUTO:
  95.                 return TipoOraRegistrazione.UNKNOWN;
  96.             }
  97.         }
  98.         return null;
  99.     }
  100.     public void setTipoOraRegistrazione(TipoOraRegistrazione tipoOraRegistrazione) {
  101.         if(tipoOraRegistrazione!=null){
  102.             if(this.riscontro.getOraRegistrazione()==null){
  103.                 this.riscontro.setOraRegistrazione(new Data());
  104.             }
  105.             if(this.riscontro.getOraRegistrazione().getSorgente()==null){
  106.                 this.riscontro.getOraRegistrazione().setSorgente(new TipoData());
  107.             }
  108.             switch (tipoOraRegistrazione) {
  109.             case LOCALE:
  110.                 this.riscontro.getOraRegistrazione().getSorgente().setTipo(TipoTempo.LOCALE);
  111.                 break;
  112.             case SINCRONIZZATO:
  113.                 this.riscontro.getOraRegistrazione().getSorgente().setTipo(TipoTempo.SINCRONIZZATO);
  114.                 break;
  115.             case UNKNOWN:
  116.                 this.riscontro.getOraRegistrazione().getSorgente().setTipo(TipoTempo.SCONOSCIUTO);
  117.                 break;
  118.             }
  119.         }
  120.         else {
  121.             if(this.riscontro.getOraRegistrazione()!=null){
  122.                 if(this.riscontro.getOraRegistrazione().getSorgente()!=null){
  123.                     if(this.riscontro.getOraRegistrazione().getSorgente().getBase()==null){
  124.                         this.riscontro.getOraRegistrazione().setSorgente(null);
  125.                     }
  126.                     else{
  127.                         this.riscontro.getOraRegistrazione().getSorgente().setTipo(null);
  128.                     }  
  129.                 }
  130.                 if(this.riscontro.getOraRegistrazione().getSorgente()==null && this.riscontro.getOraRegistrazione().getDateTime()==null){
  131.                     this.riscontro.setOraRegistrazione(null);
  132.                 }
  133.             }
  134.         }
  135.     }

  136.     public void setTipoOraRegistrazione(TipoOraRegistrazione tipo, String value) {
  137.         this.setTipoOraRegistrazione(tipo);
  138.         this.setTipoOraRegistrazioneValue(value);
  139.     }

  140.     public String getTipoOraRegistrazioneValue(IProtocolFactory<?> protocolFactory) throws ProtocolException {
  141.         String tipoOraRegistrazioneValue = null;
  142.         if(this.riscontro.getOraRegistrazione()!=null && this.riscontro.getOraRegistrazione().getSorgente()!=null){
  143.             tipoOraRegistrazioneValue = this.riscontro.getOraRegistrazione().getSorgente().getBase();
  144.         }
  145.         return tipoOraRegistrazioneValue == null ? protocolFactory.createTraduttore().toString(this.getTipoOraRegistrazione()) : tipoOraRegistrazioneValue;
  146.     }
  147.     public void setTipoOraRegistrazioneValue(String tipoOraRegistrazioneValue) {
  148.         if(tipoOraRegistrazioneValue!=null){
  149.             if(this.riscontro.getOraRegistrazione()==null){
  150.                 this.riscontro.setOraRegistrazione(new Data());
  151.             }
  152.             if(this.riscontro.getOraRegistrazione().getSorgente()==null){
  153.                 this.riscontro.getOraRegistrazione().setSorgente(new TipoData());
  154.             }
  155.             this.riscontro.getOraRegistrazione().getSorgente().setBase(tipoOraRegistrazioneValue);
  156.         }
  157.         else {
  158.             if(this.riscontro.getOraRegistrazione()!=null){
  159.                 if(this.riscontro.getOraRegistrazione().getSorgente()!=null){
  160.                     if(this.riscontro.getOraRegistrazione().getSorgente().getTipo()==null){
  161.                         this.riscontro.getOraRegistrazione().setSorgente(null);
  162.                     }
  163.                     else{
  164.                         this.riscontro.getOraRegistrazione().getSorgente().setBase(null);
  165.                     }  
  166.                 }
  167.                 if(this.riscontro.getOraRegistrazione().getSorgente()==null && this.riscontro.getOraRegistrazione().getDateTime()==null){
  168.                     this.riscontro.setOraRegistrazione(null);
  169.                 }
  170.             }
  171.         }
  172.     }

  173.     public Date getOraRegistrazione() {
  174.         if(this.riscontro.getOraRegistrazione()!=null){
  175.             return this.riscontro.getOraRegistrazione().getDateTime();
  176.         }
  177.         return null;
  178.     }
  179.     public void setOraRegistrazione(Date value) {
  180.         if(value!=null){
  181.             if(this.riscontro.getOraRegistrazione()==null){
  182.                 this.riscontro.setOraRegistrazione(new Data());
  183.             }
  184.             this.riscontro.getOraRegistrazione().setDateTime(value);
  185.         }
  186.         else {
  187.             if(this.riscontro.getOraRegistrazione()!=null){
  188.                 if(this.riscontro.getOraRegistrazione().getSorgente()==null){
  189.                     this.riscontro.setOraRegistrazione(null);
  190.                 }
  191.                 else{
  192.                     this.riscontro.getOraRegistrazione().setDateTime(null);
  193.                 }
  194.             }
  195.         }
  196.     }






  197.     public Riscontro newInstance(){

  198.         Riscontro clone = new Riscontro();

  199.         // id
  200.         clone.setId(this.getId()!=null ? Long.valueOf(this.getId()+"") : null);
  201.        
  202.         clone.setID(this.getID()!=null ? new String(this.getID()) : null);

  203.         clone.setOraRegistrazione(this.getOraRegistrazione()!=null ? new Date(this.getOraRegistrazione().getTime()) : null);

  204.         clone.setTipoOraRegistrazione(this.getTipoOraRegistrazione());
  205.         clone.setTipoOraRegistrazioneValue(this.riscontro.getOraRegistrazione()!=null &&
  206.                 this.riscontro.getOraRegistrazione().getSorgente()!=null &&
  207.                 this.riscontro.getOraRegistrazione().getSorgente().getBase()!=null ? new String(this.riscontro.getOraRegistrazione().getSorgente().getBase()) : null);

  208.         return clone;
  209.     }
  210. }