IDServizio.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 org.openspcoop2.core.constants.TipologiaServizio;
  22. import org.openspcoop2.utils.Utilities;

  23. /**
  24.  * Classe utilizzata per rappresentare un identificatore di un Servizio nel registro dei servizi
  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 IDServizio implements java.io.Serializable, Cloneable {

  32.     /**
  33.      * serialVersionUID
  34.      */
  35.     private static final long serialVersionUID = 1L;

  36.     /* ********  F I E L D S  P R I V A T I  ******** */

  37.     protected String tipo;
  38.     protected String nome;
  39.     protected Integer versione = 1;
  40.     protected IDSoggetto soggettoErogatore;
  41.    
  42.     // Campi opzionali
  43.     protected String portType;
  44.     protected String azione;
  45.     protected String uriAccordoServizioParteComune;
  46.     protected TipologiaServizio tipologia;
  47.    
  48.  

  49.     public String getTipo() {
  50.         return this.tipo;
  51.     }
  52.     public String getNome() {
  53.         return this.nome;
  54.     }
  55.     public Integer getVersione() {
  56.         return this.versione;
  57.     }
  58.     public IDSoggetto getSoggettoErogatore() {
  59.         return this.soggettoErogatore;
  60.     }
  61.    
  62.     @Deprecated
  63.     public void setTipo(String tipo) {
  64.         this.tipo = tipo;
  65.     }
  66.     @Deprecated
  67.     public void setNome(String nome) {
  68.         this.nome = nome;
  69.     }
  70.     @Deprecated
  71.     public void setVersione(Integer versione) {
  72.         this.versione = versione;
  73.     }
  74.     @Deprecated
  75.     public void setSoggettoErogatore(IDSoggetto erogatore) {
  76.         this.soggettoErogatore = erogatore;
  77.     }
  78.    
  79.    
  80.     // Campi opzionali
  81.     public String getPortType() {
  82.         return this.portType;
  83.     }
  84.     public void setPortType(String portType) {
  85.         this.portType = portType;
  86.     }
  87.     public String getAzione() {
  88.         return this.azione;
  89.     }
  90.     public void setAzione(String azione) {
  91.         this.azione = azione;
  92.     }
  93.     public String getUriAccordoServizioParteComune() {
  94.         return this.uriAccordoServizioParteComune;
  95.     }
  96.     public void setUriAccordoServizioParteComune(String uriAccordoServizioParteComune) {
  97.         this.uriAccordoServizioParteComune = uriAccordoServizioParteComune;
  98.     }
  99.     public TipologiaServizio getTipologia() {
  100.         return this.tipologia;
  101.     }
  102.     public void setTipologia(TipologiaServizio tipologia) {
  103.         this.tipologia = tipologia;
  104.     }
  105.    


  106.     @Override
  107.     public String toString(){
  108.         return this.toString(true);
  109.     }
  110.     public String toString(boolean printAzione){
  111.         StringBuilder bf = new StringBuilder();
  112.         if(this.soggettoErogatore!=null){
  113.             bf.append(this.soggettoErogatore.getTipo());
  114.             bf.append("/");
  115.             bf.append(this.soggettoErogatore.getNome());
  116.             bf.append(":");
  117.         }
  118.         bf.append(this.tipo);
  119.         bf.append("/");
  120.         bf.append(this.nome);
  121.         bf.append(":");
  122.         bf.append(this.versione);
  123.         if(printAzione && this.azione!=null){
  124.             bf.append(":");
  125.             bf.append(this.azione);
  126.         }
  127.         return bf.toString();
  128.     }



  129.    
  130.     @Override
  131.     public boolean equals(Object object){
  132.        
  133.         if(object==null)
  134.             return false;
  135.         if(!Utilities.equalsClass(object,this))
  136.             return false;
  137.         IDServizio id = (IDServizio) object;
  138.        
  139.         return this.equals(id, true);
  140.     }
  141.    
  142.     public boolean equals(IDServizio id, boolean checkAzione){
  143.        
  144.         // TIPO
  145.         if(this.getTipo()==null){
  146.             if(id.getTipo()!=null)
  147.                 return false;
  148.         }else{
  149.             if(this.getTipo().equals(id.getTipo())==false)
  150.                 return false;
  151.         }
  152.         // NOME
  153.         if(this.getNome()==null){
  154.             if(id.getNome()!=null)
  155.                 return false;
  156.         }else{
  157.             if(this.getNome().equals(id.getNome())==false)
  158.                 return false;
  159.         }
  160.         // VERSIONE
  161.         if(this.getVersione()==null) {
  162.             if(id.getVersione()!=null) {
  163.                 return false;
  164.             }
  165.         }
  166.         else {
  167.             if(id.getVersione()==null) {
  168.                 return false;
  169.             }
  170.             if(this.getVersione().intValue()!=id.getVersione().intValue()){
  171.                 return false;
  172.             }
  173.         }
  174.        
  175.         // AZIONE
  176.         if(checkAzione) {
  177.             if(this.getAzione()==null){
  178.                 if(id.getAzione()!=null)
  179.                     return false;
  180.             }else{
  181.                 if(this.getAzione().equals(id.getAzione())==false)
  182.                     return false;
  183.             }
  184.         }
  185.        
  186.         // Soggetto EROGATORE
  187.         if(this.getSoggettoErogatore()==null){
  188.             if(id.getSoggettoErogatore()!=null)
  189.                 return false;
  190.         }else{
  191.             if(this.getSoggettoErogatore().equals(id.getSoggettoErogatore())==false)
  192.                 return false;
  193.         }


  194.         return true;
  195.     }

  196.     // Utile per usare l'oggetto in hashtable come chiave
  197.     @Override
  198.     public int hashCode(){
  199.         return this.toString().hashCode();
  200.     }
  201.    
  202.     @Override
  203.     public IDServizio clone(){
  204.         IDServizio s = null;
  205.         try {
  206.             s = (IDServizio) super.clone();
  207.         }catch(Throwable t) {
  208.             s = new IDServizio();
  209.         }
  210.        
  211.         if(this.soggettoErogatore!=null){
  212.             IDSoggetto sogg = this.soggettoErogatore.clone();
  213.             s.setSoggettoErogatore(sogg);
  214.         }
  215.        
  216.         if(this.tipo!=null)
  217.             s.setTipo(new String(this.tipo));
  218.         if(this.nome!=null)
  219.             s.setNome(new String(this.nome));
  220.         s.setVersione(this.versione);
  221.        
  222.         if(this.portType!=null)
  223.             s.setPortType(new String(this.portType));
  224.        
  225.         if(this.azione!=null)
  226.             s.setAzione(new String(this.azione));
  227.        
  228.         if(this.tipologia!=null)
  229.             s.setTipologia(this.tipologia);
  230.                
  231.         if(this.uriAccordoServizioParteComune!=null)
  232.             s.setUriAccordoServizioParteComune(new String(this.uriAccordoServizioParteComune));
  233.                
  234.         return s;
  235.     }

  236.    
  237.    
  238.     public String toFormatString(){
  239.         StringBuilder sb = new StringBuilder();
  240.         sb.append(this.soggettoErogatore.getTipo());
  241.         sb.append("/");
  242.         sb.append(this.soggettoErogatore.getNome());
  243.         sb.append("/");
  244.         sb.append(this.tipo);
  245.         sb.append("/");
  246.         sb.append(this.nome);
  247.         sb.append("/");
  248.         sb.append(this.versione);
  249.         return sb.toString();
  250.     }
  251.    
  252.     public static IDServizio toIDServizio(String formatString) throws Exception {
  253.         String [] tmp = formatString.split("/");
  254.         if(tmp.length!=5) {
  255.             throw new Exception("Formato non supportato, attesi 5 valori, trovati "+tmp.length);
  256.         }
  257.         String tipoSoggettoErogatore = tmp[0];
  258.         String nomeSoggettoErogatore = tmp[1];
  259.         String tipo = tmp[2];
  260.         String nome = tmp[3];
  261.         String versioneS = tmp[4];
  262.         int versione = Integer.valueOf(versioneS);
  263.         IDServizio idServizio = new IDServizio();
  264.         idServizio.soggettoErogatore = new IDSoggetto(tipoSoggettoErogatore, nomeSoggettoErogatore);
  265.         idServizio.tipo=tipo;
  266.         idServizio.nome=nome;
  267.         idServizio.versione=versione;
  268.         return idServizio;
  269.     }
  270. }