DriverConfigurazioneDB_porteDelegateLIB.java

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

  21. import static org.openspcoop2.core.constants.CostantiDB.CREATE;
  22. import static org.openspcoop2.core.constants.CostantiDB.DELETE;
  23. import static org.openspcoop2.core.constants.CostantiDB.UPDATE;

  24. import java.sql.Connection;
  25. import java.sql.PreparedStatement;
  26. import java.sql.ResultSet;
  27. import java.sql.SQLException;
  28. import java.sql.Timestamp;
  29. import java.util.List;

  30. import org.openspcoop2.core.byok.BYOKUtilities;
  31. import org.openspcoop2.core.byok.BYOKWrappedValue;
  32. import org.openspcoop2.core.byok.IDriverBYOK;
  33. import org.openspcoop2.core.commons.DBUtils;
  34. import org.openspcoop2.core.commons.IExtendedInfo;
  35. import org.openspcoop2.core.config.AttributeAuthority;
  36. import org.openspcoop2.core.config.ConfigurazionePortaHandler;
  37. import org.openspcoop2.core.config.CorrelazioneApplicativa;
  38. import org.openspcoop2.core.config.CorrelazioneApplicativaElemento;
  39. import org.openspcoop2.core.config.CorrelazioneApplicativaRisposta;
  40. import org.openspcoop2.core.config.CorrelazioneApplicativaRispostaElemento;
  41. import org.openspcoop2.core.config.CorsConfigurazione;
  42. import org.openspcoop2.core.config.GestioneToken;
  43. import org.openspcoop2.core.config.MessageSecurity;
  44. import org.openspcoop2.core.config.MessageSecurityFlow;
  45. import org.openspcoop2.core.config.MessageSecurityFlowParameter;
  46. import org.openspcoop2.core.config.MtomProcessor;
  47. import org.openspcoop2.core.config.MtomProcessorFlow;
  48. import org.openspcoop2.core.config.MtomProcessorFlowParameter;
  49. import org.openspcoop2.core.config.PortaDelegata;
  50. import org.openspcoop2.core.config.PortaDelegataAzione;
  51. import org.openspcoop2.core.config.PortaDelegataServizio;
  52. import org.openspcoop2.core.config.PortaDelegataServizioApplicativo;
  53. import org.openspcoop2.core.config.PortaDelegataSoggettoErogatore;
  54. import org.openspcoop2.core.config.Proprieta;
  55. import org.openspcoop2.core.config.ResponseCachingConfigurazione;
  56. import org.openspcoop2.core.config.ResponseCachingConfigurazioneRegola;
  57. import org.openspcoop2.core.config.Ruolo;
  58. import org.openspcoop2.core.config.Scope;
  59. import org.openspcoop2.core.config.TracciamentoConfigurazione;
  60. import org.openspcoop2.core.config.TracciamentoConfigurazioneFiletrace;
  61. import org.openspcoop2.core.config.constants.MTOMProcessorType;
  62. import org.openspcoop2.core.config.constants.PortaDelegataAzioneIdentificazione;
  63. import org.openspcoop2.core.config.constants.StatoFunzionalita;
  64. import org.openspcoop2.core.config.constants.StatoFunzionalitaCacheDigestQueryParameter;
  65. import org.openspcoop2.core.config.driver.DriverConfigurazioneException;
  66. import org.openspcoop2.core.config.driver.ExtendedInfoManager;
  67. import org.openspcoop2.core.constants.CRUDType;
  68. import org.openspcoop2.core.constants.CostantiDB;
  69. import org.openspcoop2.utils.date.DateManager;
  70. import org.openspcoop2.utils.jdbc.JDBCUtilities;
  71. import org.openspcoop2.utils.sql.ISQLQueryObject;
  72. import org.openspcoop2.utils.sql.SQLObjectFactory;

  73. /**
  74.  * DriverConfigurazioneDB_soggettiLIB
  75.  *
  76.  * @author Stefano Corallo - corallo@link.it
  77.  * @author $Author$
  78.  * @version $Rev$, $Date$
  79.  */
  80. public class DriverConfigurazioneDB_porteDelegateLIB {



  81.    
  82.     /**
  83.      *
  84.      * @param type
  85.      * @param aPD
  86.      * @param con
  87.      * @throws DriverConfigurazioneException
  88.      */
  89.     public static long CRUDPortaDelegata(int type, PortaDelegata aPD, Connection con, IDriverBYOK driverBYOK) throws DriverConfigurazioneException {

  90.         if (aPD == null)
  91.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB_LIB::CRUDPortaDelegata] Porta Delegata non valida.");

  92.         // parametri necessari
  93.         String nomePorta = aPD.getNome();
  94.         String nomeProprietario = aPD.getNomeSoggettoProprietario();
  95.         String tipoProprietario = aPD.getTipoSoggettoProprietario();
  96.         if (nomePorta == null || nomePorta.equals(""))
  97.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB_LIB::CRUDPortaDelegata] Nome della Porta Delegata non valido.");
  98.         if (nomeProprietario == null || nomeProprietario.equals(""))
  99.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB_LIB::CRUDPortaDelegata] Nome proprietario Porta Delegata non valido.");
  100.         if (tipoProprietario == null || tipoProprietario.equals(""))
  101.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB_LIB::CRUDPortaDelegata] Tipo proprietario della Porta Delegata non valido.");

  102.         PreparedStatement stm = null;
  103.         String sqlQuery;
  104.         ResultSet rs = null;

  105.         String autenticazione = aPD.getAutenticazione();
  106.         String autorizzazione = aPD.getAutorizzazione();
  107.         String autorizzazioneXacmlPolicy = aPD.getXacmlPolicy();
  108.         String autorizzazioneContenuto = aPD.getAutorizzazioneContenuto();
  109.         String descrizione = aPD.getDescrizione();
  110.         GestioneToken gestioneToken = aPD.getGestioneToken();

  111.         PortaDelegataAzione azione = aPD.getAzione();
  112.         long idAzione = ((azione != null && azione.getId() != null) ? azione.getId() : -1);

  113.         long idSoggettoProprietario;
  114.         try {
  115.             idSoggettoProprietario = DBUtils.getIdSoggetto(nomeProprietario, tipoProprietario, con, DriverConfigurazioneDBLib.tipoDB,DriverConfigurazioneDBLib.tabellaSoggetti);
  116.         } catch (Exception e1) {
  117.             throw new DriverConfigurazioneException(e1);
  118.         }
  119.         long idPortaDelegata = -1;

  120.         PortaDelegataSoggettoErogatore soggErogatore = aPD.getSoggettoErogatore();
  121.         long idSoggettoErogatore = ((soggErogatore != null && soggErogatore.getId() != null) ? soggErogatore.getId() : -1);
  122.         /**System.out.println("PRIMA PD SOGGETTO: "+idSoggettoErogatore);*/
  123.         /** SEMPRE, VA AGGIORNATO ANCHE IN UPDATE if(idSoggettoErogatore<=0 &&*/
  124.         if(
  125.                 soggErogatore!=null && soggErogatore.getTipo()!=null && soggErogatore.getNome()!=null) {
  126.             try {
  127.                 idSoggettoErogatore = DBUtils.getIdSoggetto(soggErogatore.getNome(), soggErogatore.getTipo(), con, DriverConfigurazioneDBLib.tipoDB,DriverConfigurazioneDBLib.tabellaSoggetti);
  128.                 /**System.out.println("DOPO PD SOGGETTO: "+idSoggettoErogatore);*/
  129.             } catch (Exception e1) {
  130.                 DriverConfigurazioneDBLib.logDebug(e1.getMessage(),e1); // potrebbe non esistere la tabella
  131.             }
  132.         }
  133.        
  134.         PortaDelegataServizio servizio = aPD.getServizio();
  135.         long idServizioPD = ((servizio != null && servizio.getId() != null) ? servizio.getId() : -1);
  136.         /**System.out.println("PRIMA PD: "+idServizioPD);*/
  137.         /** SEMPRE, VA AGGIORNATO ANCHE IN UPDATE if(idServizioPD<=0 &&*/
  138.         if(
  139.                 idSoggettoErogatore>0 && servizio!=null && servizio.getTipo()!=null && servizio.getNome()!=null && servizio.getVersione()!=null && servizio.getVersione()>0) {
  140.             try {
  141.                 idServizioPD = DBUtils.getIdServizio(servizio.getNome(), servizio.getTipo(), servizio.getVersione(), idSoggettoErogatore, con, DriverConfigurazioneDBLib.tipoDB,DriverConfigurazioneDBLib.tabellaSoggetti);
  142.                 /**System.out.println("DOPO PD: "+idServizioPD);*/
  143.             } catch (Exception e1) {
  144.                 DriverConfigurazioneDBLib.logDebug(e1.getMessage(),e1); // potrebbe non esistere la tabella
  145.             }
  146.         }

  147.         MtomProcessor mtomProcessor = aPD.getMtomProcessor();
  148.         MTOMProcessorType mtomModeRequest = null;
  149.         MTOMProcessorType mtomModeResponse = null;
  150.         if(mtomProcessor!=null){
  151.             if(mtomProcessor.getRequestFlow()!=null){
  152.                 mtomModeRequest = mtomProcessor.getRequestFlow().getMode();
  153.             }
  154.             if(mtomProcessor.getResponseFlow()!=null){
  155.                 mtomModeResponse = mtomProcessor.getResponseFlow().getMode();
  156.             }
  157.         }
  158.        
  159.         MessageSecurity messageSecurity = aPD.getMessageSecurity();
  160.         String messageSecurityStatus = aPD.getStatoMessageSecurity();
  161.         StatoFunzionalita messageSecurityApplyMtomRequest = null;
  162.         StatoFunzionalita messageSecurityApplyMtomResponse = null;
  163.         String securityRequestMode = null;
  164.         String securityResponseMode = null;
  165.         if(messageSecurity!=null){
  166.             if(messageSecurity.getRequestFlow()!=null){
  167.                 messageSecurityApplyMtomRequest = messageSecurity.getRequestFlow().getApplyToMtom();
  168.                 securityRequestMode = messageSecurity.getRequestFlow().getMode();
  169.             }
  170.             if(messageSecurity.getResponseFlow()!=null){
  171.                 messageSecurityApplyMtomResponse = messageSecurity.getResponseFlow().getApplyToMtom();
  172.                 securityResponseMode = messageSecurity.getResponseFlow().getMode();
  173.             }
  174.         }
  175.        
  176.         CorrelazioneApplicativa corrApp = aPD.getCorrelazioneApplicativa();
  177.         CorrelazioneApplicativaRisposta corrAppRisposta = aPD.getCorrelazioneApplicativaRisposta();
  178.        
  179.         String msgDiagSeverita = null;
  180.         String tracciamentoStato = null;
  181.         String tracciamentoEsiti = null;
  182.         String transazioniTempiElaborazione = null;
  183.         String transazioniToken = null;
  184.         TracciamentoConfigurazione tracciamentoDatabase = null;
  185.         TracciamentoConfigurazione tracciamentoFiletrace = null;
  186.         TracciamentoConfigurazioneFiletrace tracciamentoFiletraceDetails = null;
  187.         if(aPD.getTracciamento()!=null){
  188.             msgDiagSeverita = DriverConfigurazioneDBLib.getValue(aPD.getTracciamento().getSeverita());
  189.             tracciamentoStato =  DriverConfigurazioneDBLib.getValue(aPD.getTracciamento().getStato());
  190.             tracciamentoEsiti = aPD.getTracciamento().getEsiti();
  191.             if(aPD.getTracciamento().getTransazioni()!=null) {
  192.                 transazioniTempiElaborazione = DriverConfigurazioneDBLib.getValue(aPD.getTracciamento().getTransazioni().getTempiElaborazione());
  193.                 transazioniToken = DriverConfigurazioneDBLib.getValue(aPD.getTracciamento().getTransazioni().getToken());
  194.             }
  195.             tracciamentoDatabase = aPD.getTracciamento().getDatabase();
  196.             tracciamentoFiletrace = aPD.getTracciamento().getFiletrace();
  197.             tracciamentoFiletraceDetails = aPD.getTracciamento().getFiletraceConfig();
  198.         }
  199.        
  200.         CorsConfigurazione corsConfigurazione = aPD.getGestioneCors();
  201.         String corsStato = null;
  202.         String corsTipo = null;
  203.         String corsAllAllowOrigins = null;
  204.         String corsAllAllowMethods = null;
  205.         String corsAllAllowHeaders = null;
  206.         String corsAllowCredentials = null;
  207.         int corsAllowMaxAge = CostantiDB.FALSE;
  208.         Integer corsAllowMaxAgeSeconds = null;
  209.         String corsAllowOrigins = null;
  210.         String corsAllowHeaders = null;
  211.         String corsAllowMethods = null;
  212.         String corsAllowExposeHeaders = null;
  213.         if(corsConfigurazione!=null) {
  214.             corsStato = DriverConfigurazioneDBLib.getValue(corsConfigurazione.getStato());
  215.             corsTipo = DriverConfigurazioneDBLib.getValue(corsConfigurazione.getTipo());
  216.             corsAllAllowOrigins = DriverConfigurazioneDBLib.getValue(corsConfigurazione.getAccessControlAllAllowOrigins());
  217.             corsAllAllowMethods = DriverConfigurazioneDBLib.getValue(corsConfigurazione.getAccessControlAllAllowMethods());
  218.             corsAllAllowHeaders = DriverConfigurazioneDBLib.getValue(corsConfigurazione.getAccessControlAllAllowHeaders());
  219.             corsAllowCredentials = DriverConfigurazioneDBLib.getValue(corsConfigurazione.getAccessControlAllowCredentials());
  220.             if(corsConfigurazione.getAccessControlMaxAge()!=null) {
  221.                 corsAllowMaxAge = CostantiDB.TRUE;
  222.                 corsAllowMaxAgeSeconds = corsConfigurazione.getAccessControlMaxAge();  
  223.             }
  224.             if(corsConfigurazione.getAccessControlAllowOrigins()!=null && corsConfigurazione.getAccessControlAllowOrigins().sizeOriginList()>0) {
  225.                 StringBuilder bf = new StringBuilder();
  226.                 for (int i = 0; i < corsConfigurazione.getAccessControlAllowOrigins().sizeOriginList(); i++) {
  227.                     if(i>0) {
  228.                         bf.append(",");
  229.                     }
  230.                     bf.append(corsConfigurazione.getAccessControlAllowOrigins().getOrigin(i));
  231.                 }
  232.                 corsAllowOrigins = bf.toString();
  233.             }
  234.             if(corsConfigurazione.getAccessControlAllowHeaders()!=null && corsConfigurazione.getAccessControlAllowHeaders().sizeHeaderList()>0) {
  235.                 StringBuilder bf = new StringBuilder();
  236.                 for (int i = 0; i < corsConfigurazione.getAccessControlAllowHeaders().sizeHeaderList(); i++) {
  237.                     if(i>0) {
  238.                         bf.append(",");
  239.                     }
  240.                     bf.append(corsConfigurazione.getAccessControlAllowHeaders().getHeader(i));
  241.                 }
  242.                 corsAllowHeaders = bf.toString();
  243.             }
  244.             if(corsConfigurazione.getAccessControlAllowMethods()!=null && corsConfigurazione.getAccessControlAllowMethods().sizeMethodList()>0) {
  245.                 StringBuilder bf = new StringBuilder();
  246.                 for (int i = 0; i < corsConfigurazione.getAccessControlAllowMethods().sizeMethodList(); i++) {
  247.                     if(i>0) {
  248.                         bf.append(",");
  249.                     }
  250.                     bf.append(corsConfigurazione.getAccessControlAllowMethods().getMethod(i));
  251.                 }
  252.                 corsAllowMethods = bf.toString();
  253.             }
  254.             if(corsConfigurazione.getAccessControlExposeHeaders()!=null && corsConfigurazione.getAccessControlExposeHeaders().sizeHeaderList()>0) {
  255.                 StringBuilder bf = new StringBuilder();
  256.                 for (int i = 0; i < corsConfigurazione.getAccessControlExposeHeaders().sizeHeaderList(); i++) {
  257.                     if(i>0) {
  258.                         bf.append(",");
  259.                     }
  260.                     bf.append(corsConfigurazione.getAccessControlExposeHeaders().getHeader(i));
  261.                 }
  262.                 corsAllowExposeHeaders = bf.toString();
  263.             }
  264.         }
  265.        
  266.         ResponseCachingConfigurazione responseCachingConfigurazone = aPD.getResponseCaching();
  267.         String responseCacheStato = null;
  268.         Integer responseCacheSeconds = null;
  269.         Long responseCacheMaxMsgSize = null;
  270.         String responseCacheHashUrl = null;
  271.         String responseCacheHashQuery = null;
  272.         String responseCacheHashQueryList = null;
  273.         String responseCacheHashHeaders = null;
  274.         String responseCacheHashHeadersList = null;
  275.         String responseCacheHashPayload = null;
  276.         boolean responseCacheNoCache = true;
  277.         boolean responseCacheMaxAge = true;
  278.         boolean responseCacheNoStore = true;
  279.         List<ResponseCachingConfigurazioneRegola> responseCacheRegole = null;
  280.         if(responseCachingConfigurazone!=null) {
  281.             responseCacheStato = DriverConfigurazioneDBLib.getValue(responseCachingConfigurazone.getStato());
  282.             responseCacheSeconds = responseCachingConfigurazone.getCacheTimeoutSeconds();
  283.             responseCacheMaxMsgSize = responseCachingConfigurazone.getMaxMessageSize();
  284.             if(responseCachingConfigurazone.getControl()!=null) {
  285.                 responseCacheNoCache = responseCachingConfigurazone.getControl().getNoCache();
  286.                 responseCacheMaxAge = responseCachingConfigurazone.getControl().getMaxAge();
  287.                 responseCacheNoStore = responseCachingConfigurazone.getControl().getNoStore();
  288.             }
  289.             if(responseCachingConfigurazone.getHashGenerator()!=null) {
  290.                 responseCacheHashUrl = DriverConfigurazioneDBLib.getValue(responseCachingConfigurazone.getHashGenerator().getRequestUri());
  291.                
  292.                 responseCacheHashQuery = DriverConfigurazioneDBLib.getValue(responseCachingConfigurazone.getHashGenerator().getQueryParameters());
  293.                 if(StatoFunzionalitaCacheDigestQueryParameter.SELEZIONE_PUNTUALE.equals(responseCachingConfigurazone.getHashGenerator().getQueryParameters()) &&
  294.                     (responseCachingConfigurazone.getHashGenerator().getQueryParameterList()!=null && responseCachingConfigurazone.getHashGenerator().sizeQueryParameterList()>0)
  295.                     ){
  296.                     StringBuilder bf = new StringBuilder();
  297.                     for (int i = 0; i < responseCachingConfigurazone.getHashGenerator().sizeQueryParameterList(); i++) {
  298.                         if(i>0) {
  299.                             bf.append(",");
  300.                         }
  301.                         bf.append(responseCachingConfigurazone.getHashGenerator().getQueryParameter(i));
  302.                     }
  303.                     responseCacheHashQueryList = bf.toString();
  304.                 }
  305.                
  306.                 responseCacheHashHeaders = DriverConfigurazioneDBLib.getValue(responseCachingConfigurazone.getHashGenerator().getHeaders());
  307.                 if(StatoFunzionalita.ABILITATO.equals(responseCachingConfigurazone.getHashGenerator().getHeaders()) &&
  308.                     (responseCachingConfigurazone.getHashGenerator().getHeaderList()!=null && responseCachingConfigurazone.getHashGenerator().sizeHeaderList()>0)
  309.                     ){
  310.                     StringBuilder bf = new StringBuilder();
  311.                     for (int i = 0; i < responseCachingConfigurazone.getHashGenerator().sizeHeaderList(); i++) {
  312.                         if(i>0) {
  313.                             bf.append(",");
  314.                         }
  315.                         bf.append(responseCachingConfigurazone.getHashGenerator().getHeader(i));
  316.                     }
  317.                     responseCacheHashHeadersList = bf.toString();
  318.                 }
  319.                
  320.                 responseCacheHashPayload = DriverConfigurazioneDBLib.getValue(responseCachingConfigurazone.getHashGenerator().getPayload());
  321.             }
  322.             responseCacheRegole = responseCachingConfigurazone.getRegolaList();
  323.         }
  324.        
  325.         ConfigurazionePortaHandler configHandlers = aPD.getConfigurazioneHandler();
  326.        
  327.         ExtendedInfoManager extInfoManager = ExtendedInfoManager.getInstance();
  328.         IExtendedInfo extInfoConfigurazioneDriver = extInfoManager.newInstanceExtendedInfoPortaDelegata();
  329.        
  330.         try {
  331.             int n = 0;
  332.             int i = 0;
  333.             switch (type) {
  334.             case CREATE:

  335.                 //soggetto erogatore
  336.                 String tipoSoggErogatore = (soggErogatore != null ? soggErogatore.getTipo() : null);
  337.                 String nomeSoggErogatore = (soggErogatore != null ? soggErogatore.getNome() : null);
  338.                 if(tipoSoggErogatore==null || tipoSoggErogatore.equals("")) throw new DriverConfigurazioneException("Tipo Soggetto Erogatore non impostato.");
  339.                 if(nomeSoggErogatore==null || nomeSoggErogatore.equals("")) throw new DriverConfigurazioneException("Nome Soggetto Erogatore non impostato.");

  340.                 //servizio
  341.                 String tipoServizio = (servizio != null ? servizio.getTipo() : null);
  342.                 String nomeServizio = (servizio != null ? servizio.getNome() : null);
  343.                 Integer versioneServizio = (servizio != null ? servizio.getVersione() : null);
  344.                 if(tipoServizio==null || tipoServizio.equals("")) throw new DriverConfigurazioneException("Tipo Servizio non impostato.");
  345.                 if(nomeServizio==null || nomeServizio.equals("")) throw new DriverConfigurazioneException("Nome Servizio non impostato.");
  346.                 if(versioneServizio==null) throw new DriverConfigurazioneException("Versione Servizio non impostato.");

  347.                 //Azione
  348.                 String nomeAzione = (azione != null ? azione.getNome() : null);
  349.                 String patternAzione = (azione != null ? azione.getPattern() : null);
  350.                 String nomePortaDeleganteAzione = (azione != null ? azione.getNomePortaDelegante() : null);
  351.                 StatoFunzionalita forceInterfaceBased = (azione != null ? azione.getForceInterfaceBased() : null);
  352.                 PortaDelegataAzioneIdentificazione modeAzione = (azione != null ? azione.getIdentificazione() : null);
  353.                 //Se il bean Azione nn e' presente allora non controllo nulla
  354.                 if(azione!=null){
  355.                     if(modeAzione==null || modeAzione.equals(""))
  356.                         modeAzione = PortaDelegataAzioneIdentificazione.STATIC;
  357.                     switch (modeAzione) {
  358.                     case CONTENT_BASED:
  359.                     case URL_BASED:
  360.                     case HEADER_BASED:
  361.                         if(patternAzione==null || patternAzione.equals("")) throw new DriverConfigurazioneException("Pattern Azione non impostato.");
  362.                         nomeAzione=null;
  363.                         break;
  364.                     case DELEGATED_BY:
  365.                         if(nomePortaDeleganteAzione==null || nomePortaDeleganteAzione.equals("")) throw new DriverConfigurazioneException("Nome Porta Delegante Azione non impostata.");
  366.                         nomeAzione=null;
  367.                         break;
  368.                     case INPUT_BASED:
  369.                     case SOAP_ACTION_BASED:
  370.                     case INTERFACE_BASED:
  371.                         //nessun campo obbligatorio
  372.                         break;
  373.                     case STATIC:
  374.                         //se non c'e' l'id dell'azione ci deve essere il nome
  375.                         if(idAzione<=0){
  376.                             if(nomeAzione==null || nomeAzione.equals("")) throw new DriverConfigurazioneException("Nome Azione non impostato.");
  377.                         }
  378.                         patternAzione=null;
  379.                         break;
  380.                     default:
  381.                         break;
  382.                     }
  383.                 }
  384.                
  385.                 String utenteRichiedente = null;
  386.                 if(aPD.getProprietaOggetto()!=null && aPD.getProprietaOggetto().getUtenteRichiedente()!=null) {
  387.                     utenteRichiedente = aPD.getProprietaOggetto().getUtenteRichiedente();
  388.                 }
  389.                 else {
  390.                     utenteRichiedente = DBUtils.getSuperUserServizioSafe(DriverConfigurazioneDBLib.log, "CRUDPortaApplicativa",
  391.                             idServizioPD, con, DriverConfigurazioneDBLib.tipoDB);
  392.                 }
  393.                
  394.                 Timestamp dataCreazione = null;
  395.                 if(aPD.getProprietaOggetto()!=null && aPD.getProprietaOggetto().getDataCreazione()!=null) {
  396.                     dataCreazione = new Timestamp(aPD.getProprietaOggetto().getDataCreazione().getTime());
  397.                 }
  398.                 else if(aPD.getOraRegistrazione()!=null){
  399.                     dataCreazione = new Timestamp(aPD.getOraRegistrazione().getTime());
  400.                 }
  401.                 else {
  402.                     dataCreazione = DateManager.getTimestamp();
  403.                 }

  404.                 // create
  405.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  406.                 sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE);
  407.                 sqlQueryObject.addInsertField("nome_porta", "?");
  408.                 sqlQueryObject.addInsertField("descrizione", "?");
  409.                 sqlQueryObject.addInsertField("id_soggetto_erogatore", "?");
  410.                 sqlQueryObject.addInsertField("tipo_soggetto_erogatore", "?");
  411.                 sqlQueryObject.addInsertField("nome_soggetto_erogatore", "?");
  412.                 sqlQueryObject.addInsertField("id_servizio", "?");
  413.                 sqlQueryObject.addInsertField("tipo_servizio", "?");
  414.                 sqlQueryObject.addInsertField("nome_servizio", "?");
  415.                 sqlQueryObject.addInsertField("versione_servizio", "?");
  416.                 sqlQueryObject.addInsertField("id_azione", "?");
  417.                 sqlQueryObject.addInsertField("nome_azione", "?");
  418.                 sqlQueryObject.addInsertField("mode_azione", "?");
  419.                 sqlQueryObject.addInsertField("pattern_azione", "?");
  420.                 sqlQueryObject.addInsertField("nome_porta_delegante_azione", "?");
  421.                 sqlQueryObject.addInsertField("force_interface_based_azione", "?");
  422.                 sqlQueryObject.addInsertField("autenticazione", "?");
  423.                 sqlQueryObject.addInsertField("autenticazione_opzionale", "?");
  424.                 sqlQueryObject.addInsertField("token_policy", "?");
  425.                 sqlQueryObject.addInsertField("token_opzionale", "?");
  426.                 sqlQueryObject.addInsertField("token_validazione", "?");
  427.                 sqlQueryObject.addInsertField("token_introspection", "?");
  428.                 sqlQueryObject.addInsertField("token_user_info", "?");
  429.                 sqlQueryObject.addInsertField("token_forward", "?");
  430.                 sqlQueryObject.addInsertField("token_options", "?");
  431.                 sqlQueryObject.addInsertField("token_authn_issuer", "?");
  432.                 sqlQueryObject.addInsertField("token_authn_client_id", "?");
  433.                 sqlQueryObject.addInsertField("token_authn_subject", "?");
  434.                 sqlQueryObject.addInsertField("token_authn_username", "?");
  435.                 sqlQueryObject.addInsertField("token_authn_email", "?");
  436.                 sqlQueryObject.addInsertField("autorizzazione", "?");
  437.                 sqlQueryObject.addInsertField("autorizzazione_xacml", "?");
  438.                 sqlQueryObject.addInsertField("autorizzazione_contenuto", "?");
  439.                 sqlQueryObject.addInsertField("mtom_request_mode", "?");
  440.                 sqlQueryObject.addInsertField("mtom_response_mode", "?");
  441.                 sqlQueryObject.addInsertField("security", "?");
  442.                 sqlQueryObject.addInsertField("security_mtom_req", "?");
  443.                 sqlQueryObject.addInsertField("security_mtom_res", "?");
  444.                 sqlQueryObject.addInsertField("security_request_mode", "?");
  445.                 sqlQueryObject.addInsertField("security_response_mode", "?");
  446.                 sqlQueryObject.addInsertField("id_soggetto", "?");
  447.                 sqlQueryObject.addInsertField("ricevuta_asincrona_sim", "?");
  448.                 sqlQueryObject.addInsertField("ricevuta_asincrona_asim", "?");
  449.                 sqlQueryObject.addInsertField("integrazione", "?");
  450.                 sqlQueryObject.addInsertField("scadenza_correlazione_appl", "?");
  451.                 sqlQueryObject.addInsertField("validazione_contenuti_stato", "?");
  452.                 sqlQueryObject.addInsertField("validazione_contenuti_tipo", "?");
  453.                 sqlQueryObject.addInsertField("validazione_contenuti_mtom", "?");
  454.                 sqlQueryObject.addInsertField("allega_body", "?");
  455.                 sqlQueryObject.addInsertField("scarta_body", "?");
  456.                 sqlQueryObject.addInsertField("gestione_manifest", "?");
  457.                 sqlQueryObject.addInsertField("stateless", "?");
  458.                 sqlQueryObject.addInsertField("local_forward", "?");
  459.                 sqlQueryObject.addInsertField("local_forward_pa", "?");
  460.                 sqlQueryObject.addInsertField("ruoli_match", "?");
  461.                 sqlQueryObject.addInsertField("token_sa_stato", "?");
  462.                 sqlQueryObject.addInsertField("token_ruoli_stato", "?");
  463.                 sqlQueryObject.addInsertField("token_ruoli_match", "?");
  464.                 sqlQueryObject.addInsertField("token_ruoli_tipologia", "?");
  465.                 sqlQueryObject.addInsertField("scope_stato", "?");
  466.                 sqlQueryObject.addInsertField("scope_match", "?");
  467.                 sqlQueryObject.addInsertField("ricerca_porta_azione_delegata", "?");
  468.                 sqlQueryObject.addInsertField("msg_diag_severita", "?");
  469.                 sqlQueryObject.addInsertField("tracciamento_stato", "?");
  470.                 sqlQueryObject.addInsertField("tracciamento_esiti", "?");
  471.                 sqlQueryObject.addInsertField("transazioni_tempi", "?");
  472.                 sqlQueryObject.addInsertField("transazioni_token", "?");
  473.                 sqlQueryObject.addInsertField("stato", "?");
  474.                 // cors
  475.                 sqlQueryObject.addInsertField("cors_stato", "?");
  476.                 sqlQueryObject.addInsertField("cors_tipo", "?");
  477.                 sqlQueryObject.addInsertField("cors_all_allow_origins", "?");
  478.                 sqlQueryObject.addInsertField("cors_all_allow_methods", "?");
  479.                 sqlQueryObject.addInsertField("cors_all_allow_headers", "?");
  480.                 sqlQueryObject.addInsertField("cors_allow_credentials", "?");
  481.                 sqlQueryObject.addInsertField("cors_allow_max_age", "?");
  482.                 sqlQueryObject.addInsertField("cors_allow_max_age_seconds", "?");
  483.                 sqlQueryObject.addInsertField("cors_allow_origins", "?");
  484.                 sqlQueryObject.addInsertField("cors_allow_headers", "?");
  485.                 sqlQueryObject.addInsertField("cors_allow_methods", "?");
  486.                 sqlQueryObject.addInsertField("cors_allow_expose_headers", "?");
  487.                 // responseCaching
  488.                 sqlQueryObject.addInsertField("response_cache_stato", "?");
  489.                 sqlQueryObject.addInsertField("response_cache_seconds", "?");
  490.                 sqlQueryObject.addInsertField("response_cache_max_msg_size", "?");
  491.                 sqlQueryObject.addInsertField("response_cache_control_nocache", "?");
  492.                 sqlQueryObject.addInsertField("response_cache_control_maxage", "?");
  493.                 sqlQueryObject.addInsertField("response_cache_control_nostore", "?");
  494.                 sqlQueryObject.addInsertField("response_cache_hash_url", "?");
  495.                 sqlQueryObject.addInsertField("response_cache_hash_query", "?");
  496.                 sqlQueryObject.addInsertField("response_cache_hash_query_list", "?");
  497.                 sqlQueryObject.addInsertField("response_cache_hash_headers", "?");
  498.                 sqlQueryObject.addInsertField("response_cache_hash_hdr_list", "?");
  499.                 sqlQueryObject.addInsertField("response_cache_hash_payload", "?");
  500.                 // id
  501.                 sqlQueryObject.addInsertField("id_accordo", "?");
  502.                 sqlQueryObject.addInsertField("id_port_type", "?");
  503.                 // options
  504.                 sqlQueryObject.addInsertField("options", "?");
  505.                 // options
  506.                 sqlQueryObject.addInsertField("canale", "?");
  507.                 if(utenteRichiedente!=null) {
  508.                     sqlQueryObject.addInsertField(CostantiDB.PROPRIETA_OGGETTO_UTENTE_RICHIEDENTE, "?");
  509.                 }
  510.                 if(dataCreazione!=null) {
  511.                     sqlQueryObject.addInsertField(CostantiDB.PROPRIETA_OGGETTO_DATA_CREAZIONE, "?");
  512.                 }
  513.                 sqlQuery = sqlQueryObject.createSQLInsert();
  514.                 stm = con.prepareStatement(sqlQuery);
  515.                 int index = 1;
  516.                 stm.setString(index++, nomePorta);
  517.                 stm.setString(index++, descrizione);
  518.                 stm.setLong(index++, idSoggettoErogatore);              
  519.                 stm.setString(index++, tipoSoggErogatore);
  520.                 stm.setString(index++, nomeSoggErogatore);
  521.                 stm.setLong(index++, idServizioPD);
  522.                 stm.setString(index++, tipoServizio);
  523.                 stm.setString(index++, nomeServizio);
  524.                 stm.setInt(index++, versioneServizio);
  525.                 stm.setLong(index++, idAzione);
  526.                 stm.setString(index++, nomeAzione);
  527.                 if(modeAzione!=null){
  528.                     stm.setString(index++, modeAzione.toString());
  529.                 }
  530.                 else{
  531.                     stm.setString(index++, null);
  532.                 }
  533.                 stm.setString(index++, patternAzione);
  534.                 stm.setString(index++, nomePortaDeleganteAzione);
  535.                 stm.setString(index++, DriverConfigurazioneDBLib.getValue(forceInterfaceBased));
  536.                 // autenticazione
  537.                 stm.setString(index++, autenticazione);
  538.                 stm.setString(index++, aPD!=null ? DriverConfigurazioneDBLib.getValue(aPD.getAutenticazioneOpzionale()) : null);
  539.                 // token
  540.                 stm.setString(index++, gestioneToken!=null ? gestioneToken.getPolicy() : null);
  541.                 stm.setString(index++, gestioneToken!=null ? DriverConfigurazioneDBLib.getValue(gestioneToken.getTokenOpzionale()) : null);
  542.                 stm.setString(index++, gestioneToken!=null ? DriverConfigurazioneDBLib.getValue(gestioneToken.getValidazione()) : null);
  543.                 stm.setString(index++, gestioneToken!=null ? DriverConfigurazioneDBLib.getValue(gestioneToken.getIntrospection()) : null);
  544.                 stm.setString(index++, gestioneToken!=null ? DriverConfigurazioneDBLib.getValue(gestioneToken.getUserInfo()) : null);
  545.                 stm.setString(index++, gestioneToken!=null ? DriverConfigurazioneDBLib.getValue(gestioneToken.getForward()) : null);
  546.                 stm.setString(index++, gestioneToken!=null ? gestioneToken.getOptions() : null);
  547.                 stm.setString(index++, (gestioneToken!=null && gestioneToken.getAutenticazione()!=null) ?
  548.                         DriverConfigurazioneDBLib.getValue(gestioneToken.getAutenticazione().getIssuer()) : null);
  549.                 stm.setString(index++, (gestioneToken!=null && gestioneToken.getAutenticazione()!=null) ?
  550.                         DriverConfigurazioneDBLib.getValue(gestioneToken.getAutenticazione().getClientId()) : null);
  551.                 stm.setString(index++, (gestioneToken!=null && gestioneToken.getAutenticazione()!=null) ?
  552.                         DriverConfigurazioneDBLib.getValue(gestioneToken.getAutenticazione().getSubject()) : null);
  553.                 stm.setString(index++, (gestioneToken!=null && gestioneToken.getAutenticazione()!=null) ?
  554.                         DriverConfigurazioneDBLib.getValue(gestioneToken.getAutenticazione().getUsername()) : null);
  555.                 stm.setString(index++, (gestioneToken!=null && gestioneToken.getAutenticazione()!=null) ?
  556.                         DriverConfigurazioneDBLib.getValue(gestioneToken.getAutenticazione().getEmail()) : null);
  557.                 // autorizzazione
  558.                 stm.setString(index++, autorizzazione);
  559.                 stm.setString(index++, autorizzazioneXacmlPolicy);
  560.                 stm.setString(index++, autorizzazioneContenuto);
  561.                 // mtom
  562.                 stm.setString(index++, DriverConfigurazioneDBLib.getValue(mtomModeRequest));
  563.                 stm.setString(index++, DriverConfigurazioneDBLib.getValue(mtomModeResponse));
  564.                 // messageSecurity
  565.                 stm.setString(index++, messageSecurityStatus);
  566.                 stm.setString(index++, DriverConfigurazioneDBLib.getValue(messageSecurityApplyMtomRequest));
  567.                 stm.setString(index++, DriverConfigurazioneDBLib.getValue(messageSecurityApplyMtomResponse));
  568.                 stm.setString(index++, securityRequestMode);
  569.                 stm.setString(index++, securityResponseMode);
  570.                 // proprietario
  571.                 stm.setLong(index++, idSoggettoProprietario);
  572.                 //ricevuta asincrona_asimmetrica/simmetrica
  573.                 stm.setString(index++, DriverConfigurazioneDBLib.getValue(aPD.getRicevutaAsincronaSimmetrica()));
  574.                 stm.setString(index++, DriverConfigurazioneDBLib.getValue(aPD.getRicevutaAsincronaAsimmetrica()));              
  575.                 //integrazione
  576.                 stm.setString(index++, aPD.getIntegrazione());
  577.                 //correlazione applicativa scadenza
  578.                 stm.setString(index++, aPD.getCorrelazioneApplicativa()!=null ? aPD.getCorrelazioneApplicativa().getScadenza() : null);
  579.                 //validazione xsd
  580.                 stm.setString(index++, aPD.getValidazioneContenutiApplicativi()!=null ? DriverConfigurazioneDBLib.getValue(aPD.getValidazioneContenutiApplicativi().getStato()) : null);
  581.                 stm.setString(index++, aPD.getValidazioneContenutiApplicativi()!=null ? DriverConfigurazioneDBLib.getValue(aPD.getValidazioneContenutiApplicativi().getTipo()) : null);
  582.                 stm.setString(index++, aPD.getValidazioneContenutiApplicativi()!=null ? DriverConfigurazioneDBLib.getValue(aPD.getValidazioneContenutiApplicativi().getAcceptMtomMessage()) : null);

  583.                 // InvocazionePorta: funzionalita' attachment
  584.                 stm.setString(index++, aPD!=null ? DriverConfigurazioneDBLib.getValue(aPD.getAllegaBody()) : null);
  585.                 stm.setString(index++, aPD!=null ? DriverConfigurazioneDBLib.getValue(aPD.getScartaBody()) : null);
  586.                 stm.setString(index++, aPD!=null ? DriverConfigurazioneDBLib.getValue(aPD.getGestioneManifest()) : null);
  587.                
  588.                 // Stateless
  589.                 stm.setString(index++, aPD!=null ? DriverConfigurazioneDBLib.getValue(aPD.getStateless()) : null);
  590.                
  591.                 // LocalForward
  592.                 stm.setString(index++, aPD!=null && aPD.getLocalForward()!=null ? DriverConfigurazioneDBLib.getValue(aPD.getLocalForward().getStato()) : null);
  593.                 stm.setString(index++, aPD!=null && aPD.getLocalForward()!=null ? aPD.getLocalForward().getPortaApplicativa() : null);
  594.                
  595.                 // Ruoli
  596.                 stm.setString(index++, aPD!=null && aPD.getRuoli()!=null && aPD.getRuoli().getMatch()!=null ?
  597.                         aPD.getRuoli().getMatch().getValue() : null);
  598.                
  599.                 // Token sa
  600.                 stm.setString(index++, aPD!=null && aPD.getAutorizzazioneToken()!=null && aPD.getAutorizzazioneToken().getAutorizzazioneApplicativi()!=null ?
  601.                         DriverConfigurazioneDBLib.getValue(aPD.getAutorizzazioneToken().getAutorizzazioneApplicativi()) : null);
  602.                
  603.                 // Token ruoli
  604.                 stm.setString(index++, aPD!=null && aPD.getAutorizzazioneToken()!=null && aPD.getAutorizzazioneToken().getAutorizzazioneRuoli()!=null ?
  605.                         DriverConfigurazioneDBLib.getValue(aPD.getAutorizzazioneToken().getAutorizzazioneRuoli()) : null);
  606.                 stm.setString(index++, aPD!=null && aPD.getAutorizzazioneToken()!=null && aPD.getAutorizzazioneToken().getRuoli()!=null &&
  607.                         aPD.getAutorizzazioneToken().getRuoli().getMatch()!=null ?
  608.                         aPD.getAutorizzazioneToken().getRuoli().getMatch().getValue() : null);
  609.                 stm.setString(index++, aPD!=null && aPD.getAutorizzazioneToken()!=null && aPD.getAutorizzazioneToken().getTipologiaRuoli()!=null ?
  610.                         aPD.getAutorizzazioneToken().getTipologiaRuoli().getValue() : null);
  611.                
  612.                 // Scope
  613.                 stm.setString(index++, aPD!=null && aPD.getScope()!=null && aPD.getScope().getStato()!=null ?
  614.                         DriverConfigurazioneDBLib.getValue(aPD.getScope().getStato()) : null);
  615.                 stm.setString(index++, aPD!=null && aPD.getScope()!=null && aPD.getScope().getMatch()!=null ?
  616.                         aPD.getScope().getMatch().getValue() : null);
  617.                
  618.                 // Ricerca Porta Azione Delegata
  619.                 stm.setString(index++, aPD!=null ? DriverConfigurazioneDBLib.getValue(aPD.getRicercaPortaAzioneDelegata()) : null);
  620.                
  621.                 // Tracciamento
  622.                 stm.setString(index++, msgDiagSeverita);
  623.                 stm.setString(index++, tracciamentoStato);
  624.                 stm.setString(index++, tracciamentoEsiti);
  625.                 stm.setString(index++, transazioniTempiElaborazione);
  626.                 stm.setString(index++, transazioniToken);
  627.                
  628.                 // Stato
  629.                 stm.setString(index++, aPD!=null ? DriverConfigurazioneDBLib.getValue(aPD.getStato()) : null);
  630.                
  631.                 // cors
  632.                 stm.setString(index++, corsStato);
  633.                 stm.setString(index++, corsTipo);
  634.                 stm.setString(index++, corsAllAllowOrigins);
  635.                 stm.setString(index++, corsAllAllowMethods);
  636.                 stm.setString(index++, corsAllAllowHeaders);
  637.                 stm.setString(index++, corsAllowCredentials);
  638.                 stm.setInt(index++, corsAllowMaxAge);
  639.                 if(corsAllowMaxAgeSeconds!=null) {
  640.                     stm.setInt(index++, corsAllowMaxAgeSeconds);
  641.                 }
  642.                 else {
  643.                     stm.setNull(index++, java.sql.Types.INTEGER);
  644.                 }
  645.                 stm.setString(index++, corsAllowOrigins);
  646.                 stm.setString(index++, corsAllowHeaders);
  647.                 stm.setString(index++, corsAllowMethods);
  648.                 stm.setString(index++, corsAllowExposeHeaders);
  649.                
  650.                 // responseCaching
  651.                 stm.setString(index++, responseCacheStato);
  652.                 if(responseCacheSeconds!=null) {
  653.                     stm.setInt(index++, responseCacheSeconds);
  654.                 }
  655.                 else {
  656.                     stm.setNull(index++, java.sql.Types.INTEGER);
  657.                 }
  658.                 if(responseCacheMaxMsgSize!=null) {
  659.                     stm.setLong(index++, responseCacheMaxMsgSize);
  660.                 }
  661.                 else {
  662.                     stm.setNull(index++, java.sql.Types.BIGINT);
  663.                 }
  664.                 stm.setInt(index++, responseCacheNoCache ? CostantiDB.TRUE : CostantiDB.FALSE);
  665.                 stm.setInt(index++, responseCacheMaxAge ? CostantiDB.TRUE : CostantiDB.FALSE);
  666.                 stm.setInt(index++, responseCacheNoStore ? CostantiDB.TRUE : CostantiDB.FALSE);
  667.                 stm.setString(index++, responseCacheHashUrl);
  668.                 stm.setString(index++, responseCacheHashQuery);
  669.                 stm.setString(index++, responseCacheHashQueryList);
  670.                 stm.setString(index++, responseCacheHashHeaders);
  671.                 stm.setString(index++, responseCacheHashHeadersList);
  672.                 stm.setString(index++, responseCacheHashPayload);
  673.                
  674.                 //idaccordo
  675.                 stm.setLong(index++, aPD.getIdAccordo()!=null ? aPD.getIdAccordo() : -1L);
  676.                 stm.setLong(index++, aPD.getIdPortType() !=null ? aPD.getIdPortType() : -1L);
  677.                
  678.                 // options
  679.                 stm.setString(index++, aPD.getOptions());
  680.                
  681.                 // canale
  682.                 stm.setString(index++, aPD.getCanale());
  683.                
  684.                 if(utenteRichiedente!=null) {
  685.                     stm.setString(index++, utenteRichiedente);
  686.                 }
  687.                
  688.                 if(dataCreazione!=null) {
  689.                     stm.setTimestamp(index++, dataCreazione);
  690.                 }
  691.                
  692.                 DriverConfigurazioneDBLib.logDebug("eseguo query: " +
  693.                         DBUtils.formatSQLString(sqlQuery, nomePorta, descrizione,
  694.                                 idSoggettoErogatore, tipoSoggErogatore, nomeSoggErogatore,
  695.                                 idServizioPD, tipoServizio, nomeServizio,
  696.                                 idAzione, nomeAzione, modeAzione, patternAzione, nomePortaDeleganteAzione, DriverConfigurazioneDBLib.getValue(forceInterfaceBased),
  697.                                 autenticazione, aPD.getAutenticazioneOpzionale(),
  698.                                 (gestioneToken!=null ? gestioneToken.getPolicy() : null),
  699.                                 (gestioneToken!=null ? gestioneToken.getTokenOpzionale() : null),
  700.                                 (gestioneToken!=null ? gestioneToken.getValidazione() : null),
  701.                                 (gestioneToken!=null ? gestioneToken.getIntrospection() : null),
  702.                                 (gestioneToken!=null ? gestioneToken.getUserInfo() : null),
  703.                                 (gestioneToken!=null ? gestioneToken.getForward() : null),
  704.                                 (gestioneToken!=null ? gestioneToken.getOptions() : null),
  705.                                 ((gestioneToken!=null && gestioneToken.getAutenticazione()!=null) ? gestioneToken.getAutenticazione().getIssuer() : null),
  706.                                 ((gestioneToken!=null && gestioneToken.getAutenticazione()!=null) ? gestioneToken.getAutenticazione().getClientId() : null),
  707.                                 ((gestioneToken!=null && gestioneToken.getAutenticazione()!=null) ? gestioneToken.getAutenticazione().getSubject() : null),
  708.                                 ((gestioneToken!=null && gestioneToken.getAutenticazione()!=null) ? gestioneToken.getAutenticazione().getUsername() : null),
  709.                                 ((gestioneToken!=null && gestioneToken.getAutenticazione()!=null) ? gestioneToken.getAutenticazione().getEmail() : null),
  710.                                 autorizzazione, autorizzazioneXacmlPolicy, autorizzazioneContenuto,
  711.                                 mtomModeRequest, mtomModeResponse,
  712.                                 messageSecurityStatus, messageSecurityApplyMtomRequest, messageSecurityApplyMtomResponse, securityRequestMode, securityResponseMode,
  713.                                 idSoggettoProprietario,
  714.                                 aPD.getRicevutaAsincronaSimmetrica(),aPD.getRicevutaAsincronaAsimmetrica(),aPD.getIntegrazione(),
  715.                                 (aPD.getCorrelazioneApplicativa()!=null ? aPD.getCorrelazioneApplicativa().getScadenza() : null),
  716.                                 (aPD.getValidazioneContenutiApplicativi()!=null ? aPD.getValidazioneContenutiApplicativi().getStato() : null),
  717.                                 (aPD.getValidazioneContenutiApplicativi()!=null ? aPD.getValidazioneContenutiApplicativi().getTipo() : null),
  718.                                 (aPD.getValidazioneContenutiApplicativi()!=null ? aPD.getValidazioneContenutiApplicativi().getAcceptMtomMessage() : null),
  719.                                 aPD.getAllegaBody(),aPD.getScartaBody(),aPD.getGestioneManifest(),aPD.getStateless(),aPD.getLocalForward(),
  720.                                 (aPD!=null && aPD.getRuoli()!=null && aPD.getRuoli().getMatch()!=null ?
  721.                                         aPD.getRuoli().getMatch().getValue() : null),
  722.                                 (aPD!=null && aPD.getAutorizzazioneToken()!=null && aPD.getAutorizzazioneToken().getAutorizzazioneApplicativi()!=null ?
  723.                                         DriverConfigurazioneDBLib.getValue(aPD.getAutorizzazioneToken().getAutorizzazioneApplicativi()) : null),
  724.                                 (aPD!=null && aPD.getAutorizzazioneToken()!=null && aPD.getAutorizzazioneToken().getAutorizzazioneRuoli()!=null ?
  725.                                         DriverConfigurazioneDBLib.getValue(aPD.getAutorizzazioneToken().getAutorizzazioneRuoli()) : null),
  726.                                 (aPD!=null && aPD.getAutorizzazioneToken()!=null && aPD.getAutorizzazioneToken().getRuoli()!=null &&
  727.                                     aPD.getAutorizzazioneToken().getRuoli().getMatch()!=null ?
  728.                                         aPD.getAutorizzazioneToken().getRuoli().getMatch().getValue() : null),
  729.                                 (aPD.getAutorizzazioneToken()!=null && aPD.getAutorizzazioneToken().getTipologiaRuoli()!=null ?
  730.                                         aPD.getAutorizzazioneToken().getTipologiaRuoli().getValue() : null),
  731.                                 (aPD!=null && aPD.getScope()!=null && aPD.getScope().getStato()!=null ?
  732.                                         aPD.getScope().getStato() : null),
  733.                                 (aPD!=null && aPD.getScope()!=null && aPD.getScope().getMatch()!=null ?
  734.                                         aPD.getScope().getMatch().getValue() : null),
  735.                                 aPD.getRicercaPortaAzioneDelegata(),
  736.                                 msgDiagSeverita,tracciamentoStato,tracciamentoEsiti,transazioniTempiElaborazione,transazioniToken,
  737.                                 aPD.getStato(),
  738.                                 corsStato, corsTipo, corsAllAllowOrigins, corsAllAllowMethods, corsAllAllowHeaders, corsAllowCredentials, corsAllowMaxAge, corsAllowMaxAgeSeconds,
  739.                                 corsAllowOrigins, corsAllowHeaders, corsAllowMethods, corsAllowExposeHeaders,
  740.                                 responseCacheStato, responseCacheSeconds, responseCacheMaxMsgSize,
  741.                                 (responseCacheNoCache ? CostantiDB.TRUE : CostantiDB.FALSE),
  742.                                 (responseCacheMaxAge ? CostantiDB.TRUE : CostantiDB.FALSE),
  743.                                 (responseCacheNoStore ? CostantiDB.TRUE : CostantiDB.FALSE),
  744.                                 responseCacheHashUrl, responseCacheHashQuery, responseCacheHashQueryList, responseCacheHashHeaders, responseCacheHashHeadersList, responseCacheHashPayload,
  745.                                 aPD.getIdAccordo(),aPD.getIdPortType(),
  746.                                 aPD.getOptions(),
  747.                                 aPD.getCanale()));
  748.                 n = stm.executeUpdate();
  749.                 stm.close();

  750.                 DriverConfigurazioneDBLib.logDebug("Inserted " + n + " row(s).");

  751.                 // recupero l'id della porta delegata appena inserita
  752.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  753.                 sqlQueryObject.addFromTable(CostantiDB.PORTE_DELEGATE);
  754.                 sqlQueryObject.addSelectField("id");
  755.                 sqlQueryObject.addWhereCondition("id_soggetto = ?");
  756.                 sqlQueryObject.addWhereCondition("nome_porta = ?");
  757.                 sqlQueryObject.setANDLogicOperator(true);
  758.                 sqlQuery = sqlQueryObject.createSQLQuery();
  759.                 stm = con.prepareStatement(sqlQuery);
  760.                 stm.setLong(1, idSoggettoProprietario);
  761.                 stm.setString(2, nomePorta);

  762.                 rs = stm.executeQuery();

  763.                 if (rs.next()) {
  764.                     idPortaDelegata = rs.getLong("id");
  765.                     aPD.setId(idPortaDelegata);
  766.                     rs.close();
  767.                     stm.close();
  768.                 } else {
  769.                     rs.close();
  770.                     stm.close();
  771.                     throw new DriverConfigurazioneException("[DriverConfigurazioneDB_LIB::CRUDPortaDelegata(CREATE)] Impossibile recuperare l'ID della PortaDelegata appena create.");
  772.                 }

  773.                 if(mtomProcessor!=null){
  774.                    
  775.                     MtomProcessorFlowParameter reqParam = null;
  776.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  777.                     sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_MTOM_REQUEST);
  778.                     sqlQueryObject.addInsertField("id_porta", "?");
  779.                     sqlQueryObject.addInsertField("nome", "?");
  780.                     sqlQueryObject.addInsertField("pattern", "?");
  781.                     sqlQueryObject.addInsertField("content_type", "?");
  782.                     sqlQueryObject.addInsertField("required", "?");
  783.                     sqlQuery = sqlQueryObject.createSQLInsert();
  784.                     stm = con.prepareStatement(sqlQuery);

  785.                     i = 0;
  786.                     if(mtomProcessor.getRequestFlow()!=null){
  787.                         MtomProcessorFlow flow = mtomProcessor.getRequestFlow();
  788.                         for (i = 0; i < flow.sizeParameterList(); i++) {
  789.                             reqParam = flow.getParameter(i);
  790.                             stm.setLong(1, idPortaDelegata);
  791.                             stm.setString(2, reqParam.getNome());
  792.                             stm.setString(3, reqParam.getPattern());
  793.                             stm.setString(4, reqParam.getContentType());
  794.                             stm.setInt(5, reqParam.getRequired() ? CostantiDB.TRUE : CostantiDB.FALSE);

  795.                             stm.executeUpdate();
  796.                         }  
  797.                     }
  798.                     stm.close();
  799.                     DriverConfigurazioneDBLib.logDebug("Inserted " + i + " mtom request flow con id=" + idPortaDelegata);

  800.                     MtomProcessorFlowParameter resParam = null;
  801.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  802.                     sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_MTOM_RESPONSE);
  803.                     sqlQueryObject.addInsertField("id_porta", "?");
  804.                     sqlQueryObject.addInsertField("nome", "?");
  805.                     sqlQueryObject.addInsertField("pattern", "?");
  806.                     sqlQueryObject.addInsertField("content_type", "?");
  807.                     sqlQueryObject.addInsertField("required", "?");
  808.                     sqlQuery = sqlQueryObject.createSQLInsert();
  809.                     stm = con.prepareStatement(sqlQuery);
  810.                    
  811.                     i = 0;
  812.                     if(mtomProcessor.getResponseFlow()!=null){
  813.                         MtomProcessorFlow flow = mtomProcessor.getResponseFlow();
  814.                         for (i = 0; i < flow.sizeParameterList(); i++) {
  815.                             resParam = flow.getParameter(i);
  816.                             stm.setLong(1, idPortaDelegata);
  817.                             stm.setString(2, resParam.getNome());
  818.                             stm.setString(3, resParam.getPattern());
  819.                             stm.setString(4, resParam.getContentType());
  820.                             stm.setInt(5, resParam.getRequired() ? CostantiDB.TRUE : CostantiDB.FALSE);
  821.    
  822.                             stm.executeUpdate();
  823.                         }
  824.                     }
  825.                     stm.close();
  826.                     DriverConfigurazioneDBLib.logDebug("Inserted " + i + " mtom response flow con id=" + idPortaDelegata);
  827.                    
  828.                 }
  829.                
  830.                 // se security abilitato setto la lista
  831.                 /**if ((messageSecurity != null) && CostantiConfigurazione.ABILITATO.toString().equals(messageSecurityStatus) )  {*/
  832.                 // Devo settarli sempre se ci sono, in modo che lo switch abilitato-disabilitato funzioni
  833.                 if ((messageSecurity != null) )  {
  834.                     MessageSecurityFlowParameter reqParam = null;
  835.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  836.                     sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST);
  837.                     sqlQueryObject.addInsertField("id_porta", "?");
  838.                     sqlQueryObject.addInsertField("nome", "?");
  839.                     sqlQueryObject.addInsertField("valore", "?");
  840.                     sqlQueryObject.addInsertField("enc_value", "?");
  841.                     sqlQuery = sqlQueryObject.createSQLInsert();
  842.                     stm = con.prepareStatement(sqlQuery);

  843.                     i = 0;
  844.                     if(messageSecurity.getRequestFlow()!=null){
  845.                         MessageSecurityFlow flow = messageSecurity.getRequestFlow();
  846.                         for (i = 0; i < flow.sizeParameterList(); i++) {
  847.                             reqParam = flow.getParameter(i);
  848.                             int indexSec = 1;
  849.                             stm.setLong(indexSec++, idPortaDelegata);
  850.                             stm.setString(indexSec++, reqParam.getNome());
  851.                            
  852.                             String plainValue = reqParam.getValore();
  853.                             String encValue = null;
  854.                             if(driverBYOK!=null &&
  855.                                     (
  856.                                             DriverConfigurazioneDB_genericPropertiesDriver.isConfidentialProperty(securityRequestMode, reqParam.getNome())
  857.                                             ||
  858.                                             BYOKUtilities.isWrappedValue(plainValue)
  859.                                     )
  860.                             ) {
  861.                                 BYOKWrappedValue byokValue = driverBYOK.wrap(plainValue);
  862.                                 if(byokValue!=null) {
  863.                                     encValue = byokValue.getWrappedValue();
  864.                                     plainValue = byokValue.getWrappedPlainValue();
  865.                                 }
  866.                             }
  867.                             stm.setString(indexSec++, plainValue);
  868.                             stm.setString(indexSec++, encValue);

  869.                             stm.executeUpdate();
  870.                         }  
  871.                     }
  872.                     stm.close();
  873.                     DriverConfigurazioneDBLib.logDebug("Inserted " + i + " request flow con id=" + idPortaDelegata);

  874.                     MessageSecurityFlowParameter resParam = null;
  875.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  876.                     sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE);
  877.                     sqlQueryObject.addInsertField("id_porta", "?");
  878.                     sqlQueryObject.addInsertField("nome", "?");
  879.                     sqlQueryObject.addInsertField("valore", "?");
  880.                     sqlQueryObject.addInsertField("enc_value", "?");
  881.                     sqlQuery = sqlQueryObject.createSQLInsert();
  882.                     stm = con.prepareStatement(sqlQuery);
  883.                    
  884.                     i = 0;
  885.                     if(messageSecurity.getResponseFlow()!=null){
  886.                         MessageSecurityFlow flow = messageSecurity.getResponseFlow();
  887.                         for (i = 0; i < flow.sizeParameterList(); i++) {
  888.                             resParam = flow.getParameter(i);
  889.                             int indexSec = 1;
  890.                             stm.setLong(indexSec++, idPortaDelegata);
  891.                             stm.setString(indexSec++, resParam.getNome());
  892.                            
  893.                             String plainValue = resParam.getValore();
  894.                             String encValue = null;
  895.                             if(driverBYOK!=null &&
  896.                                     (
  897.                                             DriverConfigurazioneDB_genericPropertiesDriver.isConfidentialProperty(securityResponseMode, resParam.getNome())
  898.                                             ||
  899.                                             BYOKUtilities.isWrappedValue(plainValue)
  900.                                     )
  901.                             ) {
  902.                                 BYOKWrappedValue byokValue = driverBYOK.wrap(plainValue);
  903.                                 if(byokValue!=null) {
  904.                                     encValue = byokValue.getWrappedValue();
  905.                                     plainValue = byokValue.getWrappedPlainValue();
  906.                                 }
  907.                             }
  908.                             stm.setString(indexSec++, plainValue);
  909.                             stm.setString(indexSec++, encValue);
  910.    
  911.                             stm.executeUpdate();
  912.                         }
  913.                     }
  914.                     stm.close();
  915.                     DriverConfigurazioneDBLib.logDebug("Inserted " + i + " response flow con id=" + idPortaDelegata);
  916.                 }

  917.                 // la lista di correlazioni applicative contiene tutti e soli gli elementi necessari quindi resetto la lista nel db e riscrivo la lista nuova
  918.                 if (corrApp != null) {

  919.                     //inserisco i valori presenti nella lista
  920.                     CorrelazioneApplicativaElemento cae = null;
  921.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  922.                     sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_CORRELAZIONE);
  923.                     sqlQueryObject.addInsertField("id_porta", "?");
  924.                     sqlQueryObject.addInsertField("nome_elemento", "?");
  925.                     sqlQueryObject.addInsertField("mode_correlazione", "?");
  926.                     sqlQueryObject.addInsertField("pattern", "?");
  927.                     sqlQueryObject.addInsertField("identificazione_fallita", "?");
  928.                     sqlQueryObject.addInsertField("riuso_id", "?");
  929.                     sqlQuery = sqlQueryObject.createSQLInsert();
  930.                     stm = con.prepareStatement(sqlQuery);

  931.                     for (i = 0; i < corrApp.sizeElementoList(); i++) {
  932.                         cae = corrApp.getElemento(i);
  933.                         stm.setLong(1, idPortaDelegata);
  934.                         stm.setString(2, cae.getNome());
  935.                         stm.setString(3, DriverConfigurazioneDBLib.getValue(cae.getIdentificazione()));
  936.                         if (cae.getPattern() != null)
  937.                             stm.setString(4, cae.getPattern());
  938.                         else
  939.                             stm.setString(4, "");
  940.                         stm.setString(5, DriverConfigurazioneDBLib.getValue(cae.getIdentificazioneFallita()));
  941.                         stm.setString(6, DriverConfigurazioneDBLib.getValue(cae.getRiusoIdentificativo()));
  942.                         stm.executeUpdate();
  943.                     }
  944.                     stm.close();
  945.                     DriverConfigurazioneDBLib.logDebug("Inserted " + i + " correlazione applicativa con id=" + idPortaDelegata);
  946.                 }
  947.                
  948.                 // la lista di correlazioni applicative contiene tutti e soli gli elementi necessari quindi resetto la lista nel db e riscrivo la lista nuova
  949.                 if (corrAppRisposta != null) {

  950.                     //inserisco i valori presenti nella lista
  951.                     CorrelazioneApplicativaRispostaElemento cae = null;
  952.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  953.                     sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_CORRELAZIONE_RISPOSTA);
  954.                     sqlQueryObject.addInsertField("id_porta", "?");
  955.                     sqlQueryObject.addInsertField("nome_elemento", "?");
  956.                     sqlQueryObject.addInsertField("mode_correlazione", "?");
  957.                     sqlQueryObject.addInsertField("pattern", "?");
  958.                     sqlQueryObject.addInsertField("identificazione_fallita", "?");
  959.                     sqlQuery = sqlQueryObject.createSQLInsert();
  960.                     stm = con.prepareStatement(sqlQuery);

  961.                     for (i = 0; i < corrAppRisposta.sizeElementoList(); i++) {
  962.                         cae = corrAppRisposta.getElemento(i);
  963.                         stm.setLong(1, idPortaDelegata);
  964.                         stm.setString(2, cae.getNome());
  965.                         stm.setString(3, DriverConfigurazioneDBLib.getValue(cae.getIdentificazione()));
  966.                         if (cae.getPattern() != null)
  967.                             stm.setString(4, cae.getPattern());
  968.                         else
  969.                             stm.setString(4, "");
  970.                         stm.setString(5, DriverConfigurazioneDBLib.getValue(cae.getIdentificazioneFallita()));
  971.                         stm.executeUpdate();
  972.                     }
  973.                     stm.close();
  974.                     DriverConfigurazioneDBLib.logDebug("Inserted " + i + " correlazione applicativa risposta con id=" + idPortaDelegata);
  975.                 }
  976.                
  977.                 // serviziapplicativi
  978.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  979.                 sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_SA);
  980.                 sqlQueryObject.addInsertField("id_porta", "?");
  981.                 sqlQueryObject.addInsertField("id_servizio_applicativo", "?");
  982.                 sqlQuery = sqlQueryObject.createSQLInsert();
  983.                 stm = con.prepareStatement(sqlQuery);

  984.                 for (i = 0; i < aPD.sizeServizioApplicativoList(); i++) {
  985.                     PortaDelegataServizioApplicativo servizioApplicativo = aPD.getServizioApplicativo(i);
  986.                     String nomeSA = servizioApplicativo.getNome();
  987.                     //il tipo e il nome proprietario servizio applicativo sono gli stessi della porta delegata
  988.                     String nomeProprietarioSA = aPD.getNomeSoggettoProprietario(); //servizioApplicativo.getNomeSoggettoProprietario();
  989.                     String tipoProprietarioSA = aPD.getTipoSoggettoProprietario(); //servizioApplicativo.getTipoSoggettoProprietario();
  990.                     if (nomeSA == null || nomeSA.equals(""))
  991.                         throw new DriverConfigurazioneException("Nome del ServizioApplicativo associato non valido.");
  992.                     if (nomeProprietarioSA == null || nomeProprietarioSA.equals(""))
  993.                         throw new DriverConfigurazioneException("Nome Proprietario del ServizioApplicativo associato non valido.");
  994.                     if (tipoProprietarioSA == null || tipoProprietarioSA.equals(""))
  995.                         throw new DriverConfigurazioneException("Tipo Proprietario del ServizioApplicativo associato non valido.");

  996.                     long idSA = DriverConfigurazioneDB_serviziApplicativiLIB.getIdServizioApplicativo(nomeSA, tipoProprietarioSA, nomeProprietarioSA, con, DriverConfigurazioneDBLib.tipoDB,DriverConfigurazioneDBLib.tabellaSoggetti);

  997.                     if (idSA <= 0)
  998.                         throw new DriverConfigurazioneException("Impossibile recuperare l'id del Servizio Applicativo [" + nomeSA + "] di [" + tipoProprietarioSA + "/" + nomeProprietarioSA + "]");

  999.                     stm.setLong(1, idPortaDelegata);
  1000.                     stm.setLong(2, idSA);
  1001.                     stm.executeUpdate();
  1002.                 }
  1003.                 stm.close();
  1004.                 DriverConfigurazioneDBLib.logDebug("Inseriti " + i + " associazioni ServizioApplicativo<->PortaDelegata associati alla PortaDelegata[" + idPortaDelegata + "]");

  1005.                 // set prop autenticazione
  1006.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  1007.                 sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_AUTENTICAZIONE_PROP);
  1008.                 sqlQueryObject.addInsertField("id_porta", "?");
  1009.                 sqlQueryObject.addInsertField("nome", "?");
  1010.                 sqlQueryObject.addInsertField("valore", "?");
  1011.                 sqlQueryObject.addInsertField("enc_value", "?");
  1012.                 sqlQuery = sqlQueryObject.createSQLInsert();
  1013.                 stm = con.prepareStatement(sqlQuery);
  1014.                 for (i = 0; i < aPD.sizeProprietaAutenticazioneList(); i++) {
  1015.                     Proprieta propProtocollo = aPD.getProprietaAutenticazione(i);

  1016.                     int indexP = 1;
  1017.                     stm.setLong(indexP++, aPD.getId());
  1018.                     stm.setString(indexP++, propProtocollo.getNome());
  1019.                    
  1020.                     String plainValueP = propProtocollo.getValore();
  1021.                     String encValueP = null;
  1022.                     if(driverBYOK!=null && BYOKUtilities.isWrappedValue(plainValueP) ) {
  1023.                         BYOKWrappedValue byokValue = driverBYOK.wrap(plainValueP);
  1024.                         if(byokValue!=null) {
  1025.                             encValueP = byokValue.getWrappedValue();
  1026.                             plainValueP = byokValue.getWrappedPlainValue();
  1027.                         }
  1028.                     }
  1029.                    
  1030.                     stm.setString(indexP++, plainValueP);
  1031.                     stm.setString(indexP++, encValueP);
  1032.                    
  1033.                     stm.executeUpdate();
  1034.                 }
  1035.                 stm.close();
  1036.                 DriverConfigurazioneDBLib.logDebug("Inseriti " + i + " SetProtocolPropAutenticazione associati alla PortaDelegata[" + idPortaDelegata + "]");
  1037.                
  1038.                
  1039.                 // set prop autorizzazione
  1040.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  1041.                 sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_AUTORIZZAZIONE_PROP);
  1042.                 sqlQueryObject.addInsertField("id_porta", "?");
  1043.                 sqlQueryObject.addInsertField("nome", "?");
  1044.                 sqlQueryObject.addInsertField("valore", "?");
  1045.                 sqlQueryObject.addInsertField("enc_value", "?");
  1046.                 sqlQuery = sqlQueryObject.createSQLInsert();
  1047.                 stm = con.prepareStatement(sqlQuery);
  1048.                 for (i = 0; i < aPD.sizeProprietaAutorizzazioneList(); i++) {
  1049.                     Proprieta propProtocollo = aPD.getProprietaAutorizzazione(i);

  1050.                     int indexP = 1;
  1051.                     stm.setLong(indexP++, aPD.getId());
  1052.                     stm.setString(indexP++, propProtocollo.getNome());
  1053.                    
  1054.                     String plainValueP = propProtocollo.getValore();
  1055.                     String encValueP = null;
  1056.                     if(driverBYOK!=null && BYOKUtilities.isWrappedValue(plainValueP) ) {
  1057.                         BYOKWrappedValue byokValue = driverBYOK.wrap(plainValueP);
  1058.                         if(byokValue!=null) {
  1059.                             encValueP = byokValue.getWrappedValue();
  1060.                             plainValueP = byokValue.getWrappedPlainValue();
  1061.                         }
  1062.                     }
  1063.                    
  1064.                     stm.setString(indexP++, plainValueP);
  1065.                     stm.setString(indexP++, encValueP);
  1066.                    
  1067.                     stm.executeUpdate();
  1068.                 }
  1069.                 stm.close();
  1070.                 DriverConfigurazioneDBLib.logDebug("Inseriti " + i + " SetProtocolPropAutorizzazione associati alla PortaDelegata[" + idPortaDelegata + "]");
  1071.                
  1072.                
  1073.                 // set prop autorizzazione contenuto
  1074.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  1075.                 sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_AUTORIZZAZIONE_CONTENUTI_PROP);
  1076.                 sqlQueryObject.addInsertField("id_porta", "?");
  1077.                 sqlQueryObject.addInsertField("nome", "?");
  1078.                 sqlQueryObject.addInsertField("valore", "?");
  1079.                 sqlQueryObject.addInsertField("enc_value", "?");
  1080.                 sqlQuery = sqlQueryObject.createSQLInsert();
  1081.                 stm = con.prepareStatement(sqlQuery);
  1082.                 for (i = 0; i < aPD.sizeProprietaAutorizzazioneContenutoList(); i++) {
  1083.                     Proprieta propProtocollo = aPD.getProprietaAutorizzazioneContenuto(i);
  1084.                    
  1085.                     int indexP = 1;
  1086.                     stm.setLong(indexP++, aPD.getId());
  1087.                     stm.setString(indexP++, propProtocollo.getNome());
  1088.                    
  1089.                     String plainValueP = propProtocollo.getValore();
  1090.                     String encValueP = null;
  1091.                     if(driverBYOK!=null && BYOKUtilities.isWrappedValue(plainValueP) ) {
  1092.                         BYOKWrappedValue byokValue = driverBYOK.wrap(plainValueP);
  1093.                         if(byokValue!=null) {
  1094.                             encValueP = byokValue.getWrappedValue();
  1095.                             plainValueP = byokValue.getWrappedPlainValue();
  1096.                         }
  1097.                     }
  1098.                    
  1099.                     stm.setString(indexP++, plainValueP);
  1100.                     stm.setString(indexP++, encValueP);
  1101.                    
  1102.                     stm.executeUpdate();
  1103.                 }
  1104.                 stm.close();
  1105.                 DriverConfigurazioneDBLib.logDebug("Inseriti " + i + " SetProtocolPropAutorizzazioneContenuto associati alla PortaDelegata[" + idPortaDelegata + "]");
  1106.                
  1107.                
  1108.                
  1109.                 // set prop rate limiting
  1110.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  1111.                 sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_RATE_LIMITING_PROP);
  1112.                 sqlQueryObject.addInsertField("id_porta", "?");
  1113.                 sqlQueryObject.addInsertField("nome", "?");
  1114.                 sqlQueryObject.addInsertField("valore", "?");
  1115.                 sqlQuery = sqlQueryObject.createSQLInsert();
  1116.                 stm = con.prepareStatement(sqlQuery);
  1117.                 for (i = 0; i < aPD.sizeProprietaRateLimitingList(); i++) {
  1118.                     Proprieta propProtocollo = aPD.getProprietaRateLimiting(i);
  1119.                     stm.setLong(1, aPD.getId());
  1120.                     stm.setString(2, propProtocollo.getNome());
  1121.                     stm.setString(3, propProtocollo.getValore());
  1122.                     stm.executeUpdate();
  1123.                 }
  1124.                 stm.close();
  1125.                 DriverConfigurazioneDBLib.logDebug("Inseriti " + i + " SetProtocolPropRateLimiting associati alla PortaDelegata[" + idPortaDelegata + "]");
  1126.                
  1127.                
  1128.                
  1129.                
  1130.                
  1131.                 // set prop
  1132.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  1133.                 sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_PROP);
  1134.                 sqlQueryObject.addInsertField("id_porta", "?");
  1135.                 sqlQueryObject.addInsertField("nome", "?");
  1136.                 sqlQueryObject.addInsertField("valore", "?");
  1137.                 sqlQueryObject.addInsertField("enc_value", "?");
  1138.                 sqlQuery = sqlQueryObject.createSQLInsert();
  1139.                 stm = con.prepareStatement(sqlQuery);
  1140.                 for (i = 0; i < aPD.sizeProprietaList(); i++) {
  1141.                     Proprieta propProtocollo = aPD.getProprieta(i);
  1142.                    
  1143.                     int indexP = 1;
  1144.                     stm.setLong(indexP++, aPD.getId());
  1145.                     stm.setString(indexP++, propProtocollo.getNome());
  1146.                    
  1147.                     String plainValueP = propProtocollo.getValore();
  1148.                     String encValueP = null;
  1149.                     if(driverBYOK!=null && BYOKUtilities.isWrappedValue(plainValueP) ) {
  1150.                         BYOKWrappedValue byokValue = driverBYOK.wrap(plainValueP);
  1151.                         if(byokValue!=null) {
  1152.                             encValueP = byokValue.getWrappedValue();
  1153.                             plainValueP = byokValue.getWrappedPlainValue();
  1154.                         }
  1155.                     }
  1156.                    
  1157.                     stm.setString(indexP++, plainValueP);
  1158.                     stm.setString(indexP++, encValueP);
  1159.                    
  1160.                     stm.executeUpdate();
  1161.                 }
  1162.                 stm.close();
  1163.                 DriverConfigurazioneDBLib.logDebug("Inseriti " + i + " SetProtocolProp associati alla PortaDelegata[" + idPortaDelegata + "]");
  1164.                
  1165.                 // Ruoli
  1166.                 n=0;
  1167.                 if(aPD.getRuoli()!=null && aPD.getRuoli().sizeRuoloList()>0){
  1168.                     for (int j = 0; j < aPD.getRuoli().sizeRuoloList(); j++) {
  1169.                         Ruolo ruolo = aPD.getRuoli().getRuolo(j);
  1170.                         sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  1171.                         sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_RUOLI);
  1172.                         sqlQueryObject.addInsertField("id_porta", "?");
  1173.                         sqlQueryObject.addInsertField("ruolo", "?");
  1174.                         sqlQuery = sqlQueryObject.createSQLInsert();
  1175.                         stm = con.prepareStatement(sqlQuery);
  1176.                         stm.setLong(1, aPD.getId());
  1177.                         stm.setString(2, ruolo.getNome());
  1178.                         stm.executeUpdate();
  1179.                         stm.close();
  1180.                         n++;
  1181.                         DriverConfigurazioneDBLib.logDebug("Aggiunto ruolo[" + ruolo.getNome() + "] alla PortaDelegata[" + idPortaDelegata + "]");
  1182.                     }
  1183.                 }
  1184.                
  1185.                 DriverConfigurazioneDBLib.logDebug("Aggiunti " + n + " ruoli alla PortaDelegata[" + idPortaDelegata + "]");
  1186.                
  1187.                 // Scope
  1188.                 n=0;
  1189.                 if(aPD.getScope()!=null && aPD.getScope().sizeScopeList()>0){
  1190.                     for (int j = 0; j < aPD.getScope().sizeScopeList(); j++) {
  1191.                         Scope scope = aPD.getScope().getScope(j);
  1192.                         sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  1193.                         sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_SCOPE);
  1194.                         sqlQueryObject.addInsertField("id_porta", "?");
  1195.                         sqlQueryObject.addInsertField("scope", "?");
  1196.                         sqlQuery = sqlQueryObject.createSQLInsert();
  1197.                         stm = con.prepareStatement(sqlQuery);
  1198.                         stm.setLong(1, aPD.getId());
  1199.                         stm.setString(2, scope.getNome());
  1200.                         stm.executeUpdate();
  1201.                         stm.close();
  1202.                         n++;
  1203.                         DriverConfigurazioneDBLib.logDebug("Aggiunto scope[" + scope.getNome() + "] alla PortaDelegata[" + idPortaDelegata + "]");
  1204.                     }
  1205.                 }
  1206.                
  1207.                 DriverConfigurazioneDBLib.logDebug("Aggiunti " + n + " scope alla PortaDelegata[" + idPortaDelegata + "]");
  1208.                
  1209.                
  1210.                 // serviziapplicativi (token)
  1211.                 if(aPD.getAutorizzazioneToken()!=null && aPD.getAutorizzazioneToken().getServiziApplicativi()!=null &&
  1212.                         aPD.getAutorizzazioneToken().getServiziApplicativi().sizeServizioApplicativoList()>0) {
  1213.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  1214.                     sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_TOKEN_SA);
  1215.                     sqlQueryObject.addInsertField("id_porta", "?");
  1216.                     sqlQueryObject.addInsertField("id_servizio_applicativo", "?");
  1217.                     sqlQuery = sqlQueryObject.createSQLInsert();
  1218.                     stm = con.prepareStatement(sqlQuery);
  1219.    
  1220.                     for (i = 0; i < aPD.getAutorizzazioneToken().getServiziApplicativi().sizeServizioApplicativoList(); i++) {
  1221.                         PortaDelegataServizioApplicativo servizioApplicativo = aPD.getAutorizzazioneToken().getServiziApplicativi().getServizioApplicativo(i);
  1222.                         String nomeSA = servizioApplicativo.getNome();
  1223.                         //il tipo e il nome proprietario servizio applicativo sono gli stessi della porta delegata
  1224.                         String nomeProprietarioSA = aPD.getNomeSoggettoProprietario(); //servizioApplicativo.getNomeSoggettoProprietario();
  1225.                         String tipoProprietarioSA = aPD.getTipoSoggettoProprietario(); //servizioApplicativo.getTipoSoggettoProprietario();
  1226.                         if (nomeSA == null || nomeSA.equals(""))
  1227.                             throw new DriverConfigurazioneException("Nome del ServizioApplicativo associato non valido.");
  1228.                         if (nomeProprietarioSA == null || nomeProprietarioSA.equals(""))
  1229.                             throw new DriverConfigurazioneException("Nome Proprietario del ServizioApplicativo associato non valido.");
  1230.                         if (tipoProprietarioSA == null || tipoProprietarioSA.equals(""))
  1231.                             throw new DriverConfigurazioneException("Tipo Proprietario del ServizioApplicativo associato non valido.");
  1232.    
  1233.                         long idSA = DriverConfigurazioneDB_serviziApplicativiLIB.getIdServizioApplicativo(nomeSA, tipoProprietarioSA, nomeProprietarioSA, con, DriverConfigurazioneDBLib.tipoDB,DriverConfigurazioneDBLib.tabellaSoggetti);
  1234.    
  1235.                         if (idSA <= 0)
  1236.                             throw new DriverConfigurazioneException("Impossibile recuperare l'id del Servizio Applicativo [" + nomeSA + "] di [" + tipoProprietarioSA + "/" + nomeProprietarioSA + "]");
  1237.    
  1238.                         stm.setLong(1, idPortaDelegata);
  1239.                         stm.setLong(2, idSA);
  1240.                         stm.executeUpdate();
  1241.                     }
  1242.                     stm.close();
  1243.                     DriverConfigurazioneDBLib.logDebug("Inseriti " + i + " associazioni ServizioApplicativo<->PortaDelegata (token) associati alla PortaDelegata[" + idPortaDelegata + "]");
  1244.                 }
  1245.                
  1246.                 // Ruoli (Token)
  1247.                 n=0;
  1248.                 if(aPD.getAutorizzazioneToken()!=null && aPD.getAutorizzazioneToken().getRuoli()!=null &&
  1249.                         aPD.getAutorizzazioneToken().getRuoli().sizeRuoloList()>0){
  1250.                     for (int j = 0; j < aPD.getAutorizzazioneToken().getRuoli().sizeRuoloList(); j++) {
  1251.                         Ruolo ruolo = aPD.getAutorizzazioneToken().getRuoli().getRuolo(j);
  1252.                         sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  1253.                         sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_TOKEN_RUOLI);
  1254.                         sqlQueryObject.addInsertField("id_porta", "?");
  1255.                         sqlQueryObject.addInsertField("ruolo", "?");
  1256.                         sqlQuery = sqlQueryObject.createSQLInsert();
  1257.                         stm = con.prepareStatement(sqlQuery);
  1258.                         stm.setLong(1, aPD.getId());
  1259.                         stm.setString(2, ruolo.getNome());
  1260.                         stm.executeUpdate();
  1261.                         stm.close();
  1262.                         n++;
  1263.                         DriverConfigurazioneDBLib.logDebug("Aggiunto ruolo[" + ruolo.getNome() + "] (token) alla PortaDelegata[" + idPortaDelegata + "]");
  1264.                     }
  1265.                 }
  1266.                
  1267.                 DriverConfigurazioneDBLib.logDebug("Aggiunti " + n + " ruoli (token) alla PortaDelegata[" + idPortaDelegata + "]");
  1268.                
  1269.                 // Azioni
  1270.                 n=0;
  1271.                 if(aPD.getAzione()!=null && aPD.getAzione().sizeAzioneDelegataList()>0){
  1272.                     for (int j = 0; j < aPD.getAzione().sizeAzioneDelegataList(); j++) {
  1273.                         String azioneDelegata = aPD.getAzione().getAzioneDelegata(j);
  1274.                         sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  1275.                         sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_AZIONI);
  1276.                         sqlQueryObject.addInsertField("id_porta", "?");
  1277.                         sqlQueryObject.addInsertField("azione", "?");
  1278.                         sqlQuery = sqlQueryObject.createSQLInsert();
  1279.                         stm = con.prepareStatement(sqlQuery);
  1280.                         stm.setLong(1, aPD.getId());
  1281.                         stm.setString(2, azioneDelegata);
  1282.                         stm.executeUpdate();
  1283.                         stm.close();
  1284.                         n++;
  1285.                         DriverConfigurazioneDBLib.logDebug("Aggiunto azione delegata [" + azioneDelegata + "] alla PortaDelegata[" + idPortaDelegata + "]");
  1286.                     }
  1287.                 }
  1288.                
  1289.                 DriverConfigurazioneDBLib.logDebug("Aggiunte " + n + " azioni delegate alla PortaDelegata[" + idPortaDelegata + "]");
  1290.                
  1291.                
  1292.                 // Cache Regole
  1293.                 n=0;
  1294.                 if(responseCacheRegole!=null && responseCacheRegole.size()>0){
  1295.                     for (int j = 0; j < responseCacheRegole.size(); j++) {
  1296.                         ResponseCachingConfigurazioneRegola regola = responseCacheRegole.get(j);
  1297.                         sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  1298.                         sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_CACHE_REGOLE);
  1299.                         sqlQueryObject.addInsertField("id_porta", "?");
  1300.                         if(regola.getReturnCodeMin()!=null && regola.getReturnCodeMin()>0) {
  1301.                             sqlQueryObject.addInsertField("status_min", "?");
  1302.                         }
  1303.                         if(regola.getReturnCodeMax()!=null && regola.getReturnCodeMax()>0) {
  1304.                             sqlQueryObject.addInsertField("status_max", "?");
  1305.                         }
  1306.                         sqlQueryObject.addInsertField("fault", "?");
  1307.                         if(regola.getCacheTimeoutSeconds()!=null && regola.getCacheTimeoutSeconds()>0) {
  1308.                             sqlQueryObject.addInsertField("cache_seconds", "?");
  1309.                         }
  1310.                         sqlQuery = sqlQueryObject.createSQLInsert();
  1311.                         stm = con.prepareStatement(sqlQuery);
  1312.                         int indexCR = 1;
  1313.                         stm.setLong(indexCR++, aPD.getId());
  1314.                         if(regola.getReturnCodeMin()!=null && regola.getReturnCodeMin()>0) {
  1315.                             stm.setInt(indexCR++, regola.getReturnCodeMin());
  1316.                         }
  1317.                         if(regola.getReturnCodeMax()!=null && regola.getReturnCodeMax()>0) {
  1318.                             stm.setInt(indexCR++, regola.getReturnCodeMax());
  1319.                         }
  1320.                         stm.setInt(indexCR++, regola.getFault() ? CostantiDB.TRUE : CostantiDB.FALSE);
  1321.                         if(regola.getCacheTimeoutSeconds()!=null && regola.getCacheTimeoutSeconds()>0) {
  1322.                             stm.setInt(indexCR++, regola.getCacheTimeoutSeconds());
  1323.                         }
  1324.                         stm.executeUpdate();
  1325.                         stm.close();
  1326.                         n++;
  1327.                         DriverConfigurazioneDBLib.logDebug("Aggiunta regola di cache alla PortaDelegata[" + idPortaDelegata + "]");
  1328.                     }
  1329.                 }
  1330.                
  1331.                 DriverConfigurazioneDBLib.logDebug("Aggiunte " + n + " regole di cache alla PortaDelegata[" + idPortaDelegata + "]");
  1332.                
  1333.                
  1334.                 // AttributeAuthority
  1335.                 n=0;
  1336.                 if(aPD.sizeAttributeAuthorityList()>0){
  1337.                     for (int j = 0; j < aPD.sizeAttributeAuthorityList(); j++) {
  1338.                         AttributeAuthority aa = aPD.getAttributeAuthority(j);
  1339.                        
  1340.                         String attributi = null;
  1341.                         if(aa.sizeAttributoList()>0) {
  1342.                             StringBuilder bf = new StringBuilder();
  1343.                             for (int aaI = 0; aaI < aa.sizeAttributoList(); aaI++) {
  1344.                                 if(aaI>0) {
  1345.                                     bf.append(",");
  1346.                                 }
  1347.                                 bf.append(aa.getAttributo(aaI));
  1348.                             }
  1349.                             attributi = bf.toString();
  1350.                         }
  1351.                        
  1352.                         sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  1353.                         sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_ATTRIBUTE_AUTHORITY);
  1354.                         sqlQueryObject.addInsertField("id_porta", "?");
  1355.                         sqlQueryObject.addInsertField("nome", "?");
  1356.                         sqlQueryObject.addInsertField("attributi", "?");
  1357.                         sqlQuery = sqlQueryObject.createSQLInsert();
  1358.                         stm = con.prepareStatement(sqlQuery);
  1359.                         stm.setLong(1, aPD.getId());
  1360.                         stm.setString(2, aa.getNome());
  1361.                         stm.setString(3, attributi);
  1362.                         stm.executeUpdate();
  1363.                         stm.close();
  1364.                         n++;
  1365.                         DriverConfigurazioneDBLib.logDebug("Aggiunto A.A.[" + aa.getNome() + "] alla PortaDelegata[" + idPortaDelegata + "]");
  1366.                     }
  1367.                 }
  1368.                
  1369.                 DriverConfigurazioneDBLib.logDebug("Aggiunte " + n + " A.A. alla PortaDelegata[" + idPortaDelegata + "]");
  1370.                
  1371.                
  1372.                 // tracciamentoConfigurazione
  1373.                 DriverConfigurazioneDBTracciamentoLIB.crudTracciamentoConfigurazione(type, con, tracciamentoDatabase, aPD.getId(),
  1374.                         CostantiDB.TRACCIAMENTO_CONFIGURAZIONE_PROPRIETARIO_PD,
  1375.                         CostantiDB.TRACCIAMENTO_CONFIGURAZIONE_TIPO_DB);
  1376.                
  1377.                 DriverConfigurazioneDBTracciamentoLIB.crudTracciamentoConfigurazione(type, con, tracciamentoFiletrace, aPD.getId(),
  1378.                         CostantiDB.TRACCIAMENTO_CONFIGURAZIONE_PROPRIETARIO_PD,
  1379.                         CostantiDB.TRACCIAMENTO_CONFIGURAZIONE_TIPO_FILETRACE);
  1380.                
  1381.                 DriverConfigurazioneDBTracciamentoLIB.crudTracciamentoConfigurazioneFiletrace(type, con, tracciamentoFiletraceDetails, aPD.getId(),
  1382.                         CostantiDB.TRACCIAMENTO_CONFIGURAZIONE_PROPRIETARIO_PD);
  1383.                
  1384.                 // dumpConfigurazione
  1385.                 DriverConfigurazioneDB_dumpLIB.CRUDDumpConfigurazione(type, con, aPD.getDump(), aPD.getId(), CostantiDB.DUMP_CONFIGURAZIONE_PROPRIETARIO_PD);
  1386.                
  1387.                 // trasformazioni
  1388.                 DriverConfigurazioneDBTrasformazioniLib.CRUDTrasformazioni(type, con, aPD.getTrasformazioni(), aPD.getId(), true);
  1389.                
  1390.                 // handlers
  1391.                 if(configHandlers!=null) {
  1392.                     if(configHandlers.getRequest()!=null) {
  1393.                         DriverConfigurazioneDB_handlerLIB.CRUDConfigurazioneMessageHandlers(type, con, aPD.getId(), null, true, configHandlers.getRequest());
  1394.                     }
  1395.                     if(configHandlers.getResponse()!=null) {
  1396.                         DriverConfigurazioneDB_handlerLIB.CRUDConfigurazioneMessageHandlers(type, con, aPD.getId(), null, false, configHandlers.getResponse());
  1397.                     }
  1398.                 }
  1399.                
  1400.                 // extendedInfo
  1401.                 i=0;
  1402.                 if(aPD.sizeExtendedInfoList()>0){
  1403.                     if(extInfoConfigurazioneDriver!=null){
  1404.                         for (i = 0; i < aPD.sizeExtendedInfoList(); i++) {
  1405.                             extInfoConfigurazioneDriver.createExtendedInfo(con, DriverConfigurazioneDBLib.log, aPD, aPD.getExtendedInfo(i), CRUDType.CREATE);
  1406.                         }
  1407.                     }
  1408.                 }
  1409.                 DriverConfigurazioneDBLib.logDebug("Inseriti " + i + " associazioni ExtendedInfo<->PortaDelegata associati alla PortaDelegata[" + idPortaDelegata + "]");
  1410.                
  1411.                 break;

  1412.             case UPDATE:
  1413.                 //soggetto erogatore
  1414.                 tipoSoggErogatore = (soggErogatore != null ? soggErogatore.getTipo() : null);
  1415.                 nomeSoggErogatore = (soggErogatore != null ? soggErogatore.getNome() : null);
  1416.                 if(tipoSoggErogatore==null || tipoSoggErogatore.equals("")) throw new DriverConfigurazioneException("Tipo Soggetto Erogatore non impostato.");
  1417.                 if(nomeSoggErogatore==null || nomeSoggErogatore.equals("")) throw new DriverConfigurazioneException("Nome Soggetto Erogatore non impostato.");

  1418.                 //servizio
  1419.                 tipoServizio = (servizio != null ? servizio.getTipo() : null);
  1420.                 nomeServizio = (servizio != null ? servizio.getNome() : null);
  1421.                 versioneServizio = (servizio != null ? servizio.getVersione() : null);
  1422.                 if(tipoServizio==null || tipoServizio.equals("")) throw new DriverConfigurazioneException("Tipo Servizio non impostato.");
  1423.                 if(nomeServizio==null || nomeServizio.equals("")) throw new DriverConfigurazioneException("Nome Servizio non impostato.");
  1424.                 if(versioneServizio==null) throw new DriverConfigurazioneException("Versione Servizio non impostato.");

  1425.                 //Azione
  1426.                 nomeAzione = (azione != null ? azione.getNome() : null);
  1427.                 patternAzione = (azione != null ? azione.getPattern() : null);
  1428.                 modeAzione = (azione != null ? azione.getIdentificazione() : null);
  1429.                 nomePortaDeleganteAzione = (azione != null ? azione.getNomePortaDelegante() : null);
  1430.                 forceInterfaceBased = (azione != null ? azione.getForceInterfaceBased() : null);
  1431.                 //Se il bean Azione nn e' presente allora non controllo nulla
  1432.                 if(azione!=null){
  1433.                     if(modeAzione==null || modeAzione.equals(""))
  1434.                         modeAzione = PortaDelegataAzioneIdentificazione.STATIC;
  1435.                     switch (modeAzione) {
  1436.                     case CONTENT_BASED:
  1437.                     case URL_BASED:
  1438.                     case HEADER_BASED:
  1439.                         if(patternAzione==null || patternAzione.equals("")) throw new DriverConfigurazioneException("Pattern Azione non impostato.");
  1440.                         nomeAzione=null;
  1441.                         break;
  1442.                     case DELEGATED_BY:
  1443.                         if(nomePortaDeleganteAzione==null || nomePortaDeleganteAzione.equals("")) throw new DriverConfigurazioneException("Nome Porta Delegante Azione non impostata.");
  1444.                         nomeAzione=null;
  1445.                         break;
  1446.                     case INPUT_BASED:
  1447.                     case SOAP_ACTION_BASED:
  1448.                     case INTERFACE_BASED:
  1449.                         //nessun campo obbligatorio
  1450.                         break;
  1451.                     case STATIC:
  1452.                         //se non c'e' l'id dell'azione ci deve essere il nome
  1453.                         if(idAzione<=0){
  1454.                             if(nomeAzione==null || nomeAzione.equals("")) throw new DriverConfigurazioneException("Nome Azione non impostato.");
  1455.                         }
  1456.                         patternAzione=null;
  1457.                         break;
  1458.                     default:
  1459.                         break;
  1460.                     }
  1461.                 }

  1462.                 // update
  1463.                 String oldNomePD = null;
  1464.                 if(aPD.getOldIDPortaDelegataForUpdate()!=null){
  1465.                     oldNomePD = aPD.getOldIDPortaDelegataForUpdate().getNome();
  1466.                 }
  1467.                 DriverConfigurazioneDBLib.logDebug("OLD-PD["+oldNomePD+"] PD["+nomePorta+"]");
  1468.                
  1469.                 if (oldNomePD == null || oldNomePD.equals("")){
  1470.                     DriverConfigurazioneDBLib.logDebug("old nomePD is null, assegno: "+nomePorta);
  1471.                     oldNomePD = nomePorta;
  1472.                 }

  1473.                 /** if(aPD.getId() == null || aPD.getId()<=0) throw new*/
  1474.                 // DriverConfigurazioneException("[DriverConfigurazioneDB_LIB::CRUDPortaDelegata(UPDATE)]
  1475.                 // L'id della porta e' necessario per effettuare l'UPDATE.");
  1476.                 idPortaDelegata = DBUtils.getIdPortaDelegata(oldNomePD, con, DriverConfigurazioneDBLib.tipoDB);
  1477.                 // Puo' darsi che l'old soggetto e il nuovo soggetto siano la stesso soggetto della tabella. E' stato cambiato il nome.
  1478.                 if(idPortaDelegata<=0) {
  1479.                     idPortaDelegata = DBUtils.getIdPortaDelegata(oldNomePD, con, DriverConfigurazioneDBLib.tipoDB);
  1480.                 }
  1481.                 if(idPortaDelegata<=0)
  1482.                     throw new DriverConfigurazioneException("[DriverConfigurazioneDB_LIB::CRUDPortaDelegata(UPDATE)] id porta delegata non trovato nome["+oldNomePD+"]");
  1483.                 aPD.setId(idPortaDelegata);
  1484.                
  1485.                 String utenteUltimaModifica = null;
  1486.                 if(aPD.getProprietaOggetto()!=null && aPD.getProprietaOggetto().getUtenteUltimaModifica()!=null) {
  1487.                     utenteUltimaModifica = aPD.getProprietaOggetto().getUtenteUltimaModifica();
  1488.                 }
  1489.                
  1490.                 Timestamp dataUltimaModifica = null;
  1491.                 if(aPD.getProprietaOggetto()!=null && aPD.getProprietaOggetto().getDataUltimaModifica()!=null) {
  1492.                     dataUltimaModifica = new Timestamp(aPD.getProprietaOggetto().getDataUltimaModifica().getTime());
  1493.                 }
  1494.                 else {
  1495.                     dataUltimaModifica = DateManager.getTimestamp();
  1496.                 }
  1497.                
  1498.                
  1499.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  1500.                 sqlQueryObject.addUpdateTable(CostantiDB.PORTE_DELEGATE);
  1501.                 sqlQueryObject.addUpdateField("nome_porta", "?");
  1502.                 sqlQueryObject.addUpdateField("descrizione", "?");
  1503.                 sqlQueryObject.addUpdateField("id_soggetto_erogatore", "?");
  1504.                 sqlQueryObject.addUpdateField("tipo_soggetto_erogatore", "?");
  1505.                 sqlQueryObject.addUpdateField("nome_soggetto_erogatore", "?");
  1506.                 sqlQueryObject.addUpdateField("id_servizio", "?");
  1507.                 sqlQueryObject.addUpdateField("tipo_servizio", "?");
  1508.                 sqlQueryObject.addUpdateField("nome_servizio", "?");
  1509.                 sqlQueryObject.addUpdateField("versione_servizio", "?");
  1510.                 sqlQueryObject.addUpdateField("id_azione", "?");
  1511.                 sqlQueryObject.addUpdateField("nome_azione", "?");
  1512.                 sqlQueryObject.addUpdateField("mode_azione", "?");
  1513.                 sqlQueryObject.addUpdateField("pattern_azione", "?");
  1514.                 sqlQueryObject.addUpdateField("nome_porta_delegante_azione", "?");
  1515.                 sqlQueryObject.addUpdateField("force_interface_based_azione", "?");
  1516.                 sqlQueryObject.addUpdateField("autenticazione", "?");
  1517.                 sqlQueryObject.addUpdateField("autenticazione_opzionale", "?");
  1518.                 sqlQueryObject.addUpdateField("token_policy", "?");
  1519.                 sqlQueryObject.addUpdateField("token_opzionale", "?");
  1520.                 sqlQueryObject.addUpdateField("token_validazione", "?");
  1521.                 sqlQueryObject.addUpdateField("token_introspection", "?");
  1522.                 sqlQueryObject.addUpdateField("token_user_info", "?");
  1523.                 sqlQueryObject.addUpdateField("token_forward", "?");
  1524.                 sqlQueryObject.addUpdateField("token_options", "?");
  1525.                 sqlQueryObject.addUpdateField("token_authn_issuer", "?");
  1526.                 sqlQueryObject.addUpdateField("token_authn_client_id", "?");
  1527.                 sqlQueryObject.addUpdateField("token_authn_subject", "?");
  1528.                 sqlQueryObject.addUpdateField("token_authn_username", "?");
  1529.                 sqlQueryObject.addUpdateField("token_authn_email", "?");
  1530.                 sqlQueryObject.addUpdateField("autorizzazione", "?");
  1531.                 sqlQueryObject.addUpdateField("autorizzazione_xacml", "?");
  1532.                 sqlQueryObject.addUpdateField("autorizzazione_contenuto", "?");
  1533.                 sqlQueryObject.addUpdateField("mtom_request_mode", "?");
  1534.                 sqlQueryObject.addUpdateField("mtom_response_mode", "?");
  1535.                 sqlQueryObject.addUpdateField("security", "?");
  1536.                 sqlQueryObject.addUpdateField("security_mtom_req", "?");
  1537.                 sqlQueryObject.addUpdateField("security_mtom_res", "?");
  1538.                 sqlQueryObject.addUpdateField("security_request_mode", "?");
  1539.                 sqlQueryObject.addUpdateField("security_response_mode", "?");
  1540.                 sqlQueryObject.addUpdateField("id_soggetto", "?");
  1541.                 sqlQueryObject.addUpdateField("ricevuta_asincrona_sim", "?");
  1542.                 sqlQueryObject.addUpdateField("ricevuta_asincrona_asim", "?");
  1543.                 sqlQueryObject.addUpdateField("integrazione", "?");
  1544.                 sqlQueryObject.addUpdateField("scadenza_correlazione_appl", "?");
  1545.                 sqlQueryObject.addUpdateField("validazione_contenuti_stato", "?");
  1546.                 sqlQueryObject.addUpdateField("validazione_contenuti_tipo", "?");
  1547.                 sqlQueryObject.addUpdateField("validazione_contenuti_mtom", "?");              
  1548.                 sqlQueryObject.addUpdateField("allega_body", "?");
  1549.                 sqlQueryObject.addUpdateField("scarta_body", "?");
  1550.                 sqlQueryObject.addUpdateField("gestione_manifest", "?");
  1551.                 sqlQueryObject.addUpdateField("stateless", "?");
  1552.                 sqlQueryObject.addUpdateField("local_forward", "?");
  1553.                 sqlQueryObject.addUpdateField("local_forward_pa", "?");
  1554.                 sqlQueryObject.addUpdateField("ruoli_match", "?");
  1555.                 sqlQueryObject.addUpdateField("token_sa_stato", "?");
  1556.                 sqlQueryObject.addUpdateField("token_ruoli_stato", "?");
  1557.                 sqlQueryObject.addUpdateField("token_ruoli_match", "?");
  1558.                 sqlQueryObject.addUpdateField("token_ruoli_tipologia", "?");
  1559.                 sqlQueryObject.addUpdateField("scope_stato", "?");
  1560.                 sqlQueryObject.addUpdateField("scope_match", "?");
  1561.                 sqlQueryObject.addUpdateField("ricerca_porta_azione_delegata", "?");
  1562.                 sqlQueryObject.addUpdateField("msg_diag_severita", "?");
  1563.                 sqlQueryObject.addUpdateField("tracciamento_stato", "?");
  1564.                 sqlQueryObject.addUpdateField("tracciamento_esiti", "?");
  1565.                 sqlQueryObject.addUpdateField("transazioni_tempi", "?");
  1566.                 sqlQueryObject.addUpdateField("transazioni_token", "?");
  1567.                 sqlQueryObject.addUpdateField("stato", "?");
  1568.                 // cors
  1569.                 sqlQueryObject.addUpdateField("cors_stato", "?");
  1570.                 sqlQueryObject.addUpdateField("cors_tipo", "?");
  1571.                 sqlQueryObject.addUpdateField("cors_all_allow_origins", "?");
  1572.                 sqlQueryObject.addUpdateField("cors_all_allow_methods", "?");
  1573.                 sqlQueryObject.addUpdateField("cors_all_allow_headers", "?");
  1574.                 sqlQueryObject.addUpdateField("cors_allow_credentials", "?");
  1575.                 sqlQueryObject.addUpdateField("cors_allow_max_age", "?");
  1576.                 sqlQueryObject.addUpdateField("cors_allow_max_age_seconds", "?");
  1577.                 sqlQueryObject.addUpdateField("cors_allow_origins", "?");
  1578.                 sqlQueryObject.addUpdateField("cors_allow_headers", "?");
  1579.                 sqlQueryObject.addUpdateField("cors_allow_methods", "?");
  1580.                 sqlQueryObject.addUpdateField("cors_allow_expose_headers", "?");
  1581.                 // responseCaching
  1582.                 sqlQueryObject.addUpdateField("response_cache_stato", "?");
  1583.                 sqlQueryObject.addUpdateField("response_cache_seconds", "?");
  1584.                 sqlQueryObject.addUpdateField("response_cache_max_msg_size", "?");
  1585.                 sqlQueryObject.addUpdateField("response_cache_control_nocache", "?");
  1586.                 sqlQueryObject.addUpdateField("response_cache_control_maxage", "?");
  1587.                 sqlQueryObject.addUpdateField("response_cache_control_nostore", "?");
  1588.                 sqlQueryObject.addUpdateField("response_cache_hash_url", "?");
  1589.                 sqlQueryObject.addUpdateField("response_cache_hash_query", "?");
  1590.                 sqlQueryObject.addUpdateField("response_cache_hash_query_list", "?");
  1591.                 sqlQueryObject.addUpdateField("response_cache_hash_headers", "?");
  1592.                 sqlQueryObject.addUpdateField("response_cache_hash_hdr_list", "?");
  1593.                 sqlQueryObject.addUpdateField("response_cache_hash_payload", "?");
  1594.                 // id
  1595.                 sqlQueryObject.addUpdateField("id_accordo", "?");
  1596.                 sqlQueryObject.addUpdateField("id_port_type", "?");
  1597.                 // options
  1598.                 sqlQueryObject.addUpdateField("options", "?");
  1599.                 // canale
  1600.                 sqlQueryObject.addUpdateField("canale", "?");
  1601.                
  1602.                 if(utenteUltimaModifica!=null) {
  1603.                     sqlQueryObject.addUpdateField(CostantiDB.PROPRIETA_OGGETTO_UTENTE_ULTIMA_MODIFICA, "?");
  1604.                 }
  1605.                 if(dataUltimaModifica!=null) {
  1606.                     sqlQueryObject.addUpdateField(CostantiDB.PROPRIETA_OGGETTO_DATA_ULTIMA_MODIFICA, "?");
  1607.                 }
  1608.                
  1609.                 sqlQueryObject.addWhereCondition("id=?");
  1610.                 sqlQueryObject.setANDLogicOperator(true);
  1611.                 sqlQuery = sqlQueryObject.createSQLUpdate();
  1612.                 stm = con.prepareStatement(sqlQuery);

  1613.                 index = 1;
  1614.                 stm.setString(index++, nomePorta);
  1615.                 stm.setString(index++, descrizione);
  1616.                 stm.setLong(index++, idSoggettoErogatore);
  1617.                 stm.setString(index++, tipoSoggErogatore);
  1618.                 stm.setString(index++, nomeSoggErogatore);
  1619.                 stm.setLong(index++, idServizioPD);
  1620.                 stm.setString(index++, tipoServizio);
  1621.                 stm.setString(index++, nomeServizio);
  1622.                 stm.setInt(index++, versioneServizio);
  1623.                 stm.setLong(index++, idAzione);
  1624.                 stm.setString(index++, nomeAzione);
  1625.                 if(modeAzione!=null)
  1626.                     stm.setString(index++, modeAzione.toString());
  1627.                 else
  1628.                     stm.setString(index++, null);
  1629.                 stm.setString(index++, patternAzione);
  1630.                 stm.setString(index++, nomePortaDeleganteAzione);
  1631.                 stm.setString(index++, DriverConfigurazioneDBLib.getValue(forceInterfaceBased));
  1632.                 // autenticazione
  1633.                 stm.setString(index++, autenticazione);
  1634.                 stm.setString(index++, aPD!=null ? DriverConfigurazioneDBLib.getValue(aPD.getAutenticazioneOpzionale()) : null);
  1635.                 // token
  1636.                 stm.setString(index++, gestioneToken!=null ? gestioneToken.getPolicy() : null);
  1637.                 stm.setString(index++, gestioneToken!=null ? DriverConfigurazioneDBLib.getValue(gestioneToken.getTokenOpzionale()) : null);
  1638.                 stm.setString(index++, gestioneToken!=null ? DriverConfigurazioneDBLib.getValue(gestioneToken.getValidazione()) : null);
  1639.                 stm.setString(index++, gestioneToken!=null ? DriverConfigurazioneDBLib.getValue(gestioneToken.getIntrospection()) : null);
  1640.                 stm.setString(index++, gestioneToken!=null ? DriverConfigurazioneDBLib.getValue(gestioneToken.getUserInfo()) : null);
  1641.                 stm.setString(index++, gestioneToken!=null ? DriverConfigurazioneDBLib.getValue(gestioneToken.getForward()) : null);
  1642.                 stm.setString(index++, gestioneToken!=null ? gestioneToken.getOptions() : null);
  1643.                 stm.setString(index++, (gestioneToken!=null && gestioneToken.getAutenticazione()!=null) ?
  1644.                         DriverConfigurazioneDBLib.getValue(gestioneToken.getAutenticazione().getIssuer()) : null);
  1645.                 stm.setString(index++, (gestioneToken!=null && gestioneToken.getAutenticazione()!=null) ?
  1646.                         DriverConfigurazioneDBLib.getValue(gestioneToken.getAutenticazione().getClientId()) : null);
  1647.                 stm.setString(index++, (gestioneToken!=null && gestioneToken.getAutenticazione()!=null) ?
  1648.                         DriverConfigurazioneDBLib.getValue(gestioneToken.getAutenticazione().getSubject()) : null);
  1649.                 stm.setString(index++, (gestioneToken!=null && gestioneToken.getAutenticazione()!=null) ?
  1650.                         DriverConfigurazioneDBLib.getValue(gestioneToken.getAutenticazione().getUsername()) : null);
  1651.                 stm.setString(index++, (gestioneToken!=null && gestioneToken.getAutenticazione()!=null) ?
  1652.                         DriverConfigurazioneDBLib.getValue(gestioneToken.getAutenticazione().getEmail()) : null);
  1653.                 // autorizzazione
  1654.                 stm.setString(index++, autorizzazione);
  1655.                 stm.setString(index++, autorizzazioneXacmlPolicy);
  1656.                 stm.setString(index++, autorizzazioneContenuto);
  1657.                 // mtom
  1658.                 stm.setString(index++, DriverConfigurazioneDBLib.getValue(mtomModeRequest));
  1659.                 stm.setString(index++, DriverConfigurazioneDBLib.getValue(mtomModeResponse));
  1660.                 // messageSecurity
  1661.                 stm.setString(index++, messageSecurityStatus);
  1662.                 stm.setString(index++, DriverConfigurazioneDBLib.getValue(messageSecurityApplyMtomRequest));
  1663.                 stm.setString(index++, DriverConfigurazioneDBLib.getValue(messageSecurityApplyMtomResponse));
  1664.                 stm.setString(index++, securityRequestMode);
  1665.                 stm.setString(index++, securityResponseMode);
  1666.                 // soggettoProprietario
  1667.                 stm.setLong(index++, idSoggettoProprietario);
  1668.                 //ricevuta asincrona_asimmetrica/simmetrica
  1669.                 stm.setString(index++, DriverConfigurazioneDBLib.getValue(aPD.getRicevutaAsincronaSimmetrica()));
  1670.                 stm.setString(index++, DriverConfigurazioneDBLib.getValue(aPD.getRicevutaAsincronaAsimmetrica()));
  1671.                 //integrazione
  1672.                 stm.setString(index++, aPD.getIntegrazione());
  1673.                 //scadenza correlazione applicativa
  1674.                 stm.setString(index++, aPD.getCorrelazioneApplicativa()!=null ? aPD.getCorrelazioneApplicativa().getScadenza() : null);
  1675.                 //validazione xsd
  1676.                 stm.setString(index++, aPD.getValidazioneContenutiApplicativi()!=null ? DriverConfigurazioneDBLib.getValue(aPD.getValidazioneContenutiApplicativi().getStato()) : null);
  1677.                 stm.setString(index++, aPD.getValidazioneContenutiApplicativi()!=null ? DriverConfigurazioneDBLib.getValue(aPD.getValidazioneContenutiApplicativi().getTipo()) : null);
  1678.                 stm.setString(index++, aPD.getValidazioneContenutiApplicativi()!=null ? DriverConfigurazioneDBLib.getValue(aPD.getValidazioneContenutiApplicativi().getAcceptMtomMessage()) : null);
  1679.                 // InvocazionePorta: funzionalita' attachment
  1680.                 stm.setString(index++, aPD!=null ? DriverConfigurazioneDBLib.getValue(aPD.getAllegaBody()) : null);
  1681.                 stm.setString(index++, aPD!=null ? DriverConfigurazioneDBLib.getValue(aPD.getScartaBody()) : null);
  1682.                 stm.setString(index++, aPD!=null ? DriverConfigurazioneDBLib.getValue(aPD.getGestioneManifest()) : null);
  1683.                 // Stateless
  1684.                 stm.setString(index++, aPD!=null ? DriverConfigurazioneDBLib.getValue(aPD.getStateless()) : null);
  1685.                 // LocalForward
  1686.                 stm.setString(index++, aPD!=null && aPD.getLocalForward()!=null ? DriverConfigurazioneDBLib.getValue(aPD.getLocalForward().getStato()) : null);
  1687.                 stm.setString(index++, aPD!=null && aPD.getLocalForward()!=null ? aPD.getLocalForward().getPortaApplicativa() : null);
  1688.                 // Ruoli
  1689.                 stm.setString(index++, aPD!=null && aPD.getRuoli()!=null && aPD.getRuoli().getMatch()!=null ?
  1690.                         aPD.getRuoli().getMatch().getValue() : null);
  1691.                 // Token sa
  1692.                 stm.setString(index++, aPD!=null && aPD.getAutorizzazioneToken()!=null && aPD.getAutorizzazioneToken().getAutorizzazioneApplicativi()!=null ?
  1693.                         DriverConfigurazioneDBLib.getValue(aPD.getAutorizzazioneToken().getAutorizzazioneApplicativi()) : null);    
  1694.                 // Token ruoli
  1695.                 stm.setString(index++, aPD!=null && aPD.getAutorizzazioneToken()!=null && aPD.getAutorizzazioneToken().getAutorizzazioneRuoli()!=null ?
  1696.                         DriverConfigurazioneDBLib.getValue(aPD.getAutorizzazioneToken().getAutorizzazioneRuoli()) : null);
  1697.                 stm.setString(index++, aPD!=null && aPD.getAutorizzazioneToken()!=null && aPD.getAutorizzazioneToken().getRuoli()!=null &&
  1698.                         aPD.getAutorizzazioneToken().getRuoli().getMatch()!=null ?
  1699.                         aPD.getAutorizzazioneToken().getRuoli().getMatch().getValue() : null);
  1700.                 stm.setString(index++, aPD!=null && aPD.getAutorizzazioneToken()!=null && aPD.getAutorizzazioneToken().getTipologiaRuoli()!=null ?
  1701.                         aPD.getAutorizzazioneToken().getTipologiaRuoli().getValue() : null);
  1702.                 // Scope
  1703.                 stm.setString(index++, aPD!=null && aPD.getScope()!=null && aPD.getScope().getStato()!=null ?
  1704.                         DriverConfigurazioneDBLib.getValue(aPD.getScope().getStato()) : null);
  1705.                 stm.setString(index++, aPD!=null && aPD.getScope()!=null && aPD.getScope().getMatch()!=null ?
  1706.                         aPD.getScope().getMatch().getValue() : null);
  1707.                 // RicercaPortaAzioneDelegata
  1708.                 stm.setString(index++, aPD!=null ? DriverConfigurazioneDBLib.getValue(aPD.getRicercaPortaAzioneDelegata()) : null);
  1709.                 // Tracciamento
  1710.                 stm.setString(index++, msgDiagSeverita);
  1711.                 stm.setString(index++, tracciamentoStato);
  1712.                 stm.setString(index++, tracciamentoEsiti);
  1713.                 stm.setString(index++, transazioniTempiElaborazione);
  1714.                 stm.setString(index++, transazioniToken);
  1715.                 // Stato
  1716.                 stm.setString(index++, aPD!=null ? DriverConfigurazioneDBLib.getValue(aPD.getStato()) : null);
  1717.                 // cors
  1718.                 stm.setString(index++, corsStato);
  1719.                 stm.setString(index++, corsTipo);
  1720.                 stm.setString(index++, corsAllAllowOrigins);
  1721.                 stm.setString(index++, corsAllAllowMethods);
  1722.                 stm.setString(index++, corsAllAllowHeaders);
  1723.                 stm.setString(index++, corsAllowCredentials);
  1724.                 stm.setInt(index++, corsAllowMaxAge);
  1725.                 if(corsAllowMaxAgeSeconds!=null) {
  1726.                     stm.setInt(index++, corsAllowMaxAgeSeconds);
  1727.                 }
  1728.                 else {
  1729.                     stm.setNull(index++, java.sql.Types.INTEGER);
  1730.                 }
  1731.                 stm.setString(index++, corsAllowOrigins);
  1732.                 stm.setString(index++, corsAllowHeaders);
  1733.                 stm.setString(index++, corsAllowMethods);
  1734.                 stm.setString(index++, corsAllowExposeHeaders);
  1735.                
  1736.                 // responseCaching
  1737.                 stm.setString(index++, responseCacheStato);
  1738.                 if(responseCacheSeconds!=null) {
  1739.                     stm.setInt(index++, responseCacheSeconds);
  1740.                 }
  1741.                 else {
  1742.                     stm.setNull(index++, java.sql.Types.INTEGER);
  1743.                 }
  1744.                 if(responseCacheMaxMsgSize!=null) {
  1745.                     stm.setLong(index++, responseCacheMaxMsgSize);
  1746.                 }
  1747.                 else {
  1748.                     stm.setNull(index++, java.sql.Types.BIGINT);
  1749.                 }
  1750.                 stm.setInt(index++, responseCacheNoCache ? CostantiDB.TRUE : CostantiDB.FALSE);
  1751.                 stm.setInt(index++, responseCacheMaxAge ? CostantiDB.TRUE : CostantiDB.FALSE);
  1752.                 stm.setInt(index++, responseCacheNoStore ? CostantiDB.TRUE : CostantiDB.FALSE);
  1753.                 stm.setString(index++, responseCacheHashUrl);
  1754.                 stm.setString(index++, responseCacheHashQuery);
  1755.                 stm.setString(index++, responseCacheHashQueryList);
  1756.                 stm.setString(index++, responseCacheHashHeaders);
  1757.                 stm.setString(index++, responseCacheHashHeadersList);
  1758.                 stm.setString(index++, responseCacheHashPayload);
  1759.                 //idAccordo
  1760.                 stm.setLong(index++,aPD.getIdAccordo() != null ? aPD.getIdAccordo() : -1L);
  1761.                 stm.setLong(index++, aPD.getIdPortType() != null ? aPD.getIdPortType() : -1L);
  1762.                 // options
  1763.                 stm.setString(index++, aPD.getOptions());
  1764.                 // canale
  1765.                 stm.setString(index++, aPD.getCanale());
  1766.                
  1767.                 if(utenteUltimaModifica!=null) {
  1768.                     stm.setString(index++, utenteUltimaModifica);
  1769.                 }
  1770.                
  1771.                 if(dataUltimaModifica!=null) {
  1772.                     stm.setTimestamp(index++, dataUltimaModifica);
  1773.                 }
  1774.                
  1775.                 // where
  1776.                 stm.setLong(index++, idPortaDelegata);

  1777.                 /**DriverConfigurazioneDB_LIB.log.debug("eseguo query: " + DBUtils.formatSQLString(sqlQuery, nomePorta, descrizione,
  1778.                 // soggErogatore.getId(), soggErogatore.getTipo(), soggErogatore.getNome(), soggErogatore.getIdentificazione(), servizio.getId(),
  1779.                 // servizio.getTipo(), servizio.getNome(), servizio.getIdentificazione(), azione.getId(), azione.getNome(), azione.getIdentificazione(),
  1780.                 // autenticazione, autorizzazione, messageSecurityStatus, idSoggettoProprietario, idPortaDelegata));*/

  1781.                 n = stm.executeUpdate();
  1782.                 stm.close();
  1783.                 DriverConfigurazioneDBLib.logDebug("Updated " + n + " row(s).");

  1784.                
  1785.                
  1786.                 // mtom
  1787.                
  1788.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  1789.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_MTOM_REQUEST);
  1790.                 sqlQueryObject.addWhereCondition("id_porta=?");
  1791.                 sqlQuery = sqlQueryObject.createSQLDelete();
  1792.                 stm = con.prepareStatement(sqlQuery);
  1793.                 stm.setLong(1, idPortaDelegata);
  1794.                 stm.executeUpdate();
  1795.                 stm.close();

  1796.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  1797.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_MTOM_RESPONSE);
  1798.                 sqlQueryObject.addWhereCondition("id_porta=?");
  1799.                 sqlQuery = sqlQueryObject.createSQLDelete();
  1800.                 stm = con.prepareStatement(sqlQuery);
  1801.                 stm.setLong(1, idPortaDelegata);
  1802.                 stm.executeUpdate();
  1803.                 stm.close();
  1804.                
  1805.                 if(mtomProcessor!=null){
  1806.                
  1807.                     MtomProcessorFlowParameter reqParam = null;
  1808.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  1809.                     sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_MTOM_REQUEST);
  1810.                     sqlQueryObject.addInsertField("id_porta", "?");
  1811.                     sqlQueryObject.addInsertField("nome", "?");
  1812.                     sqlQueryObject.addInsertField("pattern", "?");
  1813.                     sqlQueryObject.addInsertField("content_type", "?");
  1814.                     sqlQueryObject.addInsertField("required", "?");
  1815.                     sqlQuery = sqlQueryObject.createSQLInsert();
  1816.                     stm = con.prepareStatement(sqlQuery);
  1817.    
  1818.                     i = 0;
  1819.                     if(mtomProcessor.getRequestFlow()!=null){
  1820.                         MtomProcessorFlow flow = mtomProcessor.getRequestFlow();
  1821.                         for (i = 0; i < flow.sizeParameterList(); i++) {
  1822.                             reqParam = flow.getParameter(i);
  1823.                             stm.setLong(1, idPortaDelegata);
  1824.                             stm.setString(2, reqParam.getNome());
  1825.                             stm.setString(3, reqParam.getPattern());
  1826.                             stm.setString(4, reqParam.getContentType());
  1827.                             stm.setInt(5, reqParam.getRequired() ? CostantiDB.TRUE : CostantiDB.FALSE);
  1828.    
  1829.                             stm.executeUpdate();
  1830.                         }  
  1831.                     }
  1832.                     stm.close();
  1833.                     DriverConfigurazioneDBLib.logDebug("Inserted " + i + " mtom request flow con id=" + idPortaDelegata);
  1834.    
  1835.                     MtomProcessorFlowParameter resParam = null;
  1836.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  1837.                     sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_MTOM_RESPONSE);
  1838.                     sqlQueryObject.addInsertField("id_porta", "?");
  1839.                     sqlQueryObject.addInsertField("nome", "?");
  1840.                     sqlQueryObject.addInsertField("pattern", "?");
  1841.                     sqlQueryObject.addInsertField("content_type", "?");
  1842.                     sqlQueryObject.addInsertField("required", "?");
  1843.                     sqlQuery = sqlQueryObject.createSQLInsert();
  1844.                     stm = con.prepareStatement(sqlQuery);
  1845.                    
  1846.                     i = 0;
  1847.                     if(mtomProcessor.getResponseFlow()!=null){
  1848.                         MtomProcessorFlow flow = mtomProcessor.getResponseFlow();
  1849.                         for (i = 0; i < flow.sizeParameterList(); i++) {
  1850.                             resParam = flow.getParameter(i);
  1851.                             stm.setLong(1, idPortaDelegata);
  1852.                             stm.setString(2, resParam.getNome());
  1853.                             stm.setString(3, resParam.getPattern());
  1854.                             stm.setString(4, resParam.getContentType());
  1855.                             stm.setInt(5, resParam.getRequired() ? CostantiDB.TRUE : CostantiDB.FALSE);
  1856.    
  1857.                             stm.executeUpdate();
  1858.                         }
  1859.                     }
  1860.                     stm.close();
  1861.                     DriverConfigurazioneDBLib.logDebug("Inserted " + i + " mtom response flow con id=" + idPortaDelegata);
  1862.                    
  1863.                 }
  1864.                
  1865.                
  1866.                
  1867.                 // se security abilitato setto la lista
  1868.                 // la lista contiene tutti e soli gli elementi necessari quindi resetto la lista nel db e riscrivo la lista nuova
  1869.                 /**if ((messageSecurity != null) && CostantiConfigurazione.ABILITATO.toString().equals(messageSecurityStatus) )  {*/
  1870.                 // Devo settarli sempre se ci sono, in modo che lo switch abilitato-disabilitato funzioni
  1871.                 if ((messageSecurity != null) )  {

  1872.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  1873.                     sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST);
  1874.                     sqlQueryObject.addWhereCondition("id_porta=?");
  1875.                     sqlQuery = sqlQueryObject.createSQLDelete();
  1876.                     stm = con.prepareStatement(sqlQuery);
  1877.                     stm.setLong(1, idPortaDelegata);
  1878.                     stm.executeUpdate();
  1879.                     stm.close();

  1880.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  1881.                     sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE);
  1882.                     sqlQueryObject.addWhereCondition("id_porta=?");
  1883.                     sqlQuery = sqlQueryObject.createSQLDelete();
  1884.                     stm = con.prepareStatement(sqlQuery);
  1885.                     stm.setLong(1, idPortaDelegata);
  1886.                     stm.executeUpdate();
  1887.                     stm.close();

  1888.                     //inserisco i valori presenti nella lista
  1889.                     MessageSecurityFlowParameter reqParam = null;
  1890.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  1891.                     sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST);
  1892.                     sqlQueryObject.addInsertField("id_porta", "?");
  1893.                     sqlQueryObject.addInsertField("nome", "?");
  1894.                     sqlQueryObject.addInsertField("valore", "?");
  1895.                     sqlQueryObject.addInsertField("enc_value", "?");
  1896.                     sqlQuery = sqlQueryObject.createSQLInsert();
  1897.                     stm = con.prepareStatement(sqlQuery);

  1898.                     i = 0;
  1899.                     if(messageSecurity.getRequestFlow()!=null){
  1900.                         MessageSecurityFlow flow = messageSecurity.getRequestFlow();
  1901.                         for (i = 0; i < flow.sizeParameterList(); i++) {
  1902.                             reqParam = flow.getParameter(i);
  1903.                             int indexSec = 1;
  1904.                             stm.setLong(indexSec++, idPortaDelegata);
  1905.                             stm.setString(indexSec++, reqParam.getNome());
  1906.                            
  1907.                             String plainValue = reqParam.getValore();
  1908.                             String encValue = null;
  1909.                             if(driverBYOK!=null &&
  1910.                                     (
  1911.                                             DriverConfigurazioneDB_genericPropertiesDriver.isConfidentialProperty(securityRequestMode, reqParam.getNome())
  1912.                                             ||
  1913.                                             BYOKUtilities.isWrappedValue(plainValue)
  1914.                                     )
  1915.                             ) {
  1916.                                 BYOKWrappedValue byokValue = driverBYOK.wrap(plainValue);
  1917.                                 if(byokValue!=null) {
  1918.                                     encValue = byokValue.getWrappedValue();
  1919.                                     plainValue = byokValue.getWrappedPlainValue();
  1920.                                 }
  1921.                             }
  1922.                             stm.setString(indexSec++, plainValue);
  1923.                             stm.setString(indexSec++, encValue);
  1924.                            
  1925.                             stm.executeUpdate();
  1926.                         }
  1927.                     }
  1928.                     stm.close();
  1929.                     DriverConfigurazioneDBLib.logDebug("Inserted " + i + " request flow con id=" + idPortaDelegata);

  1930.                     MessageSecurityFlowParameter resParam = null;
  1931.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  1932.                     sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE);
  1933.                     sqlQueryObject.addInsertField("id_porta", "?");
  1934.                     sqlQueryObject.addInsertField("nome", "?");
  1935.                     sqlQueryObject.addInsertField("valore", "?");
  1936.                     sqlQueryObject.addInsertField("enc_value", "?");
  1937.                     sqlQuery = sqlQueryObject.createSQLInsert();
  1938.                     stm = con.prepareStatement(sqlQuery);
  1939.                    
  1940.                     i = 0;
  1941.                     if(messageSecurity.getResponseFlow()!=null){
  1942.                         MessageSecurityFlow flow = messageSecurity.getResponseFlow();
  1943.                         for (i = 0; i < flow.sizeParameterList(); i++) {
  1944.                             resParam = flow.getParameter(i);
  1945.                             int indexSec = 1;
  1946.                             stm.setLong(indexSec++, idPortaDelegata);
  1947.                             stm.setString(indexSec++, resParam.getNome());
  1948.                            
  1949.                             String plainValue = resParam.getValore();
  1950.                             String encValue = null;
  1951.                             if(driverBYOK!=null &&
  1952.                                     (
  1953.                                             DriverConfigurazioneDB_genericPropertiesDriver.isConfidentialProperty(securityResponseMode, resParam.getNome())
  1954.                                             ||
  1955.                                             BYOKUtilities.isWrappedValue(plainValue)
  1956.                                     )
  1957.                             ) {
  1958.                                 BYOKWrappedValue byokValue = driverBYOK.wrap(plainValue);
  1959.                                 if(byokValue!=null) {
  1960.                                     encValue = byokValue.getWrappedValue();
  1961.                                     plainValue = byokValue.getWrappedPlainValue();
  1962.                                 }
  1963.                             }
  1964.                             stm.setString(indexSec++, plainValue);
  1965.                             stm.setString(indexSec++, encValue);
  1966.                            
  1967.                             stm.executeUpdate();
  1968.                         }
  1969.                     }
  1970.                     stm.close();
  1971.                     DriverConfigurazioneDBLib.logDebug("Inserted " + i + " response flow con id=" + idPortaDelegata);
  1972.                 }


  1973.                 // la lista di correlazioni applicative contiene tutti e soli gli elementi necessari quindi resetto la lista nel db e riscrivo la lista nuova
  1974.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  1975.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_CORRELAZIONE);
  1976.                 sqlQueryObject.addWhereCondition("id_porta=?");
  1977.                 sqlQuery = sqlQueryObject.createSQLDelete();
  1978.                 stm = con.prepareStatement(sqlQuery);
  1979.                 stm.setLong(1, idPortaDelegata);
  1980.                 stm.executeUpdate();
  1981.                 stm.close();
  1982.                
  1983.                 if (corrApp != null) {
  1984.                     //inserisco i valori presenti nella lista
  1985.                     CorrelazioneApplicativaElemento cae = null;
  1986.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  1987.                     sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_CORRELAZIONE);
  1988.                     sqlQueryObject.addInsertField("id_porta", "?");
  1989.                     sqlQueryObject.addInsertField("nome_elemento", "?");
  1990.                     sqlQueryObject.addInsertField("mode_correlazione", "?");
  1991.                     sqlQueryObject.addInsertField("pattern", "?");
  1992.                     sqlQueryObject.addInsertField("identificazione_fallita", "?");
  1993.                     sqlQueryObject.addInsertField("riuso_id", "?");
  1994.                     sqlQuery = sqlQueryObject.createSQLInsert();
  1995.                     stm = con.prepareStatement(sqlQuery);

  1996.                     for (i = 0; i < corrApp.sizeElementoList(); i++) {
  1997.                         cae = corrApp.getElemento(i);
  1998.                         stm.setLong(1, idPortaDelegata);
  1999.                         stm.setString(2, cae.getNome());
  2000.                         stm.setString(3, DriverConfigurazioneDBLib.getValue(cae.getIdentificazione()));
  2001.                         if (cae.getPattern() != null)
  2002.                             stm.setString(4, cae.getPattern());
  2003.                         else
  2004.                             stm.setString(4, "");
  2005.                         stm.setString(5, DriverConfigurazioneDBLib.getValue(cae.getIdentificazioneFallita()));
  2006.                         stm.setString(6, DriverConfigurazioneDBLib.getValue(cae.getRiusoIdentificativo()));
  2007.                         stm.executeUpdate();
  2008.                     }
  2009.                     stm.close();
  2010.                     DriverConfigurazioneDBLib.logDebug("Inserted " + i + " correlazione applicativa con id=" + idPortaDelegata);
  2011.                 }

  2012.                 // la lista di correlazioni applicative risposta contiene tutti e soli gli elementi necessari quindi resetto la lista nel db e riscrivo la lista nuova
  2013.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2014.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_CORRELAZIONE_RISPOSTA);
  2015.                 sqlQueryObject.addWhereCondition("id_porta=?");
  2016.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2017.                 stm = con.prepareStatement(sqlQuery);
  2018.                 stm.setLong(1, idPortaDelegata);
  2019.                 stm.executeUpdate();
  2020.                 stm.close();
  2021.                
  2022.                 if (corrAppRisposta != null) {
  2023.                     //inserisco i valori presenti nella lista
  2024.                     CorrelazioneApplicativaRispostaElemento cae = null;
  2025.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2026.                     sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_CORRELAZIONE_RISPOSTA);
  2027.                     sqlQueryObject.addInsertField("id_porta", "?");
  2028.                     sqlQueryObject.addInsertField("nome_elemento", "?");
  2029.                     sqlQueryObject.addInsertField("mode_correlazione", "?");
  2030.                     sqlQueryObject.addInsertField("pattern", "?");
  2031.                     sqlQueryObject.addInsertField("identificazione_fallita", "?");
  2032.                     sqlQuery = sqlQueryObject.createSQLInsert();
  2033.                     stm = con.prepareStatement(sqlQuery);

  2034.                     for (i = 0; i < corrAppRisposta.sizeElementoList(); i++) {
  2035.                         cae = corrAppRisposta.getElemento(i);
  2036.                         stm.setLong(1, idPortaDelegata);
  2037.                         stm.setString(2, cae.getNome());
  2038.                         stm.setString(3, DriverConfigurazioneDBLib.getValue(cae.getIdentificazione()));
  2039.                         if (cae.getPattern() != null)
  2040.                             stm.setString(4, cae.getPattern());
  2041.                         else
  2042.                             stm.setString(4, "");
  2043.                         stm.setString(5, DriverConfigurazioneDBLib.getValue(cae.getIdentificazioneFallita()));
  2044.                         stm.executeUpdate();
  2045.                     }
  2046.                     stm.close();
  2047.                     DriverConfigurazioneDBLib.logDebug("Inserted " + i + " correlazione applicativa risposta con id=" + idPortaDelegata);
  2048.                 }
  2049.                
  2050.                 /*Sincronizzazione servizi applicativi*/
  2051.                 //la lista dei servizi applicativi passata contiene tutti e soli i servizi applicativi necessari
  2052.                 //quindi nel db devono essere presenti tutti e solo quelli presenti nella lista
  2053.                 //se la lista e' vuota allora i servizi applicativi vanno cancellati

  2054.                 //cancello i servizi applicativi associati alla porta e inserisco tutti e soli quelli presenti in lista
  2055.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2056.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_SA);
  2057.                 sqlQueryObject.addWhereCondition("id_porta=?");
  2058.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2059.                 stm = con.prepareStatement(sqlQuery);
  2060.                 stm.setLong(1, idPortaDelegata);
  2061.                 n=stm.executeUpdate();
  2062.                 stm.close();
  2063.                 DriverConfigurazioneDBLib.logDebug("Cancellati "+n+" servizi applicativi associati alla Porta Delegata "+idPortaDelegata);
  2064.                 //scrivo la lista nel db
  2065.                 n=0;
  2066.                 for (i = 0; i < aPD.sizeServizioApplicativoList(); i++) {
  2067.                     PortaDelegataServizioApplicativo servizioApplicativo = aPD.getServizioApplicativo(i);

  2068.                     String nomeSA = servizioApplicativo.getNome();
  2069.                     //il tipo e il nome proprietario servizio applicativo sono gli stessi della porta delegata
  2070.                     //controllo se sono settati gli old, perche potrei essere in un caso di update
  2071.                     String nomeProprietarioSA = aPD.getNomeSoggettoProprietario();
  2072.                     String tipoProprietarioSA = aPD.getTipoSoggettoProprietario();

  2073.                     if (nomeSA == null || nomeSA.equals(""))
  2074.                         throw new DriverConfigurazioneException("Nome del ServizioApplicativo associato non valido.");
  2075.                     if (nomeProprietarioSA == null || nomeProprietarioSA.equals(""))
  2076.                         throw new DriverConfigurazioneException("Nome Proprietario del ServizioApplicativo associato non valido.");
  2077.                     if (tipoProprietarioSA == null || tipoProprietarioSA.equals(""))
  2078.                         throw new DriverConfigurazioneException("Tipo Proprietario del ServizioApplicativo associato non valido.");

  2079.                     long idSA = DriverConfigurazioneDB_serviziApplicativiLIB.getIdServizioApplicativo(nomeSA, tipoProprietarioSA, nomeProprietarioSA, con, DriverConfigurazioneDBLib.tipoDB,DriverConfigurazioneDBLib.tabellaSoggetti);

  2080.                     if (idSA <= 0)
  2081.                         throw new DriverConfigurazioneException("Impossibile recuperare l'id del Servizio Applicativo [" + nomeSA + "] di [" + tipoProprietarioSA + "/" + nomeProprietarioSA + "]");

  2082.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2083.                     sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_SA);
  2084.                     sqlQueryObject.addInsertField("id_porta", "?");
  2085.                     sqlQueryObject.addInsertField("id_servizio_applicativo", "?");
  2086.                     sqlQuery = sqlQueryObject.createSQLInsert();
  2087.                     stm = con.prepareStatement(sqlQuery);
  2088.                     stm.setLong(1, idPortaDelegata);
  2089.                     stm.setLong(2, idSA);

  2090.                     stm.executeUpdate();
  2091.                     stm.close();
  2092.                     n++;
  2093.                     DriverConfigurazioneDBLib.logDebug("Aggiunta associazione PortaDelegata<->ServizioApplicativo [" + idPortaDelegata + "]<->[" + idSA + "]");
  2094.                 }

  2095.                 DriverConfigurazioneDBLib.logDebug("Aggiunti " + n + " associazioni PortaDelegata<->ServizioApplicativo associati alla PortaDelegata[" + idPortaDelegata + "]");

  2096.                
  2097.                
  2098.                 /*Proprieta Autenticazione associate alla Porta Delegata*/

  2099.                 //La lista di proprieta contiene tutte e sole le proprieta associate alla porta
  2100.                 //cancello le proprieta per poi sincronizzarle con la lista passata
  2101.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2102.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_AUTENTICAZIONE_PROP);
  2103.                 sqlQueryObject.addWhereCondition("id_porta=?");
  2104.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2105.                 stm = con.prepareStatement(sqlQuery);
  2106.                 stm.setLong(1, idPortaDelegata);
  2107.                 n=stm.executeUpdate();
  2108.                 stm.close();
  2109.                 DriverConfigurazioneDBLib.logDebug("Eliminate "+n+" proprieta di autenticazione associate alla Porta Delegata "+idPortaDelegata);
  2110.                 // set prop
  2111.                 int newProps = 0;
  2112.                 for (i = 0; i < aPD.sizeProprietaAutenticazioneList(); i++) {
  2113.                     Proprieta propProtocollo = aPD.getProprietaAutenticazione(i);

  2114.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2115.                     sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_AUTENTICAZIONE_PROP);
  2116.                     sqlQueryObject.addInsertField("id_porta", "?");
  2117.                     sqlQueryObject.addInsertField("nome", "?");
  2118.                     sqlQueryObject.addInsertField("valore", "?");
  2119.                     sqlQueryObject.addInsertField("enc_value", "?");
  2120.                     sqlQuery = sqlQueryObject.createSQLInsert();
  2121.                     stm = con.prepareStatement(sqlQuery);

  2122.                     int indexP = 1;
  2123.                     stm.setLong(indexP++, idPortaDelegata);
  2124.                     stm.setString(indexP++, propProtocollo.getNome());
  2125.                    
  2126.                     String plainValueP = propProtocollo.getValore();
  2127.                     String encValueP = null;
  2128.                     if(driverBYOK!=null && BYOKUtilities.isWrappedValue(plainValueP) ) {
  2129.                         BYOKWrappedValue byokValue = driverBYOK.wrap(plainValueP);
  2130.                         if(byokValue!=null) {
  2131.                             encValueP = byokValue.getWrappedValue();
  2132.                             plainValueP = byokValue.getWrappedPlainValue();
  2133.                         }
  2134.                     }
  2135.                    
  2136.                     stm.setString(indexP++, plainValueP);
  2137.                     stm.setString(indexP++, encValueP);
  2138.                    
  2139.                     stm.executeUpdate();
  2140.                     stm.close();
  2141.                     newProps++;
  2142.                 }
  2143.                 DriverConfigurazioneDBLib.logDebug("Inserted " + newProps + " SetProtocolProp Autenticazione associati alla PortaDelegata[" + idPortaDelegata + "]");
  2144.                
  2145.                
  2146.                
  2147.                 /*Proprieta Autorizzazione associate alla Porta Delegata*/

  2148.                 //La lista di proprieta contiene tutte e sole le proprieta associate alla porta
  2149.                 //cancello le proprieta per poi sincronizzarle con la lista passata
  2150.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2151.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_AUTORIZZAZIONE_PROP);
  2152.                 sqlQueryObject.addWhereCondition("id_porta=?");
  2153.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2154.                 stm = con.prepareStatement(sqlQuery);
  2155.                 stm.setLong(1, idPortaDelegata);
  2156.                 n=stm.executeUpdate();
  2157.                 stm.close();
  2158.                 DriverConfigurazioneDBLib.logDebug("Eliminate "+n+" proprieta di autorizzazione associate alla Porta Delegata "+idPortaDelegata);
  2159.                 // set prop
  2160.                 newProps = 0;
  2161.                 for (i = 0; i < aPD.sizeProprietaAutorizzazioneList(); i++) {
  2162.                     Proprieta propProtocollo = aPD.getProprietaAutorizzazione(i);

  2163.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2164.                     sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_AUTORIZZAZIONE_PROP);
  2165.                     sqlQueryObject.addInsertField("id_porta", "?");
  2166.                     sqlQueryObject.addInsertField("nome", "?");
  2167.                     sqlQueryObject.addInsertField("valore", "?");
  2168.                     sqlQueryObject.addInsertField("enc_value", "?");
  2169.                     sqlQuery = sqlQueryObject.createSQLInsert();
  2170.                     stm = con.prepareStatement(sqlQuery);

  2171.                     int indexP = 1;
  2172.                     stm.setLong(indexP++, idPortaDelegata);
  2173.                     stm.setString(indexP++, propProtocollo.getNome());
  2174.                    
  2175.                     String plainValueP = propProtocollo.getValore();
  2176.                     String encValueP = null;
  2177.                     if(driverBYOK!=null && BYOKUtilities.isWrappedValue(plainValueP) ) {
  2178.                         BYOKWrappedValue byokValue = driverBYOK.wrap(plainValueP);
  2179.                         if(byokValue!=null) {
  2180.                             encValueP = byokValue.getWrappedValue();
  2181.                             plainValueP = byokValue.getWrappedPlainValue();
  2182.                         }
  2183.                     }
  2184.                    
  2185.                     stm.setString(indexP++, plainValueP);
  2186.                     stm.setString(indexP++, encValueP);
  2187.                    
  2188.                     stm.executeUpdate();
  2189.                     stm.close();
  2190.                     newProps++;
  2191.                 }
  2192.                 DriverConfigurazioneDBLib.logDebug("Inserted " + newProps + " SetProtocolProp Autorizzazione associati alla PortaDelegata[" + idPortaDelegata + "]");
  2193.                
  2194.                
  2195.                
  2196.                
  2197.                 /*Proprieta Autorizzazione Contenuti associate alla Porta Delegata*/

  2198.                 //La lista di proprieta contiene tutte e sole le proprieta associate alla porta
  2199.                 //cancello le proprieta per poi sincronizzarle con la lista passata
  2200.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2201.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_AUTORIZZAZIONE_CONTENUTI_PROP);
  2202.                 sqlQueryObject.addWhereCondition("id_porta=?");
  2203.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2204.                 stm = con.prepareStatement(sqlQuery);
  2205.                 stm.setLong(1, idPortaDelegata);
  2206.                 n=stm.executeUpdate();
  2207.                 stm.close();
  2208.                 DriverConfigurazioneDBLib.logDebug("Eliminate "+n+" proprieta di autorizzazione contenuti associate alla Porta Delegata "+idPortaDelegata);
  2209.                 // set prop
  2210.                 newProps = 0;
  2211.                 for (i = 0; i < aPD.sizeProprietaAutorizzazioneContenutoList(); i++) {
  2212.                     Proprieta propProtocollo = aPD.getProprietaAutorizzazioneContenuto(i);

  2213.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2214.                     sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_AUTORIZZAZIONE_CONTENUTI_PROP);
  2215.                     sqlQueryObject.addInsertField("id_porta", "?");
  2216.                     sqlQueryObject.addInsertField("nome", "?");
  2217.                     sqlQueryObject.addInsertField("valore", "?");
  2218.                     sqlQueryObject.addInsertField("enc_value", "?");
  2219.                     sqlQuery = sqlQueryObject.createSQLInsert();
  2220.                     stm = con.prepareStatement(sqlQuery);

  2221.                     int indexP = 1;
  2222.                     stm.setLong(indexP++, idPortaDelegata);
  2223.                     stm.setString(indexP++, propProtocollo.getNome());
  2224.                    
  2225.                     String plainValueP = propProtocollo.getValore();
  2226.                     String encValueP = null;
  2227.                     if(driverBYOK!=null && BYOKUtilities.isWrappedValue(plainValueP) ) {
  2228.                         BYOKWrappedValue byokValue = driverBYOK.wrap(plainValueP);
  2229.                         if(byokValue!=null) {
  2230.                             encValueP = byokValue.getWrappedValue();
  2231.                             plainValueP = byokValue.getWrappedPlainValue();
  2232.                         }
  2233.                     }
  2234.                    
  2235.                     stm.setString(indexP++, plainValueP);
  2236.                     stm.setString(indexP++, encValueP);
  2237.                    
  2238.                     stm.executeUpdate();
  2239.                     stm.close();
  2240.                     newProps++;
  2241.                 }
  2242.                 DriverConfigurazioneDBLib.logDebug("Inserted " + newProps + " SetProtocolProp AutorizzazioneContenuto associati alla PortaDelegata[" + idPortaDelegata + "]");
  2243.                
  2244.                
  2245.                
  2246.                
  2247.                
  2248.                 /*Proprieta Rate Limiting associate alla Porta Delegata*/

  2249.                 //La lista di proprieta contiene tutte e sole le proprieta associate alla porta
  2250.                 //cancello le proprieta per poi sincronizzarle con la lista passata
  2251.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2252.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_RATE_LIMITING_PROP);
  2253.                 sqlQueryObject.addWhereCondition("id_porta=?");
  2254.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2255.                 stm = con.prepareStatement(sqlQuery);
  2256.                 stm.setLong(1, idPortaDelegata);
  2257.                 n=stm.executeUpdate();
  2258.                 stm.close();
  2259.                 DriverConfigurazioneDBLib.logDebug("Eliminate "+n+" proprieta di rate limiting associate alla Porta Delegata "+idPortaDelegata);
  2260.                 // set prop
  2261.                 newProps = 0;
  2262.                 for (i = 0; i < aPD.sizeProprietaRateLimitingList(); i++) {
  2263.                     Proprieta propProtocollo = aPD.getProprietaRateLimiting(i);

  2264.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2265.                     sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_RATE_LIMITING_PROP);
  2266.                     sqlQueryObject.addInsertField("id_porta", "?");
  2267.                     sqlQueryObject.addInsertField("nome", "?");
  2268.                     sqlQueryObject.addInsertField("valore", "?");
  2269.                     sqlQuery = sqlQueryObject.createSQLInsert();
  2270.                     stm = con.prepareStatement(sqlQuery);

  2271.                     stm.setLong(1, idPortaDelegata);
  2272.                     stm.setString(2, propProtocollo.getNome());
  2273.                     stm.setString(3, propProtocollo.getValore());
  2274.                     stm.executeUpdate();
  2275.                     stm.close();
  2276.                     newProps++;
  2277.                 }
  2278.                 DriverConfigurazioneDBLib.logDebug("Inserted " + newProps + " SetProtocolPropRateLimiting associati alla PortaDelegata[" + idPortaDelegata + "]");
  2279.                
  2280.                
  2281.                
  2282.                
  2283.                
  2284.                
  2285.                 /*Proprieta associate alla Porta Delegata*/

  2286.                 //La lista di proprieta contiene tutte e sole le proprieta associate alla porta
  2287.                 //cancello le proprieta per poi sincronizzarle con la lista passata
  2288.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2289.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_PROP);
  2290.                 sqlQueryObject.addWhereCondition("id_porta=?");
  2291.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2292.                 stm = con.prepareStatement(sqlQuery);
  2293.                 stm.setLong(1, idPortaDelegata);
  2294.                 n=stm.executeUpdate();
  2295.                 stm.close();
  2296.                 DriverConfigurazioneDBLib.logDebug("Eliminate "+n+" proprieta associate alla Porta Delegata "+idPortaDelegata);
  2297.                 // set prop
  2298.                 newProps = 0;
  2299.                 for (i = 0; i < aPD.sizeProprietaList(); i++) {
  2300.                     Proprieta propProtocollo = aPD.getProprieta(i);

  2301.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2302.                     sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_PROP);
  2303.                     sqlQueryObject.addInsertField("id_porta", "?");
  2304.                     sqlQueryObject.addInsertField("nome", "?");
  2305.                     sqlQueryObject.addInsertField("valore", "?");
  2306.                     sqlQueryObject.addInsertField("enc_value", "?");
  2307.                     sqlQuery = sqlQueryObject.createSQLInsert();
  2308.                     stm = con.prepareStatement(sqlQuery);

  2309.                     int indexP = 1;
  2310.                     stm.setLong(indexP++, idPortaDelegata);
  2311.                     stm.setString(indexP++, propProtocollo.getNome());
  2312.                    
  2313.                     String plainValueP = propProtocollo.getValore();
  2314.                     String encValueP = null;
  2315.                     if(driverBYOK!=null && BYOKUtilities.isWrappedValue(plainValueP) ) {
  2316.                         BYOKWrappedValue byokValue = driverBYOK.wrap(plainValueP);
  2317.                         if(byokValue!=null) {
  2318.                             encValueP = byokValue.getWrappedValue();
  2319.                             plainValueP = byokValue.getWrappedPlainValue();
  2320.                         }
  2321.                     }
  2322.                    
  2323.                     stm.setString(indexP++, plainValueP);
  2324.                     stm.setString(indexP++, encValueP);
  2325.                    
  2326.                     stm.executeUpdate();
  2327.                     stm.close();
  2328.                     newProps++;
  2329.                 }
  2330.                 DriverConfigurazioneDBLib.logDebug("Inserted " + newProps + " SetProtocolProp associati alla PortaDelegata[" + idPortaDelegata + "]");
  2331.                
  2332.                
  2333.                 // Ruoli
  2334.                
  2335.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2336.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_RUOLI);
  2337.                 sqlQueryObject.addWhereCondition("id_porta=?");
  2338.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2339.                 stm = con.prepareStatement(sqlQuery);
  2340.                 stm.setLong(1, idPortaDelegata);
  2341.                 n=stm.executeUpdate();
  2342.                 stm.close();
  2343.                 DriverConfigurazioneDBLib.logDebug("Cancellati "+n+" ruoli associati alla Porta Delegata "+idPortaDelegata);
  2344.                
  2345.                 n=0;
  2346.                 if(aPD.getRuoli()!=null && aPD.getRuoli().sizeRuoloList()>0){
  2347.                     for (int j = 0; j < aPD.getRuoli().sizeRuoloList(); j++) {
  2348.                         Ruolo ruolo = aPD.getRuoli().getRuolo(j);
  2349.                         sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2350.                         sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_RUOLI);
  2351.                         sqlQueryObject.addInsertField("id_porta", "?");
  2352.                         sqlQueryObject.addInsertField("ruolo", "?");
  2353.                         sqlQuery = sqlQueryObject.createSQLInsert();
  2354.                         stm = con.prepareStatement(sqlQuery);
  2355.                         stm.setLong(1, idPortaDelegata);
  2356.                         stm.setString(2, ruolo.getNome());
  2357.                         stm.executeUpdate();
  2358.                         stm.close();
  2359.                         n++;
  2360.                         DriverConfigurazioneDBLib.logDebug("Aggiunto ruolo[" + ruolo.getNome() + "] alla PortaDelegata[" + idPortaDelegata + "]");
  2361.                     }
  2362.                 }
  2363.                
  2364.                 DriverConfigurazioneDBLib.logDebug("Aggiunti " + n + " ruoli alla PortaDelegata[" + idPortaDelegata + "]");
  2365.                
  2366.                
  2367.                
  2368.                 // Scope
  2369.                
  2370.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2371.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_SCOPE);
  2372.                 sqlQueryObject.addWhereCondition("id_porta=?");
  2373.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2374.                 stm = con.prepareStatement(sqlQuery);
  2375.                 stm.setLong(1, idPortaDelegata);
  2376.                 n=stm.executeUpdate();
  2377.                 stm.close();
  2378.                 DriverConfigurazioneDBLib.logDebug("Cancellati "+n+" scope associati alla Porta Delegata "+idPortaDelegata);
  2379.                
  2380.                 n=0;
  2381.                 if(aPD.getScope()!=null && aPD.getScope().sizeScopeList()>0){
  2382.                     for (int j = 0; j < aPD.getScope().sizeScopeList(); j++) {
  2383.                         Scope scope = aPD.getScope().getScope(j);
  2384.                         sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2385.                         sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_SCOPE);
  2386.                         sqlQueryObject.addInsertField("id_porta", "?");
  2387.                         sqlQueryObject.addInsertField("scope", "?");
  2388.                         sqlQuery = sqlQueryObject.createSQLInsert();
  2389.                         stm = con.prepareStatement(sqlQuery);
  2390.                         stm.setLong(1, idPortaDelegata);
  2391.                         stm.setString(2, scope.getNome());
  2392.                         stm.executeUpdate();
  2393.                         stm.close();
  2394.                         n++;
  2395.                         DriverConfigurazioneDBLib.logDebug("Aggiunto scope[" + scope.getNome() + "] alla PortaDelegata[" + idPortaDelegata + "]");
  2396.                     }
  2397.                 }
  2398.                
  2399.                 DriverConfigurazioneDBLib.logDebug("Aggiunti " + n + " scope alla PortaDelegata[" + idPortaDelegata + "]");
  2400.                
  2401.                
  2402.                
  2403.                
  2404.                 /*Sincronizzazione servizi applicativi token */
  2405.                 //la lista dei servizi applicativi passata contiene tutti e soli i servizi applicativi necessari
  2406.                 //quindi nel db devono essere presenti tutti e solo quelli presenti nella lista
  2407.                 //se la lista e' vuota allora i servizi applicativi vanno cancellati

  2408.                 //cancello i servizi applicativi associati alla porta e inserisco tutti e soli quelli presenti in lista
  2409.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2410.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_TOKEN_SA);
  2411.                 sqlQueryObject.addWhereCondition("id_porta=?");
  2412.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2413.                 stm = con.prepareStatement(sqlQuery);
  2414.                 stm.setLong(1, idPortaDelegata);
  2415.                 n=stm.executeUpdate();
  2416.                 stm.close();
  2417.                 DriverConfigurazioneDBLib.logDebug("Cancellati "+n+" servizi applicativi (token) associati alla Porta Delegata "+idPortaDelegata);
  2418.            
  2419.                 // serviziapplicativi (token)
  2420.                 if(aPD.getAutorizzazioneToken()!=null && aPD.getAutorizzazioneToken().getServiziApplicativi()!=null &&
  2421.                         aPD.getAutorizzazioneToken().getServiziApplicativi().sizeServizioApplicativoList()>0) {
  2422.                     //scrivo la lista nel db
  2423.                     n=0;
  2424.                     for (i = 0; i < aPD.getAutorizzazioneToken().getServiziApplicativi().sizeServizioApplicativoList(); i++) {
  2425.                         PortaDelegataServizioApplicativo servizioApplicativo = aPD.getAutorizzazioneToken().getServiziApplicativi().getServizioApplicativo(i);
  2426.    
  2427.                         String nomeSA = servizioApplicativo.getNome();
  2428.                         //il tipo e il nome proprietario servizio applicativo sono gli stessi della porta delegata
  2429.                         //controllo se sono settati gli old, perche potrei essere in un caso di update
  2430.                         String nomeProprietarioSA = aPD.getNomeSoggettoProprietario();
  2431.                         String tipoProprietarioSA = aPD.getTipoSoggettoProprietario();
  2432.    
  2433.                         if (nomeSA == null || nomeSA.equals(""))
  2434.                             throw new DriverConfigurazioneException("Nome del ServizioApplicativo associato non valido.");
  2435.                         if (nomeProprietarioSA == null || nomeProprietarioSA.equals(""))
  2436.                             throw new DriverConfigurazioneException("Nome Proprietario del ServizioApplicativo associato non valido.");
  2437.                         if (tipoProprietarioSA == null || tipoProprietarioSA.equals(""))
  2438.                             throw new DriverConfigurazioneException("Tipo Proprietario del ServizioApplicativo associato non valido.");
  2439.    
  2440.                         long idSA = DriverConfigurazioneDB_serviziApplicativiLIB.getIdServizioApplicativo(nomeSA, tipoProprietarioSA, nomeProprietarioSA, con, DriverConfigurazioneDBLib.tipoDB,DriverConfigurazioneDBLib.tabellaSoggetti);
  2441.    
  2442.                         if (idSA <= 0)
  2443.                             throw new DriverConfigurazioneException("Impossibile recuperare l'id del Servizio Applicativo [" + nomeSA + "] di [" + tipoProprietarioSA + "/" + nomeProprietarioSA + "]");
  2444.    
  2445.                         sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2446.                         sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_TOKEN_SA);
  2447.                         sqlQueryObject.addInsertField("id_porta", "?");
  2448.                         sqlQueryObject.addInsertField("id_servizio_applicativo", "?");
  2449.                         sqlQuery = sqlQueryObject.createSQLInsert();
  2450.                         stm = con.prepareStatement(sqlQuery);
  2451.                         stm.setLong(1, idPortaDelegata);
  2452.                         stm.setLong(2, idSA);
  2453.    
  2454.                         stm.executeUpdate();
  2455.                         stm.close();
  2456.                         n++;
  2457.                         DriverConfigurazioneDBLib.logDebug("Aggiunta associazione PortaDelegata<->ServizioApplicativo (token) [" + idPortaDelegata + "]<->[" + idSA + "]");
  2458.                     }
  2459.    
  2460.                     DriverConfigurazioneDBLib.logDebug("Aggiunti " + n + " associazioni PortaDelegata<->ServizioApplicativo (token) associati alla PortaDelegata[" + idPortaDelegata + "]");
  2461.                 }
  2462.                
  2463.                
  2464.                
  2465.                 // Ruoli (token)
  2466.                
  2467.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2468.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_TOKEN_RUOLI);
  2469.                 sqlQueryObject.addWhereCondition("id_porta=?");
  2470.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2471.                 stm = con.prepareStatement(sqlQuery);
  2472.                 stm.setLong(1, idPortaDelegata);
  2473.                 n=stm.executeUpdate();
  2474.                 stm.close();
  2475.                 DriverConfigurazioneDBLib.logDebug("Cancellati "+n+" ruoli (token) associati alla Porta Delegata "+idPortaDelegata);
  2476.                
  2477.                 n=0;
  2478.                 if(aPD.getAutorizzazioneToken()!=null && aPD.getAutorizzazioneToken().getRuoli()!=null &&
  2479.                         aPD.getAutorizzazioneToken().getRuoli().sizeRuoloList()>0){
  2480.                     for (int j = 0; j < aPD.getAutorizzazioneToken().getRuoli().sizeRuoloList(); j++) {
  2481.                         Ruolo ruolo = aPD.getAutorizzazioneToken().getRuoli().getRuolo(j);
  2482.                         sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2483.                         sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_TOKEN_RUOLI);
  2484.                         sqlQueryObject.addInsertField("id_porta", "?");
  2485.                         sqlQueryObject.addInsertField("ruolo", "?");
  2486.                         sqlQuery = sqlQueryObject.createSQLInsert();
  2487.                         stm = con.prepareStatement(sqlQuery);
  2488.                         stm.setLong(1, idPortaDelegata);
  2489.                         stm.setString(2, ruolo.getNome());
  2490.                         stm.executeUpdate();
  2491.                         stm.close();
  2492.                         n++;
  2493.                         DriverConfigurazioneDBLib.logDebug("Aggiunto ruolo[" + ruolo.getNome() + "] (token) alla PortaDelegata[" + idPortaDelegata + "]");
  2494.                     }
  2495.                 }
  2496.                
  2497.                 DriverConfigurazioneDBLib.logDebug("Aggiunti " + n + " ruoli (token) alla PortaDelegata[" + idPortaDelegata + "]");
  2498.                
  2499.                
  2500.                 // Azioni
  2501.                
  2502.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2503.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_AZIONI);
  2504.                 sqlQueryObject.addWhereCondition("id_porta=?");
  2505.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2506.                 stm = con.prepareStatement(sqlQuery);
  2507.                 stm.setLong(1, idPortaDelegata);
  2508.                 n=stm.executeUpdate();
  2509.                 stm.close();
  2510.                 DriverConfigurazioneDBLib.logDebug("Cancellati "+n+" azioni delegate associate alla Porta Delegata "+idPortaDelegata);
  2511.                
  2512.                 n=0;
  2513.                 if(aPD.getAzione()!=null && aPD.getAzione().sizeAzioneDelegataList()>0){
  2514.                     for (int j = 0; j < aPD.getAzione().sizeAzioneDelegataList(); j++) {
  2515.                         String azioneDelegata = aPD.getAzione().getAzioneDelegata(j);
  2516.                         sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2517.                         sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_AZIONI);
  2518.                         sqlQueryObject.addInsertField("id_porta", "?");
  2519.                         sqlQueryObject.addInsertField("azione", "?");
  2520.                         sqlQuery = sqlQueryObject.createSQLInsert();
  2521.                         stm = con.prepareStatement(sqlQuery);
  2522.                         stm.setLong(1, idPortaDelegata);
  2523.                         stm.setString(2, azioneDelegata);
  2524.                         stm.executeUpdate();
  2525.                         stm.close();
  2526.                         n++;
  2527.                         DriverConfigurazioneDBLib.logDebug("Aggiunta azione delegata [" + azioneDelegata + "] alla PortaDelegata[" + idPortaDelegata + "]");
  2528.                     }
  2529.                 }
  2530.                
  2531.                 DriverConfigurazioneDBLib.logDebug("Aggiunte " + n + " azioni delegate alla PortaDelegata[" + idPortaDelegata + "]");
  2532.                
  2533.                
  2534.                
  2535.                
  2536.                 // Cache Regole
  2537.                
  2538.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2539.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_CACHE_REGOLE);
  2540.                 sqlQueryObject.addWhereCondition("id_porta=?");
  2541.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2542.                 stm = con.prepareStatement(sqlQuery);
  2543.                 stm.setLong(1, idPortaDelegata);
  2544.                 n=stm.executeUpdate();
  2545.                 stm.close();
  2546.                 DriverConfigurazioneDBLib.logDebug("Cancellati "+n+" regole di cache associate alla Porta Delegata "+idPortaDelegata);
  2547.                
  2548.                 n=0;
  2549.                 if(responseCacheRegole!=null && responseCacheRegole.size()>0){
  2550.                     for (int j = 0; j < responseCacheRegole.size(); j++) {
  2551.                         ResponseCachingConfigurazioneRegola regola = responseCacheRegole.get(j);
  2552.                         sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2553.                         sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_CACHE_REGOLE);
  2554.                         sqlQueryObject.addInsertField("id_porta", "?");
  2555.                         if(regola.getReturnCodeMin()!=null && regola.getReturnCodeMin()>0) {
  2556.                             sqlQueryObject.addInsertField("status_min", "?");
  2557.                         }
  2558.                         if(regola.getReturnCodeMax()!=null && regola.getReturnCodeMax()>0) {
  2559.                             sqlQueryObject.addInsertField("status_max", "?");
  2560.                         }
  2561.                         sqlQueryObject.addInsertField("fault", "?");
  2562.                         if(regola.getCacheTimeoutSeconds()!=null && regola.getCacheTimeoutSeconds()>0) {
  2563.                             sqlQueryObject.addInsertField("cache_seconds", "?");
  2564.                         }
  2565.                         sqlQuery = sqlQueryObject.createSQLInsert();
  2566.                         stm = con.prepareStatement(sqlQuery);
  2567.                         int indexCR = 1;
  2568.                         stm.setLong(indexCR++, idPortaDelegata);
  2569.                         if(regola.getReturnCodeMin()!=null && regola.getReturnCodeMin()>0) {
  2570.                             stm.setInt(indexCR++, regola.getReturnCodeMin());
  2571.                         }
  2572.                         if(regola.getReturnCodeMax()!=null && regola.getReturnCodeMax()>0) {
  2573.                             stm.setInt(indexCR++, regola.getReturnCodeMax());
  2574.                         }
  2575.                         stm.setInt(indexCR++, regola.getFault() ? CostantiDB.TRUE : CostantiDB.FALSE);
  2576.                         if(regola.getCacheTimeoutSeconds()!=null && regola.getCacheTimeoutSeconds()>0) {
  2577.                             stm.setInt(indexCR++, regola.getCacheTimeoutSeconds());
  2578.                         }
  2579.                         stm.executeUpdate();
  2580.                         stm.close();
  2581.                         n++;
  2582.                         DriverConfigurazioneDBLib.logDebug("Aggiunta regola di cache alla PortaDelegata[" + idPortaDelegata + "]");
  2583.                     }
  2584.                 }
  2585.                
  2586.                 DriverConfigurazioneDBLib.logDebug("Aggiunte " + n + " regole di cache alla PortaDelegata[" + idPortaDelegata + "]");
  2587.                
  2588.                
  2589.                
  2590.                 // AttributeAuthority
  2591.                
  2592.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2593.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_ATTRIBUTE_AUTHORITY);
  2594.                 sqlQueryObject.addWhereCondition("id_porta=?");
  2595.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2596.                 stm = con.prepareStatement(sqlQuery);
  2597.                 stm.setLong(1, idPortaDelegata);
  2598.                 n=stm.executeUpdate();
  2599.                 stm.close();
  2600.                 DriverConfigurazioneDBLib.logDebug("Cancellate "+n+" A.A. associate alla Porta Delegata "+idPortaDelegata);
  2601.                
  2602.                 n=0;
  2603.                 if(aPD.sizeAttributeAuthorityList()>0){
  2604.                     for (int j = 0; j < aPD.sizeAttributeAuthorityList(); j++) {
  2605.                         AttributeAuthority aa = aPD.getAttributeAuthority(j);
  2606.                        
  2607.                         String attributi = null;
  2608.                         if(aa.sizeAttributoList()>0) {
  2609.                             StringBuilder bf = new StringBuilder();
  2610.                             for (int aaI = 0; aaI < aa.sizeAttributoList(); aaI++) {
  2611.                                 if(aaI>0) {
  2612.                                     bf.append(",");
  2613.                                 }
  2614.                                 bf.append(aa.getAttributo(aaI));
  2615.                             }
  2616.                             attributi = bf.toString();
  2617.                         }
  2618.                        
  2619.                         sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2620.                         sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_ATTRIBUTE_AUTHORITY);
  2621.                         sqlQueryObject.addInsertField("id_porta", "?");
  2622.                         sqlQueryObject.addInsertField("nome", "?");
  2623.                         sqlQueryObject.addInsertField("attributi", "?");
  2624.                         sqlQuery = sqlQueryObject.createSQLInsert();
  2625.                         stm = con.prepareStatement(sqlQuery);
  2626.                         stm.setLong(1, idPortaDelegata);
  2627.                         stm.setString(2, aa.getNome());
  2628.                         stm.setString(3, attributi);
  2629.                         stm.executeUpdate();
  2630.                         stm.close();
  2631.                         n++;
  2632.                         DriverConfigurazioneDBLib.logDebug("Aggiunta A.A.[" + aa.getNome() + "] alla PortaDelegata[" + idPortaDelegata + "]");
  2633.                     }
  2634.                 }
  2635.                
  2636.                 DriverConfigurazioneDBLib.logDebug("Aggiunte " + n + " A.A. alla PortaDelegata[" + idPortaDelegata + "]");
  2637.                
  2638.                
  2639.                
  2640.                 // tracciamentoConfigurazione
  2641.                 DriverConfigurazioneDBTracciamentoLIB.crudTracciamentoConfigurazione(type, con, tracciamentoDatabase, idPortaDelegata,
  2642.                         CostantiDB.TRACCIAMENTO_CONFIGURAZIONE_PROPRIETARIO_PD,
  2643.                         CostantiDB.TRACCIAMENTO_CONFIGURAZIONE_TIPO_DB);
  2644.                
  2645.                 DriverConfigurazioneDBTracciamentoLIB.crudTracciamentoConfigurazione(type, con, tracciamentoFiletrace, idPortaDelegata,
  2646.                         CostantiDB.TRACCIAMENTO_CONFIGURAZIONE_PROPRIETARIO_PD,
  2647.                         CostantiDB.TRACCIAMENTO_CONFIGURAZIONE_TIPO_FILETRACE);
  2648.                
  2649.                 DriverConfigurazioneDBTracciamentoLIB.crudTracciamentoConfigurazioneFiletrace(type, con, tracciamentoFiletraceDetails, idPortaDelegata,
  2650.                         CostantiDB.TRACCIAMENTO_CONFIGURAZIONE_PROPRIETARIO_PD);
  2651.                
  2652.                
  2653.                 // dumpConfigurazione
  2654.                 DriverConfigurazioneDB_dumpLIB.CRUDDumpConfigurazione(type, con, aPD.getDump(), idPortaDelegata, CostantiDB.DUMP_CONFIGURAZIONE_PROPRIETARIO_PD);
  2655.                
  2656.                
  2657.                 // trasformazioni
  2658.                 DriverConfigurazioneDBTrasformazioniLib.CRUDTrasformazioni(type, con, aPD.getTrasformazioni(), idPortaDelegata, true);
  2659.                
  2660.                
  2661.                 // Handlers
  2662.                 DriverConfigurazioneDB_handlerLIB.CRUDConfigurazioneMessageHandlers(type, con, idPortaDelegata, null, true, (configHandlers!=null) ? configHandlers.getRequest() : null);
  2663.                 DriverConfigurazioneDB_handlerLIB.CRUDConfigurazioneMessageHandlers(type, con, idPortaDelegata, null, false, (configHandlers!=null) ? configHandlers.getResponse() : null);
  2664.                
  2665.                
  2666.                 // extendedInfo
  2667.                 if(extInfoConfigurazioneDriver!=null){
  2668.                     extInfoConfigurazioneDriver.deleteAllExtendedInfo(con, DriverConfigurazioneDBLib.log, aPD, CRUDType.UPDATE);
  2669.                 }
  2670.                
  2671.                 i=0;
  2672.                 if(aPD.sizeExtendedInfoList()>0 &&
  2673.                     (extInfoConfigurazioneDriver!=null)
  2674.                     ){
  2675.                     for (i = 0; i < aPD.sizeExtendedInfoList(); i++) {
  2676.                         extInfoConfigurazioneDriver.createExtendedInfo(con, DriverConfigurazioneDBLib.log, aPD, aPD.getExtendedInfo(i), CRUDType.UPDATE);
  2677.                     }
  2678.                 }
  2679.                 DriverConfigurazioneDBLib.logDebug("Aggiunte " + i + " associazioni ExtendedInfo<->PortaDelegata associati alla PortaDelegata[" + idPortaDelegata + "]");
  2680.                
  2681.                
  2682.                 break;

  2683.             case DELETE:
  2684.                 // delete
  2685.                 idPortaDelegata = DBUtils.getIdPortaDelegata(nomePorta, con, DriverConfigurazioneDBLib.tipoDB);
  2686.                 if (idPortaDelegata <= 0)
  2687.                     throw new DriverConfigurazioneException("[DriverConfigurazioneDB_LIB::CRUDPortaDelegata(DELETE)] Non e' stato possibile recuperare l'id della Porta Delegata, necessario per effettuare la DELETE.");

  2688.                 // tracciamentoConfigurazione
  2689.                 DriverConfigurazioneDBTracciamentoLIB.crudTracciamentoConfigurazione(type, con, tracciamentoDatabase, idPortaDelegata,
  2690.                         CostantiDB.TRACCIAMENTO_CONFIGURAZIONE_PROPRIETARIO_PD,
  2691.                         CostantiDB.TRACCIAMENTO_CONFIGURAZIONE_TIPO_DB);
  2692.                
  2693.                 DriverConfigurazioneDBTracciamentoLIB.crudTracciamentoConfigurazione(type, con, tracciamentoFiletrace, idPortaDelegata,
  2694.                         CostantiDB.TRACCIAMENTO_CONFIGURAZIONE_PROPRIETARIO_PD,
  2695.                         CostantiDB.TRACCIAMENTO_CONFIGURAZIONE_TIPO_FILETRACE);
  2696.                
  2697.                 DriverConfigurazioneDBTracciamentoLIB.crudTracciamentoConfigurazioneFiletrace(type, con, tracciamentoFiletraceDetails, idPortaDelegata,
  2698.                         CostantiDB.TRACCIAMENTO_CONFIGURAZIONE_PROPRIETARIO_PD);
  2699.                
  2700.                 // dumpConfigurazione
  2701.                 DriverConfigurazioneDB_dumpLIB.CRUDDumpConfigurazione(type, con, aPD.getDump(), idPortaDelegata, CostantiDB.DUMP_CONFIGURAZIONE_PROPRIETARIO_PD);
  2702.                
  2703.                 // trasformazioni
  2704.                 DriverConfigurazioneDBTrasformazioniLib.CRUDTrasformazioni(type, con, aPD.getTrasformazioni(), idPortaDelegata, true);
  2705.                
  2706.                 // Handlers
  2707.                 DriverConfigurazioneDB_handlerLIB.CRUDConfigurazioneMessageHandlers(type, con, idPortaDelegata, null, true, (configHandlers!=null) ? configHandlers.getRequest() : null);
  2708.                 DriverConfigurazioneDB_handlerLIB.CRUDConfigurazioneMessageHandlers(type, con, idPortaDelegata, null, false, (configHandlers!=null) ? configHandlers.getResponse() : null);
  2709.                
  2710.                 // AttributeAuthority
  2711.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2712.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_ATTRIBUTE_AUTHORITY);
  2713.                 sqlQueryObject.addWhereCondition("id_porta=?");
  2714.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2715.                 stm = con.prepareStatement(sqlQuery);
  2716.                 stm.setLong(1, idPortaDelegata);
  2717.                 n=stm.executeUpdate();
  2718.                 stm.close();
  2719.                 DriverConfigurazioneDBLib.logDebug("Cancellate "+n+" A.A. associate alla Porta Delegata "+idPortaDelegata);
  2720.                
  2721.                 // Cache Regole
  2722.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2723.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_CACHE_REGOLE);
  2724.                 sqlQueryObject.addWhereCondition("id_porta=?");
  2725.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2726.                 stm = con.prepareStatement(sqlQuery);
  2727.                 stm.setLong(1, idPortaDelegata);
  2728.                 n=stm.executeUpdate();
  2729.                 stm.close();
  2730.                 DriverConfigurazioneDBLib.logDebug("Cancellati "+n+" regole di cache associate alla Porta Delegata "+idPortaDelegata);
  2731.                
  2732.                 // azioni delegate
  2733.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2734.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_AZIONI);
  2735.                 sqlQueryObject.addWhereCondition("id_porta=?");
  2736.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2737.                 stm = con.prepareStatement(sqlQuery);
  2738.                 stm.setLong(1, idPortaDelegata);
  2739.                 n=stm.executeUpdate();
  2740.                 stm.close();
  2741.                 DriverConfigurazioneDBLib.logDebug("Cancellati "+n+" azioni delegate associate alla Porta Delegata "+idPortaDelegata);
  2742.                
  2743.                 // ruoli (token)
  2744.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2745.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_TOKEN_RUOLI);
  2746.                 sqlQueryObject.addWhereCondition("id_porta=?");
  2747.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2748.                 stm = con.prepareStatement(sqlQuery);
  2749.                 stm.setLong(1, idPortaDelegata);
  2750.                 n=stm.executeUpdate();
  2751.                 stm.close();
  2752.                 DriverConfigurazioneDBLib.logDebug("Cancellati "+n+" ruoli (token) associati alla Porta Delegata "+idPortaDelegata);
  2753.                
  2754.                 // servizi applicativi (token)
  2755.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2756.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_TOKEN_SA);
  2757.                 sqlQueryObject.addWhereCondition("id_porta=?");
  2758.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2759.                 stm = con.prepareStatement(sqlQuery);
  2760.                 stm.setLong(1, idPortaDelegata);
  2761.                 n=stm.executeUpdate();
  2762.                 stm.close();
  2763.                 DriverConfigurazioneDBLib.logDebug("Deleted " + n + " associazioni PortaDelegata<->ServizioApplicativo (token) associati alla PortaDelegata[" + idPortaDelegata + "]");
  2764.                
  2765.                 // ruoli
  2766.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2767.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_RUOLI);
  2768.                 sqlQueryObject.addWhereCondition("id_porta=?");
  2769.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2770.                 stm = con.prepareStatement(sqlQuery);
  2771.                 stm.setLong(1, idPortaDelegata);
  2772.                 n=stm.executeUpdate();
  2773.                 stm.close();
  2774.                 DriverConfigurazioneDBLib.logDebug("Cancellati "+n+" ruoli associati alla Porta Delegata "+idPortaDelegata);
  2775.                
  2776.                 // scope
  2777.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2778.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_SCOPE);
  2779.                 sqlQueryObject.addWhereCondition("id_porta=?");
  2780.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2781.                 stm = con.prepareStatement(sqlQuery);
  2782.                 stm.setLong(1, idPortaDelegata);
  2783.                 n=stm.executeUpdate();
  2784.                 stm.close();
  2785.                 DriverConfigurazioneDBLib.logDebug("Cancellati "+n+" scope associati alla Porta Delegata "+idPortaDelegata);
  2786.                
  2787.                 // mtom
  2788.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2789.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_MTOM_REQUEST);
  2790.                 sqlQueryObject.addWhereCondition("id_porta=?");
  2791.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2792.                 stm = con.prepareStatement(sqlQuery);
  2793.                 stm.setLong(1, idPortaDelegata);
  2794.                 n=stm.executeUpdate();
  2795.                 stm.close();
  2796.                 DriverConfigurazioneDBLib.logDebug("Deleted " + n + " request flow con id=" + idPortaDelegata);

  2797.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2798.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_MTOM_RESPONSE);
  2799.                 sqlQueryObject.addWhereCondition("id_porta=?");
  2800.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2801.                 stm = con.prepareStatement(sqlQuery);
  2802.                 stm.setLong(1, idPortaDelegata);
  2803.                 n=stm.executeUpdate();
  2804.                 stm.close();
  2805.                 DriverConfigurazioneDBLib.logDebug("Deleted " + n + " response flow con id=" + idPortaDelegata);

  2806.                
  2807.                 // message security
  2808.                 //if ( CostantiConfigurazione.ABILITATO.toString().equals(messageSecurityStatus) )  {
  2809.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2810.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST);
  2811.                 sqlQueryObject.addWhereCondition("id_porta=?");
  2812.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2813.                 stm = con.prepareStatement(sqlQuery);
  2814.                 stm.setLong(1, idPortaDelegata);
  2815.                 n=stm.executeUpdate();
  2816.                 stm.close();
  2817.                 DriverConfigurazioneDBLib.logDebug("Deleted " + n + " request flow con id=" + idPortaDelegata);

  2818.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2819.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE);
  2820.                 sqlQueryObject.addWhereCondition("id_porta=?");
  2821.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2822.                 stm = con.prepareStatement(sqlQuery);
  2823.                 stm.setLong(1, idPortaDelegata);
  2824.                 n=stm.executeUpdate();
  2825.                 stm.close();
  2826.                 DriverConfigurazioneDBLib.logDebug("Deleted " + n + " response flow con id=" + idPortaDelegata);
  2827.                 //}

  2828.                 // servizi applicativi
  2829.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2830.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_SA);
  2831.                 sqlQueryObject.addWhereCondition("id_porta=?");
  2832.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2833.                 stm = con.prepareStatement(sqlQuery);
  2834.                 stm.setLong(1, idPortaDelegata);
  2835.                 n=stm.executeUpdate();
  2836.                 stm.close();
  2837.                 DriverConfigurazioneDBLib.logDebug("Deleted " + n + " associazioni PortaDelegata<->ServizioApplicativo associati alla PortaDelegata[" + idPortaDelegata + "]");

  2838.                 // cancello anche le flow di request/response associate a questa
  2839.                 // porta applicativa
  2840.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2841.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST);
  2842.                 sqlQueryObject.addWhereCondition("id_porta=?");
  2843.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2844.                 stm = con.prepareStatement(sqlQuery);
  2845.                 stm.setLong(1, idPortaDelegata);
  2846.                 n=stm.executeUpdate();
  2847.                 stm.close();
  2848.                 if (n > 0)
  2849.                     DriverConfigurazioneDBLib.logDebug("Deleted " + n + " security_request flow associate alla PortaDelegata[" + idPortaDelegata + "]");

  2850.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2851.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE);
  2852.                 sqlQueryObject.addWhereCondition("id_porta=?");
  2853.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2854.                 stm = con.prepareStatement(sqlQuery);
  2855.                 stm.setLong(1, idPortaDelegata);
  2856.                 n=stm.executeUpdate();
  2857.                 stm.close();
  2858.                 if (n > 0)
  2859.                     DriverConfigurazioneDBLib.logDebug("Deleted " + n + " security_response flow associate alla PortaDelegata[" + idPortaDelegata + "]");

  2860.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2861.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_CORRELAZIONE);
  2862.                 sqlQueryObject.addWhereCondition("id_porta=?");
  2863.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2864.                 stm = con.prepareStatement(sqlQuery);
  2865.                 stm.setLong(1, idPortaDelegata);

  2866.                 n = stm.executeUpdate();
  2867.                 stm.close();
  2868.                 if (n > 0)
  2869.                     DriverConfigurazioneDBLib.logDebug("Deleted " + n + " correlazione associate alla PortaDelegata[" + idPortaDelegata + "]");

  2870.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2871.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_CORRELAZIONE_RISPOSTA);
  2872.                 sqlQueryObject.addWhereCondition("id_porta=?");
  2873.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2874.                 stm = con.prepareStatement(sqlQuery);
  2875.                 stm.setLong(1, idPortaDelegata);

  2876.                 n = stm.executeUpdate();
  2877.                 stm.close();
  2878.                 if (n > 0)
  2879.                     DriverConfigurazioneDBLib.logDebug("Deleted " + n + " correlazione per la rispsota associate alla PortaDelegata[" + idPortaDelegata + "]");

  2880.                 // cancello le prop
  2881.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2882.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_PROP);
  2883.                 sqlQueryObject.addWhereCondition("id_porta=?");
  2884.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2885.                 stm = con.prepareStatement(sqlQuery);
  2886.                 stm.setLong(1, idPortaDelegata);
  2887.                 n=stm.executeUpdate();
  2888.                 stm.close();
  2889.                 if (n > 0)
  2890.                     DriverConfigurazioneDBLib.logDebug("Deleted " + n + " SetProtocolProp associati alla PortaDelegata[" + idPortaDelegata + "]");
  2891.                
  2892.                 // cancello le prop di rate limiting
  2893.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2894.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_RATE_LIMITING_PROP);
  2895.                 sqlQueryObject.addWhereCondition("id_porta=?");
  2896.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2897.                 stm = con.prepareStatement(sqlQuery);
  2898.                 stm.setLong(1, idPortaDelegata);
  2899.                 n=stm.executeUpdate();
  2900.                 stm.close();
  2901.                 if (n > 0)
  2902.                     DriverConfigurazioneDBLib.logDebug("Deleted " + n + " SetProtocolPropRateLimiting associati alla PortaDelegata[" + idPortaDelegata + "]");
  2903.                
  2904.                 // cancello le prop di autorizzazione contenuti
  2905.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2906.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_AUTORIZZAZIONE_CONTENUTI_PROP);
  2907.                 sqlQueryObject.addWhereCondition("id_porta=?");
  2908.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2909.                 stm = con.prepareStatement(sqlQuery);
  2910.                 stm.setLong(1, idPortaDelegata);
  2911.                 n=stm.executeUpdate();
  2912.                 stm.close();
  2913.                 if (n > 0)
  2914.                     DriverConfigurazioneDBLib.logDebug("Deleted " + n + " SetProtocolPropAutorizzazioneContenuto associati alla PortaDelegata[" + idPortaDelegata + "]");
  2915.                
  2916.                 // cancello le prop di autorizzazione
  2917.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2918.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_AUTORIZZAZIONE_PROP);
  2919.                 sqlQueryObject.addWhereCondition("id_porta=?");
  2920.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2921.                 stm = con.prepareStatement(sqlQuery);
  2922.                 stm.setLong(1, idPortaDelegata);
  2923.                 n=stm.executeUpdate();
  2924.                 stm.close();
  2925.                 if (n > 0)
  2926.                     DriverConfigurazioneDBLib.logDebug("Deleted " + n + " SetProtocolPropAutorizzazione associati alla PortaDelegata[" + idPortaDelegata + "]");
  2927.                
  2928.                
  2929.                 // cancello le prop di autenticazione
  2930.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2931.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE_AUTENTICAZIONE_PROP);
  2932.                 sqlQueryObject.addWhereCondition("id_porta=?");
  2933.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2934.                 stm = con.prepareStatement(sqlQuery);
  2935.                 stm.setLong(1, idPortaDelegata);
  2936.                 n=stm.executeUpdate();
  2937.                 stm.close();
  2938.                 if (n > 0)
  2939.                     DriverConfigurazioneDBLib.logDebug("Deleted " + n + " SetProtocolPropAutenticazione associati alla PortaDelegata[" + idPortaDelegata + "]");
  2940.                
  2941.                 // extendedInfo
  2942.                 if(extInfoConfigurazioneDriver!=null){
  2943.                     extInfoConfigurazioneDriver.deleteAllExtendedInfo(con, DriverConfigurazioneDBLib.log, aPD, CRUDType.DELETE);
  2944.                 }
  2945.                
  2946.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  2947.                 sqlQueryObject.addDeleteTable(CostantiDB.PORTE_DELEGATE);
  2948.                 sqlQueryObject.addWhereCondition("id=?");
  2949.                 sqlQuery = sqlQueryObject.createSQLDelete();
  2950.                 stm = con.prepareStatement(sqlQuery);
  2951.                 stm.setLong(1, idPortaDelegata);
  2952.                 DriverConfigurazioneDBLib.logDebug("eseguo query : " + DBUtils.formatSQLString(sqlQuery, idPortaDelegata));
  2953.                 n=stm.executeUpdate();
  2954.                 stm.close();
  2955.                 DriverConfigurazioneDBLib.logDebug("Deleted " + n + " row(s).");


  2956.                 break;
  2957.             }
  2958.             return idPortaDelegata;
  2959.         } catch (DriverConfigurazioneException e) {
  2960.             throw e;
  2961.         } catch (SQLException se) {
  2962.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB_LIB::CRUDPortaDelegata] SQLException : " + se.getMessage(),se);
  2963.         } catch (Exception e) {
  2964.             throw new DriverConfigurazioneException("Errore durante operazione("+type+") CRUDPortaDelegata.",e);
  2965.         }finally {
  2966.             //Chiudo statement and resultset
  2967.             JDBCUtilities.closeResources(rs, stm);
  2968.         }
  2969.     }


  2970.    
  2971. }