DBUtils.java

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



  20. package org.openspcoop2.core.commons;

  21. import java.sql.Connection;
  22. import java.sql.PreparedStatement;
  23. import java.sql.ResultSet;
  24. import java.sql.SQLException;
  25. import java.text.MessageFormat;
  26. import java.util.ArrayList;
  27. import java.util.List;
  28. import java.util.Map;

  29. import org.openspcoop2.core.constants.CostantiDB;
  30. import org.openspcoop2.core.constants.ProprietariProtocolProperty;
  31. import org.openspcoop2.core.constants.TipiConnettore;
  32. import org.openspcoop2.core.id.IDAccordo;
  33. import org.openspcoop2.core.id.IDAccordoCooperazione;
  34. import org.openspcoop2.core.id.IDGruppo;
  35. import org.openspcoop2.core.id.IDRuolo;
  36. import org.openspcoop2.core.id.IDScope;
  37. import org.openspcoop2.core.id.IDServizio;
  38. import org.openspcoop2.core.id.IDSoggetto;
  39. import org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject;
  40. import org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCParameterUtilities;
  41. import org.openspcoop2.generic_project.dao.jdbc.utils.JDBCSqlLogger;
  42. import org.openspcoop2.utils.BooleanNullable;
  43. import org.openspcoop2.utils.TipiDatabase;
  44. import org.openspcoop2.utils.UtilsException;
  45. import org.openspcoop2.utils.jdbc.JDBCAdapterException;
  46. import org.openspcoop2.utils.jdbc.JDBCUtilities;
  47. import org.openspcoop2.utils.sql.ISQLQueryObject;
  48. import org.openspcoop2.utils.sql.LikeConfig;
  49. import org.openspcoop2.utils.sql.SQLObjectFactory;
  50. import org.openspcoop2.utils.sql.SQLQueryObjectException;
  51. import org.slf4j.Logger;


  52. /**
  53.  * Funzioni di utilita utilizzate dai driver
  54.  *
  55.  * @author Stefano Corallo (corallo@link.it)
  56.  * @author $Author$
  57.  * @version $Rev$, $Date$
  58.  */
  59. public class DBUtils {

  60.     private DBUtils() {}
  61.    
  62.     private static final String WHERE_ID_CONDITION = "id = ?";
  63.    
  64.     public static String estraiTipoDatabaseFromLocation(String location)throws CoreException{
  65.         if(location==null){
  66.             throw new CoreException("Location del db is null");
  67.         }
  68.         if(location.indexOf("@")==-1){
  69.             throw new CoreException("Tipo di database non indicato nella location, sintassi corretta e' tipoDatabase@datasource");
  70.         }
  71.         String tipoDatabase = location.split("@")[0].trim();
  72.         if( ! TipiDatabase.isAMember(tipoDatabase)){
  73.             throw new CoreException("Tipo di database indicato nella location ["+tipoDatabase+"] non supportato");
  74.         }
  75.         return tipoDatabase;
  76.     }
  77.    
  78.    
  79.     public static List<List<Object>> readCustom(Logger log, Connection connection, String tipoDB,
  80.             ISQLQueryObject sqlQueryObject, List<Class<?>> returnTypes, List<JDBCObject> paramTypes) throws CoreException
  81.     {
  82.         PreparedStatement stm = null;
  83.         ResultSet rs = null;
  84.         try
  85.         {
  86.             if(returnTypes==null || returnTypes.isEmpty()){
  87.                 throw new CoreException("Non sono stati definiti tipi da ritornare");
  88.             }
  89.            
  90.             List<List<Object>> lista = new ArrayList<>();
  91.            
  92.             String sql = sqlQueryObject.createSQLQuery();
  93.             stm=connection.prepareStatement(sql);
  94.             GenericJDBCParameterUtilities jdbcParameterUtilities = new GenericJDBCParameterUtilities(TipiDatabase.toEnumConstant(tipoDB));
  95.             JDBCObject [] paramsArray = null;
  96.             if(paramTypes!=null && !paramTypes.isEmpty()){
  97.                 paramsArray = paramTypes.toArray(new JDBCObject[1]);
  98.             }
  99.             jdbcParameterUtilities.setParameters(stm, paramsArray);
  100.            
  101.             JDBCSqlLogger sqlLogger = new JDBCSqlLogger(log);
  102.             sqlLogger.infoSql(sql, paramsArray);
  103.            
  104.             rs=stm.executeQuery();

  105.             while(rs.next()){
  106.                
  107.                 List<Object> listaInterna = new ArrayList<>();
  108.                
  109.                 for (int i = 0; i < returnTypes.size(); i++) {
  110.                     listaInterna.add(jdbcParameterUtilities.readParameter(rs, (i+1), returnTypes.get(i)));
  111.                 }
  112.                
  113.                 lista.add(listaInterna);
  114.             }

  115.             return lista;

  116.         }catch (Exception e) {
  117.             throw new CoreException(e);
  118.         }finally
  119.         {
  120.             //Chiudo statement and resultset
  121.             JDBCUtilities.closeResources(rs, stm);

  122.         }
  123.     }
  124.    
  125.    
  126.    
  127.    
  128.     /**
  129.      * Recupera l'id del soggetto in base al nome e al tipo passati come parametri
  130.      * @param nomeSoggetto
  131.      * @param tipoSoggetto
  132.      * @param con
  133.      * @return L'id del soggetto se esiste, altrimenti -1
  134.      * @throws CoreException
  135.      */
  136.     public static long getIdSoggetto(String nomeSoggetto, String tipoSoggetto,Connection con, String tipoDB) throws CoreException
  137.     {
  138.         return DBUtils.getIdSoggetto(nomeSoggetto, tipoSoggetto, con, tipoDB, CostantiDB.SOGGETTI);
  139.     }
  140.     public static long getIdSoggetto(String nomeSoggetto, String tipoSoggetto,Connection con, String tipoDB,String tabellaSoggetti) throws CoreException
  141.     {
  142.         PreparedStatement stm = null;
  143.         ResultSet rs = null;
  144.         long idSoggetto=-1;
  145.         try
  146.         {
  147.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  148.             sqlQueryObject.addFromTable(tabellaSoggetti);
  149.             sqlQueryObject.addSelectField("*");
  150.             sqlQueryObject.addWhereCondition("tipo_soggetto = ?");
  151.             sqlQueryObject.addWhereCondition("nome_soggetto = ?");
  152.             sqlQueryObject.setANDLogicOperator(true);
  153.             String query = sqlQueryObject.createSQLQuery();
  154.             stm=con.prepareStatement(query);
  155.             stm.setString(1, tipoSoggetto);
  156.             stm.setString(2, nomeSoggetto);

  157.             rs=stm.executeQuery();

  158.             if(rs.next()){
  159.                 idSoggetto = rs.getLong("id");
  160.             }

  161.             return idSoggetto;

  162.         }catch (Exception e) {
  163.             throw new CoreException(e);
  164.         }finally
  165.         {
  166.             //Chiudo statement and resultset
  167.             JDBCUtilities.closeResources(rs, stm);

  168.         }
  169.     }
  170.    
  171.     public static IDSoggetto getIdSoggetto(long id,Connection con, String tipoDB) throws CoreException
  172.     {
  173.         return DBUtils.getIdSoggetto(id, con, tipoDB, CostantiDB.SOGGETTI);
  174.     }
  175.     public static IDSoggetto getIdSoggetto(long id,Connection con, String tipoDB,String tabellaSoggetti) throws CoreException
  176.     {
  177.         PreparedStatement stm = null;
  178.         ResultSet rs = null;
  179.         IDSoggetto idSoggetto = null;
  180.         try
  181.         {
  182.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  183.             sqlQueryObject.addFromTable(tabellaSoggetti);
  184.             sqlQueryObject.addSelectField("*");
  185.             sqlQueryObject.addWhereCondition(WHERE_ID_CONDITION);
  186.             sqlQueryObject.setANDLogicOperator(true);
  187.             String query = sqlQueryObject.createSQLQuery();
  188.             stm=con.prepareStatement(query);
  189.             stm.setLong(1, id);

  190.             rs=stm.executeQuery();

  191.             if(rs.next()){
  192.                 String tipSoggetto = rs.getString("tipo_soggetto");
  193.                 String nomeSoggetto = rs.getString("nome_soggetto");
  194.                 idSoggetto = new IDSoggetto(tipSoggetto, nomeSoggetto);
  195.             }

  196.             return idSoggetto;

  197.         }catch (Exception e) {
  198.             throw new CoreException(e);
  199.         }finally
  200.         {
  201.             //Chiudo statement and resultset
  202.             JDBCUtilities.closeResources(rs, stm);

  203.         }
  204.     }
  205.    
  206.    
  207.    
  208.    

  209.     public static long getIdConnettore(String nomeConnettore,Connection con, String tipoDB) throws CoreException
  210.     {
  211.         PreparedStatement stm = null;
  212.         ResultSet rs = null;
  213.         long idConnettore=-1;
  214.         try
  215.         {
  216.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  217.             sqlQueryObject.addFromTable(CostantiDB.CONNETTORI);
  218.             sqlQueryObject.addSelectField("*");
  219.             sqlQueryObject.addWhereCondition("nome_connettore = ?");
  220.             String query = sqlQueryObject.createSQLQuery();
  221.             stm=con.prepareStatement(query);
  222.             stm.setString(1, nomeConnettore);
  223.             rs=stm.executeQuery();

  224.             if(rs.next()){
  225.                 idConnettore = rs.getLong("id");
  226.             }

  227.             return idConnettore;

  228.         }catch (Exception e) {
  229.             throw new CoreException(e);
  230.         }finally
  231.         {
  232.             //Chiudo statement and resultset
  233.             JDBCUtilities.closeResources(rs, stm);

  234.         }
  235.     }

  236.    
  237.    
  238.     /**
  239.      * Recupero l'id del servizio
  240.      */
  241.     public static long getIdServizio(String nomeServizio, String tipoServizio,Integer versioneServizio, String nomeSoggettoErogatore,String tipoSoggettoErogatore,Connection con, String tipoDB) throws CoreException{
  242.         return DBUtils.getIdServizio(nomeServizio,tipoServizio,versioneServizio,nomeSoggettoErogatore,tipoSoggettoErogatore,con,false,tipoDB, CostantiDB.SOGGETTI);
  243.     }
  244.     public static long getIdServizio(String nomeServizio, String tipoServizio,Integer versioneServizio, String nomeSoggettoErogatore,String tipoSoggettoErogatore,Connection con, String tipoDB,String tabellaSoggetti) throws CoreException{
  245.         return DBUtils.getIdServizio(nomeServizio,tipoServizio,versioneServizio,nomeSoggettoErogatore,tipoSoggettoErogatore,con,false,tipoDB,tabellaSoggetti);
  246.     }
  247.     public static long getIdServizio(String nomeServizio, String tipoServizio,Integer versioneServizio, long idSoggetto,Connection con, String tipoDB) throws CoreException{
  248.         return DBUtils.getIdServizio(nomeServizio,tipoServizio,versioneServizio,idSoggetto,con,false,tipoDB, CostantiDB.SOGGETTI);
  249.     }
  250.     public static long getIdServizio(String nomeServizio, String tipoServizio,Integer versioneServizio, long idSoggetto,Connection con, String tipoDB,String tabellaSoggetti) throws CoreException{
  251.         return DBUtils.getIdServizio(nomeServizio,tipoServizio,versioneServizio,idSoggetto,con,false,tipoDB,tabellaSoggetti);
  252.     }

  253.     /**
  254.      * Recupero l'id del servizio
  255.      */
  256.     public static long getIdServizio(String nomeServizio, String tipoServizio,Integer versioneServizio, String nomeSoggettoErogatore,String tipoSoggettoErogatore,
  257.             Connection con,boolean testServizioNonCorrelato,String tipoDB) throws CoreException
  258.     {
  259.         return DBUtils.getIdServizio(nomeServizio, tipoServizio, versioneServizio, nomeSoggettoErogatore, tipoSoggettoErogatore, con, testServizioNonCorrelato, tipoDB, CostantiDB.SOGGETTI);
  260.     }
  261.     public static long getIdServizio(String nomeServizio, String tipoServizio,Integer versioneServizio, String nomeSoggettoErogatore,String tipoSoggettoErogatore,
  262.             Connection con,boolean testServizioNonCorrelato,String tipoDB,String tabellaSoggetti) throws CoreException
  263.     {
  264.         long idSoggetto = DBUtils.getIdSoggetto(nomeSoggettoErogatore, tipoSoggettoErogatore, con, tipoDB,tabellaSoggetti);
  265.         return getIdServizio(nomeServizio, tipoServizio, versioneServizio, idSoggetto,
  266.                 con, testServizioNonCorrelato, tipoDB, tabellaSoggetti);
  267.     }
  268.     public static long getIdServizio(String nomeServizio, String tipoServizio,Integer versioneServizio, long idSoggetto,
  269.             Connection con,boolean testServizioNonCorrelato,String tipoDB) throws CoreException
  270.     {
  271.         return  getIdServizio(nomeServizio, tipoServizio, versioneServizio, idSoggetto,
  272.                 con,testServizioNonCorrelato,tipoDB,CostantiDB.SOGGETTI);
  273.     }
  274.     public static long getIdServizio(String nomeServizio, String tipoServizio,Integer versioneServizio, long idSoggetto,
  275.             Connection con,boolean testServizioNonCorrelato,String tipoDB,String tabellaSoggetti) throws CoreException
  276.     {
  277.         PreparedStatement stm = null;
  278.         ResultSet rs = null;
  279.         long idServizio=0;
  280.         try
  281.         {
  282.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  283.             sqlQueryObject.addFromTable(CostantiDB.SERVIZI);
  284.             sqlQueryObject.addSelectField("*");
  285.             sqlQueryObject.addWhereCondition("id_soggetto = ?");
  286.             sqlQueryObject.addWhereCondition("tipo_servizio = ?");
  287.             sqlQueryObject.addWhereCondition("nome_servizio = ?");
  288.             sqlQueryObject.addWhereCondition("versione_servizio = ?");
  289.             sqlQueryObject.setANDLogicOperator(true);
  290.             String query = sqlQueryObject.createSQLQuery();
  291.             if(testServizioNonCorrelato)
  292.                 query = query + " AND servizio_correlato=?";
  293.             stm=con.prepareStatement(query);
  294.             int index = 1;
  295.             stm.setLong(index++, idSoggetto);
  296.             stm.setString(index++, tipoServizio);
  297.             stm.setString(index++, nomeServizio);
  298.             stm.setInt(index++, versioneServizio);
  299.             if(testServizioNonCorrelato)
  300.                 stm.setString(index++, CostantiDB.STATO_FUNZIONALITA_DISABILITATO);

  301.             rs=stm.executeQuery();

  302.             if(rs.next()){
  303.                 idServizio = rs.getLong("id");
  304.             }

  305.             return idServizio;

  306.         }catch (Exception e) {
  307.             throw new CoreException(e);
  308.         }finally
  309.         {
  310.             //Chiudo statement and resultset
  311.             JDBCUtilities.closeResources(rs, stm);

  312.         }
  313.     }

  314.    
  315.    
  316.    
  317.    
  318.    
  319.     public static String getSuperUserSoggettoSafe(Logger log, String method,
  320.             long idSoggetto,Connection con, String tipoDB)
  321.     {
  322.         return getSuperUserSoggettoSafe(log, method,
  323.                 idSoggetto,con, tipoDB,CostantiDB.SOGGETTI);
  324.     }
  325.     public static String getSuperUserSoggettoSafe(Logger log, String method,
  326.             long idSoggetto,Connection con, String tipoDB,String tabellaSoggetti)
  327.     {
  328.         try
  329.         {
  330.             return getSuperUserSoggetto(idSoggetto, con, tipoDB, tabellaSoggetti);
  331.         }catch(Exception e) {
  332.             if(log!=null) {
  333.                 String msgError = "["+method+"] getSuperUserSoggetto failed: "+e.getMessage();
  334.                 log.error(msgError, e);
  335.             }
  336.             return null;
  337.         }
  338.     }
  339.     public static String getSuperUserSoggetto(long idSoggetto,Connection con, String tipoDB) throws CoreException
  340.     {
  341.         return getSuperUserSoggetto(idSoggetto, con, tipoDB, CostantiDB.SOGGETTI);
  342.     }
  343.     public static String getSuperUserSoggetto(long idSoggetto,Connection con, String tipoDB,String tabellaSoggetti) throws CoreException
  344.     {
  345.         PreparedStatement stm = null;
  346.         ResultSet rs = null;
  347.         String superuser=null;
  348.         try
  349.         {
  350.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  351.             sqlQueryObject.addFromTable(tabellaSoggetti);
  352.             sqlQueryObject.addSelectField("superuser");
  353.             sqlQueryObject.addWhereCondition(WHERE_ID_CONDITION);
  354.             sqlQueryObject.setANDLogicOperator(true);
  355.             String query = sqlQueryObject.createSQLQuery();
  356.             stm=con.prepareStatement(query);
  357.             stm.setLong(1, idSoggetto);

  358.             rs=stm.executeQuery();

  359.             if(rs.next()){
  360.                 superuser = rs.getString("superuser");
  361.             }

  362.             return superuser;

  363.         }
  364.         catch (Exception e) {
  365.             throw new CoreException(e);
  366.         }finally
  367.         {
  368.             //Chiudo statement and resultset
  369.             JDBCUtilities.closeResources(rs, stm);

  370.         }
  371.     }
  372.    
  373.    
  374.    
  375.    
  376.    
  377.    
  378.    
  379.    
  380.    
  381.     public static String getSuperUserServizioSafe(Logger log, String method,
  382.             long idServizio,Connection con, String tipoDB)
  383.     {
  384.         try
  385.         {
  386.             return getSuperUserServizio(idServizio, con, tipoDB);
  387.         }catch(Exception e) {
  388.             if(log!=null) {
  389.                 String msgError = "["+method+"] getSuperUserServizio failed: "+e.getMessage();
  390.                 log.error(msgError, e);
  391.             }
  392.             return null;
  393.         }
  394.     }
  395.     public static String getSuperUserServizio(long idServizio,Connection con, String tipoDB) throws CoreException
  396.     {
  397.         PreparedStatement stm = null;
  398.         ResultSet rs = null;
  399.         String superuser=null;
  400.         try
  401.         {
  402.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  403.             sqlQueryObject.addFromTable(CostantiDB.SERVIZI);
  404.             sqlQueryObject.addSelectField("superuser");
  405.             sqlQueryObject.addWhereCondition(WHERE_ID_CONDITION);
  406.             sqlQueryObject.setANDLogicOperator(true);
  407.             String query = sqlQueryObject.createSQLQuery();
  408.             stm=con.prepareStatement(query);
  409.             stm.setLong(1, idServizio);

  410.             rs=stm.executeQuery();

  411.             if(rs.next()){
  412.                 superuser = rs.getString("superuser");
  413.             }

  414.             return superuser;

  415.         }
  416.         catch (Exception e) {
  417.             throw new CoreException(e);
  418.         }finally
  419.         {
  420.             //Chiudo statement and resultset
  421.             JDBCUtilities.closeResources(rs, stm);

  422.         }
  423.     }
  424.    
  425.    
  426.    
  427.    
  428.    
  429.    

  430.     public static long getIdPortaApplicativa(String nomePorta, Connection con, String tipoDB) throws CoreException
  431.     {
  432.         PreparedStatement stm = null;
  433.         ResultSet rs = null;
  434.         long idPortaApplicativa=-1;

  435.         try
  436.         {
  437.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  438.             sqlQueryObject.addFromTable(CostantiDB.PORTE_APPLICATIVE);
  439.             sqlQueryObject.addSelectField("id");
  440.             sqlQueryObject.addWhereCondition("nome_porta = ?");
  441.             sqlQueryObject.setANDLogicOperator(true);
  442.             String sqlQuery = sqlQueryObject.createSQLQuery();
  443.             stm=con.prepareStatement(sqlQuery);
  444.             stm.setString(1, nomePorta);

  445.             rs=stm.executeQuery();

  446.             if(rs.next())
  447.             {
  448.                 idPortaApplicativa=rs.getLong("id");
  449.             }
  450.             return idPortaApplicativa;
  451.         }catch (Exception e) {
  452.             throw new CoreException(e);
  453.         }finally
  454.         {
  455.             //Chiudo statement and resultset
  456.             JDBCUtilities.closeResources(rs, stm);

  457.         }

  458.     }
  459.    
  460.    
  461.    
  462.    
  463.    
  464.    
  465.     public static long getIdPortaDelegata(String nomePorta, Connection con, String tipoDB) throws CoreException
  466.     {
  467.         PreparedStatement stm = null;
  468.         ResultSet rs = null;
  469.         long idPortaDelegata=-1;

  470.         try
  471.         {
  472.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  473.             sqlQueryObject.addFromTable(CostantiDB.PORTE_DELEGATE);
  474.             sqlQueryObject.addSelectField("id");
  475.             sqlQueryObject.addWhereCondition("nome_porta = ?");
  476.             sqlQueryObject.setANDLogicOperator(true);
  477.             String sqlQuery = sqlQueryObject.createSQLQuery();
  478.             stm=con.prepareStatement(sqlQuery);
  479.             stm.setString(1, nomePorta);

  480.             rs=stm.executeQuery();

  481.             if(rs.next())
  482.             {
  483.                 idPortaDelegata=rs.getLong("id");
  484.             }
  485.             return idPortaDelegata;
  486.         }catch (Exception e) {
  487.             throw new CoreException(e);
  488.         }finally
  489.         {
  490.             //Chiudo statement and resultset
  491.             JDBCUtilities.closeResources(rs, stm);

  492.         }

  493.     }
  494.    
  495.    
  496.    
  497.    
  498.    
  499.    
  500.     public static long getIdServizioApplicativo(String nomeServizioApplicativo, String tipoProprietario, String nomeProprietario,
  501.             Connection con, String tipoDB) throws CoreException
  502.     {
  503.         return DBUtils.getIdServizioApplicativo(nomeServizioApplicativo, tipoProprietario, nomeProprietario, con, tipoDB, CostantiDB.SOGGETTI);
  504.     }
  505.     public static long getIdServizioApplicativo(String nomeServizioApplicativo, String tipoProprietario, String nomeProprietario,
  506.             Connection con, String tipoDB,String tabellaSoggetti) throws CoreException
  507.     {
  508.         PreparedStatement stm = null;
  509.         ResultSet rs = null;
  510.         long idSoggetto;
  511.         long idServizioApplicativo=-1;

  512.         try
  513.         {
  514.             idSoggetto = DBUtils.getIdSoggetto(nomeProprietario, tipoProprietario, con, tipoDB,tabellaSoggetti);

  515.             //recupero l'id della porta applicativa appena inserita
  516.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  517.             sqlQueryObject.addFromTable(CostantiDB.SERVIZI_APPLICATIVI);
  518.             sqlQueryObject.addSelectField("id");
  519.             sqlQueryObject.addWhereCondition("id_soggetto = ?");
  520.             sqlQueryObject.addWhereCondition("nome = ?");
  521.             sqlQueryObject.setANDLogicOperator(true);
  522.             String sqlQuery = sqlQueryObject.createSQLQuery();
  523.             stm=con.prepareStatement(sqlQuery);
  524.             stm.setLong(1, idSoggetto);
  525.             stm.setString(2, nomeServizioApplicativo);

  526.             rs=stm.executeQuery();

  527.             if(rs.next())
  528.             {
  529.                 idServizioApplicativo=rs.getLong("id");
  530.             }
  531.             return idServizioApplicativo;
  532.         }catch (Exception e) {
  533.             throw new CoreException(e);
  534.         }finally
  535.         {
  536.             //Chiudo statement and resultset
  537.             JDBCUtilities.closeResources(rs, stm);

  538.         }

  539.     }

  540.    
  541.    
  542.    
  543.    
  544.    
  545.     public static long getIdPortaDominio(String nome, Connection con, String tipoDB) throws CoreException
  546.     {
  547.         PreparedStatement stm = null;
  548.         ResultSet rs = null;
  549.         long idPdD=-1;
  550.         try
  551.         {
  552.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  553.             sqlQueryObject.addFromTable(CostantiDB.PDD);
  554.             sqlQueryObject.addSelectField("*");
  555.             sqlQueryObject.addWhereCondition("nome = ?");
  556.             sqlQueryObject.setANDLogicOperator(true);
  557.             String query = sqlQueryObject.createSQLQuery();
  558.             stm=con.prepareStatement(query);
  559.             stm.setString(1, nome);

  560.             rs=stm.executeQuery();

  561.             if(rs.next()){
  562.                 idPdD = rs.getLong("id");
  563.             }

  564.             return idPdD;

  565.         }catch (Exception e) {
  566.             throw new CoreException(e);
  567.         }finally
  568.         {
  569.             //Chiudo statement and resultset
  570.             JDBCUtilities.closeResources(rs, stm);

  571.         }
  572.     }
  573.    
  574.    
  575.    
  576.    
  577.    
  578.     public static long getIdGruppo(IDGruppo idGruppo, Connection con, String tipoDB) throws CoreException
  579.     {
  580.         PreparedStatement stm = null;
  581.         ResultSet rs = null;
  582.         long idGruppoLong=-1;
  583.         try
  584.         {
  585.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  586.             sqlQueryObject.addFromTable(CostantiDB.GRUPPI);
  587.             sqlQueryObject.addSelectField("*");
  588.             sqlQueryObject.addWhereCondition("nome = ?");
  589.             sqlQueryObject.setANDLogicOperator(true);
  590.             String query = sqlQueryObject.createSQLQuery();
  591.             stm=con.prepareStatement(query);
  592.             stm.setString(1, idGruppo.getNome());

  593.             rs=stm.executeQuery();

  594.             if(rs.next()){
  595.                 idGruppoLong = rs.getLong("id");
  596.             }

  597.             return idGruppoLong;

  598.         }catch (Exception e) {
  599.             throw new CoreException(e);
  600.         }finally
  601.         {
  602.             //Chiudo statement and resultset
  603.             JDBCUtilities.closeResources(rs, stm);

  604.         }
  605.     }
  606.    
  607.    
  608.    
  609.    
  610.    
  611.    
  612.     public static long getIdRuolo(IDRuolo idRuolo, Connection con, String tipoDB) throws CoreException
  613.     {
  614.         PreparedStatement stm = null;
  615.         ResultSet rs = null;
  616.         long idRuoloLong=-1;
  617.         try
  618.         {
  619.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  620.             sqlQueryObject.addFromTable(CostantiDB.RUOLI);
  621.             sqlQueryObject.addSelectField("*");
  622.             sqlQueryObject.addWhereCondition("nome = ?");
  623.             sqlQueryObject.setANDLogicOperator(true);
  624.             String query = sqlQueryObject.createSQLQuery();
  625.             stm=con.prepareStatement(query);
  626.             stm.setString(1, idRuolo.getNome());

  627.             rs=stm.executeQuery();

  628.             if(rs.next()){
  629.                 idRuoloLong = rs.getLong("id");
  630.             }

  631.             return idRuoloLong;

  632.         }catch (Exception e) {
  633.             throw new CoreException(e);
  634.         }finally
  635.         {
  636.             //Chiudo statement and resultset
  637.             JDBCUtilities.closeResources(rs, stm);

  638.         }
  639.     }
  640.    
  641.    
  642.    
  643.    
  644.     public static long getIdScope(IDScope idScope, Connection con, String tipoDB) throws CoreException
  645.     {
  646.         PreparedStatement stm = null;
  647.         ResultSet rs = null;
  648.         long idScopeLong=-1;
  649.         try
  650.         {
  651.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  652.             sqlQueryObject.addFromTable(CostantiDB.SCOPE);
  653.             sqlQueryObject.addSelectField("*");
  654.             sqlQueryObject.addWhereCondition("nome = ?");
  655.             sqlQueryObject.setANDLogicOperator(true);
  656.             String query = sqlQueryObject.createSQLQuery();
  657.             stm=con.prepareStatement(query);
  658.             stm.setString(1, idScope.getNome());

  659.             rs=stm.executeQuery();

  660.             if(rs.next()){
  661.                 idScopeLong = rs.getLong("id");
  662.             }

  663.             return idScopeLong;

  664.         }catch (Exception e) {
  665.             throw new CoreException(e);
  666.         }finally
  667.         {
  668.             //Chiudo statement and resultset
  669.             JDBCUtilities.closeResources(rs, stm);

  670.         }
  671.     }
  672.    
  673.    
  674.    
  675.    
  676.    

  677.     public static long getIdAccordoServizioParteComune(String nomeServizio, String tipoServizio,Integer versioneServizio, String nomeSoggettoErogatore,String tipoSoggettoErogatore,Connection con, String tipoDB) throws CoreException
  678.     {
  679.         return DBUtils.getIdAccordoServizioParteComune(nomeServizio,tipoServizio,versioneServizio, nomeSoggettoErogatore,tipoSoggettoErogatore,con,tipoDB,CostantiDB.SOGGETTI);
  680.     }
  681.     public static long getIdAccordoServizioParteComune(String nomeServizio, String tipoServizio,Integer versioneServizio, String nomeSoggettoErogatore,String tipoSoggettoErogatore,Connection con, String tipoDB,String tabellaSoggetti) throws CoreException
  682.     {
  683.         PreparedStatement stm = null;
  684.         ResultSet rs = null;
  685.         long idServizio;
  686.         long idAccordo = -1;
  687.         try
  688.         {
  689.             idServizio = DBUtils.getIdServizio(nomeServizio, tipoServizio, versioneServizio, nomeSoggettoErogatore, tipoSoggettoErogatore, con, tipoDB,tabellaSoggetti);

  690.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  691.             sqlQueryObject.addFromTable(CostantiDB.SERVIZI);
  692.             sqlQueryObject.addSelectField("*");
  693.             sqlQueryObject.addWhereCondition(WHERE_ID_CONDITION);
  694.             String query = sqlQueryObject.createSQLQuery();
  695.             stm=con.prepareStatement(query);
  696.             stm.setLong(1, idServizio);

  697.             rs=stm.executeQuery();

  698.             if(rs.next()){
  699.                 idAccordo = rs.getLong("id_accordo");
  700.             }

  701.             return idAccordo;

  702.         }catch (Exception e) {
  703.             throw new CoreException(e);
  704.         }finally
  705.         {
  706.             //Chiudo statement and resultset
  707.             JDBCUtilities.closeResources(rs, stm);

  708.         }
  709.     }
  710.    
  711.     public static long getIdPortType(Long idAccordo,String nomePortType,Connection con) throws CoreException{
  712.         PreparedStatement selectStmt = null;
  713.         ResultSet selectRS = null;
  714.         long id=-1;
  715.         try
  716.         {
  717.             String selectQuery = "SELECT id FROM " + CostantiDB.PORT_TYPE + " WHERE id_accordo = ? AND nome=?";
  718.             selectStmt = con.prepareStatement(selectQuery);
  719.             selectStmt.setLong(1, idAccordo);
  720.             selectStmt.setString(2, nomePortType);
  721.             selectRS = selectStmt.executeQuery();
  722.             if (selectRS.next()) {
  723.                 id = selectRS.getLong("id");    
  724.             }
  725.             selectRS.close();
  726.             selectStmt.close();
  727.             return id;
  728.         }catch (Exception e) {
  729.             throw new CoreException(e);
  730.         }finally
  731.         {
  732.             //Chiudo statement and resultset
  733.             JDBCUtilities.closeResources(selectRS, selectStmt);

  734.         }
  735.     }
  736.    
  737.     public static long getIdResource(Long idAccordo,String nomeRisorsa,Connection con) throws CoreException{
  738.         PreparedStatement selectStmt = null;
  739.         ResultSet selectRS = null;
  740.         long id=-1;
  741.         try
  742.         {
  743.             String selectQuery = "SELECT id FROM " + CostantiDB.API_RESOURCES + " WHERE id_accordo = ? AND nome=?";
  744.             selectStmt = con.prepareStatement(selectQuery);
  745.             selectStmt.setLong(1, idAccordo);
  746.             selectStmt.setString(2, nomeRisorsa);
  747.             selectRS = selectStmt.executeQuery();
  748.             if (selectRS.next()) {
  749.                 id = selectRS.getLong("id");    
  750.             }
  751.             selectRS.close();
  752.             selectStmt.close();
  753.             return id;
  754.         }catch (Exception e) {
  755.             throw new CoreException(e);
  756.         }finally
  757.         {
  758.             //Chiudo statement and resultset
  759.             JDBCUtilities.closeResources(selectRS, selectStmt);

  760.         }
  761.     }
  762.    
  763.     public static long getIdAccordoServizioParteComune(IDAccordo idAccordo,Connection con, String tipoDB) throws CoreException{
  764.         PreparedStatement stm = null;
  765.         ResultSet rs = null;
  766.         long idAccordoLong=-1;
  767.         try
  768.         {
  769.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  770.             sqlQueryObject.addFromTable(CostantiDB.ACCORDI);
  771.             sqlQueryObject.addSelectField("*");
  772.             sqlQueryObject.addWhereCondition("nome = ?");
  773.             sqlQueryObject.addWhereCondition("id_referente = ?");
  774.             sqlQueryObject.addWhereCondition("versione = ?");
  775.             sqlQueryObject.setANDLogicOperator(true);
  776.             String query = sqlQueryObject.createSQLQuery();
  777.             stm=con.prepareStatement(query);
  778.             stm.setString(1, idAccordo.getNome());
  779.            
  780.             long idSoggettoReferente =  0;
  781.             if(idAccordo.getSoggettoReferente()!=null){
  782.                 idSoggettoReferente = DBUtils.getIdSoggetto(idAccordo.getSoggettoReferente().getNome(), idAccordo.getSoggettoReferente().getTipo(), con, tipoDB);
  783.                 if(idSoggettoReferente<=0){
  784.                     throw new CoreException("[getIdAccordoServizioParteComune] Soggetto Referente ["+idAccordo.getSoggettoReferente().toString()+"] non esiste");
  785.                 }
  786.             }
  787.             stm.setLong(2, idSoggettoReferente);
  788.                
  789.             stm.setInt(3, idAccordo.getVersione());
  790.                        
  791.             rs=stm.executeQuery();

  792.             if(rs.next()){
  793.                 idAccordoLong = rs.getLong("id");
  794.             }

  795.             return idAccordoLong;

  796.         }catch (Exception e) {
  797.             throw new CoreException(e);
  798.         }finally
  799.         {
  800.             //Chiudo statement and resultset
  801.             JDBCUtilities.closeResources(rs, stm);

  802.         }
  803.     }
  804.    
  805.     public static int getAccordoServizioParteComuneNextVersion(IDAccordo idAccordo,Connection con, String tipoDB) throws CoreException{
  806.         PreparedStatement stm = null;
  807.         ResultSet rs = null;
  808.         try
  809.         {
  810.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  811.             sqlQueryObject.addFromTable(CostantiDB.ACCORDI);
  812.             sqlQueryObject.addSelectField("versione");
  813.             sqlQueryObject.addWhereCondition("nome = ?");
  814.             sqlQueryObject.addWhereCondition("id_referente = ?");
  815.             sqlQueryObject.addOrderBy("versione");
  816.             sqlQueryObject.setSortType(false);
  817.             sqlQueryObject.setANDLogicOperator(true);
  818.             String query = sqlQueryObject.createSQLQuery();
  819.             stm=con.prepareStatement(query);
  820.             stm.setString(1, idAccordo.getNome());
  821.            
  822.             long idSoggettoReferente =  0;
  823.             if(idAccordo.getSoggettoReferente()!=null){
  824.                 idSoggettoReferente = DBUtils.getIdSoggetto(idAccordo.getSoggettoReferente().getNome(), idAccordo.getSoggettoReferente().getTipo(), con, tipoDB);
  825.                 if(idSoggettoReferente<=0){
  826.                     throw new CoreException("[getIdAccordoServizioParteComune] Soggetto Referente ["+idAccordo.getSoggettoReferente().toString()+"] non esiste");
  827.                 }
  828.             }
  829.             stm.setLong(2, idSoggettoReferente);
  830.                
  831.             rs=stm.executeQuery();

  832.             if(rs.next()){
  833.                 int versione = rs.getInt("versione");
  834.                 if(versione>0) {
  835.                     return versione+1;
  836.                 }
  837.             }

  838.             return 1; // accordo non esistente

  839.         }catch (Exception e) {
  840.             throw new CoreException(e);
  841.         }finally
  842.         {
  843.             //Chiudo statement and resultset
  844.             JDBCUtilities.closeResources(rs, stm);

  845.         }
  846.     }
  847.    
  848.    
  849.    
  850.    
  851.     public static long getIdAccordoCooperazione(IDAccordoCooperazione idAccordo,Connection con, String tipoDB) throws CoreException{
  852.         PreparedStatement stm = null;
  853.         ResultSet rs = null;
  854.         long idAccordoLong=-1;
  855.         try
  856.         {
  857.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  858.             sqlQueryObject.addFromTable(CostantiDB.ACCORDI_COOPERAZIONE);
  859.             sqlQueryObject.addSelectField("*");
  860.             sqlQueryObject.addWhereCondition("nome = ?");
  861.             sqlQueryObject.addWhereCondition("id_referente = ?");
  862.             sqlQueryObject.addWhereCondition("versione = ?");
  863.             sqlQueryObject.setANDLogicOperator(true);
  864.             String query = sqlQueryObject.createSQLQuery();
  865.             stm=con.prepareStatement(query);
  866.             stm.setString(1, idAccordo.getNome());
  867.                
  868.             long idSoggettoReferente =  0;
  869.             if(idAccordo.getSoggettoReferente()!=null){
  870.                 idSoggettoReferente = DBUtils.getIdSoggetto(idAccordo.getSoggettoReferente().getNome(), idAccordo.getSoggettoReferente().getTipo(), con, tipoDB);
  871.                 if(idSoggettoReferente<=0){
  872.                     throw new CoreException("[getIdAccordoCooperazione] Soggetto Referente ["+idAccordo.getSoggettoReferente().toString()+"] non esiste");
  873.                 }
  874.             }
  875.             stm.setLong(2, idSoggettoReferente);
  876.                
  877.             stm.setInt(3, idAccordo.getVersione());
  878.                        
  879.             rs=stm.executeQuery();

  880.             if(rs.next()){
  881.                 idAccordoLong = rs.getLong("id");
  882.             }

  883.             return idAccordoLong;

  884.         }catch (Exception e) {
  885.             throw new CoreException(e);
  886.         }finally
  887.         {
  888.             //Chiudo statement and resultset
  889.             JDBCUtilities.closeResources(rs, stm);

  890.         }
  891.     }
  892.    
  893.    
  894.     public static long getIdAccordoServizioParteSpecifica(IDServizio idServizio,Connection con, String tipoDB) throws CoreException{
  895.         PreparedStatement stm = null;
  896.         ResultSet rs = null;
  897.         long idAccordoLong=-1;
  898.         try
  899.         {
  900.            
  901.             // NOTA: nell'APS, il soggetto e la versione sono obbligatori
  902.            
  903.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  904.             sqlQueryObject.addFromTable(CostantiDB.SERVIZI);
  905.             sqlQueryObject.addFromTable(CostantiDB.SOGGETTI);
  906.             sqlQueryObject.addSelectField("*");
  907.             sqlQueryObject.setANDLogicOperator(true);
  908.             sqlQueryObject.addWhereCondition(CostantiDB.SERVIZI+".id_soggetto = "+CostantiDB.SOGGETTI+".id");
  909.             sqlQueryObject.addWhereCondition("tipo_soggetto = ?");
  910.             sqlQueryObject.addWhereCondition("nome_soggetto = ?");
  911.             sqlQueryObject.addWhereCondition("tipo_servizio = ?");
  912.             sqlQueryObject.addWhereCondition("nome_servizio = ?");
  913.             sqlQueryObject.addWhereCondition("versione_servizio = ?");
  914.             String query = sqlQueryObject.createSQLQuery();
  915.             stm=con.prepareStatement(query);
  916.             stm.setString(1, idServizio.getSoggettoErogatore().getTipo());
  917.             stm.setString(2, idServizio.getSoggettoErogatore().getNome());
  918.             stm.setString(3, idServizio.getTipo());
  919.             stm.setString(4, idServizio.getNome());
  920.             stm.setInt(5, idServizio.getVersione());
  921.            
  922.             rs=stm.executeQuery();

  923.             if(rs.next()){
  924.                 idAccordoLong = rs.getLong("id");
  925.             }

  926.             return idAccordoLong;

  927.         }catch (Exception e) {
  928.             throw new CoreException(e);
  929.         }finally
  930.         {
  931.             //Chiudo statement and resultset
  932.             JDBCUtilities.closeResources(rs, stm);

  933.         }
  934.     }
  935.    
  936.    
  937.     public static long getIdFruizioneServizio(IDServizio idServizio,IDSoggetto idFruitore, Connection con, String tipoDB) throws CoreException{
  938.         return getIdFruizioneServizio(idServizio, idFruitore, con, tipoDB, CostantiDB.SOGGETTI);
  939.     }
  940.     public static long getIdFruizioneServizio(IDServizio idServizio,IDSoggetto idFruitore, Connection con, String tipoDB, String tabellaSoggetti) throws CoreException{
  941.         return _getIdFruizioneServizio(DBUtils.getIdAccordoServizioParteSpecifica(idServizio, con, tipoDB), idFruitore, con, tipoDB, tabellaSoggetti);
  942.     }
  943.    
  944.     private static long _getIdFruizioneServizio(long idServizio,IDSoggetto idFruitore, Connection con, String tipoDB, String tabellaSoggetti) throws CoreException{
  945.         PreparedStatement stm = null;
  946.         ResultSet rs = null;
  947.         long idFruizione=-1;
  948.         try
  949.         {
  950.            
  951.             // NOTA: nell'APS, il soggetto e la versione sono obbligatori
  952.            
  953.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  954.             sqlQueryObject.addFromTable(CostantiDB.SERVIZI_FRUITORI);
  955.             sqlQueryObject.addSelectField("id");
  956.             sqlQueryObject.setANDLogicOperator(true);
  957.             sqlQueryObject.addWhereCondition(CostantiDB.SERVIZI_FRUITORI+".id_servizio = ?");
  958.             sqlQueryObject.addWhereCondition(CostantiDB.SERVIZI_FRUITORI+".id_soggetto = ?");
  959.             String query = sqlQueryObject.createSQLQuery();
  960.             stm=con.prepareStatement(query);
  961.             stm.setLong(1, idServizio);
  962.             stm.setLong(2, DBUtils.getIdSoggetto(idFruitore.getNome(), idFruitore.getTipo(), con, tipoDB,tabellaSoggetti));
  963.            
  964.             rs=stm.executeQuery();

  965.             if(rs.next()){
  966.                 idFruizione = rs.getLong("id");
  967.             }

  968.             return idFruizione;

  969.         }catch (Exception e) {
  970.             throw new CoreException(e);
  971.         }finally
  972.         {
  973.             //Chiudo statement and resultset
  974.             JDBCUtilities.closeResources(rs, stm);

  975.         }
  976.     }
  977.    

  978.     public static long getIdDocumento(String nome, String tipo, String ruolo, long idProprietario,Connection con,String tipoDB,String tipoProprietario) throws CoreException{
  979.         PreparedStatement stm = null;
  980.         ResultSet rs = null;
  981.         long idDoc=-1;
  982.         try
  983.         {
  984.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  985.             sqlQueryObject.addFromTable(CostantiDB.DOCUMENTI);
  986.             sqlQueryObject.addSelectField("id");
  987.             sqlQueryObject.addWhereCondition("id_proprietario = ?");
  988.             sqlQueryObject.addWhereCondition("nome = ?");
  989.             if(tipo!=null) {
  990.                 sqlQueryObject.addWhereCondition("tipo = ?");
  991.             }
  992.             if(ruolo!=null) {
  993.                 sqlQueryObject.addWhereCondition("ruolo = ?");
  994.             }
  995.             sqlQueryObject.addWhereCondition("tipo_proprietario = ?");
  996.             sqlQueryObject.setANDLogicOperator(true);
  997.             String sqlQuery = sqlQueryObject.createSQLQuery();
  998.             stm = con.prepareStatement(sqlQuery);
  999.             int index = 1;
  1000.             stm.setLong(index++, idProprietario);
  1001.             stm.setString(index++, nome);
  1002.             if(tipo!=null) {
  1003.                 stm.setString(index++, tipo);
  1004.             }
  1005.             if(ruolo!=null) {
  1006.                 stm.setString(index++, ruolo);
  1007.             }
  1008.             stm.setString(index++, tipoProprietario);
  1009.             rs = stm.executeQuery();
  1010.             if (rs.next())
  1011.                 idDoc = rs.getLong("id");
  1012.             rs.close();
  1013.             stm.close();

  1014.             return idDoc;
  1015.         }catch (Exception e) {
  1016.             throw new CoreException(e);
  1017.         }finally
  1018.         {
  1019.             //Chiudo statement and resultset
  1020.             JDBCUtilities.closeResources(rs, stm);

  1021.         }
  1022.     }
  1023.    
  1024.    
  1025.     public static long getIdProtocolProperty(String tipoProprietario, long idProprietario,String nome, Connection con,String tipoDB) throws CoreException{
  1026.         PreparedStatement stm = null;
  1027.         ResultSet rs = null;
  1028.         long idPP=-1;
  1029.         try
  1030.         {
  1031.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  1032.             sqlQueryObject.addFromTable(CostantiDB.PROTOCOL_PROPERTIES);
  1033.             sqlQueryObject.addSelectField("id");
  1034.             sqlQueryObject.addWhereCondition("tipo_proprietario = ?");
  1035.             sqlQueryObject.addWhereCondition("id_proprietario = ?");
  1036.             sqlQueryObject.addWhereCondition("name = ?");
  1037.             sqlQueryObject.setANDLogicOperator(true);
  1038.             String sqlQuery = sqlQueryObject.createSQLQuery();
  1039.             stm = con.prepareStatement(sqlQuery);
  1040.             stm.setString(1, tipoProprietario);
  1041.             stm.setLong(2, idProprietario);
  1042.             stm.setString(3, nome);
  1043.             rs = stm.executeQuery();
  1044.             if (rs.next())
  1045.                 idPP = rs.getLong("id");
  1046.             rs.close();
  1047.             stm.close();

  1048.             return idPP;
  1049.         }catch (Exception e) {
  1050.             throw new CoreException(e);
  1051.         }finally
  1052.         {
  1053.             //Chiudo statement and resultset
  1054.             JDBCUtilities.closeResources(rs, stm);

  1055.         }
  1056.     }
  1057.    
  1058.    
  1059.    
  1060.    
  1061.    
  1062.     public static long getIdRegistroPlugin(String nome, Connection con,String tipoDB) throws CoreException{
  1063.         PreparedStatement stm = null;
  1064.         ResultSet rs = null;
  1065.         long idRP=-1;
  1066.         try
  1067.         {
  1068.             if(nome==null) {
  1069.                 throw new CoreException("Nome non fornito");
  1070.             }
  1071.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  1072.             sqlQueryObject.addFromTable(CostantiDB.REGISTRO_PLUGINS);
  1073.             sqlQueryObject.addSelectField("id");
  1074.             sqlQueryObject.addWhereCondition("nome=?");
  1075.             sqlQueryObject.setANDLogicOperator(true);
  1076.             String sqlQuery = sqlQueryObject.createSQLQuery();
  1077.             stm = con.prepareStatement(sqlQuery);
  1078.             stm.setString(1, nome);
  1079.             rs = stm.executeQuery();
  1080.             if(rs.next()) {
  1081.                 idRP = rs.getLong("id");
  1082.             }
  1083.             rs.close();
  1084.             stm.close();
  1085.             rs=null;
  1086.             stm=null;
  1087.            
  1088.             return idRP;
  1089.         }catch (Exception e) {
  1090.             throw new CoreException(e);
  1091.         }finally
  1092.         {
  1093.             //Chiudo statement and resultset
  1094.             JDBCUtilities.closeResources(rs, stm);

  1095.         }
  1096.     }
  1097.    
  1098.    
  1099.     public static long getIdPlugin(String className, String label, String tipoPlugin, String tipo, Connection con,String tipoDB) throws CoreException{
  1100.         PreparedStatement stm = null;
  1101.         ResultSet rs = null;
  1102.         long idRP=-1;
  1103.         try
  1104.         {
  1105.             if(className==null) {
  1106.                 throw new CoreException("ClassName non fornito");
  1107.             }
  1108.             if(label==null) {
  1109.                 throw new CoreException("Label non fornito");
  1110.             }
  1111.             if(tipoPlugin==null) {
  1112.                 throw new CoreException("TipoPlugin non fornito");
  1113.             }
  1114.             if(tipo==null) {
  1115.                 throw new CoreException("Tipo non fornito");
  1116.             }
  1117.            
  1118.            
  1119.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  1120.             sqlQueryObject.addFromTable(CostantiDB.REGISTRO_CLASSI);
  1121.             sqlQueryObject.addSelectField("id");
  1122.             sqlQueryObject.addWhereCondition("class_name=?");
  1123.             sqlQueryObject.addWhereCondition("label=?");
  1124.             sqlQueryObject.addWhereCondition("tipo_plugin=?");
  1125.             sqlQueryObject.addWhereCondition("tipo=?");
  1126.             sqlQueryObject.setANDLogicOperator(true);
  1127.             String sqlQuery = sqlQueryObject.createSQLQuery();
  1128.             stm = con.prepareStatement(sqlQuery);
  1129.             stm.setString(1, className);
  1130.             stm.setString(2, label);
  1131.             stm.setString(3, tipoPlugin);
  1132.             stm.setString(4, tipo);
  1133.             rs = stm.executeQuery();
  1134.             if(rs.next()) {
  1135.                 idRP = rs.getLong("id");
  1136.             }
  1137.             rs.close();
  1138.             stm.close();
  1139.             rs=null;
  1140.             stm=null;
  1141.            
  1142.             return idRP;
  1143.         }catch (Exception e) {
  1144.             throw new CoreException(e);
  1145.         }finally
  1146.         {
  1147.             //Chiudo statement and resultset
  1148.             JDBCUtilities.closeResources(rs, stm);

  1149.         }
  1150.     }
  1151.    
  1152.    
  1153.     public static long getUrlInvocazioneRegola(String nome, Connection con,String tipoDB) throws CoreException{
  1154.         PreparedStatement stm = null;
  1155.         ResultSet rs = null;
  1156.         long idRP=-1;
  1157.         try
  1158.         {
  1159.             if(nome==null) {
  1160.                 throw new CoreException("Nome non fornito");
  1161.             }
  1162.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  1163.             sqlQueryObject.addFromTable(CostantiDB.CONFIG_URL_REGOLE);
  1164.             sqlQueryObject.addSelectField("id");
  1165.             sqlQueryObject.addWhereCondition("nome=?");
  1166.             sqlQueryObject.setANDLogicOperator(true);
  1167.             String sqlQuery = sqlQueryObject.createSQLQuery();
  1168.             stm = con.prepareStatement(sqlQuery);
  1169.             stm.setString(1, nome);
  1170.             rs = stm.executeQuery();
  1171.             if(rs.next()) {
  1172.                 idRP = rs.getLong("id");
  1173.             }
  1174.             rs.close();
  1175.             stm.close();
  1176.             rs=null;
  1177.             stm=null;
  1178.            
  1179.             return idRP;
  1180.         }catch (Exception e) {
  1181.             throw new CoreException(e);
  1182.         }finally
  1183.         {
  1184.             //Chiudo statement and resultset
  1185.             JDBCUtilities.closeResources(rs, stm);

  1186.         }
  1187.     }
  1188.    
  1189.    

  1190.     public static void setPropertiesForSearch(ISQLQueryObject sqlQueryObject, Map<String, String> properties, String tabellaPadre,
  1191.             String tabellaProprieta, String columnName, String columnValue, String columnFK) throws SQLQueryObjectException{
  1192.         if(properties!=null && properties.size()>0){
  1193.             String [] conditions = new String[properties.size()];
  1194.             int i = 0;
  1195.             for (String nome : properties.keySet()) {

  1196.                 String aliasTabella = "pp"+i+tabellaPadre;
  1197.                 sqlQueryObject.addFromTable(tabellaProprieta, aliasTabella);
  1198.                 sqlQueryObject.setANDLogicOperator(true);
  1199.                 sqlQueryObject.addWhereCondition(aliasTabella+"."+columnFK+"="+tabellaPadre+".id");
  1200.                 String valore = properties.get(nome);
  1201.                                
  1202.                 if(conditions[i]!=null){
  1203.                     conditions[i] = conditions[i] + " AND ";
  1204.                 }
  1205.                 else {
  1206.                     conditions[i] = "";
  1207.                 }
  1208.                 conditions[i] = conditions[i] + " " + aliasTabella+"."+columnName+"=?";
  1209.                
  1210.                 if(valore!=null){
  1211.                     if(conditions[i]!=null){
  1212.                         conditions[i] = conditions[i] + " AND ";
  1213.                     }
  1214.                     else {
  1215.                         conditions[i] = "";
  1216.                     }
  1217.                     conditions[i] = conditions[i] + " " + aliasTabella+"."+columnValue+"=?";
  1218.                 }
  1219.                 else {
  1220.                     if(conditions[i]!=null){
  1221.                         conditions[i] = conditions[i] + " AND ";
  1222.                     }
  1223.                     else {
  1224.                         conditions[i] = "";
  1225.                     }
  1226.                     conditions[i] = conditions[i] + " " + aliasTabella+"."+columnValue+" is null";
  1227.                 }
  1228.                
  1229.                 // casoSpecialeValoreNull
  1230.                 ISQLQueryObject sqlQueryObjectPropertyNotExists = null;
  1231.                 // in un caso dove il valore non e' definito nel database ci possono essere due casistiche:
  1232.                 // 1) Passando via govwayConsole, la proprieta' esiste con il nome ('name') ed e' valorizzata null in tutte le colonne (value_string,value_number,value_boolean)
  1233.                 // 2) Passando via govwayLoader, in una configurazione xml, non si definisce la proprietà senza il valore, quindi la riga con il nome non esistera proprio nel db.
  1234.                 if(valore==null){
  1235.                    
  1236.                     ISQLQueryObject sqlQueryObjectPropertyNotExistsInternal = sqlQueryObject.newSQLQueryObject();
  1237.                     String aliasTabellaNotExists =  "not_exists_"+aliasTabella;
  1238.                     sqlQueryObjectPropertyNotExistsInternal.addFromTable(tabellaProprieta, aliasTabellaNotExists);
  1239.                     sqlQueryObjectPropertyNotExistsInternal.addSelectField(aliasTabellaNotExists, "id");
  1240.                     sqlQueryObjectPropertyNotExistsInternal.addWhereCondition(aliasTabellaNotExists+"."+columnFK+"="+aliasTabella+"."+columnFK);
  1241.                     sqlQueryObjectPropertyNotExistsInternal.addWhereCondition(aliasTabellaNotExists+"."+columnName+"=?");
  1242.                     sqlQueryObjectPropertyNotExistsInternal.setANDLogicOperator(true);
  1243.                    
  1244.                     sqlQueryObjectPropertyNotExists = sqlQueryObject.newSQLQueryObject();
  1245.                     sqlQueryObjectPropertyNotExists.addWhereExistsCondition(true, sqlQueryObjectPropertyNotExistsInternal);

  1246.                     conditions[i] = "( " + conditions[i] + " ) OR ( " + sqlQueryObjectPropertyNotExists.createSQLConditions() + " )";
  1247.                 }
  1248.                 i++;
  1249.             }
  1250.             sqlQueryObject.addWhereCondition(true, conditions);
  1251.         }
  1252.     }
  1253.    
  1254.     public static void setPropertiesForSearch(PreparedStatement stmt, int index,
  1255.             Map<String, String> properties,
  1256.             String tipoDatabase, Logger log) throws SQLQueryObjectException, SQLException, JDBCAdapterException, UtilsException{
  1257.        
  1258.         GenericJDBCParameterUtilities jdbcParameterUtilities = new GenericJDBCParameterUtilities(TipiDatabase.toEnumConstant(tipoDatabase));
  1259.        
  1260.         if(properties!=null && properties.size()>0){
  1261.             int i = 0;
  1262.             for (String nome : properties.keySet()) {
  1263.                
  1264.                 String valore = properties.get(nome);
  1265.                
  1266.                 log.debug("Proprieta["+i+"] nome stmt.setString("+nome+")");
  1267.                 stmt.setString(index++, nome);
  1268.                                
  1269.                 if(valore!=null){
  1270.                     log.debug("Proprieta["+i+"] valore stmt.setString("+valore+")");
  1271.                     jdbcParameterUtilities.setParameter(stmt, index++, valore, String.class);
  1272.                 }
  1273.                
  1274.                 // casoSpecialeValoreNull
  1275.                 // in un caso dove il valore non e' definito nel database ci possono essere due casistiche:
  1276.                 // 1) Passando via govwayConsole, la proprieta' esiste con il nome ('name') ed e' valorizzata null in tutte le colonne (value_string,value_number,value_boolean)
  1277.                 // 2) Passando via govwayLoader, in una configurazione xml, non si definisce la proprietà senza il valore, quindi la riga con il nome non esistera proprio nel db.
  1278.                 if(valore==null){
  1279.                     log.debug("Proprieta["+i+"] nome stmt.setString("+nome+")");
  1280.                     stmt.setString(index++, nome);
  1281.                 }
  1282.                
  1283.                 i++;
  1284.             }
  1285.         }
  1286.     }


  1287.     public static void setFiltriConnettoreApplicativo(ISQLQueryObject sqlQueryObject, String tipoDB,
  1288.             TipiConnettore tipoConnettore, String endpointType, boolean tipoConnettoreIntegrationManager,
  1289.             String filtroConnettoreTokenPolicy, String filtroConnettoreEndpoint, String filtroConnettoreKeystore, String filtroConnettoreDebug) throws Exception {

  1290.         ISQLQueryObject sql = SQLObjectFactory.createSQLQueryObject(tipoDB);
  1291.         sql.addFromTable(CostantiDB.CONNETTORI);
  1292.         sql.setANDLogicOperator(true);
  1293.         sql.addWhereCondition(CostantiDB.SERVIZI_APPLICATIVI+".id_connettore_inv="+CostantiDB.CONNETTORI+".id");
  1294.         setFiltriConnettore(sql, tipoDB,
  1295.                 tipoConnettore, endpointType, tipoConnettoreIntegrationManager,
  1296.                 filtroConnettoreTokenPolicy, filtroConnettoreEndpoint, filtroConnettoreKeystore, filtroConnettoreDebug,
  1297.                 CostantiDB.SERVIZI_APPLICATIVI);
  1298.         sqlQueryObject.addWhereExistsCondition(false, sql);
  1299.        
  1300.     }
  1301.     public static void setFiltriConnettoreErogazione(ISQLQueryObject sqlQueryObject, String tipoDB,
  1302.             TipiConnettore tipoConnettore, String endpointType, boolean tipoConnettoreIntegrationManager,
  1303.             String filtroConnettoreTokenPolicy, String filtroConnettoreEndpoint, String filtroConnettoreKeystore, String filtroConnettoreDebug) throws Exception {

  1304.         String aliasMAPPING_EROGAZIONE_PA = "c_map";
  1305.         String aliasPORTE_APPLICATIVE = "c_pa";
  1306.         String aliasPORTE_APPLICATIVE_SA = "c_pasa";
  1307.         String aliasSERVIZI_APPLICATIVI = "c_sa";
  1308.        
  1309.         ISQLQueryObject sql = SQLObjectFactory.createSQLQueryObject(tipoDB);
  1310.         sql.addFromTable(CostantiDB.MAPPING_EROGAZIONE_PA, aliasMAPPING_EROGAZIONE_PA);
  1311.         sql.addFromTable(CostantiDB.PORTE_APPLICATIVE, aliasPORTE_APPLICATIVE);
  1312.         sql.addFromTable(CostantiDB.PORTE_APPLICATIVE_SA, aliasPORTE_APPLICATIVE_SA);
  1313.         sql.addFromTable(CostantiDB.SERVIZI_APPLICATIVI, aliasSERVIZI_APPLICATIVI);
  1314.         sql.addFromTable(CostantiDB.CONNETTORI);
  1315.         sql.setANDLogicOperator(true);
  1316.         sql.addWhereCondition(aliasMAPPING_EROGAZIONE_PA+".id_erogazione="+CostantiDB.SERVIZI+".id");
  1317.         sql.addWhereCondition(aliasMAPPING_EROGAZIONE_PA+".id_porta="+aliasPORTE_APPLICATIVE+".id");
  1318.         sql.addWhereCondition(aliasPORTE_APPLICATIVE_SA+".id_porta="+aliasPORTE_APPLICATIVE+".id");
  1319.         sql.addWhereCondition(aliasPORTE_APPLICATIVE_SA+".id_servizio_applicativo="+aliasSERVIZI_APPLICATIVI+".id");
  1320.         sql.addWhereCondition(aliasSERVIZI_APPLICATIVI+".id_connettore_inv="+CostantiDB.CONNETTORI+".id");
  1321.         setFiltriConnettore(sql, tipoDB,
  1322.                 tipoConnettore, endpointType, tipoConnettoreIntegrationManager,
  1323.                 filtroConnettoreTokenPolicy, filtroConnettoreEndpoint, filtroConnettoreKeystore, filtroConnettoreDebug,
  1324.                 aliasSERVIZI_APPLICATIVI);
  1325.         sqlQueryObject.addWhereExistsCondition(false, sql);
  1326.        
  1327.     }
  1328.     public static void setFiltriConnettoreFruizione(ISQLQueryObject sqlQueryObject, String tipoDB,
  1329.             TipiConnettore tipoConnettore, String endpointType, boolean tipoConnettoreIntegrationManager,
  1330.             String filtroConnettoreTokenPolicy, String filtroConnettoreEndpoint, String filtroConnettoreKeystore, String filtroConnettoreDebug) throws Exception {
  1331.        
  1332.         ISQLQueryObject sqlConnettoreDefault = SQLObjectFactory.createSQLQueryObject(tipoDB);
  1333.         sqlConnettoreDefault.addFromTable(CostantiDB.CONNETTORI);
  1334.         sqlConnettoreDefault.setANDLogicOperator(true);
  1335.         sqlConnettoreDefault.addWhereCondition(CostantiDB.SERVIZI_FRUITORI+".id_connettore="+CostantiDB.CONNETTORI+".id");
  1336.         setFiltriConnettore(sqlConnettoreDefault, tipoDB,
  1337.                 tipoConnettore, endpointType, false,
  1338.                 filtroConnettoreTokenPolicy, filtroConnettoreEndpoint, filtroConnettoreKeystore, filtroConnettoreDebug,
  1339.                 null);
  1340.        
  1341.         ISQLQueryObject sqlGruppiConnettoreRidefinito = SQLObjectFactory.createSQLQueryObject(tipoDB);
  1342.         sqlGruppiConnettoreRidefinito.addFromTable(CostantiDB.SERVIZI_FRUITORI_AZIONI);
  1343.         sqlGruppiConnettoreRidefinito.addFromTable(CostantiDB.CONNETTORI);
  1344.         sqlGruppiConnettoreRidefinito.setANDLogicOperator(true);
  1345.         sqlGruppiConnettoreRidefinito.addWhereCondition(CostantiDB.SERVIZI_FRUITORI_AZIONI+".id_fruizione="+CostantiDB.SERVIZI_FRUITORI+".id");
  1346.         sqlGruppiConnettoreRidefinito.addWhereCondition(CostantiDB.SERVIZI_FRUITORI_AZIONI+".id_connettore="+CostantiDB.CONNETTORI+".id");
  1347.         setFiltriConnettore(sqlGruppiConnettoreRidefinito, tipoDB,
  1348.                 tipoConnettore, endpointType, false,
  1349.                 filtroConnettoreTokenPolicy, filtroConnettoreEndpoint, filtroConnettoreKeystore, filtroConnettoreDebug,
  1350.                 null);
  1351.        
  1352.         sqlQueryObject.addWhereCondition(false,
  1353.                 sqlConnettoreDefault.getWhereExistsCondition(false, sqlConnettoreDefault),
  1354.                 sqlConnettoreDefault.getWhereExistsCondition(false, sqlGruppiConnettoreRidefinito));
  1355.        
  1356.     }
  1357.     private static void setFiltriConnettore(ISQLQueryObject sqlQueryObject, String tipoDB,
  1358.             TipiConnettore tipoConnettore, String endpointType, boolean tipoConnettoreIntegrationManager,
  1359.             String filtroConnettoreTokenPolicy, String filtroConnettoreEndpoint, String filtroConnettoreKeystore, String filtroConnettoreDebug,
  1360.             String aliasTabellaServiziApplicativi) throws Exception {
  1361.        
  1362.         // NOTA: logica inserita anche in PorteApplicativeHelper.applicaFiltriRicercaConnettoriMultipli
  1363.        
  1364.         boolean setEndpointtype = false;
  1365.        
  1366.         if(endpointType!=null) {
  1367.             sqlQueryObject.addWhereLikeCondition(CostantiDB.CONNETTORI+".endpointtype", endpointType, false, false, false);
  1368.             setEndpointtype=true;
  1369.         }
  1370.         else if(tipoConnettore!=null) {
  1371.             if(TipiConnettore.CUSTOM.equals(tipoConnettore)) {
  1372.                 List<String> tipiConosciuti = new ArrayList<>();
  1373.                 TipiConnettore[] tipi = TipiConnettore.values();
  1374.                 for (TipiConnettore tipiConnettore : tipi) {
  1375.                     tipiConosciuti.add(tipiConnettore.getNome());
  1376.                 }
  1377.                 ISQLQueryObject sql = SQLObjectFactory.createSQLQueryObject(tipoDB);
  1378.                 sql.addFromTable(CostantiDB.CONNETTORI);
  1379.                 sql.setANDLogicOperator(true);
  1380.                 sql.setNOTBeforeConditions(true);
  1381.                 sql.addWhereINCondition(CostantiDB.CONNETTORI+".endpointtype", true, tipiConosciuti.toArray(new String[1]));
  1382.                 setEndpointtype=true;
  1383.                 sqlQueryObject.addWhereCondition(sql.createSQLConditions());
  1384.             }
  1385.         }
  1386.        
  1387.         if(tipoConnettoreIntegrationManager) {
  1388.             sqlQueryObject.addWhereLikeCondition(aliasTabellaServiziApplicativi+".getmsginv", CostantiDB.STATO_FUNZIONALITA_ABILITATO, false, false, false);
  1389.         }
  1390.        
  1391.         if(filtroConnettoreTokenPolicy!=null) {
  1392.             sqlQueryObject.addWhereLikeCondition(CostantiDB.CONNETTORI+".token_policy", filtroConnettoreTokenPolicy, false, false, false);
  1393.         }
  1394.        
  1395.         if(filtroConnettoreEndpoint!=null) {
  1396.             List<String> query = new ArrayList<>();
  1397.             if((tipoConnettore==null || TipiConnettore.HTTP.equals(tipoConnettore))) {
  1398.                 query.add(sqlQueryObject.getWhereLikeCondition(CostantiDB.CONNETTORI+".url", filtroConnettoreEndpoint, LikeConfig.contains(true)));
  1399.             }
  1400.             if((tipoConnettore==null || TipiConnettore.HTTPS.equals(tipoConnettore))) {
  1401.                 ISQLQueryObject exists = buildSQLQueryObjectConnettoreCustomPropertyContains(tipoDB, CostantiDB.CONNETTORE_HTTP_LOCATION, filtroConnettoreEndpoint);
  1402.                 query.add(sqlQueryObject.getWhereExistsCondition(false, exists));
  1403.             }
  1404.             //if((tipoConnettore==null || TipiConnettore.FILE.equals(tipoConnettore))) {
  1405.             if(tipoConnettore!=null && TipiConnettore.FILE.equals(tipoConnettore)) {
  1406.                 ISQLQueryObject existsRequest = buildSQLQueryObjectConnettoreCustomPropertyContains(tipoDB, CostantiDB.CONNETTORE_FILE_REQUEST_OUTPUT_FILE, filtroConnettoreEndpoint);
  1407.                 query.add(sqlQueryObject.getWhereExistsCondition(false, existsRequest));
  1408.                 ISQLQueryObject existsRequestHeader = buildSQLQueryObjectConnettoreCustomPropertyContains(tipoDB, CostantiDB.CONNETTORE_FILE_REQUEST_OUTPUT_FILE_HEADERS, filtroConnettoreEndpoint);
  1409.                 query.add(sqlQueryObject.getWhereExistsCondition(false, existsRequestHeader));
  1410.                 ISQLQueryObject existsResponse = buildSQLQueryObjectConnettoreCustomPropertyContains(tipoDB, CostantiDB.CONNETTORE_FILE_RESPONSE_INPUT_FILE, filtroConnettoreEndpoint);
  1411.                 query.add(sqlQueryObject.getWhereExistsCondition(false, existsResponse));
  1412.                 ISQLQueryObject existsResponseHeader = buildSQLQueryObjectConnettoreCustomPropertyContains(tipoDB, CostantiDB.CONNETTORE_FILE_RESPONSE_INPUT_FILE_HEADERS, filtroConnettoreEndpoint);
  1413.                 query.add(sqlQueryObject.getWhereExistsCondition(false, existsResponseHeader));
  1414.             }
  1415.             //if((tipoConnettore==null || TipiConnettore.JMS.equals(tipoConnettore))) {
  1416.             if(tipoConnettore!=null && TipiConnettore.JMS.equals(tipoConnettore)) {
  1417.                 query.add(sqlQueryObject.getWhereLikeCondition(CostantiDB.CONNETTORI+".nome", filtroConnettoreEndpoint, LikeConfig.contains(true)));
  1418.                 query.add(sqlQueryObject.getWhereLikeCondition(CostantiDB.CONNETTORI+".provurl", filtroConnettoreEndpoint, LikeConfig.contains(true)));
  1419.                 query.add(sqlQueryObject.getWhereLikeCondition(CostantiDB.CONNETTORI+".connection_factory", filtroConnettoreEndpoint, LikeConfig.contains(true)));
  1420.                 query.add(sqlQueryObject.getWhereLikeCondition(CostantiDB.CONNETTORI+".initcont", filtroConnettoreEndpoint, LikeConfig.contains(true)));
  1421.                 query.add(sqlQueryObject.getWhereLikeCondition(CostantiDB.CONNETTORI+".urlpkg", filtroConnettoreEndpoint, LikeConfig.contains(true)));
  1422.             }
  1423.             if(!query.isEmpty()) {
  1424.                 sqlQueryObject.addWhereCondition(false, query.toArray(new String[1]));
  1425.                 if(!setEndpointtype) {
  1426.                     sqlQueryObject.addWhereCondition(CostantiDB.CONNETTORI+".endpointtype <> '"+TipiConnettore.DISABILITATO.getNome()+"'");
  1427.                 }
  1428.             }
  1429.         }
  1430.        
  1431.         if(filtroConnettoreKeystore!=null &&
  1432.                 (tipoConnettore==null || TipiConnettore.HTTPS.equals(tipoConnettore))
  1433.                 ) {
  1434.             ISQLQueryObject existsKeystore = buildSQLQueryObjectConnettoreCustomPropertyContains(tipoDB, CostantiDB.CONNETTORE_HTTPS_KEY_STORE_LOCATION, filtroConnettoreKeystore);
  1435.             ISQLQueryObject existsTruststore = buildSQLQueryObjectConnettoreCustomPropertyContains(tipoDB, CostantiDB.CONNETTORE_HTTPS_TRUST_STORE_LOCATION, filtroConnettoreKeystore);
  1436.             sqlQueryObject.addWhereCondition(false,
  1437.                     sqlQueryObject.getWhereExistsCondition(false, existsKeystore),
  1438.                     sqlQueryObject.getWhereExistsCondition(false, existsTruststore)
  1439.                     );
  1440.         }
  1441.        
  1442.         if(filtroConnettoreDebug!=null) {
  1443.             if(Filtri.FILTRO_CONNETTORE_DEBUG_VALORE_ABILITATO.equals(filtroConnettoreDebug)) {
  1444.                 sqlQueryObject.addWhereCondition(CostantiDB.CONNETTORI+".debug="+CostantiDB.TRUE);
  1445.             }
  1446.             else if(Filtri.FILTRO_CONNETTORE_DEBUG_VALORE_DISABILITATO.equals(filtroConnettoreDebug)) {
  1447.                 sqlQueryObject.addWhereCondition(CostantiDB.CONNETTORI+".debug="+CostantiDB.FALSE);
  1448.             }
  1449.         }
  1450.        
  1451.     }
  1452.     private static ISQLQueryObject buildSQLQueryObjectConnettoreCustomPropertyContains(String tipoDB, String nomeProprieta, String valoreProprieta) throws Exception {
  1453.         ISQLQueryObject sql = SQLObjectFactory.createSQLQueryObject(tipoDB);
  1454.         sql.addFromTable(CostantiDB.CONNETTORI_CUSTOM);
  1455.         sql.setANDLogicOperator(true);
  1456.         sql.addWhereCondition(CostantiDB.CONNETTORI_CUSTOM+".id_connettore="+CostantiDB.CONNETTORI+".id");
  1457.         sql.addWhereLikeCondition(CostantiDB.CONNETTORI_CUSTOM+".name", nomeProprieta, false, false, false);
  1458.         sql.addWhereLikeCondition(CostantiDB.CONNETTORI_CUSTOM+".value", valoreProprieta, LikeConfig.contains(true));
  1459.         return sql;
  1460.     }
  1461.    
  1462.    
  1463.    
  1464.    
  1465.     public static void setFiltriModIApplicativi(ISQLQueryObject sqlQueryObject, String tipoDB,
  1466.             Boolean filtroModISicurezzaMessaggio,
  1467.             String filtroModIKeystorePath, String filtroModIKeystoreSubject, String filtroModIKeystoreIssuer,
  1468.             Boolean filtroModISicurezzaToken,
  1469.             String filtroModITokenPolicy, String filtroModITokenClientId,
  1470.             String filtroModIAudience,
  1471.             boolean checkCredenzialiBase) throws Exception {
  1472.        
  1473.         ProprietariProtocolProperty proprietario = ProprietariProtocolProperty.SERVIZIO_APPLICATIVO;
  1474.         String tabellaDB =  CostantiDB.SERVIZI_APPLICATIVI ;
  1475.        
  1476.         List<ISQLQueryObject> listSqlQueryProtocolProperties = new ArrayList<>();
  1477.        
  1478.         if(filtroModISicurezzaMessaggio!=null) {
  1479.             ISQLQueryObject sql = buildSQLQueryObjectProtocolProperties(proprietario, tabellaDB,
  1480.                     tipoDB, CostantiDB.MODIPA_SICUREZZA_MESSAGGIO , null, null, filtroModISicurezzaMessaggio);
  1481.             listSqlQueryProtocolProperties.add(sql);
  1482.         }
  1483.        
  1484.         if(filtroModIKeystorePath!=null) {
  1485.             ISQLQueryObject sql = buildSQLQueryObjectProtocolProperties(proprietario, tabellaDB,
  1486.                     tipoDB, CostantiDB.MODIPA_KEYSTORE_PATH, null, filtroModIKeystorePath, null);
  1487.             listSqlQueryProtocolProperties.add(sql);
  1488.         }
  1489.        
  1490.         if(filtroModIKeystoreSubject!=null) {
  1491.             ISQLQueryObject sql = buildSQLQueryObjectProtocolProperties(proprietario, tabellaDB,
  1492.                     tipoDB, CostantiDB.MODIPA_KEY_CN_SUBJECT, null, filtroModIKeystoreSubject, null);
  1493.             listSqlQueryProtocolProperties.add(sql);
  1494.         }
  1495.        
  1496.         if(filtroModIKeystoreIssuer!=null) {
  1497.             ISQLQueryObject sql = buildSQLQueryObjectProtocolProperties(proprietario, tabellaDB,
  1498.                     tipoDB, CostantiDB.MODIPA_KEY_CN_ISSUER, null, filtroModIKeystoreIssuer, null);
  1499.             listSqlQueryProtocolProperties.add(sql);
  1500.         }
  1501.        
  1502.         if(filtroModISicurezzaToken!=null) {
  1503.             ISQLQueryObject sql = buildSQLQueryObjectProtocolProperties(proprietario, tabellaDB,
  1504.                     tipoDB, CostantiDB.MODIPA_SICUREZZA_TOKEN , null, null, filtroModISicurezzaToken);
  1505.             listSqlQueryProtocolProperties.add(sql);
  1506.         }
  1507.        
  1508.         if(filtroModITokenPolicy!=null) {
  1509.             ISQLQueryObject sql = buildSQLQueryObjectProtocolProperties(proprietario, tabellaDB,
  1510.                     tipoDB, CostantiDB.MODIPA_SICUREZZA_TOKEN_POLICY, null, filtroModITokenPolicy, null);
  1511.             listSqlQueryProtocolProperties.add(sql);            
  1512.         }
  1513.        
  1514.         if(filtroModITokenClientId!=null) {
  1515.             ISQLQueryObject sql = buildSQLQueryObjectProtocolProperties(proprietario, tabellaDB,
  1516.                     tipoDB, CostantiDB.MODIPA_SICUREZZA_TOKEN_CLIENT_ID, null, filtroModITokenClientId, null);
  1517.             listSqlQueryProtocolProperties.add(sql);
  1518.         }
  1519.        
  1520.         if(filtroModIAudience!=null) {
  1521.             ISQLQueryObject sql = buildSQLQueryObjectProtocolProperties(proprietario, tabellaDB,
  1522.                     tipoDB, CostantiDB.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_RISPOSTA_AUDIENCE , null, filtroModIAudience, null);
  1523.             listSqlQueryProtocolProperties.add(sql);
  1524.         }
  1525.        
  1526.        
  1527.        
  1528.         if(checkCredenzialiBase &&
  1529.                 (filtroModIKeystoreSubject!=null || filtroModIKeystoreIssuer!=null || filtroModITokenClientId!=null)) {
  1530.            
  1531.             ISQLQueryObject sqlOr = sqlQueryObject.newSQLQueryObject();
  1532.             sqlOr.addFromTable(CostantiDB.SERVIZI_APPLICATIVI);
  1533.             sqlOr.setANDLogicOperator(false);
  1534.            
  1535.             // ramo modi
  1536.             ISQLQueryObject sqlModi = sqlQueryObject.newSQLQueryObject();
  1537.             sqlModi.setANDLogicOperator(true);
  1538.             for (ISQLQueryObject sql : listSqlQueryProtocolProperties) {
  1539.                 sqlModi.addWhereExistsCondition(false, sql);
  1540.             }
  1541.             sqlOr.addWhereCondition(sqlModi.createSQLConditions());
  1542.            
  1543.             // ramo credenzialiBase
  1544.             ISQLQueryObject sqlCredenzialiBase = sqlQueryObject.newSQLQueryObject();
  1545.             sqlCredenzialiBase.setANDLogicOperator(true);
  1546.             String ssl = "ssl";// --> org.openspcoop2.core.config.constants.CredenzialeTipo.SSL.toString();
  1547.             String token = "token";// --> org.openspcoop2.core.config.constants.CredenzialeTipo.TOKEN.toString();
  1548.             if(filtroModITokenClientId!=null) {
  1549.                 sqlCredenzialiBase.addWhereCondition(false,
  1550.                         CostantiDB.SERVIZI_APPLICATIVI+".tipoauth = '"+token+"'",
  1551.                         CostantiDB.SERVIZI_APPLICATIVI+".tipoauth = '"+ssl+"' AND "+CostantiDB.SERVIZI_APPLICATIVI+".token_policy IS NOT NULL");
  1552.             }
  1553.             else {
  1554.                 sqlCredenzialiBase.addWhereCondition(CostantiDB.SERVIZI_APPLICATIVI+".tipoauth = '"+ssl+"'");
  1555.             }
  1556.             if(filtroModITokenClientId!=null) {
  1557.                 sqlCredenzialiBase.addWhereLikeCondition(CostantiDB.SERVIZI_APPLICATIVI+".utente",
  1558.                         filtroModITokenClientId, LikeConfig.contains(true,true));
  1559.             }
  1560.             if(filtroModIKeystoreSubject!=null) {
  1561.                 sqlCredenzialiBase.addWhereCondition(false,
  1562.                         sqlQueryObject.getWhereLikeCondition(CostantiDB.SERVIZI_APPLICATIVI+".cn_subject", filtroModIKeystoreSubject,
  1563.                                 LikeConfig.contains(true,true)),
  1564.                         sqlQueryObject.getWhereLikeCondition(CostantiDB.SERVIZI_APPLICATIVI+".subject", filtroModIKeystoreSubject,
  1565.                                 LikeConfig.contains(true,true)));
  1566.             }
  1567.             if(filtroModIKeystoreIssuer!=null) {
  1568.                 sqlCredenzialiBase.addWhereCondition(false,
  1569.                         sqlQueryObject.getWhereLikeCondition(CostantiDB.SERVIZI_APPLICATIVI+".cn_issuer", filtroModIKeystoreIssuer,
  1570.                                 LikeConfig.contains(true,true)),
  1571.                         sqlQueryObject.getWhereLikeCondition(CostantiDB.SERVIZI_APPLICATIVI+".issuer", filtroModIKeystoreIssuer,
  1572.                                 LikeConfig.contains(true,true)));
  1573.             }
  1574.             sqlOr.addWhereCondition(sqlCredenzialiBase.createSQLConditions());
  1575.            
  1576.             sqlQueryObject.addWhereCondition(sqlOr.createSQLConditions());
  1577.            
  1578.         }
  1579.         else {
  1580.        
  1581.             if(!listSqlQueryProtocolProperties.isEmpty()) {
  1582.                 for (ISQLQueryObject sql : listSqlQueryProtocolProperties) {
  1583.                     sqlQueryObject.addWhereExistsCondition(false, sql);
  1584.                 }
  1585.             }
  1586.            
  1587.         }
  1588.        
  1589.     }
  1590.    
  1591.     public static void setFiltriModIErogazione(ISQLQueryObject sqlQueryObject, String tipoDB,
  1592.             String filtroModISicurezzaCanale, String filtroModISicurezzaMessaggio,
  1593.             String filtroModISorgenteToken,
  1594.             Boolean filtroModIDigestRichiesta, String filtroModIInfoUtente,
  1595.             String filtroModIKeystore, String filtroModIAudience) throws Exception {
  1596.         setFiltriModIErogazioneFruizione(sqlQueryObject, tipoDB,
  1597.                 filtroModISicurezzaCanale, filtroModISicurezzaMessaggio,
  1598.                 filtroModISorgenteToken,
  1599.                 filtroModIDigestRichiesta, filtroModIInfoUtente,
  1600.                 filtroModIKeystore, filtroModIAudience,
  1601.                 true);
  1602.     }
  1603.     public static void setFiltriModIFruizione(ISQLQueryObject sqlQueryObject, String tipoDB,
  1604.             String filtroModISicurezzaCanale, String filtroModISicurezzaMessaggio,
  1605.             String filtroModISorgenteToken,
  1606.             Boolean filtroModIDigestRichiesta, String filtroModIInfoUtente,
  1607.             String filtroModIKeystore, String filtroModIAudience) throws Exception {
  1608.         setFiltriModIErogazioneFruizione(sqlQueryObject, tipoDB,
  1609.                 filtroModISicurezzaCanale, filtroModISicurezzaMessaggio,
  1610.                 filtroModISorgenteToken,
  1611.                 filtroModIDigestRichiesta, filtroModIInfoUtente,
  1612.                 filtroModIKeystore, filtroModIAudience,
  1613.                 false);
  1614.     }
  1615.     private static void setFiltriModIErogazioneFruizione(ISQLQueryObject sqlQueryObject, String tipoDB,
  1616.             String filtroModISicurezzaCanale, String filtroModISicurezzaMessaggio,
  1617.             String filtroModISorgenteToken,
  1618.             Boolean filtroModIDigestRichiesta, String filtroModIInfoUtente,
  1619.             String filtroModIKeystore, String filtroModIAudience,
  1620.             boolean erogazione) throws Exception {
  1621.        
  1622.         setFiltriModI(sqlQueryObject, tipoDB,
  1623.                 filtroModISicurezzaCanale, filtroModISicurezzaMessaggio,
  1624.                 filtroModISorgenteToken,
  1625.                 filtroModIDigestRichiesta, filtroModIInfoUtente);
  1626.        
  1627.         ProprietariProtocolProperty proprietario = erogazione ? ProprietariProtocolProperty.ACCORDO_SERVIZIO_PARTE_SPECIFICA : ProprietariProtocolProperty.FRUITORE;
  1628.         String tabellaDB =  erogazione ? CostantiDB.SERVIZI : CostantiDB.SERVIZI_FRUITORI ;
  1629.        
  1630.         if(filtroModIKeystore!=null) {
  1631.            
  1632.             List<String> query = new ArrayList<>();
  1633.            
  1634.             ISQLQueryObject sqlAccordoKeystore = buildSQLQueryObjectProtocolProperties(proprietario, tabellaDB,
  1635.                     tipoDB, CostantiDB.MODIPA_KEYSTORE_PATH, null, filtroModIKeystore, null);
  1636.             query.add(sqlQueryObject.getWhereExistsCondition(false, sqlAccordoKeystore));
  1637.            
  1638.             ISQLQueryObject sqlAccordoTruststore = buildSQLQueryObjectProtocolProperties(proprietario, tabellaDB,
  1639.                     tipoDB, CostantiDB.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CERTIFICATI_TRUSTSTORE_PATH, null, filtroModIKeystore, null);
  1640.             query.add(sqlQueryObject.getWhereExistsCondition(false, sqlAccordoTruststore));
  1641.            
  1642.             ISQLQueryObject sqlAccordoTruststoreCrl = buildSQLQueryObjectProtocolProperties(proprietario, tabellaDB,
  1643.                     tipoDB, CostantiDB.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CERTIFICATI_TRUSTSTORE_CRLS, null, filtroModIKeystore, null);
  1644.             query.add(sqlQueryObject.getWhereExistsCondition(false, sqlAccordoTruststoreCrl));
  1645.            
  1646.             ISQLQueryObject sqlAccordoTruststoreSsl = buildSQLQueryObjectProtocolProperties(proprietario, tabellaDB,
  1647.                     tipoDB, CostantiDB.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_SSL_TRUSTSTORE_PATH, null, filtroModIKeystore, null);
  1648.             query.add(sqlQueryObject.getWhereExistsCondition(false, sqlAccordoTruststoreSsl));
  1649.                        
  1650.             if(!query.isEmpty()) {
  1651.                 sqlQueryObject.addWhereCondition(false, query.toArray(new String[1]));
  1652.             }
  1653.         }
  1654.        
  1655.         if(filtroModIAudience!=null) {
  1656.            
  1657.             ISQLQueryObject sqlAudience = buildSQLQueryObjectProtocolProperties(proprietario, tabellaDB,
  1658.                     tipoDB, CostantiDB.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_RICHIESTA_AUDIENCE , null, filtroModIAudience, null);
  1659.             sqlQueryObject.addWhereExistsCondition(false, sqlAudience);
  1660.            
  1661.         }
  1662.        
  1663.     }
  1664.     public static void setFiltriModI(ISQLQueryObject sqlQueryObject, String tipoDB,
  1665.             String filtroModISicurezzaCanale, String filtroModISicurezzaMessaggio,
  1666.             String filtroModISorgenteToken,
  1667.             Boolean filtroModIDigestRichiesta, String filtroModIInfoUtente) throws Exception {
  1668.        
  1669.         if(filtroModISicurezzaCanale!=null) {
  1670.             ISQLQueryObject sql = buildSQLQueryObjectProtocolProperties(ProprietariProtocolProperty.ACCORDO_SERVIZIO_PARTE_COMUNE, CostantiDB.ACCORDI,
  1671.                     tipoDB, CostantiDB.MODIPA_PROFILO_SICUREZZA_CANALE, filtroModISicurezzaCanale, null, null);
  1672.             sqlQueryObject.addWhereExistsCondition(false, sql);
  1673.         }
  1674.         if(filtroModISicurezzaMessaggio!=null) {
  1675.            
  1676.             List<String> query = new ArrayList<>();
  1677.            
  1678.             ISQLQueryObject sqlAccordoSec = buildSQLQueryObjectProtocolProperties(ProprietariProtocolProperty.ACCORDO_SERVIZIO_PARTE_COMUNE, CostantiDB.ACCORDI,
  1679.                     tipoDB, CostantiDB.MODIPA_PROFILO_SICUREZZA_MESSAGGIO, filtroModISicurezzaMessaggio, null, null);
  1680.             query.add(sqlQueryObject.getWhereExistsCondition(false, sqlAccordoSec));
  1681.            
  1682.             addRestCondition(query, sqlQueryObject, tipoDB, CostantiDB.MODIPA_PROFILO_SICUREZZA_MESSAGGIO, filtroModISicurezzaMessaggio, null);
  1683.            
  1684.             addSoapCondition(query, sqlQueryObject, tipoDB, CostantiDB.MODIPA_PROFILO_SICUREZZA_MESSAGGIO, filtroModISicurezzaMessaggio, null);
  1685.            
  1686.             if(!query.isEmpty()) {
  1687.                 sqlQueryObject.addWhereCondition(false, query.toArray(new String[1]));
  1688.             }
  1689.         }
  1690.         if(filtroModISorgenteToken!=null) {
  1691.            
  1692.             List<String> query = new ArrayList<>();
  1693.            
  1694.             ISQLQueryObject sqlAccordoSec = buildSQLQueryObjectProtocolProperties(ProprietariProtocolProperty.ACCORDO_SERVIZIO_PARTE_COMUNE, CostantiDB.ACCORDI,
  1695.                     tipoDB, CostantiDB.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_SORGENTE_TOKEN_IDAUTH, filtroModISorgenteToken, null, null);
  1696.             query.add(sqlQueryObject.getWhereExistsCondition(false, sqlAccordoSec));
  1697.            
  1698.             addRestCondition(query, sqlQueryObject, tipoDB, CostantiDB.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_SORGENTE_TOKEN_IDAUTH, filtroModISorgenteToken, null);
  1699.            
  1700.             addSoapCondition(query, sqlQueryObject, tipoDB, CostantiDB.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_SORGENTE_TOKEN_IDAUTH, filtroModISorgenteToken, null);
  1701.            
  1702.             if(!query.isEmpty()) {
  1703.                 sqlQueryObject.addWhereCondition(false, query.toArray(new String[1]));
  1704.             }
  1705.         }
  1706.         if(filtroModIDigestRichiesta!=null) {
  1707.            
  1708.             List<String> query = new ArrayList<>();
  1709.            
  1710.             ISQLQueryObject sqlAccordoSec = buildSQLQueryObjectProtocolProperties(ProprietariProtocolProperty.ACCORDO_SERVIZIO_PARTE_COMUNE, CostantiDB.ACCORDI,
  1711.                     tipoDB, CostantiDB.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_RISPOSTA_REQUEST_DIGEST, null, null, filtroModIDigestRichiesta);
  1712.             query.add(sqlQueryObject.getWhereExistsCondition(false, sqlAccordoSec));
  1713.            
  1714.             addRestCondition(query, sqlQueryObject, tipoDB, CostantiDB.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_RISPOSTA_REQUEST_DIGEST, null, filtroModIDigestRichiesta);
  1715.            
  1716.             addSoapCondition(query, sqlQueryObject, tipoDB, CostantiDB.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_RISPOSTA_REQUEST_DIGEST, null, filtroModIDigestRichiesta);
  1717.            
  1718.             if(!query.isEmpty()) {
  1719.                 sqlQueryObject.addWhereCondition(false, query.toArray(new String[1]));
  1720.             }
  1721.         }
  1722.         if(filtroModIInfoUtente!=null) {
  1723.            
  1724.             List<String> query = new ArrayList<>();
  1725.            
  1726.             boolean enabled = true;
  1727.             ISQLQueryObject sqlAccordoSec = buildSQLQueryObjectProtocolProperties(ProprietariProtocolProperty.ACCORDO_SERVIZIO_PARTE_COMUNE, CostantiDB.ACCORDI,
  1728.                     tipoDB, CostantiDB.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA, null, null, enabled);
  1729.             query.add(sqlQueryObject.getWhereExistsCondition(false, sqlAccordoSec));
  1730.            
  1731.             addRestCondition(query, sqlQueryObject, tipoDB, CostantiDB.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA, null, enabled);
  1732.            
  1733.             addSoapCondition(query, sqlQueryObject, tipoDB, CostantiDB.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA, null, enabled);
  1734.            
  1735.             if(!query.isEmpty()) {
  1736.                 sqlQueryObject.addWhereCondition(false, query.toArray(new String[1]));
  1737.             }
  1738.            

  1739.             query = new ArrayList<>();
  1740.            
  1741.             ISQLQueryObject sqlAccordoSecPattern = buildSQLQueryObjectProtocolProperties(ProprietariProtocolProperty.ACCORDO_SERVIZIO_PARTE_COMUNE, CostantiDB.ACCORDI,
  1742.                     tipoDB, CostantiDB.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_PATTERN, filtroModIInfoUtente, null, null);
  1743.             query.add(sqlQueryObject.getWhereExistsCondition(false, sqlAccordoSecPattern));
  1744.            
  1745.             addRestCondition(query, sqlQueryObject, tipoDB, CostantiDB.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_PATTERN, filtroModIInfoUtente, null);
  1746.            
  1747.             addSoapCondition(query, sqlQueryObject, tipoDB, CostantiDB.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_PATTERN, filtroModIInfoUtente, null);
  1748.            
  1749.             if(!query.isEmpty()) {
  1750.                 sqlQueryObject.addWhereCondition(false, query.toArray(new String[1]));
  1751.             }
  1752.            
  1753.         }
  1754.                
  1755.     }
  1756.     private static void addRestCondition(List<String> query, ISQLQueryObject sqlQueryObject, String tipoDB, String nomeProprieta, String valoreProprieta, Boolean valoreProprietaBoolean) throws Exception {
  1757.         String aliasRISORSE = "m_res";
  1758.         ISQLQueryObject sqlREST = SQLObjectFactory.createSQLQueryObject(tipoDB);
  1759.         sqlREST.addFromTable(CostantiDB.API_RESOURCES, aliasRISORSE);
  1760.         sqlREST.setANDLogicOperator(true);
  1761.         sqlREST.addWhereCondition(aliasRISORSE+".id_accordo="+CostantiDB.ACCORDI+".id");
  1762.         ISQLQueryObject sqlRestSec = buildSQLQueryObjectProtocolProperties(ProprietariProtocolProperty.RESOURCE, aliasRISORSE,
  1763.                 tipoDB, nomeProprieta, valoreProprieta, null, valoreProprietaBoolean);
  1764.         sqlREST.addWhereExistsCondition(false, sqlRestSec);
  1765.         query.add(sqlQueryObject.getWhereExistsCondition(false, sqlREST));
  1766.     }
  1767.     private static void addSoapCondition(List<String> query, ISQLQueryObject sqlQueryObject, String tipoDB, String nomeProprieta, String valoreProprieta, Boolean valoreProprietaBoolean) throws Exception {
  1768.         String aliasPORTTYPES = "m_pt";
  1769.         String aliasOPERATIONS = "m_op";
  1770.         ISQLQueryObject sqlSOAP = SQLObjectFactory.createSQLQueryObject(tipoDB);
  1771.         sqlSOAP.addFromTable(CostantiDB.PORT_TYPE, aliasPORTTYPES);
  1772.         sqlSOAP.addFromTable(CostantiDB.PORT_TYPE_AZIONI, aliasOPERATIONS);
  1773.         sqlSOAP.setANDLogicOperator(true);
  1774.         sqlSOAP.addWhereCondition(aliasPORTTYPES+".id_accordo="+CostantiDB.ACCORDI+".id");
  1775.         sqlSOAP.addWhereCondition(aliasOPERATIONS+".id_port_type="+aliasPORTTYPES+".id");
  1776.         ISQLQueryObject sqlSoapSec = buildSQLQueryObjectProtocolProperties(ProprietariProtocolProperty.OPERATION, aliasOPERATIONS,
  1777.                 tipoDB, nomeProprieta, valoreProprieta, null, valoreProprietaBoolean);
  1778.         sqlSOAP.addWhereExistsCondition(false, sqlSoapSec);
  1779.         query.add(sqlQueryObject.getWhereExistsCondition(false, sqlSOAP));
  1780.     }
  1781.     private static ISQLQueryObject buildSQLQueryObjectProtocolProperties(ProprietariProtocolProperty tipoProprietario, String tabellaProprietario,
  1782.             String tipoDB, String nomeProprieta, String valoreProprietaEquals, String valoreProprietaContains, Boolean valoreProprietaBoolean) throws Exception {
  1783.         ISQLQueryObject sql = SQLObjectFactory.createSQLQueryObject(tipoDB);
  1784.         sql.addFromTable(CostantiDB.PROTOCOL_PROPERTIES);
  1785.         sql.setANDLogicOperator(true);
  1786.         sql.addWhereCondition(CostantiDB.PROTOCOL_PROPERTIES+".id_proprietario="+tabellaProprietario+".id");
  1787.         sql.addWhereLikeCondition(CostantiDB.PROTOCOL_PROPERTIES+".tipo_proprietario", tipoProprietario.name(), false, false, false);
  1788.         sql.addWhereLikeCondition(CostantiDB.PROTOCOL_PROPERTIES+".name", nomeProprieta, false, false, false);
  1789.         if(valoreProprietaContains!=null) {
  1790.             sql.addWhereLikeCondition(CostantiDB.PROTOCOL_PROPERTIES+".value_string", valoreProprietaContains, LikeConfig.contains(true));
  1791.         }
  1792.         else if(valoreProprietaEquals!=null) {
  1793.             sql.addWhereLikeCondition(CostantiDB.PROTOCOL_PROPERTIES+".value_string", valoreProprietaEquals, false, false, false);
  1794.         }
  1795.         if(valoreProprietaBoolean!=null) {
  1796.             if(valoreProprietaBoolean) {
  1797.                 sql.addWhereCondition(CostantiDB.PROTOCOL_PROPERTIES+".value_boolean="+CostantiDB.TRUE);
  1798.             }
  1799.             else {
  1800.                 sql.addWhereCondition(CostantiDB.PROTOCOL_PROPERTIES+".value_boolean="+CostantiDB.FALSE);
  1801.             }
  1802.         }
  1803.         return sql;
  1804.     }
  1805.    
  1806.    
  1807.     public static void setFiltriProprietaApplicativo(ISQLQueryObject sqlQueryObject, String tipoDB,
  1808.             String nomeProprieta, String valoreProprieta) throws Exception {
  1809.         setFiltriProprieta(sqlQueryObject, tipoDB,
  1810.                 ProprietariProtocolProperty.SERVIZIO_APPLICATIVO, null,
  1811.                 nomeProprieta, valoreProprieta);
  1812.     }
  1813.     public static void setFiltriProprietaSoggetto(ISQLQueryObject sqlQueryObject, String tipoDB,
  1814.             String nomeProprieta, String valoreProprieta) throws Exception {
  1815.         setFiltriProprieta(sqlQueryObject, tipoDB,
  1816.                 ProprietariProtocolProperty.SOGGETTO, null,
  1817.                 nomeProprieta, valoreProprieta);
  1818.     }
  1819.     public static void setFiltriProprietaErogazione(ISQLQueryObject sqlQueryObject, String tipoDB,
  1820.             String nomeProprieta, String valoreProprieta) throws Exception {
  1821.        
  1822.         String aliasMAPPING_EROGAZIONE_PA = "c_map";
  1823.         String aliasPORTE_APPLICATIVE = "c_pa";
  1824.        
  1825.         ISQLQueryObject sql = SQLObjectFactory.createSQLQueryObject(tipoDB);
  1826.         sql.addFromTable(CostantiDB.MAPPING_EROGAZIONE_PA, aliasMAPPING_EROGAZIONE_PA);
  1827.         sql.addFromTable(CostantiDB.PORTE_APPLICATIVE, aliasPORTE_APPLICATIVE);
  1828.         sql.setANDLogicOperator(true);
  1829.         sql.addWhereCondition(aliasMAPPING_EROGAZIONE_PA+".id_erogazione="+CostantiDB.SERVIZI+".id");
  1830.         sql.addWhereCondition(aliasMAPPING_EROGAZIONE_PA+".id_porta="+aliasPORTE_APPLICATIVE+".id");
  1831.         setFiltriProprieta(sql, tipoDB,
  1832.                 ProprietariProtocolProperty.ACCORDO_SERVIZIO_PARTE_SPECIFICA, aliasPORTE_APPLICATIVE,
  1833.                 nomeProprieta, valoreProprieta);
  1834.         sqlQueryObject.addWhereExistsCondition(false, sql);
  1835.        
  1836.     }
  1837.     public static void setFiltriProprietaFruizione(ISQLQueryObject sqlQueryObject, String tipoDB,
  1838.             String nomeProprieta, String valoreProprieta) throws Exception {
  1839.        
  1840.         String aliasMAPPING_FRUIZIONE_PD = "c_map";
  1841.         String aliasPORTE_DELEGATE = "c_pd";
  1842.        
  1843.         ISQLQueryObject sql = SQLObjectFactory.createSQLQueryObject(tipoDB);
  1844.         sql.addFromTable(CostantiDB.MAPPING_FRUIZIONE_PD, aliasMAPPING_FRUIZIONE_PD);
  1845.         sql.addFromTable(CostantiDB.PORTE_DELEGATE, aliasPORTE_DELEGATE);
  1846.         sql.setANDLogicOperator(true);
  1847.         sql.addWhereCondition(aliasMAPPING_FRUIZIONE_PD+".id_fruizione="+CostantiDB.SERVIZI_FRUITORI+".id");
  1848.         sql.addWhereCondition(aliasMAPPING_FRUIZIONE_PD+".id_porta="+aliasPORTE_DELEGATE+".id");
  1849.         setFiltriProprieta(sql, tipoDB,
  1850.                 ProprietariProtocolProperty.FRUITORE, aliasPORTE_DELEGATE,
  1851.                 nomeProprieta, valoreProprieta);
  1852.         sqlQueryObject.addWhereExistsCondition(false, sql);
  1853.        
  1854.     }
  1855.     private static void setFiltriProprieta(ISQLQueryObject sqlQueryObject, String tipoDB,
  1856.             ProprietariProtocolProperty tipoProprietario, String tabellaAlias,
  1857.             String nomeProprieta, String valoreProprieta) throws Exception {
  1858.         ISQLQueryObject sql = SQLObjectFactory.createSQLQueryObject(tipoDB);
  1859.         String nomeTabellaPrincipale = null;
  1860.         String nomeTabellaProprieta = null;
  1861.         String colonnaJoin = null;
  1862.         if(ProprietariProtocolProperty.SERVIZIO_APPLICATIVO.equals(tipoProprietario)) {
  1863.             nomeTabellaPrincipale = CostantiDB.SERVIZI_APPLICATIVI;
  1864.             nomeTabellaProprieta = CostantiDB.SERVIZI_APPLICATIVI_PROPS;
  1865.             colonnaJoin = "id_servizio_applicativo";
  1866.         }
  1867.         else if(ProprietariProtocolProperty.SOGGETTO.equals(tipoProprietario)) {
  1868.             nomeTabellaPrincipale = CostantiDB.SOGGETTI;
  1869.             nomeTabellaProprieta = CostantiDB.SOGGETTI_PROPS;
  1870.             colonnaJoin = "id_soggetto";
  1871.         }
  1872.         else if(ProprietariProtocolProperty.ACCORDO_SERVIZIO_PARTE_SPECIFICA.equals(tipoProprietario)) {
  1873.             nomeTabellaPrincipale = tabellaAlias;
  1874.             nomeTabellaProprieta = CostantiDB.PORTE_APPLICATIVE_PROP;
  1875.             colonnaJoin = "id_porta";
  1876.         }
  1877.         else if(ProprietariProtocolProperty.FRUITORE.equals(tipoProprietario)) {
  1878.             nomeTabellaPrincipale = tabellaAlias;
  1879.             nomeTabellaProprieta = CostantiDB.PORTE_DELEGATE_PROP;
  1880.             colonnaJoin = "id_porta";
  1881.         }
  1882.         else {
  1883.             throw new Exception("Tipo proprietario '"+tipoProprietario+"' non gestito");
  1884.         }
  1885.         sql.addFromTable(nomeTabellaProprieta);
  1886.         sql.setANDLogicOperator(true);
  1887.         sql.addWhereCondition(nomeTabellaProprieta+"."+colonnaJoin+"="+nomeTabellaPrincipale+".id");
  1888.         if(nomeProprieta!=null) {
  1889.             sql.addWhereLikeCondition(nomeTabellaProprieta+".nome", nomeProprieta, false, false, false);
  1890.         }
  1891.         if(valoreProprieta!=null) {
  1892.             sql.addWhereLikeCondition(nomeTabellaProprieta+".valore", valoreProprieta, LikeConfig.contains(true));
  1893.         }
  1894.         sqlQueryObject.addWhereExistsCondition(false, sql);
  1895.     }
  1896.    
  1897.    
  1898.    
  1899.     public static void setFiltriConfigurazioneErogazione(ISQLQueryObject sqlQueryObject, String tipoDB,
  1900.             String filtroStatoAPIImpl,
  1901.             String filtroAutenticazioneTokenPolicy,
  1902.             String filtroAutenticazioneTrasporto,
  1903.             String filtroRateLimitingStato,
  1904.             String filtroValidazioneStato,
  1905.             String filtroCacheRispostaStato,
  1906.             String filtroMessageSecurityStato,
  1907.             String filtroMTOMStato,
  1908.             String filtroTrasformazione,
  1909.             String filtroConfigurazioneTransazioni,
  1910.             String filtroCorrelazioneApplicativa,
  1911.             String filtroConfigurazioneDumpTipo,
  1912.             String filtroCORS, String filtroCORSOrigin) throws Exception {
  1913.         _setFiltriConfigurazione(sqlQueryObject, tipoDB,
  1914.                 filtroStatoAPIImpl,
  1915.                 filtroAutenticazioneTokenPolicy,
  1916.                 filtroAutenticazioneTrasporto,
  1917.                 filtroRateLimitingStato,
  1918.                 filtroValidazioneStato,
  1919.                 filtroCacheRispostaStato,
  1920.                 filtroMessageSecurityStato,
  1921.                 filtroMTOMStato,
  1922.                 filtroTrasformazione,
  1923.                 filtroConfigurazioneTransazioni,
  1924.                 filtroCorrelazioneApplicativa,
  1925.                 filtroConfigurazioneDumpTipo,
  1926.                 filtroCORS, filtroCORSOrigin,
  1927.                 true);
  1928.     }
  1929.     public static void setFiltriConfigurazioneFruizione(ISQLQueryObject sqlQueryObject, String tipoDB,
  1930.             String filtroStatoAPIImpl,
  1931.             String filtroAutenticazioneTokenPolicy,
  1932.             String filtroAutenticazioneTrasporto,
  1933.             String filtroRateLimitingStato,
  1934.             String filtroValidazioneStato,
  1935.             String filtroCacheRispostaStato,
  1936.             String filtroMessageSecurityStato,
  1937.             String filtroMTOMStato,
  1938.             String filtroTrasformazione,
  1939.             String filtroConfigurazioneTransazioni,
  1940.             String filtroCorrelazioneApplicativa,
  1941.             String filtroConfigurazioneDumpTipo,
  1942.             String filtroCORS, String filtroCORSOrigin) throws Exception {
  1943.         _setFiltriConfigurazione(sqlQueryObject, tipoDB,
  1944.                 filtroStatoAPIImpl,
  1945.                 filtroAutenticazioneTokenPolicy,
  1946.                 filtroAutenticazioneTrasporto,
  1947.                 filtroRateLimitingStato,
  1948.                 filtroValidazioneStato,
  1949.                 filtroCacheRispostaStato,
  1950.                 filtroMessageSecurityStato,
  1951.                 filtroMTOMStato,
  1952.                 filtroTrasformazione,
  1953.                 filtroConfigurazioneTransazioni,
  1954.                 filtroCorrelazioneApplicativa,
  1955.                 filtroConfigurazioneDumpTipo,
  1956.                 filtroCORS, filtroCORSOrigin,
  1957.                 false);
  1958.     }
  1959.     public static void _setFiltriConfigurazione(ISQLQueryObject sqlQueryObject, String tipoDB,
  1960.             String filtroStatoAPIImpl,
  1961.             String filtroAutenticazioneTokenPolicy,
  1962.             String filtroAutenticazioneTrasporto,
  1963.             String filtroRateLimitingStato,
  1964.             String filtroValidazioneStato,
  1965.             String filtroCacheRispostaStato,
  1966.             String filtroMessageSecurityStato,
  1967.             String filtroMTOMStato,
  1968.             String filtroTrasformazione,
  1969.             String filtroConfigurazioneTransazioni,
  1970.             String filtroCorrelazioneApplicativa,
  1971.             String filtroConfigurazioneDumpTipo,
  1972.             String filtroCORS, String filtroCORSOrigin,
  1973.             boolean erogazioni) throws Exception {

  1974.         String aliasCONFIGPORTA = "conf_p";
  1975.         String aliasCONFIGMAPPING = "conf_m";
  1976.        
  1977.         ISQLQueryObject sql = SQLObjectFactory.createSQLQueryObject(tipoDB);
  1978.         if(erogazioni) {
  1979.             sql.addFromTable(CostantiDB.PORTE_APPLICATIVE, aliasCONFIGPORTA);
  1980.             sql.addFromTable(CostantiDB.MAPPING_EROGAZIONE_PA, aliasCONFIGMAPPING);
  1981.         }
  1982.         else {
  1983.             sql.addFromTable(CostantiDB.PORTE_DELEGATE, aliasCONFIGPORTA);
  1984.             sql.addFromTable(CostantiDB.MAPPING_FRUIZIONE_PD, aliasCONFIGMAPPING);
  1985.         }
  1986.         sql.setANDLogicOperator(true);
  1987.         if(erogazioni) {
  1988.             sql.addWhereCondition(aliasCONFIGMAPPING+".id_erogazione="+CostantiDB.SERVIZI+".id");
  1989.             sql.addWhereCondition(aliasCONFIGMAPPING+".id_porta="+aliasCONFIGPORTA+".id");
  1990.         }
  1991.         else {
  1992.             sql.addWhereCondition(aliasCONFIGMAPPING+".id_fruizione="+CostantiDB.SERVIZI_FRUITORI+".id");
  1993.             sql.addWhereCondition(aliasCONFIGMAPPING+".id_porta="+aliasCONFIGPORTA+".id");
  1994.         }  
  1995.        
  1996.         if(filtroStatoAPIImpl!=null && !"".equals(filtroStatoAPIImpl)) {
  1997.             if(Filtri.FILTRO_CONFIGURAZIONE_STATO_VALORE_ABILITATO.equals(filtroStatoAPIImpl)) {
  1998.                 ISQLQueryObject sqlStato = SQLObjectFactory.createSQLQueryObject(tipoDB);
  1999.                 if(erogazioni) {
  2000.                     sqlStato.addFromTable(CostantiDB.PORTE_APPLICATIVE);
  2001.                 }
  2002.                 else {
  2003.                     sqlStato.addFromTable(CostantiDB.PORTE_DELEGATE);
  2004.                 }
  2005.                 sqlStato.setANDLogicOperator(false);
  2006.                 sqlStato.addWhereLikeCondition(aliasCONFIGPORTA+".stato", "abilitato", false, false, false);
  2007.                 sqlStato.addWhereIsNullCondition(aliasCONFIGPORTA+".stato");
  2008.                 sql.addWhereCondition(sqlStato.createSQLConditions());
  2009.             }
  2010.             else if(Filtri.FILTRO_CONFIGURAZIONE_STATO_VALORE_DISABILITATO.equals(filtroStatoAPIImpl)) {
  2011.                 sql.addWhereLikeCondition(aliasCONFIGPORTA+".stato", "disabilitato", false, false, false);
  2012.             }  
  2013.         }
  2014.        
  2015.         if(filtroAutenticazioneTokenPolicy!=null && !"".equals(filtroAutenticazioneTokenPolicy)) {
  2016.             sql.addWhereLikeCondition(aliasCONFIGPORTA+".token_policy", filtroAutenticazioneTokenPolicy, false, false, false);
  2017.         }
  2018.        
  2019.         if(filtroAutenticazioneTrasporto!=null && !"".equals(filtroAutenticazioneTrasporto)) {
  2020.             sql.addWhereLikeCondition(aliasCONFIGPORTA+".autenticazione", filtroAutenticazioneTrasporto, false, false, false);
  2021.         }
  2022.        
  2023.         if(filtroRateLimitingStato!=null && !"".equals(filtroRateLimitingStato)) {
  2024.             String aliasRT = "rt_c";
  2025.             ISQLQueryObject sqlRT = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2026.             sqlRT.addFromTable(CostantiDB.CONTROLLO_TRAFFICO_ACTIVE_POLICY, aliasRT);
  2027.             sqlRT.addSelectField(aliasRT, "id");
  2028.             sqlRT.setANDLogicOperator(true);
  2029.             sqlRT.addWhereCondition(aliasCONFIGPORTA+".nome_porta="+aliasRT+".filtro_porta");
  2030.             String ruolo = erogazioni ? "applicativa" : "delegata";
  2031.             sqlRT.addWhereLikeCondition(aliasRT+".filtro_ruolo", ruolo, false, false, false);
  2032.             if(Filtri.FILTRO_CONFIGURAZIONE_RATE_LIMITING_STATO_VALORE_ABILITATO.equals(filtroRateLimitingStato)) {
  2033.                 sql.addWhereExistsCondition(false, sqlRT);  
  2034.             }
  2035.             else if(Filtri.FILTRO_CONFIGURAZIONE_RATE_LIMITING_STATO_VALORE_DISABILITATO.equals(filtroRateLimitingStato)) {
  2036.                 sql.addWhereExistsCondition(true, sqlRT);  
  2037.             }
  2038.         }
  2039.        
  2040.         if(filtroValidazioneStato!=null && !"".equals(filtroValidazioneStato)) {
  2041.             if(Filtri.FILTRO_CONFIGURAZIONE_VALIDAZIONE_STATO_VALORE_ABILITATO.equals(filtroValidazioneStato)) {
  2042.                 sql.addWhereIsNotNullCondition(aliasCONFIGPORTA+".validazione_contenuti_stato");
  2043.             }
  2044.             else if(Filtri.FILTRO_CONFIGURAZIONE_VALIDAZIONE_STATO_VALORE_DISABILITATO.equals(filtroValidazioneStato)) {
  2045.                 sql.addWhereIsNullCondition(aliasCONFIGPORTA+".validazione_contenuti_stato");
  2046.             }
  2047.         }
  2048.        
  2049.         if(filtroCacheRispostaStato!=null && !"".equals(filtroCacheRispostaStato)) {
  2050.             if(Filtri.FILTRO_CONFIGURAZIONE_CACHE_RISPOSTA_STATO_VALORE_DISABILITATO.equals(filtroCacheRispostaStato)) {
  2051.                 ISQLQueryObject sqlStato = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2052.                 if(erogazioni) {
  2053.                     sqlStato.addFromTable(CostantiDB.PORTE_APPLICATIVE);
  2054.                 }
  2055.                 else {
  2056.                     sqlStato.addFromTable(CostantiDB.PORTE_DELEGATE);
  2057.                 }
  2058.                 sqlStato.setANDLogicOperator(false);
  2059.                 sqlStato.addWhereLikeCondition(aliasCONFIGPORTA+".response_cache_stato", "disabilitato", false, false, false);
  2060.                 sqlStato.addWhereIsNullCondition(aliasCONFIGPORTA+".response_cache_stato");
  2061.                 sql.addWhereCondition(sqlStato.createSQLConditions());
  2062.             }
  2063.             else if(Filtri.FILTRO_CONFIGURAZIONE_CACHE_RISPOSTA_STATO_VALORE_ABILITATO.equals(filtroCacheRispostaStato)) {
  2064.                 sql.addWhereLikeCondition(aliasCONFIGPORTA+".response_cache_stato", "abilitato", false, false, false);
  2065.             }  
  2066.         }
  2067.        
  2068.         if(filtroMessageSecurityStato!=null && !"".equals(filtroMessageSecurityStato)) {
  2069.             if(Filtri.FILTRO_CONFIGURAZIONE_MESSAGE_SECURITY_VALORE_ABILITATO.equals(filtroMessageSecurityStato) ||
  2070.                     Filtri.FILTRO_CONFIGURAZIONE_MESSAGE_SECURITY_VALORE_DISABILITATO.equals(filtroMessageSecurityStato)) {
  2071.                 ISQLQueryObject sqlStato = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2072.                 if(erogazioni) {
  2073.                     sqlStato.addFromTable(CostantiDB.PORTE_APPLICATIVE);
  2074.                 }
  2075.                 else {
  2076.                     sqlStato.addFromTable(CostantiDB.PORTE_DELEGATE);
  2077.                 }
  2078.                 if(Filtri.FILTRO_CONFIGURAZIONE_MESSAGE_SECURITY_VALORE_ABILITATO.equals(filtroMessageSecurityStato)) {
  2079.                     sqlStato.setANDLogicOperator(false);
  2080.                     sqlStato.addWhereIsNotNullCondition(aliasCONFIGPORTA+".security_request_mode");
  2081.                     sqlStato.addWhereIsNotNullCondition(aliasCONFIGPORTA+".security_response_mode");
  2082.                 }
  2083.                 else {
  2084.                     sqlStato.setANDLogicOperator(true);
  2085.                     sqlStato.addWhereIsNullCondition(aliasCONFIGPORTA+".security_request_mode");
  2086.                     sqlStato.addWhereIsNullCondition(aliasCONFIGPORTA+".security_response_mode");
  2087.                 }
  2088.                 sql.addWhereCondition(sqlStato.createSQLConditions());  
  2089.             }
  2090.             else if(Filtri.FILTRO_CONFIGURAZIONE_MESSAGE_SECURITY_STATO_VALORE_ABILITATO_RICHIESTA.equals(filtroMessageSecurityStato)) {
  2091.                 sql.addWhereIsNotNullCondition(aliasCONFIGPORTA+".security_request_mode");
  2092.             }
  2093.             else if(Filtri.FILTRO_CONFIGURAZIONE_MESSAGE_SECURITY_STATO_VALORE_ABILITATO_RISPOSTA.equals(filtroMessageSecurityStato)) {
  2094.                 sql.addWhereIsNotNullCondition(aliasCONFIGPORTA+".security_response_mode");
  2095.             }
  2096.         }
  2097.        
  2098.         if(filtroMTOMStato!=null && !"".equals(filtroMTOMStato)) {
  2099.             if(Filtri.FILTRO_CONFIGURAZIONE_MTOM_VALORE_ABILITATO.equals(filtroMTOMStato) ||
  2100.                     Filtri.FILTRO_CONFIGURAZIONE_MTOM_VALORE_DISABILITATO.equals(filtroMTOMStato)) {
  2101.                 ISQLQueryObject sqlStato = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2102.                 if(erogazioni) {
  2103.                     sqlStato.addFromTable(CostantiDB.PORTE_APPLICATIVE);
  2104.                 }
  2105.                 else {
  2106.                     sqlStato.addFromTable(CostantiDB.PORTE_DELEGATE);
  2107.                 }
  2108.                 if(Filtri.FILTRO_CONFIGURAZIONE_MTOM_VALORE_ABILITATO.equals(filtroMTOMStato)) {
  2109.                     sqlStato.setANDLogicOperator(false);
  2110.                     sqlStato.addWhereCondition(true,  aliasCONFIGPORTA+".mtom_request_mode is not null", aliasCONFIGPORTA+".mtom_request_mode <> 'disable'");
  2111.                     sqlStato.addWhereCondition(true,  aliasCONFIGPORTA+".mtom_response_mode is not null", aliasCONFIGPORTA+".mtom_response_mode <> 'disable'");
  2112.                 }
  2113.                 else {
  2114.                     sqlStato.setANDLogicOperator(true);
  2115.                     sqlStato.addWhereCondition(false,  aliasCONFIGPORTA+".mtom_request_mode is null", aliasCONFIGPORTA+".mtom_request_mode = 'disable'");
  2116.                     sqlStato.addWhereCondition(false,  aliasCONFIGPORTA+".mtom_response_mode is null", aliasCONFIGPORTA+".mtom_response_mode = 'disable'");
  2117.                 }
  2118.                 sql.addWhereCondition(sqlStato.createSQLConditions());  
  2119.             }
  2120.             else if(Filtri.FILTRO_CONFIGURAZIONE_MTOM_STATO_VALORE_ABILITATO_RICHIESTA.equals(filtroMTOMStato)) {
  2121.                 sql.addWhereCondition(true,  aliasCONFIGPORTA+".mtom_request_mode is not null", aliasCONFIGPORTA+".mtom_request_mode <> 'disable'");
  2122.             }
  2123.             else if(Filtri.FILTRO_CONFIGURAZIONE_MTOM_STATO_VALORE_ABILITATO_RISPOSTA.equals(filtroMTOMStato)) {
  2124.                 sql.addWhereCondition(true,  aliasCONFIGPORTA+".mtom_response_mode is not null", aliasCONFIGPORTA+".mtom_response_mode <> 'disable'");
  2125.             }
  2126.         }
  2127.        
  2128.         if(filtroTrasformazione!=null && !"".equals(filtroTrasformazione)) {        
  2129.             String aliasTRANSFORM = "tra_c";
  2130.             ISQLQueryObject sqlTrasformazione = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2131.             if(erogazioni) {
  2132.                 sqlTrasformazione.addFromTable(CostantiDB.PORTE_APPLICATIVE_TRASFORMAZIONI, aliasTRANSFORM);
  2133.             }
  2134.             else {
  2135.                 sqlTrasformazione.addFromTable(CostantiDB.PORTE_DELEGATE_TRASFORMAZIONI, aliasTRANSFORM);
  2136.             }
  2137.             sqlTrasformazione.addSelectField(aliasTRANSFORM, "id");
  2138.             sqlTrasformazione.setANDLogicOperator(true);
  2139.             sqlTrasformazione.addWhereCondition(aliasCONFIGPORTA+".id="+aliasTRANSFORM+".id_porta");
  2140.             sqlTrasformazione.addWhereLikeCondition(aliasTRANSFORM+".stato", "abilitato", false, false, false);
  2141.             sql.addWhereExistsCondition(Filtri.FILTRO_CONFIGURAZIONE_TRASFORMAZIONE_STATO_VALORE_ABILITATO.equals(filtroTrasformazione) ? false : true, sqlTrasformazione);
  2142.         }
  2143.        
  2144.         if(filtroConfigurazioneTransazioni!=null && !"".equals(filtroConfigurazioneTransazioni)) {
  2145.             addFiltroConfigurazioneTransazioni(tipoDB,
  2146.                     aliasCONFIGPORTA,
  2147.                     filtroConfigurazioneTransazioni, erogazioni,
  2148.                     sql);
  2149.         }
  2150.        
  2151.         if(filtroCorrelazioneApplicativa!=null && !"".equals(filtroCorrelazioneApplicativa)) {
  2152.            
  2153.             // Richiesta
  2154.             String aliasCorrelazioneRichiesta = erogazioni ? CostantiDB.PORTE_APPLICATIVE_CORRELAZIONE : CostantiDB.PORTE_DELEGATE_CORRELAZIONE;
  2155.             ISQLQueryObject sqlCorrelazioneRichiesta = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2156.             sqlCorrelazioneRichiesta.addFromTable(aliasCorrelazioneRichiesta);
  2157.             sqlCorrelazioneRichiesta.setANDLogicOperator(true);
  2158.             sqlCorrelazioneRichiesta.addWhereCondition(aliasCONFIGPORTA+".id="+aliasCorrelazioneRichiesta+".id_porta");
  2159.            
  2160.             // Risposta
  2161.             String aliasCorrelazioneRisposta = erogazioni ? CostantiDB.PORTE_APPLICATIVE_CORRELAZIONE_RISPOSTA : CostantiDB.PORTE_DELEGATE_CORRELAZIONE_RISPOSTA;
  2162.             ISQLQueryObject sqlCorrelazioneRisposta = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2163.             sqlCorrelazioneRisposta.addFromTable(aliasCorrelazioneRisposta);
  2164.             sqlCorrelazioneRisposta.setANDLogicOperator(true);
  2165.             sqlCorrelazioneRisposta.addWhereCondition(aliasCONFIGPORTA+".id="+aliasCorrelazioneRisposta+".id_porta");
  2166.            
  2167.             if(Filtri.FILTRO_CONFIGURAZIONE_CORRELAZIONE_APPLICATIVA_VALORE_ABILITATO.equals(filtroCorrelazioneApplicativa) ||
  2168.                     Filtri.FILTRO_CONFIGURAZIONE_CORRELAZIONE_APPLICATIVA_VALORE_DISABILITATO.equals(filtroCorrelazioneApplicativa)) {
  2169.                                
  2170.                 ISQLQueryObject sqlStato = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2171.                 if(erogazioni) {
  2172.                     sqlStato.addFromTable(CostantiDB.PORTE_APPLICATIVE);
  2173.                 }
  2174.                 else {
  2175.                     sqlStato.addFromTable(CostantiDB.PORTE_DELEGATE);
  2176.                 }
  2177.                 if(Filtri.FILTRO_CONFIGURAZIONE_CORRELAZIONE_APPLICATIVA_VALORE_ABILITATO.equals(filtroCorrelazioneApplicativa)) {
  2178.                     sqlStato.setANDLogicOperator(false);
  2179.                     sqlStato.addWhereExistsCondition(false, sqlCorrelazioneRichiesta);
  2180.                     sqlStato.addWhereExistsCondition(false, sqlCorrelazioneRisposta);
  2181.                 }
  2182.                 else {
  2183.                     sqlStato.setANDLogicOperator(true);
  2184.                     sqlStato.addWhereExistsCondition(true, sqlCorrelazioneRichiesta);
  2185.                     sqlStato.addWhereExistsCondition(true, sqlCorrelazioneRisposta);
  2186.                 }
  2187.                 sql.addWhereCondition(sqlStato.createSQLConditions());  
  2188.             }
  2189.             else if(Filtri.FILTRO_CONFIGURAZIONE_CORRELAZIONE_APPLICATIVA_STATO_VALORE_ABILITATO_RICHIESTA.equals(filtroCorrelazioneApplicativa)) {
  2190.                 sql.addWhereExistsCondition(false, sqlCorrelazioneRichiesta);
  2191.             }
  2192.             else if(Filtri.FILTRO_CONFIGURAZIONE_CORRELAZIONE_APPLICATIVA_STATO_VALORE_ABILITATO_RISPOSTA.equals(filtroCorrelazioneApplicativa)) {
  2193.                 sql.addWhereExistsCondition(false, sqlCorrelazioneRisposta);
  2194.             }
  2195.         }
  2196.        
  2197.         if(filtroConfigurazioneDumpTipo!=null && !"".equals(filtroConfigurazioneDumpTipo)) {
  2198.             addFiltroConfigurazioneDump(tipoDB,
  2199.                     aliasCONFIGPORTA,
  2200.                     filtroConfigurazioneDumpTipo, erogazioni,
  2201.                     sql);
  2202.         }
  2203.        
  2204.         if(filtroCORS!=null && !"".equals(filtroCORS)) {
  2205.             if(Filtri.FILTRO_CONFIGURAZIONE_CORS_TIPO_VALORE_DEFAULT.equals(filtroCORS)) {
  2206.                 sql.addWhereIsNullCondition(aliasCONFIGPORTA+".cors_stato");
  2207.             }
  2208.             else if(Filtri.FILTRO_CONFIGURAZIONE_CORS_TIPO_VALORE_RIDEFINITO_ABILITATO.equals(filtroCORS)) {
  2209.                 sql.addWhereLikeCondition(aliasCONFIGPORTA+".cors_stato", "abilitato", false, false, false);
  2210.                
  2211.                 if(filtroCORSOrigin!=null && !"".equals(filtroCORSOrigin)) {
  2212.                     sql.addWhereLikeCondition(aliasCONFIGPORTA+".cors_allow_origins", filtroCORSOrigin, LikeConfig.contains(true));
  2213.                 }
  2214.             }
  2215.             else if(Filtri.FILTRO_CONFIGURAZIONE_CORS_TIPO_VALORE_RIDEFINITO_DISABILITATO.equals(filtroCORS)) {
  2216.                 sql.addWhereLikeCondition(aliasCONFIGPORTA+".cors_stato", "disabilitato", false, false, false);
  2217.             }
  2218.         }
  2219.        
  2220.         sqlQueryObject.addWhereExistsCondition(false, sql);
  2221.     }
  2222.     public static void addFiltroConfigurazioneTransazioni(String tipoDB,
  2223.             String aliasCONFIGPORTA,
  2224.             String filtroConfigurazioneTransazioni, boolean erogazioni,
  2225.             ISQLQueryObject sqlQueryQuery) throws SQLQueryObjectException {

  2226.         if(Filtri.FILTRO_CONFIGURAZIONE_TRANSAZIONI_VALORE_DEFAULT.equals(filtroConfigurazioneTransazioni)) {
  2227.             sqlQueryQuery.addWhereCondition(aliasCONFIGPORTA+".tracciamento_stato is NULL OR "+aliasCONFIGPORTA+".tracciamento_stato='"+CostantiDB.STATO_FUNZIONALITA_DISABILITATO+"'");
  2228.         }
  2229.         else {
  2230.             sqlQueryQuery.addWhereCondition(aliasCONFIGPORTA+".tracciamento_stato='"+CostantiDB.STATO_FUNZIONALITA_ABILITATO+"'");
  2231.            
  2232.             String aliasTRANSAZIONICONFIGDB = "trans_cdb";
  2233.             ISQLQueryObject sqlDB = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2234.             sqlDB.addFromTable(CostantiDB.TRACCIAMENTO_CONFIGURAZIONE, aliasTRANSAZIONICONFIGDB);
  2235.             sqlDB.addSelectField(aliasTRANSAZIONICONFIGDB, CostantiDB.COLUMN_ID_PROPRIETARIO);
  2236.             sqlDB.setANDLogicOperator(true);
  2237.             sqlDB.addWhereCondition(aliasCONFIGPORTA+".id="+aliasTRANSAZIONICONFIGDB+"."+CostantiDB.COLUMN_ID_PROPRIETARIO);
  2238.             sqlDB.addWhereCondition(aliasTRANSAZIONICONFIGDB+".proprietario='"+
  2239.                     (erogazioni ? CostantiDB.TRACCIAMENTO_CONFIGURAZIONE_PROPRIETARIO_PA : CostantiDB.TRACCIAMENTO_CONFIGURAZIONE_PROPRIETARIO_PD)+"'");    
  2240.             sqlDB.addWhereCondition(aliasTRANSAZIONICONFIGDB+".tipo='"+CostantiDB.TRACCIAMENTO_CONFIGURAZIONE_TIPO_DB+"'");
  2241.            
  2242.             String aliasTRANSAZIONICONFIGFILETRACE = "trans_cft";
  2243.             ISQLQueryObject sqlFileTrace = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2244.             sqlFileTrace.addFromTable(CostantiDB.TRACCIAMENTO_CONFIGURAZIONE, aliasTRANSAZIONICONFIGFILETRACE);
  2245.             sqlFileTrace.addSelectField(aliasTRANSAZIONICONFIGFILETRACE, CostantiDB.COLUMN_ID_PROPRIETARIO);
  2246.             sqlFileTrace.setANDLogicOperator(true);
  2247.             sqlFileTrace.addWhereCondition(aliasCONFIGPORTA+".id="+aliasTRANSAZIONICONFIGFILETRACE+"."+CostantiDB.COLUMN_ID_PROPRIETARIO);
  2248.             sqlFileTrace.addWhereCondition(aliasTRANSAZIONICONFIGFILETRACE+".proprietario='"+
  2249.                     (erogazioni ? CostantiDB.TRACCIAMENTO_CONFIGURAZIONE_PROPRIETARIO_PA : CostantiDB.TRACCIAMENTO_CONFIGURAZIONE_PROPRIETARIO_PD)+"'");    
  2250.             sqlFileTrace.addWhereCondition(aliasTRANSAZIONICONFIGFILETRACE+".tipo='"+CostantiDB.TRACCIAMENTO_CONFIGURAZIONE_TIPO_FILETRACE+"'");    
  2251.        
  2252.             if(Filtri.FILTRO_CONFIGURAZIONE_TRANSAZIONI_VALORE_RIDEFINITO_ABILITATO_DATABASE_O_FILETRACE.equals(filtroConfigurazioneTransazioni)
  2253.                     ||
  2254.                     Filtri.FILTRO_CONFIGURAZIONE_TRANSAZIONI_VALORE_RIDEFINITO_ABILITATO_SOLO_DATABASE.equals(filtroConfigurazioneTransazioni)
  2255.                     ||
  2256.                     Filtri.FILTRO_CONFIGURAZIONE_TRANSAZIONI_VALORE_RIDEFINITO_ABILITATO_DATABASE_E_FILETRACE.equals(filtroConfigurazioneTransazioni)) {
  2257.                 sqlDB.addWhereCondition(aliasTRANSAZIONICONFIGDB+".stato<>'"+CostantiDB.STATO_FUNZIONALITA_DISABILITATO+"'");  
  2258.             }
  2259.             else {
  2260.                 sqlDB.addWhereCondition(aliasTRANSAZIONICONFIGDB+".stato='"+CostantiDB.STATO_FUNZIONALITA_DISABILITATO+"'");    
  2261.             }
  2262.            
  2263.             if(Filtri.FILTRO_CONFIGURAZIONE_TRANSAZIONI_VALORE_RIDEFINITO_ABILITATO_DATABASE_O_FILETRACE.equals(filtroConfigurazioneTransazioni)
  2264.                 ||
  2265.                 Filtri.FILTRO_CONFIGURAZIONE_TRANSAZIONI_VALORE_RIDEFINITO_ABILITATO_SOLO_FILETRACE.equals(filtroConfigurazioneTransazioni)
  2266.                 ||
  2267.                 Filtri.FILTRO_CONFIGURAZIONE_TRANSAZIONI_VALORE_RIDEFINITO_ABILITATO_DATABASE_E_FILETRACE.equals(filtroConfigurazioneTransazioni)) {
  2268.                 sqlFileTrace.addWhereCondition(aliasTRANSAZIONICONFIGFILETRACE+".stato<>'"+CostantiDB.STATO_FUNZIONALITA_DISABILITATO+"'");
  2269.             }
  2270.             else {
  2271.                 sqlFileTrace.addWhereCondition(aliasTRANSAZIONICONFIGFILETRACE+".stato='"+CostantiDB.STATO_FUNZIONALITA_DISABILITATO+"'");  
  2272.             }
  2273.            
  2274.             if(Filtri.FILTRO_CONFIGURAZIONE_TRANSAZIONI_VALORE_RIDEFINITO_ABILITATO_DATABASE_O_FILETRACE.equals(filtroConfigurazioneTransazioni)) {
  2275.                 ISQLQueryObject sqlUtilsDB = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2276.                 ISQLQueryObject sqlUtilsFileTrace = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2277.                 sqlQueryQuery.addWhereCondition(false,
  2278.                         sqlUtilsDB.getWhereExistsCondition(false, sqlDB),
  2279.                         sqlUtilsFileTrace.getWhereExistsCondition(false, sqlFileTrace));
  2280.             }
  2281.             else if(Filtri.FILTRO_CONFIGURAZIONE_TRANSAZIONI_VALORE_RIDEFINITO_ABILITATO_SOLO_DATABASE.equals(filtroConfigurazioneTransazioni)
  2282.                     ||
  2283.                     Filtri.FILTRO_CONFIGURAZIONE_TRANSAZIONI_VALORE_RIDEFINITO_ABILITATO_SOLO_FILETRACE.equals(filtroConfigurazioneTransazioni)
  2284.                     ||
  2285.                     Filtri.FILTRO_CONFIGURAZIONE_TRANSAZIONI_VALORE_RIDEFINITO_ABILITATO_DATABASE_E_FILETRACE.equals(filtroConfigurazioneTransazioni)
  2286.                     ||
  2287.                     Filtri.FILTRO_CONFIGURAZIONE_TRANSAZIONI_VALORE_RIDEFINITO_DISABILITATO.equals(filtroConfigurazioneTransazioni)) {
  2288.                 sqlQueryQuery.addWhereExistsCondition(false, sqlDB);
  2289.                 sqlQueryQuery.addWhereExistsCondition(false, sqlFileTrace);
  2290.             }
  2291.         }
  2292.        
  2293.     }
  2294.     public static void addFiltroConfigurazioneDump(String tipoDB,
  2295.             String aliasCONFIGPORTA,
  2296.             String filtroConfigurazioneDumpTipo, boolean erogazioni,
  2297.             ISQLQueryObject sqlQueryQuery) throws SQLQueryObjectException {

  2298.         String aliasDUMPCONFIG = "dump_c";
  2299.        
  2300.         ISQLQueryObject sql = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2301.         sql.addFromTable(CostantiDB.DUMP_CONFIGURAZIONE, aliasDUMPCONFIG);
  2302.         sql.addSelectField(aliasDUMPCONFIG, CostantiDB.COLUMN_ID_PROPRIETARIO);
  2303.         sql.setANDLogicOperator(true);
  2304.         if(erogazioni) {
  2305.             sql.addWhereCondition(aliasCONFIGPORTA+".id="+aliasDUMPCONFIG+"."+CostantiDB.COLUMN_ID_PROPRIETARIO);
  2306.             sql.addWhereLikeCondition(aliasDUMPCONFIG+".proprietario", "pa", false, false, false);
  2307.         }
  2308.         else {
  2309.             sql.addWhereCondition(aliasCONFIGPORTA+".id="+aliasDUMPCONFIG+"."+CostantiDB.COLUMN_ID_PROPRIETARIO);
  2310.             sql.addWhereLikeCondition(aliasDUMPCONFIG+".proprietario", "pd", false, false, false);
  2311.         }  
  2312.        
  2313.         //Prepariamo anzi una utility per ogni singola voce e poi ad ogni if la si chiama!
  2314.        
  2315.         boolean and = true;
  2316.         boolean or = false;
  2317.         boolean notExists = true;
  2318.         boolean exists = false;
  2319.        
  2320.         if(Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_DEFAULT.equals(filtroConfigurazioneDumpTipo)) {
  2321.             sqlQueryQuery.addWhereExistsCondition(notExists, sql);  
  2322.         }
  2323.         else if(Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO.equals(filtroConfigurazioneDumpTipo)
  2324.                 ||
  2325.                 Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER.equals(filtroConfigurazioneDumpTipo)
  2326.                 ||
  2327.                 Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_RICHIESTA.equals(filtroConfigurazioneDumpTipo)
  2328.                 ||
  2329.                 Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RICHIESTA.equals(filtroConfigurazioneDumpTipo)
  2330.                 ||
  2331.                 Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_RICHIESTA_INGRESSO.equals(filtroConfigurazioneDumpTipo)
  2332.                 ||
  2333.                 Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RICHIESTA_INGRESSO.equals(filtroConfigurazioneDumpTipo)
  2334.                 ||
  2335.                 Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_RICHIESTA_USCITA.equals(filtroConfigurazioneDumpTipo)
  2336.                 ||
  2337.                 Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RICHIESTA_USCITA.equals(filtroConfigurazioneDumpTipo)
  2338.                 ||
  2339.                 Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_RISPOSTA.equals(filtroConfigurazioneDumpTipo)
  2340.                 ||
  2341.                 Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RISPOSTA.equals(filtroConfigurazioneDumpTipo)
  2342.                 ||
  2343.                 Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_RISPOSTA_INGRESSO.equals(filtroConfigurazioneDumpTipo)
  2344.                 ||
  2345.                 Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RISPOSTA_INGRESSO.equals(filtroConfigurazioneDumpTipo)
  2346.                 ||
  2347.                 Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_RISPOSTA_USCITA.equals(filtroConfigurazioneDumpTipo)
  2348.                 ||
  2349.                 Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RISPOSTA_USCITA.equals(filtroConfigurazioneDumpTipo)
  2350.                 ){
  2351.            
  2352.             boolean soloHeader = (
  2353.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER.equals(filtroConfigurazioneDumpTipo)
  2354.                     ||
  2355.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RICHIESTA.equals(filtroConfigurazioneDumpTipo)
  2356.                     ||
  2357.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RICHIESTA_INGRESSO.equals(filtroConfigurazioneDumpTipo)
  2358.                     ||
  2359.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RICHIESTA_USCITA.equals(filtroConfigurazioneDumpTipo)
  2360.                     ||
  2361.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RISPOSTA.equals(filtroConfigurazioneDumpTipo)
  2362.                     ||
  2363.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RISPOSTA_INGRESSO.equals(filtroConfigurazioneDumpTipo)
  2364.                     ||
  2365.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RISPOSTA_USCITA.equals(filtroConfigurazioneDumpTipo)
  2366.                     );
  2367.             BooleanNullable payload = soloHeader ? BooleanNullable.FALSE() : BooleanNullable.TRUE();
  2368.             BooleanNullable headers = BooleanNullable.TRUE();
  2369.            
  2370.             boolean condizionePayloadHeaders = soloHeader ? and : or;
  2371.            
  2372.             List<ISQLQueryObject> sqlMessages = new ArrayList<>();
  2373.            
  2374.             if(Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO.equals(filtroConfigurazioneDumpTipo)
  2375.                     ||
  2376.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER.equals(filtroConfigurazioneDumpTipo)
  2377.                     ||
  2378.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_RICHIESTA.equals(filtroConfigurazioneDumpTipo)
  2379.                     ||
  2380.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RICHIESTA.equals(filtroConfigurazioneDumpTipo)
  2381.                     ||
  2382.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_RICHIESTA_INGRESSO.equals(filtroConfigurazioneDumpTipo)
  2383.                     ||
  2384.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RICHIESTA_INGRESSO.equals(filtroConfigurazioneDumpTipo)
  2385.                     ) {
  2386.                 ISQLQueryObject sqlRichiestaIngresso = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2387.                 setFiltriDumpRegolaConfigurazioneDumpEngine(tipoDB,
  2388.                         aliasDUMPCONFIG,
  2389.                         "id_richiesta_ingresso", payload, headers, condizionePayloadHeaders,
  2390.                         sqlRichiestaIngresso, exists);
  2391.                 sqlMessages.add(sqlRichiestaIngresso);
  2392.             }
  2393.            
  2394.             if(Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO.equals(filtroConfigurazioneDumpTipo)
  2395.                     ||
  2396.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER.equals(filtroConfigurazioneDumpTipo)
  2397.                     ||
  2398.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_RICHIESTA.equals(filtroConfigurazioneDumpTipo)
  2399.                     ||
  2400.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RICHIESTA.equals(filtroConfigurazioneDumpTipo)
  2401.                     ||
  2402.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_RICHIESTA_USCITA.equals(filtroConfigurazioneDumpTipo)
  2403.                     ||
  2404.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RICHIESTA_USCITA.equals(filtroConfigurazioneDumpTipo)
  2405.                     ) {
  2406.                 ISQLQueryObject sqlRichiestaUscita = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2407.                 setFiltriDumpRegolaConfigurazioneDumpEngine(tipoDB,
  2408.                         aliasDUMPCONFIG,
  2409.                         "id_richiesta_uscita", payload, headers, condizionePayloadHeaders,
  2410.                         sqlRichiestaUscita, exists);
  2411.                 sqlMessages.add(sqlRichiestaUscita);
  2412.             }
  2413.            
  2414.             if(Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO.equals(filtroConfigurazioneDumpTipo)
  2415.                     ||
  2416.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER.equals(filtroConfigurazioneDumpTipo)
  2417.                     ||
  2418.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_RISPOSTA.equals(filtroConfigurazioneDumpTipo)
  2419.                     ||
  2420.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RISPOSTA.equals(filtroConfigurazioneDumpTipo)
  2421.                     ||
  2422.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_RISPOSTA_INGRESSO.equals(filtroConfigurazioneDumpTipo)
  2423.                     ||
  2424.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RISPOSTA_INGRESSO.equals(filtroConfigurazioneDumpTipo)
  2425.                     ) {
  2426.                 ISQLQueryObject sqlRispostaIngresso = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2427.                 setFiltriDumpRegolaConfigurazioneDumpEngine(tipoDB,
  2428.                         aliasDUMPCONFIG,
  2429.                         "id_risposta_ingresso", payload, headers, condizionePayloadHeaders,
  2430.                         sqlRispostaIngresso, exists);
  2431.                 sqlMessages.add(sqlRispostaIngresso);
  2432.             }
  2433.            
  2434.             if(Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO.equals(filtroConfigurazioneDumpTipo)
  2435.                     ||
  2436.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER.equals(filtroConfigurazioneDumpTipo)
  2437.                     ||
  2438.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_RISPOSTA.equals(filtroConfigurazioneDumpTipo)
  2439.                     ||
  2440.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RISPOSTA.equals(filtroConfigurazioneDumpTipo)
  2441.                     ||
  2442.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_RISPOSTA_USCITA.equals(filtroConfigurazioneDumpTipo)
  2443.                     ||
  2444.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RISPOSTA_USCITA.equals(filtroConfigurazioneDumpTipo)
  2445.                     ) {
  2446.                 ISQLQueryObject sqlRispostaUscita = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2447.                 setFiltriDumpRegolaConfigurazioneDumpEngine(tipoDB,
  2448.                         aliasDUMPCONFIG,
  2449.                         "id_risposta_uscita", payload, headers, condizionePayloadHeaders,
  2450.                         sqlRispostaUscita, exists);
  2451.                 sqlMessages.add(sqlRispostaUscita);
  2452.             }
  2453.            
  2454.             setFiltriDumpRegolaConfigurazioneDumpEngine(tipoDB,
  2455.                     sql, or,
  2456.                     sqlMessages.toArray(new ISQLQueryObject[1]));
  2457.             sqlQueryQuery.addWhereExistsCondition(exists, sql);
  2458.         }
  2459.         else if(Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_DISABILITATO.equals(filtroConfigurazioneDumpTipo)
  2460.                 ||
  2461.                 Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_DISABILITATO_RICHIESTA.equals(filtroConfigurazioneDumpTipo)
  2462.                 ||
  2463.                 Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_DISABILITATO_RISPOSTA.equals(filtroConfigurazioneDumpTipo)
  2464.                 ){
  2465.            
  2466.             BooleanNullable payload = BooleanNullable.FALSE();
  2467.             BooleanNullable headers = BooleanNullable.FALSE();
  2468.            
  2469.             boolean condizionePayloadHeaders = and;
  2470.            
  2471.             List<ISQLQueryObject> sqlMessages = new ArrayList<>();
  2472.            
  2473.             if(Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_DISABILITATO.equals(filtroConfigurazioneDumpTipo)
  2474.                     ||
  2475.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_DISABILITATO_RICHIESTA.equals(filtroConfigurazioneDumpTipo)
  2476.                     ) {
  2477.                 ISQLQueryObject sqlRichiestaIngresso = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2478.                 setFiltriDumpRegolaConfigurazioneDumpEngine(tipoDB,
  2479.                         aliasDUMPCONFIG,
  2480.                         "id_richiesta_ingresso", payload, headers, condizionePayloadHeaders,
  2481.                         sqlRichiestaIngresso, exists);
  2482.                 sqlMessages.add(sqlRichiestaIngresso);
  2483.                
  2484.                 ISQLQueryObject sqlRichiestaUscita = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2485.                 setFiltriDumpRegolaConfigurazioneDumpEngine(tipoDB,
  2486.                         aliasDUMPCONFIG,
  2487.                         "id_richiesta_uscita", payload, headers, condizionePayloadHeaders,
  2488.                         sqlRichiestaUscita, exists);
  2489.                 sqlMessages.add(sqlRichiestaUscita);
  2490.             }

  2491.             if(Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_DISABILITATO.equals(filtroConfigurazioneDumpTipo)
  2492.                     ||
  2493.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_DISABILITATO_RISPOSTA.equals(filtroConfigurazioneDumpTipo)
  2494.                     ) {
  2495.                 ISQLQueryObject sqlRispostaIngresso = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2496.                 setFiltriDumpRegolaConfigurazioneDumpEngine(tipoDB,
  2497.                         aliasDUMPCONFIG,
  2498.                         "id_risposta_ingresso", payload, headers, condizionePayloadHeaders,
  2499.                         sqlRispostaIngresso, exists);
  2500.                 sqlMessages.add(sqlRispostaIngresso);
  2501.            
  2502.                 ISQLQueryObject sqlRispostaUscita = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2503.                 setFiltriDumpRegolaConfigurazioneDumpEngine(tipoDB,
  2504.                         aliasDUMPCONFIG,
  2505.                         "id_risposta_uscita", payload, headers, condizionePayloadHeaders,
  2506.                         sqlRispostaUscita, exists);
  2507.                 sqlMessages.add(sqlRispostaUscita);
  2508.             }
  2509.            
  2510.             setFiltriDumpRegolaConfigurazioneDumpEngine(tipoDB,
  2511.                     sql, and,
  2512.                     sqlMessages.toArray(new ISQLQueryObject[1]));
  2513.             sqlQueryQuery.addWhereExistsCondition(exists, sql);
  2514.         }
  2515.        
  2516.     }
  2517.     private static void setFiltriDumpRegolaConfigurazioneDumpEngine(String tipoDB,
  2518.             ISQLQueryObject sqlQueryObjectConditions, boolean and,
  2519.             ISQLQueryObject ... sqlQueryObjectMessage) throws SQLQueryObjectException {    
  2520.         List<String> conditions = new ArrayList<>();
  2521.        
  2522.         if(tipoDB!=null) {
  2523.             // ignore
  2524.         }
  2525.        
  2526.         if(sqlQueryObjectMessage!=null && sqlQueryObjectMessage.length>0) {
  2527.             for (ISQLQueryObject sql : sqlQueryObjectMessage) {
  2528.                 conditions.add(sql.createSQLConditions());  
  2529.             }
  2530.         }
  2531.        
  2532.         if(conditions.isEmpty()) {
  2533.             throw new SQLQueryObjectException("Usage error");
  2534.         }
  2535.         sqlQueryObjectConditions.addWhereCondition(and, conditions.toArray(new String[1]));
  2536.     }
  2537.     private static void setFiltriDumpRegolaConfigurazioneDumpEngine(String tipoDB,
  2538.             String aliasDUMPCONFIG,
  2539.             String colonna, BooleanNullable payload, BooleanNullable headers, boolean and,
  2540.             ISQLQueryObject sqlQueryObjectConditions, boolean notExists) throws SQLQueryObjectException {
  2541.        
  2542.         if(tipoDB!=null) {
  2543.             // ignore
  2544.         }
  2545.        
  2546.         String aliasDUMPCONFIGREGOLE = "dump_cr";
  2547.        
  2548.         ISQLQueryObject sql = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2549.         sql.addSelectField("id");
  2550.         sql.addFromTable(CostantiDB.DUMP_CONFIGURAZIONE_REGOLA, aliasDUMPCONFIGREGOLE);
  2551.         sql.setANDLogicOperator(true);
  2552.         sql.addWhereCondition(aliasDUMPCONFIG+"."+colonna+"="+aliasDUMPCONFIGREGOLE+".id");
  2553.         if(payload!=null && payload.getValue()!=null &&
  2554.                 headers!=null && headers.getValue()!=null) {
  2555.             sql.addWhereCondition(and,
  2556.                     sql.getWhereLikeCondition("payload", payload.getValue()!=null && payload.getValue().booleanValue() ? "abilitato" : "disabilitato", false, false, false),
  2557.                     sql.getWhereLikeCondition("headers", headers.getValue()!=null && headers.getValue().booleanValue() ? "abilitato" : "disabilitato", false, false, false));
  2558.         }
  2559.         else if(payload!=null && payload.getValue()!=null) {
  2560.             sql.addWhereLikeCondition("payload", payload.getValue()!=null && payload.getValue().booleanValue() ? "abilitato" : "disabilitato", false, false, false);
  2561.         }
  2562.         else if(headers!=null && headers.getValue()!=null) {
  2563.             sql.addWhereLikeCondition("headers", headers.getValue()!=null && headers.getValue().booleanValue() ? "abilitato" : "disabilitato", false, false, false);
  2564.         }
  2565.         else {
  2566.             throw new SQLQueryObjectException("Usage error");
  2567.         }
  2568.         sqlQueryObjectConditions.addWhereExistsCondition(notExists, sql);
  2569.     }
  2570.    
  2571.    

  2572.     /**
  2573.      * Utility per formattare la string sql con i parametri passati, e stamparla per debug
  2574.      * @param sql la string sql utilizzata nel prepared statement
  2575.      * @param params i parametri da inserire nella stringa che sostituiranno i '?'
  2576.      * @return La stringa sql con al posto dei '?' ha i parametri passati
  2577.      */
  2578.     public static String formatSQLString(String sql,Object ... params)
  2579.     {
  2580.         String res = sql;

  2581.         for (int i = 0; i < params.length; i++)
  2582.         {
  2583.             res=res.replaceFirst("\\?", "{"+i+"}");
  2584.         }

  2585.         return MessageFormat.format(res, params);

  2586.     }


  2587.    
  2588.    
  2589.    
  2590.     public static List<String> convertToList(String v){
  2591.         List<String> l = new ArrayList<>();
  2592.         if(v!=null && !"".equals(v)) {
  2593.             if(v.contains(",")) {
  2594.                 String [] tmp = v.split(",");
  2595.                 for (int i = 0; i < tmp.length; i++) {
  2596.                     l.add(tmp[i].trim());
  2597.                 }
  2598.             }else {
  2599.                 l.add(v.trim());
  2600.             }
  2601.         }
  2602.         return l;
  2603.     }
  2604. }