ConnettoriCore.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.web.ctrlstat.servlet.connettori;

  21. import java.sql.Connection;
  22. import java.util.ArrayList;
  23. import java.util.Enumeration;
  24. import java.util.List;
  25. import java.util.Properties;

  26. import org.openspcoop2.core.config.driver.DriverConfigurazioneException;
  27. import org.openspcoop2.core.registry.Connettore;
  28. import org.openspcoop2.core.registry.Property;
  29. import org.openspcoop2.core.registry.driver.DriverRegistroServiziException;
  30. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  31. import org.openspcoop2.web.ctrlstat.driver.DriverControlStationDB;

  32. /**
  33.  * ConnettoriCore
  34.  *
  35.  * @author Poli Andrea (apoli@link.it)
  36.  * @author $Author$
  37.  * @version $Rev$, $Date$
  38.  */
  39. public class ConnettoriCore extends ControlStationCore {

  40.     public ConnettoriCore() throws Exception {
  41.         super();
  42.     }
  43.     public ConnettoriCore(boolean initForApi, String confDir, String protocolloDefault) throws Exception {
  44.         super(initForApi, confDir, protocolloDefault);
  45.     }
  46.     public ConnettoriCore(ControlStationCore core) throws Exception {
  47.         super(core);
  48.     }

  49.     protected static ArrayList<Property> fromPropertiesToCollection(Properties props) {
  50.         ArrayList<Property> lista = new ArrayList<>();

  51.         Property tmp = null;
  52.         Enumeration<?> en = props.keys();
  53.         while (en.hasMoreElements()) {
  54.             String key = (String) en.nextElement();
  55.             String value = (String) props.get(key);
  56.             tmp = new Property();
  57.             tmp.setNome(key);
  58.             tmp.setValore(value);

  59.             lista.add(tmp);
  60.         }

  61.         return lista;
  62.     }

  63.     public List<String> connettoriList() throws DriverConfigurazioneException {
  64.         Connection con = null;
  65.         String nomeMetodo = "connettoriList";
  66.         DriverControlStationDB driver = null;

  67.         try {
  68.             // prendo una connessione
  69.             con = ControlStationCore.dbM.getConnection();
  70.             // istanzio il driver
  71.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  72.             return driver.getDriverConfigurazioneDB().connettoriList();

  73.         } catch (Exception e) {
  74.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  75.             throw new DriverConfigurazioneException(getPrefixError(nomeMetodo,  e),e);
  76.         } finally {
  77.             ControlStationCore.dbM.releaseConnection(con);
  78.         }
  79.     }
  80.    
  81.     public Property[] getPropertiesConnettore(String nomeConnettore) throws DriverRegistroServiziException {
  82.         Connection con = null;
  83.         String nomeMetodo = "getPropertiesConnettore";
  84.         DriverControlStationDB driver = null;

  85.         try {
  86.             // prendo una connessione
  87.             con = ControlStationCore.dbM.getConnection();
  88.             // istanzio il driver
  89.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  90.             return driver.getDriverRegistroServiziDB().getPropertiesConnettore(nomeConnettore);

  91.         } catch (Exception e) {
  92.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  93.             throw new DriverRegistroServiziException(getPrefixError(nomeMetodo,  e),e);
  94.         } finally {
  95.             ControlStationCore.dbM.releaseConnection(con);
  96.         }
  97.     }
  98.    
  99.     public org.openspcoop2.core.config.Property[] getPropertiesConnettoreConfig(String nomeConnettore) throws DriverRegistroServiziException {
  100.         Connection con = null;
  101.         String nomeMetodo = "getPropertiesConnettore";
  102.         DriverControlStationDB driver = null;

  103.         try {
  104.             // prendo una connessione
  105.             con = ControlStationCore.dbM.getConnection();
  106.             // istanzio il driver
  107.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  108.             return driver.getDriverConfigurazioneDB().getPropertiesConnettore(nomeConnettore);

  109.         } catch (Exception e) {
  110.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  111.             throw new DriverRegistroServiziException(getPrefixError(nomeMetodo,  e),e);
  112.         } finally {
  113.             ControlStationCore.dbM.releaseConnection(con);
  114.         }
  115.     }
  116.    
  117.     public Connettore getConnettoreRegistro(long idConnettore) throws DriverRegistroServiziException {
  118.         Connection con = null;
  119.         String nomeMetodo = "getConnettoreRegistro";
  120.         DriverControlStationDB driver = null;

  121.         try {
  122.             // prendo una connessione
  123.             con = ControlStationCore.dbM.getConnection();
  124.             // istanzio il driver
  125.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  126.             return driver.getDriverRegistroServiziDB().getConnettore(idConnettore);

  127.         } catch (Exception e) {
  128.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  129.             throw new DriverRegistroServiziException(getPrefixError(nomeMetodo,  e),e);
  130.         } finally {
  131.             ControlStationCore.dbM.releaseConnection(con);
  132.         }
  133.     }
  134.    
  135.     public org.openspcoop2.core.config.Connettore getConnettoreConfig(long idConnettore) throws DriverConfigurazioneException {
  136.         Connection con = null;
  137.         String nomeMetodo = "getConnettoreRegistro";
  138.         DriverControlStationDB driver = null;

  139.         try {
  140.             // prendo una connessione
  141.             con = ControlStationCore.dbM.getConnection();
  142.             // istanzio il driver
  143.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  144.             return driver.getDriverConfigurazioneDB().getConnettore(idConnettore);

  145.         } catch (Exception e) {
  146.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  147.             throw new DriverConfigurazioneException(getPrefixError(nomeMetodo,  e),e);
  148.         } finally {
  149.             ControlStationCore.dbM.releaseConnection(con);
  150.         }
  151.     }
  152. }