DriverConfigurazioneDBTrasformazioniLib.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.util.ArrayList;
  29. import java.util.Collections;
  30. import java.util.HashMap;
  31. import java.util.List;

  32. import org.openspcoop2.core.commons.DBUtils;
  33. import org.openspcoop2.core.config.TrasformazioneRegola;
  34. import org.openspcoop2.core.config.TrasformazioneRegolaApplicabilitaRichiesta;
  35. import org.openspcoop2.core.config.TrasformazioneRegolaApplicabilitaRisposta;
  36. import org.openspcoop2.core.config.TrasformazioneRegolaApplicabilitaServizioApplicativo;
  37. import org.openspcoop2.core.config.TrasformazioneRegolaApplicabilitaSoggetto;
  38. import org.openspcoop2.core.config.TrasformazioneRegolaParametro;
  39. import org.openspcoop2.core.config.TrasformazioneRegolaRichiesta;
  40. import org.openspcoop2.core.config.TrasformazioneRegolaRisposta;
  41. import org.openspcoop2.core.config.TrasformazioneRest;
  42. import org.openspcoop2.core.config.TrasformazioneSoap;
  43. import org.openspcoop2.core.config.TrasformazioneSoapRisposta;
  44. import org.openspcoop2.core.config.Trasformazioni;
  45. import org.openspcoop2.core.config.constants.StatoFunzionalita;
  46. import org.openspcoop2.core.config.driver.DriverConfigurazioneException;
  47. import org.openspcoop2.core.constants.CostantiDB;
  48. import org.openspcoop2.utils.TipiDatabase;
  49. import org.openspcoop2.utils.jdbc.CustomKeyGeneratorObject;
  50. import org.openspcoop2.utils.jdbc.IJDBCAdapter;
  51. import org.openspcoop2.utils.jdbc.InsertAndGeneratedKey;
  52. import org.openspcoop2.utils.jdbc.InsertAndGeneratedKeyJDBCType;
  53. import org.openspcoop2.utils.jdbc.InsertAndGeneratedKeyObject;
  54. import org.openspcoop2.utils.jdbc.JDBCAdapterException;
  55. import org.openspcoop2.utils.jdbc.JDBCAdapterFactory;
  56. import org.openspcoop2.utils.jdbc.JDBCUtilities;
  57. import org.openspcoop2.utils.sql.ISQLQueryObject;
  58. import org.openspcoop2.utils.sql.SQLObjectFactory;

  59. /**
  60.  * DriverConfigurazioneDB_trasformazioniLIB
  61.  *
  62.  * @author Stefano Corallo - corallo@link.it
  63.  * @author $Author$
  64.  * @version $Rev$, $Date$
  65.  */
  66. public class DriverConfigurazioneDBTrasformazioniLib {
  67.    
  68.     private DriverConfigurazioneDBTrasformazioniLib() {}

  69.     private static final String ESEGUO_QUERY_PREFIX = "eseguo query : ";
  70.    
  71.     private static void normalizePositionsEngine(Trasformazioni trasformazioni) {
  72.         if(trasformazioni==null || trasformazioni.sizeRegolaList()<=0) {
  73.             return;
  74.         }
  75.        
  76.         List<Integer> posizioni = new ArrayList<>();
  77.         HashMap<Integer, TrasformazioneRegola> regole = new HashMap<>();
  78.         for (TrasformazioneRegola regola : trasformazioni.getRegolaList()) {
  79.             posizioni.add(regola.getPosizione());
  80.             regole.put(regola.getPosizione(), regola);
  81.         }
  82.         while(trasformazioni.sizeRegolaList()>0) {
  83.             trasformazioni.removeRegola(0);
  84.         }
  85.         Collections.sort( posizioni );
  86.         int posNew = 1;
  87.         for (Integer pos : posizioni) {
  88.             TrasformazioneRegola regola = regole.get(pos);
  89.             regola.setPosizione(posNew);
  90.             trasformazioni.addRegola(regola);
  91.             posNew++;
  92.         }
  93.        
  94.         // normalizzazione delle risposte
  95.         for (TrasformazioneRegola regola : trasformazioni.getRegolaList()) {
  96.            
  97.             if(regola.getRispostaList()==null || regola.sizeRispostaList()<=0){
  98.                 continue;
  99.             }
  100.            
  101.             List<Integer> posizioniRisposta = new ArrayList<>();
  102.             HashMap<Integer, TrasformazioneRegolaRisposta> regoleRisposta = new HashMap<>();
  103.             for (TrasformazioneRegolaRisposta regolaRisposta : regola.getRispostaList()) {
  104.                 posizioniRisposta.add(regolaRisposta.getPosizione());
  105.                 regoleRisposta.put(regolaRisposta.getPosizione(), regolaRisposta);
  106.             }
  107.             while(regola.sizeRispostaList()>0) {
  108.                 regola.removeRisposta(0);
  109.             }
  110.             Collections.sort( posizioniRisposta );
  111.             int posRispostaNew = 1;
  112.             for (Integer posRisposta : posizioniRisposta) {
  113.                 TrasformazioneRegolaRisposta regolaRisposta = regoleRisposta.get(posRisposta);
  114.                 regolaRisposta.setPosizione(posRispostaNew);
  115.                 regola.addRisposta(regolaRisposta);
  116.                 posRispostaNew++;
  117.             }
  118.         }
  119.     }
  120.    
  121.     static void CRUDTrasformazioni(int type, Connection con, Trasformazioni trasformazioni,
  122.             Long idProprietario, boolean portaDelegata) throws DriverConfigurazioneException, JDBCAdapterException {
  123.        
  124.         PreparedStatement updateStmt = null;
  125.         ResultSet rs = null;
  126.         IJDBCAdapter jdbcAdapter = JDBCAdapterFactory.createJDBCAdapter(DriverConfigurazioneDBLib.tipoDB);
  127.         try {
  128.             switch (type) {
  129.             case CREATE:
  130.        
  131.                 if(trasformazioni==null || trasformazioni.sizeRegolaList()<=0) {
  132.                     break;
  133.                 }
  134.                
  135.                 normalizePositionsEngine(trasformazioni);
  136.                
  137.                 for (TrasformazioneRegola regola : trasformazioni.getRegolaList()) {
  138.                    
  139.                     String applicabilitaAzioni = null;
  140.                     if(regola.getApplicabilita()!=null && regola.getApplicabilita().sizeAzioneList()>0) {
  141.                         StringBuilder bf = new StringBuilder();
  142.                         for (int i = 0; i < regola.getApplicabilita().sizeAzioneList(); i++) {
  143.                             if(i>0) {
  144.                                 bf.append(",");
  145.                             }
  146.                             bf.append(regola.getApplicabilita().getAzione(i));
  147.                         }
  148.                         if(bf.length()>0) {
  149.                             applicabilitaAzioni = bf.toString();
  150.                         }
  151.                     }
  152.                    
  153.                     String applicabilitaCT = null;
  154.                     if(regola.getApplicabilita()!=null && regola.getApplicabilita().sizeContentTypeList()>0) {
  155.                         StringBuilder bf = new StringBuilder();
  156.                         for (int i = 0; i < regola.getApplicabilita().sizeContentTypeList(); i++) {
  157.                             if(i>0) {
  158.                                 bf.append(",");
  159.                             }
  160.                             bf.append(regola.getApplicabilita().getContentType(i));
  161.                         }
  162.                         if(bf.length()>0) {
  163.                             applicabilitaCT = bf.toString();
  164.                         }
  165.                     }
  166.                    
  167.                     String applicabilitaConnettori = null;
  168.                     if(regola.getApplicabilita()!=null && regola.getApplicabilita().sizeConnettoreList()>0) {
  169.                         StringBuilder bf = new StringBuilder();
  170.                         for (int i = 0; i < regola.getApplicabilita().sizeConnettoreList(); i++) {
  171.                             if(i>0) {
  172.                                 bf.append(",");
  173.                             }
  174.                             bf.append(regola.getApplicabilita().getConnettore(i));
  175.                         }
  176.                         if(bf.length()>0) {
  177.                             applicabilitaConnettori = bf.toString();
  178.                         }
  179.                     }
  180.                    
  181.                     List<InsertAndGeneratedKeyObject> listInsertAndGeneratedKeyObject = new ArrayList<>();
  182.                     listInsertAndGeneratedKeyObject.add( new InsertAndGeneratedKeyObject("id_porta", idProprietario , InsertAndGeneratedKeyJDBCType.LONG) );
  183.                     listInsertAndGeneratedKeyObject.add( new InsertAndGeneratedKeyObject("nome", regola.getNome() , InsertAndGeneratedKeyJDBCType.STRING) );
  184.                     listInsertAndGeneratedKeyObject.add( new InsertAndGeneratedKeyObject(CostantiDB.TRASFORMAZIONI_COLUMN_POSIZIONE, regola.getPosizione() , InsertAndGeneratedKeyJDBCType.INT) );
  185.                     listInsertAndGeneratedKeyObject.add( new InsertAndGeneratedKeyObject("stato", DriverConfigurazioneDBLib.getValue(regola.getStato()) , InsertAndGeneratedKeyJDBCType.STRING) );
  186.                     listInsertAndGeneratedKeyObject.add( new InsertAndGeneratedKeyObject("applicabilita_azioni", applicabilitaAzioni , InsertAndGeneratedKeyJDBCType.STRING) );
  187.                     listInsertAndGeneratedKeyObject.add( new InsertAndGeneratedKeyObject(CostantiDB.TRASFORMAZIONI_COLUMN_APPLICABILITA_CT, applicabilitaCT , InsertAndGeneratedKeyJDBCType.STRING) );
  188.                     listInsertAndGeneratedKeyObject.add( new InsertAndGeneratedKeyObject(CostantiDB.TRASFORMAZIONI_COLUMN_APPLICABILITA_PATTERN, (regola.getApplicabilita()!=null ? regola.getApplicabilita().getPattern() : null) , InsertAndGeneratedKeyJDBCType.STRING) );
  189.                     listInsertAndGeneratedKeyObject.add( new InsertAndGeneratedKeyObject("applicabilita_connettori", applicabilitaConnettori , InsertAndGeneratedKeyJDBCType.STRING) );
  190.                     listInsertAndGeneratedKeyObject.add( new InsertAndGeneratedKeyObject("req_conversione_enabled", ( regola.getRichiesta()!=null && regola.getRichiesta().getConversione()) ? CostantiDB.TRUE : CostantiDB.FALSE , InsertAndGeneratedKeyJDBCType.INT) );
  191.                     listInsertAndGeneratedKeyObject.add( new InsertAndGeneratedKeyObject("req_conversione_tipo", (regola.getRichiesta()!=null ? regola.getRichiesta().getConversioneTipo() : null) , InsertAndGeneratedKeyJDBCType.STRING) );
  192.                     listInsertAndGeneratedKeyObject.add( new InsertAndGeneratedKeyObject("req_content_type", (regola.getRichiesta()!=null ? regola.getRichiesta().getContentType() : null) , InsertAndGeneratedKeyJDBCType.STRING) );
  193.                     if(regola.getRichiesta()!=null && regola.getRichiesta().getTrasformazioneRest()!=null) {
  194.                         listInsertAndGeneratedKeyObject.add( new InsertAndGeneratedKeyObject("rest_transformation", CostantiDB.TRUE , InsertAndGeneratedKeyJDBCType.INT) );
  195.                         listInsertAndGeneratedKeyObject.add( new InsertAndGeneratedKeyObject("rest_method", regola.getRichiesta().getTrasformazioneRest().getMetodo() , InsertAndGeneratedKeyJDBCType.STRING) );
  196.                         listInsertAndGeneratedKeyObject.add( new InsertAndGeneratedKeyObject("rest_path", regola.getRichiesta().getTrasformazioneRest().getPath() , InsertAndGeneratedKeyJDBCType.STRING) );
  197.                     }
  198.                     if(regola.getRichiesta()!=null && regola.getRichiesta().getTrasformazioneSoap()!=null) {
  199.                         listInsertAndGeneratedKeyObject.add( new InsertAndGeneratedKeyObject("soap_transformation", CostantiDB.TRUE , InsertAndGeneratedKeyJDBCType.INT) );
  200.                         listInsertAndGeneratedKeyObject.add( new InsertAndGeneratedKeyObject("soap_version", DriverConfigurazioneDBLib.getValue(regola.getRichiesta().getTrasformazioneSoap().getVersione()) , InsertAndGeneratedKeyJDBCType.STRING) );
  201.                         listInsertAndGeneratedKeyObject.add( new InsertAndGeneratedKeyObject("soap_action", regola.getRichiesta().getTrasformazioneSoap().getSoapAction() , InsertAndGeneratedKeyJDBCType.STRING) );
  202.                         listInsertAndGeneratedKeyObject.add( new InsertAndGeneratedKeyObject(CostantiDB.TRASFORMAZIONI_COLUMN_SOAP_ENVELOPE, (regola.getRichiesta().getTrasformazioneSoap().getEnvelope() ? CostantiDB.TRUE : CostantiDB.FALSE) , InsertAndGeneratedKeyJDBCType.INT) );
  203.                         listInsertAndGeneratedKeyObject.add( new InsertAndGeneratedKeyObject(CostantiDB.TRASFORMAZIONI_COLUMN_SOAP_ENVELOPE_AS_ATTACH, (regola.getRichiesta().getTrasformazioneSoap().getEnvelopeAsAttachment() ? CostantiDB.TRUE : CostantiDB.FALSE) , InsertAndGeneratedKeyJDBCType.INT) );
  204.                         listInsertAndGeneratedKeyObject.add( new InsertAndGeneratedKeyObject(CostantiDB.TRASFORMAZIONI_COLUMN_SOAP_ENVELOPE_TIPO, regola.getRichiesta().getTrasformazioneSoap().getEnvelopeBodyConversioneTipo() , InsertAndGeneratedKeyJDBCType.STRING) );
  205.                     }
  206.                     // Insert and return generated key
  207.                     String tableName = null;
  208.                     String columnIdName = null;
  209.                     String sequence = null;
  210.                     String tableForId = null;
  211.                     if(portaDelegata) {
  212.                         tableName = CostantiDB.PORTE_DELEGATE_TRASFORMAZIONI;
  213.                         columnIdName = CostantiDB.PORTE_DELEGATE_TRASFORMAZIONI_COLUMN_ID;
  214.                         sequence = CostantiDB.PORTE_DELEGATE_TRASFORMAZIONI_SEQUENCE;
  215.                         tableForId = CostantiDB.PORTE_DELEGATE_TRASFORMAZIONI_TABLE_FOR_ID;
  216.                     }
  217.                     else {
  218.                         tableName = CostantiDB.PORTE_APPLICATIVE_TRASFORMAZIONI;
  219.                         columnIdName = CostantiDB.PORTE_APPLICATIVE_TRASFORMAZIONI_COLUMN_ID;
  220.                         sequence = CostantiDB.PORTE_APPLICATIVE_TRASFORMAZIONI_SEQUENCE;
  221.                         tableForId = CostantiDB.PORTE_APPLICATIVE_TRASFORMAZIONI_TABLE_FOR_ID;
  222.                     }
  223.                     long idtrasformazione = InsertAndGeneratedKey.insertAndReturnGeneratedKey(con, TipiDatabase.toEnumConstant(DriverConfigurazioneDBLib.tipoDB),
  224.                             new CustomKeyGeneratorObject(tableName, columnIdName, sequence, tableForId),
  225.                             listInsertAndGeneratedKeyObject.toArray(new InsertAndGeneratedKeyObject[1]));
  226.                     if(idtrasformazione<=0){
  227.                         throw new DriverConfigurazioneException("ID autoincrementale non ottenuto");
  228.                     }
  229.                    
  230.                     if( regola.getRichiesta()!=null &&
  231.                             (
  232.                                     regola.getRichiesta().getConversioneTemplate()!=null
  233.                                     ||
  234.                                     (regola.getRichiesta().getTrasformazioneSoap()!=null && regola.getRichiesta().getTrasformazioneSoap().getEnvelopeBodyConversioneTemplate()!=null)
  235.                             ) ) {
  236.                         ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  237.                         sqlQueryObject.addUpdateTable(tableName);
  238.                         if(regola.getRichiesta().getConversioneTemplate()!=null ) {
  239.                             sqlQueryObject.addUpdateField("req_conversione_template", "?");
  240.                         }
  241.                         if(regola.getRichiesta().getTrasformazioneSoap()!=null && regola.getRichiesta().getTrasformazioneSoap().getEnvelopeBodyConversioneTemplate()!=null) {
  242.                             sqlQueryObject.addUpdateField(CostantiDB.TRASFORMAZIONI_COLUMN_SOAP_ENVELOPE_TEMPLATE, "?");
  243.                         }
  244.                         sqlQueryObject.addWhereCondition(columnIdName+"=?");
  245.                         String updateQuery = sqlQueryObject.createSQLUpdate();
  246.                         updateStmt = con.prepareStatement(updateQuery);
  247.                         int index = 1;
  248.                         if(regola.getRichiesta().getConversioneTemplate()!=null ) {
  249.                             jdbcAdapter.setBinaryData(updateStmt, index++, regola.getRichiesta()!=null ? regola.getRichiesta().getConversioneTemplate() : null);
  250.                         }
  251.                         if(regola.getRichiesta().getTrasformazioneSoap()!=null && regola.getRichiesta().getTrasformazioneSoap().getEnvelopeBodyConversioneTemplate()!=null) {
  252.                             jdbcAdapter.setBinaryData(updateStmt, index++, regola.getRichiesta().getTrasformazioneSoap().getEnvelopeBodyConversioneTemplate());
  253.                         }
  254.                         updateStmt.setLong(index++, idtrasformazione);
  255.                         updateStmt.executeUpdate();
  256.                         updateStmt.close();
  257.                     }
  258.                
  259.                    
  260.                     if(regola.getRichiesta()!=null) {
  261.                        
  262.                         if(regola.getApplicabilita()!=null) {
  263.                            
  264.                             if(!portaDelegata && regola.getApplicabilita().sizeSoggettoList()>0) {
  265.                                 // Soggetti
  266.                                 int n=0;
  267.                                 for (int j = 0; j < regola.getApplicabilita().sizeSoggettoList(); j++) {
  268.                                     TrasformazioneRegolaApplicabilitaSoggetto soggetto = regola.getApplicabilita().getSoggetto(j);
  269.                                     ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  270.                                     sqlQueryObject.addInsertTable(CostantiDB.PORTE_APPLICATIVE_TRASFORMAZIONI_SOGGETTI);
  271.                                     sqlQueryObject.addInsertField(CostantiDB.TRASFORMAZIONI_COLUMN_ID_RIF_TRASFORMAZIONE, "?");
  272.                                     sqlQueryObject.addInsertField(CostantiDB.TRASFORMAZIONI_COLUMN_TIPO_SOGGETTO, "?");
  273.                                     sqlQueryObject.addInsertField(CostantiDB.TRASFORMAZIONI_COLUMN_NOME_SOGGETTO, "?");
  274.                                     String sqlQuery = sqlQueryObject.createSQLInsert();
  275.                                     updateStmt = con.prepareStatement(sqlQuery);
  276.                                     updateStmt.setLong(1, idtrasformazione);
  277.                                     updateStmt.setString(2, soggetto.getTipo());
  278.                                     updateStmt.setString(3, soggetto.getNome());
  279.                                     updateStmt.executeUpdate();
  280.                                     updateStmt.close();
  281.                                     n++;
  282.                                     DriverConfigurazioneDBLib.logDebug("Aggiunto soggetto [" + soggetto.getTipo() + "/"+soggetto.getNome()+"] alla Trasformazione[" + idtrasformazione + "]");
  283.                                 }
  284.                                
  285.                                 DriverConfigurazioneDBLib.logDebug("Aggiunti " + n + " soggetti alla Trasformazione[" + idtrasformazione + "]");
  286.                             }
  287.                            
  288.                            
  289.                             // serviziapplicativi
  290.                             if(regola.getApplicabilita().sizeServizioApplicativoList()>0) {
  291.                                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  292.                                 if(portaDelegata) {
  293.                                     sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_TRASFORMAZIONI_SA);
  294.                                 }
  295.                                 else {
  296.                                     sqlQueryObject.addInsertTable(CostantiDB.PORTE_APPLICATIVE_TRASFORMAZIONI_SA);
  297.                                 }
  298.                                 sqlQueryObject.addInsertField(CostantiDB.TRASFORMAZIONI_COLUMN_ID_RIF_TRASFORMAZIONE, "?");
  299.                                 sqlQueryObject.addInsertField("id_servizio_applicativo", "?");
  300.                                 String sqlQuery = sqlQueryObject.createSQLInsert();
  301.                                 updateStmt = con.prepareStatement(sqlQuery);
  302.                
  303.                                 int i = 0;
  304.                                 for (i = 0; i < regola.getApplicabilita().sizeServizioApplicativoList(); i++) {
  305.                                     TrasformazioneRegolaApplicabilitaServizioApplicativo servizioApplicativo = regola.getApplicabilita().getServizioApplicativo(i);
  306.                                     String nomeSA = servizioApplicativo.getNome();
  307.                                     String nomeProprietarioSA = servizioApplicativo.getNomeSoggettoProprietario();
  308.                                     String tipoProprietarioSA = servizioApplicativo.getTipoSoggettoProprietario();
  309.                                     if (nomeSA == null || nomeSA.equals(""))
  310.                                         throw new DriverConfigurazioneException("[CRUDPortaApplicativa(CREATE)[Transf]::Nome del ServizioApplicativo associato non valido.");
  311.                                     if (nomeProprietarioSA == null || nomeProprietarioSA.equals(""))
  312.                                         throw new DriverConfigurazioneException("[CRUDPortaApplicativa(CREATE)[Transf]::Nome Proprietario del ServizioApplicativo associato non valido.");
  313.                                     if (tipoProprietarioSA == null || tipoProprietarioSA.equals(""))
  314.                                         throw new DriverConfigurazioneException("[CRUDPortaApplicativa(CREATE)[Transf]::Tipo Proprietario del ServizioApplicativo associato non valido.");
  315.                
  316.                                     long idSA = DriverConfigurazioneDB_serviziApplicativiLIB.getIdServizioApplicativo(nomeSA, tipoProprietarioSA, nomeProprietarioSA, con, DriverConfigurazioneDBLib.tipoDB,DriverConfigurazioneDBLib.tabellaSoggetti);
  317.                
  318.                                     if (idSA <= 0)
  319.                                         throw new DriverConfigurazioneException("Impossibile recuperare l'id del Servizio Applicativo [" + nomeSA + "] di [" + tipoProprietarioSA + "/" + nomeProprietarioSA + "]");
  320.                
  321.                                     updateStmt.setLong(1, idtrasformazione);
  322.                                     updateStmt.setLong(2, idSA);
  323.                                     updateStmt.executeUpdate();
  324.                                 }
  325.                                 updateStmt.close();
  326.                                 DriverConfigurazioneDBLib.logDebug("Inseriti " + i + " servizi applicativi autorizzati associati alla Trasformazione[" + idtrasformazione + "]");
  327.                             }
  328.                            
  329.                         }
  330.                        
  331.                         if(regola.getRichiesta().sizeHeaderList()>0) {
  332.                             for (TrasformazioneRegolaParametro parametro : regola.getRichiesta().getHeaderList()) {
  333.                                
  334.                                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  335.                                 if(portaDelegata) {
  336.                                     sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_TRASFORMAZIONI_HEADER);
  337.                                 }
  338.                                 else {
  339.                                     sqlQueryObject.addInsertTable(CostantiDB.PORTE_APPLICATIVE_TRASFORMAZIONI_HEADER);
  340.                                 }
  341.                                 sqlQueryObject.addInsertField(CostantiDB.TRASFORMAZIONI_COLUMN_ID_RIF_TRASFORMAZIONE, "?");
  342.                                 sqlQueryObject.addInsertField("tipo", "?");
  343.                                 sqlQueryObject.addInsertField("nome", "?");
  344.                                 sqlQueryObject.addInsertField(CostantiDB.TRASFORMAZIONI_COLUMN_VALORE, "?");
  345.                                 sqlQueryObject.addInsertField(CostantiDB.TRASFORMAZIONI_COLUMN_IDENTIFICAZIONE_FALLITA, "?");
  346.                                
  347.                                 String updateQuery = sqlQueryObject.createSQLInsert();
  348.                                 updateStmt = con.prepareStatement(updateQuery);
  349.                                 int index = 1;
  350.                                 updateStmt.setLong(index++, idtrasformazione);
  351.                                 updateStmt.setString(index++, DriverConfigurazioneDBLib.getValue(parametro.getConversioneTipo()));
  352.                                 updateStmt.setString(index++, parametro.getNome());
  353.                                 updateStmt.setString(index++, parametro.getValore());
  354.                                 updateStmt.setString(index++, DriverConfigurazioneDBLib.getValue(parametro.getIdentificazioneFallita()));
  355.                                 updateStmt.executeUpdate();
  356.                                 updateStmt.close();
  357.                             }
  358.                         }
  359.                        
  360.                         if(regola.getRichiesta().sizeParametroUrlList()>0) {
  361.                             for (TrasformazioneRegolaParametro parametro : regola.getRichiesta().getParametroUrlList()) {
  362.                                
  363.                                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  364.                                 if(portaDelegata) {
  365.                                     sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_TRASFORMAZIONI_URL);
  366.                                 }
  367.                                 else {
  368.                                     sqlQueryObject.addInsertTable(CostantiDB.PORTE_APPLICATIVE_TRASFORMAZIONI_URL);
  369.                                 }
  370.                                 sqlQueryObject.addInsertField(CostantiDB.TRASFORMAZIONI_COLUMN_ID_RIF_TRASFORMAZIONE, "?");
  371.                                 sqlQueryObject.addInsertField("tipo", "?");
  372.                                 sqlQueryObject.addInsertField("nome", "?");
  373.                                 sqlQueryObject.addInsertField(CostantiDB.TRASFORMAZIONI_COLUMN_VALORE, "?");
  374.                                 sqlQueryObject.addInsertField(CostantiDB.TRASFORMAZIONI_COLUMN_IDENTIFICAZIONE_FALLITA, "?");
  375.                                
  376.                                 String updateQuery = sqlQueryObject.createSQLInsert();
  377.                                 updateStmt = con.prepareStatement(updateQuery);
  378.                                 int index = 1;
  379.                                 updateStmt.setLong(index++, idtrasformazione);
  380.                                 updateStmt.setString(index++, DriverConfigurazioneDBLib.getValue(parametro.getConversioneTipo()));
  381.                                 updateStmt.setString(index++, parametro.getNome());
  382.                                 updateStmt.setString(index++, parametro.getValore());
  383.                                 updateStmt.setString(index++, DriverConfigurazioneDBLib.getValue(parametro.getIdentificazioneFallita()));
  384.                                 updateStmt.executeUpdate();
  385.                                 updateStmt.close();
  386.                             }
  387.                         }
  388.                     }
  389.                    
  390.                     if(regola.sizeRispostaList()>0) {
  391.                        
  392.                         for (TrasformazioneRegolaRisposta regolaRisposta : regola.getRispostaList()) {
  393.                            
  394.                             String applicabilitaCtResponse = null;
  395.                             if(regolaRisposta.getApplicabilita()!=null && regolaRisposta.getApplicabilita().sizeContentTypeList()>0) {
  396.                                 StringBuilder bf = new StringBuilder();
  397.                                 for (int i = 0; i < regolaRisposta.getApplicabilita().sizeContentTypeList(); i++) {
  398.                                     if(i>0) {
  399.                                         bf.append(",");
  400.                                     }
  401.                                     bf.append(regolaRisposta.getApplicabilita().getContentType(i));
  402.                                 }
  403.                                 if(bf.length()>0) {
  404.                                     applicabilitaCtResponse = bf.toString();
  405.                                 }
  406.                             }
  407.                            
  408.                             listInsertAndGeneratedKeyObject = new ArrayList<>();
  409.                             listInsertAndGeneratedKeyObject.add( new InsertAndGeneratedKeyObject(CostantiDB.TRASFORMAZIONI_COLUMN_ID_RIF_TRASFORMAZIONE, idtrasformazione , InsertAndGeneratedKeyJDBCType.LONG) );
  410.                             listInsertAndGeneratedKeyObject.add( new InsertAndGeneratedKeyObject("nome", regolaRisposta.getNome() , InsertAndGeneratedKeyJDBCType.STRING) );
  411.                             listInsertAndGeneratedKeyObject.add( new InsertAndGeneratedKeyObject(CostantiDB.TRASFORMAZIONI_COLUMN_POSIZIONE, regolaRisposta.getPosizione() , InsertAndGeneratedKeyJDBCType.INT) );
  412.                             listInsertAndGeneratedKeyObject.add( new InsertAndGeneratedKeyObject("applicabilita_status_min",
  413.                                     (regolaRisposta.getApplicabilita()!=null && regolaRisposta.getApplicabilita().getReturnCodeMin()!=null &&
  414.                                     regolaRisposta.getApplicabilita().getReturnCodeMin().intValue()>0) ? regolaRisposta.getApplicabilita().getReturnCodeMin().intValue() : null , InsertAndGeneratedKeyJDBCType.INT) );
  415.                             listInsertAndGeneratedKeyObject.add( new InsertAndGeneratedKeyObject("applicabilita_status_max",
  416.                                     (regolaRisposta.getApplicabilita()!=null && regolaRisposta.getApplicabilita().getReturnCodeMax()!=null &&
  417.                                     regolaRisposta.getApplicabilita().getReturnCodeMax().intValue()>0) ? regolaRisposta.getApplicabilita().getReturnCodeMax().intValue() : null , InsertAndGeneratedKeyJDBCType.INT) );
  418.                             listInsertAndGeneratedKeyObject.add( new InsertAndGeneratedKeyObject(CostantiDB.TRASFORMAZIONI_COLUMN_APPLICABILITA_CT, applicabilitaCtResponse , InsertAndGeneratedKeyJDBCType.STRING) );
  419.                             listInsertAndGeneratedKeyObject.add( new InsertAndGeneratedKeyObject(CostantiDB.TRASFORMAZIONI_COLUMN_APPLICABILITA_PATTERN, (regolaRisposta.getApplicabilita()!=null ? regolaRisposta.getApplicabilita().getPattern() : null) , InsertAndGeneratedKeyJDBCType.STRING) );
  420.                             listInsertAndGeneratedKeyObject.add( new InsertAndGeneratedKeyObject("conversione_enabled", regolaRisposta.getConversione() ? CostantiDB.TRUE : CostantiDB.FALSE , InsertAndGeneratedKeyJDBCType.INT) );
  421.                             listInsertAndGeneratedKeyObject.add( new InsertAndGeneratedKeyObject("conversione_tipo", regolaRisposta.getConversioneTipo() , InsertAndGeneratedKeyJDBCType.STRING) );
  422.                             listInsertAndGeneratedKeyObject.add( new InsertAndGeneratedKeyObject("content_type", regolaRisposta.getContentType() , InsertAndGeneratedKeyJDBCType.STRING) );
  423.                             listInsertAndGeneratedKeyObject.add( new InsertAndGeneratedKeyObject("return_code", regolaRisposta.getReturnCode(), InsertAndGeneratedKeyJDBCType.STRING) );
  424.                             if(regolaRisposta.getTrasformazioneSoap()!=null) {
  425.                                 listInsertAndGeneratedKeyObject.add( new InsertAndGeneratedKeyObject(CostantiDB.TRASFORMAZIONI_COLUMN_SOAP_ENVELOPE, (regolaRisposta.getTrasformazioneSoap().getEnvelope() ? CostantiDB.TRUE : CostantiDB.FALSE) , InsertAndGeneratedKeyJDBCType.INT) );
  426.                                 listInsertAndGeneratedKeyObject.add( new InsertAndGeneratedKeyObject(CostantiDB.TRASFORMAZIONI_COLUMN_SOAP_ENVELOPE_AS_ATTACH, (regolaRisposta.getTrasformazioneSoap().getEnvelopeAsAttachment() ? CostantiDB.TRUE : CostantiDB.FALSE) , InsertAndGeneratedKeyJDBCType.INT) );
  427.                                 listInsertAndGeneratedKeyObject.add( new InsertAndGeneratedKeyObject(CostantiDB.TRASFORMAZIONI_COLUMN_SOAP_ENVELOPE_TIPO, regolaRisposta.getTrasformazioneSoap().getEnvelopeBodyConversioneTipo() , InsertAndGeneratedKeyJDBCType.STRING) );
  428.                             }
  429.                             // Insert and return generated key
  430.                             tableName = null;
  431.                             columnIdName = null;
  432.                             sequence = null;
  433.                             tableForId = null;
  434.                             if(portaDelegata) {
  435.                                 tableName = CostantiDB.PORTE_DELEGATE_TRASFORMAZIONI_RISPOSTE;
  436.                                 columnIdName = CostantiDB.PORTE_DELEGATE_TRASFORMAZIONI_RISPOSTE_COLUMN_ID;
  437.                                 sequence = CostantiDB.PORTE_DELEGATE_TRASFORMAZIONI_RISPOSTE_SEQUENCE;
  438.                                 tableForId = CostantiDB.PORTE_DELEGATE_TRASFORMAZIONI_RISPOSTE_TABLE_FOR_ID;
  439.                             }
  440.                             else {
  441.                                 tableName = CostantiDB.PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTE;
  442.                                 columnIdName = CostantiDB.PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTE_COLUMN_ID;
  443.                                 sequence = CostantiDB.PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTE_SEQUENCE;
  444.                                 tableForId = CostantiDB.PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTE_TABLE_FOR_ID;
  445.                             }
  446.                             long idtrasformazioneRisposta = InsertAndGeneratedKey.insertAndReturnGeneratedKey(con, TipiDatabase.toEnumConstant(DriverConfigurazioneDBLib.tipoDB),
  447.                                     new CustomKeyGeneratorObject(tableName, columnIdName, sequence, tableForId),
  448.                                     listInsertAndGeneratedKeyObject.toArray(new InsertAndGeneratedKeyObject[1]));
  449.                             if(idtrasformazioneRisposta<=0){
  450.                                 throw new DriverConfigurazioneException("ID autoincrementale non ottenuto");
  451.                             }
  452.                            
  453.                             if(     regolaRisposta.getConversioneTemplate()!=null
  454.                                             ||
  455.                                             (regolaRisposta.getTrasformazioneSoap()!=null && regolaRisposta.getTrasformazioneSoap().getEnvelopeBodyConversioneTemplate()!=null)
  456.                                  ) {
  457.                                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  458.                                 sqlQueryObject.addUpdateTable(tableName);
  459.                                 if(regolaRisposta.getConversioneTemplate()!=null ) {
  460.                                     sqlQueryObject.addUpdateField("conversione_template", "?");
  461.                                 }
  462.                                 if(regolaRisposta.getTrasformazioneSoap()!=null && regolaRisposta.getTrasformazioneSoap().getEnvelopeBodyConversioneTemplate()!=null) {
  463.                                     sqlQueryObject.addUpdateField(CostantiDB.TRASFORMAZIONI_COLUMN_SOAP_ENVELOPE_TEMPLATE, "?");
  464.                                 }
  465.                                 sqlQueryObject.addWhereCondition(columnIdName+"=?");
  466.                                 String updateQuery = sqlQueryObject.createSQLUpdate();
  467.                                 updateStmt = con.prepareStatement(updateQuery);
  468.                                 int index = 1;
  469.                                 if(regolaRisposta.getConversioneTemplate()!=null ) {
  470.                                     jdbcAdapter.setBinaryData(updateStmt, index++, regolaRisposta.getConversioneTemplate());
  471.                                 }
  472.                                 if(regolaRisposta.getTrasformazioneSoap()!=null && regolaRisposta.getTrasformazioneSoap().getEnvelopeBodyConversioneTemplate()!=null) {
  473.                                     jdbcAdapter.setBinaryData(updateStmt, index++, regolaRisposta.getTrasformazioneSoap().getEnvelopeBodyConversioneTemplate());
  474.                                 }
  475.                                 updateStmt.setLong(index++, idtrasformazioneRisposta);
  476.                                 updateStmt.executeUpdate();
  477.                                 updateStmt.close();
  478.                             }
  479.                            
  480.                             if(regolaRisposta.sizeHeaderList()>0) {
  481.                                 for (TrasformazioneRegolaParametro parametro : regolaRisposta.getHeaderList()) {
  482.                                    
  483.                                     ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  484.                                     if(portaDelegata) {
  485.                                         sqlQueryObject.addInsertTable(CostantiDB.PORTE_DELEGATE_TRASFORMAZIONI_RISPOSTE_HEADER);
  486.                                     }
  487.                                     else {
  488.                                         sqlQueryObject.addInsertTable(CostantiDB.PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTE_HEADER);
  489.                                     }
  490.                                     sqlQueryObject.addInsertField("id_transform_risp", "?");
  491.                                     sqlQueryObject.addInsertField("tipo", "?");
  492.                                     sqlQueryObject.addInsertField("nome", "?");
  493.                                     sqlQueryObject.addInsertField(CostantiDB.TRASFORMAZIONI_COLUMN_VALORE, "?");
  494.                                     sqlQueryObject.addInsertField(CostantiDB.TRASFORMAZIONI_COLUMN_IDENTIFICAZIONE_FALLITA, "?");
  495.                                    
  496.                                     String updateQuery = sqlQueryObject.createSQLInsert();
  497.                                     updateStmt = con.prepareStatement(updateQuery);
  498.                                     int index = 1;
  499.                                     updateStmt.setLong(index++, idtrasformazioneRisposta);
  500.                                     updateStmt.setString(index++, DriverConfigurazioneDBLib.getValue(parametro.getConversioneTipo()));
  501.                                     updateStmt.setString(index++, parametro.getNome());
  502.                                     updateStmt.setString(index++, parametro.getValore());
  503.                                     updateStmt.setString(index++, DriverConfigurazioneDBLib.getValue(parametro.getIdentificazioneFallita()));
  504.                                     updateStmt.executeUpdate();
  505.                                     updateStmt.close();
  506.                                 }
  507.                             }
  508.                         }
  509.                        
  510.                     }
  511.                    
  512.                 }
  513.                
  514.                 break;
  515.                
  516.             case UPDATE:
  517.                
  518.                 // Per la delete recupero l'immagine attuale del configurazione
  519.                 Trasformazioni trasformazioniOld = readTrasformazioni(idProprietario, portaDelegata, con);
  520.                 if(trasformazioniOld!=null) {
  521.                     CRUDTrasformazioni(DELETE, con, trasformazioniOld, idProprietario, portaDelegata);
  522.                 }
  523.                
  524.                 // Creo la nuova immagine
  525.                 if(trasformazioni!=null) {
  526.                    
  527.                     normalizePositionsEngine(trasformazioni);
  528.                    
  529.                     CRUDTrasformazioni(CREATE, con, trasformazioni, idProprietario, portaDelegata);
  530.                 }
  531.                 break;
  532.                
  533.             case DELETE:
  534.                
  535.                 if(trasformazioni==null) {
  536.                     break;
  537.                 }
  538.                
  539.                 String tableName = portaDelegata ? CostantiDB.PORTE_DELEGATE_TRASFORMAZIONI : CostantiDB.PORTE_APPLICATIVE_TRASFORMAZIONI;
  540.                 String tableNameSoggetti = portaDelegata ? null : CostantiDB.PORTE_APPLICATIVE_TRASFORMAZIONI_SOGGETTI;
  541.                 String tableNameSA = portaDelegata ? CostantiDB.PORTE_DELEGATE_TRASFORMAZIONI_SA : CostantiDB.PORTE_APPLICATIVE_TRASFORMAZIONI_SA;
  542.                 String tableNameHeader = portaDelegata ? CostantiDB.PORTE_DELEGATE_TRASFORMAZIONI_HEADER : CostantiDB.PORTE_APPLICATIVE_TRASFORMAZIONI_HEADER;
  543.                 String tableNameUrl = portaDelegata ? CostantiDB.PORTE_DELEGATE_TRASFORMAZIONI_URL : CostantiDB.PORTE_APPLICATIVE_TRASFORMAZIONI_URL;
  544.                 String tableNameRisposte = portaDelegata ? CostantiDB.PORTE_DELEGATE_TRASFORMAZIONI_RISPOSTE : CostantiDB.PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTE;
  545.                 String tableNameRisposteHeader = portaDelegata ? CostantiDB.PORTE_DELEGATE_TRASFORMAZIONI_RISPOSTE_HEADER : CostantiDB.PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTE_HEADER;
  546.                 List<Long> idTrasformazioneList = new ArrayList<>();
  547.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  548.                 sqlQueryObject.addFromTable(tableName);
  549.                 sqlQueryObject.addSelectField("id");
  550.                 sqlQueryObject.addWhereCondition(CostantiDB.PORTA_COLUMN_ID_REF+"=?");
  551.                 sqlQueryObject.setANDLogicOperator(true);
  552.                 String updateQuery = sqlQueryObject.createSQLQuery();
  553.                 updateStmt = con.prepareStatement(updateQuery);
  554.                 updateStmt.setLong(1, idProprietario);
  555.                 rs = updateStmt.executeQuery();
  556.                 while(rs.next()) {
  557.                     idTrasformazioneList.add(rs.getLong("id"));
  558.                 }
  559.                 rs.close();
  560.                 updateStmt.close();
  561.                
  562.                 if(idTrasformazioneList.isEmpty()) {
  563.                     break;
  564.                 }
  565.                
  566.                 for (Long idTrasformazione : idTrasformazioneList) {
  567.                    
  568.                     if(tableNameSoggetti!=null) {
  569.                         sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  570.                         sqlQueryObject.addDeleteTable(tableNameSoggetti);
  571.                         sqlQueryObject.addWhereCondition(CostantiDB.TRASFORMAZIONI_COLUMN_ID_RIF_TRASFORMAZIONE+"=?");
  572.                         sqlQueryObject.setANDLogicOperator(true);
  573.                         updateQuery = sqlQueryObject.createSQLDelete();
  574.                         updateStmt = con.prepareStatement(updateQuery);
  575.                         updateStmt.setLong(1, idTrasformazione);
  576.                         updateStmt.executeUpdate();
  577.                         updateStmt.close();
  578.                     }
  579.                    
  580.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  581.                     sqlQueryObject.addDeleteTable(tableNameSA);
  582.                     sqlQueryObject.addWhereCondition(CostantiDB.TRASFORMAZIONI_COLUMN_ID_RIF_TRASFORMAZIONE+"=?");
  583.                     sqlQueryObject.setANDLogicOperator(true);
  584.                     updateQuery = sqlQueryObject.createSQLDelete();
  585.                     updateStmt = con.prepareStatement(updateQuery);
  586.                     updateStmt.setLong(1, idTrasformazione);
  587.                     updateStmt.executeUpdate();
  588.                     updateStmt.close();
  589.                    
  590.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  591.                     sqlQueryObject.addDeleteTable(tableNameHeader);
  592.                     sqlQueryObject.addWhereCondition(CostantiDB.TRASFORMAZIONI_COLUMN_ID_RIF_TRASFORMAZIONE+"=?");
  593.                     sqlQueryObject.setANDLogicOperator(true);
  594.                     updateQuery = sqlQueryObject.createSQLDelete();
  595.                     updateStmt = con.prepareStatement(updateQuery);
  596.                     updateStmt.setLong(1, idTrasformazione);
  597.                     updateStmt.executeUpdate();
  598.                     updateStmt.close();
  599.                    
  600.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  601.                     sqlQueryObject.addDeleteTable(tableNameUrl);
  602.                     sqlQueryObject.addWhereCondition(CostantiDB.TRASFORMAZIONI_COLUMN_ID_RIF_TRASFORMAZIONE+"=?");
  603.                     sqlQueryObject.setANDLogicOperator(true);
  604.                     updateQuery = sqlQueryObject.createSQLDelete();
  605.                     updateStmt = con.prepareStatement(updateQuery);
  606.                     updateStmt.setLong(1, idTrasformazione);
  607.                     updateStmt.executeUpdate();
  608.                     updateStmt.close();
  609.                    
  610.                     List<Long> idTrasformazioneRisposteList = new ArrayList<>();
  611.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  612.                     sqlQueryObject.addFromTable(tableNameRisposte);
  613.                     sqlQueryObject.addSelectField("id");
  614.                     sqlQueryObject.addWhereCondition(CostantiDB.TRASFORMAZIONI_COLUMN_ID_RIF_TRASFORMAZIONE+"=?");
  615.                     sqlQueryObject.setANDLogicOperator(true);
  616.                     updateQuery = sqlQueryObject.createSQLQuery();
  617.                     updateStmt = con.prepareStatement(updateQuery);
  618.                     updateStmt.setLong(1, idTrasformazione);
  619.                     rs = updateStmt.executeQuery();
  620.                     while(rs.next()) {
  621.                         idTrasformazioneRisposteList.add(rs.getLong("id"));
  622.                     }
  623.                     rs.close();
  624.                     updateStmt.close();
  625.                    
  626.                     if(!idTrasformazioneRisposteList.isEmpty()) {
  627.                        
  628.                         for (Long idTrasformazioneRisposta : idTrasformazioneRisposteList) {
  629.                            
  630.                             sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  631.                             sqlQueryObject.addDeleteTable(tableNameRisposteHeader);
  632.                             sqlQueryObject.addWhereCondition("id_transform_risp=?");
  633.                             sqlQueryObject.setANDLogicOperator(true);
  634.                             updateQuery = sqlQueryObject.createSQLDelete();
  635.                             updateStmt = con.prepareStatement(updateQuery);
  636.                             updateStmt.setLong(1, idTrasformazioneRisposta);
  637.                             updateStmt.executeUpdate();
  638.                             updateStmt.close();
  639.                            
  640.                         }
  641.                        
  642.                     }
  643.                    
  644.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  645.                     sqlQueryObject.addDeleteTable(tableNameRisposte);
  646.                     sqlQueryObject.addWhereCondition(CostantiDB.TRASFORMAZIONI_COLUMN_ID_RIF_TRASFORMAZIONE+"=?");
  647.                     sqlQueryObject.setANDLogicOperator(true);
  648.                     updateQuery = sqlQueryObject.createSQLDelete();
  649.                     updateStmt = con.prepareStatement(updateQuery);
  650.                     updateStmt.setLong(1, idTrasformazione);
  651.                     updateStmt.executeUpdate();
  652.                     updateStmt.close();
  653.                    
  654.                 }
  655.                
  656.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  657.                 sqlQueryObject.addDeleteTable(tableName);
  658.                 sqlQueryObject.addWhereCondition(CostantiDB.PORTA_COLUMN_ID_REF+"=?");
  659.                 sqlQueryObject.setANDLogicOperator(true);
  660.                 updateQuery = sqlQueryObject.createSQLDelete();
  661.                 updateStmt = con.prepareStatement(updateQuery);
  662.                 updateStmt.setLong(1, idProprietario);
  663.                 updateStmt.executeUpdate();
  664.                 updateStmt.close();
  665.                
  666.                 break;
  667.                
  668.             default:
  669.                 break;
  670.             }
  671.        
  672.         } catch (SQLException se) {
  673.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB_LIB::CRUDConfigurazioneGenerale] SQLException [" + se.getMessage() + "].",se);
  674.         }catch (Exception se) {
  675.             throw new DriverConfigurazioneException("[DriverConfigurazioneDB_LIB::CRUDConfigurazioneGenerale] Exception [" + se.getMessage() + "].",se);
  676.         } finally {
  677.    
  678.             JDBCUtilities.closeResources(rs, updateStmt);
  679.            
  680.         }
  681.     }
  682.    
  683.     public static Trasformazioni readTrasformazioni(long idPorta, boolean portaDelegata, Connection con) throws Exception {
  684.        
  685.         PreparedStatement stm = null;
  686.         ResultSet rs = null;
  687.         PreparedStatement stm1 = null;
  688.         ResultSet rs1 = null;
  689.         Trasformazioni trasformazioni = null;
  690.         try {
  691.            
  692.             String nomeTabella = portaDelegata ? CostantiDB.PORTE_DELEGATE_TRASFORMAZIONI : CostantiDB.PORTE_APPLICATIVE_TRASFORMAZIONI;
  693.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  694.             sqlQueryObject.addFromTable(nomeTabella);
  695.             sqlQueryObject.addSelectField("*");
  696.             sqlQueryObject.addWhereCondition(CostantiDB.PORTA_COLUMN_ID_REF+"=?");
  697.             sqlQueryObject.addOrderBy(CostantiDB.TRASFORMAZIONI_COLUMN_POSIZIONE);
  698.             sqlQueryObject.addOrderBy("nome");
  699.             sqlQueryObject.setSortType(true);
  700.             String sqlQuery = sqlQueryObject.createSQLQuery();
  701.             stm = con.prepareStatement(sqlQuery);
  702.             stm.setLong(1, idPorta);
  703.    
  704.             DriverConfigurazioneDBLib.logDebug(ESEGUO_QUERY_PREFIX + DBUtils.formatSQLString(sqlQuery, idPorta));
  705.             rs = stm.executeQuery();
  706.    
  707.             while (rs.next()) {
  708.                
  709.                 if(trasformazioni==null) {
  710.                     trasformazioni = new Trasformazioni();
  711.                 }
  712.                
  713.                 TrasformazioneRegola regola = new TrasformazioneRegola();
  714.                
  715.                 String nome = rs.getString("nome");
  716.                 regola.setNome(nome);
  717.                
  718.                 int posizione = rs.getInt(CostantiDB.TRASFORMAZIONI_COLUMN_POSIZIONE);
  719.                 regola.setPosizione(posizione);
  720.                
  721.                 StatoFunzionalita stato = DriverConfigurazioneDBLib.getEnumStatoFunzionalita(rs.getString("stato"));
  722.                 regola.setStato(stato);
  723.                
  724.                 String applicabilitaAzioni = rs.getString("applicabilita_azioni");
  725.                 String applicabilitaCT = rs.getString(CostantiDB.TRASFORMAZIONI_COLUMN_APPLICABILITA_CT);
  726.                 String applicabilitaPattern = rs.getString(CostantiDB.TRASFORMAZIONI_COLUMN_APPLICABILITA_PATTERN);
  727.                 String applicabilitaConnettori = rs.getString("applicabilita_connettori");
  728.                 if( (applicabilitaAzioni!=null && !"".equals(applicabilitaAzioni)) ||
  729.                         (applicabilitaCT!=null && !"".equals(applicabilitaCT)) ||
  730.                         (applicabilitaPattern!=null && !"".equals(applicabilitaPattern))  ||
  731.                         (applicabilitaConnettori!=null && !"".equals(applicabilitaConnettori))
  732.                         ) {
  733.                     TrasformazioneRegolaApplicabilitaRichiesta applicabilita = new TrasformazioneRegolaApplicabilitaRichiesta();
  734.                    
  735.                     if( (applicabilitaAzioni!=null && !"".equals(applicabilitaAzioni)) ) {
  736.                         if(applicabilitaAzioni.contains(",")) {
  737.                             String [] tmp = applicabilitaAzioni.split(",");
  738.                             for (int i = 0; i < tmp.length; i++) {
  739.                                 applicabilita.addAzione(tmp[i].trim());
  740.                             }
  741.                         }
  742.                         else {
  743.                             applicabilita.addAzione(applicabilitaAzioni);
  744.                         }
  745.                     }
  746.                    
  747.                     if( (applicabilitaCT!=null && !"".equals(applicabilitaCT)) ) {
  748.                         if(applicabilitaCT.contains(",")) {
  749.                             String [] tmp = applicabilitaCT.split(",");
  750.                             for (int i = 0; i < tmp.length; i++) {
  751.                                 applicabilita.addContentType(tmp[i].trim());
  752.                             }
  753.                         }
  754.                         else {
  755.                             applicabilita.addContentType(applicabilitaCT);
  756.                         }
  757.                     }
  758.                    
  759.                     if(applicabilitaPattern!=null && !"".equals(applicabilitaPattern)){
  760.                         applicabilita.setPattern(applicabilitaPattern);
  761.                     }
  762.                    
  763.                     if( (applicabilitaConnettori!=null && !"".equals(applicabilitaConnettori)) ) {
  764.                         if(applicabilitaConnettori.contains(",")) {
  765.                             String [] tmp = applicabilitaConnettori.split(",");
  766.                             for (int i = 0; i < tmp.length; i++) {
  767.                                 applicabilita.addConnettore(tmp[i].trim());
  768.                             }
  769.                         }
  770.                         else {
  771.                             applicabilita.addConnettore(applicabilitaConnettori);
  772.                         }
  773.                     }
  774.                    
  775.                     regola.setApplicabilita(applicabilita);
  776.                 }
  777.                
  778.                 TrasformazioneRegolaRichiesta richiesta = new TrasformazioneRegolaRichiesta();
  779.                
  780.                 int reqConversioneEnabled = rs.getInt("req_conversione_enabled");
  781.                 richiesta.setConversione(CostantiDB.TRUE == reqConversioneEnabled);

  782.                 richiesta.setConversioneTipo(rs.getString("req_conversione_tipo"));
  783.                 IJDBCAdapter jdbcAdapter = JDBCAdapterFactory.createJDBCAdapter(DriverConfigurazioneDBLib.tipoDB);
  784.                 richiesta.setConversioneTemplate(jdbcAdapter.getBinaryData(rs, "req_conversione_template"));
  785.                 richiesta.setContentType(rs.getString("req_content_type"));
  786.                
  787.                 int trasformazioneRestIntValue = rs.getInt("rest_transformation");
  788.                 if(CostantiDB.TRUE == trasformazioneRestIntValue) {
  789.                     TrasformazioneRest trasformazioneRest = new TrasformazioneRest();
  790.                     trasformazioneRest.setMetodo(rs.getString("rest_method"));
  791.                     trasformazioneRest.setPath(rs.getString("rest_path"));
  792.                     richiesta.setTrasformazioneRest(trasformazioneRest);
  793.                 }
  794.                    
  795.                 int trasformazioneSoapIntValue = rs.getInt("soap_transformation");
  796.                 if(CostantiDB.TRUE == trasformazioneSoapIntValue) {
  797.                     TrasformazioneSoap trasformazioneSoap = new TrasformazioneSoap();
  798.                    
  799.                     trasformazioneSoap.setVersione(DriverConfigurazioneDBLib.getEnumVersioneSOAP(rs.getString("soap_version")));
  800.                     trasformazioneSoap.setSoapAction(rs.getString("soap_action"));
  801.                    
  802.                     int envelope = rs.getInt(CostantiDB.TRASFORMAZIONI_COLUMN_SOAP_ENVELOPE);
  803.                     trasformazioneSoap.setEnvelope(CostantiDB.TRUE == envelope);
  804.                    
  805.                     int envelopeAsAttach = rs.getInt(CostantiDB.TRASFORMAZIONI_COLUMN_SOAP_ENVELOPE_AS_ATTACH);
  806.                     if(CostantiDB.TRUE == envelopeAsAttach) {
  807.                         trasformazioneSoap.setEnvelopeAsAttachment(true);
  808.                        
  809.                         trasformazioneSoap.setEnvelopeBodyConversioneTipo(rs.getString(CostantiDB.TRASFORMAZIONI_COLUMN_SOAP_ENVELOPE_TIPO));
  810.                         trasformazioneSoap.setEnvelopeBodyConversioneTemplate(jdbcAdapter.getBinaryData(rs, CostantiDB.TRASFORMAZIONI_COLUMN_SOAP_ENVELOPE_TEMPLATE));
  811.                     }
  812.                     else {
  813.                         trasformazioneSoap.setEnvelopeAsAttachment(false);
  814.                     }
  815.                    
  816.                     richiesta.setTrasformazioneSoap(trasformazioneSoap);
  817.                 }
  818.                
  819.                 regola.setId(rs.getLong("id"));
  820.                
  821.                 regola.setRichiesta(richiesta);
  822.                
  823.                 trasformazioni.addRegola(regola);
  824.                
  825.             }
  826.             rs.close();
  827.             stm.close();
  828.            
  829.             if(trasformazioni==null) {
  830.                 return trasformazioni;
  831.             }
  832.            
  833.             for (TrasformazioneRegola regola : trasformazioni.getRegolaList()) {
  834.                

  835.                 // ** SOGGETTI **
  836.                
  837.                 if(!portaDelegata) {
  838.                    
  839.                     nomeTabella = CostantiDB.PORTE_APPLICATIVE_TRASFORMAZIONI_SOGGETTI;
  840.                    
  841.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  842.                     sqlQueryObject.addFromTable(nomeTabella);
  843.                     sqlQueryObject.addSelectField("*");
  844.                     sqlQueryObject.addWhereCondition(CostantiDB.TRASFORMAZIONI_COLUMN_ID_RIF_TRASFORMAZIONE+"=?");
  845.                     sqlQuery = sqlQueryObject.createSQLQuery();
  846.                     stm = con.prepareStatement(sqlQuery);
  847.                     stm.setLong(1, regola.getId());
  848.                     rs = stm.executeQuery();
  849.    
  850.                     while (rs.next()) {
  851.                        
  852.                         if(regola.getApplicabilita()==null) {
  853.                             regola.setApplicabilita(new TrasformazioneRegolaApplicabilitaRichiesta());
  854.                         }
  855.                        
  856.                         TrasformazioneRegolaApplicabilitaSoggetto soggetto = new TrasformazioneRegolaApplicabilitaSoggetto();
  857.                         soggetto.setTipo(rs.getString(CostantiDB.TRASFORMAZIONI_COLUMN_TIPO_SOGGETTO));
  858.                         soggetto.setNome(rs.getString(CostantiDB.TRASFORMAZIONI_COLUMN_NOME_SOGGETTO));
  859.                        
  860.                         regola.getApplicabilita().addSoggetto(soggetto);
  861.                    
  862.                     }
  863.                     rs.close();
  864.                     stm.close();
  865.                 }
  866.                
  867.                
  868.                 // ** APPLICATIVI **
  869.                
  870.                 nomeTabella = portaDelegata ? CostantiDB.PORTE_DELEGATE_TRASFORMAZIONI_SA : CostantiDB.PORTE_APPLICATIVE_TRASFORMAZIONI_SA;
  871.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  872.                 sqlQueryObject.addFromTable(nomeTabella);
  873.                 sqlQueryObject.addSelectField("*");
  874.                 sqlQueryObject.addWhereCondition(CostantiDB.TRASFORMAZIONI_COLUMN_ID_RIF_TRASFORMAZIONE+"=?");
  875.                 sqlQuery = sqlQueryObject.createSQLQuery();
  876.                 stm = con.prepareStatement(sqlQuery);
  877.                 stm.setLong(1, regola.getId());
  878.                 rs = stm.executeQuery();

  879.                 // per ogni entry
  880.                 // prendo l'id del servizio associato, recupero il nome e
  881.                 // aggiungo
  882.                 // il servizio applicativo alla PortaDelegata da ritornare
  883.                 while (rs.next()) {
  884.                     long idSA = rs.getLong("id_servizio_applicativo");

  885.                     if (idSA != 0) {
  886.                         sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  887.                         sqlQueryObject.addFromTable(CostantiDB.SERVIZI_APPLICATIVI);
  888.                         sqlQueryObject.addFromTable(CostantiDB.SOGGETTI);
  889.                         sqlQueryObject.addSelectField("nome");
  890.                         sqlQueryObject.addSelectField(CostantiDB.SOGGETTI_COLUMN_TIPO_SOGGETTO);
  891.                         sqlQueryObject.addSelectField(CostantiDB.SOGGETTI_COLUMN_NOME_SOGGETTO);
  892.                         sqlQueryObject.addWhereCondition(CostantiDB.SERVIZI_APPLICATIVI+".id=?");
  893.                         sqlQueryObject.addWhereCondition(CostantiDB.SERVIZI_APPLICATIVI+".id_soggetto="+CostantiDB.SOGGETTI+".id");
  894.                         sqlQueryObject.setANDLogicOperator(true);
  895.                         sqlQuery = sqlQueryObject.createSQLQuery();
  896.                         stm1 = con.prepareStatement(sqlQuery);
  897.                         stm1.setLong(1, idSA);

  898.                         DriverConfigurazioneDBLib.logDebug(ESEGUO_QUERY_PREFIX + DBUtils.formatSQLString(sqlQuery, idSA));

  899.                         rs1 = stm1.executeQuery();

  900.                         TrasformazioneRegolaApplicabilitaServizioApplicativo servizioApplicativo = null;
  901.                         if (rs1.next()) {
  902.                             // setto solo il nome come da specifica
  903.                             servizioApplicativo = new TrasformazioneRegolaApplicabilitaServizioApplicativo();
  904.                             servizioApplicativo.setId(idSA);
  905.                             servizioApplicativo.setNome(rs1.getString("nome"));
  906.                             servizioApplicativo.setTipoSoggettoProprietario(rs1.getString(CostantiDB.SOGGETTI_COLUMN_TIPO_SOGGETTO));
  907.                             servizioApplicativo.setNomeSoggettoProprietario(rs1.getString(CostantiDB.SOGGETTI_COLUMN_NOME_SOGGETTO));
  908.                             if(regola.getApplicabilita()==null) {
  909.                                 regola.setApplicabilita(new TrasformazioneRegolaApplicabilitaRichiesta());
  910.                             }
  911.                             regola.getApplicabilita().addServizioApplicativo(servizioApplicativo);
  912.                         }
  913.                         rs1.close();
  914.                         stm1.close();
  915.                     }
  916.                 }
  917.                 rs.close();
  918.                 stm.close();
  919.                
  920.                
  921.                 // ** HEADER **
  922.                
  923.                 nomeTabella = portaDelegata ? CostantiDB.PORTE_DELEGATE_TRASFORMAZIONI_HEADER : CostantiDB.PORTE_APPLICATIVE_TRASFORMAZIONI_HEADER;
  924.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  925.                 sqlQueryObject.addFromTable(nomeTabella);
  926.                 sqlQueryObject.addSelectField("*");
  927.                 sqlQueryObject.addWhereCondition(CostantiDB.TRASFORMAZIONI_COLUMN_ID_RIF_TRASFORMAZIONE+"=?");
  928.                 sqlQuery = sqlQueryObject.createSQLQuery();
  929.                 stm = con.prepareStatement(sqlQuery);
  930.                 stm.setLong(1, regola.getId());
  931.        
  932.                 DriverConfigurazioneDBLib.logDebug(ESEGUO_QUERY_PREFIX + DBUtils.formatSQLString(sqlQuery, idPorta));
  933.                 rs = stm.executeQuery();
  934.        
  935.                 while (rs.next()) {
  936.                     TrasformazioneRegolaParametro parametro = new TrasformazioneRegolaParametro();
  937.                     parametro.setConversioneTipo(DriverConfigurazioneDBLib.getEnumTrasformazioneRegolaParametroTipoAzione(rs.getString("tipo")));
  938.                     parametro.setNome(rs.getString("nome"));
  939.                     parametro.setValore(rs.getString(CostantiDB.TRASFORMAZIONI_COLUMN_VALORE));
  940.                     parametro.setIdentificazioneFallita(DriverConfigurazioneDBLib.getEnumTrasformazioneIdentificazioneRisorsaFallita(rs.getString(CostantiDB.TRASFORMAZIONI_COLUMN_IDENTIFICAZIONE_FALLITA)));
  941.                     parametro.setId(rs.getLong("id"));
  942.                     regola.getRichiesta().addHeader(parametro);
  943.                 }
  944.                
  945.                 rs.close();
  946.                 stm.close();
  947.                
  948.                
  949.                 // ** URL **
  950.                
  951.                 nomeTabella = portaDelegata ? CostantiDB.PORTE_DELEGATE_TRASFORMAZIONI_URL : CostantiDB.PORTE_APPLICATIVE_TRASFORMAZIONI_URL;
  952.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  953.                 sqlQueryObject.addFromTable(nomeTabella);
  954.                 sqlQueryObject.addSelectField("*");
  955.                 sqlQueryObject.addWhereCondition(CostantiDB.TRASFORMAZIONI_COLUMN_ID_RIF_TRASFORMAZIONE+"=?");
  956.                 sqlQuery = sqlQueryObject.createSQLQuery();
  957.                 stm = con.prepareStatement(sqlQuery);
  958.                 stm.setLong(1, regola.getId());
  959.        
  960.                 DriverConfigurazioneDBLib.logDebug(ESEGUO_QUERY_PREFIX + DBUtils.formatSQLString(sqlQuery, idPorta));
  961.                 rs = stm.executeQuery();
  962.        
  963.                 while (rs.next()) {
  964.                     TrasformazioneRegolaParametro parametro = new TrasformazioneRegolaParametro();
  965.                     parametro.setConversioneTipo(DriverConfigurazioneDBLib.getEnumTrasformazioneRegolaParametroTipoAzione(rs.getString("tipo")));
  966.                     parametro.setNome(rs.getString("nome"));
  967.                     parametro.setValore(rs.getString(CostantiDB.TRASFORMAZIONI_COLUMN_VALORE));
  968.                     parametro.setIdentificazioneFallita(DriverConfigurazioneDBLib.getEnumTrasformazioneIdentificazioneRisorsaFallita(rs.getString(CostantiDB.TRASFORMAZIONI_COLUMN_IDENTIFICAZIONE_FALLITA)));
  969.                     parametro.setId(rs.getLong("id"));
  970.                     regola.getRichiesta().addParametroUrl(parametro);
  971.                 }
  972.                
  973.                 rs.close();
  974.                 stm.close();
  975.                
  976.                
  977.                
  978.                 // ** RISPOSTE **
  979.                
  980.                 nomeTabella = portaDelegata ? CostantiDB.PORTE_DELEGATE_TRASFORMAZIONI_RISPOSTE : CostantiDB.PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTE;
  981.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  982.                 sqlQueryObject.addFromTable(nomeTabella);
  983.                 sqlQueryObject.addSelectField("*");
  984.                 sqlQueryObject.addWhereCondition(CostantiDB.TRASFORMAZIONI_COLUMN_ID_RIF_TRASFORMAZIONE+"=?");
  985.                 sqlQueryObject.addOrderBy(CostantiDB.TRASFORMAZIONI_COLUMN_POSIZIONE);
  986.                 sqlQueryObject.addOrderBy("nome");
  987.                 sqlQueryObject.setSortType(true);
  988.                 sqlQuery = sqlQueryObject.createSQLQuery();
  989.                 stm = con.prepareStatement(sqlQuery);
  990.                 stm.setLong(1, regola.getId());
  991.        
  992.                 DriverConfigurazioneDBLib.logDebug(ESEGUO_QUERY_PREFIX + DBUtils.formatSQLString(sqlQuery, idPorta));
  993.                 rs = stm.executeQuery();
  994.        
  995.                 while (rs.next()) {
  996.                
  997.                     TrasformazioneRegolaRisposta risposta = new TrasformazioneRegolaRisposta();
  998.                    
  999.                     String nome = rs.getString("nome");
  1000.                     risposta.setNome(nome);
  1001.                    
  1002.                     int posizione = rs.getInt(CostantiDB.TRASFORMAZIONI_COLUMN_POSIZIONE);
  1003.                     risposta.setPosizione(posizione);
  1004.                    
  1005.                     int applicabilitaStatusMin = rs.getInt("applicabilita_status_min");
  1006.                     int applicabilitaStatusMax = rs.getInt("applicabilita_status_max");
  1007.                     String applicabilitaCT = rs.getString(CostantiDB.TRASFORMAZIONI_COLUMN_APPLICABILITA_CT);
  1008.                     String applicabilitaPattern = rs.getString(CostantiDB.TRASFORMAZIONI_COLUMN_APPLICABILITA_PATTERN);
  1009.                     if( (applicabilitaStatusMin >0 || applicabilitaStatusMax>0) ||
  1010.                             (applicabilitaCT!=null && !"".equals(applicabilitaCT)) ||
  1011.                             (applicabilitaPattern!=null && !"".equals(applicabilitaPattern))
  1012.                             ) {
  1013.                         TrasformazioneRegolaApplicabilitaRisposta applicabilita = new TrasformazioneRegolaApplicabilitaRisposta();
  1014.                        
  1015.                         if(applicabilitaStatusMin>0) {
  1016.                             applicabilita.setReturnCodeMin(applicabilitaStatusMin);
  1017.                         }
  1018.                         if(applicabilitaStatusMax>0) {
  1019.                             applicabilita.setReturnCodeMax(applicabilitaStatusMax);
  1020.                         }

  1021.                         if( (applicabilitaCT!=null && !"".equals(applicabilitaCT)) ) {
  1022.                             if(applicabilitaCT.contains(",")) {
  1023.                                 String [] tmp = applicabilitaCT.split(",");
  1024.                                 for (int i = 0; i < tmp.length; i++) {
  1025.                                     applicabilita.addContentType(tmp[i].trim());
  1026.                                 }
  1027.                             }
  1028.                             else {
  1029.                                 applicabilita.addContentType(applicabilitaCT);
  1030.                             }
  1031.                         }
  1032.                        
  1033.                         if(applicabilitaPattern!=null && !"".equals(applicabilitaPattern)){
  1034.                             applicabilita.setPattern(applicabilitaPattern);
  1035.                         }
  1036.                        
  1037.                         risposta.setApplicabilita(applicabilita);
  1038.                     }
  1039.                    
  1040.                     int conversioneEnabled = rs.getInt("conversione_enabled");
  1041.                     risposta.setConversione(CostantiDB.TRUE == conversioneEnabled);

  1042.                     risposta.setConversioneTipo(rs.getString("conversione_tipo"));
  1043.                     IJDBCAdapter jdbcAdapter = JDBCAdapterFactory.createJDBCAdapter(DriverConfigurazioneDBLib.tipoDB);
  1044.                     risposta.setConversioneTemplate(jdbcAdapter.getBinaryData(rs, "conversione_template"));
  1045.                     risposta.setContentType(rs.getString("content_type"));
  1046.                     risposta.setReturnCode(rs.getString("return_code"));
  1047.                    
  1048.                     if(regola.getRichiesta().getTrasformazioneRest()!=null) { // La risposta deve essere ritrasformata in soap
  1049.                    
  1050.                         TrasformazioneSoapRisposta trasformazioneSoap = new TrasformazioneSoapRisposta();
  1051.                        
  1052.                         int envelope = rs.getInt(CostantiDB.TRASFORMAZIONI_COLUMN_SOAP_ENVELOPE);
  1053.                         trasformazioneSoap.setEnvelope(CostantiDB.TRUE == envelope);
  1054.                        
  1055.                         int envelopeAsAttach = rs.getInt(CostantiDB.TRASFORMAZIONI_COLUMN_SOAP_ENVELOPE_AS_ATTACH);
  1056.                         if(CostantiDB.TRUE == envelopeAsAttach) {
  1057.                             trasformazioneSoap.setEnvelopeAsAttachment(true);
  1058.                            
  1059.                             trasformazioneSoap.setEnvelopeBodyConversioneTipo(rs.getString(CostantiDB.TRASFORMAZIONI_COLUMN_SOAP_ENVELOPE_TIPO));
  1060.                             trasformazioneSoap.setEnvelopeBodyConversioneTemplate(jdbcAdapter.getBinaryData(rs, CostantiDB.TRASFORMAZIONI_COLUMN_SOAP_ENVELOPE_TEMPLATE));
  1061.                         }
  1062.                         else {
  1063.                             trasformazioneSoap.setEnvelopeAsAttachment(false);
  1064.                         }
  1065.                        
  1066.                         risposta.setTrasformazioneSoap(trasformazioneSoap);
  1067.                        
  1068.                     }

  1069.                     risposta.setId(rs.getLong("id"));
  1070.                    
  1071.                     regola.addRisposta(risposta);
  1072.                    
  1073.                 }
  1074.                
  1075.                 rs.close();
  1076.                 stm.close();
  1077.                
  1078.                
  1079.                 // ** HEADER RISPOSTA **
  1080.                
  1081.                 for (TrasformazioneRegolaRisposta risposta : regola.getRispostaList()) {
  1082.                    
  1083.                     nomeTabella = portaDelegata ? CostantiDB.PORTE_DELEGATE_TRASFORMAZIONI_RISPOSTE_HEADER : CostantiDB.PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTE_HEADER;
  1084.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverConfigurazioneDBLib.tipoDB);
  1085.                     sqlQueryObject.addFromTable(nomeTabella);
  1086.                     sqlQueryObject.addSelectField("*");
  1087.                     sqlQueryObject.addWhereCondition("id_transform_risp=?");
  1088.                     sqlQuery = sqlQueryObject.createSQLQuery();
  1089.                     stm = con.prepareStatement(sqlQuery);
  1090.                     stm.setLong(1, risposta.getId());
  1091.            
  1092.                     DriverConfigurazioneDBLib.logDebug(ESEGUO_QUERY_PREFIX + DBUtils.formatSQLString(sqlQuery, idPorta));
  1093.                     rs = stm.executeQuery();
  1094.            
  1095.                     while (rs.next()) {
  1096.                         TrasformazioneRegolaParametro parametro = new TrasformazioneRegolaParametro();
  1097.                         parametro.setConversioneTipo(DriverConfigurazioneDBLib.getEnumTrasformazioneRegolaParametroTipoAzione(rs.getString("tipo")));
  1098.                         parametro.setNome(rs.getString("nome"));
  1099.                         parametro.setValore(rs.getString(CostantiDB.TRASFORMAZIONI_COLUMN_VALORE));
  1100.                         parametro.setIdentificazioneFallita(DriverConfigurazioneDBLib.getEnumTrasformazioneIdentificazioneRisorsaFallita(rs.getString(CostantiDB.TRASFORMAZIONI_COLUMN_IDENTIFICAZIONE_FALLITA)));
  1101.                         parametro.setId(rs.getLong("id"));
  1102.                         risposta.addHeader(parametro);
  1103.                     }
  1104.                    
  1105.                     rs.close();
  1106.                     stm.close();
  1107.                    
  1108.                 }
  1109.             }
  1110.            
  1111.         }finally {
  1112.             JDBCUtilities.closeResources(rs1, stm1);
  1113.             JDBCUtilities.closeResources(rs, stm);
  1114.         }
  1115.        
  1116.         return trasformazioni;
  1117.     }
  1118.    
  1119.    
  1120. }