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.     private static boolean keystoreJksPasswordRequired = true;
  65.     private static boolean keystoreJksKeyPasswordRequired = true;
  66.     private static boolean keystorePkcs12PasswordRequired = true;
  67.     private static boolean keystorePkcs12KeyPasswordRequired = true;
  68.     private static boolean truststoreJksPasswordRequired = true;
  69.     private static boolean truststorePkcs12PasswordRequired = true;
  70.     public static boolean isKeystoreJksPasswordRequired() {
  71.         return keystoreJksPasswordRequired;
  72.     }
  73.     public static void setKeystoreJksPasswordRequired(boolean isKeystoreJksPasswordRequired) {
  74.         DBUtils.keystoreJksPasswordRequired = isKeystoreJksPasswordRequired;
  75.     }
  76.     public static boolean isKeystoreJksKeyPasswordRequired() {
  77.         return keystoreJksKeyPasswordRequired;
  78.     }
  79.     public static void setKeystoreJksKeyPasswordRequired(boolean isKeystoreJksKeyPasswordRequired) {
  80.         DBUtils.keystoreJksKeyPasswordRequired = isKeystoreJksKeyPasswordRequired;
  81.     }
  82.     public static boolean isKeystorePkcs12PasswordRequired() {
  83.         return keystorePkcs12PasswordRequired;
  84.     }
  85.     public static void setKeystorePkcs12PasswordRequired(boolean isKeystorePkcs12PasswordRequired) {
  86.         DBUtils.keystorePkcs12PasswordRequired = isKeystorePkcs12PasswordRequired;
  87.     }
  88.     public static boolean isKeystorePkcs12KeyPasswordRequired() {
  89.         return keystorePkcs12KeyPasswordRequired;
  90.     }
  91.     public static void setKeystorePkcs12KeyPasswordRequired(boolean isKeystorePkcs12KeyPasswordRequired) {
  92.         DBUtils.keystorePkcs12KeyPasswordRequired = isKeystorePkcs12KeyPasswordRequired;
  93.     }
  94.     public static boolean isTruststoreJksPasswordRequired() {
  95.         return truststoreJksPasswordRequired;
  96.     }
  97.     public static void setTruststoreJksPasswordRequired(boolean isTruststoreJksPasswordRequired) {
  98.         DBUtils.truststoreJksPasswordRequired = isTruststoreJksPasswordRequired;
  99.     }
  100.     public static boolean isTruststorePkcs12PasswordRequired() {
  101.         return truststorePkcs12PasswordRequired;
  102.     }
  103.     public static void setTruststorePkcs12PasswordRequired(boolean isTruststorePkcs12PasswordRequired) {
  104.         DBUtils.truststorePkcs12PasswordRequired = isTruststorePkcs12PasswordRequired;
  105.     }


  106.     public static String estraiTipoDatabaseFromLocation(String location)throws CoreException{
  107.         if(location==null){
  108.             throw new CoreException("Location del db is null");
  109.         }
  110.         if(location.indexOf("@")==-1){
  111.             throw new CoreException("Tipo di database non indicato nella location, sintassi corretta e' tipoDatabase@datasource");
  112.         }
  113.         String tipoDatabase = location.split("@")[0].trim();
  114.         if( ! TipiDatabase.isAMember(tipoDatabase)){
  115.             throw new CoreException("Tipo di database indicato nella location ["+tipoDatabase+"] non supportato");
  116.         }
  117.         return tipoDatabase;
  118.     }
  119.    
  120.    
  121.     public static List<List<Object>> readCustom(Logger log, Connection connection, String tipoDB,
  122.             ISQLQueryObject sqlQueryObject, List<Class<?>> returnTypes, List<JDBCObject> paramTypes) throws CoreException
  123.     {
  124.         PreparedStatement stm = null;
  125.         ResultSet rs = null;
  126.         try
  127.         {
  128.             if(returnTypes==null || returnTypes.isEmpty()){
  129.                 throw new CoreException("Non sono stati definiti tipi da ritornare");
  130.             }
  131.            
  132.             List<List<Object>> lista = new ArrayList<>();
  133.            
  134.             String sql = sqlQueryObject.createSQLQuery();
  135.             stm=connection.prepareStatement(sql);
  136.             GenericJDBCParameterUtilities jdbcParameterUtilities = new GenericJDBCParameterUtilities(TipiDatabase.toEnumConstant(tipoDB));
  137.             JDBCObject [] paramsArray = null;
  138.             if(paramTypes!=null && !paramTypes.isEmpty()){
  139.                 paramsArray = paramTypes.toArray(new JDBCObject[1]);
  140.             }
  141.             jdbcParameterUtilities.setParameters(stm, paramsArray);
  142.            
  143.             JDBCSqlLogger sqlLogger = new JDBCSqlLogger(log);
  144.             sqlLogger.infoSql(sql, paramsArray);
  145.            
  146.             rs=stm.executeQuery();

  147.             while(rs.next()){
  148.                
  149.                 List<Object> listaInterna = new ArrayList<>();
  150.                
  151.                 for (int i = 0; i < returnTypes.size(); i++) {
  152.                     listaInterna.add(jdbcParameterUtilities.readParameter(rs, (i+1), returnTypes.get(i)));
  153.                 }
  154.                
  155.                 lista.add(listaInterna);
  156.             }

  157.             return lista;

  158.         }catch (Exception e) {
  159.             throw new CoreException(e);
  160.         }finally
  161.         {
  162.             //Chiudo statement and resultset
  163.             JDBCUtilities.closeResources(rs, stm);

  164.         }
  165.     }
  166.    
  167.    
  168.    
  169.    
  170.     /**
  171.      * Recupera l'id del soggetto in base al nome e al tipo passati come parametri
  172.      * @param nomeSoggetto
  173.      * @param tipoSoggetto
  174.      * @param con
  175.      * @return L'id del soggetto se esiste, altrimenti -1
  176.      * @throws CoreException
  177.      */
  178.     public static long getIdSoggetto(String nomeSoggetto, String tipoSoggetto,Connection con, String tipoDB) throws CoreException
  179.     {
  180.         return DBUtils.getIdSoggetto(nomeSoggetto, tipoSoggetto, con, tipoDB, CostantiDB.SOGGETTI);
  181.     }
  182.     public static long getIdSoggetto(String nomeSoggetto, String tipoSoggetto,Connection con, String tipoDB,String tabellaSoggetti) throws CoreException
  183.     {
  184.         PreparedStatement stm = null;
  185.         ResultSet rs = null;
  186.         long idSoggetto=-1;
  187.         try
  188.         {
  189.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  190.             sqlQueryObject.addFromTable(tabellaSoggetti);
  191.             sqlQueryObject.addSelectField("*");
  192.             sqlQueryObject.addWhereCondition("tipo_soggetto = ?");
  193.             sqlQueryObject.addWhereCondition("nome_soggetto = ?");
  194.             sqlQueryObject.setANDLogicOperator(true);
  195.             String query = sqlQueryObject.createSQLQuery();
  196.             stm=con.prepareStatement(query);
  197.             stm.setString(1, tipoSoggetto);
  198.             stm.setString(2, nomeSoggetto);

  199.             rs=stm.executeQuery();

  200.             if(rs.next()){
  201.                 idSoggetto = rs.getLong("id");
  202.             }

  203.             return idSoggetto;

  204.         }catch (Exception e) {
  205.             throw new CoreException(e);
  206.         }finally
  207.         {
  208.             //Chiudo statement and resultset
  209.             JDBCUtilities.closeResources(rs, stm);

  210.         }
  211.     }
  212.    
  213.     public static IDSoggetto getIdSoggetto(long id,Connection con, String tipoDB) throws CoreException
  214.     {
  215.         return DBUtils.getIdSoggetto(id, con, tipoDB, CostantiDB.SOGGETTI);
  216.     }
  217.     public static IDSoggetto getIdSoggetto(long id,Connection con, String tipoDB,String tabellaSoggetti) throws CoreException
  218.     {
  219.         PreparedStatement stm = null;
  220.         ResultSet rs = null;
  221.         IDSoggetto idSoggetto = null;
  222.         try
  223.         {
  224.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  225.             sqlQueryObject.addFromTable(tabellaSoggetti);
  226.             sqlQueryObject.addSelectField("*");
  227.             sqlQueryObject.addWhereCondition(WHERE_ID_CONDITION);
  228.             sqlQueryObject.setANDLogicOperator(true);
  229.             String query = sqlQueryObject.createSQLQuery();
  230.             stm=con.prepareStatement(query);
  231.             stm.setLong(1, id);

  232.             rs=stm.executeQuery();

  233.             if(rs.next()){
  234.                 String tipSoggetto = rs.getString("tipo_soggetto");
  235.                 String nomeSoggetto = rs.getString("nome_soggetto");
  236.                 idSoggetto = new IDSoggetto(tipSoggetto, nomeSoggetto);
  237.             }

  238.             return idSoggetto;

  239.         }catch (Exception e) {
  240.             throw new CoreException(e);
  241.         }finally
  242.         {
  243.             //Chiudo statement and resultset
  244.             JDBCUtilities.closeResources(rs, stm);

  245.         }
  246.     }
  247.    
  248.    
  249.    
  250.    

  251.     public static long getIdConnettore(String nomeConnettore,Connection con, String tipoDB) throws CoreException
  252.     {
  253.         PreparedStatement stm = null;
  254.         ResultSet rs = null;
  255.         long idConnettore=-1;
  256.         try
  257.         {
  258.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  259.             sqlQueryObject.addFromTable(CostantiDB.CONNETTORI);
  260.             sqlQueryObject.addSelectField("*");
  261.             sqlQueryObject.addWhereCondition("nome_connettore = ?");
  262.             String query = sqlQueryObject.createSQLQuery();
  263.             stm=con.prepareStatement(query);
  264.             stm.setString(1, nomeConnettore);
  265.             rs=stm.executeQuery();

  266.             if(rs.next()){
  267.                 idConnettore = rs.getLong("id");
  268.             }

  269.             return idConnettore;

  270.         }catch (Exception e) {
  271.             throw new CoreException(e);
  272.         }finally
  273.         {
  274.             //Chiudo statement and resultset
  275.             JDBCUtilities.closeResources(rs, stm);

  276.         }
  277.     }

  278.    
  279.    
  280.     /**
  281.      * Recupero l'id del servizio
  282.      */
  283.     public static long getIdServizio(String nomeServizio, String tipoServizio,Integer versioneServizio, String nomeSoggettoErogatore,String tipoSoggettoErogatore,Connection con, String tipoDB) throws CoreException{
  284.         return DBUtils.getIdServizio(nomeServizio,tipoServizio,versioneServizio,nomeSoggettoErogatore,tipoSoggettoErogatore,con,false,tipoDB, CostantiDB.SOGGETTI);
  285.     }
  286.     public static long getIdServizio(String nomeServizio, String tipoServizio,Integer versioneServizio, String nomeSoggettoErogatore,String tipoSoggettoErogatore,Connection con, String tipoDB,String tabellaSoggetti) throws CoreException{
  287.         return DBUtils.getIdServizio(nomeServizio,tipoServizio,versioneServizio,nomeSoggettoErogatore,tipoSoggettoErogatore,con,false,tipoDB,tabellaSoggetti);
  288.     }
  289.     public static long getIdServizio(String nomeServizio, String tipoServizio,Integer versioneServizio, long idSoggetto,Connection con, String tipoDB) throws CoreException{
  290.         return DBUtils.getIdServizio(nomeServizio,tipoServizio,versioneServizio,idSoggetto,con,false,tipoDB, CostantiDB.SOGGETTI);
  291.     }
  292.     public static long getIdServizio(String nomeServizio, String tipoServizio,Integer versioneServizio, long idSoggetto,Connection con, String tipoDB,String tabellaSoggetti) throws CoreException{
  293.         return DBUtils.getIdServizio(nomeServizio,tipoServizio,versioneServizio,idSoggetto,con,false,tipoDB,tabellaSoggetti);
  294.     }

  295.     /**
  296.      * Recupero l'id del servizio
  297.      */
  298.     public static long getIdServizio(String nomeServizio, String tipoServizio,Integer versioneServizio, String nomeSoggettoErogatore,String tipoSoggettoErogatore,
  299.             Connection con,boolean testServizioNonCorrelato,String tipoDB) throws CoreException
  300.     {
  301.         return DBUtils.getIdServizio(nomeServizio, tipoServizio, versioneServizio, nomeSoggettoErogatore, tipoSoggettoErogatore, con, testServizioNonCorrelato, tipoDB, CostantiDB.SOGGETTI);
  302.     }
  303.     public static long getIdServizio(String nomeServizio, String tipoServizio,Integer versioneServizio, String nomeSoggettoErogatore,String tipoSoggettoErogatore,
  304.             Connection con,boolean testServizioNonCorrelato,String tipoDB,String tabellaSoggetti) throws CoreException
  305.     {
  306.         long idSoggetto = DBUtils.getIdSoggetto(nomeSoggettoErogatore, tipoSoggettoErogatore, con, tipoDB,tabellaSoggetti);
  307.         return getIdServizio(nomeServizio, tipoServizio, versioneServizio, idSoggetto,
  308.                 con, testServizioNonCorrelato, tipoDB, tabellaSoggetti);
  309.     }
  310.     public static long getIdServizio(String nomeServizio, String tipoServizio,Integer versioneServizio, long idSoggetto,
  311.             Connection con,boolean testServizioNonCorrelato,String tipoDB) throws CoreException
  312.     {
  313.         return  getIdServizio(nomeServizio, tipoServizio, versioneServizio, idSoggetto,
  314.                 con,testServizioNonCorrelato,tipoDB,CostantiDB.SOGGETTI);
  315.     }
  316.     public static long getIdServizio(String nomeServizio, String tipoServizio,Integer versioneServizio, long idSoggetto,
  317.             Connection con,boolean testServizioNonCorrelato,String tipoDB,String tabellaSoggetti) throws CoreException
  318.     {
  319.         PreparedStatement stm = null;
  320.         ResultSet rs = null;
  321.         long idServizio=0;
  322.         try
  323.         {
  324.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  325.             sqlQueryObject.addFromTable(CostantiDB.SERVIZI);
  326.             sqlQueryObject.addSelectField("*");
  327.             sqlQueryObject.addWhereCondition("id_soggetto = ?");
  328.             sqlQueryObject.addWhereCondition("tipo_servizio = ?");
  329.             sqlQueryObject.addWhereCondition("nome_servizio = ?");
  330.             sqlQueryObject.addWhereCondition("versione_servizio = ?");
  331.             sqlQueryObject.setANDLogicOperator(true);
  332.             String query = sqlQueryObject.createSQLQuery();
  333.             if(testServizioNonCorrelato)
  334.                 query = query + " AND servizio_correlato=?";
  335.             stm=con.prepareStatement(query);
  336.             int index = 1;
  337.             stm.setLong(index++, idSoggetto);
  338.             stm.setString(index++, tipoServizio);
  339.             stm.setString(index++, nomeServizio);
  340.             stm.setInt(index++, versioneServizio);
  341.             if(testServizioNonCorrelato)
  342.                 stm.setString(index++, CostantiDB.STATO_FUNZIONALITA_DISABILITATO);

  343.             rs=stm.executeQuery();

  344.             if(rs.next()){
  345.                 idServizio = rs.getLong("id");
  346.             }

  347.             return idServizio;

  348.         }catch (Exception e) {
  349.             throw new CoreException(e);
  350.         }finally
  351.         {
  352.             //Chiudo statement and resultset
  353.             JDBCUtilities.closeResources(rs, stm);

  354.         }
  355.     }

  356.    
  357.    
  358.    
  359.    
  360.    
  361.     public static String getSuperUserSoggettoSafe(Logger log, String method,
  362.             long idSoggetto,Connection con, String tipoDB)
  363.     {
  364.         return getSuperUserSoggettoSafe(log, method,
  365.                 idSoggetto,con, tipoDB,CostantiDB.SOGGETTI);
  366.     }
  367.     public static String getSuperUserSoggettoSafe(Logger log, String method,
  368.             long idSoggetto,Connection con, String tipoDB,String tabellaSoggetti)
  369.     {
  370.         try
  371.         {
  372.             return getSuperUserSoggetto(idSoggetto, con, tipoDB, tabellaSoggetti);
  373.         }catch(Exception e) {
  374.             if(log!=null) {
  375.                 String msgError = "["+method+"] getSuperUserSoggetto failed: "+e.getMessage();
  376.                 log.error(msgError, e);
  377.             }
  378.             return null;
  379.         }
  380.     }
  381.     public static String getSuperUserSoggetto(long idSoggetto,Connection con, String tipoDB) throws CoreException
  382.     {
  383.         return getSuperUserSoggetto(idSoggetto, con, tipoDB, CostantiDB.SOGGETTI);
  384.     }
  385.     public static String getSuperUserSoggetto(long idSoggetto,Connection con, String tipoDB,String tabellaSoggetti) throws CoreException
  386.     {
  387.         PreparedStatement stm = null;
  388.         ResultSet rs = null;
  389.         String superuser=null;
  390.         try
  391.         {
  392.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  393.             sqlQueryObject.addFromTable(tabellaSoggetti);
  394.             sqlQueryObject.addSelectField("superuser");
  395.             sqlQueryObject.addWhereCondition(WHERE_ID_CONDITION);
  396.             sqlQueryObject.setANDLogicOperator(true);
  397.             String query = sqlQueryObject.createSQLQuery();
  398.             stm=con.prepareStatement(query);
  399.             stm.setLong(1, idSoggetto);

  400.             rs=stm.executeQuery();

  401.             if(rs.next()){
  402.                 superuser = rs.getString("superuser");
  403.             }

  404.             return superuser;

  405.         }
  406.         catch (Exception e) {
  407.             throw new CoreException(e);
  408.         }finally
  409.         {
  410.             //Chiudo statement and resultset
  411.             JDBCUtilities.closeResources(rs, stm);

  412.         }
  413.     }
  414.    
  415.    
  416.    
  417.    
  418.    
  419.    
  420.    
  421.    
  422.    
  423.     public static String getSuperUserServizioSafe(Logger log, String method,
  424.             long idServizio,Connection con, String tipoDB)
  425.     {
  426.         try
  427.         {
  428.             return getSuperUserServizio(idServizio, con, tipoDB);
  429.         }catch(Exception e) {
  430.             if(log!=null) {
  431.                 String msgError = "["+method+"] getSuperUserServizio failed: "+e.getMessage();
  432.                 log.error(msgError, e);
  433.             }
  434.             return null;
  435.         }
  436.     }
  437.     public static String getSuperUserServizio(long idServizio,Connection con, String tipoDB) throws CoreException
  438.     {
  439.         PreparedStatement stm = null;
  440.         ResultSet rs = null;
  441.         String superuser=null;
  442.         try
  443.         {
  444.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  445.             sqlQueryObject.addFromTable(CostantiDB.SERVIZI);
  446.             sqlQueryObject.addSelectField("superuser");
  447.             sqlQueryObject.addWhereCondition(WHERE_ID_CONDITION);
  448.             sqlQueryObject.setANDLogicOperator(true);
  449.             String query = sqlQueryObject.createSQLQuery();
  450.             stm=con.prepareStatement(query);
  451.             stm.setLong(1, idServizio);

  452.             rs=stm.executeQuery();

  453.             if(rs.next()){
  454.                 superuser = rs.getString("superuser");
  455.             }

  456.             return superuser;

  457.         }
  458.         catch (Exception e) {
  459.             throw new CoreException(e);
  460.         }finally
  461.         {
  462.             //Chiudo statement and resultset
  463.             JDBCUtilities.closeResources(rs, stm);

  464.         }
  465.     }
  466.    
  467.    
  468.    
  469.    
  470.    
  471.    

  472.     public static long getIdPortaApplicativa(String nomePorta, Connection con, String tipoDB) throws CoreException
  473.     {
  474.         PreparedStatement stm = null;
  475.         ResultSet rs = null;
  476.         long idPortaApplicativa=-1;

  477.         try
  478.         {
  479.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  480.             sqlQueryObject.addFromTable(CostantiDB.PORTE_APPLICATIVE);
  481.             sqlQueryObject.addSelectField("id");
  482.             sqlQueryObject.addWhereCondition("nome_porta = ?");
  483.             sqlQueryObject.setANDLogicOperator(true);
  484.             String sqlQuery = sqlQueryObject.createSQLQuery();
  485.             stm=con.prepareStatement(sqlQuery);
  486.             stm.setString(1, nomePorta);

  487.             rs=stm.executeQuery();

  488.             if(rs.next())
  489.             {
  490.                 idPortaApplicativa=rs.getLong("id");
  491.             }
  492.             return idPortaApplicativa;
  493.         }catch (Exception e) {
  494.             throw new CoreException(e);
  495.         }finally
  496.         {
  497.             //Chiudo statement and resultset
  498.             JDBCUtilities.closeResources(rs, stm);

  499.         }

  500.     }
  501.    
  502.    
  503.    
  504.    
  505.    
  506.    
  507.     public static long getIdPortaDelegata(String nomePorta, Connection con, String tipoDB) throws CoreException
  508.     {
  509.         PreparedStatement stm = null;
  510.         ResultSet rs = null;
  511.         long idPortaDelegata=-1;

  512.         try
  513.         {
  514.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  515.             sqlQueryObject.addFromTable(CostantiDB.PORTE_DELEGATE);
  516.             sqlQueryObject.addSelectField("id");
  517.             sqlQueryObject.addWhereCondition("nome_porta = ?");
  518.             sqlQueryObject.setANDLogicOperator(true);
  519.             String sqlQuery = sqlQueryObject.createSQLQuery();
  520.             stm=con.prepareStatement(sqlQuery);
  521.             stm.setString(1, nomePorta);

  522.             rs=stm.executeQuery();

  523.             if(rs.next())
  524.             {
  525.                 idPortaDelegata=rs.getLong("id");
  526.             }
  527.             return idPortaDelegata;
  528.         }catch (Exception e) {
  529.             throw new CoreException(e);
  530.         }finally
  531.         {
  532.             //Chiudo statement and resultset
  533.             JDBCUtilities.closeResources(rs, stm);

  534.         }

  535.     }
  536.    
  537.    
  538.    
  539.    
  540.    
  541.    
  542.     public static long getIdServizioApplicativo(String nomeServizioApplicativo, String tipoProprietario, String nomeProprietario,
  543.             Connection con, String tipoDB) throws CoreException
  544.     {
  545.         return DBUtils.getIdServizioApplicativo(nomeServizioApplicativo, tipoProprietario, nomeProprietario, con, tipoDB, CostantiDB.SOGGETTI);
  546.     }
  547.     public static long getIdServizioApplicativo(String nomeServizioApplicativo, String tipoProprietario, String nomeProprietario,
  548.             Connection con, String tipoDB,String tabellaSoggetti) throws CoreException
  549.     {
  550.         PreparedStatement stm = null;
  551.         ResultSet rs = null;
  552.         long idSoggetto;
  553.         long idServizioApplicativo=-1;

  554.         try
  555.         {
  556.             idSoggetto = DBUtils.getIdSoggetto(nomeProprietario, tipoProprietario, con, tipoDB,tabellaSoggetti);

  557.             //recupero l'id della porta applicativa appena inserita
  558.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  559.             sqlQueryObject.addFromTable(CostantiDB.SERVIZI_APPLICATIVI);
  560.             sqlQueryObject.addSelectField("id");
  561.             sqlQueryObject.addWhereCondition("id_soggetto = ?");
  562.             sqlQueryObject.addWhereCondition("nome = ?");
  563.             sqlQueryObject.setANDLogicOperator(true);
  564.             String sqlQuery = sqlQueryObject.createSQLQuery();
  565.             stm=con.prepareStatement(sqlQuery);
  566.             stm.setLong(1, idSoggetto);
  567.             stm.setString(2, nomeServizioApplicativo);

  568.             rs=stm.executeQuery();

  569.             if(rs.next())
  570.             {
  571.                 idServizioApplicativo=rs.getLong("id");
  572.             }
  573.             return idServizioApplicativo;
  574.         }catch (Exception e) {
  575.             throw new CoreException(e);
  576.         }finally
  577.         {
  578.             //Chiudo statement and resultset
  579.             JDBCUtilities.closeResources(rs, stm);

  580.         }

  581.     }

  582.    
  583.    
  584.    
  585.    
  586.    
  587.     public static long getIdPortaDominio(String nome, Connection con, String tipoDB) throws CoreException
  588.     {
  589.         PreparedStatement stm = null;
  590.         ResultSet rs = null;
  591.         long idPdD=-1;
  592.         try
  593.         {
  594.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  595.             sqlQueryObject.addFromTable(CostantiDB.PDD);
  596.             sqlQueryObject.addSelectField("*");
  597.             sqlQueryObject.addWhereCondition("nome = ?");
  598.             sqlQueryObject.setANDLogicOperator(true);
  599.             String query = sqlQueryObject.createSQLQuery();
  600.             stm=con.prepareStatement(query);
  601.             stm.setString(1, nome);

  602.             rs=stm.executeQuery();

  603.             if(rs.next()){
  604.                 idPdD = rs.getLong("id");
  605.             }

  606.             return idPdD;

  607.         }catch (Exception e) {
  608.             throw new CoreException(e);
  609.         }finally
  610.         {
  611.             //Chiudo statement and resultset
  612.             JDBCUtilities.closeResources(rs, stm);

  613.         }
  614.     }
  615.    
  616.    
  617.    
  618.    
  619.    
  620.     public static long getIdGruppo(IDGruppo idGruppo, Connection con, String tipoDB) throws CoreException
  621.     {
  622.         PreparedStatement stm = null;
  623.         ResultSet rs = null;
  624.         long idGruppoLong=-1;
  625.         try
  626.         {
  627.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  628.             sqlQueryObject.addFromTable(CostantiDB.GRUPPI);
  629.             sqlQueryObject.addSelectField("*");
  630.             sqlQueryObject.addWhereCondition("nome = ?");
  631.             sqlQueryObject.setANDLogicOperator(true);
  632.             String query = sqlQueryObject.createSQLQuery();
  633.             stm=con.prepareStatement(query);
  634.             stm.setString(1, idGruppo.getNome());

  635.             rs=stm.executeQuery();

  636.             if(rs.next()){
  637.                 idGruppoLong = rs.getLong("id");
  638.             }

  639.             return idGruppoLong;

  640.         }catch (Exception e) {
  641.             throw new CoreException(e);
  642.         }finally
  643.         {
  644.             //Chiudo statement and resultset
  645.             JDBCUtilities.closeResources(rs, stm);

  646.         }
  647.     }
  648.    
  649.    
  650.    
  651.    
  652.    
  653.    
  654.     public static long getIdRuolo(IDRuolo idRuolo, Connection con, String tipoDB) throws CoreException
  655.     {
  656.         PreparedStatement stm = null;
  657.         ResultSet rs = null;
  658.         long idRuoloLong=-1;
  659.         try
  660.         {
  661.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  662.             sqlQueryObject.addFromTable(CostantiDB.RUOLI);
  663.             sqlQueryObject.addSelectField("*");
  664.             sqlQueryObject.addWhereCondition("nome = ?");
  665.             sqlQueryObject.setANDLogicOperator(true);
  666.             String query = sqlQueryObject.createSQLQuery();
  667.             stm=con.prepareStatement(query);
  668.             stm.setString(1, idRuolo.getNome());

  669.             rs=stm.executeQuery();

  670.             if(rs.next()){
  671.                 idRuoloLong = rs.getLong("id");
  672.             }

  673.             return idRuoloLong;

  674.         }catch (Exception e) {
  675.             throw new CoreException(e);
  676.         }finally
  677.         {
  678.             //Chiudo statement and resultset
  679.             JDBCUtilities.closeResources(rs, stm);

  680.         }
  681.     }
  682.    
  683.    
  684.    
  685.    
  686.     public static long getIdScope(IDScope idScope, Connection con, String tipoDB) throws CoreException
  687.     {
  688.         PreparedStatement stm = null;
  689.         ResultSet rs = null;
  690.         long idScopeLong=-1;
  691.         try
  692.         {
  693.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  694.             sqlQueryObject.addFromTable(CostantiDB.SCOPE);
  695.             sqlQueryObject.addSelectField("*");
  696.             sqlQueryObject.addWhereCondition("nome = ?");
  697.             sqlQueryObject.setANDLogicOperator(true);
  698.             String query = sqlQueryObject.createSQLQuery();
  699.             stm=con.prepareStatement(query);
  700.             stm.setString(1, idScope.getNome());

  701.             rs=stm.executeQuery();

  702.             if(rs.next()){
  703.                 idScopeLong = rs.getLong("id");
  704.             }

  705.             return idScopeLong;

  706.         }catch (Exception e) {
  707.             throw new CoreException(e);
  708.         }finally
  709.         {
  710.             //Chiudo statement and resultset
  711.             JDBCUtilities.closeResources(rs, stm);

  712.         }
  713.     }
  714.    
  715.    
  716.    
  717.    
  718.    

  719.     public static long getIdAccordoServizioParteComune(String nomeServizio, String tipoServizio,Integer versioneServizio, String nomeSoggettoErogatore,String tipoSoggettoErogatore,Connection con, String tipoDB) throws CoreException
  720.     {
  721.         return DBUtils.getIdAccordoServizioParteComune(nomeServizio,tipoServizio,versioneServizio, nomeSoggettoErogatore,tipoSoggettoErogatore,con,tipoDB,CostantiDB.SOGGETTI);
  722.     }
  723.     public static long getIdAccordoServizioParteComune(String nomeServizio, String tipoServizio,Integer versioneServizio, String nomeSoggettoErogatore,String tipoSoggettoErogatore,Connection con, String tipoDB,String tabellaSoggetti) throws CoreException
  724.     {
  725.         PreparedStatement stm = null;
  726.         ResultSet rs = null;
  727.         long idServizio;
  728.         long idAccordo = -1;
  729.         try
  730.         {
  731.             idServizio = DBUtils.getIdServizio(nomeServizio, tipoServizio, versioneServizio, nomeSoggettoErogatore, tipoSoggettoErogatore, con, tipoDB,tabellaSoggetti);

  732.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  733.             sqlQueryObject.addFromTable(CostantiDB.SERVIZI);
  734.             sqlQueryObject.addSelectField("*");
  735.             sqlQueryObject.addWhereCondition(WHERE_ID_CONDITION);
  736.             String query = sqlQueryObject.createSQLQuery();
  737.             stm=con.prepareStatement(query);
  738.             stm.setLong(1, idServizio);

  739.             rs=stm.executeQuery();

  740.             if(rs.next()){
  741.                 idAccordo = rs.getLong("id_accordo");
  742.             }

  743.             return idAccordo;

  744.         }catch (Exception e) {
  745.             throw new CoreException(e);
  746.         }finally
  747.         {
  748.             //Chiudo statement and resultset
  749.             JDBCUtilities.closeResources(rs, stm);

  750.         }
  751.     }
  752.    
  753.     public static long getIdPortType(Long idAccordo,String nomePortType,Connection con) throws CoreException{
  754.         PreparedStatement selectStmt = null;
  755.         ResultSet selectRS = null;
  756.         long id=-1;
  757.         try
  758.         {
  759.             String selectQuery = "SELECT id FROM " + CostantiDB.PORT_TYPE + " WHERE id_accordo = ? AND nome=?";
  760.             selectStmt = con.prepareStatement(selectQuery);
  761.             selectStmt.setLong(1, idAccordo);
  762.             selectStmt.setString(2, nomePortType);
  763.             selectRS = selectStmt.executeQuery();
  764.             if (selectRS.next()) {
  765.                 id = selectRS.getLong("id");    
  766.             }
  767.             selectRS.close();
  768.             selectStmt.close();
  769.             return id;
  770.         }catch (Exception e) {
  771.             throw new CoreException(e);
  772.         }finally
  773.         {
  774.             //Chiudo statement and resultset
  775.             JDBCUtilities.closeResources(selectRS, selectStmt);

  776.         }
  777.     }
  778.    
  779.     public static long getIdResource(Long idAccordo,String nomeRisorsa,Connection con) throws CoreException{
  780.         PreparedStatement selectStmt = null;
  781.         ResultSet selectRS = null;
  782.         long id=-1;
  783.         try
  784.         {
  785.             String selectQuery = "SELECT id FROM " + CostantiDB.API_RESOURCES + " WHERE id_accordo = ? AND nome=?";
  786.             selectStmt = con.prepareStatement(selectQuery);
  787.             selectStmt.setLong(1, idAccordo);
  788.             selectStmt.setString(2, nomeRisorsa);
  789.             selectRS = selectStmt.executeQuery();
  790.             if (selectRS.next()) {
  791.                 id = selectRS.getLong("id");    
  792.             }
  793.             selectRS.close();
  794.             selectStmt.close();
  795.             return id;
  796.         }catch (Exception e) {
  797.             throw new CoreException(e);
  798.         }finally
  799.         {
  800.             //Chiudo statement and resultset
  801.             JDBCUtilities.closeResources(selectRS, selectStmt);

  802.         }
  803.     }
  804.    
  805.     public static long getIdAccordoServizioParteComune(IDAccordo idAccordo,Connection con, String tipoDB) throws CoreException{
  806.         PreparedStatement stm = null;
  807.         ResultSet rs = null;
  808.         long idAccordoLong=-1;
  809.         try
  810.         {
  811.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  812.             sqlQueryObject.addFromTable(CostantiDB.ACCORDI);
  813.             sqlQueryObject.addSelectField("*");
  814.             sqlQueryObject.addWhereCondition("nome = ?");
  815.             sqlQueryObject.addWhereCondition("id_referente = ?");
  816.             sqlQueryObject.addWhereCondition("versione = ?");
  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.             stm.setInt(3, idAccordo.getVersione());
  832.                        
  833.             rs=stm.executeQuery();

  834.             if(rs.next()){
  835.                 idAccordoLong = rs.getLong("id");
  836.             }

  837.             return idAccordoLong;

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

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

  874.             if(rs.next()){
  875.                 int versione = rs.getInt("versione");
  876.                 if(versione>0) {
  877.                     return versione+1;
  878.                 }
  879.             }

  880.             return 1; // accordo non esistente

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

  887.         }
  888.     }
  889.    
  890.    
  891.    
  892.    
  893.     public static long getIdAccordoCooperazione(IDAccordoCooperazione idAccordo,Connection con, String tipoDB) throws CoreException{
  894.         PreparedStatement stm = null;
  895.         ResultSet rs = null;
  896.         long idAccordoLong=-1;
  897.         try
  898.         {
  899.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  900.             sqlQueryObject.addFromTable(CostantiDB.ACCORDI_COOPERAZIONE);
  901.             sqlQueryObject.addSelectField("*");
  902.             sqlQueryObject.addWhereCondition("nome = ?");
  903.             sqlQueryObject.addWhereCondition("id_referente = ?");
  904.             sqlQueryObject.addWhereCondition("versione = ?");
  905.             sqlQueryObject.setANDLogicOperator(true);
  906.             String query = sqlQueryObject.createSQLQuery();
  907.             stm=con.prepareStatement(query);
  908.             stm.setString(1, idAccordo.getNome());
  909.                
  910.             long idSoggettoReferente =  0;
  911.             if(idAccordo.getSoggettoReferente()!=null){
  912.                 idSoggettoReferente = DBUtils.getIdSoggetto(idAccordo.getSoggettoReferente().getNome(), idAccordo.getSoggettoReferente().getTipo(), con, tipoDB);
  913.                 if(idSoggettoReferente<=0){
  914.                     throw new CoreException("[getIdAccordoCooperazione] Soggetto Referente ["+idAccordo.getSoggettoReferente().toString()+"] non esiste");
  915.                 }
  916.             }
  917.             stm.setLong(2, idSoggettoReferente);
  918.                
  919.             stm.setInt(3, idAccordo.getVersione());
  920.                        
  921.             rs=stm.executeQuery();

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

  925.             return idAccordoLong;

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

  932.         }
  933.     }
  934.    
  935.    
  936.     public static long getIdAccordoServizioParteSpecifica(IDServizio idServizio,Connection con, String tipoDB) throws CoreException{
  937.         PreparedStatement stm = null;
  938.         ResultSet rs = null;
  939.         long idAccordoLong=-1;
  940.         try
  941.         {
  942.            
  943.             // NOTA: nell'APS, il soggetto e la versione sono obbligatori
  944.            
  945.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  946.             sqlQueryObject.addFromTable(CostantiDB.SERVIZI);
  947.             sqlQueryObject.addFromTable(CostantiDB.SOGGETTI);
  948.             sqlQueryObject.addSelectField("*");
  949.             sqlQueryObject.setANDLogicOperator(true);
  950.             sqlQueryObject.addWhereCondition(CostantiDB.SERVIZI+".id_soggetto = "+CostantiDB.SOGGETTI+".id");
  951.             sqlQueryObject.addWhereCondition("tipo_soggetto = ?");
  952.             sqlQueryObject.addWhereCondition("nome_soggetto = ?");
  953.             sqlQueryObject.addWhereCondition("tipo_servizio = ?");
  954.             sqlQueryObject.addWhereCondition("nome_servizio = ?");
  955.             sqlQueryObject.addWhereCondition("versione_servizio = ?");
  956.             String query = sqlQueryObject.createSQLQuery();
  957.             stm=con.prepareStatement(query);
  958.             stm.setString(1, idServizio.getSoggettoErogatore().getTipo());
  959.             stm.setString(2, idServizio.getSoggettoErogatore().getNome());
  960.             stm.setString(3, idServizio.getTipo());
  961.             stm.setString(4, idServizio.getNome());
  962.             stm.setInt(5, idServizio.getVersione());
  963.            
  964.             rs=stm.executeQuery();

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

  968.             return idAccordoLong;

  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.    
  979.     public static long getIdFruizioneServizio(IDServizio idServizio,IDSoggetto idFruitore, Connection con, String tipoDB) throws CoreException{
  980.         return getIdFruizioneServizio(idServizio, idFruitore, con, tipoDB, CostantiDB.SOGGETTI);
  981.     }
  982.     public static long getIdFruizioneServizio(IDServizio idServizio,IDSoggetto idFruitore, Connection con, String tipoDB, String tabellaSoggetti) throws CoreException{
  983.         return _getIdFruizioneServizio(DBUtils.getIdAccordoServizioParteSpecifica(idServizio, con, tipoDB), idFruitore, con, tipoDB, tabellaSoggetti);
  984.     }
  985.    
  986.     private static long _getIdFruizioneServizio(long idServizio,IDSoggetto idFruitore, Connection con, String tipoDB, String tabellaSoggetti) throws CoreException{
  987.         PreparedStatement stm = null;
  988.         ResultSet rs = null;
  989.         long idFruizione=-1;
  990.         try
  991.         {
  992.            
  993.             // NOTA: nell'APS, il soggetto e la versione sono obbligatori
  994.            
  995.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  996.             sqlQueryObject.addFromTable(CostantiDB.SERVIZI_FRUITORI);
  997.             sqlQueryObject.addSelectField("id");
  998.             sqlQueryObject.setANDLogicOperator(true);
  999.             sqlQueryObject.addWhereCondition(CostantiDB.SERVIZI_FRUITORI+".id_servizio = ?");
  1000.             sqlQueryObject.addWhereCondition(CostantiDB.SERVIZI_FRUITORI+".id_soggetto = ?");
  1001.             String query = sqlQueryObject.createSQLQuery();
  1002.             stm=con.prepareStatement(query);
  1003.             stm.setLong(1, idServizio);
  1004.             stm.setLong(2, DBUtils.getIdSoggetto(idFruitore.getNome(), idFruitore.getTipo(), con, tipoDB,tabellaSoggetti));
  1005.            
  1006.             rs=stm.executeQuery();

  1007.             if(rs.next()){
  1008.                 idFruizione = rs.getLong("id");
  1009.             }

  1010.             return idFruizione;

  1011.         }catch (Exception e) {
  1012.             throw new CoreException(e);
  1013.         }finally
  1014.         {
  1015.             //Chiudo statement and resultset
  1016.             JDBCUtilities.closeResources(rs, stm);

  1017.         }
  1018.     }
  1019.    

  1020.     public static long getIdDocumento(String nome, String tipo, String ruolo, long idProprietario,Connection con,String tipoDB,String tipoProprietario) throws CoreException{
  1021.         PreparedStatement stm = null;
  1022.         ResultSet rs = null;
  1023.         long idDoc=-1;
  1024.         try
  1025.         {
  1026.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  1027.             sqlQueryObject.addFromTable(CostantiDB.DOCUMENTI);
  1028.             sqlQueryObject.addSelectField("id");
  1029.             sqlQueryObject.addWhereCondition("id_proprietario = ?");
  1030.             sqlQueryObject.addWhereCondition("nome = ?");
  1031.             if(tipo!=null) {
  1032.                 sqlQueryObject.addWhereCondition("tipo = ?");
  1033.             }
  1034.             if(ruolo!=null) {
  1035.                 sqlQueryObject.addWhereCondition("ruolo = ?");
  1036.             }
  1037.             sqlQueryObject.addWhereCondition("tipo_proprietario = ?");
  1038.             sqlQueryObject.setANDLogicOperator(true);
  1039.             String sqlQuery = sqlQueryObject.createSQLQuery();
  1040.             stm = con.prepareStatement(sqlQuery);
  1041.             int index = 1;
  1042.             stm.setLong(index++, idProprietario);
  1043.             stm.setString(index++, nome);
  1044.             if(tipo!=null) {
  1045.                 stm.setString(index++, tipo);
  1046.             }
  1047.             if(ruolo!=null) {
  1048.                 stm.setString(index++, ruolo);
  1049.             }
  1050.             stm.setString(index++, tipoProprietario);
  1051.             rs = stm.executeQuery();
  1052.             if (rs.next())
  1053.                 idDoc = rs.getLong("id");
  1054.             rs.close();
  1055.             stm.close();

  1056.             return idDoc;
  1057.         }catch (Exception e) {
  1058.             throw new CoreException(e);
  1059.         }finally
  1060.         {
  1061.             //Chiudo statement and resultset
  1062.             JDBCUtilities.closeResources(rs, stm);

  1063.         }
  1064.     }
  1065.    
  1066.    
  1067.     public static long getIdProtocolProperty(String tipoProprietario, long idProprietario,String nome, Connection con,String tipoDB) throws CoreException{
  1068.         PreparedStatement stm = null;
  1069.         ResultSet rs = null;
  1070.         long idPP=-1;
  1071.         try
  1072.         {
  1073.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  1074.             sqlQueryObject.addFromTable(CostantiDB.PROTOCOL_PROPERTIES);
  1075.             sqlQueryObject.addSelectField("id");
  1076.             sqlQueryObject.addWhereCondition("tipo_proprietario = ?");
  1077.             sqlQueryObject.addWhereCondition("id_proprietario = ?");
  1078.             sqlQueryObject.addWhereCondition("name = ?");
  1079.             sqlQueryObject.setANDLogicOperator(true);
  1080.             String sqlQuery = sqlQueryObject.createSQLQuery();
  1081.             stm = con.prepareStatement(sqlQuery);
  1082.             stm.setString(1, tipoProprietario);
  1083.             stm.setLong(2, idProprietario);
  1084.             stm.setString(3, nome);
  1085.             rs = stm.executeQuery();
  1086.             if (rs.next())
  1087.                 idPP = rs.getLong("id");
  1088.             rs.close();
  1089.             stm.close();

  1090.             return idPP;
  1091.         }catch (Exception e) {
  1092.             throw new CoreException(e);
  1093.         }finally
  1094.         {
  1095.             //Chiudo statement and resultset
  1096.             JDBCUtilities.closeResources(rs, stm);

  1097.         }
  1098.     }
  1099.    
  1100.    
  1101.    
  1102.    
  1103.    
  1104.     public static long getIdRegistroPlugin(String nome, Connection con,String tipoDB) throws CoreException{
  1105.         PreparedStatement stm = null;
  1106.         ResultSet rs = null;
  1107.         long idRP=-1;
  1108.         try
  1109.         {
  1110.             if(nome==null) {
  1111.                 throw new CoreException("Nome non fornito");
  1112.             }
  1113.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  1114.             sqlQueryObject.addFromTable(CostantiDB.REGISTRO_PLUGINS);
  1115.             sqlQueryObject.addSelectField("id");
  1116.             sqlQueryObject.addWhereCondition("nome=?");
  1117.             sqlQueryObject.setANDLogicOperator(true);
  1118.             String sqlQuery = sqlQueryObject.createSQLQuery();
  1119.             stm = con.prepareStatement(sqlQuery);
  1120.             stm.setString(1, nome);
  1121.             rs = stm.executeQuery();
  1122.             if(rs.next()) {
  1123.                 idRP = rs.getLong("id");
  1124.             }
  1125.             rs.close();
  1126.             stm.close();
  1127.             rs=null;
  1128.             stm=null;
  1129.            
  1130.             return idRP;
  1131.         }catch (Exception e) {
  1132.             throw new CoreException(e);
  1133.         }finally
  1134.         {
  1135.             //Chiudo statement and resultset
  1136.             JDBCUtilities.closeResources(rs, stm);

  1137.         }
  1138.     }
  1139.    
  1140.    
  1141.     public static long getIdPlugin(String className, String label, String tipoPlugin, String tipo, Connection con,String tipoDB) throws CoreException{
  1142.         PreparedStatement stm = null;
  1143.         ResultSet rs = null;
  1144.         long idRP=-1;
  1145.         try
  1146.         {
  1147.             if(className==null) {
  1148.                 throw new CoreException("ClassName non fornito");
  1149.             }
  1150.             if(label==null) {
  1151.                 throw new CoreException("Label non fornito");
  1152.             }
  1153.             if(tipoPlugin==null) {
  1154.                 throw new CoreException("TipoPlugin non fornito");
  1155.             }
  1156.             if(tipo==null) {
  1157.                 throw new CoreException("Tipo non fornito");
  1158.             }
  1159.            
  1160.            
  1161.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  1162.             sqlQueryObject.addFromTable(CostantiDB.REGISTRO_CLASSI);
  1163.             sqlQueryObject.addSelectField("id");
  1164.             sqlQueryObject.addWhereCondition("class_name=?");
  1165.             sqlQueryObject.addWhereCondition("label=?");
  1166.             sqlQueryObject.addWhereCondition("tipo_plugin=?");
  1167.             sqlQueryObject.addWhereCondition("tipo=?");
  1168.             sqlQueryObject.setANDLogicOperator(true);
  1169.             String sqlQuery = sqlQueryObject.createSQLQuery();
  1170.             stm = con.prepareStatement(sqlQuery);
  1171.             stm.setString(1, className);
  1172.             stm.setString(2, label);
  1173.             stm.setString(3, tipoPlugin);
  1174.             stm.setString(4, tipo);
  1175.             rs = stm.executeQuery();
  1176.             if(rs.next()) {
  1177.                 idRP = rs.getLong("id");
  1178.             }
  1179.             rs.close();
  1180.             stm.close();
  1181.             rs=null;
  1182.             stm=null;
  1183.            
  1184.             return idRP;
  1185.         }catch (Exception e) {
  1186.             throw new CoreException(e);
  1187.         }finally
  1188.         {
  1189.             //Chiudo statement and resultset
  1190.             JDBCUtilities.closeResources(rs, stm);

  1191.         }
  1192.     }
  1193.    
  1194.    
  1195.     public static long getUrlInvocazioneRegola(String nome, Connection con,String tipoDB) throws CoreException{
  1196.         PreparedStatement stm = null;
  1197.         ResultSet rs = null;
  1198.         long idRP=-1;
  1199.         try
  1200.         {
  1201.             if(nome==null) {
  1202.                 throw new CoreException("Nome non fornito");
  1203.             }
  1204.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  1205.             sqlQueryObject.addFromTable(CostantiDB.CONFIG_URL_REGOLE);
  1206.             sqlQueryObject.addSelectField("id");
  1207.             sqlQueryObject.addWhereCondition("nome=?");
  1208.             sqlQueryObject.setANDLogicOperator(true);
  1209.             String sqlQuery = sqlQueryObject.createSQLQuery();
  1210.             stm = con.prepareStatement(sqlQuery);
  1211.             stm.setString(1, nome);
  1212.             rs = stm.executeQuery();
  1213.             if(rs.next()) {
  1214.                 idRP = rs.getLong("id");
  1215.             }
  1216.             rs.close();
  1217.             stm.close();
  1218.             rs=null;
  1219.             stm=null;
  1220.            
  1221.             return idRP;
  1222.         }catch (Exception e) {
  1223.             throw new CoreException(e);
  1224.         }finally
  1225.         {
  1226.             //Chiudo statement and resultset
  1227.             JDBCUtilities.closeResources(rs, stm);

  1228.         }
  1229.     }
  1230.    
  1231.    

  1232.     public static void setPropertiesForSearch(ISQLQueryObject sqlQueryObject, Map<String, String> properties, String tabellaPadre,
  1233.             String tabellaProprieta, String columnName, String columnValue, String columnFK) throws SQLQueryObjectException{
  1234.         if(properties!=null && properties.size()>0){
  1235.             String [] conditions = new String[properties.size()];
  1236.             int i = 0;
  1237.             for (String nome : properties.keySet()) {

  1238.                 String aliasTabella = "pp"+i+tabellaPadre;
  1239.                 sqlQueryObject.addFromTable(tabellaProprieta, aliasTabella);
  1240.                 sqlQueryObject.setANDLogicOperator(true);
  1241.                 sqlQueryObject.addWhereCondition(aliasTabella+"."+columnFK+"="+tabellaPadre+".id");
  1242.                 String valore = properties.get(nome);
  1243.                                
  1244.                 if(conditions[i]!=null){
  1245.                     conditions[i] = conditions[i] + " AND ";
  1246.                 }
  1247.                 else {
  1248.                     conditions[i] = "";
  1249.                 }
  1250.                 conditions[i] = conditions[i] + " " + aliasTabella+"."+columnName+"=?";
  1251.                
  1252.                 if(valore!=null){
  1253.                     if(conditions[i]!=null){
  1254.                         conditions[i] = conditions[i] + " AND ";
  1255.                     }
  1256.                     else {
  1257.                         conditions[i] = "";
  1258.                     }
  1259.                     conditions[i] = conditions[i] + " " + aliasTabella+"."+columnValue+"=?";
  1260.                 }
  1261.                 else {
  1262.                     if(conditions[i]!=null){
  1263.                         conditions[i] = conditions[i] + " AND ";
  1264.                     }
  1265.                     else {
  1266.                         conditions[i] = "";
  1267.                     }
  1268.                     conditions[i] = conditions[i] + " " + aliasTabella+"."+columnValue+" is null";
  1269.                 }
  1270.                
  1271.                 // casoSpecialeValoreNull
  1272.                 ISQLQueryObject sqlQueryObjectPropertyNotExists = null;
  1273.                 // in un caso dove il valore non e' definito nel database ci possono essere due casistiche:
  1274.                 // 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)
  1275.                 // 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.
  1276.                 if(valore==null){
  1277.                    
  1278.                     ISQLQueryObject sqlQueryObjectPropertyNotExistsInternal = sqlQueryObject.newSQLQueryObject();
  1279.                     String aliasTabellaNotExists =  "not_exists_"+aliasTabella;
  1280.                     sqlQueryObjectPropertyNotExistsInternal.addFromTable(tabellaProprieta, aliasTabellaNotExists);
  1281.                     sqlQueryObjectPropertyNotExistsInternal.addSelectField(aliasTabellaNotExists, "id");
  1282.                     sqlQueryObjectPropertyNotExistsInternal.addWhereCondition(aliasTabellaNotExists+"."+columnFK+"="+aliasTabella+"."+columnFK);
  1283.                     sqlQueryObjectPropertyNotExistsInternal.addWhereCondition(aliasTabellaNotExists+"."+columnName+"=?");
  1284.                     sqlQueryObjectPropertyNotExistsInternal.setANDLogicOperator(true);
  1285.                    
  1286.                     sqlQueryObjectPropertyNotExists = sqlQueryObject.newSQLQueryObject();
  1287.                     sqlQueryObjectPropertyNotExists.addWhereExistsCondition(true, sqlQueryObjectPropertyNotExistsInternal);

  1288.                     conditions[i] = "( " + conditions[i] + " ) OR ( " + sqlQueryObjectPropertyNotExists.createSQLConditions() + " )";
  1289.                 }
  1290.                 i++;
  1291.             }
  1292.             sqlQueryObject.addWhereCondition(true, conditions);
  1293.         }
  1294.     }
  1295.    
  1296.     public static void setPropertiesForSearch(PreparedStatement stmt, int index,
  1297.             Map<String, String> properties,
  1298.             String tipoDatabase, Logger log) throws SQLQueryObjectException, SQLException, JDBCAdapterException, UtilsException{
  1299.        
  1300.         GenericJDBCParameterUtilities jdbcParameterUtilities = new GenericJDBCParameterUtilities(TipiDatabase.toEnumConstant(tipoDatabase));
  1301.        
  1302.         if(properties!=null && properties.size()>0){
  1303.             int i = 0;
  1304.             for (String nome : properties.keySet()) {
  1305.                
  1306.                 String valore = properties.get(nome);
  1307.                
  1308.                 log.debug("Proprieta["+i+"] nome stmt.setString("+nome+")");
  1309.                 stmt.setString(index++, nome);
  1310.                                
  1311.                 if(valore!=null){
  1312.                     log.debug("Proprieta["+i+"] valore stmt.setString("+valore+")");
  1313.                     jdbcParameterUtilities.setParameter(stmt, index++, valore, String.class);
  1314.                 }
  1315.                
  1316.                 // casoSpecialeValoreNull
  1317.                 // in un caso dove il valore non e' definito nel database ci possono essere due casistiche:
  1318.                 // 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)
  1319.                 // 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.
  1320.                 if(valore==null){
  1321.                     log.debug("Proprieta["+i+"] nome stmt.setString("+nome+")");
  1322.                     stmt.setString(index++, nome);
  1323.                 }
  1324.                
  1325.                 i++;
  1326.             }
  1327.         }
  1328.     }


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

  1332.         ISQLQueryObject sql = SQLObjectFactory.createSQLQueryObject(tipoDB);
  1333.         sql.addFromTable(CostantiDB.CONNETTORI);
  1334.         sql.setANDLogicOperator(true);
  1335.         sql.addWhereCondition(CostantiDB.SERVIZI_APPLICATIVI+".id_connettore_inv="+CostantiDB.CONNETTORI+".id");
  1336.         setFiltriConnettore(sql, tipoDB,
  1337.                 tipoConnettore, endpointType, tipoConnettoreIntegrationManager,
  1338.                 filtroConnettoreTokenPolicy, filtroConnettoreEndpoint, filtroConnettoreKeystore, filtroConnettoreDebug,
  1339.                 CostantiDB.SERVIZI_APPLICATIVI);
  1340.         sqlQueryObject.addWhereExistsCondition(false, sql);
  1341.        
  1342.     }
  1343.     public static void setFiltriConnettoreErogazione(ISQLQueryObject sqlQueryObject, String tipoDB,
  1344.             TipiConnettore tipoConnettore, String endpointType, boolean tipoConnettoreIntegrationManager,
  1345.             String filtroConnettoreTokenPolicy, String filtroConnettoreEndpoint, String filtroConnettoreKeystore, String filtroConnettoreDebug) throws Exception {

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

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

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

  2268.         if(Filtri.FILTRO_CONFIGURAZIONE_TRANSAZIONI_VALORE_DEFAULT.equals(filtroConfigurazioneTransazioni)) {
  2269.             sqlQueryQuery.addWhereCondition(aliasCONFIGPORTA+".tracciamento_stato is NULL OR "+aliasCONFIGPORTA+".tracciamento_stato='"+CostantiDB.STATO_FUNZIONALITA_DISABILITATO+"'");
  2270.         }
  2271.         else {
  2272.             sqlQueryQuery.addWhereCondition(aliasCONFIGPORTA+".tracciamento_stato='"+CostantiDB.STATO_FUNZIONALITA_ABILITATO+"'");
  2273.            
  2274.             String aliasTRANSAZIONICONFIGDB = "trans_cdb";
  2275.             ISQLQueryObject sqlDB = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2276.             sqlDB.addFromTable(CostantiDB.TRACCIAMENTO_CONFIGURAZIONE, aliasTRANSAZIONICONFIGDB);
  2277.             sqlDB.addSelectField(aliasTRANSAZIONICONFIGDB, CostantiDB.COLUMN_ID_PROPRIETARIO);
  2278.             sqlDB.setANDLogicOperator(true);
  2279.             sqlDB.addWhereCondition(aliasCONFIGPORTA+".id="+aliasTRANSAZIONICONFIGDB+"."+CostantiDB.COLUMN_ID_PROPRIETARIO);
  2280.             sqlDB.addWhereCondition(aliasTRANSAZIONICONFIGDB+".proprietario='"+
  2281.                     (erogazioni ? CostantiDB.TRACCIAMENTO_CONFIGURAZIONE_PROPRIETARIO_PA : CostantiDB.TRACCIAMENTO_CONFIGURAZIONE_PROPRIETARIO_PD)+"'");    
  2282.             sqlDB.addWhereCondition(aliasTRANSAZIONICONFIGDB+".tipo='"+CostantiDB.TRACCIAMENTO_CONFIGURAZIONE_TIPO_DB+"'");
  2283.            
  2284.             String aliasTRANSAZIONICONFIGFILETRACE = "trans_cft";
  2285.             ISQLQueryObject sqlFileTrace = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2286.             sqlFileTrace.addFromTable(CostantiDB.TRACCIAMENTO_CONFIGURAZIONE, aliasTRANSAZIONICONFIGFILETRACE);
  2287.             sqlFileTrace.addSelectField(aliasTRANSAZIONICONFIGFILETRACE, CostantiDB.COLUMN_ID_PROPRIETARIO);
  2288.             sqlFileTrace.setANDLogicOperator(true);
  2289.             sqlFileTrace.addWhereCondition(aliasCONFIGPORTA+".id="+aliasTRANSAZIONICONFIGFILETRACE+"."+CostantiDB.COLUMN_ID_PROPRIETARIO);
  2290.             sqlFileTrace.addWhereCondition(aliasTRANSAZIONICONFIGFILETRACE+".proprietario='"+
  2291.                     (erogazioni ? CostantiDB.TRACCIAMENTO_CONFIGURAZIONE_PROPRIETARIO_PA : CostantiDB.TRACCIAMENTO_CONFIGURAZIONE_PROPRIETARIO_PD)+"'");    
  2292.             sqlFileTrace.addWhereCondition(aliasTRANSAZIONICONFIGFILETRACE+".tipo='"+CostantiDB.TRACCIAMENTO_CONFIGURAZIONE_TIPO_FILETRACE+"'");    
  2293.        
  2294.             if(Filtri.FILTRO_CONFIGURAZIONE_TRANSAZIONI_VALORE_RIDEFINITO_ABILITATO_DATABASE_O_FILETRACE.equals(filtroConfigurazioneTransazioni)
  2295.                     ||
  2296.                     Filtri.FILTRO_CONFIGURAZIONE_TRANSAZIONI_VALORE_RIDEFINITO_ABILITATO_SOLO_DATABASE.equals(filtroConfigurazioneTransazioni)
  2297.                     ||
  2298.                     Filtri.FILTRO_CONFIGURAZIONE_TRANSAZIONI_VALORE_RIDEFINITO_ABILITATO_DATABASE_E_FILETRACE.equals(filtroConfigurazioneTransazioni)) {
  2299.                 sqlDB.addWhereCondition(aliasTRANSAZIONICONFIGDB+".stato<>'"+CostantiDB.STATO_FUNZIONALITA_DISABILITATO+"'");  
  2300.             }
  2301.             else {
  2302.                 sqlDB.addWhereCondition(aliasTRANSAZIONICONFIGDB+".stato='"+CostantiDB.STATO_FUNZIONALITA_DISABILITATO+"'");    
  2303.             }
  2304.            
  2305.             if(Filtri.FILTRO_CONFIGURAZIONE_TRANSAZIONI_VALORE_RIDEFINITO_ABILITATO_DATABASE_O_FILETRACE.equals(filtroConfigurazioneTransazioni)
  2306.                 ||
  2307.                 Filtri.FILTRO_CONFIGURAZIONE_TRANSAZIONI_VALORE_RIDEFINITO_ABILITATO_SOLO_FILETRACE.equals(filtroConfigurazioneTransazioni)
  2308.                 ||
  2309.                 Filtri.FILTRO_CONFIGURAZIONE_TRANSAZIONI_VALORE_RIDEFINITO_ABILITATO_DATABASE_E_FILETRACE.equals(filtroConfigurazioneTransazioni)) {
  2310.                 sqlFileTrace.addWhereCondition(aliasTRANSAZIONICONFIGFILETRACE+".stato<>'"+CostantiDB.STATO_FUNZIONALITA_DISABILITATO+"'");
  2311.             }
  2312.             else {
  2313.                 sqlFileTrace.addWhereCondition(aliasTRANSAZIONICONFIGFILETRACE+".stato='"+CostantiDB.STATO_FUNZIONALITA_DISABILITATO+"'");  
  2314.             }
  2315.            
  2316.             if(Filtri.FILTRO_CONFIGURAZIONE_TRANSAZIONI_VALORE_RIDEFINITO_ABILITATO_DATABASE_O_FILETRACE.equals(filtroConfigurazioneTransazioni)) {
  2317.                 ISQLQueryObject sqlUtilsDB = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2318.                 ISQLQueryObject sqlUtilsFileTrace = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2319.                 sqlQueryQuery.addWhereCondition(false,
  2320.                         sqlUtilsDB.getWhereExistsCondition(false, sqlDB),
  2321.                         sqlUtilsFileTrace.getWhereExistsCondition(false, sqlFileTrace));
  2322.             }
  2323.             else if(Filtri.FILTRO_CONFIGURAZIONE_TRANSAZIONI_VALORE_RIDEFINITO_ABILITATO_SOLO_DATABASE.equals(filtroConfigurazioneTransazioni)
  2324.                     ||
  2325.                     Filtri.FILTRO_CONFIGURAZIONE_TRANSAZIONI_VALORE_RIDEFINITO_ABILITATO_SOLO_FILETRACE.equals(filtroConfigurazioneTransazioni)
  2326.                     ||
  2327.                     Filtri.FILTRO_CONFIGURAZIONE_TRANSAZIONI_VALORE_RIDEFINITO_ABILITATO_DATABASE_E_FILETRACE.equals(filtroConfigurazioneTransazioni)
  2328.                     ||
  2329.                     Filtri.FILTRO_CONFIGURAZIONE_TRANSAZIONI_VALORE_RIDEFINITO_DISABILITATO.equals(filtroConfigurazioneTransazioni)) {
  2330.                 sqlQueryQuery.addWhereExistsCondition(false, sqlDB);
  2331.                 sqlQueryQuery.addWhereExistsCondition(false, sqlFileTrace);
  2332.             }
  2333.         }
  2334.        
  2335.     }
  2336.     public static void addFiltroConfigurazioneDump(String tipoDB,
  2337.             String aliasCONFIGPORTA,
  2338.             String filtroConfigurazioneDumpTipo, boolean erogazioni,
  2339.             ISQLQueryObject sqlQueryQuery) throws SQLQueryObjectException {

  2340.         String aliasDUMPCONFIG = "dump_c";
  2341.        
  2342.         ISQLQueryObject sql = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2343.         sql.addFromTable(CostantiDB.DUMP_CONFIGURAZIONE, aliasDUMPCONFIG);
  2344.         sql.addSelectField(aliasDUMPCONFIG, CostantiDB.COLUMN_ID_PROPRIETARIO);
  2345.         sql.setANDLogicOperator(true);
  2346.         if(erogazioni) {
  2347.             sql.addWhereCondition(aliasCONFIGPORTA+".id="+aliasDUMPCONFIG+"."+CostantiDB.COLUMN_ID_PROPRIETARIO);
  2348.             sql.addWhereLikeCondition(aliasDUMPCONFIG+".proprietario", "pa", false, false, false);
  2349.         }
  2350.         else {
  2351.             sql.addWhereCondition(aliasCONFIGPORTA+".id="+aliasDUMPCONFIG+"."+CostantiDB.COLUMN_ID_PROPRIETARIO);
  2352.             sql.addWhereLikeCondition(aliasDUMPCONFIG+".proprietario", "pd", false, false, false);
  2353.         }  
  2354.        
  2355.         //Prepariamo anzi una utility per ogni singola voce e poi ad ogni if la si chiama!
  2356.        
  2357.         boolean and = true;
  2358.         boolean or = false;
  2359.         boolean notExists = true;
  2360.         boolean exists = false;
  2361.        
  2362.         if(Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_DEFAULT.equals(filtroConfigurazioneDumpTipo)) {
  2363.             sqlQueryQuery.addWhereExistsCondition(notExists, sql);  
  2364.         }
  2365.         else if(Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO.equals(filtroConfigurazioneDumpTipo)
  2366.                 ||
  2367.                 Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER.equals(filtroConfigurazioneDumpTipo)
  2368.                 ||
  2369.                 Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_RICHIESTA.equals(filtroConfigurazioneDumpTipo)
  2370.                 ||
  2371.                 Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RICHIESTA.equals(filtroConfigurazioneDumpTipo)
  2372.                 ||
  2373.                 Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_RICHIESTA_INGRESSO.equals(filtroConfigurazioneDumpTipo)
  2374.                 ||
  2375.                 Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RICHIESTA_INGRESSO.equals(filtroConfigurazioneDumpTipo)
  2376.                 ||
  2377.                 Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_RICHIESTA_USCITA.equals(filtroConfigurazioneDumpTipo)
  2378.                 ||
  2379.                 Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RICHIESTA_USCITA.equals(filtroConfigurazioneDumpTipo)
  2380.                 ||
  2381.                 Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_RISPOSTA.equals(filtroConfigurazioneDumpTipo)
  2382.                 ||
  2383.                 Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RISPOSTA.equals(filtroConfigurazioneDumpTipo)
  2384.                 ||
  2385.                 Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_RISPOSTA_INGRESSO.equals(filtroConfigurazioneDumpTipo)
  2386.                 ||
  2387.                 Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RISPOSTA_INGRESSO.equals(filtroConfigurazioneDumpTipo)
  2388.                 ||
  2389.                 Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_RISPOSTA_USCITA.equals(filtroConfigurazioneDumpTipo)
  2390.                 ||
  2391.                 Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RISPOSTA_USCITA.equals(filtroConfigurazioneDumpTipo)
  2392.                 ){
  2393.            
  2394.             boolean soloHeader = (
  2395.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER.equals(filtroConfigurazioneDumpTipo)
  2396.                     ||
  2397.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RICHIESTA.equals(filtroConfigurazioneDumpTipo)
  2398.                     ||
  2399.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RICHIESTA_INGRESSO.equals(filtroConfigurazioneDumpTipo)
  2400.                     ||
  2401.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RICHIESTA_USCITA.equals(filtroConfigurazioneDumpTipo)
  2402.                     ||
  2403.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RISPOSTA.equals(filtroConfigurazioneDumpTipo)
  2404.                     ||
  2405.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RISPOSTA_INGRESSO.equals(filtroConfigurazioneDumpTipo)
  2406.                     ||
  2407.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RISPOSTA_USCITA.equals(filtroConfigurazioneDumpTipo)
  2408.                     );
  2409.             BooleanNullable payload = soloHeader ? BooleanNullable.FALSE() : BooleanNullable.TRUE();
  2410.             BooleanNullable headers = BooleanNullable.TRUE();
  2411.            
  2412.             boolean condizionePayloadHeaders = soloHeader ? and : or;
  2413.            
  2414.             List<ISQLQueryObject> sqlMessages = new ArrayList<>();
  2415.            
  2416.             if(Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO.equals(filtroConfigurazioneDumpTipo)
  2417.                     ||
  2418.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER.equals(filtroConfigurazioneDumpTipo)
  2419.                     ||
  2420.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_RICHIESTA.equals(filtroConfigurazioneDumpTipo)
  2421.                     ||
  2422.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RICHIESTA.equals(filtroConfigurazioneDumpTipo)
  2423.                     ||
  2424.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_RICHIESTA_INGRESSO.equals(filtroConfigurazioneDumpTipo)
  2425.                     ||
  2426.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RICHIESTA_INGRESSO.equals(filtroConfigurazioneDumpTipo)
  2427.                     ) {
  2428.                 ISQLQueryObject sqlRichiestaIngresso = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2429.                 setFiltriDumpRegolaConfigurazioneDumpEngine(tipoDB,
  2430.                         aliasDUMPCONFIG,
  2431.                         "id_richiesta_ingresso", payload, headers, condizionePayloadHeaders,
  2432.                         sqlRichiestaIngresso, exists);
  2433.                 sqlMessages.add(sqlRichiestaIngresso);
  2434.             }
  2435.            
  2436.             if(Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO.equals(filtroConfigurazioneDumpTipo)
  2437.                     ||
  2438.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER.equals(filtroConfigurazioneDumpTipo)
  2439.                     ||
  2440.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_RICHIESTA.equals(filtroConfigurazioneDumpTipo)
  2441.                     ||
  2442.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RICHIESTA.equals(filtroConfigurazioneDumpTipo)
  2443.                     ||
  2444.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_RICHIESTA_USCITA.equals(filtroConfigurazioneDumpTipo)
  2445.                     ||
  2446.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RICHIESTA_USCITA.equals(filtroConfigurazioneDumpTipo)
  2447.                     ) {
  2448.                 ISQLQueryObject sqlRichiestaUscita = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2449.                 setFiltriDumpRegolaConfigurazioneDumpEngine(tipoDB,
  2450.                         aliasDUMPCONFIG,
  2451.                         "id_richiesta_uscita", payload, headers, condizionePayloadHeaders,
  2452.                         sqlRichiestaUscita, exists);
  2453.                 sqlMessages.add(sqlRichiestaUscita);
  2454.             }
  2455.            
  2456.             if(Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO.equals(filtroConfigurazioneDumpTipo)
  2457.                     ||
  2458.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER.equals(filtroConfigurazioneDumpTipo)
  2459.                     ||
  2460.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_RISPOSTA.equals(filtroConfigurazioneDumpTipo)
  2461.                     ||
  2462.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RISPOSTA.equals(filtroConfigurazioneDumpTipo)
  2463.                     ||
  2464.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_RISPOSTA_INGRESSO.equals(filtroConfigurazioneDumpTipo)
  2465.                     ||
  2466.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RISPOSTA_INGRESSO.equals(filtroConfigurazioneDumpTipo)
  2467.                     ) {
  2468.                 ISQLQueryObject sqlRispostaIngresso = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2469.                 setFiltriDumpRegolaConfigurazioneDumpEngine(tipoDB,
  2470.                         aliasDUMPCONFIG,
  2471.                         "id_risposta_ingresso", payload, headers, condizionePayloadHeaders,
  2472.                         sqlRispostaIngresso, exists);
  2473.                 sqlMessages.add(sqlRispostaIngresso);
  2474.             }
  2475.            
  2476.             if(Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO.equals(filtroConfigurazioneDumpTipo)
  2477.                     ||
  2478.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER.equals(filtroConfigurazioneDumpTipo)
  2479.                     ||
  2480.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_RISPOSTA.equals(filtroConfigurazioneDumpTipo)
  2481.                     ||
  2482.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RISPOSTA.equals(filtroConfigurazioneDumpTipo)
  2483.                     ||
  2484.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_RISPOSTA_USCITA.equals(filtroConfigurazioneDumpTipo)
  2485.                     ||
  2486.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_ABILITATO_SOLO_HEADER_RISPOSTA_USCITA.equals(filtroConfigurazioneDumpTipo)
  2487.                     ) {
  2488.                 ISQLQueryObject sqlRispostaUscita = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2489.                 setFiltriDumpRegolaConfigurazioneDumpEngine(tipoDB,
  2490.                         aliasDUMPCONFIG,
  2491.                         "id_risposta_uscita", payload, headers, condizionePayloadHeaders,
  2492.                         sqlRispostaUscita, exists);
  2493.                 sqlMessages.add(sqlRispostaUscita);
  2494.             }
  2495.            
  2496.             setFiltriDumpRegolaConfigurazioneDumpEngine(tipoDB,
  2497.                     sql, or,
  2498.                     sqlMessages.toArray(new ISQLQueryObject[1]));
  2499.             sqlQueryQuery.addWhereExistsCondition(exists, sql);
  2500.         }
  2501.         else if(Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_DISABILITATO.equals(filtroConfigurazioneDumpTipo)
  2502.                 ||
  2503.                 Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_DISABILITATO_RICHIESTA.equals(filtroConfigurazioneDumpTipo)
  2504.                 ||
  2505.                 Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_DISABILITATO_RISPOSTA.equals(filtroConfigurazioneDumpTipo)
  2506.                 ){
  2507.            
  2508.             BooleanNullable payload = BooleanNullable.FALSE();
  2509.             BooleanNullable headers = BooleanNullable.FALSE();
  2510.            
  2511.             boolean condizionePayloadHeaders = and;
  2512.            
  2513.             List<ISQLQueryObject> sqlMessages = new ArrayList<>();
  2514.            
  2515.             if(Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_DISABILITATO.equals(filtroConfigurazioneDumpTipo)
  2516.                     ||
  2517.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_DISABILITATO_RICHIESTA.equals(filtroConfigurazioneDumpTipo)
  2518.                     ) {
  2519.                 ISQLQueryObject sqlRichiestaIngresso = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2520.                 setFiltriDumpRegolaConfigurazioneDumpEngine(tipoDB,
  2521.                         aliasDUMPCONFIG,
  2522.                         "id_richiesta_ingresso", payload, headers, condizionePayloadHeaders,
  2523.                         sqlRichiestaIngresso, exists);
  2524.                 sqlMessages.add(sqlRichiestaIngresso);
  2525.                
  2526.                 ISQLQueryObject sqlRichiestaUscita = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2527.                 setFiltriDumpRegolaConfigurazioneDumpEngine(tipoDB,
  2528.                         aliasDUMPCONFIG,
  2529.                         "id_richiesta_uscita", payload, headers, condizionePayloadHeaders,
  2530.                         sqlRichiestaUscita, exists);
  2531.                 sqlMessages.add(sqlRichiestaUscita);
  2532.             }

  2533.             if(Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_DISABILITATO.equals(filtroConfigurazioneDumpTipo)
  2534.                     ||
  2535.                     Filtri.FILTRO_CONFIGURAZIONE_DUMP_TIPO_VALORE_RIDEFINITO_DISABILITATO_RISPOSTA.equals(filtroConfigurazioneDumpTipo)
  2536.                     ) {
  2537.                 ISQLQueryObject sqlRispostaIngresso = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2538.                 setFiltriDumpRegolaConfigurazioneDumpEngine(tipoDB,
  2539.                         aliasDUMPCONFIG,
  2540.                         "id_risposta_ingresso", payload, headers, condizionePayloadHeaders,
  2541.                         sqlRispostaIngresso, exists);
  2542.                 sqlMessages.add(sqlRispostaIngresso);
  2543.            
  2544.                 ISQLQueryObject sqlRispostaUscita = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2545.                 setFiltriDumpRegolaConfigurazioneDumpEngine(tipoDB,
  2546.                         aliasDUMPCONFIG,
  2547.                         "id_risposta_uscita", payload, headers, condizionePayloadHeaders,
  2548.                         sqlRispostaUscita, exists);
  2549.                 sqlMessages.add(sqlRispostaUscita);
  2550.             }
  2551.            
  2552.             setFiltriDumpRegolaConfigurazioneDumpEngine(tipoDB,
  2553.                     sql, and,
  2554.                     sqlMessages.toArray(new ISQLQueryObject[1]));
  2555.             sqlQueryQuery.addWhereExistsCondition(exists, sql);
  2556.         }
  2557.        
  2558.     }
  2559.     private static void setFiltriDumpRegolaConfigurazioneDumpEngine(String tipoDB,
  2560.             ISQLQueryObject sqlQueryObjectConditions, boolean and,
  2561.             ISQLQueryObject ... sqlQueryObjectMessage) throws SQLQueryObjectException {    
  2562.         List<String> conditions = new ArrayList<>();
  2563.        
  2564.         if(tipoDB!=null) {
  2565.             // ignore
  2566.         }
  2567.        
  2568.         if(sqlQueryObjectMessage!=null && sqlQueryObjectMessage.length>0) {
  2569.             for (ISQLQueryObject sql : sqlQueryObjectMessage) {
  2570.                 conditions.add(sql.createSQLConditions());  
  2571.             }
  2572.         }
  2573.        
  2574.         if(conditions.isEmpty()) {
  2575.             throw new SQLQueryObjectException("Usage error");
  2576.         }
  2577.         sqlQueryObjectConditions.addWhereCondition(and, conditions.toArray(new String[1]));
  2578.     }
  2579.     private static void setFiltriDumpRegolaConfigurazioneDumpEngine(String tipoDB,
  2580.             String aliasDUMPCONFIG,
  2581.             String colonna, BooleanNullable payload, BooleanNullable headers, boolean and,
  2582.             ISQLQueryObject sqlQueryObjectConditions, boolean notExists) throws SQLQueryObjectException {
  2583.        
  2584.         if(tipoDB!=null) {
  2585.             // ignore
  2586.         }
  2587.        
  2588.         String aliasDUMPCONFIGREGOLE = "dump_cr";
  2589.        
  2590.         ISQLQueryObject sql = SQLObjectFactory.createSQLQueryObject(tipoDB);
  2591.         sql.addSelectField("id");
  2592.         sql.addFromTable(CostantiDB.DUMP_CONFIGURAZIONE_REGOLA, aliasDUMPCONFIGREGOLE);
  2593.         sql.setANDLogicOperator(true);
  2594.         sql.addWhereCondition(aliasDUMPCONFIG+"."+colonna+"="+aliasDUMPCONFIGREGOLE+".id");
  2595.         if(payload!=null && payload.getValue()!=null &&
  2596.                 headers!=null && headers.getValue()!=null) {
  2597.             sql.addWhereCondition(and,
  2598.                     sql.getWhereLikeCondition("payload", payload.getValue()!=null && payload.getValue().booleanValue() ? "abilitato" : "disabilitato", false, false, false),
  2599.                     sql.getWhereLikeCondition("headers", headers.getValue()!=null && headers.getValue().booleanValue() ? "abilitato" : "disabilitato", false, false, false));
  2600.         }
  2601.         else if(payload!=null && payload.getValue()!=null) {
  2602.             sql.addWhereLikeCondition("payload", payload.getValue()!=null && payload.getValue().booleanValue() ? "abilitato" : "disabilitato", false, false, false);
  2603.         }
  2604.         else if(headers!=null && headers.getValue()!=null) {
  2605.             sql.addWhereLikeCondition("headers", headers.getValue()!=null && headers.getValue().booleanValue() ? "abilitato" : "disabilitato", false, false, false);
  2606.         }
  2607.         else {
  2608.             throw new SQLQueryObjectException("Usage error");
  2609.         }
  2610.         sqlQueryObjectConditions.addWhereExistsCondition(notExists, sql);
  2611.     }
  2612.    
  2613.    

  2614.     /**
  2615.      * Utility per formattare la string sql con i parametri passati, e stamparla per debug
  2616.      * @param sql la string sql utilizzata nel prepared statement
  2617.      * @param params i parametri da inserire nella stringa che sostituiranno i '?'
  2618.      * @return La stringa sql con al posto dei '?' ha i parametri passati
  2619.      */
  2620.     public static String formatSQLString(String sql,Object ... params)
  2621.     {
  2622.         String res = sql;

  2623.         for (int i = 0; i < params.length; i++)
  2624.         {
  2625.             res=res.replaceFirst("\\?", "{"+i+"}");
  2626.         }

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

  2628.     }


  2629.    
  2630.    
  2631.    
  2632.     public static List<String> convertToList(String v){
  2633.         List<String> l = new ArrayList<>();
  2634.         if(v!=null && !"".equals(v)) {
  2635.             if(v.contains(",")) {
  2636.                 String [] tmp = v.split(",");
  2637.                 for (int i = 0; i < tmp.length; i++) {
  2638.                     l.add(tmp[i].trim());
  2639.                 }
  2640.             }else {
  2641.                 l.add(v.trim());
  2642.             }
  2643.         }
  2644.         return l;
  2645.     }
  2646. }