DriverUsersDB.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.lib.users;

  21. import java.sql.Connection;
  22. import java.sql.DriverManager;
  23. import java.sql.PreparedStatement;
  24. import java.sql.ResultSet;
  25. import java.sql.SQLException;
  26. import java.sql.Timestamp;
  27. import java.util.ArrayList;
  28. import java.util.Date;
  29. import java.util.List;
  30. import java.util.Properties;

  31. import javax.sql.DataSource;

  32. import org.openspcoop2.core.commons.DBUtils;
  33. import org.openspcoop2.core.commons.Filtri;
  34. import org.openspcoop2.core.commons.ISearch;
  35. import org.openspcoop2.core.commons.Liste;
  36. import org.openspcoop2.core.commons.SearchUtils;
  37. import org.openspcoop2.core.commons.search.AccordoServizioParteSpecifica;
  38. import org.openspcoop2.core.commons.search.Soggetto;
  39. import org.openspcoop2.core.commons.search.dao.IDBAccordoServizioParteSpecificaServiceSearch;
  40. import org.openspcoop2.core.commons.search.dao.IDBSoggettoServiceSearch;
  41. import org.openspcoop2.core.commons.search.dao.jdbc.JDBCServiceManager;
  42. import org.openspcoop2.core.constants.CostantiDB;
  43. import org.openspcoop2.core.id.IDServizio;
  44. import org.openspcoop2.core.id.IDSoggetto;
  45. import org.openspcoop2.core.registry.constants.PddTipologia;
  46. import org.openspcoop2.core.registry.driver.IDServizioFactory;
  47. import org.openspcoop2.generic_project.dao.jdbc.JDBCServiceManagerProperties;
  48. import org.openspcoop2.protocol.sdk.tracciamento.DriverTracciamentoException;
  49. import org.openspcoop2.utils.LoggerWrapperFactory;
  50. import org.openspcoop2.utils.TipiDatabase;
  51. import org.openspcoop2.utils.date.DateManager;
  52. import org.openspcoop2.utils.resources.GestoreJNDI;
  53. import org.openspcoop2.utils.sql.ISQLQueryObject;
  54. import org.openspcoop2.utils.sql.SQLObjectFactory;
  55. import org.openspcoop2.web.lib.users.dao.InterfaceType;
  56. import org.openspcoop2.web.lib.users.dao.PermessiUtente;
  57. import org.openspcoop2.web.lib.users.dao.Stato;
  58. import org.openspcoop2.web.lib.users.dao.UserObjects;
  59. import org.openspcoop2.web.lib.users.dao.User;
  60. import org.openspcoop2.web.lib.users.dao.UserPassword;
  61. import org.slf4j.Logger;

  62. /**
  63.  * Sono forniti metodi per la lettura dei dati di Users
  64.  *
  65.  *
  66.  * @author Andrea Poli (apoli@link.it)
  67.  * @author Stefano Corallo (corallo@link.it)
  68.  * @author Sandra Giangrandi (sandra@link.it)
  69.  * @author $Author$
  70.  * @version $Rev$, $Date$
  71.  *
  72.  */

  73. public class DriverUsersDB {

  74.      private static final String LOG_DRIVER_DB_USER = "DRIVER_DB_USER";
  75.    
  76.     /**
  77.      * DataSource
  78.      */
  79.     private DataSource datasource = null;
  80.     /**
  81.      * Connessione
  82.      */
  83.     private Connection connection = null;
  84.     private boolean connectionOpenViaJDBCInCostructor = false;
  85.     /**
  86.      * SQLQueryObject
  87.      */
  88.     String tipoDatabase = null;
  89.     /**
  90.      * Logger
  91.      */
  92.     private Logger log;

  93.    
  94.     public void close() throws DriverTracciamentoException {
  95.         try{
  96.             if(this.connectionOpenViaJDBCInCostructor){
  97.                 if(this.connection!=null && this.connection.isClosed()==false){
  98.                     this.connection.close();
  99.                 }
  100.             }
  101.         }catch(Exception e){
  102.             throw new DriverTracciamentoException(e.getMessage(),e);
  103.         }
  104.     }
  105.    
  106.    
  107.    
  108.     public DriverUsersDB(String nomeDataSource, String tipoDatabase, Properties jndiContext) throws DriverUsersDBException {
  109.         this(nomeDataSource, tipoDatabase, jndiContext, null);
  110.     }
  111.     public DriverUsersDB(String nomeDataSource, String tipoDatabase, Properties jndiContext, Logger log) throws DriverUsersDBException {
  112.        
  113.         // Logger
  114.         try {
  115.             if(log==null)
  116.                 this.log = LoggerWrapperFactory.getLogger(LOG_DRIVER_DB_USER);
  117.             else
  118.                 this.log = log;
  119.         } catch (Exception e) {
  120.             throw new DriverUsersDBException("Errore durante l'inizializzazione del logger...",e);
  121.         }

  122.         // Datasource
  123.         try {
  124.             this.log.info("Inizializzo DriverUsersDB...");
  125.             GestoreJNDI gestoreJNDI = new GestoreJNDI(jndiContext);
  126.             this.datasource = (DataSource) gestoreJNDI.lookup(nomeDataSource);
  127.             if (this.datasource == null)
  128.                 throw new Exception ("datasource is null");

  129.             this.log.info("Inizializzo DriverUsersDB terminata.");
  130.         } catch (Exception e) {
  131.             this.log.error("Errore durante la ricerca del datasource...",e);
  132.             throw new DriverUsersDBException("Errore durante la ricerca del datasource...",e);
  133.         }

  134.         // ISQLQueryObject
  135.         try {
  136.             this.log.info("Inizializzo ISQLQueryObject...");
  137.             if (TipiDatabase.isAMember(tipoDatabase)) {
  138.                 this.tipoDatabase = tipoDatabase;              
  139.             } else {
  140.                 throw new Exception("Tipo database non gestito");
  141.             }
  142.             this.log.info("Inizializzo ISQLQueryObject terminata.");

  143.         } catch (Exception e) {
  144.             this.log.error("Errore durante la ricerca del SQLQueryObject...",e);
  145.             throw new DriverUsersDBException("Errore durante la ricerca del SQLQueryObject...",e);
  146.         }
  147.        
  148.     }
  149.    
  150.     public DriverUsersDB(DataSource dataSourceObject, String tipoDatabase) throws DriverUsersDBException {
  151.         this(dataSourceObject, tipoDatabase, null);
  152.     }
  153.     public DriverUsersDB(DataSource dataSourceObject, String tipoDatabase, Logger log) throws DriverUsersDBException {
  154.        
  155.         // Logger
  156.         try {
  157.             if(log==null)
  158.                 this.log = LoggerWrapperFactory.getLogger(LOG_DRIVER_DB_USER);
  159.             else
  160.                 this.log = log;
  161.         } catch (Exception e) {
  162.             throw new DriverUsersDBException("Errore durante l'inizializzazione del logger...",e);
  163.         }

  164.         // Datasource
  165.         try {
  166.             this.datasource = dataSourceObject;
  167.             if (this.datasource == null)
  168.                 throw new Exception ("datasource is null");
  169.         } catch (Exception e) {
  170.             this.log.error("Errore durante la ricerca del datasource...",e);
  171.             throw new DriverUsersDBException("Errore durante la ricerca del datasource...",e);
  172.         }

  173.         // ISQLQueryObject
  174.         try {
  175.             this.log.info("Inizializzo ISQLQueryObject...");
  176.             if (TipiDatabase.isAMember(tipoDatabase)) {
  177.                 this.tipoDatabase = tipoDatabase;              
  178.             } else {
  179.                 throw new Exception("Tipo database non gestito");
  180.             }
  181.             this.log.info("Inizializzo ISQLQueryObject terminata.");

  182.         } catch (Exception e) {
  183.             this.log.error("Errore durante la ricerca del SQLQueryObject...",e);
  184.             throw new DriverUsersDBException("Errore durante la ricerca del SQLQueryObject...",e);
  185.         }
  186.     }
  187.    
  188.     public DriverUsersDB(Connection connection, String tipoDatabase) throws DriverUsersDBException {
  189.         this(connection, tipoDatabase, null);
  190.     }
  191.     public DriverUsersDB(Connection connection, String tipoDatabase, Logger log) throws DriverUsersDBException {
  192.        
  193.         // Logger
  194.         try {
  195.             if(log==null)
  196.                 this.log = LoggerWrapperFactory.getLogger(LOG_DRIVER_DB_USER);
  197.             else
  198.                 this.log = log;
  199.         } catch (Exception e) {
  200.             throw new DriverUsersDBException("Errore durante l'inizializzazione del logger...",e);
  201.         }

  202.         // connection
  203.         this.connection = connection;
  204.        
  205.         // ISQLQueryObject
  206.         try {
  207.             this.log.info("Inizializzo ISQLQueryObject...");
  208.             if (TipiDatabase.isAMember(tipoDatabase)) {
  209.                 this.tipoDatabase = tipoDatabase;              
  210.             } else {
  211.                 throw new Exception("Tipo database non gestito");
  212.             }
  213.             this.log.info("Inizializzo ISQLQueryObject terminata.");

  214.         } catch (Exception e) {
  215.             this.log.error("Errore durante la ricerca del SQLQueryObject...",e);
  216.             throw new DriverUsersDBException("Errore durante la ricerca del SQLQueryObject...",e);
  217.         }
  218.     }
  219.    
  220.     public DriverUsersDB(String urlJDBC,String driverJDBC,
  221.             String username,String password,
  222.             String tipoDatabase) throws DriverUsersDBException {
  223.         this(urlJDBC, driverJDBC, username, password, tipoDatabase, null);
  224.     }
  225.     public DriverUsersDB(String urlJDBC,String driverJDBC,
  226.             String username,String password,
  227.             String tipoDatabase, Logger log) throws DriverUsersDBException {
  228.        
  229.         // Logger
  230.         try {
  231.             if(log==null)
  232.                 this.log = LoggerWrapperFactory.getLogger(LOG_DRIVER_DB_USER);
  233.             else
  234.                 this.log = log;
  235.         } catch (Exception e) {
  236.             throw new DriverUsersDBException("Errore durante l'inizializzazione del logger...",e);
  237.         }

  238.         // connection
  239.         try {
  240.             Class.forName(driverJDBC);
  241.            
  242.             if(username!=null){
  243.                 this.connection = DriverManager.getConnection(urlJDBC,username,password);
  244.             }else{
  245.                 this.connection = DriverManager.getConnection(urlJDBC);
  246.             }
  247.             this.connectionOpenViaJDBCInCostructor = true;
  248.            
  249.         } catch (Exception e) {
  250.             this.log.error("Errore durante l'inizializzazione della connessione...",e);
  251.             throw new DriverUsersDBException("Errore durante l'inizializzazione della connessione...",e);
  252.         }
  253.        
  254.         // ISQLQueryObject
  255.         try {
  256.             this.log.info("Inizializzo ISQLQueryObject...");
  257.             if (TipiDatabase.isAMember(tipoDatabase)) {
  258.                 this.tipoDatabase = tipoDatabase;              
  259.             } else {
  260.                 throw new Exception("Tipo database non gestito");
  261.             }
  262.             this.log.info("Inizializzo ISQLQueryObject terminata.");

  263.         } catch (Exception e) {
  264.             this.log.error("Errore durante la ricerca del SQLQueryObject...",e);
  265.             throw new DriverUsersDBException("Errore durante la ricerca del SQLQueryObject...",e);
  266.         }
  267.        
  268.     }
  269.    
  270.    
  271.     private Connection getConnection() throws Exception {
  272.         Connection connectionDB = null;
  273.         if(this.connection!=null)
  274.             connectionDB = this.connection;
  275.         else{
  276.             connectionDB = this.datasource.getConnection();
  277.         }
  278.         checkConnection(connectionDB);
  279.         return connectionDB;
  280.     }
  281.     private void checkConnection(Connection connectionDB) throws Exception {
  282.         if(connectionDB==null)
  283.             throw new Exception("Connection non ottenuta dal datasource["+this.datasource+"]");
  284.     }
  285.     private void releaseConnection(Connection connectionDB) {
  286.         try{
  287.             if(this.connection==null) {
  288.                 if(connectionDB!=null) {
  289.                     connectionDB.close();
  290.                 }
  291.             }
  292.         }catch(Exception eClose){
  293.             // close
  294.         }
  295.     }


  296.     /**
  297.      * Restituisce l'utente identificato da <var>login</var>
  298.      *
  299.      * @param login
  300.      *                Identificatore di un utente
  301.      * @return L'utente identificato dal parametro.
  302.      */
  303.     public User getUser(String login) throws DriverUsersDBException {
  304.         if (login == null)
  305.             throw new DriverUsersDBException("[getUser] Parametri Non Validi");

  306.         Connection connectionDB = null;
  307.         try {
  308.             // Get Connection
  309.             connectionDB = getConnection();
  310.            
  311.             return getUser(connectionDB, login);
  312.            
  313.         } catch (SQLException se) {
  314.             throw new DriverUsersDBException("[DriverUsersDB::getUser] SqlException: " + se.getMessage(),se);
  315.         } catch (Exception ex) {
  316.             throw new DriverUsersDBException("[DriverUsersDB::getUser] Exception: " + ex.getMessage(),ex);
  317.         } finally {
  318.             releaseConnection(connectionDB);
  319.         }
  320.     }
  321.    
  322.     public User getUser(Connection conParam, String login) throws DriverUsersDBException {
  323.         if (login == null)
  324.             throw new DriverUsersDBException("[getUser] Parametri Non Validi");

  325.         User user = null;
  326.         PreparedStatement stm = null;
  327.         ResultSet rs = null;

  328.         try {
  329.            
  330.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  331.             sqlQueryObject.addFromTable(CostantiDB.USERS);
  332.             sqlQueryObject.addSelectField("*");
  333.             sqlQueryObject.addWhereCondition("login = ?");
  334.             String sqlQuery = sqlQueryObject.createSQLQuery();
  335.             stm = conParam.prepareStatement(sqlQuery);
  336.             stm.setString(1, login);
  337.             rs = stm.executeQuery();
  338.             if (rs.next()) {
  339.                 user = new User();
  340.                 user.setId(Long.valueOf(rs.getInt("id")));
  341.                 user.setLogin(login);
  342.                 user.setPassword(rs.getString("password"));
  343.                 user.setLastUpdatePassword(rs.getTimestamp("data_password"));
  344.                 user.setCheckLastUpdatePassword(rs.getInt("check_data_password") == CostantiDB.TRUE);
  345.                
  346.                 String gui =rs.getString("tipo_interfaccia");
  347.                 if(gui==null || "".equals(gui))
  348.                     user.setInterfaceType(InterfaceType.AVANZATA);
  349.                 else
  350.                     user.setInterfaceType(InterfaceType.valueOf(gui.toUpperCase()));

  351.                 int interfaceCompletePermit = rs.getInt("interfaccia_completa");
  352.                 if(CostantiDB.TRUE == interfaceCompletePermit) {
  353.                     user.setPermitInterfaceComplete(true);
  354.                 }
  355.                 else {
  356.                     user.setPermitInterfaceComplete(false);
  357.                 }
  358.                
  359.                 String perm =rs.getString("permessi");
  360.                 user.setPermessi(PermessiUtente.toPermessiUtente(perm));
  361.                
  362.                 String protocolli =rs.getString("protocolli");
  363.                 user.setProtocolliSupportatiFromString(protocolli);
  364.                
  365.                 String protocollo_pddconsole =rs.getString("protocollo_pddconsole");
  366.                 user.setProtocolloSelezionatoPddConsole(protocollo_pddconsole);
  367.                
  368.                 String protocollo_pddmonitor =rs.getString("protocollo_pddmonitor");
  369.                 user.setProtocolloSelezionatoPddMonitor(protocollo_pddmonitor);
  370.                
  371.                 String soggetto_pddconsole =rs.getString("soggetto_pddconsole");
  372.                 user.setSoggettoSelezionatoPddConsole(soggetto_pddconsole);
  373.                
  374.                 String soggetto_pddmonitor =rs.getString("soggetto_pddmonitor");
  375.                 user.setSoggettoSelezionatoPddMonitor(soggetto_pddmonitor);
  376.                
  377.                 int permitAllSoggetti = rs.getInt("soggetti_all");
  378.                 if(CostantiDB.TRUE == permitAllSoggetti) {
  379.                     user.setPermitAllSoggetti(true);
  380.                 }
  381.                 else {
  382.                     user.setPermitAllSoggetti(false);
  383.                 }
  384.                
  385.                 int permitAllServizi = rs.getInt("servizi_all");
  386.                 if(CostantiDB.TRUE == permitAllServizi) {
  387.                     user.setPermitAllServizi(true);
  388.                 }
  389.                 else {
  390.                     user.setPermitAllServizi(false);
  391.                 }
  392.                
  393.                 // Fix: se completa, siamo per forza in modalità completa
  394.                 if(user.isPermitInterfaceComplete()) {
  395.                     user.setInterfaceType(InterfaceType.COMPLETA);
  396.                 }
  397.                
  398.             }
  399.             rs.close();
  400.             stm.close();
  401.            
  402.             if (user == null)
  403.                 throw new DriverUsersDBException("[DriverUsersDB::getUser] User [" + login + "] non esistente.");
  404.            
  405.             JDBCServiceManagerProperties jdbcProperties = new JDBCServiceManagerProperties();
  406.             jdbcProperties.setDatabaseType(this.tipoDatabase);
  407.             jdbcProperties.setShowSql(true);
  408.             JDBCServiceManager search = new JDBCServiceManager(conParam, jdbcProperties, this.log);
  409.             IDBSoggettoServiceSearch soggettiSearch = (IDBSoggettoServiceSearch) search.getSoggettoServiceSearch();
  410.             IDBAccordoServizioParteSpecificaServiceSearch serviziSearch = (IDBAccordoServizioParteSpecificaServiceSearch) search.getAccordoServizioParteSpecificaServiceSearch();
  411.            
  412.             sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  413.             sqlQueryObject.addFromTable(CostantiDB.USERS_STATI);
  414.             sqlQueryObject.addSelectField("*");
  415.             sqlQueryObject.addWhereCondition("id_utente = ?");
  416.             sqlQueryObject.addOrderBy(CostantiDB.USERS_STATI+".oggetto");
  417.             sqlQueryObject.setSortType(true);
  418.             sqlQueryObject.setANDLogicOperator(true);
  419.             sqlQuery = sqlQueryObject.createSQLQuery();
  420.             stm = conParam.prepareStatement(sqlQuery);
  421.             stm.setLong(1, user.getId());
  422.             rs = stm.executeQuery();
  423.             while (rs.next()) {
  424.                 String oggetto = rs.getString("oggetto");
  425.                 String stato = rs.getString("stato");
  426.                 Stato statoObject = new Stato();
  427.                 statoObject.setOggetto(oggetto);
  428.                 statoObject.setStato(stato);
  429.                 user.getStati().add(statoObject);
  430.             }
  431.             rs.close();
  432.             stm.close();
  433.            
  434.             sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  435.             sqlQueryObject.addFromTable(CostantiDB.USERS_PASSWORD);
  436.             sqlQueryObject.addSelectField("*");
  437.             sqlQueryObject.addWhereCondition("id_utente = ?");
  438.             sqlQueryObject.addOrderBy(CostantiDB.USERS_PASSWORD+".data_password");
  439.             sqlQueryObject.setSortType(false);
  440.             sqlQueryObject.setANDLogicOperator(true);
  441.             sqlQuery = sqlQueryObject.createSQLQuery();
  442.             stm = conParam.prepareStatement(sqlQuery);
  443.             stm.setLong(1, user.getId());
  444.             rs = stm.executeQuery();
  445.             while (rs.next()) {
  446.                 UserPassword userPassword = new UserPassword();
  447.                 userPassword.setPassword(rs.getString("password"));
  448.                 userPassword.setDatePassword(rs.getTimestamp("data_password"));
  449.                 user.getPrecedentiPassword().add(userPassword);
  450.             }
  451.             rs.close();
  452.             stm.close();
  453.            
  454.             sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  455.             sqlQueryObject.addFromTable(CostantiDB.USERS_SOGGETTI);
  456.             sqlQueryObject.addFromTable(CostantiDB.SOGGETTI);
  457.             sqlQueryObject.addSelectField(CostantiDB.USERS_SOGGETTI+".id_soggetto");
  458.             sqlQueryObject.addSelectField(CostantiDB.SOGGETTI+".nome_soggetto");
  459.             sqlQueryObject.addSelectField(CostantiDB.SOGGETTI+".tipo_soggetto");
  460.             sqlQueryObject.addWhereCondition("id_utente = ?");
  461.             sqlQueryObject.addWhereCondition(CostantiDB.USERS_SOGGETTI+".id_soggetto = "+CostantiDB.SOGGETTI+".id");
  462.             sqlQueryObject.addOrderBy(CostantiDB.SOGGETTI+".nome_soggetto");
  463.             sqlQueryObject.addOrderBy(CostantiDB.SOGGETTI+".tipo_soggetto");
  464.             sqlQueryObject.setSortType(true);
  465.             sqlQueryObject.setANDLogicOperator(true);
  466.             sqlQuery = sqlQueryObject.createSQLQuery();
  467.             stm = conParam.prepareStatement(sqlQuery);
  468.             stm.setLong(1, user.getId());
  469.             rs = stm.executeQuery();
  470.             while (rs.next()) {
  471.                 long id = rs.getLong("id_soggetto");
  472.                 Soggetto soggetto = soggettiSearch.get(id);
  473.                 IDSoggetto idSoggetto = new IDSoggetto(soggetto.getTipoSoggetto(), soggetto.getNomeSoggetto(), soggetto.getIdentificativoPorta());
  474.                 user.getSoggetti().add(idSoggetto);
  475.             }
  476.             rs.close();
  477.             stm.close();
  478.            
  479.             sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  480.             sqlQueryObject.addFromTable(CostantiDB.USERS_SERVIZI);
  481.             sqlQueryObject.addFromTable(CostantiDB.SERVIZI);
  482.             sqlQueryObject.addFromTable(CostantiDB.SOGGETTI);
  483.             sqlQueryObject.addSelectField(CostantiDB.USERS_SERVIZI+".id_servizio");
  484.             sqlQueryObject.addSelectField(CostantiDB.SERVIZI+".tipo_servizio");
  485.             sqlQueryObject.addSelectField(CostantiDB.SERVIZI+".nome_servizio");
  486.             sqlQueryObject.addSelectField(CostantiDB.SERVIZI+".versione_servizio");
  487.             sqlQueryObject.addSelectField(CostantiDB.SOGGETTI+".tipo_soggetto");
  488.             sqlQueryObject.addSelectField(CostantiDB.SOGGETTI+".nome_soggetto");
  489.             sqlQueryObject.addWhereCondition("id_utente = ?");
  490.             sqlQueryObject.addWhereCondition(CostantiDB.USERS_SERVIZI+".id_servizio = "+CostantiDB.SERVIZI+".id");
  491.             sqlQueryObject.addWhereCondition(CostantiDB.SERVIZI+".id_soggetto = "+CostantiDB.SOGGETTI+".id");
  492.             sqlQueryObject.addOrderBy(CostantiDB.SERVIZI+".nome_servizio");
  493.             sqlQueryObject.addOrderBy(CostantiDB.SERVIZI+".versione_servizio");
  494.             sqlQueryObject.addOrderBy(CostantiDB.SOGGETTI+".nome_soggetto");
  495.             sqlQueryObject.addOrderBy(CostantiDB.SERVIZI+".tipo_servizio");
  496.             sqlQueryObject.addOrderBy(CostantiDB.SOGGETTI+".tipo_soggetto");
  497.             sqlQueryObject.setSortType(true);
  498.             sqlQueryObject.setANDLogicOperator(true);
  499.             sqlQuery = sqlQueryObject.createSQLQuery();
  500.             stm = conParam.prepareStatement(sqlQuery);
  501.             stm.setLong(1, user.getId());
  502.             rs = stm.executeQuery();
  503.             while (rs.next()) {
  504.                 long id = rs.getLong("id_servizio");
  505.                 AccordoServizioParteSpecifica servizio = serviziSearch.get(id);
  506.                 IDServizio idServizio = IDServizioFactory.getInstance().getIDServizioFromValues(servizio.getTipo(),
  507.                         servizio.getNome(),
  508.                         servizio.getIdErogatore().getTipo(),
  509.                         servizio.getIdErogatore().getNome(),
  510.                         servizio.getVersione());
  511.                 user.getServizi().add(idServizio);
  512.             }
  513.             rs.close();
  514.             stm.close();


  515.             return user;
  516.         } catch (SQLException se) {
  517.             throw new DriverUsersDBException("[DriverUsersDB::getUser] SqlException: " + se.getMessage(),se);
  518.         } catch (Exception ex) {
  519.             throw new DriverUsersDBException("[DriverUsersDB::getUser] Exception: " + ex.getMessage(),ex);
  520.         } finally {
  521.             try {
  522.                 rs.close();
  523.             } catch (Exception e) {
  524.                 // ignore exception
  525.             }
  526.             try {
  527.                 stm.close();
  528.             } catch (Exception e) {
  529.                 // ignore exception
  530.             }
  531.         }
  532.     }

  533.     public User getUser(Long id) throws DriverUsersDBException {
  534.         if (id == null || id<=0)
  535.             throw new DriverUsersDBException("[getUser] Parametri Non Validi");

  536.         Connection connectionDB = null;
  537.         User user = null;
  538.         PreparedStatement stm = null;
  539.         ResultSet rs = null;

  540.         try {
  541.             // Get Connection
  542.             connectionDB = getConnection();
  543.            
  544.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  545.             sqlQueryObject.addFromTable(CostantiDB.USERS);
  546.             sqlQueryObject.addSelectField("login");
  547.             sqlQueryObject.addWhereCondition("id = ?");
  548.             String sqlQuery = sqlQueryObject.createSQLQuery();
  549.             stm = connectionDB.prepareStatement(sqlQuery);
  550.             stm.setLong(1, id);
  551.             rs = stm.executeQuery();
  552.             if (rs.next()) {
  553.                 user = this.getUser(connectionDB, rs.getString("login"));
  554.             }
  555.             rs.close();
  556.             stm.close();

  557.             if (user == null)
  558.                 throw new DriverUsersDBException("[DriverUsersDB::getUser] User [id:" + id + "] non esistente.");

  559.             return user;
  560.         } catch (SQLException se) {
  561.             throw new DriverUsersDBException("[DriverUsersDB::getUser] SqlException: " + se.getMessage(),se);
  562.         } catch (Exception ex) {
  563.             throw new DriverUsersDBException("[DriverUsersDB::getUser] Exception: " + ex.getMessage(),ex);
  564.         } finally {
  565.             try {
  566.                 if(rs!=null) {
  567.                     rs.close();
  568.                 }
  569.             } catch (Exception e) {
  570.                 // ignore exception
  571.             }
  572.             try {
  573.                 if(stm!=null) {
  574.                     stm.close();
  575.                 }
  576.             } catch (Exception e) {
  577.                 // ignore exception
  578.             }
  579.             releaseConnection(connectionDB);

  580.         }
  581.     }
  582.    
  583.     public List<User> userList(ISearch ricerca) throws DriverUsersDBException {
  584.         return userList(ricerca,Liste.SU);
  585.     }
  586.     public List<User> userList(ISearch ricerca, int IDLISTA) throws DriverUsersDBException {
  587.        
  588.         String nomeMetodo = "userList";
  589.         int idLista = IDLISTA;
  590.         int offset;
  591.         int limit;
  592.         String search;
  593.         String queryString;

  594.         limit = ricerca.getPageSize(idLista);
  595.         offset = ricerca.getIndexIniziale(idLista);
  596.         search = (org.openspcoop2.core.constants.Costanti.SESSION_ATTRIBUTE_VALUE_RICERCA_UNDEFINED.equals(ricerca.getSearchString(idLista)) ? "" : ricerca.getSearchString(idLista));

  597.         Connection connectionDB = null;
  598.         PreparedStatement stmt = null;
  599.         ResultSet risultato = null;
  600.         ArrayList<User> lista = new ArrayList<User>();

  601.         try {
  602.             // Get Connection
  603.             connectionDB = getConnection();
  604.            
  605.             if (!search.equals("")) {
  606.                 //query con search
  607.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  608.                 sqlQueryObject.addFromTable(CostantiDB.USERS);
  609.                 sqlQueryObject.addSelectCountField("*", "cont");
  610.                 sqlQueryObject.addWhereLikeCondition("login", search, true, true);
  611.                 queryString = sqlQueryObject.createSQLQuery();
  612.             } else {
  613.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  614.                 sqlQueryObject.addFromTable(CostantiDB.USERS);
  615.                 sqlQueryObject.addSelectCountField("*", "cont");
  616.                 queryString = sqlQueryObject.createSQLQuery();
  617.             }
  618.             stmt = connectionDB.prepareStatement(queryString);
  619.             risultato = stmt.executeQuery();
  620.             if (risultato.next())
  621.                 ricerca.setNumEntries(idLista, risultato.getInt(1));
  622.             risultato.close();
  623.             stmt.close();

  624.             // ricavo le entries
  625.             if (limit == 0) // con limit
  626.                 limit = ISQLQueryObject.LIMIT_DEFAULT_VALUE;
  627.             if (!search.equals("")) { // con search
  628.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  629.                 sqlQueryObject.addFromTable(CostantiDB.USERS);
  630.                 sqlQueryObject.addSelectField("login");
  631.                 sqlQueryObject.addWhereLikeCondition("login", search, true, true);
  632.                 sqlQueryObject.addOrderBy("login");
  633.                 sqlQueryObject.setSortType(true);
  634.                 sqlQueryObject.setLimit(limit);
  635.                 sqlQueryObject.setOffset(offset);
  636.                 queryString = sqlQueryObject.createSQLQuery();
  637.             } else {
  638.                 // senza search
  639.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  640.                 sqlQueryObject.addFromTable(CostantiDB.USERS);
  641.                 sqlQueryObject.addSelectField("login");
  642.                 sqlQueryObject.addOrderBy("login");
  643.                 sqlQueryObject.setSortType(true);
  644.                 sqlQueryObject.setLimit(limit);
  645.                 sqlQueryObject.setOffset(offset);
  646.                 queryString = sqlQueryObject.createSQLQuery();
  647.             }
  648.             stmt = connectionDB.prepareStatement(queryString);
  649.             risultato = stmt.executeQuery();

  650.             User newU = null;
  651.             while (risultato.next()) {
  652.                 newU = this.getUser(connectionDB, risultato.getString("login"));
  653.                 lista.add(newU);
  654.             }
  655.             risultato.close();
  656.             return lista;

  657.         } catch (Exception qe) {
  658.             throw new DriverUsersDBException("[DriverUsersDB::" + nomeMetodo + "] Errore : " + qe.getMessage(),qe);
  659.         } finally {

  660.             //Chiudo statement and resultset
  661.             try {
  662.                 if(risultato!=null) {
  663.                     risultato.close();
  664.                 }
  665.             } catch (Exception e) {
  666.                 // ignore exception
  667.             }
  668.             try {
  669.                 if(stmt!=null) {
  670.                     stmt.close();
  671.                 }
  672.             } catch (Exception e) {
  673.                 // ignore exception
  674.             }
  675.             releaseConnection(connectionDB);

  676.         }
  677.     }

  678.     public boolean existsUser(String login) throws DriverUsersDBException {
  679.        
  680.         Connection connectionDB = null;
  681.         PreparedStatement stm = null;
  682.         ResultSet rs = null;
  683.         String sqlQuery = "";

  684.         try {
  685.             // Get Connection
  686.             connectionDB = getConnection();
  687.                        
  688.             boolean esiste = false;
  689.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  690.             sqlQueryObject.addFromTable(CostantiDB.USERS);
  691.             sqlQueryObject.addSelectField("*");
  692.             sqlQueryObject.addWhereCondition("login = ?");
  693.             sqlQuery = sqlQueryObject.createSQLQuery();
  694.             stm = connectionDB.prepareStatement(sqlQuery);
  695.             stm.setString(1, login);
  696.             rs = stm.executeQuery();
  697.             if (rs.next())
  698.                 esiste = true;
  699.             rs.close();
  700.             stm.close();

  701.             return esiste;
  702.         } catch (Exception qe) {
  703.             throw new DriverUsersDBException(qe.getMessage(),qe);
  704.         } finally {

  705.             //Chiudo statement and resultset
  706.             try {
  707.                 if(rs!=null) {
  708.                     rs.close();
  709.                 }
  710.             } catch (Exception e) {
  711.                 // ignore exception
  712.             }
  713.             try {
  714.                 if(stm!=null) {
  715.                     stm.close();
  716.                 }
  717.             } catch (Exception e) {
  718.                 // ignore exception
  719.             }
  720.            
  721.             releaseConnection(connectionDB);

  722.         }
  723.     }

  724.     public List<String> getUsersByPermesso(String permesso) throws DriverUsersDBException {
  725.        
  726.         Connection connectionDB = null;
  727.         PreparedStatement stm = null;
  728.         ResultSet rs = null;
  729.         String sqlQuery = "";

  730.         try {
  731.             // Get Connection
  732.             connectionDB = getConnection();
  733.            
  734.             List<String> userWithType = new ArrayList<>();
  735.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  736.             sqlQueryObject.addFromTable(CostantiDB.USERS);
  737.             sqlQueryObject.addSelectField("*");
  738.             sqlQueryObject.setANDLogicOperator(true);
  739.             sqlQueryObject.addWhereLikeCondition("permessi", permesso, true, true);
  740.             sqlQuery = sqlQueryObject.createSQLQuery();
  741.             stm = connectionDB.prepareStatement(sqlQuery);
  742.             rs = stm.executeQuery();
  743.             while (rs.next())
  744.                 userWithType.add(rs.getString("login"));
  745.             rs.close();
  746.             stm.close();

  747.             return userWithType;
  748.         } catch (Exception qe) {
  749.             throw new DriverUsersDBException(qe.getMessage(),qe);
  750.         } finally {

  751.             //Chiudo statement and resultset
  752.             try {
  753.                 if(rs!=null) {
  754.                     rs.close();
  755.                 }
  756.             } catch (Exception e) {
  757.                 // ignore exception
  758.             }
  759.             try {
  760.                 if(stm!=null) {
  761.                     stm.close();
  762.                 }
  763.             } catch (Exception e) {
  764.                 // ignore exception
  765.             }
  766.            
  767.             releaseConnection(connectionDB);

  768.         }
  769.     }
  770.    
  771.     public List<String> getUsersByProtocolloSupportato(String protocollo) throws DriverUsersDBException {
  772.         return getUsersByProtocolloSupportato(protocollo, false);
  773.     }
  774.    
  775.     public List<String> getUsersByProtocolloSupportato(String protocollo, boolean esclusiUtentiConSoloPermessoUtente) throws DriverUsersDBException {
  776.        
  777.         Connection connectionDB = null;
  778.         PreparedStatement stm = null;
  779.         ResultSet rs = null;
  780.         String sqlQuery = "";

  781.         try {
  782.             // Get Connection
  783.             connectionDB = getConnection();
  784.            
  785.             List<String> userWithType = new ArrayList<>();
  786.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  787.             sqlQueryObject.addFromTable(CostantiDB.USERS);
  788.             sqlQueryObject.addSelectField("*");
  789.             sqlQueryObject.setANDLogicOperator(true);
  790.            
  791.             ISQLQueryObject sqlQueryObjectPermit = sqlQueryObject.newSQLQueryObject();
  792.             sqlQueryObjectPermit.addWhereIsNullCondition("protocolli"); // significa che li supporta tutti
  793.             sqlQueryObjectPermit.addWhereLikeCondition("protocolli", protocollo, true, true);
  794.             sqlQueryObjectPermit.setANDLogicOperator(false);
  795.             sqlQueryObject.addWhereCondition(sqlQueryObjectPermit.createSQLConditions());
  796.             if(esclusiUtentiConSoloPermessoUtente)
  797.                 sqlQueryObject.addWhereCondition("permessi <> ?");
  798.            
  799.             sqlQuery = sqlQueryObject.createSQLQuery();
  800.             stm = connectionDB.prepareStatement(sqlQuery);
  801.            
  802.             if(esclusiUtentiConSoloPermessoUtente)
  803.                 stm.setString(1, "U");
  804.            
  805.             rs = stm.executeQuery();
  806.             while (rs.next())
  807.                 userWithType.add(rs.getString("login"));
  808.             rs.close();
  809.             stm.close();

  810.             return userWithType;
  811.         } catch (Exception qe) {
  812.             throw new DriverUsersDBException(qe.getMessage(),qe);
  813.         } finally {

  814.             //Chiudo statement and resultset
  815.             try {
  816.                 if(rs!=null) {
  817.                     rs.close();
  818.                 }
  819.             } catch (Exception e) {
  820.                 // ignore exception
  821.             }
  822.             try {
  823.                 if(stm!=null) {
  824.                     stm.close();
  825.                 }
  826.             } catch (Exception e) {
  827.                 // ignore exception
  828.             }
  829.            
  830.             releaseConnection(connectionDB);

  831.         }
  832.     }

  833.     public void createUser(User user) throws DriverUsersDBException {
  834.        
  835.         Connection connectionDB = null;
  836.         PreparedStatement stm = null;
  837.         ResultSet rs = null;
  838.         String sqlQuery = "";

  839.         if (user == null)
  840.             throw new DriverUsersDBException("[DriverUsersDB::createUser] Parametro non valido.");

  841.         String login = user.getLogin();
  842.         if (login == null || login.equals(""))
  843.             throw new DriverUsersDBException("[DriverUsersDB::createUser] Parametro Login non valido.");

  844.         try {
  845.             // Get Connection
  846.             connectionDB = getConnection();
  847.            
  848.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  849.             sqlQueryObject.addInsertTable(CostantiDB.USERS);
  850.             sqlQueryObject.addInsertField("login", "?");
  851.             sqlQueryObject.addInsertField("password", "?");
  852.             sqlQueryObject.addInsertField("data_password", "?");
  853.             sqlQueryObject.addInsertField("check_data_password", "?");
  854.             sqlQueryObject.addInsertField("tipo_interfaccia", "?");
  855.             sqlQueryObject.addInsertField("interfaccia_completa", "?");
  856.             sqlQueryObject.addInsertField("permessi", "?");
  857.             sqlQueryObject.addInsertField("protocolli", "?");
  858.             sqlQueryObject.addInsertField("protocollo_pddconsole", "?");
  859.             sqlQueryObject.addInsertField("protocollo_pddmonitor", "?");
  860.             sqlQueryObject.addInsertField("soggetto_pddconsole", "?");
  861.             sqlQueryObject.addInsertField("soggetto_pddmonitor", "?");
  862.             sqlQueryObject.addInsertField("soggetti_all", "?");
  863.             sqlQueryObject.addInsertField("servizi_all", "?");
  864.             sqlQuery = sqlQueryObject.createSQLInsert();
  865.             stm = connectionDB.prepareStatement(sqlQuery);
  866.             int index = 1;
  867.             stm.setString(index++, login);
  868.             stm.setString(index++, user.getPassword());
  869.             Timestamp dataPassword = DateManager.getTimestamp();
  870.             if(user.getLastUpdatePassword()!=null) {
  871.                 dataPassword = new Timestamp(user.getLastUpdatePassword().getTime());
  872.             }
  873.             stm.setTimestamp(index++, dataPassword);
  874.             stm.setInt(index++, user.isCheckLastUpdatePassword()? CostantiDB.TRUE : CostantiDB.FALSE);
  875.             stm.setString(index++, user.getInterfaceType().toString());
  876.             stm.setInt(index++, user.isPermitInterfaceComplete()? CostantiDB.TRUE : CostantiDB.FALSE);
  877.             stm.setString(index++, user.getPermessi().toString());
  878.             stm.setString(index++, user.getProtocolliSupportatiAsString());
  879.             stm.setString(index++, user.getProtocolloSelezionatoPddConsole());
  880.             stm.setString(index++, user.getProtocolloSelezionatoPddMonitor());
  881.             stm.setString(index++, user.getSoggettoSelezionatoPddConsole());
  882.             stm.setString(index++, user.getSoggettoSelezionatoPddMonitor());
  883.             stm.setInt(index++, user.isPermitAllSoggetti()? CostantiDB.TRUE : CostantiDB.FALSE);
  884.             stm.setInt(index++, user.isPermitAllServizi()? CostantiDB.TRUE : CostantiDB.FALSE);
  885.             stm.executeUpdate();
  886.             stm.close();
  887.                        
  888.             if(user.getStati().size()>0 || user.getPrecedentiPassword().size()>0 || user.getSoggetti().size()>0 || user.getServizi().size()>0) {
  889.            
  890.                 // recupero id
  891.                 long idUser = this._getIdUser(connectionDB, login);
  892.                
  893.                 _addListeUtente(connectionDB, user, idUser);
  894.                
  895.             }
  896.            
  897.         } catch (Exception qe) {
  898.             throw new DriverUsersDBException(qe.getMessage(),qe);
  899.         } finally {

  900.             //Chiudo statement and resultset
  901.             try {
  902.                 if (rs != null)
  903.                     rs.close();
  904.             } catch (Exception e) {
  905.                 //ignore
  906.             }
  907.             try {
  908.                 if (stm != null)
  909.                     stm.close();
  910.             } catch (Exception e) {
  911.                 //ignore
  912.             }
  913.            
  914.             try{
  915.                 if(this.connection==null) {
  916.                     connectionDB.close();
  917.                 }
  918.             }catch(Exception eClose){
  919.                 // close
  920.             }
  921.         }
  922.     }

  923.     public void updateUser(User user) throws DriverUsersDBException {
  924.        
  925.         Connection connectionDB = null;
  926.         PreparedStatement stm = null;
  927.         ResultSet rs = null;
  928.         String sqlQuery = "";

  929.         if (user == null)
  930.             throw new DriverUsersDBException("[DriverUsersDB::updateUser] Parametro non valido.");

  931.         String login = user.getLogin();
  932.         if (login == null || login.equals(""))
  933.             throw new DriverUsersDBException("[DriverUsersDB::updateUser] Parametro Login non valido.");

  934.         try {
  935.             // Get Connection
  936.             connectionDB = getConnection();
  937.            
  938.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  939.             sqlQueryObject.addUpdateTable(CostantiDB.USERS);
  940.             sqlQueryObject.addUpdateField("password", "?");
  941.             if(user.getLastUpdatePassword()!=null) {
  942.                 sqlQueryObject.addUpdateField("data_password", "?");
  943.             }
  944.             sqlQueryObject.addUpdateField("check_data_password", "?");
  945.             sqlQueryObject.addUpdateField("tipo_interfaccia", "?");
  946.             sqlQueryObject.addUpdateField("interfaccia_completa", "?");
  947.             sqlQueryObject.addUpdateField("permessi", "?");
  948.             sqlQueryObject.addUpdateField("protocolli", "?");
  949.             sqlQueryObject.addUpdateField("protocollo_pddconsole", "?");
  950.             sqlQueryObject.addUpdateField("protocollo_pddmonitor", "?");
  951.             sqlQueryObject.addUpdateField("soggetto_pddconsole", "?");
  952.             sqlQueryObject.addUpdateField("soggetto_pddmonitor", "?");
  953.             sqlQueryObject.addUpdateField("soggetti_all", "?");
  954.             sqlQueryObject.addUpdateField("servizi_all", "?");
  955.             sqlQueryObject.addWhereCondition("login=?");
  956.             sqlQuery = sqlQueryObject.createSQLUpdate();
  957.             stm = connectionDB.prepareStatement(sqlQuery);
  958.             int index = 1;
  959.             stm.setString(index++, user.getPassword());
  960.             if(user.getLastUpdatePassword()!=null) {
  961.                 stm.setTimestamp(index++, new Timestamp(user.getLastUpdatePassword().getTime()));
  962.             }
  963.             stm.setInt(index++, user.isCheckLastUpdatePassword()? CostantiDB.TRUE : CostantiDB.FALSE);
  964.             stm.setString(index++,user.getInterfaceType().toString());
  965.             stm.setInt(index++, user.isPermitInterfaceComplete()? CostantiDB.TRUE : CostantiDB.FALSE);
  966.             stm.setString(index++,user.getPermessi().toString());
  967.             stm.setString(index++, user.getProtocolliSupportatiAsString());
  968.             stm.setString(index++, user.getProtocolloSelezionatoPddConsole());
  969.             stm.setString(index++, user.getProtocolloSelezionatoPddMonitor());
  970.             stm.setString(index++, user.getSoggettoSelezionatoPddConsole());
  971.             stm.setString(index++, user.getSoggettoSelezionatoPddMonitor());
  972.             stm.setInt(index++, user.isPermitAllSoggetti()? CostantiDB.TRUE : CostantiDB.FALSE);
  973.             stm.setInt(index++, user.isPermitAllServizi()? CostantiDB.TRUE : CostantiDB.FALSE);
  974.             stm.setString(index++, user.getLogin());
  975.             stm.executeUpdate();
  976.             stm.close();
  977.            
  978.             long idUser = this._getIdUser(connectionDB, user);
  979.                
  980.             _deleteListeUtente(connectionDB, idUser);
  981.            
  982.             if(user.getStati().size()>0 || user.getPrecedentiPassword().size()>0 || user.getSoggetti().size()>0 || user.getServizi().size()>0) {
  983.                 _addListeUtente(connectionDB, user, idUser);
  984.             }
  985.            
  986.         } catch (Exception qe) {
  987.             throw new DriverUsersDBException(qe.getMessage(),qe);
  988.         } finally {

  989.             //Chiudo statement and resultset
  990.             try {
  991.                 if (rs != null)
  992.                     rs.close();
  993.             } catch (Exception e) {
  994.                 //ignore
  995.             }
  996.             try {
  997.                 if (stm != null)
  998.                     stm.close();
  999.             } catch (Exception e) {
  1000.                 //ignore
  1001.             }
  1002.            
  1003.             releaseConnection(connectionDB);

  1004.         }
  1005.     }
  1006.    
  1007.     public void deleteUser(User user) throws DriverUsersDBException {
  1008.        
  1009.         Connection connectionDB = null;
  1010.         PreparedStatement stm = null;
  1011.         String sqlQuery = "";

  1012.         if (user == null)
  1013.             throw new DriverUsersDBException("[DriverUsersDB::deleteUser] Parametro non valido.");

  1014.         String login = user.getLogin();
  1015.         if (login == null || login.equals(""))
  1016.             throw new DriverUsersDBException("[DriverUsersDB::deleteUser] Parametro Login non valido.");

  1017.         try {
  1018.             // Get Connection
  1019.             connectionDB = getConnection();
  1020.            
  1021.             long idUser = this._getIdUser(connectionDB, user);
  1022.            
  1023.             _deleteListeUtente(connectionDB, idUser);
  1024.            
  1025.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1026.             sqlQueryObject.addDeleteTable(CostantiDB.USERS);
  1027.             sqlQueryObject.addWhereCondition("login = ?");
  1028.             sqlQuery = sqlQueryObject.createSQLDelete();
  1029.             stm = connectionDB.prepareStatement(sqlQuery);
  1030.             stm.setString(1, login);
  1031.             stm.executeUpdate();
  1032.             stm.close();
  1033.         } catch (Exception qe) {
  1034.             throw new DriverUsersDBException(qe.getMessage(),qe);
  1035.         } finally {

  1036.             //Chiudo statement and resultset
  1037.             try {
  1038.                 if (stm != null)
  1039.                     stm.close();
  1040.             } catch (Exception e) {
  1041.                 //ignore
  1042.             }
  1043.            
  1044.             releaseConnection(connectionDB);

  1045.         }
  1046.     }

  1047.    
  1048.    
  1049.     private void _addListeUtente(Connection connectionDB, User user, long idUser) throws Exception {
  1050.        
  1051.         PreparedStatement stm = null;
  1052.         ResultSet rs = null;
  1053.         try {
  1054.             if(user.getStati().size()>0) {
  1055.                 for (Stato stato : user.getStati()) {
  1056.                    
  1057.                     ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1058.                     sqlQueryObject.addInsertTable(CostantiDB.USERS_STATI);
  1059.                     sqlQueryObject.addInsertField("id_utente", "?");
  1060.                     sqlQueryObject.addInsertField("oggetto", "?");
  1061.                     sqlQueryObject.addInsertField("stato", "?");
  1062.                     String sqlQuery = sqlQueryObject.createSQLInsert();
  1063.                     stm = connectionDB.prepareStatement(sqlQuery);
  1064.                     int index = 1;
  1065.                     stm.setLong(index++, idUser);
  1066.                     stm.setString(index++, stato.getOggetto());
  1067.                     stm.setString(index++, stato.getStato());
  1068.                     stm.executeUpdate();
  1069.                     stm.close();
  1070.                 }
  1071.             }
  1072.            
  1073.             if(user.getPrecedentiPassword().size()>0) {
  1074.                 for (UserPassword userPassword : user.getPrecedentiPassword()) {
  1075.                    
  1076.                     ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1077.                     sqlQueryObject.addInsertTable(CostantiDB.USERS_PASSWORD);
  1078.                     sqlQueryObject.addInsertField("id_utente", "?");
  1079.                     sqlQueryObject.addInsertField("password", "?");
  1080.                     sqlQueryObject.addInsertField("data_password", "?");
  1081.                     String sqlQuery = sqlQueryObject.createSQLInsert();
  1082.                     stm = connectionDB.prepareStatement(sqlQuery);
  1083.                     int index = 1;
  1084.                     stm.setLong(index++, idUser);
  1085.                     stm.setString(index++, userPassword.getPassword());
  1086.                     stm.setTimestamp(index++, new Timestamp(userPassword.getDatePassword().getTime()));
  1087.                     stm.executeUpdate();
  1088.                     stm.close();
  1089.                 }
  1090.             }
  1091.            
  1092.             if(user.getSoggetti().size()>0) {
  1093.                 for (IDSoggetto idSoggetto : user.getSoggetti()) {
  1094.                    
  1095.                     long idSoggettoLong = DBUtils.getIdSoggetto(idSoggetto.getNome(), idSoggetto.getTipo(), connectionDB, this.tipoDatabase);
  1096.                     if(idSoggettoLong<=0) {
  1097.                         throw new Exception("Impossibile recuperare id soggetto ["+idSoggetto+"]");
  1098.                     }
  1099.                     ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1100.                     sqlQueryObject.addInsertTable(CostantiDB.USERS_SOGGETTI);
  1101.                     sqlQueryObject.addInsertField("id_utente", "?");
  1102.                     sqlQueryObject.addInsertField("id_soggetto", "?");
  1103.                     String sqlQuery = sqlQueryObject.createSQLInsert();
  1104.                     stm = connectionDB.prepareStatement(sqlQuery);
  1105.                     int index = 1;
  1106.                     stm.setLong(index++, idUser);
  1107.                     stm.setLong(index++, idSoggettoLong);
  1108.                     stm.executeUpdate();
  1109.                     stm.close();
  1110.                 }
  1111.             }
  1112.            
  1113.             if(user.getServizi().size()>0) {
  1114.                 for (IDServizio idServizio : user.getServizi()) {
  1115.                    
  1116.                     long idServizioLong = DBUtils.getIdServizio(idServizio.getNome(), idServizio.getTipo(), idServizio.getVersione(),
  1117.                             idServizio.getSoggettoErogatore().getNome(), idServizio.getSoggettoErogatore().getTipo(),
  1118.                             connectionDB, this.tipoDatabase);
  1119.                     if(idServizioLong<=0) {
  1120.                         throw new Exception("Impossibile recuperare id soggetto ["+idServizio+"]");
  1121.                     }
  1122.                     ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1123.                     sqlQueryObject.addInsertTable(CostantiDB.USERS_SERVIZI);
  1124.                     sqlQueryObject.addInsertField("id_utente", "?");
  1125.                     sqlQueryObject.addInsertField("id_servizio", "?");
  1126.                     String sqlQuery = sqlQueryObject.createSQLInsert();
  1127.                     stm = connectionDB.prepareStatement(sqlQuery);
  1128.                     int index = 1;
  1129.                     stm.setLong(index++, idUser);
  1130.                     stm.setLong(index++, idServizioLong);
  1131.                     stm.executeUpdate();
  1132.                     stm.close();
  1133.                 }
  1134.             }
  1135.         } finally {

  1136.             //Chiudo statement and resultset
  1137.             try {
  1138.                 if (rs != null)
  1139.                     rs.close();
  1140.             } catch (Exception e) {
  1141.                 //ignore
  1142.             }
  1143.             try {
  1144.                 if (stm != null)
  1145.                     stm.close();
  1146.             } catch (Exception e) {
  1147.                 //ignore
  1148.             }
  1149.            
  1150.         }
  1151.     }
  1152.    
  1153.     private void _deleteListeUtente(Connection connectionDB, long idUser) throws Exception {
  1154.        
  1155.         PreparedStatement stm = null;
  1156.         try {
  1157.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1158.             sqlQueryObject.addDeleteTable(CostantiDB.USERS_STATI);
  1159.             sqlQueryObject.addWhereCondition("id_utente = ?");
  1160.             String sqlQuery = sqlQueryObject.createSQLDelete();
  1161.             stm = connectionDB.prepareStatement(sqlQuery);
  1162.             stm.setLong(1, idUser);
  1163.             stm.executeUpdate();
  1164.             stm.close();
  1165.            
  1166.             sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1167.             sqlQueryObject.addDeleteTable(CostantiDB.USERS_PASSWORD);
  1168.             sqlQueryObject.addWhereCondition("id_utente = ?");
  1169.             sqlQuery = sqlQueryObject.createSQLDelete();
  1170.             stm = connectionDB.prepareStatement(sqlQuery);
  1171.             stm.setLong(1, idUser);
  1172.             stm.executeUpdate();
  1173.             stm.close();
  1174.            
  1175.             sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1176.             sqlQueryObject.addDeleteTable(CostantiDB.USERS_SOGGETTI);
  1177.             sqlQueryObject.addWhereCondition("id_utente = ?");
  1178.             sqlQuery = sqlQueryObject.createSQLDelete();
  1179.             stm = connectionDB.prepareStatement(sqlQuery);
  1180.             stm.setLong(1, idUser);
  1181.             stm.executeUpdate();
  1182.             stm.close();
  1183.            
  1184.             sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1185.             sqlQueryObject.addDeleteTable(CostantiDB.USERS_SERVIZI);
  1186.             sqlQueryObject.addWhereCondition("id_utente = ?");
  1187.             sqlQuery = sqlQueryObject.createSQLDelete();
  1188.             stm = connectionDB.prepareStatement(sqlQuery);
  1189.             stm.setLong(1, idUser);
  1190.             stm.executeUpdate();
  1191.             stm.close();
  1192.         } finally {

  1193.             //Chiudo statement and resultset
  1194.             try {
  1195.                 if (stm != null)
  1196.                     stm.close();
  1197.             } catch (Exception e) {
  1198.                 //ignore
  1199.             }
  1200.         }
  1201.     }
  1202.    
  1203.     private long _getIdUser(Connection connectionDB, User user) throws Exception {
  1204.        
  1205.         if (user == null)
  1206.             throw new DriverUsersDBException("[DriverUsersDB::_getIdUser] Parametro non valido.");

  1207.         String login = user.getLogin();
  1208.         if (login == null || login.equals(""))
  1209.             throw new DriverUsersDBException("[DriverUsersDB::_getIdUser] Parametro Login non valido.");

  1210.         long idUser = -1;
  1211.         if(user.getId()==null || user.getId().longValue()<=0) {
  1212.             idUser = this._getIdUser(connectionDB, login);
  1213.         }
  1214.         else {
  1215.             idUser = user.getId().longValue();
  1216.         }
  1217.        
  1218.         return idUser;
  1219.            
  1220.     }
  1221.     private long _getIdUser(Connection connectionDB, String login) throws Exception {
  1222.        
  1223.         PreparedStatement stm = null;
  1224.         ResultSet rs = null;
  1225.         String sqlQuery = "";

  1226.         if (login == null || login.equals(""))
  1227.             throw new DriverUsersDBException("[DriverUsersDB::_getIdUser] Parametro Login non valido.");

  1228.         try {
  1229.            
  1230.             long idUser = -1;
  1231.             // recupero id
  1232.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1233.             sqlQueryObject.addFromTable(CostantiDB.USERS);
  1234.             sqlQueryObject.addWhereCondition("login = ?");
  1235.             sqlQuery = sqlQueryObject.createSQLQuery();
  1236.             stm = connectionDB.prepareStatement(sqlQuery);
  1237.             stm.setString(1, login);
  1238.             rs = stm.executeQuery();
  1239.             if(rs.next()) {
  1240.                 idUser = rs.getLong("id");
  1241.             }
  1242.             if(idUser<=0) {
  1243.                 throw new Exception("Impossibile recuperare id utente con login ["+login+"]");
  1244.             }
  1245.             rs.close();
  1246.             stm.close();
  1247.            
  1248.             return idUser;
  1249.            
  1250.         } finally {

  1251.             //Chiudo statement and resultset
  1252.             try {
  1253.                 if (rs != null)
  1254.                     rs.close();
  1255.             } catch (Exception e) {
  1256.                 //ignore
  1257.             }
  1258.             try {
  1259.                 if (stm != null)
  1260.                     stm.close();
  1261.             } catch (Exception e) {
  1262.                 //ignore
  1263.             }
  1264.         }
  1265.     }
  1266.    
  1267.     public List<IDServizio> utentiServiziList(String login, ISearch ricerca) throws DriverUsersDBException {
  1268.         String nomeMetodo = "utentiServiziList";
  1269.         int idLista = Liste.UTENTI_SERVIZI;
  1270.         int offset;
  1271.         int limit;
  1272.         String search;
  1273.         String queryString;

  1274.         limit = ricerca.getPageSize(idLista);
  1275.         offset = ricerca.getIndexIniziale(idLista);
  1276.         search = (org.openspcoop2.core.constants.Costanti.SESSION_ATTRIBUTE_VALUE_RICERCA_UNDEFINED.equals(ricerca.getSearchString(idLista)) ? "" : ricerca.getSearchString(idLista));

  1277.         String filterProtocollo = SearchUtils.getFilter(ricerca, idLista, Filtri.FILTRO_PROTOCOLLO);
  1278.         String filterProtocolli = SearchUtils.getFilter(ricerca, idLista, Filtri.FILTRO_PROTOCOLLI);
  1279.         List<String> tipoServiziProtocollo = null;
  1280.         try {
  1281.             tipoServiziProtocollo = Filtri.convertToTipiServizi(filterProtocollo, filterProtocolli);
  1282.         }catch(Exception e) {
  1283.             throw new DriverUsersDBException(e.getMessage(),e);
  1284.         }

  1285.         String filterDominio = SearchUtils.getFilter(ricerca, idLista,  Filtri.FILTRO_DOMINIO);
  1286.         PddTipologia pddTipologia = null;
  1287.         if(filterDominio!=null && !"".equals(filterDominio)) {
  1288.             pddTipologia = PddTipologia.toPddTipologia(filterDominio);
  1289.         }
  1290.        
  1291.         this.log.debug("search : " + search);
  1292.         this.log.debug("filterProtocollo : " + filterProtocollo);
  1293.         this.log.debug("filterProtocolli : " + filterProtocolli);
  1294.         this.log.debug("filterDominio : " + filterDominio);
  1295.        
  1296.         Connection connectionDB = null;
  1297.         PreparedStatement stmt = null;
  1298.         ResultSet risultato = null;
  1299.         ArrayList<IDServizio> lista = new ArrayList<IDServizio>();

  1300.         try {
  1301.             // Get Connection
  1302.             connectionDB = getConnection();
  1303.            
  1304.             ISQLQueryObject sqlQueryObjectSoggetti = null;
  1305.             if (!search.equals("")) {
  1306.                 sqlQueryObjectSoggetti = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1307.                 sqlQueryObjectSoggetti.addFromTable(CostantiDB.SOGGETTI);
  1308.                 sqlQueryObjectSoggetti.addSelectField(CostantiDB.SOGGETTI, "tipo_soggetto");
  1309.                 sqlQueryObjectSoggetti.addSelectField(CostantiDB.SOGGETTI, "nome_soggetto");
  1310.                 sqlQueryObjectSoggetti.setANDLogicOperator(true);
  1311.                 sqlQueryObjectSoggetti.addWhereCondition(CostantiDB.SERVIZI+".id_soggetto="+CostantiDB.SOGGETTI+".id");
  1312.                 sqlQueryObjectSoggetti.addWhereCondition(false,
  1313.                         //sqlQueryObjectSoggetti.getWhereLikeCondition("tipo_soggetto", search, true, true),
  1314.                         sqlQueryObjectSoggetti.getWhereLikeCondition("nome_soggetto", search, true, true));
  1315.             }

  1316.             ISQLQueryObject sqlQueryObjectPdd = null;
  1317.             if(pddTipologia!=null && PddTipologia.ESTERNO.equals(pddTipologia)) {
  1318.                 ISQLQueryObject sqlQueryObjectExistsPdd = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1319.                 sqlQueryObjectExistsPdd.addSelectField(CostantiDB.PDD+".nome");
  1320.                 sqlQueryObjectExistsPdd.addFromTable(CostantiDB.PDD);
  1321.                 sqlQueryObjectExistsPdd.setANDLogicOperator(true);
  1322.                 sqlQueryObjectExistsPdd.addWhereCondition(CostantiDB.PDD+".nome="+CostantiDB.SOGGETTI+".server");
  1323.                 sqlQueryObjectExistsPdd.addWhereCondition(CostantiDB.PDD+".tipo=?");
  1324.                
  1325.                 sqlQueryObjectPdd = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1326.                 sqlQueryObjectPdd.setANDLogicOperator(false);
  1327.                 sqlQueryObjectPdd.addWhereIsNullCondition(CostantiDB.SOGGETTI+".server");
  1328.                 sqlQueryObjectPdd.addWhereExistsCondition(false, sqlQueryObjectExistsPdd);
  1329.             }
  1330.            
  1331.            
  1332.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1333.             sqlQueryObject.addSelectCountField("*", "cont");
  1334.             sqlQueryObject.addFromTable(CostantiDB.USERS);
  1335.             sqlQueryObject.addFromTable(CostantiDB.USERS_SERVIZI);
  1336.             sqlQueryObject.addFromTable(CostantiDB.SERVIZI);
  1337.             sqlQueryObject.addFromTable(CostantiDB.SOGGETTI);
  1338.             sqlQueryObject.addWhereCondition(CostantiDB.USERS+".login = ?");
  1339.             sqlQueryObject.addWhereCondition(CostantiDB.USERS_SERVIZI+".id_utente = "+CostantiDB.USERS+".id");
  1340.             sqlQueryObject.addWhereCondition(CostantiDB.USERS_SERVIZI+".id_servizio = "+CostantiDB.SERVIZI+".id");
  1341.             sqlQueryObject.addWhereCondition(CostantiDB.SERVIZI+".id_soggetto = "+CostantiDB.SOGGETTI+".id");
  1342.            
  1343.             if (!search.equals("")) {
  1344.                 //query con search
  1345.                 sqlQueryObject.addWhereCondition(false,
  1346.                         // - ricerca su tipo/nome servizio
  1347.                         //sqlQueryObject.getWhereLikeCondition("tipo_servizio", search, true, true),
  1348.                         sqlQueryObject.getWhereLikeCondition(CostantiDB.SERVIZI+".nome_servizio", search, true, true),
  1349.                         //sqlQueryObject.getWhereLikeCondition("versione_servizio", search, true, true),
  1350.                         sqlQueryObject.getWhereExistsCondition(false, sqlQueryObjectSoggetti));
  1351.             }
  1352.            
  1353.             if(tipoServiziProtocollo!=null && tipoServiziProtocollo.size()>0) {
  1354.                 sqlQueryObject.addWhereINCondition(CostantiDB.SERVIZI+".tipo_servizio", true, tipoServiziProtocollo.toArray(new String[1]));
  1355.             }
  1356.             if(pddTipologia!=null) {
  1357.                 if(PddTipologia.ESTERNO.equals(pddTipologia)) {
  1358.                     sqlQueryObject.addWhereCondition(sqlQueryObjectPdd.createSQLConditions());                          
  1359.                 }
  1360.                 else {
  1361.                     sqlQueryObject.addFromTable(CostantiDB.PDD);
  1362.                     sqlQueryObject.addWhereCondition(true,CostantiDB.PDD+".nome="+CostantiDB.SOGGETTI+".server",CostantiDB.PDD+".tipo=?");
  1363.                 }
  1364.             }
  1365.            
  1366.             sqlQueryObject.setANDLogicOperator(true);
  1367.             queryString = sqlQueryObject.createSQLQuery();
  1368.             stmt = connectionDB.prepareStatement(queryString);
  1369.             int index = 1;
  1370.             stmt.setString(index++, login);
  1371.             if(pddTipologia!=null) {
  1372.                 stmt.setString(index++, pddTipologia.toString());
  1373.             }
  1374.             risultato = stmt.executeQuery();
  1375.             if (risultato.next())
  1376.                 ricerca.setNumEntries(idLista, risultato.getInt(1));
  1377.             risultato.close();
  1378.             stmt.close();

  1379.             // ricavo le entries
  1380.             if (limit == 0) // con limit
  1381.                 limit = ISQLQueryObject.LIMIT_DEFAULT_VALUE;
  1382.            
  1383.             sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1384.             sqlQueryObject.addSelectField(CostantiDB.USERS_SERVIZI+".id_servizio");
  1385.             sqlQueryObject.addSelectField(CostantiDB.SERVIZI+".tipo_servizio");
  1386.             sqlQueryObject.addSelectField(CostantiDB.SERVIZI+".nome_servizio");
  1387.             sqlQueryObject.addSelectField(CostantiDB.SERVIZI+".versione_servizio");
  1388.             sqlQueryObject.addSelectField(CostantiDB.SOGGETTI+".tipo_soggetto");
  1389.             sqlQueryObject.addSelectField(CostantiDB.SOGGETTI+".nome_soggetto");
  1390.             sqlQueryObject.addFromTable(CostantiDB.USERS);
  1391.             sqlQueryObject.addFromTable(CostantiDB.USERS_SERVIZI);
  1392.             sqlQueryObject.addFromTable(CostantiDB.SERVIZI);
  1393.             sqlQueryObject.addFromTable(CostantiDB.SOGGETTI);
  1394.             sqlQueryObject.addWhereCondition(CostantiDB.USERS+".login = ?");
  1395.             sqlQueryObject.addWhereCondition(CostantiDB.USERS_SERVIZI+".id_utente = "+CostantiDB.USERS+".id");
  1396.             sqlQueryObject.addWhereCondition(CostantiDB.USERS_SERVIZI+".id_servizio = "+CostantiDB.SERVIZI+".id");
  1397.             sqlQueryObject.addWhereCondition(CostantiDB.SERVIZI+".id_soggetto = "+CostantiDB.SOGGETTI+".id");
  1398.            
  1399.             if (!search.equals("")) {
  1400.                 //query con search
  1401.                 sqlQueryObject.addWhereCondition(false,
  1402.                         // - ricerca su tipo/nome servizio
  1403.                         //sqlQueryObject.getWhereLikeCondition("tipo_servizio", search, true, true),
  1404.                         sqlQueryObject.getWhereLikeCondition(CostantiDB.SERVIZI+".nome_servizio", search, true, true),
  1405.                         //sqlQueryObject.getWhereLikeCondition("versione_servizio", search, true, true),
  1406.                         sqlQueryObject.getWhereExistsCondition(false, sqlQueryObjectSoggetti));
  1407.             }
  1408.            
  1409.             if(tipoServiziProtocollo!=null && tipoServiziProtocollo.size()>0) {
  1410.                 sqlQueryObject.addWhereINCondition(CostantiDB.SERVIZI+".tipo_servizio", true, tipoServiziProtocollo.toArray(new String[1]));
  1411.             }
  1412.             if(pddTipologia!=null) {
  1413.                 if(PddTipologia.ESTERNO.equals(pddTipologia)) {
  1414.                     sqlQueryObject.addWhereCondition(sqlQueryObjectPdd.createSQLConditions());                          
  1415.                 }
  1416.                 else {
  1417.                     sqlQueryObject.addFromTable(CostantiDB.PDD);
  1418.                     sqlQueryObject.addWhereCondition(true,CostantiDB.PDD+".nome="+CostantiDB.SOGGETTI+".server",CostantiDB.PDD+".tipo=?");
  1419.                 }
  1420.             }
  1421.            
  1422.             sqlQueryObject.addOrderBy(CostantiDB.SERVIZI+".nome_servizio");
  1423.             sqlQueryObject.addOrderBy(CostantiDB.SERVIZI+".versione_servizio");
  1424.             sqlQueryObject.addOrderBy(CostantiDB.SOGGETTI+".nome_soggetto");
  1425.             sqlQueryObject.addOrderBy(CostantiDB.SERVIZI+".tipo_servizio");
  1426.             sqlQueryObject.addOrderBy(CostantiDB.SOGGETTI+".tipo_soggetto");
  1427.             sqlQueryObject.setSortType(true);
  1428.             sqlQueryObject.setLimit(limit);
  1429.             sqlQueryObject.setOffset(offset);
  1430.             sqlQueryObject.setANDLogicOperator(true);
  1431.             queryString = sqlQueryObject.createSQLQuery();
  1432.             stmt = connectionDB.prepareStatement(queryString);
  1433.             index = 1;
  1434.             stmt.setString(index++, login);
  1435.             if(pddTipologia!=null) {
  1436.                 stmt.setString(index++, pddTipologia.toString());
  1437.             }
  1438.             risultato = stmt.executeQuery();
  1439.            
  1440.             JDBCServiceManagerProperties jdbcProperties = new JDBCServiceManagerProperties();
  1441.             jdbcProperties.setDatabaseType(this.tipoDatabase);
  1442.             jdbcProperties.setShowSql(true);
  1443.             JDBCServiceManager manager = new JDBCServiceManager(connectionDB, jdbcProperties, this.log);
  1444. //          IDBSoggettoServiceSearch soggettiSearch = (IDBSoggettoServiceSearch) manager.getSoggettoServiceSearch();
  1445.             IDBAccordoServizioParteSpecificaServiceSearch serviziSearch = (IDBAccordoServizioParteSpecificaServiceSearch) manager.getAccordoServizioParteSpecificaServiceSearch();
  1446.            
  1447.             while (risultato.next()) {
  1448.                 long id = risultato.getLong("id_servizio");
  1449.                 AccordoServizioParteSpecifica servizio = serviziSearch.get(id);
  1450.                 IDServizio idServizio = IDServizioFactory.getInstance().getIDServizioFromValues(servizio.getTipo(),
  1451.                         servizio.getNome(),
  1452.                         servizio.getIdErogatore().getTipo(),
  1453.                         servizio.getIdErogatore().getNome(),
  1454.                         servizio.getVersione());
  1455.                 lista.add(idServizio);
  1456.             }
  1457.             risultato.close();
  1458.             return lista;

  1459.         } catch (Exception qe) {
  1460.             throw new DriverUsersDBException("[DriverUsersDB::" + nomeMetodo + "] Errore : " + qe.getMessage(),qe);
  1461.         } finally {

  1462.             //Chiudo statement and resultset
  1463.             try {
  1464.                 if(risultato!=null) {
  1465.                     risultato.close();
  1466.                 }
  1467.             } catch (Exception e) {
  1468.                 // ignore exception
  1469.             }
  1470.             try {
  1471.                 if(stmt!=null) {
  1472.                     stmt.close();
  1473.                 }
  1474.             } catch (Exception e) {
  1475.                 // ignore exception
  1476.             }
  1477.            
  1478.             releaseConnection(connectionDB);

  1479.         }
  1480.     }
  1481.    
  1482.    
  1483.     public List<IDSoggetto> utentiSoggettiList(String login, ISearch ricerca) throws DriverUsersDBException {
  1484.         String nomeMetodo = "utentiSoggettiList";
  1485.         int idLista = Liste.UTENTI_SOGGETTI;
  1486.         int offset;
  1487.         int limit;
  1488.         String search;
  1489.         String queryString;

  1490.         limit = ricerca.getPageSize(idLista);
  1491.         offset = ricerca.getIndexIniziale(idLista);
  1492.         search = (org.openspcoop2.core.constants.Costanti.SESSION_ATTRIBUTE_VALUE_RICERCA_UNDEFINED.equals(ricerca.getSearchString(idLista)) ? "" : ricerca.getSearchString(idLista));

  1493.         String filterProtocollo = SearchUtils.getFilter(ricerca, idLista, Filtri.FILTRO_PROTOCOLLO);
  1494.         String filterProtocolli = SearchUtils.getFilter(ricerca, idLista, Filtri.FILTRO_PROTOCOLLI);
  1495.         List<String> tipoSoggettiProtocollo = null;
  1496.         try {
  1497.             tipoSoggettiProtocollo = Filtri.convertToTipiSoggetti(filterProtocollo, filterProtocolli);
  1498.         }catch(Exception e) {
  1499.             throw new DriverUsersDBException(e.getMessage(),e);
  1500.         }
  1501.        
  1502.         String filterDominio = SearchUtils.getFilter(ricerca, idLista,  Filtri.FILTRO_DOMINIO);
  1503.         PddTipologia pddTipologia = null;
  1504.         if(filterDominio!=null && !"".equals(filterDominio)) {
  1505.             pddTipologia = PddTipologia.toPddTipologia(filterDominio);
  1506.         }
  1507.        
  1508.         this.log.debug("search : " + search);
  1509.         this.log.debug("filterProtocollo : " + filterProtocollo);
  1510.         this.log.debug("filterProtocolli : " + filterProtocolli);
  1511.         this.log.debug("filterDominio : " + filterDominio);
  1512.        
  1513.         Connection connectionDB = null;
  1514.         PreparedStatement stmt = null;
  1515.         ResultSet risultato = null;
  1516.         ArrayList<IDSoggetto> lista = new ArrayList<IDSoggetto>();

  1517.         try {
  1518.            
  1519.             // Get Connection
  1520.             connectionDB = getConnection();
  1521.            
  1522.             ISQLQueryObject sqlQueryObjectPdd = null;
  1523.             if(pddTipologia!=null && PddTipologia.ESTERNO.equals(pddTipologia)) {
  1524.                 ISQLQueryObject sqlQueryObjectExistsPdd = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1525.                 sqlQueryObjectExistsPdd.addSelectField(CostantiDB.PDD+".nome");
  1526.                 sqlQueryObjectExistsPdd.addFromTable(CostantiDB.PDD);
  1527.                 sqlQueryObjectExistsPdd.setANDLogicOperator(true);
  1528.                 sqlQueryObjectExistsPdd.addWhereCondition(CostantiDB.PDD+".nome="+CostantiDB.SOGGETTI+".server");
  1529.                 sqlQueryObjectExistsPdd.addWhereCondition(CostantiDB.PDD+".tipo=?");
  1530.                
  1531.                 sqlQueryObjectPdd = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1532.                 sqlQueryObjectPdd.setANDLogicOperator(false);
  1533.                 sqlQueryObjectPdd.addWhereIsNullCondition(CostantiDB.SOGGETTI+".server");
  1534.                 sqlQueryObjectPdd.addWhereExistsCondition(false, sqlQueryObjectExistsPdd);
  1535.             }
  1536.            
  1537.            
  1538.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1539.             sqlQueryObject.addSelectCountField("*", "cont");
  1540.             sqlQueryObject.addFromTable(CostantiDB.USERS);
  1541.             sqlQueryObject.addFromTable(CostantiDB.USERS_SOGGETTI);
  1542.             sqlQueryObject.addFromTable(CostantiDB.SOGGETTI);
  1543.             sqlQueryObject.addWhereCondition(CostantiDB.USERS+".login = ?");
  1544.             sqlQueryObject.addWhereCondition(CostantiDB.USERS_SOGGETTI+".id_utente = "+CostantiDB.USERS+".id");
  1545.             sqlQueryObject.addWhereCondition(CostantiDB.USERS_SOGGETTI+".id_soggetto = "+CostantiDB.SOGGETTI+".id");
  1546.            
  1547.             if (!search.equals("")) {
  1548.                 //query con search
  1549.                 sqlQueryObject.addWhereLikeCondition(CostantiDB.SOGGETTI+".nome_soggetto", search, true, true);
  1550.             }
  1551.            
  1552.             if(tipoSoggettiProtocollo!=null && tipoSoggettiProtocollo.size()>0) {
  1553.                 sqlQueryObject.addWhereINCondition(CostantiDB.SOGGETTI+".tipo_soggetto", true, tipoSoggettiProtocollo.toArray(new String[1]));
  1554.             }
  1555.             if(pddTipologia!=null) {
  1556.                 if(PddTipologia.ESTERNO.equals(pddTipologia)) {
  1557.                     sqlQueryObject.addWhereCondition(sqlQueryObjectPdd.createSQLConditions());                          
  1558.                 }
  1559.                 else {
  1560.                     sqlQueryObject.addFromTable(CostantiDB.PDD);
  1561.                     sqlQueryObject.addWhereCondition(true,CostantiDB.PDD+".nome="+CostantiDB.SOGGETTI+".server",CostantiDB.PDD+".tipo=?");
  1562.                 }
  1563.             }
  1564.            
  1565.             sqlQueryObject.setANDLogicOperator(true);
  1566.             queryString = sqlQueryObject.createSQLQuery();
  1567.             stmt = connectionDB.prepareStatement(queryString);
  1568.             int index = 1;
  1569.             stmt.setString(index++, login);
  1570.             if(pddTipologia!=null) {
  1571.                 stmt.setString(index++, pddTipologia.toString());
  1572.             }
  1573.             risultato = stmt.executeQuery();
  1574.             if (risultato.next())
  1575.                 ricerca.setNumEntries(idLista, risultato.getInt(1));
  1576.             risultato.close();
  1577.             stmt.close();

  1578.             // ricavo le entries
  1579.             if (limit == 0) // con limit
  1580.                 limit = ISQLQueryObject.LIMIT_DEFAULT_VALUE;
  1581.            
  1582.             sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1583.             sqlQueryObject.addSelectField(CostantiDB.USERS_SOGGETTI+".id_soggetto");
  1584.             sqlQueryObject.addSelectField(CostantiDB.SOGGETTI+".nome_soggetto");
  1585.             sqlQueryObject.addSelectField(CostantiDB.SOGGETTI+".tipo_soggetto");
  1586.             sqlQueryObject.addFromTable(CostantiDB.USERS);
  1587.             sqlQueryObject.addFromTable(CostantiDB.USERS_SOGGETTI);
  1588.             sqlQueryObject.addFromTable(CostantiDB.SOGGETTI);
  1589.             sqlQueryObject.addWhereCondition(CostantiDB.USERS+".login = ?");
  1590.             sqlQueryObject.addWhereCondition(CostantiDB.USERS_SOGGETTI+".id_utente = "+CostantiDB.USERS+".id");
  1591.             sqlQueryObject.addWhereCondition(CostantiDB.USERS_SOGGETTI+".id_soggetto = "+CostantiDB.SOGGETTI+".id");
  1592.            
  1593.             if (!search.equals("")) { // con search
  1594.                 sqlQueryObject.addWhereLikeCondition(CostantiDB.SOGGETTI+".nome_soggetto", search, true, true);
  1595.             }  
  1596.            
  1597.             if(tipoSoggettiProtocollo!=null && tipoSoggettiProtocollo.size()>0) {
  1598.                 sqlQueryObject.addWhereINCondition(CostantiDB.SOGGETTI+".tipo_soggetto", true, tipoSoggettiProtocollo.toArray(new String[1]));
  1599.             }
  1600.             if(pddTipologia!=null) {
  1601.                 if(PddTipologia.ESTERNO.equals(pddTipologia)) {
  1602.                     sqlQueryObject.addWhereCondition(sqlQueryObjectPdd.createSQLConditions());                                  
  1603.                 }
  1604.                 else {
  1605.                     sqlQueryObject.addFromTable(CostantiDB.PDD);
  1606.                     sqlQueryObject.addWhereCondition(true,CostantiDB.PDD+".nome="+CostantiDB.SOGGETTI+".server",CostantiDB.PDD+".tipo=?");
  1607.                 }
  1608.             }
  1609.            
  1610.             sqlQueryObject.addOrderBy(CostantiDB.SOGGETTI+".nome_soggetto");
  1611.             sqlQueryObject.addOrderBy(CostantiDB.SOGGETTI+".tipo_soggetto");
  1612.             sqlQueryObject.setSortType(true);
  1613.             sqlQueryObject.setLimit(limit);
  1614.             sqlQueryObject.setOffset(offset);
  1615.             sqlQueryObject.setANDLogicOperator(true);
  1616.             queryString = sqlQueryObject.createSQLQuery();
  1617.             stmt = connectionDB.prepareStatement(queryString);
  1618.             index = 1;
  1619.             stmt.setString(index++, login);
  1620.             if(pddTipologia!=null) {
  1621.                 stmt.setString(index++, pddTipologia.toString());
  1622.             }
  1623.             risultato = stmt.executeQuery();
  1624.            
  1625.             JDBCServiceManagerProperties jdbcProperties = new JDBCServiceManagerProperties();
  1626.             jdbcProperties.setDatabaseType(this.tipoDatabase);
  1627.             jdbcProperties.setShowSql(true);
  1628.             JDBCServiceManager manager = new JDBCServiceManager(connectionDB, jdbcProperties, this.log);
  1629.             IDBSoggettoServiceSearch soggettiSearch = (IDBSoggettoServiceSearch) manager.getSoggettoServiceSearch();
  1630.            
  1631.             while (risultato.next()) {
  1632.                 long id = risultato.getLong("id_soggetto");
  1633.                 Soggetto soggetto = soggettiSearch.get(id);
  1634.                 IDSoggetto idSoggetto = new IDSoggetto(soggetto.getTipoSoggetto(), soggetto.getNomeSoggetto(), soggetto.getIdentificativoPorta());
  1635.                 lista.add(idSoggetto);
  1636.             }
  1637.             risultato.close();
  1638.             return lista;

  1639.         } catch (Exception qe) {
  1640.             throw new DriverUsersDBException("[DriverUsersDB::" + nomeMetodo + "] Errore : " + qe.getMessage(),qe);
  1641.         } finally {

  1642.             //Chiudo statement and resultset
  1643.             try {
  1644.                 if(risultato!=null) {
  1645.                     risultato.close();
  1646.                 }
  1647.             } catch (Exception e) {
  1648.                 // ignore exception
  1649.             }
  1650.             try {
  1651.                 if(stmt!=null) {
  1652.                     stmt.close();
  1653.                 }
  1654.             } catch (Exception e) {
  1655.                 // ignore exception
  1656.             }
  1657.            
  1658.             releaseConnection(connectionDB);

  1659.         }
  1660.     }
  1661.    
  1662.     /**
  1663.      * Restituisce lo stato identificato da <var>login</var> e da <var>nomeOggetto</var>
  1664.      *
  1665.      * @param login Identificatore di un utente
  1666.      * @param nomeOggetto Oggetto da ricercare
  1667.      *              
  1668.      * @return Lo stato individuato
  1669.      */
  1670.     public Stato getStato(String login, String nomeOggetto) throws DriverUsersDBException {
  1671.         if (login == null || nomeOggetto == null)
  1672.             throw new DriverUsersDBException("[getStato] Parametri Non Validi");

  1673.         Connection connectionDB = null;
  1674.         PreparedStatement stm = null;
  1675.         ResultSet rs = null;
  1676.         Stato statoObject = null;
  1677.         try {
  1678.             // Get Connection
  1679.             connectionDB = getConnection();
  1680.            
  1681.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1682.             sqlQueryObject.addFromTable(CostantiDB.USERS);
  1683.             sqlQueryObject.addFromTable(CostantiDB.USERS_STATI);
  1684.             sqlQueryObject.addSelectField(CostantiDB.USERS_STATI+".stato");
  1685.             sqlQueryObject.addSelectField(CostantiDB.USERS_STATI+".oggetto");
  1686.             sqlQueryObject.addWhereCondition(CostantiDB.USERS_STATI+".id_utente = "+CostantiDB.USERS+".id");
  1687.             sqlQueryObject.addWhereCondition(CostantiDB.USERS +".login = ?");
  1688.             sqlQueryObject.addWhereCondition(CostantiDB.USERS_STATI +".oggetto = ?");
  1689.             sqlQueryObject.setANDLogicOperator(true);
  1690.             String sqlQuery = sqlQueryObject.createSQLQuery();
  1691.             stm = connectionDB.prepareStatement(sqlQuery);
  1692.             stm.setString(1, login);
  1693.             stm.setString(2, nomeOggetto);
  1694.             rs = stm.executeQuery();
  1695.             while (rs.next()) {
  1696.                 String oggetto = rs.getString("oggetto");
  1697.                 String stato = rs.getString("stato");
  1698.                 statoObject = new Stato();
  1699.                 statoObject.setOggetto(oggetto);
  1700.                 statoObject.setStato(stato);
  1701.             }
  1702.             rs.close();
  1703.             stm.close();

  1704.             return statoObject;
  1705.         } catch (SQLException se) {
  1706.             throw new DriverUsersDBException("[DriverUsersDB::getStato] SqlException: " + se.getMessage(),se);
  1707.         } catch (Exception ex) {
  1708.             throw new DriverUsersDBException("[DriverUsersDB::getStato] Exception: " + ex.getMessage(),ex);
  1709.         } finally {
  1710.             try {
  1711.                 if(rs!=null) {
  1712.                     rs.close();
  1713.                 }
  1714.             } catch (Exception e) {
  1715.                 // ignore exception
  1716.             }
  1717.             try {
  1718.                 if(stm!=null) {
  1719.                     stm.close();
  1720.                 }
  1721.             } catch (Exception e) {
  1722.                 // ignore exception
  1723.             }
  1724.             releaseConnection(connectionDB);

  1725.         }
  1726.     }
  1727.    
  1728.     /**
  1729.      * Aggiorna il protocollo utilizzato dall'utente <var>login</var>
  1730.      *
  1731.      * @param login Identificatore di un utente
  1732.      * @param protocollo Protocollo
  1733.      *              
  1734.      */
  1735.     public void saveProtocolloUtilizzatoPddConsole(String login, String protocollo) throws DriverUsersDBException {
  1736.         if (login == null)
  1737.             throw new DriverUsersDBException("[saveProtocolloUtilizzatoPddConsole] Parametri Non Validi");

  1738.         Connection connectionDB = null;
  1739.         PreparedStatement stm = null;
  1740.         try {
  1741.             // Get Connection
  1742.             connectionDB = getConnection();
  1743.            
  1744.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1745.             sqlQueryObject.addUpdateTable(CostantiDB.USERS);
  1746.             sqlQueryObject.addUpdateField("protocollo_pddconsole", "?");
  1747.             sqlQueryObject.addWhereCondition(CostantiDB.USERS +".login = ?");
  1748.             sqlQueryObject.setANDLogicOperator(true);
  1749.             String sqlQuery = sqlQueryObject.createSQLUpdate();
  1750.             stm = connectionDB.prepareStatement(sqlQuery);
  1751.             stm.setString(1, protocollo);
  1752.             stm.setString(2, login);
  1753.             stm.executeUpdate();
  1754.             stm.close();

  1755.         } catch (SQLException se) {
  1756.             throw new DriverUsersDBException("[DriverUsersDB::saveProtocolloUtilizzatoPddConsole] SqlException: " + se.getMessage(),se);
  1757.         } catch (Exception ex) {
  1758.             throw new DriverUsersDBException("[DriverUsersDB::saveProtocolloUtilizzatoPddConsole] Exception: " + ex.getMessage(),ex);
  1759.         } finally {
  1760.             try {
  1761.                 if(stm!=null) {
  1762.                     stm.close();
  1763.                 }
  1764.             } catch (Exception e) {
  1765.                 // ignore exception
  1766.             }
  1767.             releaseConnection(connectionDB);

  1768.         }
  1769.     }
  1770.    
  1771.     /**
  1772.      * Aggiorna il protocollo utilizzato dall'utente <var>login</var>
  1773.      *
  1774.      * @param login Identificatore di un utente
  1775.      * @param protocollo Protocollo
  1776.      *              
  1777.      */
  1778.     public void saveProtocolloUtilizzatoPddMonitor(String login, String protocollo) throws DriverUsersDBException {
  1779.         if (login == null)
  1780.             throw new DriverUsersDBException("[saveProtocolloUtilizzatoPddMonitor] Parametri Non Validi");

  1781.         Connection connectionDB = null;
  1782.         PreparedStatement stm = null;
  1783.         try {
  1784.             // Get Connection
  1785.             connectionDB = getConnection();
  1786.            
  1787.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1788.             sqlQueryObject.addUpdateTable(CostantiDB.USERS);
  1789.             sqlQueryObject.addUpdateField("protocollo_pddmonitor", "?");
  1790.             sqlQueryObject.addWhereCondition(CostantiDB.USERS +".login = ?");
  1791.             sqlQueryObject.setANDLogicOperator(true);
  1792.             String sqlQuery = sqlQueryObject.createSQLUpdate();
  1793.             stm = connectionDB.prepareStatement(sqlQuery);
  1794.             stm.setString(1, protocollo);
  1795.             stm.setString(2, login);
  1796.             stm.executeUpdate();
  1797.             stm.close();

  1798.         } catch (SQLException se) {
  1799.             throw new DriverUsersDBException("[DriverUsersDB::saveProtocolloUtilizzatoPddMonitor] SqlException: " + se.getMessage(),se);
  1800.         } catch (Exception ex) {
  1801.             throw new DriverUsersDBException("[DriverUsersDB::saveProtocolloUtilizzatoPddMonitor] Exception: " + ex.getMessage(),ex);
  1802.         } finally {
  1803.             try {
  1804.                 if(stm!=null) {
  1805.                     stm.close();
  1806.                 }
  1807.             } catch (Exception e) {
  1808.                 // ignore exception
  1809.             }
  1810.             releaseConnection(connectionDB);

  1811.         }
  1812.     }
  1813.    
  1814.     /**
  1815.      * Aggiorna il soggetto utilizzato dall'utente <var>login</var>
  1816.      *
  1817.      * @param login Identificatore di un utente
  1818.      * @param soggetto Soggetto
  1819.      *              
  1820.      */
  1821.     public void saveSoggettoUtilizzatoPddConsole(String login, String soggetto) throws DriverUsersDBException {
  1822.         if (login == null)
  1823.             throw new DriverUsersDBException("[saveSoggettoUtilizzatoPddConsole] Parametri Non Validi");

  1824.         Connection connectionDB = null;
  1825.         try {
  1826.             // Get Connection
  1827.             connectionDB = getConnection();
  1828.            
  1829.             saveSoggettoUtilizzatoPddConsole(connectionDB, login, soggetto);

  1830.         } catch (SQLException se) {
  1831.             throw new DriverUsersDBException("[DriverUsersDB::saveSoggettoUtilizzatoPddConsole] SqlException: " + se.getMessage(),se);
  1832.         } catch (Exception ex) {
  1833.             throw new DriverUsersDBException("[DriverUsersDB::saveSoggettoUtilizzatoPddConsole] Exception: " + ex.getMessage(),ex);
  1834.         } finally {
  1835.             releaseConnection(connectionDB);

  1836.         }
  1837.     }
  1838.    
  1839.     public void saveSoggettoUtilizzatoPddConsole(Connection conParam, String login, String soggetto) throws DriverUsersDBException {
  1840.         if (login == null)
  1841.             throw new DriverUsersDBException("[saveSoggettoUtilizzatoPddConsole] Parametri Non Validi");

  1842.         PreparedStatement stm = null;
  1843.         try {          
  1844.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1845.             sqlQueryObject.addUpdateTable(CostantiDB.USERS);
  1846.             sqlQueryObject.addUpdateField("soggetto_pddconsole", "?");
  1847.             sqlQueryObject.addWhereCondition(CostantiDB.USERS +".login = ?");
  1848.             sqlQueryObject.setANDLogicOperator(true);
  1849.             String sqlQuery = sqlQueryObject.createSQLUpdate();
  1850.             stm = conParam.prepareStatement(sqlQuery);
  1851.             stm.setString(1, soggetto);
  1852.             stm.setString(2, login);
  1853.             stm.executeUpdate();
  1854.             stm.close();

  1855.         } catch (SQLException se) {
  1856.             throw new DriverUsersDBException("[DriverUsersDB::saveSoggettoUtilizzatoPddConsole] SqlException: " + se.getMessage(),se);
  1857.         } catch (Exception ex) {
  1858.             throw new DriverUsersDBException("[DriverUsersDB::saveSoggettoUtilizzatoPddConsole] Exception: " + ex.getMessage(),ex);
  1859.         } finally {
  1860.             try {
  1861.                 if(stm!=null) {
  1862.                     stm.close();
  1863.                 }
  1864.             } catch (Exception e) {
  1865.                 // ignore exception
  1866.             }
  1867.         }
  1868.     }
  1869.    
  1870.     /**
  1871.      * Aggiorna il soggetto utilizzato dall'utente <var>login</var>
  1872.      *
  1873.      * @param login Identificatore di un utente
  1874.      * @param soggetto Soggetto
  1875.      *              
  1876.      */
  1877.     public void saveSoggettoUtilizzatoPddMonitor(String login, String soggetto) throws DriverUsersDBException {
  1878.         if (login == null)
  1879.             throw new DriverUsersDBException("[saveSoggettoUtilizzatoPddMonitor] Parametri Non Validi");

  1880.         Connection connectionDB = null;
  1881.         try {
  1882.             // Get Connection
  1883.             connectionDB = getConnection();
  1884.            
  1885.             saveSoggettoUtilizzatoPddMonitor(connectionDB, login, soggetto);

  1886.         } catch (SQLException se) {
  1887.             throw new DriverUsersDBException("[DriverUsersDB::saveSoggettoUtilizzatoPddMonitor] SqlException: " + se.getMessage(),se);
  1888.         } catch (Exception ex) {
  1889.             throw new DriverUsersDBException("[DriverUsersDB::saveSoggettoUtilizzatoPddMonitor] Exception: " + ex.getMessage(),ex);
  1890.         } finally {
  1891.             releaseConnection(connectionDB);

  1892.         }
  1893.     }
  1894.    
  1895.     public void saveSoggettoUtilizzatoPddMonitor(Connection conParam, String login, String soggetto) throws DriverUsersDBException {
  1896.         if (login == null)
  1897.             throw new DriverUsersDBException("[saveSoggettoUtilizzatoPddMonitor] Parametri Non Validi");

  1898.         PreparedStatement stm = null;
  1899.         try {          
  1900.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1901.             sqlQueryObject.addUpdateTable(CostantiDB.USERS);
  1902.             sqlQueryObject.addUpdateField("soggetto_pddmonitor", "?");
  1903.             sqlQueryObject.addWhereCondition(CostantiDB.USERS +".login = ?");
  1904.             sqlQueryObject.setANDLogicOperator(true);
  1905.             String sqlQuery = sqlQueryObject.createSQLUpdate();
  1906.             stm = conParam.prepareStatement(sqlQuery);
  1907.             stm.setString(1, soggetto);
  1908.             stm.setString(2, login);
  1909.             stm.executeUpdate();
  1910.             stm.close();

  1911.         } catch (SQLException se) {
  1912.             throw new DriverUsersDBException("[DriverUsersDB::saveSoggettoUtilizzatoPddMonitor] SqlException: " + se.getMessage(),se);
  1913.         } catch (Exception ex) {
  1914.             throw new DriverUsersDBException("[DriverUsersDB::saveSoggettoUtilizzatoPddMonitor] Exception: " + ex.getMessage(),ex);
  1915.         } finally {
  1916.             try {
  1917.                 if(stm!=null) {
  1918.                     stm.close();
  1919.                 }
  1920.             } catch (Exception e) {
  1921.                 // ignore exception
  1922.             }
  1923.         }
  1924.     }
  1925.    
  1926.     /**
  1927.      * Aggiorna il soggetto utilizzato dall'utente <var>login</var>
  1928.      *
  1929.      * @param oldSoggetto Identita precedentemente associata
  1930.      * @param newSoggetto Nuova identita associata
  1931.      *              
  1932.      */
  1933.     public void modificaSoggettoUtilizzatoConsole(String oldSoggetto, String newSoggetto) throws DriverUsersDBException {
  1934.         if (oldSoggetto == null) // || newSoggetto==null)
  1935.             throw new DriverUsersDBException("[modificaSoggettoUtilizzatoConsole] Parametri Non Validi");

  1936.         Connection connectionDB = null;
  1937.         PreparedStatement stm = null;
  1938.         ResultSet rs = null;
  1939.         try {
  1940.             // Get Connection
  1941.             connectionDB = getConnection();
  1942.            
  1943.             List<String> users = new ArrayList<>();
  1944.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1945.             sqlQueryObject.addFromTable(CostantiDB.USERS);
  1946.             sqlQueryObject.addWhereCondition("soggetto_pddconsole=?");
  1947.             sqlQueryObject.setANDLogicOperator(true);
  1948.             String sqlQuery = sqlQueryObject.createSQLQuery();
  1949.             stm = connectionDB.prepareStatement(sqlQuery);
  1950.             stm.setString(1, oldSoggetto);
  1951.             rs = stm.executeQuery();
  1952.             while(rs.next()) {
  1953.                 String login = rs.getString("login");
  1954.                 users.add(login);
  1955.             }
  1956.             rs.close();
  1957.             stm.close();
  1958.             if(!users.isEmpty()) {
  1959.                 for (String user : users) {
  1960.                     this.saveSoggettoUtilizzatoPddConsole(connectionDB, user, newSoggetto);
  1961.                 }
  1962.             }
  1963.            
  1964.             users = new ArrayList<>();
  1965.             sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1966.             sqlQueryObject.addFromTable(CostantiDB.USERS);
  1967.             sqlQueryObject.addWhereCondition("soggetto_pddmonitor=?");
  1968.             sqlQueryObject.setANDLogicOperator(true);
  1969.             sqlQuery = sqlQueryObject.createSQLQuery();
  1970.             stm = connectionDB.prepareStatement(sqlQuery);
  1971.             stm.setString(1, oldSoggetto);
  1972.             rs = stm.executeQuery();
  1973.             while(rs.next()) {
  1974.                 String login = rs.getString("login");
  1975.                 users.add(login);
  1976.             }
  1977.             rs.close();
  1978.             stm.close();
  1979.             if(!users.isEmpty()) {
  1980.                 for (String user : users) {
  1981.                     this.saveSoggettoUtilizzatoPddMonitor(connectionDB, user, newSoggetto);
  1982.                 }
  1983.             }


  1984.         } catch (SQLException se) {
  1985.             throw new DriverUsersDBException("[DriverUsersDB::saveSoggettoUtilizzatoPddMonitor] SqlException: " + se.getMessage(),se);
  1986.         } catch (Exception ex) {
  1987.             throw new DriverUsersDBException("[DriverUsersDB::saveSoggettoUtilizzatoPddMonitor] Exception: " + ex.getMessage(),ex);
  1988.         } finally {
  1989.             try {
  1990.                 if(rs!=null) {
  1991.                     rs.close();
  1992.                 }
  1993.             } catch (Exception e) {
  1994.                 // ignore exception
  1995.             }
  1996.             try {
  1997.                 if(stm!=null) {
  1998.                     stm.close();
  1999.                 }
  2000.             } catch (Exception e) {
  2001.                 // ignore exception
  2002.             }
  2003.             releaseConnection(connectionDB);

  2004.         }
  2005.     }
  2006.    
  2007.     /**
  2008.      * Aggiorna lo stato identificato da <var>login</var> e da <var>nomeOggetto</var>
  2009.      *
  2010.      * @param login Identificatore di un utente
  2011.      * @param nomeOggetto Oggetto da ricercare
  2012.      * @param statoOggetto Stato da salvare
  2013.      *              
  2014.      */
  2015.     public void saveStato(String login, String nomeOggetto, String statoOggetto) throws DriverUsersDBException {
  2016.         if (login == null || nomeOggetto == null)
  2017.             throw new DriverUsersDBException("[saveStato] Parametri Non Validi");

  2018.         Connection connectionDB = null;
  2019.         PreparedStatement stm = null;
  2020.         ResultSet rs = null;
  2021.         try {
  2022.             // Get Connection
  2023.             connectionDB = getConnection();
  2024.            
  2025.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  2026.             sqlQueryObject.addSelectField("id");
  2027.             sqlQueryObject.addFromTable(CostantiDB.USERS);
  2028.             sqlQueryObject.addWhereCondition(CostantiDB.USERS +".login = ?");
  2029.             String sqlQuery = sqlQueryObject.createSQLQuery();
  2030.             stm = connectionDB.prepareStatement(sqlQuery);
  2031.             stm.setString(1, login);
  2032.             rs = stm.executeQuery();
  2033.            
  2034.             Long idUtente = null;
  2035.             while (rs.next()) {
  2036.                 idUtente = rs.getLong("id");
  2037.             }
  2038.             rs.close();
  2039.             stm.close();
  2040.            
  2041.             sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  2042.             sqlQueryObject.addUpdateTable(CostantiDB.USERS_STATI);
  2043.             sqlQueryObject.addUpdateField("stato","?");
  2044.             sqlQueryObject.addWhereCondition(CostantiDB.USERS_STATI+".id_utente = ?");
  2045.             sqlQueryObject.addWhereCondition(CostantiDB.USERS_STATI +".oggetto = ?");
  2046.             sqlQueryObject.setANDLogicOperator(true);
  2047.             sqlQuery = sqlQueryObject.createSQLUpdate();
  2048.             stm = connectionDB.prepareStatement(sqlQuery);
  2049.             stm.setString(1, statoOggetto);
  2050.             stm.setLong(2, idUtente);
  2051.             stm.setString(3, nomeOggetto);
  2052.             int update = stm.executeUpdate();
  2053.             stm.close();
  2054.            
  2055.             // nuovo stato
  2056.             if(update == 0) {
  2057.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  2058.                 sqlQueryObject.addInsertTable(CostantiDB.USERS_STATI);
  2059.                 sqlQueryObject.addInsertField("stato","?");
  2060.                 sqlQueryObject.addInsertField("id_utente","?");
  2061.                 sqlQueryObject.addInsertField("oggetto","?");
  2062.                 sqlQuery = sqlQueryObject.createSQLInsert();
  2063.                 stm = connectionDB.prepareStatement(sqlQuery);
  2064.                 stm.setString(1, statoOggetto);
  2065.                 stm.setLong(2, idUtente);
  2066.                 stm.setString(3, nomeOggetto);
  2067.                 update = stm.executeUpdate();
  2068.                 stm.close();
  2069.             }

  2070.         } catch (SQLException se) {
  2071.             throw new DriverUsersDBException("[DriverUsersDB::saveStato] SqlException: " + se.getMessage(),se);
  2072.         } catch (Exception ex) {
  2073.             throw new DriverUsersDBException("[DriverUsersDB::saveStato] Exception: " + ex.getMessage(),ex);
  2074.         } finally {
  2075.             try {
  2076.                 if(rs!=null) {
  2077.                     rs.close();
  2078.                 }
  2079.             } catch (Exception e) {
  2080.                 // ignore exception
  2081.             }
  2082.             try {
  2083.                 if(stm!=null) {
  2084.                     stm.close();
  2085.                 }
  2086.             } catch (Exception e) {
  2087.                 // ignore exception
  2088.             }
  2089.             releaseConnection(connectionDB);

  2090.         }
  2091.     }
  2092.    
  2093.    
  2094.     public void savePassword(Long idUser, String login, String newPassword, Date dataAggiornamentoPassword) throws DriverUsersDBException {
  2095.         this.savePassword(idUser, login, newPassword, dataAggiornamentoPassword, null);
  2096.     }
  2097.    
  2098.     public void savePassword(Long idUser, String login, String password, Date dataAggiornamentoPassword, List<UserPassword> storicoPassword) throws DriverUsersDBException {
  2099.         if (login == null || password==null)
  2100.             throw new DriverUsersDBException("[savePassword] Parametri Non Validi");

  2101.         Connection connectionDB = null;
  2102.         PreparedStatement stm = null;
  2103.         try {
  2104.             // Get Connection
  2105.             connectionDB = getConnection();
  2106.            
  2107.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  2108.             sqlQueryObject.addUpdateTable(CostantiDB.USERS);
  2109.             sqlQueryObject.addUpdateField("password", "?");
  2110.             if(dataAggiornamentoPassword!=null) {
  2111.                 sqlQueryObject.addUpdateField("data_password", "?");
  2112.             }
  2113.             sqlQueryObject.addWhereCondition(CostantiDB.USERS +".login = ?");
  2114.             sqlQueryObject.setANDLogicOperator(true);
  2115.             String sqlQuery = sqlQueryObject.createSQLUpdate();
  2116.             stm = connectionDB.prepareStatement(sqlQuery);
  2117.             int index = 1;
  2118.             stm.setString(index++, password);
  2119.             if(dataAggiornamentoPassword!=null) {
  2120.                 stm.setTimestamp(index++, new Timestamp(dataAggiornamentoPassword.getTime()));
  2121.             }
  2122.             stm.setString(index++, login);
  2123.             stm.executeUpdate();
  2124.             stm.close();
  2125.            
  2126.             // salvataggio dello storico password
  2127.             if(storicoPassword != null) {
  2128.                 try {
  2129.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  2130.                     sqlQueryObject.addDeleteTable(CostantiDB.USERS_PASSWORD);
  2131.                     sqlQueryObject.addWhereCondition("id_utente = ?");
  2132.                     sqlQuery = sqlQueryObject.createSQLDelete();
  2133.                     stm = connectionDB.prepareStatement(sqlQuery);
  2134.                     stm.setLong(1, idUser);
  2135.                     stm.executeUpdate();
  2136.                     stm.close();
  2137.                 } finally {

  2138.                     //Chiudo statement and resultset
  2139.                     try {
  2140.                         if (stm != null)
  2141.                             stm.close();
  2142.                     } catch (Exception e) {
  2143.                         //ignore
  2144.                     }
  2145.                 }
  2146.                
  2147.                 if(storicoPassword.size()>0) {
  2148.                     stm = null;
  2149.                     ResultSet rs = null;
  2150.                     try {
  2151.                         for (UserPassword userPassword : storicoPassword) {
  2152.                            
  2153.                             sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  2154.                             sqlQueryObject.addInsertTable(CostantiDB.USERS_PASSWORD);
  2155.                             sqlQueryObject.addInsertField("id_utente", "?");
  2156.                             sqlQueryObject.addInsertField("password", "?");
  2157.                             sqlQueryObject.addInsertField("data_password", "?");
  2158.                             sqlQuery = sqlQueryObject.createSQLInsert();
  2159.                             stm = connectionDB.prepareStatement(sqlQuery);
  2160.                             index = 1;
  2161.                             stm.setLong(index++, idUser);
  2162.                             stm.setString(index++, userPassword.getPassword());
  2163.                             stm.setTimestamp(index++, new Timestamp(userPassword.getDatePassword().getTime()));
  2164.                             stm.executeUpdate();
  2165.                             stm.close();
  2166.                         }
  2167.                     } finally {

  2168.                         //Chiudo statement and resultset
  2169.                         try {
  2170.                             if (rs != null)
  2171.                                 rs.close();
  2172.                         } catch (Exception e) {
  2173.                             //ignore
  2174.                         }
  2175.                         try {
  2176.                             if (stm != null)
  2177.                                 stm.close();
  2178.                         } catch (Exception e) {
  2179.                             //ignore
  2180.                         }
  2181.                        
  2182.                     }
  2183.                 }
  2184.             }

  2185.         } catch (SQLException se) {
  2186.             throw new DriverUsersDBException("[DriverUsersDB::savePassword] SqlException: " + se.getMessage(),se);
  2187.         } catch (Exception ex) {
  2188.             throw new DriverUsersDBException("[DriverUsersDB::savePassword] Exception: " + ex.getMessage(),ex);
  2189.         } finally {
  2190.             try {
  2191.                 if(stm!=null) {
  2192.                     stm.close();
  2193.                 }
  2194.             } catch (Exception e) {
  2195.                 // ignore exception
  2196.             }
  2197.             releaseConnection(connectionDB);

  2198.         }
  2199.     }
  2200.    
  2201.     public UserObjects countUserServizi(String user) throws DriverUsersDBException {
  2202.         return countUser(user, false);
  2203.     }
  2204.     public UserObjects countUserCooperazione(String user) throws DriverUsersDBException {
  2205.         return countUser(user, true);
  2206.     }
  2207.     public UserObjects countUser(String user, boolean cooperazione) throws DriverUsersDBException {
  2208.         if (user==null)
  2209.             throw new DriverUsersDBException("[countUser] Parametri Non Validi");

  2210.         Connection connectionDB = null;
  2211.         PreparedStatement stm = null;
  2212.         ResultSet rs = null;
  2213.         try {
  2214.             // Get Connection
  2215.             connectionDB = getConnection();
  2216.            
  2217.             List<String> tables = new ArrayList<>();
  2218.             if(cooperazione) {
  2219.                 tables.add(CostantiDB.ACCORDI_COOPERAZIONE);
  2220.                 tables.add(CostantiDB.ACCORDI);
  2221.             }
  2222.             else {
  2223.                 tables.add(CostantiDB.PDD);
  2224.                 tables.add(CostantiDB.GRUPPI);
  2225.                 tables.add(CostantiDB.RUOLI);
  2226.                 tables.add(CostantiDB.SCOPE);
  2227.                 tables.add(CostantiDB.SOGGETTI);
  2228.                 tables.add(CostantiDB.ACCORDI);
  2229.                 tables.add(CostantiDB.SERVIZI);
  2230.             }
  2231.        
  2232.             UserObjects results = new UserObjects();
  2233.            
  2234.             for (String table : tables) {
  2235.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  2236.                 sqlQueryObject.addFromTable(table);
  2237.                 sqlQueryObject.addSelectCountField("id", "somma");
  2238.                 sqlQueryObject.addWhereCondition("superuser = ?");
  2239.                 if(CostantiDB.ACCORDI.equals(table)) {
  2240.                    
  2241.                     ISQLQueryObject sqlQueryObjectExclude = null;
  2242.                     sqlQueryObjectExclude = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  2243.                     sqlQueryObjectExclude.addFromTable(CostantiDB.ACCORDI_SERVIZI_COMPOSTO);
  2244.                     sqlQueryObjectExclude.addSelectField(CostantiDB.ACCORDI_SERVIZI_COMPOSTO, "id_accordo");
  2245.                     sqlQueryObjectExclude.addWhereCondition(CostantiDB.ACCORDI_SERVIZI_COMPOSTO+".id_accordo="+CostantiDB.ACCORDI+".id");
  2246.                     if(cooperazione){
  2247.                         sqlQueryObject.addWhereExistsCondition(false, sqlQueryObjectExclude);
  2248.                     }
  2249.                     else{
  2250.                         sqlQueryObject.addWhereExistsCondition(true, sqlQueryObjectExclude);
  2251.                     }
  2252.                    
  2253.                 }
  2254.                 sqlQueryObject.setANDLogicOperator(true);
  2255.                 String sqlQuery = sqlQueryObject.createSQLQuery();
  2256.                 stm = connectionDB.prepareStatement(sqlQuery);
  2257.                 int index = 1;
  2258.                 stm.setString(index++, user);
  2259.                 rs = stm.executeQuery();
  2260.                 int result = rs.getInt("somma");
  2261.                 rs.close();
  2262.                 stm.close();
  2263.                
  2264.                 if(CostantiDB.PDD.equals(table)) {
  2265.                     results.pdd = result;
  2266.                 }
  2267.                 else if(CostantiDB.GRUPPI.equals(table)) {
  2268.                     results.gruppi = result;
  2269.                 }
  2270.                 else if(CostantiDB.RUOLI.equals(table)) {
  2271.                     results.ruoli = result;
  2272.                 }
  2273.                 else if(CostantiDB.SCOPE.equals(table)) {
  2274.                     results.scope = result;
  2275.                 }
  2276.                 else if(CostantiDB.SOGGETTI.equals(table)) {
  2277.                     results.soggetti = result;
  2278.                 }
  2279.                 else if(CostantiDB.ACCORDI.equals(table)) {
  2280.                     results.accordi_parte_comune = result;
  2281.                 }
  2282.                 else if(CostantiDB.ACCORDI_COOPERAZIONE.equals(table)) {
  2283.                     results.accordi_accoperazione = result;
  2284.                 }
  2285.                 else if(CostantiDB.SERVIZI.equals(table)) {
  2286.                     results.accordi_parte_specifica = result;
  2287.                 }
  2288.             }
  2289.            
  2290.             return results;
  2291.            
  2292.         } catch (SQLException se) {
  2293.             throw new DriverUsersDBException("[DriverUsersDB::countUser] SqlException: " + se.getMessage(),se);
  2294.         } catch (Exception ex) {
  2295.             throw new DriverUsersDBException("[DriverUsersDB::countUser] Exception: " + ex.getMessage(),ex);
  2296.         } finally {
  2297.             try {
  2298.                 if(rs!=null) {
  2299.                     rs.close();
  2300.                 }
  2301.             } catch (Exception e) {
  2302.                 // ignore exception
  2303.             }
  2304.             try {
  2305.                 if(stm!=null) {
  2306.                     stm.close();
  2307.                 }
  2308.             } catch (Exception e) {
  2309.                 // ignore exception
  2310.             }
  2311.             releaseConnection(connectionDB);

  2312.         }
  2313.     }
  2314.    
  2315.     public UserObjects updateUserServizi(String oldUser, String newUser) throws DriverUsersDBException {
  2316.         return updateUser(oldUser, newUser, false);
  2317.     }
  2318.     public UserObjects updateUserCooperazione(String oldUser, String newUser) throws DriverUsersDBException {
  2319.         return updateUser(oldUser, newUser, true);
  2320.     }
  2321.     public UserObjects updateUser(String oldUser, String newUser, boolean cooperazione) throws DriverUsersDBException {
  2322.         if (oldUser == null || newUser==null)
  2323.             throw new DriverUsersDBException("[updateUser] Parametri Non Validi");

  2324.         Connection connectionDB = null;
  2325.         PreparedStatement stm = null;
  2326.         try {
  2327.             // Get Connection
  2328.             connectionDB = getConnection();
  2329.            
  2330.             List<String> tables = new ArrayList<>();
  2331.             if(cooperazione) {
  2332.                 tables.add(CostantiDB.ACCORDI_COOPERAZIONE);
  2333.                 tables.add(CostantiDB.ACCORDI);
  2334.             }
  2335.             else {
  2336.                 tables.add(CostantiDB.PDD);
  2337.                 tables.add(CostantiDB.GRUPPI);
  2338.                 tables.add(CostantiDB.RUOLI);
  2339.                 tables.add(CostantiDB.SCOPE);
  2340.                 tables.add(CostantiDB.SOGGETTI);
  2341.                 tables.add(CostantiDB.ACCORDI);
  2342.                 tables.add(CostantiDB.SERVIZI);
  2343.             }
  2344.        
  2345.             UserObjects results = new UserObjects();
  2346.            
  2347.             for (String table : tables) {
  2348.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  2349.                 sqlQueryObject.addUpdateTable(table);
  2350.                 sqlQueryObject.addUpdateField("superuser", "?");
  2351.                 sqlQueryObject.addWhereCondition("superuser = ?");
  2352.                 if(CostantiDB.ACCORDI.equals(table)) {
  2353.                    
  2354.                     ISQLQueryObject sqlQueryObjectExclude = null;
  2355.                     sqlQueryObjectExclude = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  2356.                     sqlQueryObjectExclude.addFromTable(CostantiDB.ACCORDI_SERVIZI_COMPOSTO);
  2357.                     sqlQueryObjectExclude.addSelectField(CostantiDB.ACCORDI_SERVIZI_COMPOSTO, "id_accordo");
  2358.                     sqlQueryObjectExclude.addWhereCondition(CostantiDB.ACCORDI_SERVIZI_COMPOSTO+".id_accordo="+CostantiDB.ACCORDI+".id");
  2359.                     if(cooperazione){
  2360.                         sqlQueryObject.addWhereExistsCondition(false, sqlQueryObjectExclude);
  2361.                     }
  2362.                     else{
  2363.                         sqlQueryObject.addWhereExistsCondition(true, sqlQueryObjectExclude);
  2364.                     }
  2365.                    
  2366.                 }
  2367.                 sqlQueryObject.setANDLogicOperator(true);
  2368.                 String sqlQuery = sqlQueryObject.createSQLUpdate();
  2369.                 stm = connectionDB.prepareStatement(sqlQuery);
  2370.                 int index = 1;
  2371.                 stm.setString(index++, newUser);
  2372.                 stm.setString(index++, oldUser);
  2373.                 int result = stm.executeUpdate();
  2374.                 stm.close();
  2375.                
  2376.                 if(CostantiDB.PDD.equals(table)) {
  2377.                     results.pdd = result;
  2378.                 }
  2379.                 else if(CostantiDB.GRUPPI.equals(table)) {
  2380.                     results.gruppi = result;
  2381.                 }
  2382.                 else if(CostantiDB.RUOLI.equals(table)) {
  2383.                     results.ruoli = result;
  2384.                 }
  2385.                 else if(CostantiDB.SCOPE.equals(table)) {
  2386.                     results.scope = result;
  2387.                 }
  2388.                 else if(CostantiDB.SOGGETTI.equals(table)) {
  2389.                     results.soggetti = result;
  2390.                 }
  2391.                 else if(CostantiDB.ACCORDI.equals(table)) {
  2392.                     results.accordi_parte_comune = result;
  2393.                 }
  2394.                 else if(CostantiDB.ACCORDI_COOPERAZIONE.equals(table)) {
  2395.                     results.accordi_accoperazione = result;
  2396.                 }
  2397.                 else if(CostantiDB.SERVIZI.equals(table)) {
  2398.                     results.accordi_parte_specifica = result;
  2399.                 }
  2400.             }
  2401.            
  2402.             return results;
  2403.            
  2404.         } catch (SQLException se) {
  2405.             throw new DriverUsersDBException("[DriverUsersDB::updateUser] SqlException: " + se.getMessage(),se);
  2406.         } catch (Exception ex) {
  2407.             throw new DriverUsersDBException("[DriverUsersDB::updateUser] Exception: " + ex.getMessage(),ex);
  2408.         } finally {
  2409.             try {
  2410.                 if(stm!=null) {
  2411.                     stm.close();
  2412.                 }
  2413.             } catch (Exception e) {
  2414.                 // ignore exception
  2415.             }
  2416.             releaseConnection(connectionDB);
  2417.         }
  2418.     }
  2419. }