PddProperties.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.pdd.config;


  21. import java.io.FileInputStream;
  22. import java.util.Properties;

  23. import org.slf4j.Logger;
  24. import org.openspcoop2.pdd.logger.OpenSPCoop2Logger;
  25. import org.openspcoop2.pdd.services.OpenSPCoop2Startup;
  26. import org.openspcoop2.utils.LoggerWrapperFactory;
  27. import org.openspcoop2.utils.UtilsException;


  28. /**
  29.  * Questo file permette ridefinire alcune configurazioni della porta di dominio,
  30.  * definite normalmente in govway.properties o nella configurazione xml/db della porta,
  31.  * con lo scopo di far interoperare correttamente la porta di dominio openspcoop con altre implementazioni.
  32.  * L'implementazione di una pdd associata ad un soggetto viene indicata nella definizione della porta di dominio presente
  33.  * nel registro dei servizi di OpenSPCoop. Tale informazione verra' utilizzata dalla PdD a runtime, per accedere a questo file di properties,
  34.  * e verificare se vi sono qualche opzioni ridefinite per l'implementazione della porta di dominio del soggetto erogatore/fruitore del servizio.
  35.  *
  36.  * @author Poli Andrea (apoli@link.it)
  37.  * @author $Author$
  38.  * @version $Rev$, $Date$
  39.  */


  40. public class PddProperties {    

  41.     /** Logger utilizzato per errori eventuali. */
  42.     private Logger log = null;



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

  44.     /** Reader delle proprieta' impostate nel file 'govway.pdd.properties' */
  45.     private PddInstanceProperties reader;

  46.     /** Copia Statica */
  47.     private static PddProperties pddProperties = null;


  48.     /* ********  C O S T R U T T O R E  ******** */

  49.     /**
  50.      * Viene chiamato in causa per istanziare il properties reader
  51.      *
  52.      *
  53.      */
  54.     private PddProperties(String location,String confDir) throws UtilsException {

  55.         if(OpenSPCoop2Startup.initialize)
  56.             this.log = OpenSPCoop2Logger.getLoggerOpenSPCoopCore();
  57.         else
  58.             this.log = LoggerWrapperFactory.getLogger(PddProperties.class);
  59.        
  60.         /* ---- Lettura del cammino del file di configurazione ---- */
  61.         Properties propertiesReader = new Properties();
  62.         java.io.InputStream properties = null;
  63.         try{  
  64.             if(location!=null){
  65.                 properties = new FileInputStream(location);
  66.             }else{
  67.                 properties = PddProperties.class.getResourceAsStream("/govway.pdd.properties");
  68.             }
  69.             if(properties==null){
  70.                 throw new UtilsException("File '/govway.pdd.properties' not found");
  71.             }
  72.             propertiesReader.load(properties);
  73.         }catch(Exception e) {
  74.             doError(e);
  75.         }finally{
  76.             try{
  77.                 if(properties!=null)
  78.                     properties.close();
  79.             }catch(Exception er){
  80.                 // close
  81.             }
  82.         }

  83.         this.reader = new PddInstanceProperties(propertiesReader, this.log, confDir);
  84.     }
  85.     private void doError(Exception e) throws UtilsException {
  86.         this.log.error("Riscontrato errore durante la lettura del file 'govway.pdd.properties': "+e.getMessage(),e);
  87.         throw new UtilsException("PddProperties initialize error: "+e.getMessage(),e);
  88.     }


  89.     /**
  90.      * Il Metodo si occupa di inizializzare il propertiesReader
  91.      *
  92.      *
  93.      */
  94.     public static boolean initialize(String location,String confDir){

  95.         try {
  96.             PddProperties.pddProperties = new PddProperties(location,confDir);  
  97.             return true;
  98.         }
  99.         catch(Exception e) {
  100.             return false;
  101.         }
  102.     }
  103.    
  104.     /**
  105.      * Ritorna l'istanza di questa classe
  106.      *
  107.      * @return Istanza di ClassNameProperties
  108.      *
  109.      */
  110.     public static PddProperties getInstance() throws OpenSPCoop2ConfigurationException{
  111.         if(PddProperties.pddProperties==null) {
  112.             // spotbugs warning 'SING_SINGLETON_GETTER_NOT_SYNCHRONIZED': l'istanza viene creata allo startup
  113.             synchronized (PddProperties.class) {
  114.                 throw new OpenSPCoop2ConfigurationException("PddProperties non inizializzato");
  115.             }
  116.         }
  117.         return PddProperties.pddProperties;
  118.     }
  119.    
  120.     public static void updateLocalImplementation(Properties prop){
  121.         PddProperties.pddProperties.reader.setLocalObjectImplementation(prop);
  122.     }








  123.     /* ********  M E T O D I  ******** */

  124.     /**
  125.      * Ritorna la la proprieta' ridefinita per la porta di dominio passata come parametro.
  126.      *
  127.      *
  128.      */
  129.     public String getValidazioneBuste_Stato(String nomePdd){
  130.         return this.get(nomePdd, ".validazioneBuste.stato");
  131.     }
  132.     public String getValidazioneBuste_Controllo(String nomePdd){
  133.         return this.get(nomePdd,".validazioneBuste.controllo");
  134.     }
  135.     public String getValidazioneBuste_ProfiloCollaborazione(String nomePdd){
  136.         return this.get(nomePdd,".validazioneBuste.profiloCollaborazione");
  137.     }
  138.     public String getValidazioneBuste_ManifestAttachments(String nomePdd){
  139.         return this.get(nomePdd,".validazioneBuste.manifestAttachments");
  140.     }
  141.     public String getValidazione_FiltroDuplicatiLetturaRegistro(String nomePdd){
  142.         return this.get(nomePdd,".validazioneBuste.filtroDuplicati.letturaRegistro");
  143.     }
  144.     public String getValidazione_ConfermaRicezioneLetturaRegistro(String nomePdd){
  145.         return this.get(nomePdd,".validazioneBuste.confermaRicezione.letturaRegistro");
  146.     }
  147.     public String getValidazione_ConsegnaInOrdineLetturaRegistro(String nomePdd){
  148.         return this.get(nomePdd,".validazioneBuste.consegnaInOrdine.letturaRegistro");
  149.     }
  150.     public String getValidazione_readQualifiedAttribute(String nomePdd){
  151.         return this.get(nomePdd,".validazioneBuste.readQualifiedAttribute");
  152.     }
  153.     public String getValidazione_ValidazioneIDBustaCompleta(String nomePdd){
  154.         return this.get(nomePdd,".validazioneBuste.validazioneIDBustaCompleta");
  155.     }
  156.    
  157.    
  158.     public String getBusta_TempoTipo(String nomePdd){
  159.         return this.get(nomePdd,".busta.tempo.tipo");
  160.     }
  161.     public String getBusta_AsincroniAttributiCorrelatiEnable(String nomePdd){
  162.         return this.get(nomePdd,".busta.asincroni.attributiCorrelati.enable");
  163.     }
  164.     public String getBusta_CollaborazioneEnable(String nomePdd){
  165.         return this.get(nomePdd,".busta.collaborazione.enable");
  166.     }
  167.     public String getBusta_IdRiferimentoRichiestaEnable(String nomePdd){
  168.         return this.get(nomePdd,".busta.idRiferimentoRichiesta.enable");
  169.     }
  170.     public String getBusta_ConsegnaInOrdineEnable(String nomePdd){
  171.         return this.get(nomePdd,".busta.consegnaInOrdine.enable");
  172.     }
  173.     public String getBusta_TrasmissioneEnable(String nomePdd){
  174.         return this.get(nomePdd,".busta.trasmissione.enable");
  175.     }
  176.     public String getBusta_RiscontriEnable(String nomePdd){
  177.         return this.get(nomePdd,".busta.riscontri.enable");
  178.     }
  179.     public String getBusta_FiltroduplicatiGenerazioneBustaErrore(String nomePdd){
  180.         return this.get(nomePdd,".busta.filtroduplicati.generazioneBustaErrore");
  181.     }
  182.    
  183.    
  184.    
  185.     public String getValidazioneContenutiApplicativi_Stato(String nomePdd){
  186.         return this.get(nomePdd,".validazioneContenutiApplicativi.stato");
  187.     }
  188.     public String getValidazioneContenutiApplicativi_Tipo(String nomePdd){
  189.         return this.get(nomePdd,".validazioneContenutiApplicativi.tipo");
  190.     }
  191.     public String getValidazioneContenutiApplicativi_AcceptMtomMessage(String nomePdd){
  192.         return this.get(nomePdd,".validazioneContenutiApplicativi.acceptMtomMessage");
  193.     }
  194.    
  195.    
  196.    
  197.     public String getMessageSecurity_ActorDefaultEnable(String nomePdd){
  198.         return this.get(nomePdd,".messageSecurity.actorDefault.enable");
  199.     }
  200.     public String getMessageSecurity_ActorDefaultValue(String nomePdd){
  201.         return this.get(nomePdd,".messageSecurity.actorDefault.valore");
  202.     }

  203.    
  204.    
  205.    
  206.     private String get(String nomePdd,String proprieta){
  207.         try{
  208.             return this.reader.getValue(nomePdd+proprieta);
  209.         }catch(Exception e){
  210.             this.log.error("Errore durante la lettura della proprieta' '"+nomePdd+proprieta+"': "+e.getMessage(),e);
  211.             return null;
  212.         }
  213.     }
  214. }