IDFruizione.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.id;

  21. import java.io.Serializable;

  22. import org.openspcoop2.utils.Utilities;


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

  31. public class IDFruizione implements Serializable, Cloneable {

  32.     /**
  33.      *
  34.      */
  35.     private static final long serialVersionUID = 1L;
  36.    
  37.     protected IDServizio idServizio;
  38.    
  39.     protected IDSoggetto idFruitore;
  40.    
  41.    
  42.     public IDServizio getIdServizio() {
  43.         return this.idServizio;
  44.     }

  45.     public void setIdServizio(IDServizio idServizio) {
  46.         this.idServizio = idServizio;
  47.     }

  48.     public IDSoggetto getIdFruitore() {
  49.         return this.idFruitore;
  50.     }

  51.     public void setIdFruitore(IDSoggetto idFruitore) {
  52.         this.idFruitore = idFruitore;
  53.     }

  54.    
  55.     @Override
  56.     public String toString(){
  57.         StringBuilder bf = new StringBuilder();
  58.         if(this.idServizio!=null)
  59.             bf.append(" idServizio["+this.idServizio+"]");
  60.         if(this.idFruitore!=null)
  61.             bf.append(" idFruitore["+this.idFruitore+"]");
  62.         return bf.toString();
  63.     }
  64.    
  65.     @Override
  66.     public boolean equals(Object object){
  67.         if(object == null)
  68.             return false;
  69.         if(!Utilities.equalsClass(object,this))
  70.             return false;
  71.         IDFruizione id = (IDFruizione) object;
  72.        
  73.         if(this.idServizio==null){
  74.             if(id.idServizio!=null)
  75.                 return false;
  76.         }else{
  77.             if(this.idServizio.equals(id.idServizio)==false)
  78.                 return false;
  79.         }
  80.        
  81.         if(this.idFruitore==null){
  82.             if(id.idFruitore!=null)
  83.                 return false;
  84.         }else{
  85.             if(this.idFruitore.equals(id.idFruitore)==false)
  86.                 return false;
  87.         }
  88.        
  89.         return true;
  90.     }
  91.    
  92.     // Utile per usare l'oggetto in hashtable come chiave
  93.     @Override
  94.     public int hashCode(){
  95.         return this.toString().hashCode();
  96.     }
  97.    
  98.     @Override
  99.     public IDFruizione clone(){
  100.         IDFruizione idFruizione = new IDFruizione();
  101.         if(this.idServizio!=null){
  102.             idFruizione.idServizio = this.idServizio.clone();
  103.         }
  104.         if(this.idFruitore!=null){
  105.             idFruizione.idFruitore = this.idFruitore.clone();
  106.         }
  107.         return idFruizione;
  108.     }
  109.    
  110.     public String toFormatString(){
  111.         StringBuilder sb = new StringBuilder();
  112.         sb.append(this.idFruitore.toFormatString());
  113.         sb.append(" ");
  114.         sb.append(this.idServizio.toFormatString());
  115.         return sb.toString();
  116.     }
  117.    
  118.     public static IDFruizione toIDFruizione(String formatString) throws Exception {
  119.         String [] tmp = formatString.split(" ");
  120.         if(tmp.length!=2) {
  121.             throw new Exception("Formato non supportato, attesi 2 valori, trovati "+tmp.length);
  122.         }
  123.         String fruitore = tmp[0];
  124.         String servizio = tmp[1];
  125.         IDFruizione idFruizione = new IDFruizione();
  126.         idFruizione.setIdFruitore(IDSoggetto.toIDSoggetto(fruitore));
  127.         idFruizione.setIdServizio(IDServizio.toIDServizio(servizio));
  128.         return idFruizione;
  129.     }
  130. }