RegistroServizi.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.registry;

  21. import java.io.Serializable;
  22. import java.lang.reflect.Method;
  23. import java.sql.Connection;
  24. import java.util.ArrayList;
  25. import java.util.HashMap;
  26. import java.util.List;
  27. import java.util.Map;
  28. import java.util.Set;

  29. import org.openspcoop2.core.byok.IDriverBYOK;
  30. import org.openspcoop2.core.byok.IDriverBYOKConfig;
  31. import org.openspcoop2.core.config.AccessoRegistro;
  32. import org.openspcoop2.core.config.AccessoRegistroRegistro;
  33. import org.openspcoop2.core.config.constants.CostantiConfigurazione;
  34. import org.openspcoop2.core.id.IDAccordo;
  35. import org.openspcoop2.core.id.IDAccordoAzione;
  36. import org.openspcoop2.core.id.IDAccordoCooperazione;
  37. import org.openspcoop2.core.id.IDFruizione;
  38. import org.openspcoop2.core.id.IDGruppo;
  39. import org.openspcoop2.core.id.IDPortType;
  40. import org.openspcoop2.core.id.IDPortTypeAzione;
  41. import org.openspcoop2.core.id.IDResource;
  42. import org.openspcoop2.core.id.IDRuolo;
  43. import org.openspcoop2.core.id.IDScope;
  44. import org.openspcoop2.core.id.IDServizio;
  45. import org.openspcoop2.core.id.IDSoggetto;
  46. import org.openspcoop2.core.registry.AccordoCooperazione;
  47. import org.openspcoop2.core.registry.AccordoServizioParteComune;
  48. import org.openspcoop2.core.registry.AccordoServizioParteSpecifica;
  49. import org.openspcoop2.core.registry.Azione;
  50. import org.openspcoop2.core.registry.CredenzialiSoggetto;
  51. import org.openspcoop2.core.registry.Documento;
  52. import org.openspcoop2.core.registry.Fruitore;
  53. import org.openspcoop2.core.registry.Gruppo;
  54. import org.openspcoop2.core.registry.Operation;
  55. import org.openspcoop2.core.registry.PortType;
  56. import org.openspcoop2.core.registry.PortaDominio;
  57. import org.openspcoop2.core.registry.Resource;
  58. import org.openspcoop2.core.registry.Ruolo;
  59. import org.openspcoop2.core.registry.Scope;
  60. import org.openspcoop2.core.registry.Soggetto;
  61. import org.openspcoop2.core.registry.constants.CostantiRegistroServizi;
  62. import org.openspcoop2.core.registry.constants.CredenzialeTipo;
  63. import org.openspcoop2.core.registry.constants.FormatoSpecifica;
  64. import org.openspcoop2.core.registry.constants.ProfiloCollaborazione;
  65. import org.openspcoop2.core.registry.constants.RuoliDocumento;
  66. import org.openspcoop2.core.registry.constants.StatiAccordo;
  67. import org.openspcoop2.core.registry.constants.TipiDocumentoLivelloServizio;
  68. import org.openspcoop2.core.registry.constants.TipiDocumentoSemiformale;
  69. import org.openspcoop2.core.registry.constants.TipiDocumentoSicurezza;
  70. import org.openspcoop2.core.registry.constants.TipologiaServizio;
  71. import org.openspcoop2.core.registry.driver.DriverRegistroServiziException;
  72. import org.openspcoop2.core.registry.driver.DriverRegistroServiziNotFound;
  73. import org.openspcoop2.core.registry.driver.FiltroRicerca;
  74. import org.openspcoop2.core.registry.driver.FiltroRicercaAccordi;
  75. import org.openspcoop2.core.registry.driver.FiltroRicercaAzioni;
  76. import org.openspcoop2.core.registry.driver.FiltroRicercaFruizioniServizio;
  77. import org.openspcoop2.core.registry.driver.FiltroRicercaGruppi;
  78. import org.openspcoop2.core.registry.driver.FiltroRicercaOperations;
  79. import org.openspcoop2.core.registry.driver.FiltroRicercaPortTypes;
  80. import org.openspcoop2.core.registry.driver.FiltroRicercaResources;
  81. import org.openspcoop2.core.registry.driver.FiltroRicercaRuoli;
  82. import org.openspcoop2.core.registry.driver.FiltroRicercaScope;
  83. import org.openspcoop2.core.registry.driver.FiltroRicercaServizi;
  84. import org.openspcoop2.core.registry.driver.FiltroRicercaSoggetti;
  85. import org.openspcoop2.core.registry.driver.IDAccordoCooperazioneFactory;
  86. import org.openspcoop2.core.registry.driver.IDAccordoFactory;
  87. import org.openspcoop2.core.registry.driver.IDServizioFactory;
  88. import org.openspcoop2.core.registry.driver.IDriverRegistroServiziGet;
  89. import org.openspcoop2.core.registry.driver.db.DriverRegistroServiziDB;
  90. import org.openspcoop2.core.registry.driver.uddi.DriverRegistroServiziUDDI;
  91. import org.openspcoop2.core.registry.driver.utils.DriverRegistroServiziWSInitUtilities;
  92. import org.openspcoop2.core.registry.driver.web.DriverRegistroServiziWEB;
  93. import org.openspcoop2.core.registry.driver.xml.DriverRegistroServiziXML;
  94. import org.openspcoop2.core.registry.wsdl.AccordoServizioWrapper;
  95. import org.openspcoop2.core.registry.wsdl.AccordoServizioWrapperUtilities;
  96. import org.openspcoop2.message.OpenSPCoop2MessageFactory;
  97. import org.openspcoop2.protocol.sdk.constants.InformationApiSource;
  98. import org.openspcoop2.protocol.sdk.state.RequestInfo;
  99. import org.openspcoop2.utils.LoggerWrapperFactory;
  100. import org.openspcoop2.utils.SemaphoreLock;
  101. import org.openspcoop2.utils.UtilsException;
  102. import org.openspcoop2.utils.UtilsRuntimeException;
  103. import org.openspcoop2.utils.cache.Cache;
  104. import org.openspcoop2.utils.cache.CacheAlgorithm;
  105. import org.openspcoop2.utils.cache.CacheResponse;
  106. import org.openspcoop2.utils.cache.CacheType;
  107. import org.openspcoop2.utils.certificate.ArchiveLoader;
  108. import org.openspcoop2.utils.certificate.ArchiveType;
  109. import org.openspcoop2.utils.certificate.CertificateInfo;
  110. import org.openspcoop2.utils.crypt.CryptConfig;
  111. import org.openspcoop2.utils.rest.api.ApiOperation;
  112. import org.slf4j.Logger;




  113. /**
  114.  * Classe utilizzata per effettuare query a registri di servizio di openspcoop.
  115.  * E' possibile indicare piu' di una sorgente e/o una cache
  116.  *
  117.  *
  118.  * @author Poli Andrea (apoli@link.it)
  119.  * @author $Author$
  120.  * @version $Rev$, $Date$
  121.  */

  122. public class RegistroServizi  {

  123.     /** Fonti su cui effettuare le query:
  124.      * - CACHE
  125.      * - Registri deployati
  126.      */
  127.     private Cache cache = null;
  128.     private java.util.Map<String,IDriverRegistroServiziGet> driverRegistroServizi;

  129.     /** Indicazione se usare la connessione della PdD */
  130.     private Map<String, String> mappingNomeRegistroToTipiDatabase = new HashMap<>();
  131.     private Map<String, Boolean> mappingNomeRegistroToUseConnectionPdD = new HashMap<String, Boolean>();
  132.    
  133.     /** Eventuale RegistriXML da cui prelevare le definizioni dei connettori */
  134.     private List<DriverRegistroServiziXML> registriXML;

  135.     /** Logger utilizzato per debug. */
  136.     private Logger log = null;

  137.     /** Indicazione sulla gestione della gerarchia dei registri */
  138.     private boolean raggiungibilitaTotale = false;
  139.    
  140.     /** Indicazione se la porta di dominio deve processare gli accordi di servizio, i servizi e i fruitori ancora in stato di bozza */
  141.     private boolean readObjectStatoBozza = false;
  142. //  public boolean isReadObjectStatoBozza() {
  143. //      return this.readObjectStatoBozza;
  144. //  }

  145.     // Factory
  146.     private IDAccordoFactory idAccordoFactory = IDAccordoFactory.getInstance();
  147.     private IDAccordoCooperazioneFactory idAccordoCooperazioneFactory = IDAccordoCooperazioneFactory.getInstance();

  148.     private static String notFoundClassName = DriverRegistroServiziNotFound.class.getName()+"";
  149.     private static String excClassName = org.openspcoop2.core.registry.driver.DriverRegistroServiziException.class.getName() + "";
  150.        
  151.    
  152.     /* --------------- Cache --------------------*/
  153.     public boolean isCacheAbilitata(){
  154.         return this.cache!=null;
  155.     }
  156.     public void resetCache() throws DriverRegistroServiziException{
  157.         if(this.cache!=null){
  158.             try{
  159.                 this.cache.clear();
  160.             }catch(Exception e){
  161.                 throw new DriverRegistroServiziException(e.getMessage(),e);
  162.             }
  163.         }
  164.     }
  165.     public String printStatsCache(String separator) throws DriverRegistroServiziException{
  166.         if(this.cache!=null){
  167.             try{
  168.                 return this.cache.printStats(separator);
  169.             }catch(Exception e){
  170.                 throw new DriverRegistroServiziException(e.getMessage(),e);
  171.             }
  172.         }else{
  173.             throw new DriverRegistroServiziException("Cache non abilitata");
  174.         }
  175.     }
  176.     public void abilitaCache() throws DriverRegistroServiziException{
  177.         if(this.cache!=null)
  178.             throw new DriverRegistroServiziException("Cache gia' abilitata");
  179.         else{
  180.             try{
  181.                 this.cache = new Cache(CacheType.JCS, CostantiRegistroServizi.CACHE_REGISTRO_SERVIZI);  // lascio JCS come default abilitato via jmx
  182.                 this.cache.build();
  183.             }catch(Exception e){
  184.                 throw new DriverRegistroServiziException(e.getMessage(),e);
  185.             }
  186.         }
  187.     }
  188.     public void abilitaCache(Long dimensioneCache,Boolean algoritmoCacheLRU,Long itemIdleTime,Long itemLifeSecond, CryptConfig cryptConfigSoggetti) throws DriverRegistroServiziException{
  189.         if(this.cache!=null)
  190.             throw new DriverRegistroServiziException("Cache gia' abilitata");
  191.         else{
  192.             try{
  193.                 org.openspcoop2.core.config.Cache configurazioneCache = new org.openspcoop2.core.config.Cache();
  194.                 if(dimensioneCache!=null)
  195.                     configurazioneCache.setDimensione(dimensioneCache+"");
  196.                 if(algoritmoCacheLRU!=null){
  197.                     if(algoritmoCacheLRU)
  198.                         configurazioneCache.setAlgoritmo(CostantiConfigurazione.CACHE_LRU);
  199.                     else
  200.                         configurazioneCache.setAlgoritmo(CostantiConfigurazione.CACHE_MRU);
  201.                 }
  202.                 if(itemIdleTime!=null){
  203.                     configurazioneCache.setItemIdleTime(itemIdleTime+"");
  204.                 }
  205.                 if(itemLifeSecond!=null){
  206.                     configurazioneCache.setItemLifeSecond(itemLifeSecond+"");
  207.                 }
  208.                 initCacheRegistriServizi(CacheType.JCS, configurazioneCache,null,false, cryptConfigSoggetti);  // lascio JCS come default abilitato via jmx
  209.             }catch(Exception e){
  210.                 throw new DriverRegistroServiziException(e.getMessage(),e);
  211.             }
  212.         }
  213.     }
  214.     public void disabilitaCache() throws DriverRegistroServiziException{
  215.         if(this.cache==null)
  216.             throw new DriverRegistroServiziException("Cache gia' disabilitata");
  217.         else{
  218.             try{
  219.                 this.cache.clear();
  220.                 this.cache = null;
  221.             }catch(Exception e){
  222.                 throw new DriverRegistroServiziException(e.getMessage(),e);
  223.             }
  224.         }
  225.     }
  226.     public String listKeysCache(String separator) throws DriverRegistroServiziException{
  227.         if(this.cache!=null){
  228.             try{
  229.                 return this.cache.printKeys(separator);
  230.             }catch(Exception e){
  231.                 throw new DriverRegistroServiziException(e.getMessage(),e);
  232.             }
  233.         }else{
  234.             throw new DriverRegistroServiziException("Cache non abilitata");
  235.         }
  236.     }
  237.     public List<String> keysCache() throws DriverRegistroServiziException{
  238.         if(this.cache!=null){
  239.             try{
  240.                 return this.cache.keys();
  241.             }catch(Exception e){
  242.                 throw new DriverRegistroServiziException(e.getMessage(),e);
  243.             }
  244.         }else{
  245.             throw new DriverRegistroServiziException("Cache non abilitata");
  246.         }
  247.     }
  248.     public String getObjectCache(String key) throws DriverRegistroServiziException{
  249.         if(this.cache!=null){
  250.             try{
  251.                 Object o = this.cache.get(key);
  252.                 if(o!=null){
  253.                     return o.toString();
  254.                 }else{
  255.                     return "oggetto con chiave ["+key+"] non presente";
  256.                 }
  257.             }catch(Exception e){
  258.                 throw new DriverRegistroServiziException(e.getMessage(),e);
  259.             }
  260.         }else{
  261.             throw new DriverRegistroServiziException("Cache non abilitata");
  262.         }
  263.     }
  264.     public Object getRawObjectCache(String key) throws DriverRegistroServiziException{
  265.         if(this.cache!=null){
  266.             try{
  267.                 Object o = this.cache.get(key);
  268.                 if(o!=null){
  269.                     if(o instanceof CacheResponse) {
  270.                         CacheResponse cR = (CacheResponse) o;
  271.                         if(cR.getObject()!=null) {
  272.                             o = cR.getObject();
  273.                         }
  274.                         else if(cR.getException()!=null) {
  275.                             o = cR.getException();
  276.                         }
  277.                     }
  278.                     return o;
  279.                 }else{
  280.                     return null;
  281.                 }
  282.             }catch(Exception e){
  283.                 throw new DriverRegistroServiziException(e.getMessage(),e);
  284.             }
  285.         }else{
  286.             throw new DriverRegistroServiziException("Cache non abilitata");
  287.         }
  288.     }
  289.     public void removeObjectCache(String key) throws DriverRegistroServiziException{
  290.         if(this.cache!=null){
  291.             try{
  292.                 this.cache.remove(key);
  293.             }catch(Exception e){
  294.                 throw new DriverRegistroServiziException(e.getMessage(),e);
  295.             }
  296.         }else{
  297.             throw new DriverRegistroServiziException("Cache non abilitata");
  298.         }
  299.     }



  300.     /*   -------------- Costruttore -----------------  */

  301.     /**
  302.      * Si occupa di inizializzare l'engine che permette di effettuare
  303.      * query al registro dei servizi.
  304.      * L'engine inizializzato sara' diverso a seconda del <var>tipo</var> di registro :
  305.      * <ul>
  306.      * <li> {@link DriverRegistroServiziUDDI}, interroga un registro dei servizi UDDI.
  307.      * <li> {@link DriverRegistroServiziXML}, interroga un registro dei servizi realizzato tramite un file xml.
  308.      * <li> {@link DriverRegistroServiziWEB}, interroga un registro dei servizi realizzato come un WEB Server.
  309.      * <li> {@link DriverRegistroServiziDB}, interroga un registro dei servizi realizzato come un Database relazionale.
  310.      * </ul>
  311.      *
  312.      * @param accessoRegistro Informazioni per accedere al registro Servizi.
  313.      */
  314.     public RegistroServizi(AccessoRegistro accessoRegistro,Logger alog,
  315.             Logger alogConsole,boolean raggiungibilitaTotale, boolean readObjectStatoBozza,
  316.             String jndiNameDatasourcePdD, boolean useOp2UtilsDatasource, boolean bindJMX,
  317.             boolean prefillCache, CryptConfig cryptConfigSoggetti,
  318.             CacheType cacheType, IDriverBYOK driverBYOK)throws DriverRegistroServiziException{

  319.         if(alog!=null)
  320.             this.log = alog;
  321.         else
  322.             this.log = LoggerWrapperFactory.getLogger(RegistroServizi.class);
  323.         if(this.log==null) {
  324.             throw new UtilsRuntimeException("Logger unavailable");
  325.         }
  326.        
  327.         try{
  328.             this.driverRegistroServizi = new java.util.HashMap<>();
  329.             this.registriXML = new ArrayList<>();

  330.             this.raggiungibilitaTotale = raggiungibilitaTotale;

  331.             this.readObjectStatoBozza = readObjectStatoBozza;
  332.            
  333.             for(int i=0; i<accessoRegistro.sizeRegistroList(); i++){    

  334.                 IDriverRegistroServiziGet driver = null;
  335.                 AccessoRegistroRegistro registro = accessoRegistro.getRegistro(i);
  336.                 String nomeRegistro = registro.getNome();
  337.                 if(nomeRegistro == null)
  338.                     nomeRegistro = "Registro"+i+registro.getTipo();


  339.                 String path = registro.getLocation();
  340.                 if(CostantiConfigurazione.REGISTRO_XML.equals(registro.getTipo())){
  341.                     //if( (path.startsWith("http://")==false) && (path.startsWith("file://")==false) ){
  342.                     while (path.indexOf("${")!=-1){
  343.                         int indexStart = path.indexOf("${");
  344.                         int indexEnd = path.indexOf("}");
  345.                         if(indexEnd==-1){
  346.                             this.log.error("errore durante l'interpretazione del path ["+path+"]: ${ utilizzato senza la rispettiva chiusura }");
  347.                             continue;
  348.                         }
  349.                         String nameSystemProperty = path.substring(indexStart+"${".length(),indexEnd);
  350.                         String valueSystemProperty = System.getProperty(nameSystemProperty);
  351.                         if(valueSystemProperty==null){
  352.                             this.log.error("errore durante l'interpretazione del path ["+path+"]: variabile di sistema ${"+nameSystemProperty+"} non esistente");
  353.                             continue;
  354.                         }
  355.                         path = path.replace("${"+nameSystemProperty+"}", valueSystemProperty);
  356.                     }
  357.                     //}
  358.                 }


  359.                 String msg = "carico registro "+nomeRegistro+" di tipo["+registro.getTipo()+"]   location["+path+"]";
  360.                 this.log.info(msg);
  361.                 if(alogConsole!=null)
  362.                     alogConsole.info(msg);


  363.                 // inizializzazione XML
  364.                 if(CostantiConfigurazione.REGISTRO_XML.equals(registro.getTipo())){

  365.                     driver = new DriverRegistroServiziXML(path,this.log);
  366.                     if( ((DriverRegistroServiziXML)driver).create ){
  367.                         this.driverRegistroServizi.put(nomeRegistro,driver);
  368.                         this.registriXML.add((DriverRegistroServiziXML)driver);
  369.                     }else{
  370.                         msg ="Riscontrato errore durante l'inizializzazione del registro di tipo "+
  371.                         registro.getTipo()+" con location: "+registro.getLocation();
  372.                         this.log.error(msg);
  373.                         if(alogConsole!=null)
  374.                             alogConsole.info(msg);
  375.                     }
  376.                 }

  377.                 // inizializzazione UDDI
  378.                 else if(CostantiConfigurazione.REGISTRO_UDDI.equals(registro.getTipo())){
  379.                     if( (registro.getUser()!=null) && (registro.getPassword()!=null))
  380.                         driver = new DriverRegistroServiziUDDI(path,
  381.                                 registro.getUser(),
  382.                                 registro.getPassword(),this.log);
  383.                     else
  384.                         driver = new DriverRegistroServiziUDDI(registro.getLocation(),this.log);
  385.                     if( ((DriverRegistroServiziUDDI)driver).create ){
  386.                         this.driverRegistroServizi.put(nomeRegistro,driver);
  387.                     }else{
  388.                         msg = "Riscontrato errore durante l'inizializzazione del registro di tipo "+
  389.                         registro.getTipo()+" con location: "+registro.getLocation();
  390.                         this.log.error(msg);
  391.                         if(alogConsole!=null)
  392.                             alogConsole.info(msg);
  393.                     }
  394.                 }

  395.                 // inizializzazione WEB
  396.                 else if(CostantiConfigurazione.REGISTRO_WEB.equals(registro.getTipo())){
  397.                     driver = new DriverRegistroServiziWEB(path,this.log);
  398.                     if( ((DriverRegistroServiziWEB)driver).create ){
  399.                         this.driverRegistroServizi.put(nomeRegistro,driver);
  400.                     }else{
  401.                         msg ="Riscontrato errore durante l'inizializzazione del registro di tipo "+
  402.                         registro.getTipo()+" con location: "+registro.getLocation();
  403.                         this.log.error(msg);
  404.                         if(alogConsole!=null)
  405.                             alogConsole.info(msg);
  406.                     }
  407.                 }

  408.                 // inizializzazione DB
  409.                 else if(CostantiConfigurazione.REGISTRO_DB.equals(registro.getTipo())){
  410.                     driver = new DriverRegistroServiziDB(path,null,this.log,registro.getTipoDatabase(),
  411.                             useOp2UtilsDatasource,bindJMX);
  412.                     this.mappingNomeRegistroToTipiDatabase.put(nomeRegistro, registro.getTipoDatabase());
  413.                     this.mappingNomeRegistroToUseConnectionPdD.put(nomeRegistro, path.equals(jndiNameDatasourcePdD));
  414.                     if( ((DriverRegistroServiziDB)driver).create ){
  415.                         this.driverRegistroServizi.put(nomeRegistro,driver);
  416.                     }else{
  417.                         msg ="Riscontrato errore durante l'inizializzazione del registro di tipo "+
  418.                         registro.getTipo()+" con location: "+registro.getLocation();
  419.                         this.log.error(msg);
  420.                         if(alogConsole!=null)
  421.                             alogConsole.info(msg);
  422.                     }
  423.                    
  424.                     if(driver instanceof IDriverBYOKConfig) {
  425.                         IDriverBYOKConfig c = (IDriverBYOKConfig) driver;
  426.                         c.initialize(driverBYOK, false, true);
  427.                     }
  428.                 }

  429.                 // inizializzazione WS
  430.                 else if(CostantiConfigurazione.REGISTRO_WS.equals(registro.getTipo())){
  431.                     try{
  432.                         driver = DriverRegistroServiziWSInitUtilities.newInstance(registro.getLocation(),
  433.                                 registro.getUser(),
  434.                                 registro.getPassword(), this.log);
  435.                         this.driverRegistroServizi.put(nomeRegistro,driver);
  436.                     }catch(Throwable e){
  437.                         msg ="Riscontrato errore durante l'inizializzazione del registro di tipo "+
  438.                                 registro.getTipo()+" con location: "+registro.getLocation();
  439.                         this.log.error(msg);
  440.                         if(alogConsole!=null)
  441.                             alogConsole.info(msg);
  442.                     }
  443.                 }

  444.                 // tipo di registro non conosciuto
  445.                 else{
  446.                     msg = "Riscontrato errore durante l'inizializzazione del registro di tipo sconosciuto "+
  447.                     registro.getTipo()+" con location: "+registro.getLocation();
  448.                     this.log.error(msg);
  449.                     if(alogConsole!=null)
  450.                         alogConsole.info(msg);
  451.                 }
  452.             }


  453.             // Inizializzazione della Cache
  454.             if(accessoRegistro.getCache()!=null){
  455.                 initCacheRegistriServizi(cacheType, accessoRegistro.getCache(),alogConsole,prefillCache, cryptConfigSoggetti);
  456.             }

  457.         }catch(Exception e){
  458.             String msg = "Riscontrato errore durante l'inizializzazione del registro: "+e.getMessage();
  459.             this.log.error(msg);
  460.             if(alogConsole!=null)
  461.                 alogConsole.info(msg);
  462.             throw new DriverRegistroServiziException("Riscontrato errore durante l'inizializzazione del registro: "+e.getMessage());
  463.         }

  464.         if( this.driverRegistroServizi.size() == 0 )
  465.             throw new DriverRegistroServiziException("Non e' stato possibile inizializzare nessuna sorgente di lettura per un Registro dei Servizi");
  466.     }
  467.    
  468.     // Costruttore per implementare classe org.openspcoop2.protocol.basic.registry.RegistryReader
  469.     public RegistroServizi(IDriverRegistroServiziGet driverRegistroServiziGET, Logger alog, boolean readObjectStatoBozza, String tipoRegistro)throws DriverRegistroServiziException{

  470.         if(alog!=null)
  471.             this.log = alog;
  472.         else
  473.             this.log = LoggerWrapperFactory.getLogger(RegistroServizi.class);
  474.         if(this.log==null) {
  475.             throw new UtilsRuntimeException("Logger unavailable");
  476.         }
  477.        
  478.         try{
  479.             this.driverRegistroServizi = new java.util.HashMap<>();
  480.             this.registriXML = new ArrayList<>();

  481.             this.raggiungibilitaTotale = true;

  482.             this.readObjectStatoBozza = readObjectStatoBozza;
  483.            
  484.             IDriverRegistroServiziGet driver = driverRegistroServiziGET;
  485.             String nomeRegistro = "Registro_"+tipoRegistro;
  486.            
  487.             this.mappingNomeRegistroToTipiDatabase.put(nomeRegistro, tipoRegistro);
  488.             this.mappingNomeRegistroToUseConnectionPdD.put(nomeRegistro, false);
  489.             this.driverRegistroServizi.put(nomeRegistro,driver);

  490.         }catch(Exception e){
  491.             String msg = "Riscontrato errore durante l'inizializzazione del registro: "+e.getMessage();
  492.             this.log.error(msg);
  493.             throw new DriverRegistroServiziException("Riscontrato errore durante l'inizializzazione del registro: "+e.getMessage());
  494.         }

  495.         if( this.driverRegistroServizi.size() == 0 )
  496.             throw new DriverRegistroServiziException("Non e' stato possibile inizializzare nessuna sorgente di lettura per un Registro dei Servizi");
  497.     }




  498.     private void initCacheRegistriServizi(CacheType cacheType, org.openspcoop2.core.config.Cache configurazioneCache,Logger alogConsole, boolean prefillCache, CryptConfig cryptConfigSoggetti) throws Exception{
  499.         this.cache = new Cache(cacheType, CostantiRegistroServizi.CACHE_REGISTRO_SERVIZI);

  500.         if( (configurazioneCache.getDimensione()!=null) ||
  501.                 (configurazioneCache.getAlgoritmo() != null) ){

  502.             try{
  503.                 if( configurazioneCache.getDimensione()!=null ){
  504.                     int dimensione = -1;                
  505.                     if(prefillCache){
  506.                         dimensione = Integer.MAX_VALUE;
  507.                     }
  508.                     else{
  509.                         dimensione = Integer.parseInt(configurazioneCache.getDimensione());
  510.                     }
  511.                     String msg = "Dimensione della cache (RegistroServizi) impostata al valore: "+dimensione;
  512.                     if(prefillCache){
  513.                         msg = "[Prefill Enabled] " + msg;
  514.                     }
  515.                     if(prefillCache){
  516.                         this.log.warn(msg);
  517.                     }
  518.                     else{
  519.                         this.log.info(msg);
  520.                     }
  521.                     if(alogConsole!=null){
  522.                         if(prefillCache){
  523.                             alogConsole.warn(msg);
  524.                         }
  525.                         else{
  526.                             alogConsole.info(msg);
  527.                         }
  528.                     }
  529.                     this.cache.setCacheSize(dimensione);
  530.                 }
  531.                 else{
  532.                     if(prefillCache){
  533.                         int dimensione = Integer.MAX_VALUE;
  534.                         String msg = "[Prefill Enabled] Dimensione della cache (RegistroServizi) impostata al valore: "+dimensione;
  535.                         this.log.warn(msg);
  536.                         if(alogConsole!=null){
  537.                             alogConsole.warn(msg);
  538.                         }
  539.                         this.cache.setCacheSize(dimensione);
  540.                     }
  541.                 }
  542.             }catch(Exception error){
  543.                 String msg = "Parametro errato per la dimensione della cache (RegistroServizi): "+error.getMessage();
  544.                 this.log.error(msg);
  545.                 if(alogConsole!=null)
  546.                     alogConsole.info(msg);
  547.             }
  548.            
  549.             if( configurazioneCache.getAlgoritmo() != null ){
  550.                 String msg = "Algoritmo di cache (RegistroServizi) impostato al valore: "+configurazioneCache.getAlgoritmo();
  551.                 this.log.info(msg);
  552.                 if(alogConsole!=null)
  553.                     alogConsole.info(msg);
  554.                 if(CostantiConfigurazione.CACHE_MRU.equals(configurazioneCache.getAlgoritmo()))
  555.                     this.cache.setCacheAlgoritm(CacheAlgorithm.MRU);
  556.                 else
  557.                     this.cache.setCacheAlgoritm(CacheAlgorithm.LRU);
  558.             }

  559.         }
  560.         if( (configurazioneCache.getItemIdleTime() != null) ||
  561.                 (configurazioneCache.getItemLifeSecond() != null) ){

  562.             try{
  563.                 if( configurazioneCache.getItemIdleTime() != null  ){
  564.                     int itemIdleTime = -1;              
  565.                     if(prefillCache){
  566.                         itemIdleTime = -1;
  567.                     }
  568.                     else{
  569.                         itemIdleTime = Integer.parseInt(configurazioneCache.getItemIdleTime());
  570.                     }
  571.                     String msg = "Attributo 'IdleTime' (RegistroServizi) impostato al valore: "+itemIdleTime;
  572.                     if(prefillCache){
  573.                         msg = "[Prefill Enabled] " + msg;
  574.                     }
  575.                     if(prefillCache){
  576.                         this.log.warn(msg);
  577.                     }
  578.                     else{
  579.                         this.log.info(msg);
  580.                     }
  581.                     if(alogConsole!=null){
  582.                         if(prefillCache){
  583.                             alogConsole.warn(msg);
  584.                         }
  585.                         else{
  586.                             alogConsole.info(msg);
  587.                         }
  588.                     }
  589.                     this.cache.setItemIdleTime(itemIdleTime);
  590.                 }
  591.                 else{
  592.                     if(prefillCache){
  593.                         int itemIdleTime = -1;
  594.                         String msg = "[Prefill Enabled] Attributo 'IdleTime' (RegistroServizi) impostato al valore: "+itemIdleTime;
  595.                         this.log.warn(msg);
  596.                         if(alogConsole!=null){
  597.                             alogConsole.warn(msg);
  598.                         }
  599.                         this.cache.setItemIdleTime(itemIdleTime);
  600.                     }
  601.                 }
  602.             }catch(Exception error){
  603.                 String msg = "Parametro errato per l'attributo 'IdleTime' (RegistroServizi): "+error.getMessage();
  604.                 this.log.error(msg);
  605.                 if(alogConsole!=null)
  606.                     alogConsole.info(msg);
  607.             }
  608.            
  609.             try{
  610.                 if( configurazioneCache.getItemLifeSecond() != null  ){
  611.                     int itemLifeSecond = -1;                
  612.                     if(prefillCache){
  613.                         itemLifeSecond = -1;
  614.                     }
  615.                     else{
  616.                         itemLifeSecond = Integer.parseInt(configurazioneCache.getItemLifeSecond());
  617.                     }
  618.                     String msg = "Attributo 'MaxLifeSecond' (RegistroServizi) impostato al valore: "+itemLifeSecond;
  619.                     if(prefillCache){
  620.                         msg = "[Prefill Enabled] " + msg;
  621.                     }
  622.                     if(prefillCache){
  623.                         this.log.warn(msg);
  624.                     }
  625.                     else{
  626.                         this.log.info(msg);
  627.                     }
  628.                     if(alogConsole!=null){
  629.                         if(prefillCache){
  630.                             alogConsole.warn(msg);
  631.                         }
  632.                         else{
  633.                             alogConsole.info(msg);
  634.                         }
  635.                     }
  636.                     this.cache.setItemLifeTime(itemLifeSecond);
  637.                 }
  638.                 else{
  639.                     if(prefillCache){
  640.                         int itemLifeSecond = -1;
  641.                         String msg = "Attributo 'MaxLifeSecond' (RegistroServizi) impostato al valore: "+itemLifeSecond;
  642.                         this.log.warn(msg);
  643.                         if(alogConsole!=null){
  644.                             alogConsole.warn(msg);
  645.                         }
  646.                         this.cache.setItemLifeTime(itemLifeSecond);
  647.                     }
  648.                 }
  649.             }catch(Exception error){
  650.                 String msg = "Parametro errato per l'attributo 'MaxLifeSecond' (RegistroServizi): "+error.getMessage();
  651.                 this.log.error(msg);
  652.                 if(alogConsole!=null)
  653.                     alogConsole.info(msg);
  654.             }

  655.         }
  656.        
  657.         this.cache.build();
  658.        
  659.         if(prefillCache){
  660.             this.prefillCache(null,alogConsole, cryptConfigSoggetti);
  661.         }
  662.     }

  663.     @SuppressWarnings("deprecation")
  664.     @Deprecated
  665.     public void disableSyncronizedGet() throws UtilsException {
  666.         if(this.cache==null) {
  667.             throw new UtilsException("Cache disabled");
  668.         }
  669.         this.cache.disableSyncronizedGet();
  670.     }
  671.     @SuppressWarnings("deprecation")
  672.     @Deprecated
  673.     public boolean isDisableSyncronizedGet() throws UtilsException {
  674.         if(this.cache==null) {
  675.             throw new UtilsException("Cache disabled");
  676.         }
  677.         return this.cache.isDisableSyncronizedGet();
  678.     }



  679.     protected java.util.Map<String, IDriverRegistroServiziGet> getDriverRegistroServizi() {
  680.         return this.driverRegistroServizi;
  681.     }

  682.     public void prefillCache(Connection connectionPdD,Logger alogConsole,
  683.             CryptConfig cryptConfigSoggetti){
  684.        
  685.         String msg = "[Prefill] Inizializzazione cache (RegistroServizi) in corso ...";
  686.         this.log.info(msg);
  687.         if(alogConsole!=null){
  688.             alogConsole.info(msg);
  689.         }
  690.        
  691.         Set<String> registri = this.driverRegistroServizi.keySet();
  692.                
  693.         for (String nomeRegistro : registri) {
  694.        
  695.            
  696.             msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+"]";
  697.             this.log.debug(msg);
  698.             if(alogConsole!=null){
  699.                 alogConsole.debug(msg);
  700.             }
  701.            
  702.            
  703.             /* ********  R I C E R C A    S E R V I Z I  (utilizzo dei driver) ******** */
  704.            

  705.             msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+"], recupero accordi di servizio parte comune ...";
  706.             this.log.debug(msg);
  707.             if(alogConsole!=null){
  708.                 alogConsole.debug(msg);
  709.             }
  710.            
  711.             FiltroRicercaAccordi filtroAccordi = new FiltroRicercaAccordi();
  712.             List<IDAccordo> listAccordi = null;
  713.             try{
  714.                 listAccordi = this.driverRegistroServizi.get(nomeRegistro).getAllIdAccordiServizioParteComune(filtroAccordi);
  715.             }
  716.             catch(DriverRegistroServiziNotFound notFound){
  717.                 // ignore
  718.             }
  719.             catch(DriverRegistroServiziException e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  720.            
  721.             msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+"], recuperati "+(listAccordi!=null ? listAccordi.size() : 0)+" accordi di servizio parte comune";
  722.             this.log.debug(msg);
  723.             if(alogConsole!=null){
  724.                 alogConsole.debug(msg);
  725.             }
  726.            
  727.             if(listAccordi!=null && listAccordi.size()>0){
  728.                
  729.                 msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+"], lettura di "+listAccordi.size()+" accordi di servizio parte comune ...";
  730.                 this.log.debug(msg);
  731.                 if(alogConsole!=null){
  732.                     alogConsole.debug(msg);
  733.                 }
  734.                
  735.                 for (IDAccordo idAccordo : listAccordi) {
  736.                    
  737.                     msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+"], recupero dati per l'accordo di servizio parte comune ["+idAccordo+"] ...";
  738.                     this.log.debug(msg);
  739.                     if(alogConsole!=null){
  740.                         alogConsole.debug(msg);
  741.                     }
  742.                    
  743.                     try{
  744.                         this.cache.remove(_getKey_getAccordoServizioParteComune(this.idAccordoFactory, idAccordo, null, null));
  745.                         this.getAccordoServizioParteComune(connectionPdD, nomeRegistro, idAccordo);
  746.                     }
  747.                     catch(DriverRegistroServiziNotFound notFound){
  748.                         // ignore
  749.                     }
  750.                     catch(Exception e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  751.                    
  752.                     // uguale a quello sopra
  753. //                  try{
  754. //                      this.cache.remove(_getKey_getAccordoServizioParteComune(this.idAccordoFactory, idAccordo, false, false));
  755. //                      this.getAccordoServizioParteComune(connectionPdD, nomeRegistro, idAccordo, false, false);
  756. //                  }
  757. //                  catch(DriverRegistroServiziNotFound notFound){
  758. //                      // ignore                  
  759. //                  }
  760. //                  catch(Exception e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  761.                    
  762.                     AccordoServizioParteComune as = null;
  763.                     try{
  764.                         this.cache.remove(_getKey_getAccordoServizioParteComune(this.idAccordoFactory, idAccordo, true, true));
  765.                         as = this.getAccordoServizioParteComune(connectionPdD, nomeRegistro, idAccordo, true, true);
  766.                     }
  767.                     catch(DriverRegistroServiziNotFound notFound){
  768.                         // ignore
  769.                     }
  770.                     catch(Exception e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  771.                                        
  772.                     boolean serviziCorrelati = false;
  773.                     if(as!=null) {
  774.                         ProfiloCollaborazione profiloAS = as.getProfiloCollaborazione();
  775.                         for (Azione az : as.getAzioneList()) {
  776.                             ProfiloCollaborazione profiloAZ = profiloAS;
  777.                             if (CostantiRegistroServizi.PROFILO_AZIONE_RIDEFINITO.equals(az.getProfAzione())) {
  778.                                 profiloAZ = az.getProfiloCollaborazione();
  779.                             }
  780.                             if(ProfiloCollaborazione.ASINCRONO_ASIMMETRICO.equals(profiloAZ) ||
  781.                                     ProfiloCollaborazione.ASINCRONO_SIMMETRICO.equals(profiloAZ)) {
  782.                                 serviziCorrelati = true;
  783.                                 break;
  784.                             }
  785.                         }
  786.                         if(!serviziCorrelati) {
  787.                             for (PortType pt : as.getPortTypeList()) {
  788.                                 ProfiloCollaborazione profiloPT = profiloAS;
  789.                                 if (CostantiRegistroServizi.PROFILO_AZIONE_RIDEFINITO.equals(pt.getProfiloPT())) {
  790.                                     profiloPT = pt.getProfiloCollaborazione();
  791.                                 }
  792.                                 for (Operation az : pt.getAzioneList()) {
  793.                                     ProfiloCollaborazione profiloAZ = profiloPT;
  794.                                     if (CostantiRegistroServizi.PROFILO_AZIONE_RIDEFINITO.equals(az.getProfAzione())) {
  795.                                         profiloAZ = az.getProfiloCollaborazione();
  796.                                     }
  797.                                     if(ProfiloCollaborazione.ASINCRONO_ASIMMETRICO.equals(profiloAZ) ||
  798.                                             ProfiloCollaborazione.ASINCRONO_SIMMETRICO.equals(profiloAZ)) {
  799.                                         serviziCorrelati = true;
  800.                                         break;
  801.                                     }
  802.                                 }
  803.                                 if(serviziCorrelati) {
  804.                                     break;
  805.                                 }
  806.                             }
  807.                         }
  808.                     }
  809.                    
  810.                     msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+"], recupero dati per l'accordo di servizio parte comune ["+idAccordo+"] completato";
  811.                     this.log.debug(msg);
  812.                     if(alogConsole!=null){
  813.                         alogConsole.debug(msg);
  814.                     }
  815.                    
  816.                     if(serviziCorrelati) {
  817.                    
  818.                         msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+"], (analisi profilo asincrono) recupero servizi che implementano l'accordo di servizio parte comune ["+idAccordo+"] ...";
  819.                         this.log.debug(msg);
  820.                         if(alogConsole!=null){
  821.                             alogConsole.debug(msg);
  822.                         }
  823.                    
  824.                         FiltroRicercaServizi filtroServizi = new FiltroRicercaServizi();
  825.                         filtroServizi.setIdAccordoServizioParteComune(idAccordo);
  826.                         List<IDServizio> listServizi = null;
  827.                         try{
  828.                             listServizi = this.driverRegistroServizi.get(nomeRegistro).getAllIdServizi(filtroServizi);
  829.                         }
  830.                         catch(DriverRegistroServiziNotFound notFound){
  831.                             // ignore
  832.                         }
  833.                         catch(DriverRegistroServiziException e){this.log.error("[prefill] errore"+e.getMessage(),e);}

  834.                         msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+"], (analisi profilo asincrono) recuperati "+(listServizi!=null ? listServizi.size() : 0)+" servizi che implementano l'accordo di servizio parte comune ["+idAccordo+"]";
  835.                         this.log.debug(msg);
  836.                         if(alogConsole!=null){
  837.                             alogConsole.debug(msg);
  838.                         }
  839.                        
  840.                         if(listServizi!=null && listServizi.size()>0) {
  841.                             for (IDServizio idServizio : listServizi) {
  842.                                
  843.                                 IDSoggetto idSoggetto = idServizio.getSoggettoErogatore();
  844.                                
  845.                                 if(org.openspcoop2.core.constants.TipologiaServizio.CORRELATO.equals(idServizio.getTipologia())) {
  846.                                    
  847.                                     msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+
  848.                                             "], recupero dati asincroni per l'accordo di servizio parte comune ["+idAccordo+"] e soggetto ["+idSoggetto+"] ...";
  849.                                     this.log.debug(msg);
  850.                                     if(alogConsole!=null){
  851.                                         alogConsole.debug(msg);
  852.                                     }
  853.                                                                        
  854.                                     try{
  855.                                         this.cache.remove(_getKey_getAccordoServizioParteSpecifica_ServizioCorrelato(idSoggetto, idAccordo,null));
  856.                                         this.getAccordoServizioParteSpecifica_ServizioCorrelato(connectionPdD, nomeRegistro, idSoggetto, idAccordo);
  857.                                     }
  858.                                     catch(DriverRegistroServiziNotFound notFound){
  859.                                         // ignore
  860.                                     }
  861.                                     catch(Exception e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  862.                                    
  863.                                     try{
  864.                                         this.cache.remove(_getKey_getAccordoServizioParteSpecifica_ServizioCorrelato(idSoggetto, idAccordo,false));
  865.                                         this.getAccordoServizioParteSpecifica_ServizioCorrelato(connectionPdD, nomeRegistro, idSoggetto, idAccordo, false);
  866.                                     }
  867.                                     catch(DriverRegistroServiziNotFound notFound){
  868.                                         // ignore
  869.                                     }
  870.                                     catch(Exception e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  871.                                    
  872.                                     try{
  873.                                         this.cache.remove(_getKey_getAccordoServizioParteSpecifica_ServizioCorrelato(idSoggetto, idAccordo,true));
  874.                                         this.getAccordoServizioParteSpecifica_ServizioCorrelato(connectionPdD, nomeRegistro, idSoggetto, idAccordo, true);
  875.                                     }
  876.                                     catch(DriverRegistroServiziNotFound notFound){
  877.                                         // ignore
  878.                                     }
  879.                                     catch(Exception e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  880.                                    
  881.                                     msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+
  882.                                             "], recupero dati asincroni per l'accordo di servizio parte comune ["+idAccordo+"] e soggetto ["+idSoggetto+"] completato";
  883.                                     this.log.debug(msg);
  884.                                     if(alogConsole!=null){
  885.                                         alogConsole.debug(msg);
  886.                                     }
  887.                                    
  888.                                 }
  889.                                
  890.                                 else {
  891.                                     msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+
  892.                                             "], recupero dati asincroni per l'accordo di servizio parte comune ["+idAccordo+"] e soggetto ["+idSoggetto+"] non effettuata essendo il servizio non di tipologia correlata";
  893.                                     this.log.debug(msg);
  894.                                     if(alogConsole!=null){
  895.                                         alogConsole.debug(msg);
  896.                                     }
  897.                                 }
  898.                             }
  899.                         }
  900.                     }

  901.                 }
  902.                
  903.                 msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+"], lettura di "+listAccordi.size()+" accordi di servizio parte comune completato";
  904.                 this.log.debug(msg);
  905.                 if(alogConsole!=null){
  906.                     alogConsole.debug(msg);
  907.                 }
  908.             }
  909.            
  910.             msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+"], recupero porte di dominio ...";
  911.             this.log.debug(msg);
  912.             if(alogConsole!=null){
  913.                 alogConsole.debug(msg);
  914.             }
  915.            
  916.             FiltroRicerca filtroPdd = new FiltroRicerca();
  917.             List<String> listPdd = null;
  918.             try{
  919.                 listPdd = this.driverRegistroServizi.get(nomeRegistro).getAllIdPorteDominio(filtroPdd);
  920.             }
  921.             catch(DriverRegistroServiziNotFound notFound){
  922.                 // ignore
  923.             }
  924.             catch(DriverRegistroServiziException e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  925.            
  926.             msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+"], recuperate "+(listPdd!=null ? listPdd.size() : 0)+" porte di dominio";
  927.             this.log.debug(msg);
  928.             if(alogConsole!=null){
  929.                 alogConsole.debug(msg);
  930.             }
  931.            
  932.             if(listPdd!=null && listPdd.size()>0){
  933.                
  934.                 msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+"], lettura di "+listPdd.size()+" porte di dominio ...";
  935.                 this.log.debug(msg);
  936.                 if(alogConsole!=null){
  937.                     alogConsole.debug(msg);
  938.                 }
  939.                
  940.                 for (String idPdd : listPdd) {
  941.                    
  942.                     try{
  943.                         this.cache.remove(_getKey_getPortaDominio(idPdd));
  944.                         this.getPortaDominio(connectionPdD, nomeRegistro, idPdd);
  945.                     }
  946.                     catch(DriverRegistroServiziNotFound notFound){
  947.                         // ignore
  948.                     }
  949.                     catch(Exception e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  950.                    
  951.                 }
  952.                
  953.                 msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+"], lettura di "+listPdd.size()+" porte di dominio completata";
  954.                 this.log.debug(msg);
  955.                 if(alogConsole!=null){
  956.                     alogConsole.debug(msg);
  957.                 }
  958.             }
  959.            
  960.             msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+"], recupero ruoli ...";
  961.             this.log.debug(msg);
  962.             if(alogConsole!=null){
  963.                 alogConsole.debug(msg);
  964.             }
  965.            
  966.             FiltroRicercaRuoli filtroRuoli = new FiltroRicercaRuoli();
  967.             List<IDRuolo> listRuoli = null;
  968.             try{
  969.                 listRuoli = this.driverRegistroServizi.get(nomeRegistro).getAllIdRuoli(filtroRuoli);
  970.             }
  971.             catch(DriverRegistroServiziNotFound notFound){
  972.                 // ignore
  973.             }
  974.             catch(DriverRegistroServiziException e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  975.            
  976.             msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+"], recuperati "+(listRuoli!=null ? listRuoli.size() : 0)+" ruoli";
  977.             this.log.debug(msg);
  978.             if(alogConsole!=null){
  979.                 alogConsole.debug(msg);
  980.             }
  981.            
  982.             if(listRuoli!=null && listRuoli.size()>0){
  983.                
  984.                 msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+"], lettura di "+listRuoli.size()+" ruoli ...";
  985.                 this.log.debug(msg);
  986.                 if(alogConsole!=null){
  987.                     alogConsole.debug(msg);
  988.                 }
  989.                
  990.                 for (IDRuolo idRuolo : listRuoli) {
  991.                    
  992.                     try{
  993.                         this.cache.remove(_getKey_getRuolo(idRuolo.getNome()));
  994.                         this.getRuolo(connectionPdD, nomeRegistro, idRuolo.getNome());
  995.                     }
  996.                     catch(DriverRegistroServiziNotFound notFound){
  997.                         // ignore
  998.                     }
  999.                     catch(Exception e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  1000.                    
  1001.                 }
  1002.                
  1003.                 msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+"], lettura di "+listRuoli.size()+" ruoli completata";
  1004.                 this.log.debug(msg);
  1005.                 if(alogConsole!=null){
  1006.                     alogConsole.debug(msg);
  1007.                 }
  1008.             }
  1009.            
  1010.            
  1011.             msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+"], recupero scope ...";
  1012.             this.log.debug(msg);
  1013.             if(alogConsole!=null){
  1014.                 alogConsole.debug(msg);
  1015.             }
  1016.            
  1017.             FiltroRicercaScope filtroScope = new FiltroRicercaScope();
  1018.             List<IDScope> listScope = null;
  1019.             try{
  1020.                 listScope = this.driverRegistroServizi.get(nomeRegistro).getAllIdScope(filtroScope);
  1021.             }
  1022.             catch(DriverRegistroServiziNotFound notFound){
  1023.                 // ignore
  1024.             }
  1025.             catch(DriverRegistroServiziException e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  1026.            
  1027.             msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+"], recuperati "+(listScope!=null ? listScope.size() : 0)+" scope";
  1028.             this.log.debug(msg);
  1029.             if(alogConsole!=null){
  1030.                 alogConsole.debug(msg);
  1031.             }
  1032.            
  1033.             if(listScope!=null && listScope.size()>0){
  1034.                
  1035.                 msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+"], lettura di "+listScope.size()+" scope ...";
  1036.                 this.log.debug(msg);
  1037.                 if(alogConsole!=null){
  1038.                     alogConsole.debug(msg);
  1039.                 }
  1040.                
  1041.                 for (IDScope idScope : listScope) {
  1042.                    
  1043.                     try{
  1044.                         this.cache.remove(_getKey_getScope(idScope.getNome()));
  1045.                         this.getScope(connectionPdD, nomeRegistro, idScope.getNome());
  1046.                     }
  1047.                     catch(DriverRegistroServiziNotFound notFound){
  1048.                         // ignore
  1049.                     }
  1050.                     catch(Exception e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  1051.                    
  1052.                 }
  1053.                
  1054.                 msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+"], lettura di "+listScope.size()+" scope completata";
  1055.                 this.log.debug(msg);
  1056.                 if(alogConsole!=null){
  1057.                     alogConsole.debug(msg);
  1058.                 }
  1059.             }
  1060.            
  1061.            
  1062.             msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+"], recupero soggetti ...";
  1063.             this.log.debug(msg);
  1064.             if(alogConsole!=null){
  1065.                 alogConsole.debug(msg);
  1066.             }
  1067.            
  1068.             FiltroRicercaSoggetti filtroSoggetti = new FiltroRicercaSoggetti();
  1069.             List<IDSoggetto> listSoggetti = null;
  1070.             try{
  1071.                 listSoggetti = this.driverRegistroServizi.get(nomeRegistro).getAllIdSoggetti(filtroSoggetti);
  1072.             }
  1073.             catch(DriverRegistroServiziNotFound notFound){
  1074.                 // ignore
  1075.             }
  1076.             catch(DriverRegistroServiziException e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  1077.            
  1078.             msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+"], recuperati "+(listSoggetti!=null ? listSoggetti.size() : 0)+" soggetti";
  1079.             this.log.debug(msg);
  1080.             if(alogConsole!=null){
  1081.                 alogConsole.debug(msg);
  1082.             }
  1083.            
  1084.             if(listSoggetti!=null && listSoggetti.size()>0){
  1085.                
  1086.                 msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+"], lettura di "+listSoggetti.size()+" soggetti ...";
  1087.                 this.log.debug(msg);
  1088.                 if(alogConsole!=null){
  1089.                     alogConsole.debug(msg);
  1090.                 }
  1091.                
  1092.                 for (IDSoggetto idSoggetto : listSoggetti) {
  1093.                    
  1094.                     try{
  1095.                         this.cache.remove(_getKey_getSoggetto(idSoggetto));
  1096.                         this.getSoggetto(connectionPdD, nomeRegistro, idSoggetto);
  1097.                     }
  1098.                     catch(DriverRegistroServiziNotFound notFound){
  1099.                         // ignore
  1100.                     }
  1101.                     catch(Exception e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  1102.                    
  1103.                     Soggetto soggetto = null;
  1104.                     try{
  1105.                         soggetto = this.driverRegistroServizi.get(nomeRegistro).getSoggetto(idSoggetto);
  1106.                     }
  1107.                     catch(DriverRegistroServiziNotFound notFound){
  1108.                         // ignore
  1109.                     }
  1110.                     catch(DriverRegistroServiziException e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  1111.                    
  1112.                     if(soggetto!=null){
  1113.                         if(soggetto.sizeCredenzialiList()>0){
  1114.                             for (CredenzialiSoggetto credenziale : soggetto.getCredenzialiList()) {
  1115.                                 if(credenziale!=null && credenziale.getTipo()!=null){
  1116.                                     if(CredenzialeTipo.BASIC.equals(credenziale.getTipo())){
  1117.                                         try{
  1118.                                             this.cache.remove(_getKey_getSoggettoByCredenzialiBasic(credenziale.getUser(), credenziale.getPassword()));
  1119.                                             this.getSoggettoByCredenzialiBasic(connectionPdD, nomeRegistro, credenziale.getUser(), credenziale.getPassword(), cryptConfigSoggetti);
  1120.                                         }
  1121.                                         catch(DriverRegistroServiziNotFound notFound){
  1122.                                             // ignore
  1123.                                         }
  1124.                                         catch(Exception e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  1125.                                     }
  1126.                                     else if(CredenzialeTipo.APIKEY.equals(credenziale.getTipo())){
  1127.                                         try{
  1128.                                             this.cache.remove(_getKey_getSoggettoByCredenzialiApiKey(credenziale.getUser(), credenziale.getPassword(), credenziale.isCertificateStrictVerification()));
  1129.                                             this.getSoggettoByCredenzialiApiKey(connectionPdD, nomeRegistro, credenziale.getUser(), credenziale.getPassword(), credenziale.isCertificateStrictVerification(), cryptConfigSoggetti);
  1130.                                         }
  1131.                                         catch(DriverRegistroServiziNotFound notFound){
  1132.                                             // ignore
  1133.                                         }
  1134.                                         catch(Exception e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  1135.                                     }
  1136.                                     else if(CredenzialeTipo.SSL.equals(credenziale.getTipo())){
  1137.                                         if(credenziale.getSubject()!=null) {
  1138.                                             try{
  1139.                                                 this.cache.remove(_getKey_getSoggettoByCredenzialiSsl(credenziale.getSubject(),credenziale.getIssuer()));
  1140.                                                 this.getSoggettoByCredenzialiSsl(connectionPdD, nomeRegistro, credenziale.getSubject(),credenziale.getIssuer());
  1141.                                             }
  1142.                                             catch(DriverRegistroServiziNotFound notFound){
  1143.                                                 // ignore
  1144.                                             }
  1145.                                             catch(Exception e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  1146.                                         }
  1147.                                         if(credenziale.getCertificate()!=null) {
  1148.                                             try{
  1149.                                                 CertificateInfo certificato = ArchiveLoader.load(ArchiveType.CER, credenziale.getCertificate(), 0, null).getCertificate();
  1150.                                                 this.cache.remove(_getKey_getSoggettoByCredenzialiSsl(certificato, credenziale.isCertificateStrictVerification()));
  1151.                                                 this.getSoggettoByCredenzialiSsl(connectionPdD, nomeRegistro, certificato, credenziale.isCertificateStrictVerification());
  1152.                                             }
  1153.                                             catch(DriverRegistroServiziNotFound notFound){
  1154.                                                 // ignore
  1155.                                             }
  1156.                                             catch(Exception e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  1157.                                         }
  1158.                                     }
  1159.                                     else if(CredenzialeTipo.PRINCIPAL.equals(credenziale.getTipo())){
  1160.                                         try{
  1161.                                             this.cache.remove(_getKey_getSoggettoByCredenzialiPrincipal(credenziale.getUser()));
  1162.                                             this.getSoggettoByCredenzialiPrincipal(connectionPdD, nomeRegistro, credenziale.getUser());
  1163.                                         }
  1164.                                         catch(DriverRegistroServiziNotFound notFound){
  1165.                                             // ignore
  1166.                                         }
  1167.                                         catch(Exception e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  1168.                                     }
  1169.                                 }
  1170.                             }
  1171.                         }
  1172.                     }
  1173.                 }
  1174.                
  1175.                 msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+"], lettura di "+listSoggetti.size()+" soggetti completata";
  1176.                 this.log.debug(msg);
  1177.                 if(alogConsole!=null){
  1178.                     alogConsole.debug(msg);
  1179.                 }
  1180.             }
  1181.            
  1182.             msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+"], recupero servizi ...";
  1183.             this.log.debug(msg);
  1184.             if(alogConsole!=null){
  1185.                 alogConsole.debug(msg);
  1186.             }
  1187.            
  1188.             FiltroRicercaServizi filtroServizi = new FiltroRicercaServizi();
  1189.             List<IDServizio> listServizi = null;
  1190.             try{
  1191.                 listServizi = this.driverRegistroServizi.get(nomeRegistro).getAllIdServizi(filtroServizi);
  1192.             }
  1193.             catch(DriverRegistroServiziNotFound notFound){
  1194.                 // ignore
  1195.             }
  1196.             catch(DriverRegistroServiziException e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  1197.            
  1198.             msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+"], recuperati "+(listServizi!=null ? listServizi.size() : 0)+" servizi";
  1199.             this.log.debug(msg);
  1200.             if(alogConsole!=null){
  1201.                 alogConsole.debug(msg);
  1202.             }
  1203.            
  1204.             if(listServizi!=null && listServizi.size()>0){
  1205.                
  1206.                 msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+"], lettura di "+listServizi.size()+" servizi ...";
  1207.                 this.log.debug(msg);
  1208.                 if(alogConsole!=null){
  1209.                     alogConsole.debug(msg);
  1210.                 }
  1211.                
  1212.                 for (IDServizio idServizio : listServizi) {
  1213.                    
  1214.                     msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+"], recupero dati per l'accordo di servizio parte specifica ["+idServizio+"] ...";
  1215.                     this.log.debug(msg);
  1216.                     if(alogConsole!=null){
  1217.                         alogConsole.debug(msg);
  1218.                     }
  1219.                    
  1220.                     try{
  1221.                         this.cache.remove(_getKey_getAccordoServizioParteSpecifica(idServizio,null));
  1222.                         this.getAccordoServizioParteSpecifica(connectionPdD, nomeRegistro, idServizio);
  1223.                     }
  1224.                     catch(DriverRegistroServiziNotFound notFound){
  1225.                         // ignore
  1226.                     }
  1227.                     catch(Exception e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  1228.                                        
  1229.                     try{
  1230.                         this.cache.remove(_getKey_getAccordoServizioParteSpecifica(idServizio,false));
  1231.                         this.getAccordoServizioParteSpecifica(connectionPdD, nomeRegistro, idServizio, false);
  1232.                     }
  1233.                     catch(DriverRegistroServiziNotFound notFound){
  1234.                         // ignore
  1235.                     }
  1236.                     catch(Exception e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  1237.                    
  1238.                     try{
  1239.                         this.cache.remove(_getKey_getAccordoServizioParteSpecifica(idServizio,true));
  1240.                         this.getAccordoServizioParteSpecifica(connectionPdD, nomeRegistro, idServizio, true);
  1241.                     }
  1242.                     catch(DriverRegistroServiziNotFound notFound){
  1243.                         // ignore
  1244.                     }
  1245.                     catch(Exception e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  1246.                
  1247.                     AccordoServizioParteSpecifica asps = null;
  1248.                     try{
  1249.                         asps = this.driverRegistroServizi.get(nomeRegistro).getAccordoServizioParteSpecifica(idServizio);
  1250.                     }
  1251.                     catch(DriverRegistroServiziNotFound notFound){
  1252.                         // ignore
  1253.                     }
  1254.                     catch(DriverRegistroServiziException e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  1255.                    
  1256.                     try{
  1257.                         if(asps!=null && asps.getAccordoServizioParteComune()!=null){
  1258.                             IDAccordo idAPC = this.idAccordoFactory.getIDAccordoFromUri(asps.getAccordoServizioParteComune());
  1259.                             AccordoServizioParteComune apc = this.getAccordoServizioParteComune(connectionPdD,nomeRegistro,idAPC); // giĆ  aggiornato precedentemente
  1260.                             if(apc!=null){
  1261.                                 if(asps.getPortType()!=null && !"".equals(asps.getPortType())){
  1262.                                     if(apc.sizePortTypeList()>0){
  1263.                                         for (PortType pt : apc.getPortTypeList()) {
  1264.                                             if(pt.getNome().equals(asps.getPortType())){
  1265.                                                 if(pt.sizeAzioneList()>0){
  1266.                                                     for (Operation azione : pt.getAzioneList()) {
  1267.                                                         idServizio.setAzione(azione.getNome());
  1268.                                                         try{
  1269.                                                             this.cache.remove(_getKey_getAccordoServizioParteSpecifica(idServizio,null));
  1270.                                                             this.getAccordoServizioParteSpecifica(connectionPdD, nomeRegistro, idServizio);
  1271.                                                         }
  1272.                                                         catch(DriverRegistroServiziNotFound notFound){
  1273.                                                             // ignore
  1274.                                                         }
  1275.                                                         catch(Exception e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  1276.                                                        
  1277.                                                         try{
  1278.                                                             this.cache.remove(_getKey_getAccordoServizioParteSpecifica(idServizio,false));
  1279.                                                             this.getAccordoServizioParteSpecifica(connectionPdD, nomeRegistro, idServizio, false);
  1280.                                                         }
  1281.                                                         catch(DriverRegistroServiziNotFound notFound){
  1282.                                                             // ignore
  1283.                                                         }
  1284.                                                         catch(Exception e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  1285.                                                        
  1286.                                                         try{
  1287.                                                             this.cache.remove(_getKey_getAccordoServizioParteSpecifica(idServizio,true));
  1288.                                                             this.getAccordoServizioParteSpecifica(connectionPdD, nomeRegistro, idServizio, true);
  1289.                                                         }
  1290.                                                         catch(DriverRegistroServiziNotFound notFound){
  1291.                                                             // ignore
  1292.                                                         }
  1293.                                                         catch(Exception e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  1294.                                                     }
  1295.                                                 }
  1296.                                             }
  1297.                                         }
  1298.                                     }
  1299.                                 }
  1300.                                 else{
  1301.                                     if(apc.sizeAzioneList()>0){
  1302.                                         for (Azione azione : apc.getAzioneList()) {
  1303.                                             idServizio.setAzione(azione.getNome());
  1304.                                             try{
  1305.                                                 this.cache.remove(_getKey_getAccordoServizioParteSpecifica(idServizio,null));
  1306.                                                 this.getAccordoServizioParteSpecifica(connectionPdD, nomeRegistro, idServizio);
  1307.                                             }
  1308.                                             catch(DriverRegistroServiziNotFound notFound){
  1309.                                                 // ignore
  1310.                                             }
  1311.                                             catch(Exception e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  1312.                                            
  1313.                                             try{
  1314.                                                 this.cache.remove(_getKey_getAccordoServizioParteSpecifica(idServizio,false));
  1315.                                                 this.getAccordoServizioParteSpecifica(connectionPdD, nomeRegistro, idServizio, false);
  1316.                                             }
  1317.                                             catch(DriverRegistroServiziNotFound notFound){
  1318.                                                 // ignore
  1319.                                             }
  1320.                                             catch(Exception e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  1321.                                            
  1322.                                             try{
  1323.                                                 this.cache.remove(_getKey_getAccordoServizioParteSpecifica(idServizio,true));
  1324.                                                 this.getAccordoServizioParteSpecifica(connectionPdD, nomeRegistro, idServizio, true);
  1325.                                             }
  1326.                                             catch(DriverRegistroServiziNotFound notFound){
  1327.                                                 // ignore
  1328.                                             }
  1329.                                             catch(Exception e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  1330.                                         }
  1331.                                     }
  1332.                                 }
  1333.                             }
  1334.                         }
  1335.                     }catch(DriverRegistroServiziNotFound notFound){
  1336.                         // ignore
  1337.                     }
  1338.                     catch(Exception e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  1339.                    
  1340.                     // Correlato implementato nella parte comune
  1341.                    
  1342.                     msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+"], recupero dati per l'accordo di servizio parte specifica ["+idServizio+"] completata";
  1343.                     this.log.debug(msg);
  1344.                     if(alogConsole!=null){
  1345.                         alogConsole.debug(msg);
  1346.                     }
  1347.                 }
  1348.                
  1349.                 msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+"], lettura di "+listServizi.size()+" servizi completata";
  1350.                 this.log.debug(msg);
  1351.                 if(alogConsole!=null){
  1352.                     alogConsole.debug(msg);
  1353.                 }
  1354.             }
  1355.            
  1356.             msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+"], recupero accordi di cooperazione ...";
  1357.             this.log.debug(msg);
  1358.             if(alogConsole!=null){
  1359.                 alogConsole.debug(msg);
  1360.             }
  1361.            
  1362.             FiltroRicercaAccordi filtroAccordiCooperazione = new FiltroRicercaAccordi();
  1363.             List<IDAccordoCooperazione> listAccordiCooperazione = null;
  1364.             try{
  1365.                 listAccordiCooperazione = this.driverRegistroServizi.get(nomeRegistro).getAllIdAccordiCooperazione(filtroAccordiCooperazione);
  1366.             }
  1367.             catch(DriverRegistroServiziNotFound notFound){
  1368.                 // ignore
  1369.             }
  1370.             catch(DriverRegistroServiziException e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  1371.            
  1372.             msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+"], recuperati "+(listAccordiCooperazione!=null ? listAccordiCooperazione.size() : 0)+" accordi di cooperazione";
  1373.             this.log.debug(msg);
  1374.             if(alogConsole!=null){
  1375.                 alogConsole.debug(msg);
  1376.             }
  1377.            
  1378.             if(listAccordiCooperazione!=null && listAccordiCooperazione.size()>0){
  1379.                
  1380.                 msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+"], lettura di "+listAccordiCooperazione.size()+" accordi di cooperazione ...";
  1381.                 this.log.debug(msg);
  1382.                 if(alogConsole!=null){
  1383.                     alogConsole.debug(msg);
  1384.                 }
  1385.                
  1386.                 for (IDAccordoCooperazione idAccordoCooperazione : listAccordiCooperazione) {
  1387.                    
  1388.                     try{
  1389.                         this.cache.remove(_getKey_getAccordoCooperazione(this.idAccordoCooperazioneFactory, idAccordoCooperazione, null));
  1390.                         this.getAccordoCooperazione(connectionPdD, nomeRegistro, idAccordoCooperazione);
  1391.                     }
  1392.                     catch(DriverRegistroServiziNotFound notFound){
  1393.                         // ignore
  1394.                     }
  1395.                     catch(Exception e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  1396.                    
  1397.                     try{
  1398.                         this.cache.remove(_getKey_getAccordoCooperazione(this.idAccordoCooperazioneFactory, idAccordoCooperazione, false));
  1399.                         this.getAccordoCooperazione(connectionPdD, nomeRegistro, idAccordoCooperazione, false);
  1400.                     }
  1401.                     catch(DriverRegistroServiziNotFound notFound){
  1402.                         // ignore
  1403.                     }
  1404.                     catch(Exception e){this.log.error("[prefill] errore"+e.getMessage(),e);}
  1405.                    
  1406.                     try{
  1407.                         this.cache.remove(_getKey_getAccordoCooperazione(this.idAccordoCooperazioneFactory, idAccordoCooperazione, true));
  1408.                         this.getAccordoCooperazione(connectionPdD, nomeRegistro, idAccordoCooperazione, true);
  1409.                     }
  1410.                     catch(DriverRegistroServiziNotFound notFound){
  1411.                         // ignore
  1412.                     }
  1413.                     catch(Exception e){this.log.error("[prefill] errore"+e.getMessage(),e);}

  1414.                 }
  1415.                
  1416.                 msg = "[Prefill] Inizializzazione cache (RegistroServizi) per il registro ["+nomeRegistro+"], lettura di "+listAccordiCooperazione.size()+" accordi di cooperazione completata";
  1417.                 this.log.debug(msg);
  1418.                 if(alogConsole!=null){
  1419.                     alogConsole.debug(msg);
  1420.                 }
  1421.             }
  1422.            
  1423.            
  1424.            
  1425.             /* ********  R I C E R C A  I D   E L E M E N T I   P R I M I T I V I  ******** */
  1426.            
  1427.             // Dipende dal filtro, non ĆØ possibile pre-inizializzarlo
  1428.         }
  1429.        
  1430.        
  1431.         msg = "[Prefill] Inizializzazione cache (RegistroServizi) completata";
  1432.         this.log.info(msg);
  1433.         if(alogConsole!=null){
  1434.             alogConsole.info(msg);
  1435.         }
  1436.     }




  1437.     /**
  1438.      * Si occupa di effettuare una ricerca nei registri, e di inserire la ricerca in cache
  1439.      */
  1440.     public Object getObjectCache(String keyCache,String methodName,
  1441.             String nomeRegistro,
  1442.             Boolean readContenutoAllegati,
  1443.             Connection connectionPdD,
  1444.             Object ... instances) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{
  1445.         Class<?>[] classArgoments = null;
  1446.         Object[] values = null;
  1447.         if(instances!=null && instances.length>0){
  1448.             classArgoments = new Class<?>[instances.length];
  1449.             values = new Object[instances.length];
  1450.             for (int i = 0; i < instances.length; i++) {
  1451.                 if("getAccordoServizioParteComune".equals(methodName) && i==1) {
  1452.                     classArgoments[i] = boolean.class; // readDatiRegistro
  1453.                 }
  1454.                 else {
  1455.                     classArgoments[i] = instances[i].getClass();
  1456.                 }
  1457.                 values[i] = instances[i];
  1458.             }
  1459.         }
  1460.         return getObjectCache(keyCache, methodName, nomeRegistro, readContenutoAllegati, connectionPdD, classArgoments, values);
  1461.     }
  1462.     private static org.openspcoop2.utils.Semaphore semaphore_getObjectCache = new org.openspcoop2.utils.Semaphore("RegistroServizi_Object");
  1463.     public Object getObjectCache(String keyCache,String methodName,
  1464.             String nomeRegistro,
  1465.             Boolean readContenutoAllegati,
  1466.             Connection connectionPdD,
  1467.             Class<?>[] classArgoments, Object[] values) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{

  1468.         SemaphoreLock lock = semaphore_getObjectCache.acquireThrowRuntime("getObjectCache");        
  1469.         DriverRegistroServiziNotFound dNotFound = null;
  1470.         Object obj = null;
  1471.         try{

  1472. //          System.out.println("@"+keyCache+"@ INFO CACHE: "+this.cache.toString());
  1473. //          System.out.println("@"+keyCache+"@ KEYS: \n\t"+this.cache.printKeys("\n\t"));
  1474.            
  1475.             // Raccolta dati
  1476.             if(keyCache == null)
  1477.                 throw new DriverRegistroServiziException("["+methodName+"]: KeyCache non definita");    

  1478.             // se e' attiva una cache provo ad utilizzarla
  1479.             if(this.cache!=null){
  1480.                 org.openspcoop2.utils.cache.CacheResponse response =
  1481.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(keyCache);
  1482.                 if(response != null){
  1483.                     if(response.getObject()!=null){
  1484.                         this.log.debug("Oggetto (tipo:"+response.getObject().getClass().getName()+") con chiave ["+keyCache+"] (method:"+methodName+") nel registro["+nomeRegistro+"] in cache.");
  1485.                         return response.getObject();
  1486.                     }else if(response.getException()!=null){
  1487.                         this.log.debug("Eccezione (tipo:"+response.getException().getClass().getName()+") con chiave ["+keyCache+"] (method:"+methodName+") nel registro["+nomeRegistro+"] in cache.");
  1488.                         throw (Exception) response.getException();
  1489.                     }else{
  1490.                         this.log.error("In cache non e' presente ne un oggetto ne un'eccezione.");
  1491.                     }
  1492.                 }
  1493.             }

  1494.             // Effettuo le query nella mia gerarchia di registri.
  1495.             this.log.debug("oggetto con chiave ["+keyCache+"] (method:"+methodName+") nel registro["+nomeRegistro+"] non in cache, ricerco nel registro...");
  1496.             try{
  1497.                 obj = getObject(methodName,nomeRegistro,readContenutoAllegati,connectionPdD,classArgoments,values);
  1498.             }catch(DriverRegistroServiziNotFound e){
  1499.                 dNotFound = e;
  1500.             }

  1501.             // Aggiungo la risposta in cache (se esiste una cache)  
  1502.             // Se ho una eccezione aggiungo in cache solo una not found
  1503.             if( this.cache!=null ){    
  1504.                 if(dNotFound!=null){
  1505.                     this.log.info("Aggiungo eccezione ["+keyCache+"] in cache");
  1506.                 }else if(obj!=null){
  1507.                     this.log.info("Aggiungo oggetto ["+keyCache+"] in cache");
  1508.                 }else{
  1509.                     throw new Exception("Metodo ("+methodName+") nel registro["+nomeRegistro+"] ha ritornato un valore null");
  1510.                 }
  1511.                 try{    
  1512.                     org.openspcoop2.utils.cache.CacheResponse responseCache = new org.openspcoop2.utils.cache.CacheResponse();
  1513.                     if(dNotFound!=null){
  1514.                         responseCache.setException(dNotFound);
  1515.                     }else{
  1516.                         responseCache.setObject((java.io.Serializable)obj);
  1517.                     }
  1518.                     this.cache.put(keyCache,responseCache);
  1519.                 }catch(UtilsException e){
  1520.                     this.log.error("Errore durante l'inserimento in cache ["+keyCache+"]: "+e.getMessage());
  1521.                 }
  1522.             }

  1523.         }catch(DriverRegistroServiziException e){
  1524.             throw e;
  1525.         }catch(DriverRegistroServiziNotFound e){
  1526.             throw e;
  1527.         }
  1528.         catch(Exception e){
  1529.             if(notFoundClassName.equals(e.getClass().getName()))
  1530.                 throw (DriverRegistroServiziNotFound) e;
  1531.             else
  1532.                 throw new DriverRegistroServiziException("RegistroServizi, Algoritmo di Cache fallito: "+e.getMessage(),e);
  1533.         }finally {
  1534.             semaphore_getObjectCache.release(lock, "getObjectCache");
  1535.         }

  1536.         if(dNotFound!=null){
  1537.             throw dNotFound;
  1538.         }else
  1539.             return obj;
  1540.     }


  1541.     /**
  1542.      * Si occupa di effettuare una ricerca nei registri
  1543.      */
  1544.     public Object getObject(String methodName,
  1545.             String nomeRegistro,
  1546.             Boolean readContenutoAllegati,
  1547.             Connection connectionPdD,
  1548.             Object ... instances) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{
  1549.         Class<?>[] classArgoments = null;
  1550.         Object[] values = null;
  1551.         if(instances!=null && instances.length>0){
  1552.             classArgoments = new Class<?>[instances.length];
  1553.             values = new Object[instances.length];
  1554.             for (int i = 0; i < instances.length; i++) {
  1555.                 if("getAccordoServizioParteComune".equals(methodName) && i==1) {
  1556.                     classArgoments[i] = boolean.class; // readDatiRegistro
  1557.                 }
  1558.                 else {
  1559.                     classArgoments[i] = instances[i].getClass();
  1560.                 }
  1561.                 values[i] = instances[i];
  1562.             }
  1563.         }
  1564.         return getObject(methodName, nomeRegistro, readContenutoAllegati, connectionPdD, classArgoments, values);
  1565.     }
  1566.     public Object getObject(String methodName,
  1567.             String nomeRegistro,
  1568.             Boolean readContenutoAllegati,
  1569.             Connection connectionPdD,
  1570.             Class<?>[] classArgoments, Object[] values) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{


  1571.         // Effettuo le query nella mia gerarchia di registri.
  1572.         Object obj = null;
  1573.         //Recupero la classe specificata dal parametro passato
  1574.         if(nomeRegistro!=null){
  1575.             this.log.debug("Cerco nel registro ["+nomeRegistro+"]");
  1576.             try{
  1577.                 //org.openspcoop2.core.registry.driver.IDriverRegistroServiziGet driver = this.driverRegistroServizi.get(nomeRegistro);
  1578.                 org.openspcoop2.core.registry.driver.IDriverRegistroServiziGet driver = this.getDriver(connectionPdD, nomeRegistro);
  1579.                 this.log.debug("invocazione metodo ["+methodName+"]...");
  1580.                 if(classArgoments==null || classArgoments.length==0){
  1581.                     Method method =  null;
  1582.                     if((driver instanceof DriverRegistroServiziDB) && (readContenutoAllegati!=null) ){
  1583.                         method = driver.getClass().getMethod(methodName,boolean.class);
  1584.                         obj = method.invoke(driver,readContenutoAllegati);
  1585.                     }else{
  1586.                         method = driver.getClass().getMethod(methodName);
  1587.                         obj = method.invoke(driver);
  1588.                     }
  1589.                 }else if(classArgoments.length==1){
  1590.                     Method method =  null;
  1591.                     if((driver instanceof DriverRegistroServiziDB) && (readContenutoAllegati!=null) ){
  1592.                         method = driver.getClass().getMethod(methodName,classArgoments[0],boolean.class);
  1593.                         obj = method.invoke(driver,values[0],readContenutoAllegati);
  1594.                     }else{
  1595.                         method = driver.getClass().getMethod(methodName,classArgoments[0]);
  1596.                         obj = method.invoke(driver,values[0]);
  1597.                     }
  1598.                 }else if(classArgoments.length==2){
  1599.                     Method method =  null;
  1600.                     if((driver instanceof DriverRegistroServiziDB) && (readContenutoAllegati!=null) ){
  1601.                         if("getAccordoServizioParteComune".equals(methodName)) {
  1602.                             method = driver.getClass().getMethod(methodName,classArgoments[0],boolean.class,classArgoments[1]);
  1603.                             obj = method.invoke(driver,values[0],readContenutoAllegati,values[1]);
  1604.                         }
  1605.                         else {
  1606.                             method = driver.getClass().getMethod(methodName,classArgoments[0],classArgoments[1],boolean.class);
  1607.                             obj = method.invoke(driver,values[0],values[1],readContenutoAllegati);
  1608.                         }
  1609.                     }else{
  1610.                         if("getAccordoServizioParteComune".equals(methodName)) {
  1611.                             method = driver.getClass().getMethod(methodName,classArgoments[0]);
  1612.                             obj = method.invoke(driver,values[0]);
  1613.                         }
  1614.                         else {
  1615.                             method = driver.getClass().getMethod(methodName,classArgoments[0],classArgoments[1]);
  1616.                             obj = method.invoke(driver,values[0],values[1]);
  1617.                         }
  1618.                     }
  1619.                 }else if(classArgoments.length==3){
  1620.                     Method method =  null;
  1621.                     if((driver instanceof DriverRegistroServiziDB) && (readContenutoAllegati!=null) ){
  1622.                         method = driver.getClass().getMethod(methodName,classArgoments[0],classArgoments[1],classArgoments[2],boolean.class);
  1623.                         obj = method.invoke(driver,values[0],values[1],values[2],readContenutoAllegati);
  1624.                     }else{
  1625.                         method = driver.getClass().getMethod(methodName,classArgoments[0],classArgoments[1],classArgoments[2]);
  1626.                         obj = method.invoke(driver,values[0],values[1],values[2]);
  1627.                     }
  1628.                 }else if(classArgoments.length==4){
  1629.                    
  1630.                     Class<?> cArg2 = classArgoments[2];
  1631.                     if("getSoggettoByCredenzialiApiKey".equals(methodName)) {
  1632.                         cArg2 = boolean.class;
  1633.                     }
  1634.                    
  1635.                     Method method =  null;
  1636.                     if((driver instanceof DriverRegistroServiziDB) && (readContenutoAllegati!=null) ){
  1637.                         method = driver.getClass().getMethod(methodName,classArgoments[0],classArgoments[1],cArg2,classArgoments[3],boolean.class);
  1638.                         obj = method.invoke(driver,values[0],values[1],values[2],values[3],readContenutoAllegati);
  1639.                     }else{
  1640.                         method = driver.getClass().getMethod(methodName,classArgoments[0],classArgoments[1],cArg2,classArgoments[3]);
  1641.                         obj = method.invoke(driver,values[0],values[1],values[2],values[3]);
  1642.                     }
  1643.                 }else
  1644.                     throw new Exception("Troppi argomenti per gestire la chiamata del metodo");
  1645.                
  1646.                 // Check stato
  1647.                 if( (!this.readObjectStatoBozza) && (driver instanceof DriverRegistroServiziDB) ){
  1648.                     if(obj instanceof AccordoCooperazione){
  1649.                         AccordoCooperazione ac = (AccordoCooperazione) obj;
  1650.                         if(StatiAccordo.bozza.toString().equals(ac.getStatoPackage())){
  1651.                             obj = null;
  1652.                             throw new DriverRegistroServiziNotFound("Accordo presente in uno stato bozza");
  1653.                         }
  1654.                     }else if(obj instanceof AccordoServizioParteComune){
  1655.                         AccordoServizioParteComune as = (AccordoServizioParteComune) obj;
  1656.                         if(StatiAccordo.bozza.toString().equals(as.getStatoPackage())){
  1657.                             obj = null;
  1658.                             throw new DriverRegistroServiziNotFound("Accordo presente in uno stato bozza");
  1659.                         }
  1660.                     }else if(obj instanceof AccordoServizioParteSpecifica){
  1661.                         AccordoServizioParteSpecifica s = (AccordoServizioParteSpecifica) obj;
  1662.                         if(StatiAccordo.bozza.toString().equals(s.getStatoPackage())){
  1663.                             obj = null;
  1664.                             throw new DriverRegistroServiziNotFound("Accordo presente in uno stato bozza");
  1665.                         }else{
  1666.                             // Check fruitori
  1667.                             List<Fruitore> fruitoriConStatoNonBozza = new ArrayList<Fruitore>();
  1668.                             while(s.sizeFruitoreList()>0){
  1669.                                 Fruitore tmpF = s.removeFruitore(0);
  1670.                                 if(StatiAccordo.bozza.toString().equals(tmpF.getStatoPackage())==false){
  1671.                                     fruitoriConStatoNonBozza.add(tmpF);
  1672.                                 }
  1673.                             }
  1674.                             while(fruitoriConStatoNonBozza.size()>0){
  1675.                                 s.addFruitore(fruitoriConStatoNonBozza.remove(0));
  1676.                             }
  1677.                         }
  1678.                     }
  1679.                 }
  1680.                
  1681.             }catch(DriverRegistroServiziNotFound e){
  1682.                 // Non presente
  1683.                 this.log.debug("Ricerca nel registro non riuscita (metodo ["+methodName+"]): "+e.getMessage());
  1684.                 throw e;
  1685.             }
  1686.             catch(java.lang.reflect.InvocationTargetException e){
  1687.                 if(e.getTargetException()!=null){
  1688.                     if(notFoundClassName.equals(e.getTargetException().getClass().getName())){
  1689.                         // Non presente
  1690.                         this.log.debug("Ricerca nel registro ["+nomeRegistro+"] non riuscita [NotFound] (metodo ["+methodName+"]): "+e.getTargetException().getMessage());
  1691.                         throw new DriverRegistroServiziNotFound(e.getTargetException().getMessage(),e.getTargetException());
  1692.                     }else if(excClassName.equals(e.getTargetException().getClass().getName())){
  1693.                         // Non presente
  1694.                         this.log.debug("Ricerca nel registro ["+nomeRegistro+"] non riuscita [DriverException] (metodo ["+methodName+"]): "+e.getTargetException().getMessage(),e.getTargetException());
  1695.                         throw new DriverRegistroServiziException(e.getTargetException().getMessage(),e.getTargetException());
  1696.                     }else{
  1697.                         this.log.debug("Ricerca nel registro ["+nomeRegistro+"] non riuscita [InvTargetExcp.getTarget] (metodo ["+methodName+"]), "+e.getTargetException().getMessage(),e.getTargetException());
  1698.                         throw new DriverRegistroServiziException(e.getTargetException().getMessage(),e.getTargetException());
  1699.                     }
  1700.                 }else{
  1701.                     this.log.debug("Ricerca nel registro ["+nomeRegistro+"] non riuscita [InvTargetExcp] (metodo ["+methodName+"]), "+e.getMessage(),e);
  1702.                     throw new DriverRegistroServiziException(e.getMessage(),e);
  1703.                 }
  1704.             }
  1705.             catch(Exception e){
  1706.                 // Non presente
  1707.                 this.log.debug("Ricerca nel registro ["+nomeRegistro+"] non riuscita, "+e.getMessage(),e);
  1708.                 throw new DriverRegistroServiziException(e.getMessage(),e);
  1709.             }

  1710.             this.log.debug("invocazione metodo ["+methodName+"] completata.");
  1711.             return obj;

  1712.         }else{
  1713.             this.log.debug("Cerco nella mia gerarchia di registri");
  1714.             StringBuilder notFoundProblem = new StringBuilder();
  1715.             StringBuilder exceptionProblem = new StringBuilder();
  1716.             boolean find = false;
  1717.             for (String nomeRegInLista : this.driverRegistroServizi.keySet()) {
  1718.                 this.log.debug("Cerco nel registro con nome["+nomeRegInLista+"]");
  1719.                 try{
  1720.                     //org.openspcoop2.core.registry.driver.IDriverRegistroServiziGet driver = this.driverRegistroServizi.get(nomeRegInLista);
  1721.                     org.openspcoop2.core.registry.driver.IDriverRegistroServiziGet driver = this.getDriver(connectionPdD, nomeRegInLista);
  1722.                     this.log.debug("invocazione metodo ["+methodName+"] nel registro["+nomeRegInLista+"]...");
  1723.                     if(classArgoments==null || classArgoments.length==0){
  1724.                         Method method =  null;
  1725.                         if((driver instanceof DriverRegistroServiziDB) && (readContenutoAllegati!=null) ){
  1726.                             method = driver.getClass().getMethod(methodName,boolean.class);
  1727.                             obj = method.invoke(driver,readContenutoAllegati);
  1728.                         }else{
  1729.                             method = driver.getClass().getMethod(methodName);
  1730.                             obj = method.invoke(driver);
  1731.                         }
  1732.                         find = true;
  1733.                     }else if(classArgoments.length==1){
  1734.                         Method method =  null;
  1735.                         if((driver instanceof DriverRegistroServiziDB) && (readContenutoAllegati!=null) ){
  1736.                             method = driver.getClass().getMethod(methodName,classArgoments[0],boolean.class);
  1737.                             obj = method.invoke(driver,values[0],readContenutoAllegati);
  1738.                         }else{
  1739.                             method = driver.getClass().getMethod(methodName,classArgoments[0]);
  1740.                             obj = method.invoke(driver,values[0]);
  1741.                         }
  1742.                         find = true;
  1743.                     }else if(classArgoments.length==2){
  1744.                         Method method =  null;
  1745.                         if((driver instanceof DriverRegistroServiziDB) && (readContenutoAllegati!=null) ){
  1746.                             if("getAccordoServizioParteComune".equals(methodName)) {
  1747.                                 method = driver.getClass().getMethod(methodName,classArgoments[0],boolean.class,classArgoments[1]);
  1748.                                 obj = method.invoke(driver,values[0],readContenutoAllegati,values[1]);
  1749.                             }
  1750.                             else {
  1751.                                 method = driver.getClass().getMethod(methodName,classArgoments[0],classArgoments[1],boolean.class);
  1752.                                 obj = method.invoke(driver,values[0],values[1],readContenutoAllegati);
  1753.                             }
  1754.                         }else{
  1755.                             if("getAccordoServizioParteComune".equals(methodName)) {
  1756.                                 method = driver.getClass().getMethod(methodName,classArgoments[0]);
  1757.                                 obj = method.invoke(driver,values[0]);
  1758.                             }
  1759.                             else {
  1760.                                 method = driver.getClass().getMethod(methodName,classArgoments[0],classArgoments[1]);
  1761.                                 obj = method.invoke(driver,values[0],values[1]);
  1762.                             }
  1763.                         }
  1764.                         find = true;
  1765.                     }else if(classArgoments.length==3){
  1766.                         Method method =  null;
  1767.                         if((driver instanceof DriverRegistroServiziDB) && (readContenutoAllegati!=null) ){
  1768.                             method = driver.getClass().getMethod(methodName,classArgoments[0],classArgoments[1],classArgoments[2],boolean.class);
  1769.                             obj = method.invoke(driver,values[0],values[1],values[2],readContenutoAllegati);
  1770.                         }else{
  1771.                             method = driver.getClass().getMethod(methodName,classArgoments[0],classArgoments[1],classArgoments[2]);
  1772.                             obj = method.invoke(driver,values[0],values[1],values[2]);
  1773.                         }
  1774.                         find = true;
  1775.                     }else if(classArgoments.length==4){
  1776.                        
  1777.                         Class<?> cArg2 = classArgoments[2];
  1778.                         if("getSoggettoByCredenzialiApiKey".equals(methodName)) {
  1779.                             cArg2 = boolean.class;
  1780.                         }
  1781.                        
  1782.                         Method method =  null;
  1783.                         if((driver instanceof DriverRegistroServiziDB) && (readContenutoAllegati!=null) ){
  1784.                             method = driver.getClass().getMethod(methodName,classArgoments[0],classArgoments[1],cArg2,classArgoments[3],boolean.class);
  1785.                             obj = method.invoke(driver,values[0],values[1],values[2],values[3],readContenutoAllegati);
  1786.                         }else{
  1787.                             method = driver.getClass().getMethod(methodName,classArgoments[0],classArgoments[1],cArg2,classArgoments[3]);
  1788.                             obj = method.invoke(driver,values[0],values[1],values[2],values[3]);
  1789.                         }
  1790.                         find = true;
  1791.                     }else
  1792.                         throw new Exception("Troppi argomenti per gestire la chiamata del metodo");
  1793.                    
  1794.                     // Check stato
  1795.                     if((!this.readObjectStatoBozza) && (driver instanceof DriverRegistroServiziDB) ){
  1796.                         if(obj instanceof AccordoCooperazione){
  1797.                             AccordoCooperazione ac = (AccordoCooperazione) obj;
  1798.                             if(StatiAccordo.bozza.toString().equals(ac.getStatoPackage())){
  1799.                                 obj = null;
  1800.                                 find = false;
  1801.                                 throw new DriverRegistroServiziNotFound("Accordo presente in uno stato bozza");
  1802.                             }
  1803.                         }else if(obj instanceof AccordoServizioParteComune){
  1804.                             AccordoServizioParteComune as = (AccordoServizioParteComune) obj;
  1805.                             if(StatiAccordo.bozza.toString().equals(as.getStatoPackage())){
  1806.                                 obj = null;
  1807.                                 find = false;
  1808.                                 throw new DriverRegistroServiziNotFound("Accordo presente in uno stato bozza");
  1809.                             }
  1810.                         }else if(obj instanceof AccordoServizioParteSpecifica){
  1811.                             AccordoServizioParteSpecifica s = (AccordoServizioParteSpecifica) obj;
  1812.                             if(StatiAccordo.bozza.toString().equals(s.getStatoPackage())){
  1813.                                 obj = null;
  1814.                                 find = false;
  1815.                                 throw new DriverRegistroServiziNotFound("Accordo presente in uno stato bozza");
  1816.                             }else{
  1817.                                 // Check fruitori
  1818.                                 List<Fruitore> fruitoriConStatoNonBozza = new ArrayList<Fruitore>();
  1819.                                 while(s.sizeFruitoreList()>0){
  1820.                                     Fruitore tmpF = s.removeFruitore(0);
  1821.                                     if(StatiAccordo.bozza.toString().equals(tmpF.getStatoPackage())==false){
  1822.                                         fruitoriConStatoNonBozza.add(tmpF);
  1823.                                     }
  1824.                                 }
  1825.                                 while(fruitoriConStatoNonBozza.size()>0){
  1826.                                     s.addFruitore(fruitoriConStatoNonBozza.remove(0));
  1827.                                 }
  1828.                             }
  1829.                         }
  1830.                     }
  1831.                    
  1832.                 }catch(DriverRegistroServiziNotFound ed){
  1833.                     // Non presente
  1834.                     this.log.debug("Ricerca nel registro ["+nomeRegInLista+"] non riuscita (metodo ["+methodName+"]): "+ed.getMessage());
  1835.                     notFoundProblem.append("\nRegistro["+nomeRegInLista+"], ricerca fallita: "+ed.getMessage());
  1836.                 }
  1837.                 catch(java.lang.reflect.InvocationTargetException e){
  1838.                     if(e.getTargetException()!=null){
  1839.                         if(notFoundClassName.equals(e.getTargetException().getClass().getName())){
  1840.                             // Non presente
  1841.                             this.log.debug("Ricerca nel registro ["+nomeRegInLista+"] non riuscita [NotFound] (metodo ["+methodName+"]): "+e.getTargetException().getMessage());
  1842.                             notFoundProblem.append("\nRegistro["+nomeRegInLista+"], ricerca fallita: "+e.getTargetException().getMessage());
  1843.                         }else if(excClassName.equals(e.getTargetException().getClass().getName())){
  1844.                             // Non presente
  1845.                             this.log.debug("Ricerca nel registro ["+nomeRegInLista+"] non riuscita [DriverException] (metodo ["+methodName+"]): "+e.getTargetException().getMessage(),e.getTargetException());
  1846.                             if(this.raggiungibilitaTotale)
  1847.                                 throw new DriverRegistroServiziException(e.getTargetException().getMessage(),e.getTargetException());
  1848.                             else
  1849.                                 exceptionProblem.append("\nRegistro["+nomeRegInLista+"], accesso non riuscito: "+e.getTargetException().getMessage());
  1850.                         }else{
  1851.                             this.log.debug("Ricerca nel registro ["+nomeRegInLista+"] non riuscita [InvTargetExcp.getTarget] (metodo ["+methodName+"]), "+e.getTargetException().getMessage(),e.getTargetException());
  1852.                             if(this.raggiungibilitaTotale)
  1853.                                 throw new DriverRegistroServiziException(e.getTargetException().getMessage(),e.getTargetException());
  1854.                             else
  1855.                                 exceptionProblem.append("\nRegistro["+nomeRegInLista+"], accesso non riuscito: "+e.getTargetException().getMessage());
  1856.                         }
  1857.                     }else{
  1858.                         this.log.debug("Ricerca nel registro ["+nomeRegInLista+"] non riuscita [InvTargetExcp] (metodo ["+methodName+"]), "+e.getMessage(),e);
  1859.                         if(this.raggiungibilitaTotale)
  1860.                             throw new DriverRegistroServiziException(e.getMessage(),e);
  1861.                         else
  1862.                             exceptionProblem.append("\nRegistro["+nomeRegInLista+"], accesso non riuscito: "+e.getMessage());
  1863.                     }
  1864.                 }catch(Exception e){
  1865.                     // Non presente
  1866.                     this.log.debug("Ricerca nel registro ["+nomeRegInLista+"] non riuscita, "+e.getMessage(),e);
  1867.                     if(this.raggiungibilitaTotale)
  1868.                         throw new DriverRegistroServiziException(e.getMessage(),e);
  1869.                     else
  1870.                         exceptionProblem.append("\nRegistro["+nomeRegInLista+"], accesso non riuscito: "+e.getMessage());
  1871.                 }
  1872.                 if(find)
  1873.                     break;
  1874.             }

  1875.             this.log.debug("invocazione metodo ["+methodName+"] completata.");
  1876.             if(find){
  1877.                 return obj;
  1878.             }else if(exceptionProblem.length()>0 && notFoundProblem.length()>0){
  1879.                 throw new DriverRegistroServiziException("["+methodName+"]:"+exceptionProblem.toString()+notFoundProblem.toString());
  1880.             }else if(exceptionProblem.length()>0){
  1881.                 throw new DriverRegistroServiziException("["+methodName+"]:"+exceptionProblem.toString());
  1882.             }else if(notFoundProblem.length()>0){
  1883.                 throw new DriverRegistroServiziNotFound("["+methodName+"]:"+notFoundProblem.toString());
  1884.             }else{
  1885.                 throw new DriverRegistroServiziException("["+methodName+"]: ricerca non riuscita in tutti i registri");
  1886.             }
  1887.         }


  1888.     }


  1889.     private org.openspcoop2.core.registry.driver.IDriverRegistroServiziGet getDriver(Connection connectionPdD,String nomeRegistro) throws DriverRegistroServiziException{
  1890.        
  1891.         org.openspcoop2.core.registry.driver.IDriverRegistroServiziGet driver = this.driverRegistroServizi.get(nomeRegistro);
  1892.         if((driver instanceof DriverRegistroServiziDB)){
  1893.             Boolean useConnectionPdD = this.mappingNomeRegistroToUseConnectionPdD.get(nomeRegistro);
  1894.             if(connectionPdD!=null && useConnectionPdD){
  1895.                 //System.out.println("[REGISTRY] USE CONNECTION VERSIONE!!!!!");
  1896.                 driver = new DriverRegistroServiziDB(connectionPdD, this.log, this.mappingNomeRegistroToTipiDatabase.get(nomeRegistro));
  1897.                 if( ((DriverRegistroServiziDB)driver).create == false){
  1898.                     throw new DriverRegistroServiziException("Inizializzazione DriverRegistroServizi("+nomeRegistro+") con connessione PdD non riuscita");
  1899.                 }
  1900.             }
  1901.             else{
  1902.                 //System.out.println("[REGISTRY] USE DATASOURCE VERSIONE!!!!!");
  1903.             }
  1904.         }
  1905.        
  1906.         return driver;
  1907.     }














  1908.     /* ********  R I C E R C A    S E R V I Z I  (utilizzo dei driver) ******** */
  1909.    
  1910.     protected static String _getKey_getAccordoServizioParteComune(IDAccordoFactory idAccordoFactory, IDAccordo idAccordo,Boolean readContenutiAllegati,Boolean readDatiRegistro) throws DriverRegistroServiziException{
  1911.         String uriAccordoServizio = idAccordoFactory.getUriFromIDAccordo(idAccordo);
  1912.         String key = "getAccordoServizio_" + uriAccordoServizio;
  1913.         if(readContenutiAllegati!=null && readContenutiAllegati){
  1914.             key = key + "_READ-ALLEGATI("+readContenutiAllegati.booleanValue()+")";
  1915.         }
  1916.         if(readDatiRegistro!=null && readDatiRegistro){
  1917.             key = key + "_READ-DATI-REGISTRO("+readDatiRegistro.booleanValue()+")";
  1918.         }
  1919.         return key;
  1920.     }
  1921.     public AccordoServizioParteComune getAccordoServizioParteComune(Connection connectionPdD,String nomeRegistro,IDAccordo idAccordo) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{
  1922.         return getAccordoServizioParteComune(connectionPdD, nomeRegistro, idAccordo, null, null);
  1923.     }
  1924.     public AccordoServizioParteComune getAccordoServizioParteComune(Connection connectionPdD,String nomeRegistro,IDAccordo idAccordo,Boolean readContenutiAllegati,Boolean readDatiRegistro) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{

  1925.         // Raccolta dati
  1926.         if(idAccordo == null)
  1927.             throw new DriverRegistroServiziException("[getAccordoServizioParteComune]: Parametro non definito");    
  1928.         if(idAccordo.getNome() == null)
  1929.             throw new DriverRegistroServiziException("[getAccordoServizioParteComune]: Nome accordo di servizio non definito");
  1930.        
  1931.         // se e' attiva una cache provo ad utilizzarla
  1932.         String key = null;  
  1933.         if(this.cache!=null){
  1934.             key = _getKey_getAccordoServizioParteComune(this.idAccordoFactory, idAccordo, readContenutiAllegati, readDatiRegistro);
  1935.             org.openspcoop2.utils.cache.CacheResponse response =
  1936.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  1937.             if(response != null){
  1938.                 if(response.getException()!=null){
  1939.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  1940.                         throw (DriverRegistroServiziNotFound) response.getException();
  1941.                     else
  1942.                         throw (DriverRegistroServiziException) response.getException();
  1943.                 }else{
  1944.                     return ((AccordoServizioParteComune) response.getObject());
  1945.                 }
  1946.             }
  1947.         }


  1948.         // Algoritmo CACHE
  1949.         AccordoServizioParteComune as = null;
  1950.         if(this.cache!=null){
  1951.             if(readDatiRegistro!=null) {
  1952.                 as = (AccordoServizioParteComune) this.getObjectCache(key,"getAccordoServizioParteComune",nomeRegistro,readContenutiAllegati,connectionPdD,idAccordo,readDatiRegistro);
  1953.             }else {
  1954.                 as = (AccordoServizioParteComune) this.getObjectCache(key,"getAccordoServizioParteComune",nomeRegistro,readContenutiAllegati,connectionPdD,idAccordo);
  1955.             }
  1956.         }else{
  1957.             if(readDatiRegistro!=null) {
  1958.                 as = (AccordoServizioParteComune) this.getObject("getAccordoServizioParteComune",nomeRegistro,readContenutiAllegati,connectionPdD,idAccordo,readDatiRegistro);
  1959.             }
  1960.             else {
  1961.                 as = (AccordoServizioParteComune) this.getObject("getAccordoServizioParteComune",nomeRegistro,readContenutiAllegati,connectionPdD,idAccordo);
  1962.             }
  1963.         }

  1964.         if(as!=null)
  1965.             return as;
  1966.         else
  1967.             throw new DriverRegistroServiziNotFound("[getAccordoServizio] Accordo di Servizio ["+idAccordo+"] non trovato");



  1968.     }

  1969.    
  1970.     protected static String _getKey_getPortaDominio(String nomePdD) throws DriverRegistroServiziException{
  1971.         return "getPortaDominio_" + nomePdD;
  1972.     }
  1973.     public org.openspcoop2.core.registry.PortaDominio getPortaDominio(Connection connectionPdD,String nomeRegistro,String nomePdD) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{
  1974.        
  1975.         // Raccolta dati
  1976.         if(nomePdD == null)
  1977.             throw new DriverRegistroServiziException("[getPortaDominio]: Parametro non definito");  

  1978.         // se e' attiva una cache provo ad utilizzarla
  1979.         String key = null;  
  1980.         if(this.cache!=null){
  1981.             key = _getKey_getPortaDominio(nomePdD);
  1982.             org.openspcoop2.utils.cache.CacheResponse response =
  1983.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  1984.             if(response != null){
  1985.                 if(response.getException()!=null){
  1986.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  1987.                         throw (DriverRegistroServiziNotFound) response.getException();
  1988.                     else
  1989.                         throw (DriverRegistroServiziException) response.getException();
  1990.                 }else{
  1991.                     return ((PortaDominio) response.getObject());
  1992.                 }
  1993.             }
  1994.         }


  1995.         // Algoritmo CACHE
  1996.         PortaDominio pd = null;
  1997.         if(this.cache!=null){
  1998.             pd = (PortaDominio) this.getObjectCache(key,"getPortaDominio",nomeRegistro,null,connectionPdD,nomePdD);
  1999.         }else{
  2000.             pd = (PortaDominio) this.getObject("getPortaDominio",nomeRegistro,null,connectionPdD,nomePdD);
  2001.         }

  2002.         if(pd!=null)
  2003.             return pd;
  2004.         else
  2005.             throw new DriverRegistroServiziNotFound("[getPortaDominio] Porta di dominio ["+nomePdD+"] non Trovata");

  2006.     }
  2007.    
  2008.    
  2009.     protected static String _getKey_getGruppo(String nomeGruppo) throws DriverRegistroServiziException{
  2010.         return "getGruppo_" + nomeGruppo;
  2011.     }
  2012.     public org.openspcoop2.core.registry.Gruppo getGruppo(Connection connectionPdD,String nomeRegistro,String nomeGruppo) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{
  2013.        
  2014.         // Raccolta dati
  2015.         if(nomeGruppo == null)
  2016.             throw new DriverRegistroServiziException("[getGruppo]: Parametro non definito");    
  2017.         IDGruppo idGruppo = new IDGruppo(nomeGruppo);
  2018.        
  2019.         // se e' attiva una cache provo ad utilizzarla
  2020.         String key = null;  
  2021.         if(this.cache!=null){
  2022.             key = _getKey_getGruppo(nomeGruppo);
  2023.             org.openspcoop2.utils.cache.CacheResponse response =
  2024.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  2025.             if(response != null){
  2026.                 if(response.getException()!=null){
  2027.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  2028.                         throw (DriverRegistroServiziNotFound) response.getException();
  2029.                     else
  2030.                         throw (DriverRegistroServiziException) response.getException();
  2031.                 }else{
  2032.                     return ((Gruppo) response.getObject());
  2033.                 }
  2034.             }
  2035.         }


  2036.         // Algoritmo CACHE
  2037.         Gruppo gruppo = null;
  2038.         if(this.cache!=null){
  2039.             gruppo = (Gruppo) this.getObjectCache(key,"getGruppo",nomeRegistro,null,connectionPdD,idGruppo);
  2040.         }else{
  2041.             gruppo = (Gruppo) this.getObject("getGruppo",nomeRegistro,null,connectionPdD,idGruppo);
  2042.         }

  2043.         if(gruppo!=null)
  2044.             return gruppo;
  2045.         else
  2046.             throw new DriverRegistroServiziNotFound("[getGruppo] Gruppo ["+nomeGruppo+"] non trovato");

  2047.     }
  2048.    
  2049.    
  2050.    
  2051.     protected static String _getKey_getRuolo(String nomeRuolo) throws DriverRegistroServiziException{
  2052.         return "getRuolo_" + nomeRuolo;
  2053.     }
  2054.     public org.openspcoop2.core.registry.Ruolo getRuolo(Connection connectionPdD,String nomeRegistro,String nomeRuolo) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{
  2055.        
  2056.         // Raccolta dati
  2057.         if(nomeRuolo == null)
  2058.             throw new DriverRegistroServiziException("[getRuolo]: Parametro non definito");
  2059.         IDRuolo idRuolo = new IDRuolo(nomeRuolo);
  2060.        
  2061.         // se e' attiva una cache provo ad utilizzarla
  2062.         String key = null;  
  2063.         if(this.cache!=null){
  2064.             key = _getKey_getRuolo(nomeRuolo);
  2065.             org.openspcoop2.utils.cache.CacheResponse response =
  2066.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  2067.             if(response != null){
  2068.                 if(response.getException()!=null){
  2069.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  2070.                         throw (DriverRegistroServiziNotFound) response.getException();
  2071.                     else
  2072.                         throw (DriverRegistroServiziException) response.getException();
  2073.                 }else{
  2074.                     return ((Ruolo) response.getObject());
  2075.                 }
  2076.             }
  2077.         }


  2078.         // Algoritmo CACHE
  2079.         Ruolo ruolo = null;
  2080.         if(this.cache!=null){
  2081.             ruolo = (Ruolo) this.getObjectCache(key,"getRuolo",nomeRegistro,null,connectionPdD,idRuolo);
  2082.         }else{
  2083.             ruolo = (Ruolo) this.getObject("getRuolo",nomeRegistro,null,connectionPdD,idRuolo);
  2084.         }

  2085.         if(ruolo!=null)
  2086.             return ruolo;
  2087.         else
  2088.             throw new DriverRegistroServiziNotFound("[getRuolo] Ruolo ["+nomeRuolo+"] non trovato");

  2089.     }
  2090.    
  2091.    
  2092.     protected static String _getKey_getScope(String nomeScope) throws DriverRegistroServiziException{
  2093.         return "getScope_" + nomeScope;
  2094.     }
  2095.     public org.openspcoop2.core.registry.Scope getScope(Connection connectionPdD,String nomeRegistro,String nomeScope) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{
  2096.        
  2097.         // Raccolta dati
  2098.         if(nomeScope == null)
  2099.             throw new DriverRegistroServiziException("[getScope]: Parametro non definito");
  2100.         IDScope idScope = new IDScope(nomeScope);
  2101.        
  2102.         // se e' attiva una cache provo ad utilizzarla
  2103.         String key = null;  
  2104.         if(this.cache!=null){
  2105.             key = _getKey_getScope(nomeScope);
  2106.             org.openspcoop2.utils.cache.CacheResponse response =
  2107.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  2108.             if(response != null){
  2109.                 if(response.getException()!=null){
  2110.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  2111.                         throw (DriverRegistroServiziNotFound) response.getException();
  2112.                     else
  2113.                         throw (DriverRegistroServiziException) response.getException();
  2114.                 }else{
  2115.                     return ((Scope) response.getObject());
  2116.                 }
  2117.             }
  2118.         }


  2119.         // Algoritmo CACHE
  2120.         Scope scope = null;
  2121.         if(this.cache!=null){
  2122.             scope = (Scope) this.getObjectCache(key,"getScope",nomeRegistro,null,connectionPdD,idScope);
  2123.         }else{
  2124.             scope = (Scope) this.getObject("getScope",nomeRegistro,null,connectionPdD,idScope);
  2125.         }

  2126.         if(scope!=null)
  2127.             return scope;
  2128.         else
  2129.             throw new DriverRegistroServiziNotFound("[getScope] Scope ["+nomeScope+"] non trovato");

  2130.     }
  2131.    
  2132.     protected static String _getKey_getSoggetto(IDSoggetto idSoggetto) throws DriverRegistroServiziException{
  2133.         return "getSoggetto_" + idSoggetto.getTipo() +"/" + idSoggetto.getNome();
  2134.     }
  2135.     public Soggetto getSoggetto(Connection connectionPdD,String nomeRegistro,IDSoggetto idSoggetto) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{

  2136.         // Raccolta dati
  2137.         if(idSoggetto==null)
  2138.             throw new DriverRegistroServiziException("[getSoggetto] Parametro Non Valido");
  2139.         String tipoSP = idSoggetto.getTipo();
  2140.         String codiceSP = idSoggetto.getNome();
  2141.         if(tipoSP == null || codiceSP == null)
  2142.             throw new DriverRegistroServiziException("[getSoggetto] Parametri Non Validi");

  2143.         //  se e' attiva una cache provo ad utilizzarla
  2144.         String key = null;  
  2145.         if(this.cache!=null){
  2146.             key = _getKey_getSoggetto(idSoggetto);
  2147.             org.openspcoop2.utils.cache.CacheResponse response =
  2148.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  2149.             if(response != null){
  2150.                 if(response.getException()!=null){
  2151.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  2152.                         throw (DriverRegistroServiziNotFound) response.getException();
  2153.                     else
  2154.                         throw (DriverRegistroServiziException) response.getException();
  2155.                 }else{
  2156.                     return ((Soggetto) response.getObject());
  2157.                 }
  2158.             }
  2159.         }

  2160.         // Algoritmo CACHE
  2161.         Soggetto soggetto = null;
  2162.         if(this.cache!=null){
  2163.             soggetto = (Soggetto) this.getObjectCache(key,"getSoggetto",nomeRegistro,null,connectionPdD,idSoggetto);
  2164.         }else{
  2165.             soggetto = (Soggetto) this.getObject("getSoggetto",nomeRegistro,null,connectionPdD,idSoggetto);
  2166.         }

  2167.         if(soggetto!=null)
  2168.             return soggetto;
  2169.         else
  2170.             throw new DriverRegistroServiziNotFound("[getSoggetto] Soggetto non trovato");

  2171.     }

  2172.     protected static String _toKey_getSoggettoByCredenzialiBasicPrefix() {
  2173.         return "getSoggettoByCredenzialiBasic_";
  2174.     }
  2175.     private String _getKey_getSoggettoByCredenzialiBasic(String user,String password) throws DriverRegistroServiziException{
  2176.         return _toKey_getSoggettoByCredenzialiBasicPrefix() + user +"_" + password;
  2177.     }
  2178.     public Soggetto getSoggettoByCredenzialiBasic(Connection connectionPdD,String nomeRegistro,String user,String password, CryptConfig config) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{

  2179.         // Raccolta dati
  2180.         if(user==null)
  2181.             throw new DriverRegistroServiziException("[getSoggettoByCredenzialiBasic] Parametro user Non Valido");
  2182.         if(password==null)
  2183.             throw new DriverRegistroServiziException("[getSoggettoByCredenzialiBasic] Parametro password Non Valido");

  2184.         //  se e' attiva una cache provo ad utilizzarla
  2185.         String key = null;  
  2186.         if(this.cache!=null){
  2187.             key = this._getKey_getSoggettoByCredenzialiBasic(user, password);
  2188.             org.openspcoop2.utils.cache.CacheResponse response =
  2189.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  2190.             if(response != null){
  2191.                 if(response.getException()!=null){
  2192.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  2193.                         throw (DriverRegistroServiziNotFound) response.getException();
  2194.                     else
  2195.                         throw (DriverRegistroServiziException) response.getException();
  2196.                 }else{
  2197.                     return ((Soggetto) response.getObject());
  2198.                 }
  2199.             }
  2200.         }

  2201.         // Algoritmo CACHE
  2202.         Soggetto soggetto = null;
  2203.         if(this.cache!=null){
  2204.             soggetto = (Soggetto) this.getObjectCache(key,"getSoggettoByCredenzialiBasic",nomeRegistro,null,connectionPdD,user,password,config);
  2205.         }else{
  2206.             soggetto = (Soggetto) this.getObject("getSoggettoByCredenzialiBasic",nomeRegistro,null,connectionPdD,user,password,config);
  2207.         }

  2208.         if(soggetto!=null)
  2209.             return soggetto;
  2210.         else
  2211.             throw new DriverRegistroServiziNotFound("[getSoggettoByCredenzialiBasic] Soggetto non Trovato");

  2212.     }
  2213.    
  2214.     protected static String _toKey_getSoggettoByCredenzialiApiKeyPrefix(boolean appId) {
  2215.         return (appId ? "getSoggettoByCredenzialiMultipleApiKey_" : "getSoggettoByCredenzialiApiKey_");
  2216.     }
  2217.     private String _getKey_getSoggettoByCredenzialiApiKey(String user,String password, boolean appId) throws DriverRegistroServiziException{
  2218.         return _toKey_getSoggettoByCredenzialiApiKeyPrefix(appId) + user +"_" + password;
  2219.     }
  2220.     public Soggetto getSoggettoByCredenzialiApiKey(Connection connectionPdD,String nomeRegistro,String user,String password, boolean appId, CryptConfig config) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{

  2221.         // Raccolta dati
  2222.         if(user==null)
  2223.             throw new DriverRegistroServiziException("[getSoggettoByCredenzialiApiKey] Parametro user Non Valido");
  2224.         if(password==null)
  2225.             throw new DriverRegistroServiziException("[getSoggettoByCredenzialiApiKey] Parametro password Non Valido");

  2226.         //  se e' attiva una cache provo ad utilizzarla
  2227.         String key = null;  
  2228.         if(this.cache!=null){
  2229.             key = this._getKey_getSoggettoByCredenzialiApiKey(user, password, appId);
  2230.             org.openspcoop2.utils.cache.CacheResponse response =
  2231.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  2232.             if(response != null){
  2233.                 if(response.getException()!=null){
  2234.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  2235.                         throw (DriverRegistroServiziNotFound) response.getException();
  2236.                     else
  2237.                         throw (DriverRegistroServiziException) response.getException();
  2238.                 }else{
  2239.                     return ((Soggetto) response.getObject());
  2240.                 }
  2241.             }
  2242.         }

  2243.         // Algoritmo CACHE
  2244.         Soggetto soggetto = null;
  2245.         if(this.cache!=null){
  2246.             soggetto = (Soggetto) this.getObjectCache(key,"getSoggettoByCredenzialiApiKey",nomeRegistro,null,connectionPdD,user,password,appId,config);
  2247.         }else{
  2248.             soggetto = (Soggetto) this.getObject("getSoggettoByCredenzialiApiKey",nomeRegistro,null,connectionPdD,user,password,appId,config);
  2249.         }

  2250.         if(soggetto!=null)
  2251.             return soggetto;
  2252.         else
  2253.             throw new DriverRegistroServiziNotFound("[getSoggettoByCredenzialiApiKey] Soggetto non Trovato");

  2254.     }
  2255.    
  2256.     protected static String _toKey_getSoggettoByCredenzialiSslPrefix(boolean separator) {
  2257.         return "getSoggettoByCredenzialiSsl"+(separator?"_":"");
  2258.     }
  2259.     private String _getKey_getSoggettoByCredenzialiSsl(String aSubject, String Issuer){
  2260.         String key = _toKey_getSoggettoByCredenzialiSslPrefix(false);
  2261.         key = key +"_subject:"+aSubject;
  2262.         if(Issuer!=null) {
  2263.             key = key +"_issuer:"+Issuer;
  2264.         }
  2265.         else {
  2266.             key = key +"_issuer:nonDefinito";
  2267.         }
  2268.         return key;
  2269.     }
  2270.     public Soggetto getSoggettoByCredenzialiSsl(Connection connectionPdD,String nomeRegistro,String subject, String issuer) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{

  2271.         // Raccolta dati
  2272.         if(subject==null)
  2273.             throw new DriverRegistroServiziException("[getSoggettoByCredenzialiSsl] Parametro subject Non Valido");

  2274.         //  se e' attiva una cache provo ad utilizzarla
  2275.         String key = null;  
  2276.         if(this.cache!=null){
  2277.             key = this._getKey_getSoggettoByCredenzialiSsl(subject, issuer);
  2278.             org.openspcoop2.utils.cache.CacheResponse response =
  2279.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  2280.             if(response != null){
  2281.                 if(response.getException()!=null){
  2282.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  2283.                         throw (DriverRegistroServiziNotFound) response.getException();
  2284.                     else
  2285.                         throw (DriverRegistroServiziException) response.getException();
  2286.                 }else{
  2287.                     return ((Soggetto) response.getObject());
  2288.                 }
  2289.             }
  2290.         }

  2291.         // Algoritmo CACHE
  2292.         Class<?>[] classArguments = new Class[] {String.class, String.class};
  2293.         Object[]values = new Object[] {subject,issuer}; // passo gli argomenti tramite array poich' aIssuer puo' essere null
  2294.         Soggetto soggetto = null;
  2295.         if(this.cache!=null){
  2296.             soggetto = (Soggetto) this.getObjectCache(key,"getSoggettoByCredenzialiSsl",nomeRegistro,null,connectionPdD,classArguments, values);
  2297.         }else{
  2298.             soggetto = (Soggetto) this.getObject("getSoggettoByCredenzialiSsl",nomeRegistro,null,connectionPdD,classArguments, values);
  2299.         }

  2300.         if(soggetto!=null)
  2301.             return soggetto;
  2302.         else
  2303.             throw new DriverRegistroServiziNotFound("[getSoggettoByCredenzialiSsl] Soggetto non Trovato");

  2304.     }
  2305.    
  2306.     protected static String _toKey_getSoggettoByCredenzialiSslCertPrefix(boolean separator) {
  2307.         return "getSoggettoByCredenzialiSslCert"+(separator?"_":"");
  2308.     }
  2309.     private String _getKey_getSoggettoByCredenzialiSsl(CertificateInfo certificate, boolean strictVerifier) throws DriverRegistroServiziException{
  2310.         try {
  2311.             String key = _toKey_getSoggettoByCredenzialiSslCertPrefix(false);
  2312.             key = key +"_cert:"+certificate.digestBase64Encoded();
  2313.             key = key +"_strictVerifier:"+strictVerifier;
  2314.             return key;
  2315.         }catch(Exception e) {
  2316.             throw new DriverRegistroServiziException(e.getMessage(),e);
  2317.         }
  2318.     }
  2319.     public Soggetto getSoggettoByCredenzialiSsl(Connection connectionPdD,String nomeRegistro,CertificateInfo certificate, boolean strictVerifier) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{

  2320.         // Raccolta dati
  2321.         if(certificate==null)
  2322.             throw new DriverRegistroServiziException("[getSoggettoByCredenzialiSsl] Parametro certificate Non Valido");

  2323.         //  se e' attiva una cache provo ad utilizzarla
  2324.         String key = null;  
  2325.         if(this.cache!=null){
  2326.             key = this._getKey_getSoggettoByCredenzialiSsl(certificate, strictVerifier);
  2327.             org.openspcoop2.utils.cache.CacheResponse response =
  2328.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  2329.             if(response != null){
  2330.                 if(response.getException()!=null){
  2331.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  2332.                         throw (DriverRegistroServiziNotFound) response.getException();
  2333.                     else
  2334.                         throw (DriverRegistroServiziException) response.getException();
  2335.                 }else{
  2336.                     return ((Soggetto) response.getObject());
  2337.                 }
  2338.             }
  2339.         }

  2340.         // Algoritmo CACHE
  2341.         Class<?>[] classArguments = new Class[] {CertificateInfo.class, boolean.class};
  2342.         Object[]values = new Object[] {certificate , strictVerifier};
  2343.         Soggetto soggetto = null;
  2344.         if(this.cache!=null){
  2345.             soggetto = (Soggetto) this.getObjectCache(key,"getSoggettoByCredenzialiSsl",nomeRegistro,null,connectionPdD, classArguments, values);
  2346.         }else{
  2347.             soggetto = (Soggetto) this.getObject("getSoggettoByCredenzialiSsl",nomeRegistro,null,connectionPdD, classArguments, values);
  2348.         }

  2349.         if(soggetto!=null)
  2350.             return soggetto;
  2351.         else
  2352.             throw new DriverRegistroServiziNotFound("[getSoggettoByCredenzialiSsl] Soggetto non Trovato");

  2353.     }
  2354.    
  2355.     protected static String _toKey_getSoggettoByCredenzialiPrincipalPrefix() {
  2356.         return "getSoggettoByCredenzialiPrincipal_";
  2357.     }
  2358.     private String _getKey_getSoggettoByCredenzialiPrincipal(String principal) throws DriverRegistroServiziException{
  2359.         return _toKey_getSoggettoByCredenzialiPrincipalPrefix() + principal;
  2360.     }
  2361.     public Soggetto getSoggettoByCredenzialiPrincipal(Connection connectionPdD,String nomeRegistro,String principal) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{

  2362.         // Raccolta dati
  2363.         if(principal==null)
  2364.             throw new DriverRegistroServiziException("[getSoggettoByCredenzialiPrincipal] Parametro principal Non Valido");

  2365.         //  se e' attiva una cache provo ad utilizzarla
  2366.         String key = null;  
  2367.         if(this.cache!=null){
  2368.             key = this._getKey_getSoggettoByCredenzialiPrincipal(principal);
  2369.             org.openspcoop2.utils.cache.CacheResponse response =
  2370.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  2371.             if(response != null){
  2372.                 if(response.getException()!=null){
  2373.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  2374.                         throw (DriverRegistroServiziNotFound) response.getException();
  2375.                     else
  2376.                         throw (DriverRegistroServiziException) response.getException();
  2377.                 }else{
  2378.                     return ((Soggetto) response.getObject());
  2379.                 }
  2380.             }
  2381.         }

  2382.         // Algoritmo CACHE
  2383.         Soggetto soggetto = null;
  2384.         if(this.cache!=null){
  2385.             soggetto = (Soggetto) this.getObjectCache(key,"getSoggettoByCredenzialiPrincipal",nomeRegistro,null,connectionPdD,principal);
  2386.         }else{
  2387.             soggetto = (Soggetto) this.getObject("getSoggettoByCredenzialiPrincipal",nomeRegistro,null,connectionPdD,principal);
  2388.         }

  2389.         if(soggetto!=null)
  2390.             return soggetto;
  2391.         else
  2392.             throw new DriverRegistroServiziNotFound("[getSoggettoByCredenzialiPrincipal] Soggetto non Trovato");

  2393.     }
  2394.    
  2395.     protected static String _toKey_getAccordoServizioParteSpecificaPrefix(IDServizio idService) throws DriverRegistroServiziException{
  2396.         String servizio = idService.getNome();
  2397.         String tipoServizio = idService.getTipo();
  2398.         Integer versioneServizio = idService.getVersione();
  2399.         String tipoSogg = idService.getSoggettoErogatore().getTipo();
  2400.         String nomeSogg = idService.getSoggettoErogatore().getNome();
  2401.        
  2402.         String key = "getServizio_"+ tipoSogg +"/" + nomeSogg +
  2403.                 "_" + tipoServizio + "/" + servizio+"/"+versioneServizio.intValue();
  2404.        
  2405.         return key;
  2406.     }
  2407.     protected static String _getKey_getAccordoServizioParteSpecifica(IDServizio idService,Boolean readContenutiAllegati) throws DriverRegistroServiziException{
  2408.         String key = _toKey_getAccordoServizioParteSpecificaPrefix(idService);
  2409.         String azione = idService.getAzione();
  2410.         if(azione !=null)
  2411.             key = key + "_" + azione;      
  2412.         if(readContenutiAllegati!=null){
  2413.             key = key + "_READ-ALLEGATI("+readContenutiAllegati.booleanValue()+")";
  2414.         }
  2415.         return key;
  2416.     }
  2417.     public AccordoServizioParteSpecifica getAccordoServizioParteSpecifica(Connection connectionPdD,String nomeRegistro,IDServizio idService) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{
  2418.         return getAccordoServizioParteSpecifica(connectionPdD,nomeRegistro, idService, null);
  2419.     }
  2420.     public AccordoServizioParteSpecifica getAccordoServizioParteSpecifica(Connection connectionPdD,String nomeRegistro,IDServizio idService,Boolean readContenutiAllegati) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{

  2421.         // Raccolta dati
  2422.         if(idService == null)
  2423.             throw new DriverRegistroServiziException("[getAccordoServizioParteSpecifica] Parametro Non Valido");
  2424.         String servizio = idService.getNome();
  2425.         String tipoServizio = idService.getTipo();
  2426.         Integer versioneServizio = idService.getVersione();
  2427.         if(servizio == null || tipoServizio == null || versioneServizio==null)
  2428.             throw new DriverRegistroServiziException("[getAccordoServizioParteSpecifica] Parametri (Servizio) Non Validi");
  2429.         String tipoSogg = idService.getSoggettoErogatore().getTipo();
  2430.         String nomeSogg = idService.getSoggettoErogatore().getNome();
  2431.         if(tipoSogg == null || nomeSogg == null)
  2432.             throw new DriverRegistroServiziException("[getAccordoServizioParteSpecifica] Parametri (Soggetto) Non Validi");

  2433.         //  se e' attiva una cache provo ad utilizzarla
  2434.         String key = null;  
  2435.         if(this.cache!=null){
  2436.             key = _getKey_getAccordoServizioParteSpecifica(idService, readContenutiAllegati);
  2437.             org.openspcoop2.utils.cache.CacheResponse response =
  2438.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  2439.             if(response != null){
  2440.                 if(response.getException()!=null){
  2441.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  2442.                         throw (DriverRegistroServiziNotFound) response.getException();
  2443.                     else
  2444.                         throw (DriverRegistroServiziException) response.getException();
  2445.                 }else{
  2446.                     return ((AccordoServizioParteSpecifica) response.getObject());
  2447.                 }
  2448.             }
  2449.         }

  2450.         // Algoritmo CACHE
  2451.         AccordoServizioParteSpecifica serv = null;
  2452.         if(this.cache!=null){
  2453.             serv = (AccordoServizioParteSpecifica) this.getObjectCache(key,"getAccordoServizioParteSpecifica",nomeRegistro,readContenutiAllegati,connectionPdD,idService);
  2454.         }else{
  2455.             serv = (AccordoServizioParteSpecifica) this.getObject("getAccordoServizioParteSpecifica",nomeRegistro,readContenutiAllegati,connectionPdD,idService);
  2456.         }

  2457.         if(serv!=null)
  2458.             return serv;
  2459.         else
  2460.             throw new DriverRegistroServiziNotFound("[getAccordoServizioParteSpecifica] Servizio non trovato");
  2461.     }

  2462.     protected static String _toKey_getAccordoServizioParteSpecifica_ServizioCorrelato_prefix() throws DriverRegistroServiziException{
  2463.         return "getServizioCorrelato(RicercaPerAccordo)_";
  2464.     }
  2465.     protected static String _toKey_getAccordoServizioParteSpecifica_ServizioCorrelato(IDAccordoFactory idAccordoFactory, IDAccordo idAccordo) throws DriverRegistroServiziException{
  2466.         return "_"+idAccordoFactory.getUriFromIDAccordo(idAccordo)+"_";
  2467.     }
  2468.     private String _getKey_getAccordoServizioParteSpecifica_ServizioCorrelato(IDSoggetto idSoggetto, IDAccordo idAccordo,Boolean readContenutiAllegati) throws DriverRegistroServiziException{
  2469.         String key = _toKey_getAccordoServizioParteSpecifica_ServizioCorrelato_prefix() + idSoggetto.getTipo() +"/" + idSoggetto.getNome();
  2470.         key = key + _toKey_getAccordoServizioParteSpecifica_ServizioCorrelato(this.idAccordoFactory, idAccordo);
  2471.         if(readContenutiAllegati!=null){
  2472.             key = key + "READ-ALLEGATI("+readContenutiAllegati.booleanValue()+")";
  2473.         }
  2474.         return key;
  2475.     }
  2476.     public AccordoServizioParteSpecifica getAccordoServizioParteSpecifica_ServizioCorrelato(Connection connectionPdD,String nomeRegistro,IDSoggetto idSoggetto, IDAccordo idAccordo) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{
  2477.         return getAccordoServizioParteSpecifica_ServizioCorrelato(connectionPdD,nomeRegistro, idSoggetto, idAccordo,null);
  2478.     }
  2479.     public AccordoServizioParteSpecifica getAccordoServizioParteSpecifica_ServizioCorrelato(Connection connectionPdD,String nomeRegistro,
  2480.             IDSoggetto idSoggetto, IDAccordo idAccordo,Boolean readContenutiAllegati) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{

  2481.         // Raccolta dati
  2482.         if(idSoggetto == null)
  2483.             throw new DriverRegistroServiziException("[getAccordoServizioParteSpecifica_ServizioCorrelato] Parametro Non Valido");
  2484.         String nome = idSoggetto.getNome();
  2485.         String tipo = idSoggetto.getTipo();
  2486.         if(tipo == null || nome == null || idAccordo==null)
  2487.             throw new DriverRegistroServiziException("[getAccordoServizioParteSpecifica_ServizioCorrelato] Parametri Non Validi");

  2488.         //  se e' attiva una cache provo ad utilizzarla
  2489.         String key = null;  
  2490.         if(this.cache!=null){
  2491.             key = this._getKey_getAccordoServizioParteSpecifica_ServizioCorrelato(idSoggetto, idAccordo, readContenutiAllegati);
  2492.             org.openspcoop2.utils.cache.CacheResponse response =
  2493.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  2494.             if(response != null){
  2495.                 if(response.getException()!=null){
  2496.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  2497.                         throw (DriverRegistroServiziNotFound) response.getException();
  2498.                     else
  2499.                         throw (DriverRegistroServiziException) response.getException();
  2500.                 }else{
  2501.                     return ((AccordoServizioParteSpecifica) response.getObject());
  2502.                 }
  2503.             }
  2504.         }

  2505.         // Algoritmo CACHE
  2506.         AccordoServizioParteSpecifica servCorrelato = null;
  2507.         if(this.cache!=null){
  2508.             servCorrelato = (AccordoServizioParteSpecifica) this.getObjectCache(key,"getAccordoServizioParteSpecifica_ServizioCorrelato",nomeRegistro,readContenutiAllegati,connectionPdD,idSoggetto,idAccordo);
  2509.         }else{
  2510.             servCorrelato = (AccordoServizioParteSpecifica) this.getObject("getAccordoServizioParteSpecifica_ServizioCorrelato",nomeRegistro,readContenutiAllegati,connectionPdD,idSoggetto,idAccordo);
  2511.         }

  2512.         if(servCorrelato!=null)
  2513.             return servCorrelato;
  2514.         else
  2515.             throw new DriverRegistroServiziNotFound("[getAccordoServizioParteSpecifica_ServizioCorrelato] ServizioCorrelato non trovato");
  2516.     }
  2517.    
  2518.     protected static String _getKey_getAccordoCooperazione(IDAccordoCooperazioneFactory idAccordoCooperazioneFactory, IDAccordoCooperazione idAccordo,Boolean readContenutiAllegati) throws DriverRegistroServiziException{
  2519.         String uriAccordoCooperazione = idAccordoCooperazioneFactory.getUriFromIDAccordo(idAccordo);

  2520.         String key = "getAccordoCooperazione_" + uriAccordoCooperazione;  
  2521.         if(readContenutiAllegati!=null){
  2522.             key = key + "_READ-ALLEGATI("+readContenutiAllegati.booleanValue()+")";
  2523.         }
  2524.         return key;
  2525.     }
  2526.     public AccordoCooperazione getAccordoCooperazione(Connection connectionPdD,String nomeRegistro,IDAccordoCooperazione idAccordo) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{
  2527.         return getAccordoCooperazione(connectionPdD,nomeRegistro, idAccordo, null);
  2528.     }
  2529.     public AccordoCooperazione getAccordoCooperazione(Connection connectionPdD,String nomeRegistro,IDAccordoCooperazione idAccordo,Boolean readContenutiAllegati) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{

  2530.         // Raccolta dati
  2531.         if(idAccordo == null)
  2532.             throw new DriverRegistroServiziException("[getAccordoCooperazione]: Parametro non definito");  
  2533.         if(idAccordo.getNome() == null)
  2534.             throw new DriverRegistroServiziException("[getAccordoCooperazione]: Nome accordo di servizio non definito");    
  2535.        
  2536.         // se e' attiva una cache provo ad utilizzarla
  2537.         String key = null;  
  2538.         if(this.cache!=null){
  2539.             key = _getKey_getAccordoCooperazione(this.idAccordoCooperazioneFactory, idAccordo, readContenutiAllegati);
  2540.             org.openspcoop2.utils.cache.CacheResponse response =
  2541.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  2542.             if(response != null){
  2543.                 if(response.getException()!=null){
  2544.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  2545.                         throw (DriverRegistroServiziNotFound) response.getException();
  2546.                     else
  2547.                         throw (DriverRegistroServiziException) response.getException();
  2548.                 }else{
  2549.                     return ((AccordoCooperazione) response.getObject());
  2550.                 }
  2551.             }
  2552.         }

  2553.         // Algoritmo CACHE
  2554.         AccordoCooperazione ac = null;
  2555.         if(this.cache!=null){
  2556.             ac = (AccordoCooperazione) this.getObjectCache(key,"getAccordoCooperazione",nomeRegistro,readContenutiAllegati,connectionPdD,idAccordo);
  2557.         }else{
  2558.             ac = (AccordoCooperazione) this.getObject("getAccordoCooperazione",nomeRegistro,readContenutiAllegati,connectionPdD,idAccordo);
  2559.         }

  2560.         if(ac!=null)
  2561.             return ac;
  2562.         else
  2563.             throw new DriverRegistroServiziNotFound("[getAccordoCooperazione] Accordo non trovato");
  2564.     }

  2565.    
  2566.    
  2567.    
  2568.    
  2569.     /* ********  R I C E R C A  I D   E L E M E N T I   P R I M I T I V I  ******** */
  2570.    
  2571.     protected static String _toKey_getAllIdPorteDominio_method(){
  2572.         return "getAllIdPorteDominio";
  2573.     }
  2574.     @SuppressWarnings("unchecked")
  2575.     public List<String> getAllIdPorteDominio(Connection connectionPdD,String nomeRegistro,FiltroRicerca filtroRicerca) throws DriverRegistroServiziException, DriverRegistroServiziNotFound{
  2576.         return (List<String>) _getAllIdEngine(connectionPdD, nomeRegistro, filtroRicerca, _toKey_getAllIdPorteDominio_method());
  2577.     }
  2578.    
  2579.     protected static String _toKey_getAllIdGruppi_method(){
  2580.         return "getAllIdGruppi";
  2581.     }
  2582.     @SuppressWarnings("unchecked")
  2583.     public List<IDGruppo> getAllIdGruppi(Connection connectionPdD,String nomeRegistro,FiltroRicercaGruppi filtroRicerca) throws DriverRegistroServiziException, DriverRegistroServiziNotFound{
  2584.         return (List<IDGruppo>) _getAllIdEngine(connectionPdD, nomeRegistro, filtroRicerca, _toKey_getAllIdGruppi_method());
  2585.     }
  2586.    
  2587.     protected static String _toKey_getAllIdRuoli_method(){
  2588.         return "getAllIdRuoli";
  2589.     }
  2590.     @SuppressWarnings("unchecked")
  2591.     public List<IDRuolo> getAllIdRuoli(Connection connectionPdD,String nomeRegistro,FiltroRicercaRuoli filtroRicerca) throws DriverRegistroServiziException, DriverRegistroServiziNotFound{
  2592.         return (List<IDRuolo>) _getAllIdEngine(connectionPdD, nomeRegistro, filtroRicerca, _toKey_getAllIdRuoli_method());
  2593.     }
  2594.    
  2595.     protected static String _toKey_getAllIdScope_method(){
  2596.         return "getAllIdScope";
  2597.     }
  2598.     @SuppressWarnings("unchecked")
  2599.     public List<IDScope> getAllIdScope(Connection connectionPdD,String nomeRegistro,FiltroRicercaScope filtroRicerca) throws DriverRegistroServiziException, DriverRegistroServiziNotFound{
  2600.         return (List<IDScope>) _getAllIdEngine(connectionPdD, nomeRegistro, filtroRicerca, _toKey_getAllIdScope_method());
  2601.     }

  2602.     protected static String _toKey_getAllIdSoggetti_method(){
  2603.         return "getAllIdSoggetti";
  2604.     }
  2605.     @SuppressWarnings("unchecked")
  2606.     public List<IDSoggetto> getAllIdSoggetti(Connection connectionPdD,String nomeRegistro, FiltroRicercaSoggetti filtroRicerca) throws DriverRegistroServiziException, DriverRegistroServiziNotFound{
  2607.         return (List<IDSoggetto>) _getAllIdEngine(connectionPdD, nomeRegistro, filtroRicerca, _toKey_getAllIdSoggetti_method());
  2608.     }
  2609.    
  2610.     protected static String _toKey_getAllIdAccordiCooperazione_method(){
  2611.         return "getAllIdAccordiCooperazione";
  2612.     }
  2613.     @SuppressWarnings("unchecked")
  2614.     public List<IDAccordoCooperazione> getAllIdAccordiCooperazione(Connection connectionPdD,String nomeRegistro, FiltroRicercaAccordi filtroRicerca) throws DriverRegistroServiziException, DriverRegistroServiziNotFound{
  2615.         return (List<IDAccordoCooperazione>) _getAllIdEngine(connectionPdD, nomeRegistro, filtroRicerca, _toKey_getAllIdAccordiCooperazione_method());
  2616.     }
  2617.    
  2618.     protected static String _toKey_getAllIdAccordiServizioParteComune_method(){
  2619.         return "getAllIdAccordiServizioParteComune";
  2620.     }
  2621.     @SuppressWarnings("unchecked")
  2622.     public List<IDAccordo> getAllIdAccordiServizioParteComune(Connection connectionPdD,String nomeRegistro, FiltroRicercaAccordi filtroRicerca) throws DriverRegistroServiziException, DriverRegistroServiziNotFound{
  2623.         return (List<IDAccordo>) _getAllIdEngine(connectionPdD, nomeRegistro, filtroRicerca, _toKey_getAllIdAccordiServizioParteComune_method());
  2624.     }
  2625.    
  2626.     protected static String _toKey_getAllIdPortType_method(){
  2627.         return "getAllIdPortType";
  2628.     }
  2629.     @SuppressWarnings("unchecked")
  2630.     public List<IDPortType> getAllIdPortType(Connection connectionPdD,String nomeRegistro, FiltroRicercaPortTypes filtroRicerca) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{
  2631.         return (List<IDPortType>) _getAllIdEngine(connectionPdD, nomeRegistro, filtroRicerca, _toKey_getAllIdPortType_method());
  2632.     }
  2633.    
  2634.     protected static String _toKey_getAllIdAzionePortType_method(){
  2635.         return "getAllIdAzionePortType";
  2636.     }
  2637.     @SuppressWarnings("unchecked")
  2638.     public List<IDPortTypeAzione> getAllIdAzionePortType(Connection connectionPdD, String nomeRegistro, FiltroRicercaOperations filtroRicerca) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{
  2639.         return (List<IDPortTypeAzione>) _getAllIdEngine(connectionPdD, nomeRegistro, filtroRicerca, _toKey_getAllIdAzionePortType_method());
  2640.     }
  2641.    
  2642.     protected static String _toKey_getAllIdAzione_method(){
  2643.         return "getAllIdAzioneAccordo";
  2644.     }
  2645.     @SuppressWarnings("unchecked")
  2646.     public List<IDAccordoAzione> getAllIdAzioneAccordo(Connection connectionPdD, String nomeRegistro, FiltroRicercaAzioni filtroRicerca) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{
  2647.         return (List<IDAccordoAzione>) _getAllIdEngine(connectionPdD, nomeRegistro, filtroRicerca, _toKey_getAllIdAzione_method());
  2648.     }
  2649.    
  2650.     protected static String _toKey_getAllIdResource_method(){
  2651.         return "getAllIdResource";
  2652.     }
  2653.     @SuppressWarnings("unchecked")
  2654.     public List<IDResource> getAllIdResource(Connection connectionPdD, String nomeRegistro, FiltroRicercaResources filtroRicerca) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{
  2655.         return (List<IDResource>) _getAllIdEngine(connectionPdD, nomeRegistro, filtroRicerca, _toKey_getAllIdResource_method());
  2656.     }
  2657.    
  2658.     protected static String _toKey_getAllIdServizi_method(){
  2659.         return "getAllIdServizi";
  2660.     }
  2661.     @SuppressWarnings("unchecked")
  2662.     public List<IDServizio> getAllIdServizi(Connection connectionPdD, String nomeRegistro, FiltroRicercaServizi filtroRicerca) throws DriverRegistroServiziException, DriverRegistroServiziNotFound{
  2663.         return (List<IDServizio>) _getAllIdEngine(connectionPdD, nomeRegistro, filtroRicerca, _toKey_getAllIdServizi_method());
  2664.     }
  2665.    
  2666.     protected static String _toKey_getAllIdFruizioniServizio_method(){
  2667.         return "getAllIdFruizioniServizio";
  2668.     }
  2669.     @SuppressWarnings("unchecked")
  2670.     public List<IDFruizione> getAllIdFruizioniServizio(Connection connectionPdD, String nomeRegistro, FiltroRicercaFruizioniServizio filtroRicerca) throws DriverRegistroServiziException, DriverRegistroServiziNotFound{
  2671.         return (List<IDFruizione>) _getAllIdEngine(connectionPdD, nomeRegistro, filtroRicerca, _toKey_getAllIdFruizioniServizio_method());
  2672.     }
  2673.    
  2674.     private List<?> _getAllIdEngine(Connection connectionPdD,String nomeRegistro,Object filtroRicerca,String nomeMetodo) throws DriverRegistroServiziException, DriverRegistroServiziNotFound{
  2675.        
  2676.         // Raccolta dati
  2677.         if(filtroRicerca == null)
  2678.             throw new DriverRegistroServiziException("["+nomeMetodo+"]: Parametro non definito");  

  2679.         // se e' attiva una cache provo ad utilizzarla
  2680.         String key = null;  
  2681.         if(this.cache!=null){
  2682.             key = nomeMetodo+"_" + filtroRicerca.toString();  
  2683.             org.openspcoop2.utils.cache.CacheResponse response =
  2684.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  2685.             if(response != null){
  2686.                 if(response.getException()!=null){
  2687.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  2688.                         throw (DriverRegistroServiziNotFound) response.getException();
  2689.                     else
  2690.                         throw (DriverRegistroServiziException) response.getException();
  2691.                 }else{
  2692.                     return ((List<?>) response.getObject());
  2693.                 }
  2694.             }
  2695.         }

  2696.         // Algoritmo CACHE
  2697.         List<?> list = null;
  2698.         if(this.cache!=null){
  2699.             list = (List<?>) this.getObjectCache(key,nomeMetodo,nomeRegistro,null,connectionPdD,filtroRicerca);
  2700.         }else{
  2701.             list = (List<?>) this.getObject(nomeMetodo,nomeRegistro,null,connectionPdD,filtroRicerca);
  2702.         }

  2703.         if(list!=null)
  2704.             return list;
  2705.         else
  2706.             throw new DriverRegistroServiziNotFound("["+nomeMetodo+"] Elementi non trovati");
  2707.     }
  2708.    
  2709.    
  2710.    
  2711.    
  2712.    
  2713.     /* ********  R I C E R C A  D O C U M E N T I  ******** */
  2714.    
  2715.     protected static String _toKey_prefixGetAllegatoAccordoServizioParteComune(IDAccordo idAccordo){
  2716.         return "getAllegatoAccordoServizioParteComune_"+idAccordo.toString()+"_";
  2717.     }
  2718.     protected static String getKeyGetAllegatoAccordoServizioParteComune(IDAccordo idAccordo, RuoliDocumento ruolo, Object tipo, String nome){
  2719.         StringBuilder key = new StringBuilder(_toKey_prefixGetAllegatoAccordoServizioParteComune(idAccordo));
  2720.         key.append(ruolo.toString());
  2721.         if(tipo!=null) {
  2722.             key.append("_").append(tipo.toString());
  2723.         }
  2724.         key.append("_").append(nome);
  2725.         return key.toString();
  2726.     }
  2727.    
  2728.     protected Documento getAllegato(Connection connectionPdD, String nomeRegistro, IDAccordo idAccordo, String nome,
  2729.             RequestInfo requestInfo) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{
  2730.         return _getAllegatoAccordoServizioParteComune(connectionPdD, nomeRegistro, "getAllegato",
  2731.                 idAccordo,
  2732.                 RuoliDocumento.allegato, null, nome,
  2733.                 requestInfo);
  2734.     }
  2735.     protected Documento getSpecificaSemiformale(Connection connectionPdD, String nomeRegistro, IDAccordo idAccordo, TipiDocumentoSemiformale tipo, String nome,
  2736.             RequestInfo requestInfo)throws DriverRegistroServiziException,DriverRegistroServiziNotFound{
  2737.         return _getAllegatoAccordoServizioParteComune(connectionPdD, nomeRegistro, "getSpecificaSemiformale",
  2738.                 idAccordo,
  2739.                 RuoliDocumento.specificaSemiformale, tipo, nome,
  2740.                 requestInfo);
  2741.     }
  2742.    
  2743.     private Documento _getAllegatoAccordoServizioParteComune(Connection connectionPdD, String nomeRegistro, String nomeMetodo,
  2744.             IDAccordo idAccordo,
  2745.             RuoliDocumento ruolo, Object tipo, String nome,
  2746.             RequestInfo requestInfo) throws DriverRegistroServiziException,DriverRegistroServiziNotFound {
  2747.                    
  2748.         String key = getKeyGetAllegatoAccordoServizioParteComune(idAccordo, ruolo, tipo, nome);  
  2749.        
  2750.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null;
  2751.         if(useRequestInfo) {
  2752.             Documento doc = requestInfo.getRequestConfig().getAllegatoApi(key);
  2753.             if(doc!=null) {
  2754.                 return doc;
  2755.             }
  2756.         }
  2757.        
  2758.         Documento doc = _getAllegatoAccordoServizioParteComune(connectionPdD, nomeRegistro, nomeMetodo,
  2759.                 idAccordo,
  2760.                 ruolo, tipo, nome,
  2761.                 key);
  2762.         if(useRequestInfo && requestInfo!=null) {
  2763.             requestInfo.getRequestConfig().addAllegatoApi(key, doc,
  2764.                     requestInfo.getIdTransazione());
  2765.         }
  2766.         return doc;
  2767.     }
  2768.     private Documento _getAllegatoAccordoServizioParteComune(Connection connectionPdD, String nomeRegistro, String nomeMetodo,
  2769.             IDAccordo idAccordo,
  2770.             RuoliDocumento ruolo, Object tipo, String nome,
  2771.             String key) throws DriverRegistroServiziException,DriverRegistroServiziNotFound {
  2772.        
  2773.         // Raccolta dati
  2774.         if(idAccordo == null || ruolo==null || nome == null)
  2775.             throw new DriverRegistroServiziException("["+nomeMetodo+"]: Parametri non definito");
  2776.         if(!RuoliDocumento.allegato.equals(ruolo)) {
  2777.             if(tipo==null) {
  2778.                 throw new DriverRegistroServiziException("["+nomeMetodo+"]: Tipo documento definito");
  2779.             }
  2780.         }

  2781.         // se e' attiva una cache provo ad utilizzarla
  2782.         if(this.cache!=null){
  2783.             org.openspcoop2.utils.cache.CacheResponse response =
  2784.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  2785.             if(response != null){
  2786.                 if(response.getException()!=null){
  2787.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  2788.                         throw (DriverRegistroServiziNotFound) response.getException();
  2789.                     else
  2790.                         throw (DriverRegistroServiziException) response.getException();
  2791.                 }else{
  2792.                     return ((Documento) response.getObject());
  2793.                 }
  2794.             }
  2795.         }

  2796.         // Algoritmo CACHE
  2797.         Documento documento = null;
  2798.         if(RuoliDocumento.allegato.equals(ruolo)) {
  2799.             if(this.cache!=null){
  2800.                 documento = (Documento) this.getObjectCache(key,nomeMetodo,nomeRegistro,null,connectionPdD, idAccordo, nome);
  2801.             }else{
  2802.                 documento = (Documento) this.getObject(nomeMetodo,nomeRegistro,null,connectionPdD, idAccordo, nome);
  2803.             }
  2804.         }
  2805.         else {
  2806.             if(this.cache!=null){
  2807.                 documento = (Documento) this.getObjectCache(key,nomeMetodo,nomeRegistro,null,connectionPdD, idAccordo, tipo, nome);
  2808.             }else{
  2809.                 documento = (Documento) this.getObject(nomeMetodo,nomeRegistro,null,connectionPdD, idAccordo, tipo, nome);
  2810.             }
  2811.         }

  2812.         if(documento!=null)
  2813.             return documento;
  2814.         else
  2815.             throw new DriverRegistroServiziNotFound("["+nomeMetodo+"] Documento non trovato");
  2816.        
  2817.     }
  2818.    
  2819.    
  2820.    
  2821.     protected static String _toKey_prefixGetAllegatoAccordoServizioParteSpecifica(IDServizio idServizio){
  2822.         return "getAllegatoAccordoServizioParteSpecifica_"+idServizio.toString(false)+"_";
  2823.     }
  2824.     protected static String getKeyGetAllegatoAccordoServizioParteSpecifica(IDServizio idServizio, RuoliDocumento ruolo, Object tipo, String nome){
  2825.         StringBuilder key = new StringBuilder(_toKey_prefixGetAllegatoAccordoServizioParteSpecifica(idServizio));
  2826.         key.append(ruolo.toString());
  2827.         if(tipo!=null) {
  2828.             key.append("_").append(tipo.toString());
  2829.         }
  2830.         key.append("_").append(nome);
  2831.         return key.toString();
  2832.     }
  2833.    
  2834.     protected Documento getAllegato(Connection connectionPdD, String nomeRegistro, IDServizio idServizio, String nome,
  2835.             RequestInfo requestInfo) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{
  2836.         return _getAllegatoAccordoServizioParteSpecifica(connectionPdD, nomeRegistro, "getAllegato",
  2837.                 idServizio,
  2838.                 RuoliDocumento.allegato, null, nome,
  2839.                 requestInfo);
  2840.     }
  2841.     protected Documento getSpecificaSemiformale(Connection connectionPdD, String nomeRegistro, IDServizio idServizio, TipiDocumentoSemiformale tipo, String nome,
  2842.             RequestInfo requestInfo)throws DriverRegistroServiziException,DriverRegistroServiziNotFound{
  2843.         return _getAllegatoAccordoServizioParteSpecifica(connectionPdD, nomeRegistro, "getSpecificaSemiformale",
  2844.                 idServizio,
  2845.                 RuoliDocumento.specificaSemiformale, tipo, nome,
  2846.                 requestInfo);
  2847.     }
  2848.     protected Documento getSpecificaSicurezza(Connection connectionPdD, String nomeRegistro,  IDServizio idServizio, TipiDocumentoSicurezza tipo, String nome,
  2849.             RequestInfo requestInfo)throws DriverRegistroServiziException,DriverRegistroServiziNotFound{
  2850.         return _getAllegatoAccordoServizioParteSpecifica(connectionPdD, nomeRegistro, "getSpecificaSicurezza",
  2851.                 idServizio,
  2852.                 RuoliDocumento.specificaSicurezza, tipo, nome,
  2853.                 requestInfo);
  2854.     }
  2855.     protected Documento getSpecificaLivelloServizio(Connection connectionPdD, String nomeRegistro,  IDServizio idServizio, TipiDocumentoLivelloServizio tipo, String nome,
  2856.             RequestInfo requestInfo)throws DriverRegistroServiziException,DriverRegistroServiziNotFound{
  2857.         return _getAllegatoAccordoServizioParteSpecifica(connectionPdD, nomeRegistro, "getSpecificaLivelloServizio",
  2858.                 idServizio,
  2859.                 RuoliDocumento.specificaSicurezza, tipo, nome,
  2860.                 requestInfo);
  2861.     }
  2862.    
  2863.     private Documento _getAllegatoAccordoServizioParteSpecifica(Connection connectionPdD, String nomeRegistro, String nomeMetodo,
  2864.             IDServizio idServizio,
  2865.             RuoliDocumento ruolo, Object tipo, String nome,
  2866.             RequestInfo requestInfo) throws DriverRegistroServiziException,DriverRegistroServiziNotFound {
  2867.    
  2868.         String key = getKeyGetAllegatoAccordoServizioParteSpecifica(idServizio, ruolo, tipo, nome);  
  2869.    
  2870.         boolean useRequestInfo = requestInfo!=null && requestInfo.getRequestConfig()!=null;
  2871.         if(useRequestInfo) {
  2872.             Documento doc = requestInfo.getRequestConfig().getAllegatoServizio(key);
  2873.             if(doc!=null) {
  2874.                 return doc;
  2875.             }
  2876.         }
  2877.    
  2878.         Documento doc = _getAllegatoAccordoServizioParteSpecifica(connectionPdD, nomeRegistro, nomeMetodo,
  2879.                 idServizio,
  2880.                 ruolo, tipo, nome,
  2881.                 key);
  2882.         if(useRequestInfo && requestInfo!=null) {
  2883.             requestInfo.getRequestConfig().addAllegatoServizio(key, doc,
  2884.                     requestInfo.getIdTransazione());
  2885.         }
  2886.         return doc;
  2887.     }
  2888.     private Documento _getAllegatoAccordoServizioParteSpecifica(Connection connectionPdD, String nomeRegistro, String nomeMetodo,
  2889.             IDServizio idServizio,
  2890.             RuoliDocumento ruolo, Object tipo, String nome,
  2891.             String key) throws DriverRegistroServiziException,DriverRegistroServiziNotFound {
  2892.        
  2893.         // Raccolta dati
  2894.         if(idServizio == null || ruolo==null || nome == null)
  2895.             throw new DriverRegistroServiziException("["+nomeMetodo+"]: Parametri non definito");
  2896.         if(!RuoliDocumento.allegato.equals(ruolo)) {
  2897.             if(tipo==null) {
  2898.                 throw new DriverRegistroServiziException("["+nomeMetodo+"]: Tipo documento definito");
  2899.             }
  2900.         }

  2901.         // se e' attiva una cache provo ad utilizzarla
  2902.         if(this.cache!=null){
  2903.             org.openspcoop2.utils.cache.CacheResponse response =
  2904.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  2905.             if(response != null){
  2906.                 if(response.getException()!=null){
  2907.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  2908.                         throw (DriverRegistroServiziNotFound) response.getException();
  2909.                     else
  2910.                         throw (DriverRegistroServiziException) response.getException();
  2911.                 }else{
  2912.                     return ((Documento) response.getObject());
  2913.                 }
  2914.             }
  2915.         }

  2916.         // Algoritmo CACHE
  2917.         Documento documento = null;
  2918.         if(RuoliDocumento.allegato.equals(ruolo)) {
  2919.             if(this.cache!=null){
  2920.                 documento = (Documento) this.getObjectCache(key,nomeMetodo,nomeRegistro,null,connectionPdD, idServizio, nome);
  2921.             }else{
  2922.                 documento = (Documento) this.getObject(nomeMetodo,nomeRegistro,null,connectionPdD, idServizio, nome);
  2923.             }
  2924.         }
  2925.         else {
  2926.             if(this.cache!=null){
  2927.                 documento = (Documento) this.getObjectCache(key,nomeMetodo,nomeRegistro,null,connectionPdD, idServizio, tipo, nome);
  2928.             }else{
  2929.                 documento = (Documento) this.getObject(nomeMetodo,nomeRegistro,null,connectionPdD, idServizio, tipo, nome);
  2930.             }
  2931.         }

  2932.         if(documento!=null)
  2933.             return documento;
  2934.         else
  2935.             throw new DriverRegistroServiziNotFound("["+nomeMetodo+"] Documento non trovato");
  2936.        
  2937.     }
  2938.    
  2939.    
  2940.    

  2941.     /**
  2942.      * Si occupa di ritornare l'oggetto {@link org.openspcoop2.core.registry.RegistroServizi},
  2943.      * identificato grazie al parametro
  2944.      * <var>idSoggetto</var> di tipo {@link org.openspcoop2.core.id.IDSoggetto}.
  2945.      * Il connettore viene ricercato come definizione esterna, al soggetto (xml nel registro direttamente)
  2946.      *
  2947.      * @return l'oggetto di tipo {@link org.openspcoop2.core.registry.RegistroServizi} se la ricerca nel registro ha successo,
  2948.      *         null altrimenti.
  2949.      *
  2950.      */
  2951.     public org.openspcoop2.core.registry.RegistroServizi[] getRegistriServiziXML(){
  2952.         if(this.registriXML.size()>0){
  2953.             org.openspcoop2.core.registry.RegistroServizi[] r = new org.openspcoop2.core.registry.RegistroServizi[this.registriXML.size()];
  2954.             for(int i=0; i<this.registriXML.size(); i++){
  2955.                 r[i] = this.registriXML.get(i).getRegistroXML();
  2956.             }
  2957.             return r;
  2958.         }else{
  2959.             return null;
  2960.         }
  2961.     }










  2962.     protected static String _toKey_getWsdlAccordoServizioPrefix(){
  2963.         return "getWsdlAccordoServizio_";
  2964.     }
  2965.     protected static String _toKey_getWsdlAccordoServizioService(IDServizio idService){
  2966.         String servizio = idService.getNome();
  2967.         String tipoServizio = idService.getTipo();
  2968.         Integer versioneServizio = idService.getVersione();
  2969.         String tipoSogg = idService.getSoggettoErogatore().getTipo();
  2970.         String nomeSogg = idService.getSoggettoErogatore().getNome();
  2971.         return "_"+ tipoSogg +"/" + nomeSogg +
  2972.                 "_" + tipoServizio + "/" + servizio+"/"+versioneServizio.intValue()+"_";
  2973.     }
  2974.    
  2975.     /**
  2976.      * Si occupa di ritornare le informazioni sui wsdl di un servizio
  2977.      *
  2978.      * @param idService Identificatore del Servizio di tipo {@link org.openspcoop2.core.id.IDServizio}.
  2979.      * @return l'oggetto di tipo {@link org.openspcoop2.core.registry.wsdl.AccordoServizioWrapper} se la ricerca nel registro ha successo,
  2980.      *         null altrimenti.
  2981.      */
  2982.     public org.openspcoop2.core.registry.wsdl.AccordoServizioWrapper getWsdlAccordoServizio(Connection connectionPdD,String nomeRegistro,
  2983.             IDServizio idService,InformationApiSource infoWsdlSource,boolean buildSchemaXSD, boolean readDatiRegistro)
  2984.     throws DriverRegistroServiziException,DriverRegistroServiziNotFound{

  2985.         // Raccolta dati
  2986.         if(idService == null)
  2987.             throw new DriverRegistroServiziException("[getWsdlAccordoServizio] Parametro Non Valido");
  2988.         String servizio = idService.getNome();
  2989.         String tipoServizio = idService.getTipo();
  2990.         Integer versioneServizio = idService.getVersione();
  2991.         if(servizio == null || tipoServizio == null || versioneServizio==null)
  2992.             throw new DriverRegistroServiziException("[getWsdlAccordoServizio] Parametri (Servizio) Non Validi");
  2993.         String tipoSogg = idService.getSoggettoErogatore().getTipo();
  2994.         String nomeSogg = idService.getSoggettoErogatore().getNome();
  2995.         if(tipoSogg == null || nomeSogg == null)
  2996.             throw new DriverRegistroServiziException("[getWsdlAccordoServizio] Parametri (Soggetto) Non Validi");

  2997.         // se e' attiva una cache provo ad utilizzarla
  2998.         String key = null;  
  2999.         if(this.cache!=null){
  3000.             key = _toKey_getWsdlAccordoServizioPrefix()+infoWsdlSource.name()+
  3001.                     _toKey_getWsdlAccordoServizioService(idService)+
  3002.                     "schema_"+buildSchemaXSD+
  3003.                     "readDatiRegistro_"+readDatiRegistro;
  3004.             org.openspcoop2.utils.cache.CacheResponse response =
  3005.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  3006.             if(response != null){
  3007.                 if(response.getException()!=null){
  3008.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  3009.                         throw (DriverRegistroServiziNotFound) response.getException();
  3010.                     else
  3011.                         throw (DriverRegistroServiziException) response.getException();
  3012.                 }else{
  3013.                     return ((org.openspcoop2.core.registry.wsdl.AccordoServizioWrapper) response.getObject());
  3014.                 }
  3015.             }
  3016.         }

  3017.         // Algoritmo CACHE
  3018.         org.openspcoop2.core.registry.wsdl.AccordoServizioWrapper wsdlAS = null;
  3019.         if(this.cache!=null){
  3020.             wsdlAS = this.getAccordoServizioSoapCache(key, idService, infoWsdlSource, nomeRegistro, connectionPdD,buildSchemaXSD, readDatiRegistro);
  3021.         }else{
  3022.             wsdlAS = this.getAccordoServizioSoapEngine(idService, infoWsdlSource, nomeRegistro, connectionPdD,buildSchemaXSD, readDatiRegistro);
  3023.         }

  3024.         if(wsdlAS!=null)
  3025.             return wsdlAS;
  3026.         else
  3027.             throw new DriverRegistroServiziNotFound("[getWsdlAccordoServizio] WSDLAccordoServizio non trovato");
  3028.     }



  3029.     /**
  3030.      * Si occupa di effettuare una ricerca nei registri, e di inserire la ricerca in cache
  3031.      *
  3032.      * @param keyCache Chiave di ricerca in cache
  3033.      * @param idService ID del Servizio
  3034.      * @param nomeRegistro Nome del registro su cui effettuare la ricerca (null per tutti i registri)
  3035.      * @return l'oggetto se trovato, null altrimenti.
  3036.      *
  3037.      */
  3038.     private static org.openspcoop2.utils.Semaphore semaphore_getAccordoServizioSoapCache = new org.openspcoop2.utils.Semaphore("RegistroServizi_AccordoServizioSoap");
  3039.     private org.openspcoop2.core.registry.wsdl.AccordoServizioWrapper getAccordoServizioSoapCache(String keyCache,IDServizio idService,
  3040.             InformationApiSource infoWsdlSource,String nomeRegistro,Connection connectionPdD,boolean buildSchemaXSD,boolean readDatiRegistro) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{

  3041.         SemaphoreLock lock = semaphore_getAccordoServizioSoapCache.acquireThrowRuntime("getAccordoServizioSoapCache");
  3042.         DriverRegistroServiziNotFound dNotFound = null;
  3043.         org.openspcoop2.core.registry.wsdl.AccordoServizioWrapper obj = null;
  3044.         try{

  3045. //          System.out.println("@"+keyCache+"@ INFO CACHE: "+this.cache.toString());
  3046. //          System.out.println("@"+keyCache+"@ KEYS: \n\t"+this.cache.printKeys("\n\t"));
  3047.            
  3048.             // Raccolta dati
  3049.             if(keyCache == null)
  3050.                 throw new DriverRegistroServiziException("[getWSDLAccordoServizio]: KeyCache non definita");    

  3051.             // se e' attiva una cache provo ad utilizzarla
  3052.             if(this.cache!=null){
  3053.                 org.openspcoop2.utils.cache.CacheResponse response =
  3054.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(keyCache);
  3055.                 if(response != null){
  3056.                     if(response.getObject()!=null){
  3057.                         this.log.debug("Oggetto (tipo:"+response.getObject().getClass().getName()+") con chiave ["+keyCache+"] (method:getWSDLAccordoServizio) nel registro["+nomeRegistro+"] in cache.");
  3058.                         return (org.openspcoop2.core.registry.wsdl.AccordoServizioWrapper) response.getObject();
  3059.                     }else if(response.getException()!=null){
  3060.                         this.log.debug("Eccezione (tipo:"+response.getException().getClass().getName()+") con chiave ["+keyCache+"] (method:getWSDLAccordoServizio) nel registro["+nomeRegistro+"] in cache.");
  3061.                         throw (Exception) response.getException();
  3062.                     }else{
  3063.                         this.log.error("In cache non e' presente ne un oggetto ne un'eccezione.");
  3064.                     }
  3065.                 }
  3066.             }

  3067.             // Effettuo le query nella mia gerarchia di registri.
  3068.             this.log.debug("oggetto con chiave ["+keyCache+"] (method:WSDLAccordoServizio) nel registro["+nomeRegistro+"] non in cache, ricerco nel registro...");
  3069.             try{
  3070.                 obj = getAccordoServizioSoapEngine(idService, infoWsdlSource,nomeRegistro,connectionPdD,buildSchemaXSD,readDatiRegistro);
  3071.             }catch(DriverRegistroServiziNotFound e){
  3072.                 dNotFound = e;
  3073.             }

  3074.             // Aggiungo la risposta in cache (se esiste una cache)  
  3075.             // Se ho una eccezione aggiungo in cache solo una not found
  3076.             if( this.cache!=null ){    
  3077.                 if(obj!=null){
  3078.                     this.log.info("Aggiungo oggetto ["+keyCache+"] in cache");
  3079.                 }
  3080.                 else {
  3081.                 //  if(dNotFound!=null){
  3082.                     this.log.info("Aggiungo eccezione ["+keyCache+"] in cache");
  3083.                 }
  3084. //              else{
  3085. //                  throw new Exception("Metodo (WSDLAccordoServizio) nel registro["+nomeRegistro+"] ha ritornato un valore null");
  3086. //              }
  3087.                 try{    
  3088.                     org.openspcoop2.utils.cache.CacheResponse responseCache = new org.openspcoop2.utils.cache.CacheResponse();
  3089.                     if(dNotFound!=null){
  3090.                         responseCache.setException(dNotFound);
  3091.                     }else{
  3092.                         responseCache.setObject(obj);
  3093.                     }
  3094.                     this.cache.put(keyCache,responseCache);
  3095.                 }catch(UtilsException e){
  3096.                     this.log.error("Errore durante l'inserimento in cache ["+keyCache+"]: "+e.getMessage());
  3097.                 }
  3098.             }

  3099.         }catch(DriverRegistroServiziException e){
  3100.             throw e;
  3101.         }catch(DriverRegistroServiziNotFound e){
  3102.             throw e;
  3103.         }
  3104.         catch(Exception e){
  3105.             if(notFoundClassName.equals(e.getClass().getName()))
  3106.                 throw (DriverRegistroServiziNotFound) e;
  3107.             else
  3108.                 throw new DriverRegistroServiziException("RegistroServizi, Algoritmo di Cache fallito: "+e.getMessage(),e);
  3109.         }finally {
  3110.             semaphore_getAccordoServizioSoapCache.release(lock, "getAccordoServizioSoapCache");
  3111.         }

  3112.         if(dNotFound!=null){
  3113.             throw dNotFound;
  3114.         }else
  3115.             return obj;
  3116.     }


  3117.     /**
  3118.      * Si occupa di effettuare una ricerca nei registri
  3119.      *
  3120.      * @param idService ID del Servizio
  3121.      * @param nomeRegistro Nome del registro su cui effettuare la ricerca (null per tutti i registri)
  3122.      * @return l'oggetto se trovato, null altrimenti.
  3123.      *
  3124.      */
  3125.     private org.openspcoop2.core.registry.wsdl.AccordoServizioWrapper getAccordoServizioSoapEngine(IDServizio idService,InformationApiSource infoWsdlSource,
  3126.             String nomeRegistro,Connection connectionPdD,boolean buildSchemaXSD,boolean readDatiRegistro) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{

  3127.         _ASWrapperDati asWrapper = this.buildASWrapperDati(nomeRegistro, idService, connectionPdD, readDatiRegistro);
  3128.        
  3129.         // Effettuo le query nella mia gerarchia di registri.
  3130.         org.openspcoop2.core.registry.AccordoServizioParteSpecifica servizio = asWrapper.servizio;
  3131.         org.openspcoop2.core.registry.AccordoServizioParteComune as = asWrapper.as;

  3132.         //Recupero la classe specificata dal parametro passato
  3133.         boolean registroServiziDB = asWrapper.registroServiziDB;



  3134.         // Costruisco oggetto
  3135.         org.openspcoop2.core.registry.wsdl.AccordoServizioWrapper accordoServizioWrapper = new org.openspcoop2.core.registry.wsdl.AccordoServizioWrapper();

  3136.         IDAccordo idAccordo = this.idAccordoFactory.getIDAccordoFromAccordo(as);
  3137.         accordoServizioWrapper.setIdAccordoServizio(idAccordo);
  3138.        
  3139.         accordoServizioWrapper.setNomePortType(servizio.getPortType());
  3140.        
  3141.         accordoServizioWrapper.setTipologiaServizio(servizio.getTipologiaServizio());
  3142.        
  3143.         accordoServizioWrapper.setAccordoServizio(as);
  3144.        
  3145.         accordoServizioWrapper.setLocationWsdlImplementativoErogatore(servizio.getWsdlImplementativoErogatore());
  3146.         accordoServizioWrapper.setLocationWsdlImplementativoFruitore(servizio.getWsdlImplementativoFruitore());
  3147.         accordoServizioWrapper.setBytesWsdlImplementativoErogatore(servizio.getByteWsdlImplementativoErogatore());
  3148.         accordoServizioWrapper.setBytesWsdlImplementativoFruitore(servizio.getByteWsdlImplementativoFruitore());
  3149.        
  3150.         OpenSPCoop2MessageFactory defaultMessageFactory = OpenSPCoop2MessageFactory.getDefaultMessageFactory();
  3151.        
  3152.         AccordoServizioWrapperUtilities wsdlWrapperUtilities = new AccordoServizioWrapperUtilities(defaultMessageFactory, this.log);
  3153.         wsdlWrapperUtilities.setAccordoServizio(accordoServizioWrapper);
  3154.            
  3155.         if(buildSchemaXSD){
  3156.             try{
  3157.                 boolean buildFromBytes = registroServiziDB;
  3158.                 // buildFromBytes=false: Costruzione attraverso Location (versione XML,WEB,UDDI)
  3159.                 // buildFromBytes=true:  Costruzione attraverso bytes registrati sul DB
  3160.                 wsdlWrapperUtilities.buildSchema(buildFromBytes);
  3161.                
  3162.             }catch(DriverRegistroServiziException e){
  3163.                 throw new DriverRegistroServiziException("[SchemaXSD] "+e.getMessage(),e);
  3164.             }
  3165.         }

  3166.         try{
  3167.             if(InformationApiSource.SPECIFIC.equals(infoWsdlSource)){
  3168.                
  3169.                 this.log.debug("Costruisco WSDLAccordoServizio from WSDL...");
  3170.                 _loadFromWsdl(servizio, registroServiziDB, wsdlWrapperUtilities);
  3171.                
  3172.             }else if(InformationApiSource.REGISTRY.equals(infoWsdlSource)){
  3173.                
  3174.                 this.log.debug("Costruisco WSDLAccordoServizio from AccordoServizio...");
  3175.                 wsdlWrapperUtilities.buildAccordoServizioWrapperFromOpenSPCoopAS(as);
  3176.                
  3177.             }
  3178.             else if(InformationApiSource.SPECIFIC_REGISTRY.equals(infoWsdlSource) ||
  3179.                     InformationApiSource.SAFE_SPECIFIC_REGISTRY.equals(infoWsdlSource)){
  3180.            
  3181.                 this.log.debug("Costruisco WSDLAccordoServizio from WSDL (Step1)...");
  3182.                 try{
  3183.                     _loadFromWsdl(servizio, registroServiziDB, wsdlWrapperUtilities);
  3184.                 }catch(DriverRegistroServiziException e){
  3185.                     if(InformationApiSource.SPECIFIC_REGISTRY.equals(infoWsdlSource)){
  3186.                         throw e;
  3187.                     }
  3188.                 }
  3189.                
  3190.                 this.log.debug("Costruisco WSDLAccordoServizio from AccordoServizio (Step2)...");
  3191.                 AccordoServizioWrapperUtilities wsdlWrapperUtilitiesStep2 = new AccordoServizioWrapperUtilities(defaultMessageFactory, this.log);
  3192.                 AccordoServizioWrapper accordoServizioWrapperStep2 = accordoServizioWrapper.clone(false);
  3193.                 wsdlWrapperUtilitiesStep2.setAccordoServizio(accordoServizioWrapperStep2);
  3194.                 try{
  3195.                     wsdlWrapperUtilitiesStep2.buildAccordoServizioWrapperFromOpenSPCoopAS(as);
  3196.                 }catch(DriverRegistroServiziException e){
  3197.                     if(InformationApiSource.SPECIFIC_REGISTRY.equals(infoWsdlSource)){
  3198.                         throw e;
  3199.                     }
  3200.                 }
  3201.                
  3202.                 this.log.debug("Costruisco WSDLAccordoServizio merge WSDL e AccordoServizio (Step3)...");
  3203.                 _merge(accordoServizioWrapper, accordoServizioWrapperStep2);
  3204.                
  3205.             }
  3206.             else if(InformationApiSource.REGISTRY_SPECIFIC.equals(infoWsdlSource) ||
  3207.                     InformationApiSource.SAFE_REGISTRY_SPECIFIC.equals(infoWsdlSource)){
  3208.                
  3209.                 this.log.debug("Costruisco WSDLAccordoServizio from AccordoServizio (Step1)...");
  3210.                 try{
  3211.                     wsdlWrapperUtilities.buildAccordoServizioWrapperFromOpenSPCoopAS(as);
  3212.                 }catch(DriverRegistroServiziException e){
  3213.                     if(InformationApiSource.REGISTRY_SPECIFIC.equals(infoWsdlSource)){
  3214.                         throw e;
  3215.                     }
  3216.                 }
  3217.                
  3218.                 this.log.debug("Costruisco WSDLAccordoServizio from WSDL (Step2)...");
  3219.                 AccordoServizioWrapperUtilities wsdlWrapperUtilitiesStep2 = new AccordoServizioWrapperUtilities(defaultMessageFactory, this.log);
  3220.                 AccordoServizioWrapper accordoServizioWrapperStep2 = accordoServizioWrapper.clone(false);
  3221.                 wsdlWrapperUtilitiesStep2.setAccordoServizio(accordoServizioWrapperStep2);
  3222.                 try{
  3223.                     _loadFromWsdl(servizio, registroServiziDB, wsdlWrapperUtilitiesStep2);
  3224.                 }catch(DriverRegistroServiziException e){
  3225.                     if(InformationApiSource.REGISTRY_SPECIFIC.equals(infoWsdlSource)){
  3226.                         throw e;
  3227.                     }
  3228.                 }
  3229.                    
  3230.                 this.log.debug("Costruisco WSDLAccordoServizio merge  AccordoServizio e WSDL (Step3)...");
  3231.                 _merge(accordoServizioWrapper, accordoServizioWrapperStep2);
  3232.                                
  3233.             }
  3234.         }catch(DriverRegistroServiziException e){
  3235.             if(TipologiaServizio.CORRELATO.equals(servizio.getTipologiaServizio())){
  3236.                 throw new DriverRegistroServiziException("[WSDL-FRUITORE] "+e.getMessage(),e);
  3237.             }else{
  3238.                 throw new DriverRegistroServiziException("[WSDL-EROGATORE] "+e.getMessage(),e);
  3239.             }
  3240.         }

  3241.         this.log.debug("invocazione metodo getWSDLAccordoServizio completata.");
  3242.         return accordoServizioWrapper;
  3243.     }

  3244.     private void _loadFromWsdl(AccordoServizioParteSpecifica servizio, boolean registroServiziDB, AccordoServizioWrapperUtilities wsdlWrapperUtilities) throws DriverRegistroServiziException{
  3245.         if(TipologiaServizio.CORRELATO.equals(servizio.getTipologiaServizio())){
  3246.             javax.wsdl.Definition wsdlFruitore = null;
  3247.             if(registroServiziDB){
  3248.                 wsdlFruitore = wsdlWrapperUtilities.buildWsdlFruitoreFromBytes();
  3249.             }else{
  3250.                 wsdlFruitore = wsdlWrapperUtilities.buildWsdlFruitore();
  3251.             }
  3252.             boolean readParteImplementativa =
  3253.                 ( (servizio.getWsdlImplementativoFruitore()!=null) && ("".equals(servizio.getWsdlImplementativoFruitore())==false) )
  3254.                 ||
  3255.                 (servizio.getByteWsdlImplementativoFruitore()!=null)
  3256.                 ||
  3257.                 (wsdlFruitore.getAllBindings()!=null && wsdlFruitore.getAllBindings().size()>0)
  3258.                 ;
  3259.             wsdlWrapperUtilities.buildAccordoServizioWrapperFromWsdl(wsdlFruitore,readParteImplementativa);
  3260.         }else{
  3261.             javax.wsdl.Definition wsdlErogatore = null;
  3262.             if(registroServiziDB){
  3263.                 wsdlErogatore = wsdlWrapperUtilities.buildWsdlErogatoreFromBytes();
  3264.             }else{
  3265.                 wsdlErogatore = wsdlWrapperUtilities.buildWsdlErogatore();
  3266.             }
  3267.             boolean readParteImplementativa =    
  3268.                 ( (servizio.getWsdlImplementativoErogatore()!=null) && ("".equals(servizio.getWsdlImplementativoErogatore())==false) )
  3269.                 ||
  3270.                 (servizio.getByteWsdlImplementativoErogatore()!=null)
  3271.                 ||
  3272.                 (wsdlErogatore.getAllBindings()!=null && wsdlErogatore.getAllBindings().size()>0)
  3273.                 ;
  3274.             wsdlWrapperUtilities.buildAccordoServizioWrapperFromWsdl(wsdlErogatore,readParteImplementativa);
  3275.         }
  3276.     }
  3277.    
  3278.     private void _merge(AccordoServizioWrapper ptA, AccordoServizioWrapper ptB){
  3279.         for (int i = 0; i < ptB.sizePortTypeList(); i++) {
  3280.             PortType portTypeB = ptB.getPortType(i);
  3281.             boolean exists = false;
  3282.             for (int j = 0; j < ptA.sizePortTypeList(); j++) {
  3283.                 PortType portTypeA = ptA.getPortType(j);
  3284.                 if(portTypeB.getNome().equals(portTypeA.getNome())){
  3285.                    
  3286.                     // verifico le operation interne
  3287.                     for (Operation opB : portTypeB.getAzioneList()) {
  3288.                         boolean existsOperation = false;
  3289.                         for (Operation opA : portTypeA.getAzioneList()) {
  3290.                             if(opB.getNome().equals(opA.getNome())){
  3291.                                 existsOperation = true;
  3292.                                 break;
  3293.                             }
  3294.                         }
  3295.                         if(!existsOperation){
  3296.                             //System.out.println("ADD OP ["+opB.getNome()+"]");
  3297.                             portTypeA.addAzione(opB);
  3298.                         }
  3299.                     }
  3300.                    
  3301.                     exists = true;
  3302.                     break;
  3303.                 }
  3304.             }
  3305.             if(!exists){
  3306.                 //System.out.println("ADD PT ["+portTypeB.getNome()+"]");
  3307.                 ptA.addPortType(portTypeB);
  3308.             }
  3309.         }
  3310.        
  3311.     }
  3312.    
  3313.    
  3314.    
  3315.    
  3316.    
  3317.    
  3318.    
  3319.    
  3320.    
  3321.    
  3322.    
  3323.    
  3324.    
  3325.    
  3326.    
  3327.    
  3328.     protected static String _toKey_getRestAccordoServizioPrefix(){
  3329.         return "getRestAccordoServizio_";
  3330.     }
  3331.     protected static String _toKey_getRestAccordoServizioService(IDServizio idService){
  3332.         String servizio = idService.getNome();
  3333.         String tipoServizio = idService.getTipo();
  3334.         Integer versioneServizio = idService.getVersione();
  3335.         String tipoSogg = idService.getSoggettoErogatore().getTipo();
  3336.         String nomeSogg = idService.getSoggettoErogatore().getNome();
  3337.         return "_"+ tipoSogg +"/" + nomeSogg +
  3338.                 "_" + tipoServizio + "/" + servizio+"/"+versioneServizio.intValue()+"_";
  3339.     }
  3340.    
  3341.     /**
  3342.      * Si occupa di ritornare le informazioni sulla specifica REST di un servizio
  3343.      *
  3344.      * @param idService Identificatore del Servizio di tipo {@link org.openspcoop2.core.id.IDServizio}.
  3345.      * @return l'oggetto di tipo {@link org.openspcoop2.core.registry.rest.AccordoServizioWrapper} se la ricerca nel registro ha successo,
  3346.      *         null altrimenti.
  3347.      */
  3348.     public org.openspcoop2.core.registry.rest.AccordoServizioWrapper getRestAccordoServizio(Connection connectionPdD,String nomeRegistro,
  3349.             IDServizio idService,InformationApiSource infoWsdlSource,boolean buildSchemaXSD, boolean processIncludeForOpenApi, boolean readDatiRegistro)
  3350.     throws DriverRegistroServiziException,DriverRegistroServiziNotFound{

  3351.         // Raccolta dati
  3352.         if(idService == null)
  3353.             throw new DriverRegistroServiziException("[getRestAccordoServizio] Parametro Non Valido");
  3354.         String servizio = idService.getNome();
  3355.         String tipoServizio = idService.getTipo();
  3356.         Integer versioneServizio = idService.getVersione();
  3357.         if(servizio == null || tipoServizio == null || versioneServizio==null)
  3358.             throw new DriverRegistroServiziException("[getRestAccordoServizio] Parametri (Servizio) Non Validi");
  3359.         String tipoSogg = idService.getSoggettoErogatore().getTipo();
  3360.         String nomeSogg = idService.getSoggettoErogatore().getNome();
  3361.         if(tipoSogg == null || nomeSogg == null)
  3362.             throw new DriverRegistroServiziException("[getRestAccordoServizio] Parametri (Soggetto) Non Validi");

  3363.         // se e' attiva una cache provo ad utilizzarla
  3364.         String key = null;  
  3365.         if(this.cache!=null){
  3366.             key = _toKey_getRestAccordoServizioPrefix()+infoWsdlSource.name()+
  3367.             _toKey_getRestAccordoServizioService(idService)
  3368.             +"schema_"+buildSchemaXSD
  3369.             +"_processInclude_"+processIncludeForOpenApi
  3370.             +"_readDatiRegistro_"+readDatiRegistro;
  3371.             org.openspcoop2.utils.cache.CacheResponse response =
  3372.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  3373.             if(response != null){
  3374.                 if(response.getException()!=null){
  3375.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  3376.                         throw (DriverRegistroServiziNotFound) response.getException();
  3377.                     else
  3378.                         throw (DriverRegistroServiziException) response.getException();
  3379.                 }else{
  3380.                     return ((org.openspcoop2.core.registry.rest.AccordoServizioWrapper) response.getObject());
  3381.                 }
  3382.             }
  3383.         }

  3384.         // Algoritmo CACHE
  3385.         org.openspcoop2.core.registry.rest.AccordoServizioWrapper restAS = null;
  3386.         if(this.cache!=null){
  3387.             restAS = this.getAccordoServizioRestCache(key, idService, infoWsdlSource, nomeRegistro, connectionPdD,buildSchemaXSD, processIncludeForOpenApi, readDatiRegistro);
  3388.         }else{
  3389.             restAS = this.getAccordoServizioRestEngine(idService, infoWsdlSource, nomeRegistro, connectionPdD,buildSchemaXSD, processIncludeForOpenApi, readDatiRegistro);
  3390.         }

  3391.         if(restAS!=null)
  3392.             return restAS;
  3393.         else
  3394.             throw new DriverRegistroServiziNotFound("[getRestAccordoServizio] API non trovata");
  3395.     }



  3396.     /**
  3397.      * Si occupa di effettuare una ricerca nei registri, e di inserire la ricerca in cache
  3398.      *
  3399.      * @param keyCache Chiave di ricerca in cache
  3400.      * @param idService ID del Servizio
  3401.      * @param nomeRegistro Nome del registro su cui effettuare la ricerca (null per tutti i registri)
  3402.      * @return l'oggetto se trovato, null altrimenti.
  3403.      *
  3404.      */
  3405.     private static org.openspcoop2.utils.Semaphore semaphore_getAccordoServizioRestCache = new org.openspcoop2.utils.Semaphore("RegistroServizi_AccordoServizioRest");
  3406.     private org.openspcoop2.core.registry.rest.AccordoServizioWrapper getAccordoServizioRestCache(String keyCache,IDServizio idService,
  3407.             InformationApiSource infoWsdlSource,String nomeRegistro,Connection connectionPdD,boolean buildSchemaXSD, boolean processIncludeForOpenApi, boolean readDatiRegistro) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{

  3408.         SemaphoreLock lock = semaphore_getAccordoServizioRestCache.acquireThrowRuntime("getAccordoServizioRestCache");
  3409.         DriverRegistroServiziNotFound dNotFound = null;
  3410.         org.openspcoop2.core.registry.rest.AccordoServizioWrapper obj = null;
  3411.         try{

  3412. //          System.out.println("@"+keyCache+"@ INFO CACHE: "+this.cache.toString());
  3413. //          System.out.println("@"+keyCache+"@ KEYS: \n\t"+this.cache.printKeys("\n\t"));
  3414.            
  3415.             // Raccolta dati
  3416.             if(keyCache == null)
  3417.                 throw new DriverRegistroServiziException("[getRestAccordoServizio]: KeyCache non definita");    

  3418.             // se e' attiva una cache provo ad utilizzarla
  3419.             if(this.cache!=null){
  3420.                 org.openspcoop2.utils.cache.CacheResponse response =
  3421.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(keyCache);
  3422.                 if(response != null){
  3423.                     if(response.getObject()!=null){
  3424.                         this.log.debug("Oggetto (tipo:"+response.getObject().getClass().getName()+") con chiave ["+keyCache+"] (method:getRestAccordoServizio) nel registro["+nomeRegistro+"] in cache.");
  3425.                         return (org.openspcoop2.core.registry.rest.AccordoServizioWrapper) response.getObject();
  3426.                     }else if(response.getException()!=null){
  3427.                         this.log.debug("Eccezione (tipo:"+response.getException().getClass().getName()+") con chiave ["+keyCache+"] (method:getRestAccordoServizio) nel registro["+nomeRegistro+"] in cache.");
  3428.                         throw (Exception) response.getException();
  3429.                     }else{
  3430.                         this.log.error("In cache non e' presente ne un oggetto ne un'eccezione.");
  3431.                     }
  3432.                 }
  3433.             }

  3434.             // Effettuo le query nella mia gerarchia di registri.
  3435.             this.log.debug("oggetto con chiave ["+keyCache+"] (method:getRestAccordoServizio) nel registro["+nomeRegistro+"] non in cache, ricerco nel registro...");
  3436.             try{
  3437.                 obj = getAccordoServizioRestEngine(idService, infoWsdlSource,nomeRegistro,connectionPdD,buildSchemaXSD, processIncludeForOpenApi,readDatiRegistro);
  3438.             }catch(DriverRegistroServiziNotFound e){
  3439.                 dNotFound = e;
  3440.             }

  3441.             // Aggiungo la risposta in cache (se esiste una cache)  
  3442.             // Se ho una eccezione aggiungo in cache solo una not found
  3443.             if( this.cache!=null ){    
  3444.                 if(obj!=null){
  3445.                     this.log.info("Aggiungo oggetto ["+keyCache+"] in cache");
  3446.                 }
  3447.                 else {
  3448.                 //  if(dNotFound!=null){
  3449.                     this.log.info("Aggiungo eccezione ["+keyCache+"] in cache");
  3450.                 }
  3451. //              else{
  3452. //                  throw new Exception("Metodo (getRestAccordoServizio) nel registro["+nomeRegistro+"] ha ritornato un valore null");
  3453. //              }
  3454.                 try{    
  3455.                     org.openspcoop2.utils.cache.CacheResponse responseCache = new org.openspcoop2.utils.cache.CacheResponse();
  3456.                     if(dNotFound!=null){
  3457.                         responseCache.setException(dNotFound);
  3458.                     }else{
  3459.                         responseCache.setObject(obj);
  3460.                     }
  3461.                     this.cache.put(keyCache,responseCache);
  3462.                 }catch(UtilsException e){
  3463.                     this.log.error("Errore durante l'inserimento in cache ["+keyCache+"]: "+e.getMessage());
  3464.                 }
  3465.             }

  3466.         }catch(DriverRegistroServiziException e){
  3467.             throw e;
  3468.         }catch(DriverRegistroServiziNotFound e){
  3469.             throw e;
  3470.         }
  3471.         catch(Exception e){
  3472.             if(notFoundClassName.equals(e.getClass().getName()))
  3473.                 throw (DriverRegistroServiziNotFound) e;
  3474.             else
  3475.                 throw new DriverRegistroServiziException("RegistroServizi, Algoritmo di Cache fallito: "+e.getMessage(),e);
  3476.         }finally {
  3477.             semaphore_getAccordoServizioRestCache.release(lock, "getAccordoServizioRestCache");
  3478.         }

  3479.         if(dNotFound!=null){
  3480.             throw dNotFound;
  3481.         }else
  3482.             return obj;
  3483.     }
  3484.    
  3485.     /**
  3486.      * Si occupa di effettuare una ricerca nei registri
  3487.      *
  3488.      * @param idService ID del Servizio
  3489.      * @param nomeRegistro Nome del registro su cui effettuare la ricerca (null per tutti i registri)
  3490.      * @return l'oggetto se trovato, null altrimenti.
  3491.      *
  3492.      */
  3493.     private org.openspcoop2.core.registry.rest.AccordoServizioWrapper getAccordoServizioRestEngine(IDServizio idService,InformationApiSource infoWsdlSource,
  3494.             String nomeRegistro,Connection connectionPdD,boolean buildSchemi,boolean processIncludeForOpenApi,
  3495.             boolean readDatiRegistro) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{


  3496.         _ASWrapperDati asWrapper = this.buildASWrapperDati(nomeRegistro, idService, connectionPdD,
  3497.                 readDatiRegistro);
  3498.        
  3499.         // Effettuo le query nella mia gerarchia di registri.
  3500.         org.openspcoop2.core.registry.AccordoServizioParteSpecifica servizio = asWrapper.servizio;
  3501.         org.openspcoop2.core.registry.AccordoServizioParteComune as = asWrapper.as;
  3502.         if(as==null) {
  3503.             throw new DriverRegistroServiziException("AS undefined");
  3504.         }

  3505.         //Recupero la classe specificata dal parametro passato
  3506.         boolean registroServiziDB = asWrapper.registroServiziDB;



  3507.         // Costruisco oggetto
  3508.         org.openspcoop2.core.registry.rest.AccordoServizioWrapper accordoServizioWrapper = new org.openspcoop2.core.registry.rest.AccordoServizioWrapper();

  3509.         IDAccordo idAccordo = this.idAccordoFactory.getIDAccordoFromAccordo(as);
  3510.         accordoServizioWrapper.setIdAccordoServizio(idAccordo);
  3511.        
  3512.         accordoServizioWrapper.setAccordoServizio(as);
  3513.         boolean processInclude = buildSchemi;
  3514.         if(buildSchemi && as!=null && FormatoSpecifica.OPEN_API_3.equals(as.getFormatoSpecifica())) {
  3515.             processInclude = processIncludeForOpenApi;
  3516.         }
  3517.        
  3518.         accordoServizioWrapper.setLocationSpecifica(as.getWsdlConcettuale());
  3519.         accordoServizioWrapper.setBytesSpecifica(as.getByteWsdlConcettuale());
  3520.        
  3521.         accordoServizioWrapper.setRegistroServiziDB(asWrapper.registroServiziDB);
  3522.        
  3523.         OpenSPCoop2MessageFactory defaultMessageFactory = OpenSPCoop2MessageFactory.getDefaultMessageFactory();
  3524.        
  3525.         org.openspcoop2.core.registry.rest.AccordoServizioWrapperUtilities wsdlWrapperUtilities =
  3526.                 new org.openspcoop2.core.registry.rest.AccordoServizioWrapperUtilities(defaultMessageFactory, this.log, accordoServizioWrapper);
  3527.            

  3528.         try{
  3529.             if(InformationApiSource.SPECIFIC.equals(infoWsdlSource)){
  3530.                
  3531.                 this.log.debug("Costruisco API tramite la specifica...");
  3532.                 wsdlWrapperUtilities.buildApiFromSpecific(registroServiziDB, buildSchemi, processInclude);
  3533.                
  3534.             }else if(InformationApiSource.REGISTRY.equals(infoWsdlSource)){
  3535.                
  3536.                 this.log.debug("Costruisco API tramite il registro...");
  3537.                 wsdlWrapperUtilities.buildApiFromRegistry(registroServiziDB, buildSchemi);
  3538.                
  3539.             }
  3540.             else if(InformationApiSource.SPECIFIC_REGISTRY.equals(infoWsdlSource) ||
  3541.                     InformationApiSource.SAFE_SPECIFIC_REGISTRY.equals(infoWsdlSource)){
  3542.            
  3543.                 this.log.debug("Costruisco API tramite la specifica (Step1)...");
  3544.                 try{
  3545.                     wsdlWrapperUtilities.buildApiFromSpecific(registroServiziDB, buildSchemi, processInclude);
  3546.                 }catch(DriverRegistroServiziException e){
  3547.                     if(InformationApiSource.SPECIFIC_REGISTRY.equals(infoWsdlSource)){
  3548.                         throw e;
  3549.                     }
  3550.                     else {
  3551.                         String errorMsg = "Costruisco API tramite il registro (Step1) error: "+e.getMessage();
  3552.                         if(org.openspcoop2.core.registry.rest.AccordoServizioWrapperUtilities.API_SENZA_SPECIFICA.equals(e.getMessage())) {
  3553.                             this.log.warn(errorMsg,e);
  3554.                         }
  3555.                         else {
  3556.                             this.log.error(errorMsg,e);
  3557.                         }
  3558.                     }
  3559.                 }
  3560.                
  3561.                 this.log.debug("Costruisco API tramite il registro (Step2)...");
  3562.                 org.openspcoop2.core.registry.rest.AccordoServizioWrapper accordoServizioWrapperStep2 = accordoServizioWrapper.clone();
  3563.                 org.openspcoop2.core.registry.rest.AccordoServizioWrapperUtilities wsdlWrapperUtilitiesStep2 =
  3564.                         new org.openspcoop2.core.registry.rest.AccordoServizioWrapperUtilities(defaultMessageFactory, this.log, accordoServizioWrapperStep2);
  3565.                 try{
  3566.                     wsdlWrapperUtilitiesStep2.buildApiFromRegistry(registroServiziDB, buildSchemi);
  3567.                 }catch(DriverRegistroServiziException e){
  3568.                     if(InformationApiSource.SPECIFIC_REGISTRY.equals(infoWsdlSource)){
  3569.                         throw e;
  3570.                     }
  3571.                     else {
  3572.                         String errorMsg = "Costruisco API tramite il registro (Step2) error: "+e.getMessage();
  3573.                         if(org.openspcoop2.core.registry.rest.AccordoServizioWrapperUtilities.API_SENZA_SPECIFICA.equals(e.getMessage())) {
  3574.                             this.log.warn(errorMsg,e);
  3575.                         }
  3576.                         else {
  3577.                             this.log.error(errorMsg,e);
  3578.                         }
  3579.                     }
  3580.                 }
  3581.                
  3582.                 this.log.debug("Costruisco API merge specifica e registro (Step3)...");
  3583.                 _merge(accordoServizioWrapper, accordoServizioWrapperStep2);
  3584.                
  3585.             }
  3586.             else if(InformationApiSource.REGISTRY_SPECIFIC.equals(infoWsdlSource) ||
  3587.                     InformationApiSource.SAFE_REGISTRY_SPECIFIC.equals(infoWsdlSource)){
  3588.                
  3589.                 this.log.debug("Costruisco API tramite il registro (Step1)...");
  3590.                 try{
  3591.                     wsdlWrapperUtilities.buildApiFromRegistry(registroServiziDB, buildSchemi);
  3592.                 }catch(DriverRegistroServiziException e){
  3593.                     if(InformationApiSource.REGISTRY_SPECIFIC.equals(infoWsdlSource)){
  3594.                         throw e;
  3595.                     }
  3596.                     else {
  3597.                         String errorMsg = "Costruisco API tramite il registro (Step1) error: "+e.getMessage();
  3598.                         if(org.openspcoop2.core.registry.rest.AccordoServizioWrapperUtilities.API_SENZA_SPECIFICA.equals(e.getMessage())) {
  3599.                             this.log.warn(errorMsg,e);
  3600.                         }
  3601.                         else {
  3602.                             this.log.error(errorMsg,e);
  3603.                         }
  3604.                     }
  3605.                 }
  3606.                
  3607.                 this.log.debug("Costruisco API tramite la specifica (Step2)...");
  3608.                 org.openspcoop2.core.registry.rest.AccordoServizioWrapper accordoServizioWrapperStep2 = accordoServizioWrapper.clone();
  3609.                 org.openspcoop2.core.registry.rest.AccordoServizioWrapperUtilities wsdlWrapperUtilitiesStep2 =
  3610.                         new org.openspcoop2.core.registry.rest.AccordoServizioWrapperUtilities(defaultMessageFactory, this.log, accordoServizioWrapperStep2);
  3611.                 try{
  3612.                     wsdlWrapperUtilitiesStep2.buildApiFromSpecific(registroServiziDB, buildSchemi, processInclude);
  3613.                 }catch(DriverRegistroServiziException e){
  3614.                     if(InformationApiSource.REGISTRY_SPECIFIC.equals(infoWsdlSource)){
  3615.                         throw e;
  3616.                     }
  3617.                     else {
  3618.                         String errorMsg = "Costruisco API tramite il registro (Step2) error: "+e.getMessage();
  3619.                         if(org.openspcoop2.core.registry.rest.AccordoServizioWrapperUtilities.API_SENZA_SPECIFICA.equals(e.getMessage())) {
  3620.                             this.log.warn(errorMsg,e);
  3621.                         }
  3622.                         else {
  3623.                             this.log.error(errorMsg,e);
  3624.                         }
  3625.                     }
  3626.                 }
  3627.                    
  3628.                 this.log.debug("Costruisco WSDLAccordoServizio merge  AccordoServizio e WSDL (Step3)...");
  3629.                 _merge(accordoServizioWrapper, accordoServizioWrapperStep2);
  3630.                                
  3631.             }
  3632.         }catch(DriverRegistroServiziException e){
  3633.             if(TipologiaServizio.CORRELATO.equals(servizio.getTipologiaServizio())){
  3634.                 throw new DriverRegistroServiziException("[CORRELATO] "+e.getMessage(),e);
  3635.             }else{
  3636.                 throw new DriverRegistroServiziException(e.getMessage(),e);
  3637.             }
  3638.         }

  3639.         this.log.debug("invocazione metodo getWSDLAccordoServizio completata.");
  3640.         return accordoServizioWrapper;
  3641.     }
  3642.    
  3643.     private void _merge(org.openspcoop2.core.registry.rest.AccordoServizioWrapper asAwrapper, org.openspcoop2.core.registry.rest.AccordoServizioWrapper asBwrapper){
  3644.         AccordoServizioParteComune asA = asAwrapper.getAccordoServizio();
  3645.         AccordoServizioParteComune asB = asBwrapper.getAccordoServizio();
  3646.         for (int i = 0; i < asB.sizeResourceList(); i++) {
  3647.             Resource resourceB = asB.getResource(i);
  3648.             boolean exists = false;
  3649.             for (int j = 0; j < asA.sizeResourceList(); j++) {
  3650.                 Resource resourceA = asA.getResource(j);
  3651.                 if(resourceB.getNome().equals(resourceA.getNome())){
  3652.                    
  3653.                     exists = true;
  3654.                     break;
  3655.                 }
  3656.             }
  3657.             if(!exists){
  3658.                 //System.out.println("ADD PT ["+portTypeB.getNome()+"]");
  3659.                 asA.addResource(resourceB);
  3660.             }
  3661.         }
  3662.        
  3663.         // merge API
  3664.         if(asAwrapper.getApi()==null) {
  3665.             asAwrapper.setApi(asBwrapper.getApi());
  3666.         }
  3667.         else {
  3668.             if(asBwrapper.getApi()!=null) {
  3669.                 for (int i = 0; i < asBwrapper.getApi().sizeOperations(); i++) {
  3670.                     ApiOperation apiOpB = asBwrapper.getApi().getOperation(i);
  3671.                     boolean exists = false;
  3672.                     for (int j = 0; j < asAwrapper.getApi().sizeOperations(); j++) {
  3673.                         ApiOperation apiOpA = asAwrapper.getApi().getOperation(j);
  3674.                        
  3675.                         if(apiOpA.getPath()==null) {
  3676.                             if(apiOpB.getPath()!=null) {
  3677.                                 continue;
  3678.                             }
  3679.                         }
  3680.                         else if(!apiOpA.getPath().equals(apiOpB.getPath())) {
  3681.                             continue;
  3682.                         }
  3683.                        
  3684.                         if(apiOpA.getHttpMethod()==null) {
  3685.                             if(apiOpB.getHttpMethod()!=null) {
  3686.                                 continue;
  3687.                             }
  3688.                         }
  3689.                         else {
  3690.                             if(apiOpB.getHttpMethod()==null) {
  3691.                                 continue;
  3692.                             }
  3693.                             if(!apiOpA.getHttpMethod().equals(apiOpB.getHttpMethod())) {
  3694.                                 continue;
  3695.                             }
  3696.                         }
  3697.                         exists = true;
  3698.                         break;
  3699.                     }
  3700.                     if(!exists){
  3701.                         //System.out.println("ADD OP ["+apiOpB.getHttpMethod()+"] ["+apiOpB.getPath()+"]");
  3702.                         asAwrapper.getApi().addOperation(apiOpB);
  3703.                     }
  3704.                 }
  3705.             }
  3706.         }
  3707.     }
  3708.    
  3709.    
  3710.    
  3711.    
  3712.    
  3713.     protected static String _getKey_getServiceBinding(IDServizio idService){
  3714.         String servizio = idService.getNome();
  3715.         String tipoServizio = idService.getTipo();
  3716.         Integer versioneServizio = idService.getVersione();
  3717.         String tipoSogg = idService.getSoggettoErogatore().getTipo();
  3718.         String nomeSogg = idService.getSoggettoErogatore().getNome();
  3719.         return "getServiceBinding_"+tipoSogg +"/" + nomeSogg +
  3720.                 "_" + tipoServizio + "/" + servizio+"/"+versioneServizio.intValue();
  3721.     }
  3722.     /**
  3723.      * Si occupa di ritornare il tipo di service binding del servizio
  3724.      *
  3725.      * @param idService Identificatore del Servizio di tipo {@link org.openspcoop2.core.id.IDServizio}.
  3726.      * @return l'oggetto di tipo {@link org.openspcoop2.core.registry.constants.ServiceBinding} se la ricerca nel registro ha successo,
  3727.      *         null altrimenti.
  3728.      */
  3729.     public org.openspcoop2.core.registry.constants.ServiceBinding getServiceBinding(Connection connectionPdD,String nomeRegistro,IDServizio idService)
  3730.     throws DriverRegistroServiziException,DriverRegistroServiziNotFound{

  3731.         // Raccolta dati
  3732.         if(idService == null)
  3733.             throw new DriverRegistroServiziException("[getServiceBinding] Parametro Non Valido");
  3734.         String servizio = idService.getNome();
  3735.         String tipoServizio = idService.getTipo();
  3736.         Integer versioneServizio = idService.getVersione();
  3737.         if(servizio == null || tipoServizio == null || versioneServizio==null)
  3738.             throw new DriverRegistroServiziException("[getServiceBinding] Parametri (Servizio) Non Validi");
  3739.         String tipoSogg = idService.getSoggettoErogatore().getTipo();
  3740.         String nomeSogg = idService.getSoggettoErogatore().getNome();
  3741.         if(tipoSogg == null || nomeSogg == null)
  3742.             throw new DriverRegistroServiziException("[getServiceBinding] Parametri (Soggetto) Non Validi");

  3743.         // se e' attiva una cache provo ad utilizzarla
  3744.         String key = null;  
  3745.         if(this.cache!=null){
  3746.             key = _getKey_getServiceBinding(idService);
  3747.             org.openspcoop2.utils.cache.CacheResponse response =
  3748.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  3749.             if(response != null){
  3750.                 if(response.getException()!=null){
  3751.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  3752.                         throw (DriverRegistroServiziNotFound) response.getException();
  3753.                     else
  3754.                         throw (DriverRegistroServiziException) response.getException();
  3755.                 }else{
  3756.                     return ((org.openspcoop2.core.registry.constants.ServiceBinding) response.getObject());
  3757.                 }
  3758.             }
  3759.         }

  3760.         // Algoritmo CACHE
  3761.         org.openspcoop2.core.registry.constants.ServiceBinding sb = null;
  3762.         if(this.cache!=null){
  3763.             sb = this.getServiceBindingCache(key, idService, nomeRegistro, connectionPdD);
  3764.         }else{
  3765.             sb = this.getServiceBindingEngine(idService, nomeRegistro, connectionPdD);
  3766.         }

  3767.         if(sb!=null)
  3768.             return sb;
  3769.         else
  3770.             throw new DriverRegistroServiziNotFound("[getServiceBinding] API non trovata");
  3771.     }



  3772.     /**
  3773.      * Si occupa di effettuare una ricerca nei registri, e di inserire la ricerca in cache
  3774.      *
  3775.      * @param keyCache Chiave di ricerca in cache
  3776.      * @param idService ID del Servizio
  3777.      * @param nomeRegistro Nome del registro su cui effettuare la ricerca (null per tutti i registri)
  3778.      * @return l'oggetto se trovato, null altrimenti.
  3779.      *
  3780.      */
  3781.     private static org.openspcoop2.utils.Semaphore semaphore_getServiceBindingCache = new org.openspcoop2.utils.Semaphore("RegistroServizi_ServiceBinding");
  3782.     private org.openspcoop2.core.registry.constants.ServiceBinding getServiceBindingCache(String keyCache,IDServizio idService,
  3783.             String nomeRegistro,Connection connectionPdD) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{

  3784.         SemaphoreLock lock = semaphore_getServiceBindingCache.acquireThrowRuntime("getServiceBindingCache");
  3785.         DriverRegistroServiziNotFound dNotFound = null;
  3786.         org.openspcoop2.core.registry.constants.ServiceBinding obj = null;
  3787.         try{

  3788. //          System.out.println("@"+keyCache+"@ INFO CACHE: "+this.cache.toString());
  3789. //          System.out.println("@"+keyCache+"@ KEYS: \n\t"+this.cache.printKeys("\n\t"));
  3790.            
  3791.             // Raccolta dati
  3792.             if(keyCache == null)
  3793.                 throw new DriverRegistroServiziException("[getServiceBinding]: KeyCache non definita");

  3794.             // se e' attiva una cache provo ad utilizzarla
  3795.             if(this.cache!=null){
  3796.                 org.openspcoop2.utils.cache.CacheResponse response =
  3797.                     (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(keyCache);
  3798.                 if(response != null){
  3799.                     if(response.getObject()!=null){
  3800.                         this.log.debug("Oggetto (tipo:"+response.getObject().getClass().getName()+") con chiave ["+keyCache+"] (method:getServiceBinding) nel registro["+nomeRegistro+"] in cache.");
  3801.                         return (org.openspcoop2.core.registry.constants.ServiceBinding) response.getObject();
  3802.                     }else if(response.getException()!=null){
  3803.                         this.log.debug("Eccezione (tipo:"+response.getException().getClass().getName()+") con chiave ["+keyCache+"] (method:getServiceBinding) nel registro["+nomeRegistro+"] in cache.");
  3804.                         throw (Exception) response.getException();
  3805.                     }else{
  3806.                         this.log.error("In cache non e' presente ne un oggetto ne un'eccezione.");
  3807.                     }
  3808.                 }
  3809.             }

  3810.             // Effettuo le query nella mia gerarchia di registri.
  3811.             this.log.debug("oggetto con chiave ["+keyCache+"] (method:getServiceBinding) nel registro["+nomeRegistro+"] non in cache, ricerco nel registro...");
  3812.             try{
  3813.                 obj = getServiceBindingEngine(idService, nomeRegistro,connectionPdD);
  3814.             }catch(DriverRegistroServiziNotFound e){
  3815.                 dNotFound = e;
  3816.             }

  3817.             // Aggiungo la risposta in cache (se esiste una cache)  
  3818.             // Se ho una eccezione aggiungo in cache solo una not found
  3819.             if( this.cache!=null ){    
  3820.                 if(dNotFound!=null){
  3821.                     this.log.info("Aggiungo eccezione ["+keyCache+"] in cache");
  3822.                 }else if(obj!=null){
  3823.                     this.log.info("Aggiungo oggetto ["+keyCache+"] in cache");
  3824.                 }else{
  3825.                     throw new Exception("Metodo (getServiceBinding) nel registro["+nomeRegistro+"] ha ritornato un valore null");
  3826.                 }
  3827.                 try{    
  3828.                     org.openspcoop2.utils.cache.CacheResponse responseCache = new org.openspcoop2.utils.cache.CacheResponse();
  3829.                     if(dNotFound!=null){
  3830.                         responseCache.setException(dNotFound);
  3831.                     }else{
  3832.                         responseCache.setObject(obj);
  3833.                     }
  3834.                     this.cache.put(keyCache,responseCache);
  3835.                 }catch(UtilsException e){
  3836.                     this.log.error("Errore durante l'inserimento in cache ["+keyCache+"]: "+e.getMessage());
  3837.                 }
  3838.             }

  3839.         }catch(DriverRegistroServiziException e){
  3840.             throw e;
  3841.         }catch(DriverRegistroServiziNotFound e){
  3842.             throw e;
  3843.         }
  3844.         catch(Exception e){
  3845.             if(notFoundClassName.equals(e.getClass().getName()))
  3846.                 throw (DriverRegistroServiziNotFound) e;
  3847.             else
  3848.                 throw new DriverRegistroServiziException("RegistroServizi, Algoritmo di Cache fallito: "+e.getMessage(),e);
  3849.         }finally {
  3850.             semaphore_getServiceBindingCache.release(lock, "getServiceBindingCache");
  3851.         }

  3852.         if(dNotFound!=null){
  3853.             throw dNotFound;
  3854.         }else
  3855.             return obj;
  3856.     }
  3857.    
  3858.     private org.openspcoop2.core.registry.constants.ServiceBinding getServiceBindingEngine(IDServizio idService, String nomeRegistro,Connection connectionPdD) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{
  3859.         _ASWrapperDati asWrapper = this.buildASWrapperDati(nomeRegistro, idService, connectionPdD,false);
  3860.         return asWrapper.as.getServiceBinding();
  3861.     }
  3862.    
  3863.    
  3864.    
  3865.    
  3866.    
  3867.    
  3868.     private _ASWrapperDati buildASWrapperDati(String nomeRegistro, IDServizio idService, Connection connectionPdD, boolean readDatiRegistro) throws DriverRegistroServiziNotFound, DriverRegistroServiziException {
  3869.             // Logger log, IDServizio idService, Connection connectionPdD, IDAccordoFactory idAccordoFactory) {
  3870.        
  3871.         _ASWrapperDati asWrapper = new _ASWrapperDati();
  3872.        
  3873.         if(nomeRegistro!=null){
  3874.             this.log.debug("Cerco wsdl nel registro ["+nomeRegistro+"]");
  3875.             try{
  3876.                 String uriServizio = IDServizioFactory.getInstance().getUriFromIDServizio(idService);
  3877.                
  3878.                 //org.openspcoop2.core.registry.driver.IDriverRegistroServiziGet driver = this.driverRegistroServizi.get(nomeRegistro);
  3879.                 org.openspcoop2.core.registry.driver.IDriverRegistroServiziGet driver = this.getDriver(connectionPdD, nomeRegistro);
  3880.                 this.log.debug("invocazione metodo getWSDLAccordoServizio (search servizio)...");
  3881.                 // ricerca servizio richiesto
  3882.                 try{
  3883.                     if(driver instanceof DriverRegistroServiziDB)
  3884.                         asWrapper.servizio = ((DriverRegistroServiziDB)driver).getAccordoServizioParteSpecifica(idService,true); // leggo contenuto allegati
  3885.                     else
  3886.                         asWrapper.servizio = driver.getAccordoServizioParteSpecifica(idService);    
  3887.                 }catch(DriverRegistroServiziNotFound e){
  3888.                     // ignore
  3889.                 }
  3890.                 if(asWrapper.servizio == null){
  3891.                     throw new DriverRegistroServiziNotFound("Servizio ["+uriServizio+"] non definito");
  3892.                 }
  3893.                 IDAccordo idAccordo = this.idAccordoFactory.getIDAccordoFromUri(asWrapper.servizio.getAccordoServizioParteComune());
  3894.                 this.log.debug("invocazione metodo getWSDLAccordoServizio (search accordo)...");
  3895.                 if(driver instanceof DriverRegistroServiziDB)
  3896.                     asWrapper.as = ((DriverRegistroServiziDB)driver).getAccordoServizioParteComune(idAccordo,true, readDatiRegistro); // leggo contenuto allegati
  3897.                 else
  3898.                     asWrapper.as = driver.getAccordoServizioParteComune(idAccordo);
  3899.                 if (asWrapper.as == null){
  3900.                     throw new DriverRegistroServiziNotFound("Accordo di servizio ["+idAccordo+"] associato al servizio ["+uriServizio+"] non presente nel registro");
  3901.                 }
  3902.                 if(asWrapper.servizio.getPortType()!=null && ("".equals(asWrapper.servizio.getPortType())==false)){
  3903.                     // verifico presenza portType in accordo di servizio
  3904.                     boolean findPortType = false;
  3905.                     for(int l=0;l<asWrapper.as.sizePortTypeList();l++){
  3906.                         if(asWrapper.servizio.getPortType().equals(asWrapper.as.getPortType(l).getNome())){
  3907.                             findPortType = true;
  3908.                             break;
  3909.                         }
  3910.                     }
  3911.                     if(findPortType==false){
  3912.                         throw new DriverRegistroServiziNotFound("PortType["+asWrapper.servizio.getPortType()+"] associato al servizio ["+uriServizio+"] non presente nell'Accordo di servizio ["+idAccordo+"]");
  3913.                     }
  3914.                 }

  3915.                 // trovato!
  3916.                 asWrapper.registroServiziDB = (driver instanceof DriverRegistroServiziDB);
  3917.                
  3918.             }catch(DriverRegistroServiziNotFound e){
  3919.                 // Non presente
  3920.                 this.log.debug("Ricerca nel registro non riuscita (metodo getWSDLAccordoServizio): "+e.getMessage());
  3921.                 throw e;
  3922.             }
  3923.             catch(Exception e){
  3924.                 // Non presente
  3925.                 this.log.debug("Ricerca nel registro ["+nomeRegistro+"] non riuscita, "+e.getMessage(),e);
  3926.                 throw new DriverRegistroServiziException(e.getMessage(),e);
  3927.             }

  3928.         }else{
  3929.             this.log.debug("Cerco nella mia gerarchia di registri");
  3930.             StringBuilder notFoundProblem = new StringBuilder();
  3931.             StringBuilder exceptionProblem = new StringBuilder();
  3932.             boolean find = false;
  3933.             for (String nomeRegInLista : this.driverRegistroServizi.keySet()) {
  3934.                 this.log.debug("Cerco nel registro con nome["+nomeRegInLista+"]");
  3935.                 try{
  3936.                     String uriServizio = IDServizioFactory.getInstance().getUriFromIDServizio(idService);
  3937.                    
  3938.                     //org.openspcoop2.core.registry.driver.IDriverRegistroServiziGet driver = this.driverRegistroServizi.get(nomeRegInLista);
  3939.                     org.openspcoop2.core.registry.driver.IDriverRegistroServiziGet driver = this.getDriver(connectionPdD, nomeRegInLista);
  3940.                     this.log.debug("invocazione metodo getWSDLAccordoServizio (search servizio) nel registro["+nomeRegInLista+"]...");
  3941.                     // ricerca servizio richiesto
  3942.                     try{
  3943.                         if(driver instanceof DriverRegistroServiziDB)
  3944.                             asWrapper.servizio = ((DriverRegistroServiziDB)driver).getAccordoServizioParteSpecifica(idService,true); // leggo contenuto allegati
  3945.                         else
  3946.                             asWrapper.servizio = driver.getAccordoServizioParteSpecifica(idService);    
  3947.                     }catch(DriverRegistroServiziNotFound e){
  3948.                         // ignore
  3949.                     }
  3950.                     if(asWrapper.servizio == null){
  3951.                         throw new DriverRegistroServiziNotFound("Servizio ["+uriServizio+"] non definito");
  3952.                     }
  3953.                     IDAccordo idAccordo = this.idAccordoFactory.getIDAccordoFromUri(asWrapper.servizio.getAccordoServizioParteComune());
  3954.                     this.log.debug("invocazione metodo getWSDLAccordoServizio (search accordo) nel registro["+nomeRegInLista+"]...");
  3955.                     if(driver instanceof DriverRegistroServiziDB)
  3956.                         asWrapper.as = ((DriverRegistroServiziDB)driver).getAccordoServizioParteComune(idAccordo,true,readDatiRegistro); // leggo contenuto allegati
  3957.                     else
  3958.                         asWrapper.as = driver.getAccordoServizioParteComune(idAccordo);
  3959.                     if (asWrapper.as == null){
  3960.                         throw new DriverRegistroServiziNotFound("Accordo di servizio ["+idAccordo+"] associato al servizio ["+uriServizio+"] non presente nel registro");
  3961.                     }
  3962.                     if(asWrapper.servizio.getPortType()!=null && ("".equals(asWrapper.servizio.getPortType())==false)){
  3963.                         // verifico presenza portType in accordo di servizio
  3964.                         boolean findPortType = false;
  3965.                         for(int l=0;l<asWrapper.as.sizePortTypeList();l++){
  3966.                             if(asWrapper.servizio.getPortType().equals(asWrapper.as.getPortType(l).getNome())){
  3967.                                 findPortType = true;
  3968.                                 break;
  3969.                             }
  3970.                         }
  3971.                         if(findPortType==false){
  3972.                             throw new DriverRegistroServiziNotFound("PortType["+asWrapper.servizio.getPortType()+"] associato al servizio ["+uriServizio+"] non presente nell'Accordo di servizio ["+idAccordo+"]");
  3973.                         }
  3974.                     }
  3975.                    
  3976.                     // trovato!
  3977.                     asWrapper.registroServiziDB = (driver instanceof DriverRegistroServiziDB);
  3978.                     find=true;

  3979.                 }catch(DriverRegistroServiziNotFound ed){
  3980.                     // Non presente
  3981.                     this.log.debug("Ricerca nel registro ["+nomeRegInLista+"] non riuscita (metodo getWSDLAccordoServizio): "+ed.getMessage());
  3982.                     notFoundProblem.append("\nRegistro["+nomeRegInLista+"], ricerca fallita: "+ed.getMessage());
  3983.                 }catch(Exception e){
  3984.                     // Non presente
  3985.                     this.log.debug("Ricerca nel registro ["+nomeRegInLista+"] non riuscita, "+e.getMessage(),e);
  3986.                     if(this.raggiungibilitaTotale)
  3987.                         throw new DriverRegistroServiziException(e.getMessage(),e);
  3988.                     else
  3989.                         exceptionProblem.append("\nRegistro["+nomeRegInLista+"], accesso non riuscito: "+e.getMessage());
  3990.                 }
  3991.                 if(find)
  3992.                     break;
  3993.             }

  3994.             this.log.debug("invocazione metodo getWSDLAccordoServizio completata.");
  3995.             if(find==false){
  3996.                 if(exceptionProblem.length()>0 && notFoundProblem.length()>0){
  3997.                     throw new DriverRegistroServiziException("getWSDLAccordoServizio:"+exceptionProblem.toString()+notFoundProblem.toString());
  3998.                 }else if(exceptionProblem.length()>0){
  3999.                     throw new DriverRegistroServiziException("getWSDLAccordoServizio:"+exceptionProblem.toString());
  4000.                 }else if(notFoundProblem.length()>0){
  4001.                     throw new DriverRegistroServiziNotFound("getWSDLAccordoServizio:"+notFoundProblem.toString());
  4002.                 }else{
  4003.                     throw new DriverRegistroServiziException("getWSDLAccordoServizio: ricerca non riuscita in tutti i registri");
  4004.                 }
  4005.             }
  4006.         }
  4007.        
  4008.         return asWrapper;
  4009.     }
  4010.    
  4011.    
  4012.    
  4013.    
  4014.    
  4015.    
  4016.    
  4017.     public Serializable pushGenericObject(String keyObject, Serializable object) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{
  4018.         if(this.cache!=null){
  4019.             return this._pushGenericObject(keyObject, object);
  4020.         }
  4021.         return object;
  4022.     }
  4023.    
  4024.     private static org.openspcoop2.utils.Semaphore semaphore_pushGenericObject = new org.openspcoop2.utils.Semaphore("RegistroServizi_GenericObject");
  4025.     private Serializable _pushGenericObject(String keyObject, Serializable object) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{
  4026.        
  4027.         SemaphoreLock lock = semaphore_pushGenericObject.acquireThrowRuntime("_pushGenericObject");
  4028.         try {
  4029.        
  4030.             // Raccolta dati
  4031.             if(keyObject == null)
  4032.                 throw new DriverRegistroServiziException("[getGenericObject]: Parametro non definito");
  4033.            
  4034.             // se e' attiva una cache provo ad utilizzarla per vedere se un altro thread lo ha giĆ  aggiunto
  4035.             String key = null;  
  4036.             key = "getGenericObject_" + keyObject;
  4037.             org.openspcoop2.utils.cache.CacheResponse response =
  4038.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  4039.             if(response != null){
  4040.                 if(response.getException()!=null){
  4041.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  4042.                         throw (DriverRegistroServiziNotFound) response.getException();
  4043.                     else
  4044.                         throw (DriverRegistroServiziException) response.getException();
  4045.                 }else{
  4046.                     return ((Serializable) response.getObject());
  4047.                 }
  4048.             }
  4049.            
  4050.             // Aggiungo la risposta in cache
  4051.             try{    
  4052.                 org.openspcoop2.utils.cache.CacheResponse responseCache = new org.openspcoop2.utils.cache.CacheResponse();
  4053.                 responseCache.setObject(object);
  4054.                 this.cache.put(key,responseCache);
  4055.             }catch(UtilsException e){
  4056.                 this.log.error("Errore durante l'inserimento in cache ["+key+"]: "+e.getMessage());
  4057.             }
  4058.            
  4059.             return object;
  4060.            
  4061.         }finally {
  4062.             semaphore_pushGenericObject.release(lock, "_pushGenericObject");
  4063.         }
  4064.        
  4065.     }
  4066.    
  4067.     public Serializable getGenericObject(String keyObject) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{

  4068.         // Raccolta dati
  4069.         if(keyObject == null)
  4070.             throw new DriverRegistroServiziException("[getGenericObject]: Parametro non definito");
  4071.        
  4072.         // se e' attiva una cache provo ad utilizzarla
  4073.         String key = null;  
  4074.         if(this.cache!=null){
  4075.             key = "getGenericObject_" + keyObject;
  4076.             org.openspcoop2.utils.cache.CacheResponse response =
  4077.                 (org.openspcoop2.utils.cache.CacheResponse) this.cache.get(key);
  4078.             if(response != null){
  4079.                 if(response.getException()!=null){
  4080.                     if(notFoundClassName.equals(response.getException().getClass().getName()))
  4081.                         throw (DriverRegistroServiziNotFound) response.getException();
  4082.                     else
  4083.                         throw (DriverRegistroServiziException) response.getException();
  4084.                 }else{
  4085.                     return ((Serializable) response.getObject());
  4086.                 }
  4087.             }
  4088.         }

  4089.         throw new DriverRegistroServiziNotFound("GenericObject with key ["+keyObject+"] not found");

  4090.     }

  4091. }

  4092. class _ASWrapperDati {
  4093.    
  4094.     // Effettuo le query nella mia gerarchia di registri.
  4095.     org.openspcoop2.core.registry.AccordoServizioParteSpecifica servizio = null;
  4096.     org.openspcoop2.core.registry.AccordoServizioParteComune as = null;

  4097.     //Recupero la classe specificata dal parametro passato
  4098.     boolean registroServiziDB = false;
  4099.    
  4100.    
  4101. }