DriverConfigurazioneDB_configSearchDriver.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */
  20. package org.openspcoop2.core.config.driver.db;

  21. import java.sql.Connection;
  22. import java.sql.PreparedStatement;
  23. import java.sql.ResultSet;
  24. import java.util.ArrayList;
  25. import java.util.List;

  26. import org.apache.commons.lang.StringUtils;
  27. import org.openspcoop2.core.commons.DBUtils;
  28. import org.openspcoop2.core.commons.ISearch;
  29. import org.openspcoop2.core.commons.Liste;
  30. import org.openspcoop2.core.config.AccessoRegistroRegistro;
  31. import org.openspcoop2.core.config.CanaleConfigurazione;
  32. import org.openspcoop2.core.config.CanaleConfigurazioneNodo;
  33. import org.openspcoop2.core.config.ConfigurazioneUrlInvocazioneRegola;
  34. import org.openspcoop2.core.config.IdSoggetto;
  35. import org.openspcoop2.core.config.Property;
  36. import org.openspcoop2.core.config.ResponseCachingConfigurazioneRegola;
  37. import org.openspcoop2.core.config.constants.CostantiConfigurazione;
  38. import org.openspcoop2.core.config.constants.RegistroTipo;
  39. import org.openspcoop2.core.config.constants.StatoFunzionalita;
  40. import org.openspcoop2.core.config.constants.StatoFunzionalitaConPersonalizzazione;
  41. import org.openspcoop2.core.config.driver.DriverConfigurazioneException;
  42. import org.openspcoop2.core.constants.CostantiDB;
  43. import org.openspcoop2.core.id.IDSoggetto;
  44. import org.openspcoop2.utils.jdbc.JDBCUtilities;
  45. import org.openspcoop2.utils.sql.ISQLQueryObject;
  46. import org.openspcoop2.utils.sql.SQLObjectFactory;

  47. /**
  48.  * DriverConfigurazioneDB_configSearchDriver
  49.  *
  50.  *
  51.  * @author Sandra Giangrandi (sandra@link.it)
  52.  * @author Stefano Corallo (corallo@link.it)
  53.  * @author $Author$
  54.  * @version $Rev$, $Date$
  55.  */
  56. public class DriverConfigurazioneDB_configSearchDriver {

  57.     private DriverConfigurazioneDB driver = null;
  58.    
  59.     protected DriverConfigurazioneDB_configSearchDriver(DriverConfigurazioneDB driver) {
  60.         this.driver = driver;
  61.     }
  62.    
  63.     protected List<Property> systemPropertyList(ISearch ricerca) throws DriverConfigurazioneException {
  64.         String nomeMetodo = "systemPropertyList";
  65.         int idLista = Liste.SYSTEM_PROPERTIES;

  66.         int offset;
  67.         int limit;
  68.         String search;
  69.         String queryString;
  70.         limit = ricerca.getPageSize(idLista);
  71.         offset = ricerca.getIndexIniziale(idLista);
  72.         search = (org.openspcoop2.core.constants.Costanti.SESSION_ATTRIBUTE_VALUE_RICERCA_UNDEFINED.equals(ricerca.getSearchString(idLista)) ? "" : ricerca.getSearchString(idLista));


  73.         Connection con = null;
  74.         PreparedStatement stmt=null;
  75.         ResultSet risultato=null;
  76.         ArrayList<Property> lista = new ArrayList<>();

  77.         if (this.driver.atomica) {
  78.             try {
  79.                 con = this.driver.getConnectionFromDatasource("systemPropertyList");
  80.             } catch (Exception e) {
  81.                 throw new DriverConfigurazioneException("[DriverConfigurazioneDB::" + nomeMetodo + "] Exception accedendo al datasource :" + e.getMessage(),e);

  82.             }

  83.         } else
  84.             con = this.driver.globalConnection;

  85.         this.driver.logDebug("operazione this.driver.atomica = " + this.driver.atomica);

  86.         try {

  87.             if (!search.equals("")) {
  88.                 //query con search
  89.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  90.                 sqlQueryObject.addFromTable(CostantiDB.SYSTEM_PROPERTIES_PDD);
  91.                 sqlQueryObject.addSelectCountField("*", "cont");
  92.                 sqlQueryObject.addWhereLikeCondition("nome", search, true, true);
  93.                 sqlQueryObject.setANDLogicOperator(true);
  94.                 queryString = sqlQueryObject.createSQLQuery();
  95.             } else {
  96.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  97.                 sqlQueryObject.addFromTable(CostantiDB.SYSTEM_PROPERTIES_PDD);
  98.                 sqlQueryObject.addSelectCountField("*", "cont");
  99.                 queryString = sqlQueryObject.createSQLQuery();
  100.             }
  101.             stmt = con.prepareStatement(queryString);
  102.             risultato = stmt.executeQuery();
  103.             if (risultato.next())
  104.                 ricerca.setNumEntries(idLista,risultato.getInt(1));
  105.             risultato.close();
  106.             stmt.close();

  107.             // ricavo le entries
  108.             if (limit == 0) // con limit
  109.                 limit = ISQLQueryObject.LIMIT_DEFAULT_VALUE;
  110.             if (!search.equals("")) { // con search
  111.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  112.                 sqlQueryObject.addFromTable(CostantiDB.SYSTEM_PROPERTIES_PDD);
  113.                 sqlQueryObject.addSelectField("id");
  114.                 sqlQueryObject.addSelectField("nome");
  115.                 sqlQueryObject.addSelectField("valore");
  116.                 sqlQueryObject.addSelectField("enc_value");
  117.                 sqlQueryObject.addWhereLikeCondition("nome", search, true, true);
  118.                 sqlQueryObject.setANDLogicOperator(true);
  119.                 sqlQueryObject.addOrderBy("nome");
  120.                 sqlQueryObject.setSortType(true);
  121.                 sqlQueryObject.setLimit(limit);
  122.                 sqlQueryObject.setOffset(offset);
  123.                 queryString = sqlQueryObject.createSQLQuery();
  124.             } else {
  125.                 // senza search
  126.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  127.                 sqlQueryObject.addFromTable(CostantiDB.SYSTEM_PROPERTIES_PDD);
  128.                 sqlQueryObject.addSelectField("id");
  129.                 sqlQueryObject.addSelectField("nome");
  130.                 sqlQueryObject.addSelectField("valore");
  131.                 sqlQueryObject.addSelectField("enc_value");
  132.                 sqlQueryObject.addOrderBy("nome");
  133.                 sqlQueryObject.setSortType(true);
  134.                 sqlQueryObject.setLimit(limit);
  135.                 sqlQueryObject.setOffset(offset);
  136.                 queryString = sqlQueryObject.createSQLQuery();
  137.             }
  138.             stmt = con.prepareStatement(queryString);
  139.             risultato = stmt.executeQuery();

  140.             Property sp;
  141.             while (risultato.next()) {

  142.                 sp = new Property();

  143.                 sp.setId(risultato.getLong("id"));
  144.                 sp.setNome(risultato.getString("nome"));
  145.                
  146.                 String plainValue = risultato.getString("valore");
  147.                 String encValue = risultato.getString("enc_value");
  148.                 if(encValue!=null && StringUtils.isNotEmpty(encValue)) {
  149.                     sp.setValore(encValue);
  150.                 }
  151.                 else {
  152.                     sp.setValore(plainValue);
  153.                 }

  154.                 lista.add(sp);
  155.             }

  156.             return lista;

  157.         } catch (Exception qe) {
  158.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB::" + nomeMetodo + "] Errore : " + qe.getMessage(),qe);
  159.         } finally {

  160.             //Chiudo statement and resultset
  161.             JDBCUtilities.closeResources(risultato, stmt);

  162.             this.driver.closeConnection(con);
  163.         }
  164.     }
  165.    
  166.     protected List<AccessoRegistroRegistro> registriList(ISearch ricerca) throws DriverConfigurazioneException {
  167.         String nomeMetodo = "registriList";
  168.         int idLista = Liste.REGISTRI;
  169.         int offset;
  170.         int limit;
  171.         String search;
  172.         String queryString;

  173.         limit = ricerca.getPageSize(idLista);
  174.         offset = ricerca.getIndexIniziale(idLista);
  175.         search = (org.openspcoop2.core.constants.Costanti.SESSION_ATTRIBUTE_VALUE_RICERCA_UNDEFINED.equals(ricerca.getSearchString(idLista)) ? "" : ricerca.getSearchString(idLista));


  176.         Connection con = null;
  177.         PreparedStatement stmt=null;
  178.         ResultSet risultato=null;
  179.         ArrayList<AccessoRegistroRegistro> lista = new ArrayList<>();

  180.         if (this.driver.atomica) {
  181.             try {
  182.                 con = this.driver.getConnectionFromDatasource("registriList");
  183.             } catch (Exception e) {
  184.                 throw new DriverConfigurazioneException("[DriverConfigurazioneDB::" + nomeMetodo + "] Exception accedendo al datasource :" + e.getMessage(),e);

  185.             }

  186.         } else
  187.             con = this.driver.globalConnection;

  188.         this.driver.logDebug("operazione this.driver.atomica = " + this.driver.atomica);

  189.         try {

  190.             if (!search.equals("")) {
  191.                 //query con search
  192.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  193.                 sqlQueryObject.addFromTable(CostantiDB.REGISTRI);
  194.                 sqlQueryObject.addSelectCountField("*", "cont");
  195.                 sqlQueryObject.addWhereLikeCondition("nome", search, true, true);
  196.                 queryString = sqlQueryObject.createSQLQuery();
  197.             } else {
  198.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  199.                 sqlQueryObject.addFromTable(CostantiDB.REGISTRI);
  200.                 sqlQueryObject.addSelectCountField("*", "cont");
  201.                 queryString = sqlQueryObject.createSQLQuery();
  202.             }
  203.             stmt = con.prepareStatement(queryString);
  204.             risultato = stmt.executeQuery();
  205.             if (risultato.next())
  206.                 ricerca.setNumEntries(idLista,risultato.getInt(1));
  207.             risultato.close();
  208.             stmt.close();

  209.             // ricavo le entries
  210.             if (limit == 0) // con limit
  211.                 limit = ISQLQueryObject.LIMIT_DEFAULT_VALUE;

  212.             if (!search.equals("")) { // con search
  213.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  214.                 sqlQueryObject.addFromTable(CostantiDB.REGISTRI);
  215.                 sqlQueryObject.addSelectField("id");
  216.                 sqlQueryObject.addSelectField("nome");
  217.                 sqlQueryObject.addSelectField("tipo");
  218.                 sqlQueryObject.addWhereLikeCondition("nome", search, true, true);
  219.                 sqlQueryObject.addOrderBy("nome");
  220.                 sqlQueryObject.setSortType(true);
  221.                 sqlQueryObject.setLimit(limit);
  222.                 sqlQueryObject.setOffset(offset);
  223.                 queryString = sqlQueryObject.createSQLQuery();
  224.             } else {
  225.                 // senza search
  226.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  227.                 sqlQueryObject.addFromTable(CostantiDB.REGISTRI);
  228.                 sqlQueryObject.addSelectField("id");
  229.                 sqlQueryObject.addSelectField("nome");
  230.                 sqlQueryObject.addSelectField("tipo");
  231.                 sqlQueryObject.addOrderBy("nome");
  232.                 sqlQueryObject.setSortType(true);
  233.                 sqlQueryObject.setLimit(limit);
  234.                 sqlQueryObject.setOffset(offset);
  235.                 queryString = sqlQueryObject.createSQLQuery();
  236.             }
  237.             stmt = con.prepareStatement(queryString);
  238.             risultato = stmt.executeQuery();

  239.             AccessoRegistroRegistro arr;
  240.             while (risultato.next()) {

  241.                 arr = new AccessoRegistroRegistro();

  242.                 arr.setId(risultato.getLong("id"));
  243.                 arr.setNome(risultato.getString("nome"));
  244.                 arr.setTipo(RegistroTipo.toEnumConstant(risultato.getString("tipo")));

  245.                 lista.add(arr);
  246.             }

  247.             return lista;

  248.         } catch (Exception qe) {
  249.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB::" + nomeMetodo + "] Errore : " + qe.getMessage(),qe);
  250.         } finally {

  251.             //Chiudo statement and resultset
  252.             JDBCUtilities.closeResources(risultato, stmt);

  253.             this.driver.closeConnection(con);
  254.         }
  255.     }
  256.    
  257.     protected List<ResponseCachingConfigurazioneRegola> responseCachingConfigurazioneRegolaList(ISearch ricerca) throws DriverConfigurazioneException {
  258.         String nomeMetodo = "responseCachingConfigurazioneRegolaList";
  259.         int idLista = Liste.CONFIGURAZIONE_RESPONSE_CACHING_CONFIGURAZIONE_REGOLA;
  260.         int offset;
  261.         int limit;
  262.         String queryString;

  263.         limit = ricerca.getPageSize(idLista);
  264.         offset = ricerca.getIndexIniziale(idLista);

  265.         Connection con = null;
  266.         PreparedStatement stmt=null;
  267.         ResultSet risultato=null;
  268.         ArrayList<ResponseCachingConfigurazioneRegola> lista = new ArrayList<>();

  269.         if (this.driver.atomica) {
  270.             try {
  271.                 con = this.driver.getConnectionFromDatasource("responseCachingConfigurazioneRegolaList");
  272.             } catch (Exception e) {
  273.                 throw new DriverConfigurazioneException("[DriverConfigurazioneDB::" + nomeMetodo + "] Exception accedendo al datasource :" + e.getMessage(),e);

  274.             }

  275.         } else
  276.             con = this.driver.globalConnection;

  277.         this.driver.logDebug("operazione this.driver.atomica = " + this.driver.atomica);

  278.         try {

  279.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  280.             sqlQueryObject.addFromTable(CostantiDB.CONFIGURAZIONE_CACHE_REGOLE);
  281.             sqlQueryObject.addSelectCountField("id", "cont");
  282.             queryString = sqlQueryObject.createSQLQuery();
  283.             stmt = con.prepareStatement(queryString);
  284.             risultato = stmt.executeQuery();
  285.             if (risultato.next())
  286.                 ricerca.setNumEntries(idLista,risultato.getInt(1));
  287.             risultato.close();
  288.             stmt.close();

  289.             // ricavo le entries
  290.             if (limit == 0) // con limit
  291.                 limit = ISQLQueryObject.LIMIT_DEFAULT_VALUE;

  292.             sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  293.             sqlQueryObject.addFromTable(CostantiDB.CONFIGURAZIONE_CACHE_REGOLE);
  294.             sqlQueryObject.addSelectField("id");
  295.             sqlQueryObject.addOrderBy("id");
  296.             sqlQueryObject.setSortType(true);
  297.             sqlQueryObject.setLimit(limit);
  298.             sqlQueryObject.setOffset(offset);
  299.             queryString = sqlQueryObject.createSQLQuery();
  300.             stmt = con.prepareStatement(queryString);
  301.             risultato = stmt.executeQuery();

  302.             List<Long> idLong = new ArrayList<>();
  303.             while (risultato.next()) {
  304.                 idLong.add(risultato.getLong("id"));
  305.             }
  306.             risultato.close();
  307.             stmt.close();
  308.            
  309.             if(!idLong.isEmpty()) {
  310.                
  311.                 for (Long idLongRegola : idLong) {
  312.                    
  313.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  314.                     sqlQueryObject.addFromTable(CostantiDB.CONFIGURAZIONE_CACHE_REGOLE);
  315.                     sqlQueryObject.addSelectField("id");
  316.                     sqlQueryObject.addSelectField("status_min");
  317.                     sqlQueryObject.addSelectField("status_max");
  318.                     sqlQueryObject.addSelectField("fault");
  319.                     sqlQueryObject.addSelectField("cache_seconds");
  320.                     sqlQueryObject.addWhereCondition("id=?");
  321.                     queryString = sqlQueryObject.createSQLQuery();
  322.                     stmt = con.prepareStatement(queryString);
  323.                     stmt.setLong(1, idLongRegola);
  324.                     risultato = stmt.executeQuery();
  325.                    
  326.                     if(risultato.next()) {
  327.                         ResponseCachingConfigurazioneRegola regola = new ResponseCachingConfigurazioneRegola();
  328.                        
  329.                         regola.setId(risultato.getLong("id"));
  330.                         int status_min = risultato.getInt("status_min");
  331.                         int status_max = risultato.getInt("status_max");
  332.                         if(status_min>0) {
  333.                             regola.setReturnCodeMin(status_min);
  334.                         }
  335.                         if(status_max>0) {
  336.                             regola.setReturnCodeMax(status_max);
  337.                         }

  338.                         int fault = risultato.getInt("fault");
  339.                         if(CostantiDB.TRUE == fault) {
  340.                             regola.setFault(true);
  341.                         }
  342.                         else if(CostantiDB.FALSE == fault) {
  343.                             regola.setFault(false);
  344.                         }
  345.                        
  346.                         int cacheSeconds = risultato.getInt("cache_seconds");
  347.                         if(cacheSeconds>0) {
  348.                             regola.setCacheTimeoutSeconds(cacheSeconds);
  349.                         }

  350.                         lista.add(regola);
  351.                     }
  352.                    
  353.                     risultato.close();
  354.                     stmt.close();
  355.                 }
  356.                
  357.             }
  358.            
  359.             return lista;

  360.         } catch (Exception qe) {
  361.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB::" + nomeMetodo + "] Errore : " + qe.getMessage(),qe);
  362.         } finally {

  363.             //Chiudo statement and resultset
  364.             JDBCUtilities.closeResources(risultato, stmt);

  365.             this.driver.closeConnection(con);
  366.         }
  367.     }
  368.    
  369.     protected List<ConfigurazioneUrlInvocazioneRegola> proxyPassConfigurazioneRegolaList(ISearch ricerca) throws DriverConfigurazioneException {
  370.         String nomeMetodo = "proxyPassConfigurazioneRegolaList";
  371.         int idLista = Liste.CONFIGURAZIONE_PROXY_PASS_REGOLA;
  372.         int offset;
  373.         int limit;
  374.         String queryString;
  375.         String search;

  376.         limit = ricerca.getPageSize(idLista);
  377.         offset = ricerca.getIndexIniziale(idLista);
  378.         search = (org.openspcoop2.core.constants.Costanti.SESSION_ATTRIBUTE_VALUE_RICERCA_UNDEFINED.equals(ricerca.getSearchString(idLista)) ? "" : ricerca.getSearchString(idLista));

  379.         Connection con = null;
  380.         PreparedStatement stmt=null;
  381.         ResultSet risultato=null;
  382.         ArrayList<ConfigurazioneUrlInvocazioneRegola> lista = new ArrayList<>();

  383.         if (this.driver.atomica) {
  384.             try {
  385.                 con = this.driver.getConnectionFromDatasource("responseCachingConfigurazioneRegolaList");
  386.             } catch (Exception e) {
  387.                 throw new DriverConfigurazioneException("[DriverConfigurazioneDB::" + nomeMetodo + "] Exception accedendo al datasource :" + e.getMessage(),e);

  388.             }

  389.         } else
  390.             con = this.driver.globalConnection;

  391.         this.driver.logDebug("operazione this.driver.atomica = " + this.driver.atomica);

  392.         try {

  393.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  394.             sqlQueryObject.addFromTable(CostantiDB.CONFIG_URL_REGOLE);
  395.             sqlQueryObject.addSelectCountField("id", "cont");
  396.            
  397.             if (!search.equals("")) {
  398.                 sqlQueryObject.addWhereLikeCondition("nome", search, true, true);
  399.             }
  400.            
  401.             queryString = sqlQueryObject.createSQLQuery();
  402.             stmt = con.prepareStatement(queryString);
  403.             risultato = stmt.executeQuery();
  404.             if (risultato.next())
  405.                 ricerca.setNumEntries(idLista,risultato.getInt(1));
  406.             risultato.close();
  407.             stmt.close();

  408.             // ricavo le entries
  409.             if (limit == 0) // con limit
  410.                 limit = ISQLQueryObject.LIMIT_DEFAULT_VALUE;

  411.             sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  412.             sqlQueryObject.addFromTable(CostantiDB.CONFIG_URL_REGOLE);
  413.             sqlQueryObject.addSelectField("id");
  414.             sqlQueryObject.addSelectField("nome");            
  415.             sqlQueryObject.addSelectField("posizione");      
  416.             sqlQueryObject.addSelectField("stato");          
  417.             sqlQueryObject.addSelectField("descrizione");    
  418.             sqlQueryObject.addSelectField("regexpr");        
  419.             sqlQueryObject.addSelectField("regola");          
  420.             sqlQueryObject.addSelectField("contesto_esterno");
  421.             sqlQueryObject.addSelectField("base_url");        
  422.             sqlQueryObject.addSelectField("protocollo");      
  423.             sqlQueryObject.addSelectField("ruolo");          
  424.             sqlQueryObject.addSelectField("service_binding");
  425.             sqlQueryObject.addSelectField("tipo_soggetto");  
  426.             sqlQueryObject.addSelectField("nome_soggetto");
  427.            
  428.             if (!search.equals("")) {
  429.                 sqlQueryObject.addWhereLikeCondition("nome", search, true, true);
  430.             }
  431.             sqlQueryObject.addOrderBy("posizione");
  432.             sqlQueryObject.addOrderBy("nome");
  433.             sqlQueryObject.setSortType(true);
  434.             sqlQueryObject.setLimit(limit);
  435.             sqlQueryObject.setOffset(offset);
  436.             queryString = sqlQueryObject.createSQLQuery();
  437.             stmt = con.prepareStatement(queryString);
  438.             risultato = stmt.executeQuery();

  439.            
  440.             while (risultato.next()) {
  441.                 ConfigurazioneUrlInvocazioneRegola regola = new ConfigurazioneUrlInvocazioneRegola();
  442.                 regola.setId(risultato.getLong("id"));
  443.                 regola.setNome(risultato.getString("nome"));
  444.                 regola.setPosizione(risultato.getInt("posizione"));
  445.                 regola.setStato(DriverConfigurazioneDBLib.getEnumStatoFunzionalita(risultato.getString("stato")));
  446.                 regola.setDescrizione(risultato.getString("descrizione"));
  447.                 if(risultato.getInt("regexpr") == CostantiDB.TRUE) {
  448.                     regola.setRegexpr(true);
  449.                 }else {
  450.                     regola.setRegexpr(false);
  451.                 }
  452.                 regola.setRegola(risultato.getString("regola"));
  453.                 // Fix stringa vuota in Oracle, impostato dalla console e non accettato da Oracle che lo traduce in null e fa schiantare per via del NOT NULL sul db
  454.                 String s = risultato.getString("contesto_esterno");
  455.                 if(CostantiConfigurazione.REGOLA_PROXY_PASS_CONTESTO_VUOTO.equals(s)) {
  456.                     s = "";
  457.                 }
  458.                 regola.setContestoEsterno(s);
  459.                 regola.setBaseUrl(risultato.getString("base_url"));
  460.                 regola.setProtocollo(risultato.getString("protocollo"));
  461.                 regola.setRuolo(DriverConfigurazioneDBLib.getEnumRuoloContesto(risultato.getString("ruolo")));
  462.                 regola.setServiceBinding(DriverConfigurazioneDBLib.getEnumServiceBinding(risultato.getString("service_binding")));
  463.                 String tipoSoggetto = risultato.getString("tipo_soggetto");
  464.                 String nomeSoggetto = risultato.getString("nome_soggetto");
  465.                 if(tipoSoggetto!=null && !"".equals(tipoSoggetto) && nomeSoggetto!=null && !"".equals(nomeSoggetto)) {
  466.                     regola.setSoggetto(new IdSoggetto(new IDSoggetto(tipoSoggetto, nomeSoggetto)));
  467.                 }
  468.                
  469.                 lista.add(regola);
  470.            
  471.             }
  472.             risultato.close();
  473.             stmt.close();
  474.            
  475.             return lista;

  476.         } catch (Exception qe) {
  477.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB::" + nomeMetodo + "] Errore : " + qe.getMessage(),qe);
  478.         } finally {

  479.             //Chiudo statement and resultset
  480.             JDBCUtilities.closeResources(risultato, stmt);

  481.             this.driver.closeConnection(con);
  482.         }
  483.     }
  484.    
  485.     protected List<CanaleConfigurazione> canaleConfigurazioneList(ISearch ricerca) throws DriverConfigurazioneException {
  486.         String nomeMetodo = "canaleConfigurazioneList";
  487.         int idLista = Liste.CONFIGURAZIONE_CANALI;
  488.         int offset;
  489.         int limit;
  490.         String queryString;
  491.         String search;

  492.         limit = ricerca.getPageSize(idLista);
  493.         offset = ricerca.getIndexIniziale(idLista);
  494.         search = (org.openspcoop2.core.constants.Costanti.SESSION_ATTRIBUTE_VALUE_RICERCA_UNDEFINED.equals(ricerca.getSearchString(idLista)) ? "" : ricerca.getSearchString(idLista));

  495.         Connection con = null;
  496.         PreparedStatement stmt=null;
  497.         ResultSet risultato=null;
  498.         ArrayList<CanaleConfigurazione> lista = new ArrayList<>();

  499.         if (this.driver.atomica) {
  500.             try {
  501.                 con = this.driver.getConnectionFromDatasource(nomeMetodo);
  502.             } catch (Exception e) {
  503.                 throw new DriverConfigurazioneException("[DriverConfigurazioneDB::" + nomeMetodo + "] Exception accedendo al datasource :" + e.getMessage(),e);

  504.             }

  505.         } else
  506.             con = this.driver.globalConnection;

  507.         this.driver.logDebug("operazione this.driver.atomica = " + this.driver.atomica);

  508.         try {

  509.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  510.             sqlQueryObject.addFromTable(CostantiDB.CONFIGURAZIONE_CANALI);
  511.             sqlQueryObject.addSelectCountField("id", "cont");
  512.            
  513.             if (!search.equals("")) {
  514.                 sqlQueryObject.addWhereLikeCondition("nome", search, true, true);
  515.             }
  516.            
  517.             queryString = sqlQueryObject.createSQLQuery();
  518.             stmt = con.prepareStatement(queryString);
  519.             risultato = stmt.executeQuery();
  520.             if (risultato.next())
  521.                 ricerca.setNumEntries(idLista,risultato.getInt(1));
  522.             risultato.close();
  523.             stmt.close();

  524.             // ricavo le entries
  525.             if (limit == 0) // con limit
  526.                 limit = ISQLQueryObject.LIMIT_DEFAULT_VALUE;

  527.             sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  528.             sqlQueryObject.addFromTable(CostantiDB.CONFIGURAZIONE_CANALI);
  529.             sqlQueryObject.addSelectField("id");
  530.             sqlQueryObject.addSelectField("nome");            
  531.             sqlQueryObject.addSelectField("descrizione");    
  532.             sqlQueryObject.addSelectField("canale_default");        
  533.            
  534.             if (!search.equals("")) {
  535.                 sqlQueryObject.addWhereLikeCondition("nome", search, true, true);
  536.             }
  537.             sqlQueryObject.addOrderBy("nome");
  538.             sqlQueryObject.setSortType(true);
  539.             sqlQueryObject.setLimit(limit);
  540.             sqlQueryObject.setOffset(offset);
  541.             queryString = sqlQueryObject.createSQLQuery();
  542.             stmt = con.prepareStatement(queryString);
  543.             risultato = stmt.executeQuery();

  544.            
  545.             while (risultato.next()) {
  546.                 CanaleConfigurazione canale = new CanaleConfigurazione();
  547.                 canale.setId(risultato.getLong("id"));
  548.                 canale.setNome(risultato.getString("nome"));
  549.                 canale.setDescrizione(risultato.getString("descrizione"));
  550.                 int v = risultato.getInt("canale_default");
  551.                 if(v == CostantiDB.TRUE) {
  552.                     canale.setCanaleDefault(true);
  553.                 }
  554.                 else {
  555.                     canale.setCanaleDefault(false);
  556.                 }
  557.                
  558.                 lista.add(canale);
  559.            
  560.             }
  561.             risultato.close();
  562.             stmt.close();
  563.            
  564.             return lista;

  565.         } catch (Exception qe) {
  566.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB::" + nomeMetodo + "] Errore : " + qe.getMessage(),qe);
  567.         } finally {

  568.             //Chiudo statement and resultset
  569.             JDBCUtilities.closeResources(risultato, stmt);

  570.             this.driver.closeConnection(con);
  571.         }
  572.     }
  573.    
  574.     protected List<CanaleConfigurazioneNodo> canaleNodoConfigurazioneList(ISearch ricerca) throws DriverConfigurazioneException {
  575.         String nomeMetodo = "canaleNodoConfigurazioneList";
  576.         int idLista = Liste.CONFIGURAZIONE_CANALI_NODI;
  577.         int offset;
  578.         int limit;
  579.         String queryString;
  580.         String search;

  581.         limit = ricerca.getPageSize(idLista);
  582.         offset = ricerca.getIndexIniziale(idLista);
  583.         search = (org.openspcoop2.core.constants.Costanti.SESSION_ATTRIBUTE_VALUE_RICERCA_UNDEFINED.equals(ricerca.getSearchString(idLista)) ? "" : ricerca.getSearchString(idLista));

  584.         Connection con = null;
  585.         PreparedStatement stmt=null;
  586.         ResultSet risultato=null;
  587.         ArrayList<CanaleConfigurazioneNodo> lista = new ArrayList<>();

  588.         if (this.driver.atomica) {
  589.             try {
  590.                 con = this.driver.getConnectionFromDatasource(nomeMetodo);
  591.             } catch (Exception e) {
  592.                 throw new DriverConfigurazioneException("[DriverConfigurazioneDB::" + nomeMetodo + "] Exception accedendo al datasource :" + e.getMessage(),e);

  593.             }

  594.         } else
  595.             con = this.driver.globalConnection;

  596.         this.driver.logDebug("operazione this.driver.atomica = " + this.driver.atomica);

  597.         try {

  598.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  599.             sqlQueryObject.addFromTable(CostantiDB.CONFIGURAZIONE_CANALI_NODI);
  600.             sqlQueryObject.addSelectCountField("id", "cont");
  601.            
  602.             if (!search.equals("")) {
  603.                 sqlQueryObject.addWhereLikeCondition("nome", search, true, true);
  604.             }
  605.            
  606.             queryString = sqlQueryObject.createSQLQuery();
  607.             stmt = con.prepareStatement(queryString);
  608.             risultato = stmt.executeQuery();
  609.             if (risultato.next())
  610.                 ricerca.setNumEntries(idLista,risultato.getInt(1));
  611.             risultato.close();
  612.             stmt.close();

  613.             // ricavo le entries
  614.             if (limit == 0) // con limit
  615.                 limit = ISQLQueryObject.LIMIT_DEFAULT_VALUE;

  616.             sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  617.             sqlQueryObject.addFromTable(CostantiDB.CONFIGURAZIONE_CANALI_NODI);
  618.             sqlQueryObject.addSelectField("id");
  619.             sqlQueryObject.addSelectField("nome");            
  620.             sqlQueryObject.addSelectField("descrizione");    
  621.             sqlQueryObject.addSelectField("canali");        
  622.            
  623.             if (!search.equals("")) {
  624.                 sqlQueryObject.addWhereLikeCondition("nome", search, true, true);
  625.             }
  626.             sqlQueryObject.addOrderBy("nome");
  627.             sqlQueryObject.setSortType(true);
  628.             sqlQueryObject.setLimit(limit);
  629.             sqlQueryObject.setOffset(offset);
  630.             queryString = sqlQueryObject.createSQLQuery();
  631.             stmt = con.prepareStatement(queryString);
  632.             risultato = stmt.executeQuery();

  633.            
  634.             while (risultato.next()) {
  635.                 CanaleConfigurazioneNodo canaleNodo = new CanaleConfigurazioneNodo();
  636.                 canaleNodo.setId(risultato.getLong("id"));
  637.                 canaleNodo.setNome(risultato.getString("nome"));
  638.                 canaleNodo.setDescrizione(risultato.getString("descrizione"));
  639.                 List<String> l = DBUtils.convertToList(risultato.getString("canali"));
  640.                 canaleNodo.setCanaleList(l);
  641.                
  642.                 lista.add(canaleNodo);
  643.            
  644.             }
  645.             risultato.close();
  646.             stmt.close();
  647.            
  648.             return lista;

  649.         } catch (Exception qe) {
  650.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB::" + nomeMetodo + "] Errore : " + qe.getMessage(),qe);
  651.         } finally {

  652.             //Chiudo statement and resultset
  653.             JDBCUtilities.closeResources(risultato, stmt);

  654.             this.driver.closeConnection(con);
  655.         }
  656.     }
  657.    
  658.    
  659.    
  660.     protected boolean existsFaseTracciamentoDBRequestIn(boolean erogazioni, boolean fruizioni) throws DriverConfigurazioneException {
  661.         return existsFaseTracciamentoDB("existsFaseTracciamentoDBRequestIn", erogazioni, fruizioni,
  662.                 true, false, false);
  663.     }
  664.     protected boolean existsFaseTracciamentoDBRequestOut(boolean erogazioni, boolean fruizioni) throws DriverConfigurazioneException {
  665.         return existsFaseTracciamentoDB("existsFaseTracciamentoDBRequestOut", erogazioni, fruizioni,
  666.                 false, true, false);
  667.     }
  668.     protected boolean existsFaseTracciamentoDBResponseOut(boolean erogazioni, boolean fruizioni) throws DriverConfigurazioneException {
  669.         return existsFaseTracciamentoDB("existsFaseTracciamentoDBResponseOut", erogazioni, fruizioni,
  670.                 false, false, true);
  671.     }
  672.     private boolean existsFaseTracciamentoDB(String nomeMetodo, boolean erogazioni, boolean fruizioni,
  673.             boolean inRequest, boolean outRequest, boolean outResponse) throws DriverConfigurazioneException {
  674.        
  675.         Connection con = null;
  676.         PreparedStatement stmt=null;
  677.         ResultSet risultato=null;

  678.         if (this.driver.atomica) {
  679.             try {
  680.                 con = this.driver.getConnectionFromDatasource(nomeMetodo);
  681.             } catch (Exception e) {
  682.                 throw new DriverConfigurazioneException("[DriverConfigurazioneDB::" + nomeMetodo + "] Exception accedendo al datasource :" + e.getMessage(),e);

  683.             }

  684.         } else
  685.             con = this.driver.globalConnection;

  686.         this.driver.logDebug("operazione this.driver.atomica = " + this.driver.atomica);

  687.         try {

  688.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  689.             sqlQueryObject.addFromTable(CostantiDB.TRACCIAMENTO_CONFIGURAZIONE);
  690.             sqlQueryObject.addSelectCountField("id", "cont");
  691.             sqlQueryObject.addWhereLikeCondition("stato", StatoFunzionalitaConPersonalizzazione.PERSONALIZZATO.getValue(), false, false);
  692.             sqlQueryObject.addWhereLikeCondition(CostantiDB.TRACCIAMENTO_CONFIGURAZIONE_COLUMN_TIPO, CostantiDB.TRACCIAMENTO_CONFIGURAZIONE_TIPO_DB, false, false);
  693.             List<String> valori = new ArrayList<>();
  694.             if(erogazioni) {
  695.                 valori.add(CostantiDB.TRACCIAMENTO_CONFIGURAZIONE_PROPRIETARIO_CONFIG_PA);
  696.                 valori.add(CostantiDB.TRACCIAMENTO_CONFIGURAZIONE_PROPRIETARIO_PA);
  697.             }
  698.             if(fruizioni) {
  699.                 valori.add(CostantiDB.TRACCIAMENTO_CONFIGURAZIONE_PROPRIETARIO_CONFIG_PD);
  700.                 valori.add(CostantiDB.TRACCIAMENTO_CONFIGURAZIONE_PROPRIETARIO_PD);
  701.             }
  702.             sqlQueryObject.addWhereINCondition(CostantiDB.TRACCIAMENTO_CONFIGURAZIONE_COLUMN_PROPRIETARIO, true, valori.toArray(new String[1]));
  703.             if(inRequest) {
  704.                 sqlQueryObject.addWhereLikeCondition("request_in", StatoFunzionalita.ABILITATO.getValue(), false, false);
  705.             }
  706.             if(outRequest) {
  707.                 sqlQueryObject.addWhereLikeCondition("request_out", StatoFunzionalita.ABILITATO.getValue(), false, false);
  708.             }
  709.             if(outResponse) {
  710.                 sqlQueryObject.addWhereLikeCondition("response_out", StatoFunzionalita.ABILITATO.getValue(), false, false);
  711.             }
  712.             sqlQueryObject.setANDLogicOperator(true);
  713.            
  714.             String queryString = sqlQueryObject.createSQLQuery();
  715.             stmt = con.prepareStatement(queryString);
  716.             risultato = stmt.executeQuery();
  717.             boolean result = false;
  718.             if (risultato.next()) {
  719.                 int c = risultato.getInt(1);
  720.                 result = c>0;
  721.             }
  722.             risultato.close();
  723.             stmt.close();

  724.             return result;

  725.         } catch (Exception qe) {
  726.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB::" + nomeMetodo + "] Errore : " + qe.getMessage(),qe);
  727.         } finally {

  728.             //Chiudo statement and resultset
  729.             JDBCUtilities.closeResources(risultato, stmt);

  730.             this.driver.closeConnection(con);
  731.         }
  732.     }
  733. }