IDAccordoDB.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.core.registry.driver.db;

  21. import java.io.Serializable;

  22. import org.openspcoop2.core.id.IDAccordo;
  23. import org.openspcoop2.core.id.IDSoggetto;

  24. /**
  25.  * Classe utilizzata per rappresentare un identificatore di un Accordo nel Registro
  26.  *
  27.  *
  28.  * @author Poli Andrea (apoli@link.it)
  29.  * @author Nardi Lorenzo (nardi@link.it)
  30.  * @author $Author$
  31.  * @version $Rev$, $Date$
  32.  */

  33. public class IDAccordoDB extends IDAccordo implements Serializable {

  34.     /**
  35.      *
  36.      */
  37.     private static final long serialVersionUID = 1L;

  38.     private Long id;

  39.     public Long getId() {
  40.         return this.id;
  41.     }

  42.     public void setId(Long id) {
  43.         this.id = id;
  44.     }
  45.    
  46.     public IDAccordoDB() {
  47.        
  48.     }
  49.     @SuppressWarnings("deprecation")
  50.     public IDAccordoDB(IDAccordo idAccordo) {
  51.         super.setNome(idAccordo.getNome());
  52.         if(idAccordo.getSoggettoReferente() instanceof IDSoggettoDB) {
  53.             super.setSoggettoReferente(idAccordo.getSoggettoReferente());
  54.         }
  55.         else {
  56.             IDSoggettoDB soggettoReferente = new IDSoggettoDB(idAccordo.getSoggettoReferente());
  57.             super.setSoggettoReferente(soggettoReferente);
  58.         }
  59.         super.setVersione(idAccordo.getVersione());
  60.     }
  61.     @SuppressWarnings("deprecation")
  62.     public IDAccordoDB(String nomeAccordo, IDSoggettoDB soggettoReferente, int versioneAccordo) {
  63.         super.setNome(nomeAccordo);
  64.         super.setSoggettoReferente(soggettoReferente);
  65.         super.setVersione(versioneAccordo);
  66.     }

  67.     public IDSoggettoDB getSoggettoReferenteDB() {
  68.         return (IDSoggettoDB) this.soggettoReferente;
  69.     }
  70.     @Override
  71.     @SuppressWarnings("deprecation")
  72.     @Deprecated
  73.     public void setSoggettoReferente(IDSoggetto soggettoReferente) {
  74.         if(soggettoReferente instanceof IDSoggettoDB) {
  75.             this.soggettoReferente = soggettoReferente;
  76.         }
  77.         else {
  78.             IDSoggettoDB soggettoReferenteDB = new IDSoggettoDB(soggettoReferente);
  79.             this.soggettoReferente = soggettoReferenteDB;
  80.         }
  81.     }
  82.    
  83.     @Override
  84.     public String toString(){
  85.         StringBuilder bf = new StringBuilder();
  86.         bf.append(super.toString());
  87.         bf.append(" ");
  88.         if(this.id!=null)
  89.             bf.append("Id:"+this.id);
  90.         else
  91.             bf.append("Id");
  92.         return bf.toString();
  93.     }
  94.    
  95.     @Override
  96.     public boolean equals(Object object){
  97.         return super._equals(object, false);
  98.     }
  99.    
  100.     // Utile per usare l'oggetto in hashtable come chiave
  101.     @Override
  102.     public int hashCode(){
  103.         return this.toString().hashCode();
  104.     }
  105.    
  106.     @SuppressWarnings("deprecation")
  107.     @Override
  108.     public IDAccordoDB clone(){
  109.         IDAccordoDB idAccordo = new IDAccordoDB();
  110.         if(this.getNome()!=null){
  111.             idAccordo.setNome(new String(this.getNome()));
  112.         }
  113.         if(this.getVersione()!=null){
  114.             idAccordo.setVersione(Integer.valueOf(this.getVersione().intValue()+""));
  115.         }
  116.         if(this.getSoggettoReferente()!=null){
  117.             idAccordo.setSoggettoReferente((IDSoggettoDB)this.getSoggettoReferente().clone());
  118.         }
  119.         if(this.id!=null){
  120.             idAccordo.setId(Long.valueOf(this.id+""));
  121.         }
  122.         return idAccordo;
  123.     }
  124. }