IDAccordoCooperazioneFactory.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;

  21. import org.openspcoop2.core.id.IDAccordo;
  22. import org.openspcoop2.core.id.IDAccordoCooperazione;
  23. import org.openspcoop2.core.id.IDSoggetto;
  24. import org.openspcoop2.core.registry.AccordoCooperazione;

  25. /**
  26.  * IDAccordoCooperazioneFactory
  27.  *
  28.  *
  29.  * @author Poli Andrea (apoli@link.it)
  30.  * @author $Author$
  31.  * @version $Rev$, $Date$
  32.  */
  33. public class IDAccordoCooperazioneFactory {

  34.     private static final String ACCORDO_NON_FORNITO = "Accordo non fornito";
  35.    
  36.     private static IDAccordoCooperazioneFactory factory = null;
  37.     private static synchronized void init(){
  38.         if(IDAccordoCooperazioneFactory.factory==null){
  39.             IDAccordoCooperazioneFactory.factory = new IDAccordoCooperazioneFactory();
  40.         }
  41.     }
  42.     public static IDAccordoCooperazioneFactory getInstance(){
  43.         if(IDAccordoCooperazioneFactory.factory==null){
  44.             // spotbugs warning 'SING_SINGLETON_GETTER_NOT_SYNCHRONIZED'
  45.             synchronized (IDAccordoCooperazioneFactory.class) {
  46.                 IDAccordoCooperazioneFactory.init();
  47.             }
  48.         }
  49.         return IDAccordoCooperazioneFactory.factory;
  50.     }
  51.    
  52.     private IDAccordoFactory idAccordoFactory = null;
  53.     private IDAccordoCooperazioneFactory(){
  54.         this.idAccordoFactory = IDAccordoFactory.getInstance();
  55.     }
  56.    
  57.    

  58.     @SuppressWarnings("deprecation")
  59.     private IDAccordoCooperazione build(IDAccordo idAccordo){
  60.         IDAccordoCooperazione idAccordoCooperazione = new IDAccordoCooperazione();
  61.         idAccordoCooperazione.setNome(idAccordo.getNome());
  62.         idAccordoCooperazione.setSoggettoReferente(idAccordo.getSoggettoReferente());
  63.         idAccordoCooperazione.setVersione(idAccordo.getVersione());
  64.         return idAccordoCooperazione;
  65.     }
  66.     @SuppressWarnings("deprecation")
  67.     private IDAccordo build(IDAccordoCooperazione idAccordoCooperazione){
  68.         IDAccordo idAccordo = new IDAccordo();
  69.         idAccordo.setNome(idAccordoCooperazione.getNome());
  70.         idAccordo.setSoggettoReferente(idAccordoCooperazione.getSoggettoReferente());
  71.         idAccordo.setVersione(idAccordoCooperazione.getVersione());
  72.         return idAccordo;
  73.     }
  74.     @SuppressWarnings("deprecation")
  75.     private IDAccordo build(String nome, IDSoggetto soggettoReferente, int versione){
  76.         IDAccordo idAccordo = new IDAccordo();
  77.         idAccordo.setNome(nome);
  78.         idAccordo.setSoggettoReferente(soggettoReferente);
  79.         idAccordo.setVersione(versione);
  80.         return idAccordo;
  81.     }
  82.    
  83.     public String normalizeUri(String uri) throws DriverRegistroServiziException{
  84.         // La uri può non contenere la versione, che invece nella 3.0 è obbligatoria.
  85.         // Facendo la doppia conversione, viene aggiunta la versione di default
  86.         IDAccordoCooperazione idAccordo = this.getIDAccordoFromUri(uri);
  87.         return this.getUriFromIDAccordo(idAccordo);
  88.     }
  89.    
  90.     public String getUriFromIDAccordo(IDAccordoCooperazione idAccordo) throws DriverRegistroServiziException{
  91.        
  92.         return this.idAccordoFactory.getUriFromIDAccordo(build(idAccordo));
  93.     }
  94.    
  95.     public String getUriFromAccordo(AccordoCooperazione accordo)  throws DriverRegistroServiziException{
  96.         if(accordo==null){
  97.             throw new DriverRegistroServiziException(ACCORDO_NON_FORNITO);
  98.         }
  99.         IDAccordo idAccordo = this.build(accordo.getNome(),BeanUtilities.getSoggettoReferenteID(accordo.getSoggettoReferente()),accordo.getVersione());
  100.         return this.idAccordoFactory.getUriFromIDAccordo(idAccordo);
  101.     }
  102.    
  103.     public String getUriFromValues(String nomeAS,String tipoSoggettoReferente,String nomeSoggettoReferente,int ver)  throws DriverRegistroServiziException{
  104.         if(nomeAS==null){
  105.             throw new DriverRegistroServiziException(ACCORDO_NON_FORNITO);
  106.         }
  107.         IDSoggetto soggettoReferente = null;
  108.         if(tipoSoggettoReferente!=null && nomeSoggettoReferente!=null)
  109.             soggettoReferente = new IDSoggetto(tipoSoggettoReferente,nomeSoggettoReferente);
  110.         IDAccordo idAccordo = this.build(nomeAS,soggettoReferente,ver);
  111.         return this.idAccordoFactory.getUriFromIDAccordo(idAccordo);
  112.     }
  113.    
  114.     public String getUriFromValues(String nomeAS,IDSoggetto soggettoReferente,int ver)  throws DriverRegistroServiziException{
  115.         if(nomeAS==null){
  116.             throw new DriverRegistroServiziException(ACCORDO_NON_FORNITO);
  117.         }
  118.         if(soggettoReferente==null){
  119.             return this.getUriFromValues(nomeAS,null,null,ver);
  120.         }else{
  121.             return this.getUriFromValues(nomeAS,soggettoReferente.getTipo(),soggettoReferente.getNome(),ver);
  122.         }
  123.     }
  124.    
  125.     public IDAccordoCooperazione getIDAccordoFromUri(String uriAccordo) throws DriverRegistroServiziException{
  126.         return this.build(this.idAccordoFactory.getIDAccordoFromUri(uriAccordo));
  127.     }
  128.    
  129.     public IDAccordoCooperazione getIDAccordoFromAccordo(AccordoCooperazione accordo) throws DriverRegistroServiziException{
  130.         if(accordo==null){
  131.             throw new DriverRegistroServiziException(ACCORDO_NON_FORNITO);
  132.         }
  133.         IDAccordo idAccordo = this.build(accordo.getNome(),BeanUtilities.getSoggettoReferenteID(accordo.getSoggettoReferente()),accordo.getVersione());
  134.         return this.build(idAccordo);
  135.     }
  136.    
  137.     public IDAccordoCooperazione getIDAccordoFromValues(String nomeAS,String tipoSoggettoReferente,String nomeSoggettoReferente,int ver) throws DriverRegistroServiziException{
  138.         if(nomeAS==null){
  139.             throw new DriverRegistroServiziException(ACCORDO_NON_FORNITO);
  140.         }
  141.         IDSoggetto soggettoReferente = null;
  142.         if(tipoSoggettoReferente!=null && nomeSoggettoReferente!=null)
  143.             soggettoReferente = new IDSoggetto(tipoSoggettoReferente,nomeSoggettoReferente);
  144.         IDAccordo idAccordo = this.build(nomeAS,soggettoReferente,ver);
  145.         return this.build(idAccordo);
  146.     }
  147.     public IDAccordoCooperazione getIDAccordoFromValuesWithoutCheck(String nomeAS,String tipoSoggettoReferente,String nomeSoggettoReferente,int ver) {
  148.         IDSoggetto soggettoReferente = new IDSoggetto(tipoSoggettoReferente,nomeSoggettoReferente);
  149.         IDAccordo idAccordo = this.build(nomeAS,soggettoReferente,ver);
  150.         return this.build(idAccordo);
  151.     }
  152.     public IDAccordoCooperazione getIDAccordoFromValues(String nomeAS,IDSoggetto soggettoReferente,int ver) throws DriverRegistroServiziException{
  153.         if(soggettoReferente==null){
  154.             return this.getIDAccordoFromValues(nomeAS,null,null,ver);
  155.         }else{
  156.             return this.getIDAccordoFromValues(nomeAS,soggettoReferente.getTipo(),soggettoReferente.getNome(),ver);
  157.         }
  158.     }
  159.    
  160.    
  161. }