DriverTracciamento.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.logger;

  21. import java.sql.Connection;
  22. import java.util.List;
  23. import java.util.Map;
  24. import java.util.Properties;

  25. import javax.sql.DataSource;

  26. import org.openspcoop2.core.id.IDSoggetto;
  27. import org.openspcoop2.protocol.basic.ProtocolliRegistrati;
  28. import org.openspcoop2.protocol.engine.BasicProtocolFactory;
  29. import org.openspcoop2.protocol.engine.ProtocolFactoryManager;
  30. import org.openspcoop2.protocol.sdk.IProtocolFactory;
  31. import org.openspcoop2.protocol.sdk.constants.RuoloMessaggio;
  32. import org.openspcoop2.protocol.sdk.diagnostica.DriverMsgDiagnosticiException;
  33. import org.openspcoop2.protocol.sdk.tracciamento.DriverTracciamentoException;
  34. import org.openspcoop2.protocol.sdk.tracciamento.DriverTracciamentoNotFoundException;
  35. import org.openspcoop2.protocol.sdk.tracciamento.FiltroRicercaTracce;
  36. import org.openspcoop2.protocol.sdk.tracciamento.FiltroRicercaTracceConPaginazione;
  37. import org.openspcoop2.protocol.sdk.tracciamento.ITracciaDriver;
  38. import org.openspcoop2.protocol.sdk.tracciamento.Traccia;
  39. import org.slf4j.Logger;



  40. /**
  41.  * Interfaccia Tracciamento
  42.  *
  43.  * @author Stefano Corallo (corallo@link.it)
  44.  * @author $Author$
  45.  * @version $Rev$, $Date$
  46.  */
  47. public class DriverTracciamento implements ITracciaDriver {

  48.    
  49.     @Override
  50.     public IProtocolFactory<?> getProtocolFactory() {
  51.         return this.basicProtocolFactory;
  52.     }

  53.     /**
  54.      * Properties
  55.      */
  56.     public void setProperties(List<String> properties) {
  57.         this.driverBase.setProperties(properties);
  58.     }
  59.    
  60.     /** Driver di base: valido per tutti i protocolli */
  61.     org.openspcoop2.protocol.basic.tracciamento.TracciaDriver driverBase = null;
  62.    
  63.     /** Factory di base */
  64.     private BasicProtocolFactory basicProtocolFactory;
  65.    
  66.     public DriverTracciamento(String nomeDataSource, String tipoDatabase, Properties prop) throws DriverTracciamentoException {
  67.         this(nomeDataSource,tipoDatabase,prop,null);
  68.     }
  69.    
  70.     public DriverTracciamento(String nomeDataSource, String tipoDatabase, Properties prop, Logger log) throws DriverTracciamentoException {
  71.        
  72.         try{
  73.             this.basicProtocolFactory = new BasicProtocolFactory(log);
  74.             this.driverBase = (org.openspcoop2.protocol.basic.tracciamento.TracciaDriver) this.basicProtocolFactory.createTracciaDriver();
  75.             ProtocolliRegistrati pRegistrati = new ProtocolliRegistrati(ProtocolFactoryManager.getInstance().getProtocolFactories());
  76.             this.driverBase.init(pRegistrati,nomeDataSource, tipoDatabase,prop,log);
  77.         }catch(Exception e){
  78.             throw new DriverTracciamentoException(e.getMessage(),e);
  79.         }
  80.        
  81.     }
  82.    
  83.     public DriverTracciamento(DataSource dataSourceObject, String tipoDatabase) throws DriverTracciamentoException {
  84.         this(dataSourceObject,tipoDatabase,null);
  85.     }
  86.    
  87.     public DriverTracciamento(DataSource dataSourceObject, String tipoDatabase, Logger log) throws DriverTracciamentoException {
  88.         try{
  89.             this.basicProtocolFactory = new BasicProtocolFactory(log);
  90.             this.driverBase = (org.openspcoop2.protocol.basic.tracciamento.TracciaDriver) this.basicProtocolFactory.createTracciaDriver();
  91.             ProtocolliRegistrati pRegistrati = new ProtocolliRegistrati(ProtocolFactoryManager.getInstance().getProtocolFactories());
  92.             this.driverBase.init(pRegistrati,dataSourceObject, tipoDatabase,log);
  93.         }catch(Exception e){
  94.             throw new DriverTracciamentoException(e.getMessage(),e);
  95.         }
  96.     }
  97.    
  98.     public DriverTracciamento(Connection connection, String tipoDatabase, Logger log) throws DriverTracciamentoException {
  99.         try{
  100.             this.basicProtocolFactory = new BasicProtocolFactory(log);
  101.             this.driverBase = (org.openspcoop2.protocol.basic.tracciamento.TracciaDriver) this.basicProtocolFactory.createTracciaDriver();
  102.             ProtocolliRegistrati pRegistrati = new ProtocolliRegistrati(ProtocolFactoryManager.getInstance().getProtocolFactories());
  103.             this.driverBase.init(pRegistrati,connection, tipoDatabase,log);
  104.         }catch(Exception e){
  105.             throw new DriverTracciamentoException(e.getMessage(),e);
  106.         }
  107.     }
  108.    
  109.     public DriverTracciamento(String urlJDBC,String driverJDBC,
  110.             String username,String password,
  111.             String tipoDatabase, Logger log) throws DriverTracciamentoException {
  112.         try{
  113.             this.basicProtocolFactory = new BasicProtocolFactory(log);
  114.             this.driverBase = (org.openspcoop2.protocol.basic.tracciamento.TracciaDriver) this.basicProtocolFactory.createTracciaDriver();
  115.             ProtocolliRegistrati pRegistrati = new ProtocolliRegistrati(ProtocolFactoryManager.getInstance().getProtocolFactories());
  116.             this.driverBase.init(pRegistrati,urlJDBC, driverJDBC,
  117.                     username, password,
  118.                     tipoDatabase,log);
  119.         }catch(Exception e){
  120.             throw new DriverTracciamentoException(e.getMessage(),e);
  121.         }
  122.     }
  123.    

  124.    
  125.    
  126.    
  127.    
  128.     /* *********** ACCESSI TRAMITE RICERCHE ******* */
  129.    
  130.     /**
  131.      * Si occupa di ritornare il numero di tracce che rispettano il filtro di ricerca
  132.      *
  133.      * @param filtro Filtro di ricerca
  134.      * @return numero di tracce che rispettano il filtro di ricerca
  135.      *
  136.      */
  137.     @Override
  138.     public int countTracce(FiltroRicercaTracce filtro) throws DriverTracciamentoException{
  139.         return this.driverBase.countTracce(filtro);
  140.     }
  141.    
  142.     /**
  143.      * Si occupa di ritornare le tracce che rispettano il filtro di ricerca
  144.      *
  145.      * @param filtro Filtro di ricerca
  146.      * @return tracce che rispettano il filtro di ricerca
  147.      *
  148.      */
  149.     @Override
  150.     public List<Traccia> getTracce(FiltroRicercaTracceConPaginazione filtro)  throws DriverTracciamentoException, DriverTracciamentoNotFoundException{
  151.         return this.driverBase.getTracce(filtro);
  152.     }
  153.    
  154.    
  155.     /**
  156.      * Si occupa di eliminare le tracce che rispettano il filtro di ricerca
  157.      *
  158.      * @param filtro Filtro di ricerca
  159.      * @return numero di tracce eliminate
  160.      * @throws DriverTracciamentoException
  161.      */
  162.     @Override
  163.     public int deleteTracce(FiltroRicercaTracce filtro) throws DriverTracciamentoException{
  164.         return this.driverBase.deleteTracce(filtro);
  165.     }
  166.    
  167.    
  168.    
  169.    
  170.    
  171.    
  172.    
  173.    
  174.     /* ******* ACCESSI PUNTUALI ********** */
  175.    
  176.     /**
  177.      * Recupera la traccia
  178.      *
  179.      * @return Traccia
  180.      * @throws DriverMsgDiagnosticiException
  181.      */
  182.     @Override
  183.     public Traccia getTraccia(String idBusta,IDSoggetto codicePorta) throws DriverTracciamentoException, DriverTracciamentoNotFoundException{
  184.         return this.driverBase.getTraccia(idBusta, codicePorta);
  185.     }
  186.    
  187.     /**
  188.      * Recupera la traccia
  189.      *
  190.      * @return Traccia
  191.      * @throws DriverMsgDiagnosticiException
  192.      */
  193.     @Override
  194.     public Traccia getTraccia(String idBusta,IDSoggetto codicePorta,boolean ricercaIdBustaComeRiferimentoMessaggio) throws DriverTracciamentoException, DriverTracciamentoNotFoundException{
  195.         return this.driverBase.getTraccia(idBusta, codicePorta, ricercaIdBustaComeRiferimentoMessaggio);
  196.     }
  197.    
  198.     /**
  199.      * Recupera la traccia in base all'id di transazione
  200.      *
  201.      * @return Traccia
  202.      * @throws DriverMsgDiagnosticiException
  203.      */
  204.     @Override
  205.     public Traccia getTraccia(String idTransazione, RuoloMessaggio tipoTraccia) throws DriverTracciamentoException, DriverTracciamentoNotFoundException{
  206.         return this.driverBase.getTraccia(idTransazione, tipoTraccia);
  207.     }
  208.    
  209.     /**
  210.      * Recupera la traccia in base ad una serie di properties
  211.      *
  212.      * @return Traccia
  213.      * @throws DriverMsgDiagnosticiException
  214.      */
  215.     @Override
  216.     public Traccia getTraccia(RuoloMessaggio tipoTraccia,Map<String, String> propertiesRicerca) throws DriverTracciamentoException, DriverTracciamentoNotFoundException{
  217.         return this.driverBase.getTraccia(tipoTraccia, propertiesRicerca);
  218.     }
  219.    

  220.    
  221.    
  222.    
  223.    
  224.    
  225.    
  226.     /* ******* RISORSE INTERNE ********** */
  227.    
  228.     @Override
  229.     public void close() throws DriverTracciamentoException {
  230.         this.driverBase.close();
  231.     }
  232. }