DriverRegistroServiziDB_accordiSoapLIB.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.registry.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 org.openspcoop2.core.byok.IDriverBYOK;
  29. import org.openspcoop2.core.commons.DBUtils;
  30. import org.openspcoop2.core.constants.CostantiDB;
  31. import org.openspcoop2.core.constants.ProprietariProtocolProperty;
  32. import org.openspcoop2.core.registry.AccordoServizioParteComune;
  33. import org.openspcoop2.core.registry.Azione;
  34. import org.openspcoop2.core.registry.MessagePart;
  35. import org.openspcoop2.core.registry.Operation;
  36. import org.openspcoop2.core.registry.PortType;
  37. import org.openspcoop2.core.registry.constants.CostantiRegistroServizi;
  38. import org.openspcoop2.core.registry.driver.DriverRegistroServiziException;
  39. import org.openspcoop2.core.registry.driver.IDAccordoFactory;
  40. import org.openspcoop2.utils.jdbc.JDBCUtilities;
  41. import org.openspcoop2.utils.sql.ISQLQueryObject;
  42. import org.openspcoop2.utils.sql.SQLObjectFactory;

  43. /**
  44.  * Classe utilizzata per effettuare query ad un registro dei servizi openspcoop
  45.  * formato db.
  46.  *
  47.  *
  48.  * @author Sandra Giangrandi (sandra@link.it)
  49.  * @author Stefano Corallo (corallo@link.it)
  50.  * @author $Author$
  51.  * @version $Rev$, $Date$
  52.  */
  53. public class DriverRegistroServiziDB_accordiSoapLIB {
  54.    
  55.    

  56.     public static long CRUDAzione(int type, AccordoServizioParteComune as,Azione azione, Connection con, long idAccordo, IDriverBYOK driverBYOK) throws DriverRegistroServiziException {
  57.         PreparedStatement updateStmt = null;
  58.         String updateQuery;
  59.         PreparedStatement selectStmt = null;
  60.         String selectQuery = "";
  61.         ResultSet selectRS = null;
  62.         long n = 0;
  63.         if (idAccordo <= 0)
  64.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB_LIB::CRUDAzione] ID Accordo non valido.");

  65.         try {
  66.             switch (type) {
  67.             case CREATE:
  68.                 // create
  69.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverRegistroServiziDB_LIB.tipoDB);
  70.                 sqlQueryObject.addInsertTable(CostantiDB.ACCORDI_AZIONI);
  71.                 sqlQueryObject.addInsertField("id_accordo", "?");
  72.                 sqlQueryObject.addInsertField("nome", "?");
  73.                 sqlQueryObject.addInsertField("profilo_azione", "?");
  74.                 sqlQueryObject.addInsertField("filtro_duplicati", "?");
  75.                 sqlQueryObject.addInsertField("conferma_ricezione", "?");
  76.                 sqlQueryObject.addInsertField("identificativo_collaborazione", "?");
  77.                 sqlQueryObject.addInsertField("id_riferimento_richiesta", "?");
  78.                 sqlQueryObject.addInsertField("consegna_in_ordine", "?");
  79.                 sqlQueryObject.addInsertField("scadenza", "?");
  80.                 sqlQueryObject.addInsertField("profilo_collaborazione", "?");
  81.                 sqlQueryObject.addInsertField("correlata", "?");
  82.                 updateQuery = sqlQueryObject.createSQLInsert();
  83.                 updateStmt = con.prepareStatement(updateQuery);
  84.                 int index = 1;
  85.                 updateStmt.setLong(index++, idAccordo);
  86.                 updateStmt.setString(index++, azione.getNome());
  87.                 updateStmt.setString(index++, azione.getProfAzione());

  88.                 DriverRegistroServiziDB_LIB.log.debug("Aggiungo azione ["+azione.getNome()+"] con profilo ["+azione.getProfAzione()+"]");

  89.                 if(CostantiRegistroServizi.PROFILO_AZIONE_RIDEFINITO.equals(azione.getProfAzione())){
  90.                     DriverRegistroServiziDB_LIB.log.debug("ridefinizione...");
  91.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getFiltroDuplicati()));
  92.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getConfermaRicezione()));
  93.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getIdCollaborazione()));
  94.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getIdRiferimentoRichiesta()));
  95.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getConsegnaInOrdine()));
  96.                     updateStmt.setString(index++, azione.getScadenza());
  97.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getProfiloCollaborazione()));
  98.                 }else{
  99.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getFiltroDuplicati()));
  100.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getConfermaRicezione()));
  101.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getIdCollaborazione()));
  102.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getIdRiferimentoRichiesta()));
  103.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getConsegnaInOrdine()));
  104.                     updateStmt.setString(index++, as.getScadenza());
  105.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getProfiloCollaborazione()));
  106.                 }
  107.                 updateStmt.setString(index++, azione.getCorrelata());

  108.                 DriverRegistroServiziDB_LIB.log.debug("CRUDAzione CREATE :\n"+DriverRegistroServiziDB_LIB.formatSQLString(updateQuery,idAccordo,azione.getNome(),azione.getProfAzione()));
  109.                 n = updateStmt.executeUpdate();

  110.                 DriverRegistroServiziDB_LIB.log.debug("CRUDAzione type = " + type + " row affected =" + n);
  111.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverRegistroServiziDB_LIB.tipoDB);
  112.                 sqlQueryObject.addFromTable(CostantiDB.ACCORDI_AZIONI);
  113.                 sqlQueryObject.addSelectField("id");
  114.                 sqlQueryObject.addWhereCondition("id_accordo = ?");
  115.                 sqlQueryObject.addWhereCondition("nome = ?");
  116.                 sqlQueryObject.setANDLogicOperator(true);
  117.                 selectQuery = sqlQueryObject.createSQLQuery();
  118.                 selectStmt = con.prepareStatement(selectQuery);
  119.                 selectStmt.setLong(1, idAccordo);
  120.                 selectStmt.setString(2, azione.getNome());

  121.                 break;

  122.             case UPDATE:
  123.                 // update
  124.                 //
  125.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverRegistroServiziDB_LIB.tipoDB);
  126.                 sqlQueryObject.addUpdateTable(CostantiDB.ACCORDI_AZIONI);
  127.                 sqlQueryObject.addUpdateField("profilo_azione", "?");
  128.                 sqlQueryObject.addUpdateField("filtro_duplicati", "?");
  129.                 sqlQueryObject.addUpdateField("conferma_ricezione", "?");
  130.                 sqlQueryObject.addUpdateField("identificativo_collaborazione", "?");
  131.                 sqlQueryObject.addUpdateField("id_riferimento_richiesta", "?");
  132.                 sqlQueryObject.addUpdateField("consegna_in_ordine", "?");
  133.                 sqlQueryObject.addUpdateField("scadenza", "?");
  134.                 sqlQueryObject.addUpdateField("profilo_collaborazione", "?");
  135.                 sqlQueryObject.addUpdateField("correlata", "?");
  136.                 sqlQueryObject.addWhereCondition("id_accordo=?");
  137.                 sqlQueryObject.addWhereCondition("nome=?");
  138.                 sqlQueryObject.setANDLogicOperator(true);
  139.                 updateQuery = sqlQueryObject.createSQLUpdate();
  140.                 updateStmt = con.prepareStatement(updateQuery);
  141.                 index = 1;
  142.                 updateStmt.setString(1, azione.getProfAzione());

  143.                 if(CostantiRegistroServizi.PROFILO_AZIONE_RIDEFINITO.equals(azione.getProfAzione())){
  144.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getFiltroDuplicati()));
  145.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getConfermaRicezione()));
  146.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getIdCollaborazione()));
  147.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getIdRiferimentoRichiesta()));
  148.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getConsegnaInOrdine()));
  149.                     updateStmt.setString(index++, azione.getScadenza());
  150.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getProfiloCollaborazione()));
  151.                 }else{
  152.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getFiltroDuplicati()));
  153.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getConfermaRicezione()));
  154.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getIdCollaborazione()));
  155.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getIdRiferimentoRichiesta()));
  156.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getConsegnaInOrdine()));
  157.                     updateStmt.setString(index++, as.getScadenza());
  158.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getProfiloCollaborazione()));
  159.                 }

  160.                 updateStmt.setString(index++, azione.getCorrelata());

  161.                 updateStmt.setLong(index++, idAccordo);
  162.                 updateStmt.setString(index++, azione.getNome());
  163.                 n = updateStmt.executeUpdate();

  164.                 DriverRegistroServiziDB_LIB.log.debug("CRUDAzione type = " + type + " row affected =" + n);
  165.                 // log.debug("CRUDAzione UPDATE :
  166.                 // \n"+formatSQLString(updateQuery,wsdlImplementativoErogatore,wsdlImplementativoFruitore,
  167.                 // idServizio,idSoggettoFruitore,idConnettore));

  168.                 break;

  169.             case DELETE:
  170.                 // delete

  171.                 // ProtocolProperties
  172.                 DriverRegistroServiziDB_LIB.CRUDProtocolProperty(CostantiDB.DELETE, null,
  173.                         azione.getId(), ProprietariProtocolProperty.AZIONE_ACCORDO, con, DriverRegistroServiziDB_LIB.tipoDB, driverBYOK);
  174.                
  175.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverRegistroServiziDB_LIB.tipoDB);
  176.                 sqlQueryObject.addDeleteTable(CostantiDB.ACCORDI_AZIONI);
  177.                 sqlQueryObject.addWhereCondition("id_accordo=?");
  178.                 sqlQueryObject.addWhereCondition("nome=?");
  179.                 sqlQueryObject.setANDLogicOperator(true);
  180.                 String sqlQuery = sqlQueryObject.createSQLDelete();
  181.                 updateStmt = con.prepareStatement(sqlQuery);
  182.                 updateStmt.setLong(1, idAccordo);
  183.                 updateStmt.setString(2, azione.getNome());
  184.                 n=updateStmt.executeUpdate();
  185.                 updateStmt.close();
  186.                 DriverRegistroServiziDB_LIB.log.debug("CRUDAzione type = " + type + " row affected =" + n);
  187.                 // log.debug("CRUDAzione DELETE :
  188.                 // \n"+formatSQLString(updateQuery,idServizio,idSoggettoFruitore,idConnettore));

  189.                 break;
  190.             }



  191.             if (CostantiDB.CREATE == type) {
  192.                 if(selectStmt!=null) {
  193.                     selectRS = selectStmt.executeQuery();
  194.                     if (selectRS.next()) {
  195.    
  196.                         azione.setId(selectRS.getLong("id"));
  197.                        
  198.                         // ProtocolProperties
  199.                         DriverRegistroServiziDB_LIB.CRUDProtocolProperty(type, azione.getProtocolPropertyList(),
  200.                                 azione.getId(), ProprietariProtocolProperty.AZIONE_ACCORDO, con, DriverRegistroServiziDB_LIB.tipoDB, driverBYOK);
  201.                        
  202.                         return azione.getId();
  203.    
  204.                     }
  205.                 }
  206.             }

  207.             return n;

  208.         } catch (SQLException se) {
  209.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB_LIB::CRUDAzione] SQLException : " + se.getMessage(),se);
  210.         } catch (Exception se) {
  211.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB_LIB::CRUDAzione] Exception : " + se.getMessage(),se);
  212.         } finally {
  213.             JDBCUtilities.closeResources(selectRS, selectStmt);
  214.             JDBCUtilities.closeResources(updateStmt);
  215.         }
  216.     }

  217.     public static long CRUDPortType(int type, AccordoServizioParteComune as,PortType pt, Connection con, long idAccordo, IDriverBYOK driverBYOK) throws DriverRegistroServiziException {
  218.         PreparedStatement updateStmt = null;
  219.         String updateQuery;
  220.         PreparedStatement selectStmt = null;
  221.         ResultSet selectRS = null;
  222.         long n = 0;
  223.         if (idAccordo <= 0)
  224.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB_LIB::CRUDPortType] ID Accordo non valido.");

  225.         try {
  226.             switch (type) {
  227.             case CREATE:
  228.                 // create
  229.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverRegistroServiziDB_LIB.tipoDB);
  230.                 sqlQueryObject.addInsertTable(CostantiDB.PORT_TYPE);
  231.                 sqlQueryObject.addInsertField("id_accordo", "?");
  232.                 sqlQueryObject.addInsertField("nome", "?");
  233.                 sqlQueryObject.addInsertField("descrizione", "?");
  234.                 sqlQueryObject.addInsertField("message_type", "?");
  235.                 sqlQueryObject.addInsertField("profilo_pt", "?");
  236.                 sqlQueryObject.addInsertField("filtro_duplicati", "?");
  237.                 sqlQueryObject.addInsertField("conferma_ricezione", "?");
  238.                 sqlQueryObject.addInsertField("identificativo_collaborazione", "?");
  239.                 sqlQueryObject.addInsertField("id_riferimento_richiesta", "?");
  240.                 sqlQueryObject.addInsertField("consegna_in_ordine", "?");
  241.                 sqlQueryObject.addInsertField("scadenza", "?");
  242.                 sqlQueryObject.addInsertField("profilo_collaborazione", "?");
  243.                 sqlQueryObject.addInsertField("soap_style", "?");
  244.                 updateQuery = sqlQueryObject.createSQLInsert();
  245.                 updateStmt = con.prepareStatement(updateQuery);
  246.                 int index = 1;
  247.                 updateStmt.setLong(index++, idAccordo);
  248.                 updateStmt.setString(index++, pt.getNome());
  249.                 updateStmt.setString(index++, pt.getDescrizione());
  250.                 updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getMessageType()));
  251.                 updateStmt.setString(index++, pt.getProfiloPT());

  252.                 DriverRegistroServiziDB_LIB.log.debug("Aggiungo port-type ["+pt.getNome()+"] con profilo ["+pt.getProfiloPT()+"]");

  253.                 if(CostantiRegistroServizi.PROFILO_AZIONE_RIDEFINITO.equals(pt.getProfiloPT())){
  254.                     DriverRegistroServiziDB_LIB.log.debug("ridefinizione...");
  255.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getFiltroDuplicati()));
  256.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getConfermaRicezione()));
  257.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getIdCollaborazione()));
  258.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getIdRiferimentoRichiesta()));
  259.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getConsegnaInOrdine()));
  260.                     updateStmt.setString(index++, pt.getScadenza());
  261.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getProfiloCollaborazione()));
  262.                 }else{
  263.                     if(pt.getFiltroDuplicati()!=null)
  264.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getFiltroDuplicati()));
  265.                     else
  266.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getFiltroDuplicati()));
  267.                     if(pt.getConfermaRicezione()!=null)
  268.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getConfermaRicezione()));
  269.                     else
  270.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getConfermaRicezione()));
  271.                     if(pt.getIdCollaborazione()!=null)
  272.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getIdCollaborazione()));
  273.                     else
  274.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getIdCollaborazione()));
  275.                     if(pt.getIdRiferimentoRichiesta()!=null)
  276.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getIdRiferimentoRichiesta()));
  277.                     else
  278.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getIdRiferimentoRichiesta()));
  279.                     if(pt.getConsegnaInOrdine()!=null)
  280.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getConsegnaInOrdine()));
  281.                     else
  282.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getConsegnaInOrdine()));
  283.                     if(pt.getScadenza()!=null)
  284.                         updateStmt.setString(index++, pt.getScadenza());
  285.                     else
  286.                         updateStmt.setString(index++, as.getScadenza());
  287.                     if(pt.getProfiloCollaborazione()!=null)
  288.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getProfiloCollaborazione()));
  289.                     else
  290.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getProfiloCollaborazione()));
  291.                 }
  292.                 updateStmt.setString(index++,DriverRegistroServiziDB_LIB.getValue(pt.getStyle()));
  293.                 // log.debug("CRUDAzione CREATE :
  294.                 // \n"+formatSQLString(updateQuery,idAccordo,idSoggettoFruitore,idConnettore,wsdlImplementativoErogatore,wsdlImplementativoFruitore));
  295.                 n = updateStmt.executeUpdate();

  296.                 DriverRegistroServiziDB_LIB.log.debug("CRUDPortType type = " + type + " row affected =" + n);

  297.                 break;

  298.             case UPDATE:
  299.                 // update
  300.                 //
  301.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverRegistroServiziDB_LIB.tipoDB);
  302.                 sqlQueryObject.addUpdateTable(CostantiDB.PORT_TYPE);
  303.                 sqlQueryObject.addUpdateField("descrizione", "?");
  304.                 sqlQueryObject.addUpdateField("message_type", "?");
  305.                 sqlQueryObject.addUpdateField("profilo_pt", "?");
  306.                 sqlQueryObject.addUpdateField("filtro_duplicati", "?");
  307.                 sqlQueryObject.addUpdateField("conferma_ricezione", "?");
  308.                 sqlQueryObject.addUpdateField("identificativo_collaborazione", "?");
  309.                 sqlQueryObject.addUpdateField("id_riferimento_richiesta", "?");
  310.                 sqlQueryObject.addUpdateField("consegna_in_ordine", "?");
  311.                 sqlQueryObject.addUpdateField("scadenza", "?");
  312.                 sqlQueryObject.addUpdateField("profilo_collaborazione", "?");
  313.                 sqlQueryObject.addUpdateField("soap_style", "?");
  314.                 sqlQueryObject.addWhereCondition("id_accordo=?");
  315.                 sqlQueryObject.addWhereCondition("nome=?");
  316.                 sqlQueryObject.setANDLogicOperator(true);
  317.                 updateQuery = sqlQueryObject.createSQLUpdate();
  318.                 updateStmt = con.prepareStatement(updateQuery);
  319.                 index = 1;
  320.                 updateStmt.setString(index++, pt.getDescrizione());
  321.                 updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getMessageType()));
  322.                 updateStmt.setString(index++, pt.getProfiloPT());


  323.                 if(CostantiRegistroServizi.PROFILO_AZIONE_RIDEFINITO.equals(pt.getProfiloPT())){
  324.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getFiltroDuplicati()));
  325.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getConfermaRicezione()));
  326.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getIdCollaborazione()));
  327.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getIdRiferimentoRichiesta()));
  328.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getConsegnaInOrdine()));
  329.                     updateStmt.setString(index++, pt.getScadenza());
  330.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getProfiloCollaborazione()));
  331.                 }else{
  332.                     if(pt.getFiltroDuplicati()!=null)
  333.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getFiltroDuplicati()));
  334.                     else
  335.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getFiltroDuplicati()));
  336.                     if(pt.getConfermaRicezione()!=null)
  337.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getConfermaRicezione()));
  338.                     else
  339.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getConfermaRicezione()));
  340.                     if(pt.getIdCollaborazione()!=null)
  341.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getIdCollaborazione()));
  342.                     else
  343.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getIdCollaborazione()));
  344.                     if(pt.getIdRiferimentoRichiesta()!=null)
  345.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getIdRiferimentoRichiesta()));
  346.                     else
  347.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getIdRiferimentoRichiesta()));
  348.                     if(pt.getConsegnaInOrdine()!=null)
  349.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getConsegnaInOrdine()));
  350.                     else
  351.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getConsegnaInOrdine()));
  352.                     if(pt.getScadenza()!=null)
  353.                         updateStmt.setString(index++, pt.getScadenza());
  354.                     else
  355.                         updateStmt.setString(index++, as.getScadenza());
  356.                     if(pt.getProfiloCollaborazione()!=null)
  357.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getProfiloCollaborazione()));
  358.                     else
  359.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getProfiloCollaborazione()));
  360.                 }
  361.                 updateStmt.setString(index++,DriverRegistroServiziDB_LIB.getValue(pt.getStyle()));
  362.                 updateStmt.setLong(index++, idAccordo);
  363.                 updateStmt.setString(index++, pt.getNome());
  364.                 n = updateStmt.executeUpdate();

  365.                 DriverRegistroServiziDB_LIB.log.debug("CRUDPortType type = " + type + " row affected =" + n);
  366.                 // log.debug("CRUDAzione UPDATE :
  367.                 // \n"+formatSQLString(updateQuery,wsdlImplementativoErogatore,wsdlImplementativoFruitore,
  368.                 // idServizio,idSoggettoFruitore,idConnettore));

  369.                 break;

  370.             case DELETE:
  371.                 // delete

  372.                 Long idPT = 0l;
  373.                 if(pt.getId()==null || pt.getId()<=0){
  374.                     idPT = DBUtils.getIdPortType(idAccordo, pt.getNome(), con);
  375.                     if(idPT==null || idPT<=0)
  376.                         throw new Exception("ID del porttype["+pt.getNome()+"] idAccordo["+idAccordo+"] non trovato");
  377.                 }
  378.                 else {
  379.                     idPT = pt.getId();
  380.                 }

  381.                 // Operations
  382.                 for(int i=0;i<pt.sizeAzioneList();i++){
  383.                     DriverRegistroServiziDB_accordiSoapLIB.CRUDAzionePortType(CostantiDB.DELETE, as, pt, pt.getAzione(i), con, idPT, driverBYOK);
  384.                 }

  385.                 // ProtocolProperties
  386.                 DriverRegistroServiziDB_LIB.CRUDProtocolProperty(CostantiDB.DELETE, null,
  387.                         idPT, ProprietariProtocolProperty.PORT_TYPE, con, DriverRegistroServiziDB_LIB.tipoDB, driverBYOK);
  388.                
  389.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverRegistroServiziDB_LIB.tipoDB);
  390.                 sqlQueryObject.addDeleteTable(CostantiDB.PORT_TYPE);
  391.                 sqlQueryObject.addWhereCondition("id_accordo=?");
  392.                 sqlQueryObject.addWhereCondition("nome=?");
  393.                 sqlQueryObject.setANDLogicOperator(true);
  394.                 updateQuery = sqlQueryObject.createSQLDelete();
  395.                 updateStmt = con.prepareStatement(updateQuery);

  396.                 updateStmt.setLong(1, idAccordo);
  397.                 updateStmt.setString(2, pt.getNome());
  398.                 n = updateStmt.executeUpdate();

  399.                 DriverRegistroServiziDB_LIB.log.debug("CRUDPortType type = " + type + " row affected =" + n);
  400.                 // log.debug("CRUDAzione DELETE :
  401.                 // \n"+formatSQLString(updateQuery,idServizio,idSoggettoFruitore,idConnettore));

  402.                 break;
  403.             }



  404.             if ( (CostantiDB.CREATE == type) || (CostantiDB.UPDATE == type)) {
  405.                 Long idPT = DBUtils.getIdPortType(idAccordo, pt.getNome(), con);
  406.                 if(idPT==null || idPT<=0)
  407.                     throw new Exception("ID del porttype["+pt.getNome()+"] idAccordo["+idAccordo+"] non trovato");

  408.                 DriverRegistroServiziDB_LIB.log.debug("ID port type: "+idPT);

  409.                 if ( CostantiDB.UPDATE == type ){
  410.                     n = 0;
  411.                     for(int i=0;i<pt.sizeAzioneList();i++){
  412.                         n += DriverRegistroServiziDB_accordiSoapLIB.CRUDAzionePortType(CostantiDB.DELETE, as, pt, pt.getAzione(i), con, idPT, driverBYOK);
  413.                     }
  414.                    
  415. //                  ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverRegistroServiziDB_LIB.tipoDB);
  416. //                  sqlQueryObject.addDeleteTable(CostantiDB.PORT_TYPE_AZIONI);
  417. //                  sqlQueryObject.addWhereCondition("id_port_type=?");
  418. //                  sqlQueryObject.setANDLogicOperator(true);
  419. //                  String sqlQuery = sqlQueryObject.createSQLDelete();
  420. //                  updateStmt=con.prepareStatement(sqlQuery);
  421. //                  updateStmt.setLong(1, idPT);
  422. //                  n=updateStmt.executeUpdate();
  423. //                  updateStmt.close();
  424.                     DriverRegistroServiziDB_LIB.log.info("Cancellate "+n+" azioni del port type ["+idPT+"] associate all'accordo "+idAccordo);
  425.                 }

  426.                 // Azioni PortType
  427.                 Operation azione = null;
  428.                 for (int i = 0; i < pt.sizeAzioneList(); i++) {
  429.                     azione = pt.getAzione(i);
  430.                     DriverRegistroServiziDB_accordiSoapLIB.CRUDAzionePortType(CostantiDB.CREATE,as,pt, azione, con, idPT, driverBYOK);
  431.                 }
  432.                 DriverRegistroServiziDB_LIB.log.debug("inserite " + pt.sizeAzioneList() + " azioni relative al port type["+pt.getNome()+"] id-porttype["+pt.getId()+"] dell'accordo :" + IDAccordoFactory.getInstance().getUriFromAccordo(as) + " id-accordo :" + idAccordo);
  433.                
  434.                
  435.                 // ProtocolProperties
  436.                 DriverRegistroServiziDB_LIB.CRUDProtocolProperty(type, pt.getProtocolPropertyList(),
  437.                         idPT, ProprietariProtocolProperty.PORT_TYPE, con, DriverRegistroServiziDB_LIB.tipoDB, driverBYOK);
  438.             }


  439.             return n;

  440.         } catch (SQLException se) {
  441.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB_LIB::CRUDPortType] SQLException : " + se.getMessage(),se);
  442.         } catch (Exception se) {
  443.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB_LIB::CRUDPortType] Exception : " + se.getMessage(),se);
  444.         } finally {
  445.             JDBCUtilities.closeResources(selectRS, selectStmt);
  446.             JDBCUtilities.closeResources(updateStmt);
  447.         }
  448.     }

  449.     public static long CRUDAzionePortType(int type, AccordoServizioParteComune as,PortType pt,Operation azione, Connection con, long idPortType, IDriverBYOK driverBYOK) throws DriverRegistroServiziException {
  450.         PreparedStatement updateStmt = null;
  451.         String updateQuery;
  452.         PreparedStatement selectStmt = null;
  453.         String selectQuery = "";
  454.         ResultSet selectRS = null;
  455.         long n = 0;
  456.         if (idPortType <= 0)
  457.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB_LIB::CRUDAzionePortType] ID Port Type non valido.");

  458.         try {
  459.             switch (type) {
  460.             case CREATE:
  461.                 // create
  462.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverRegistroServiziDB_LIB.tipoDB);
  463.                 sqlQueryObject.addInsertTable(CostantiDB.PORT_TYPE_AZIONI);
  464.                 sqlQueryObject.addInsertField("id_port_type", "?");
  465.                 sqlQueryObject.addInsertField("nome", "?");
  466.                 sqlQueryObject.addInsertField("profilo_pt_azione", "?");
  467.                 sqlQueryObject.addInsertField("filtro_duplicati", "?");
  468.                 sqlQueryObject.addInsertField("conferma_ricezione", "?");
  469.                 sqlQueryObject.addInsertField("identificativo_collaborazione", "?");
  470.                 sqlQueryObject.addInsertField("id_riferimento_richiesta", "?");
  471.                 sqlQueryObject.addInsertField("consegna_in_ordine", "?");
  472.                 sqlQueryObject.addInsertField("scadenza", "?");
  473.                 sqlQueryObject.addInsertField("profilo_collaborazione", "?");
  474.                 sqlQueryObject.addInsertField("soap_style", "?");
  475.                 sqlQueryObject.addInsertField("soap_action", "?");
  476.                 sqlQueryObject.addInsertField("soap_use_msg_input", "?");
  477.                 sqlQueryObject.addInsertField("soap_namespace_msg_input", "?");
  478.                 sqlQueryObject.addInsertField("soap_use_msg_output", "?");
  479.                 sqlQueryObject.addInsertField("soap_namespace_msg_output", "?");
  480.                 sqlQueryObject.addInsertField("correlata_servizio", "?");
  481.                 sqlQueryObject.addInsertField("correlata", "?");
  482.                 updateQuery = sqlQueryObject.createSQLInsert();
  483.                 updateStmt = con.prepareStatement(updateQuery);
  484.                 int index = 1;
  485.                 updateStmt.setLong(index++, idPortType);
  486.                 updateStmt.setString(index++, azione.getNome());
  487.                 updateStmt.setString(index++, azione.getProfAzione());

  488.                 DriverRegistroServiziDB_LIB.log.debug("Aggiungo azione ["+azione.getNome()+"] pt ["+pt.getNome()+"] con profilo ["+azione.getProfAzione()+"]");

  489.                 if(CostantiRegistroServizi.PROFILO_AZIONE_RIDEFINITO.equals(azione.getProfAzione())){
  490.                     DriverRegistroServiziDB_LIB.log.debug("ridefinizione...");
  491.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getFiltroDuplicati()));
  492.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getConfermaRicezione()));
  493.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getIdCollaborazione()));
  494.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getIdRiferimentoRichiesta()));
  495.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getConsegnaInOrdine()));
  496.                     updateStmt.setString(index++, azione.getScadenza());
  497.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getProfiloCollaborazione()));
  498.                 }else{
  499.                     if(azione.getFiltroDuplicati()!=null)
  500.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getFiltroDuplicati()));
  501.                     else if(pt.getFiltroDuplicati()!=null)
  502.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getFiltroDuplicati()));
  503.                     else
  504.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getFiltroDuplicati()));

  505.                     if(azione.getConfermaRicezione()!=null)
  506.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getConfermaRicezione()));
  507.                     else if(pt.getConfermaRicezione()!=null)
  508.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getConfermaRicezione()));
  509.                     else
  510.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getConfermaRicezione()));

  511.                     if(azione.getIdCollaborazione()!=null)
  512.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getIdCollaborazione()));
  513.                     else if(pt.getIdCollaborazione()!=null)
  514.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getIdCollaborazione()));
  515.                     else
  516.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getIdCollaborazione()));
  517.                    
  518.                     if(azione.getIdRiferimentoRichiesta()!=null)
  519.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getIdRiferimentoRichiesta()));
  520.                     else if(pt.getIdRiferimentoRichiesta()!=null)
  521.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getIdRiferimentoRichiesta()));
  522.                     else
  523.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getIdRiferimentoRichiesta()));

  524.                     if(azione.getConsegnaInOrdine()!=null)
  525.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getConsegnaInOrdine()));
  526.                     else if(pt.getConsegnaInOrdine()!=null)
  527.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getConsegnaInOrdine()));
  528.                     else
  529.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getConsegnaInOrdine()));

  530.                     if(azione.getScadenza()!=null)
  531.                         updateStmt.setString(index++, azione.getScadenza());
  532.                     else if(pt.getScadenza()!=null)
  533.                         updateStmt.setString(index++, pt.getScadenza());
  534.                     else
  535.                         updateStmt.setString(index++, as.getScadenza());

  536.                     if(azione.getProfiloCollaborazione()!=null)
  537.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getProfiloCollaborazione()));
  538.                     else if(pt.getProfiloCollaborazione()!=null)
  539.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getProfiloCollaborazione()));
  540.                     else
  541.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getProfiloCollaborazione()));
  542.                 }
  543.                 updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getStyle()));
  544.                 updateStmt.setString(index++, azione.getSoapAction());
  545.                 if(azione.getMessageInput()!=null){
  546.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getMessageInput().getUse()));
  547.                     updateStmt.setString(index++, azione.getMessageInput().getSoapNamespace());
  548.                 }else{
  549.                     updateStmt.setString(index++, null);
  550.                     updateStmt.setString(index++, null);
  551.                 }
  552.                 if(azione.getMessageOutput()!=null){
  553.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getMessageOutput().getUse()));
  554.                     updateStmt.setString(index++, azione.getMessageOutput().getSoapNamespace());
  555.                 }else{
  556.                     updateStmt.setString(index++, null);
  557.                     updateStmt.setString(index++, null);
  558.                 }

  559.                 updateStmt.setString(index++, azione.getCorrelataServizio());
  560.                 updateStmt.setString(index++, azione.getCorrelata());

  561.                 DriverRegistroServiziDB_LIB.log.debug("CRUDPortTypeAzione CREATE :\n"+updateQuery);
  562.                 n = updateStmt.executeUpdate();

  563.                 DriverRegistroServiziDB_LIB.log.debug("CRUDAzionePortType type = " + type + " row affected =" + n);
  564.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverRegistroServiziDB_LIB.tipoDB);
  565.                 sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE_AZIONI);
  566.                 sqlQueryObject.addSelectField("id");
  567.                 sqlQueryObject.addWhereCondition("id_port_type = ?");
  568.                 sqlQueryObject.addWhereCondition("nome = ?");
  569.                 sqlQueryObject.setANDLogicOperator(true);
  570.                 selectQuery = sqlQueryObject.createSQLQuery();
  571.                 selectStmt = con.prepareStatement(selectQuery);
  572.                 selectStmt.setLong(1, idPortType);
  573.                 selectStmt.setString(2, azione.getNome());

  574.                 break;

  575.             case UPDATE:
  576.                 // update
  577.                 //
  578.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverRegistroServiziDB_LIB.tipoDB);
  579.                 sqlQueryObject.addUpdateTable(CostantiDB.PORT_TYPE_AZIONI);
  580.                 sqlQueryObject.addUpdateField("profilo_azione", "?");
  581.                 sqlQueryObject.addUpdateField("filtro_duplicati", "?");
  582.                 sqlQueryObject.addUpdateField("conferma_ricezione", "?");
  583.                 sqlQueryObject.addUpdateField("identificativo_collaborazione", "?");
  584.                 sqlQueryObject.addUpdateField("id_riferimento_richiesta", "?");
  585.                 sqlQueryObject.addUpdateField("consegna_in_ordine", "?");
  586.                 sqlQueryObject.addUpdateField("scadenza", "?");
  587.                 sqlQueryObject.addUpdateField("profilo_collaborazione", "?");
  588.                 sqlQueryObject.addUpdateField("soap_style", "?");
  589.                 sqlQueryObject.addUpdateField("soap_action", "?");
  590.                 sqlQueryObject.addUpdateField("soap_use_msg_input", "?");
  591.                 sqlQueryObject.addUpdateField("soap_namespace_msg_input", "?");
  592.                 sqlQueryObject.addUpdateField("soap_use_msg_output", "?");
  593.                 sqlQueryObject.addUpdateField("soap_namespace_msg_output", "?");
  594.                 sqlQueryObject.addUpdateField("correlata_servizio", "?");
  595.                 sqlQueryObject.addUpdateField("correlata", "?");
  596.                 sqlQueryObject.addWhereCondition("id_port_type=?");
  597.                 sqlQueryObject.addWhereCondition("nome=?");
  598.                 sqlQueryObject.setANDLogicOperator(true);
  599.                 updateQuery = sqlQueryObject.createSQLUpdate();
  600.                 updateStmt = con.prepareStatement(updateQuery);
  601.                 index = 1;
  602.                 updateStmt.setString(1, azione.getProfAzione());

  603.                 if(CostantiRegistroServizi.PROFILO_AZIONE_RIDEFINITO.equals(azione.getProfAzione())){
  604.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getFiltroDuplicati()));
  605.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getConfermaRicezione()));
  606.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getIdCollaborazione()));
  607.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getIdRiferimentoRichiesta()));
  608.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getConsegnaInOrdine()));
  609.                     updateStmt.setString(index++, azione.getScadenza());
  610.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getProfiloCollaborazione()));
  611.                 }else{
  612.                     if(azione.getFiltroDuplicati()!=null)
  613.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getFiltroDuplicati()));
  614.                     else if(pt.getFiltroDuplicati()!=null)
  615.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getFiltroDuplicati()));
  616.                     else
  617.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getFiltroDuplicati()));

  618.                     if(azione.getConfermaRicezione()!=null)
  619.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getConfermaRicezione()));
  620.                     else if(pt.getConfermaRicezione()!=null)
  621.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getConfermaRicezione()));
  622.                     else
  623.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getConfermaRicezione()));

  624.                     if(azione.getIdCollaborazione()!=null)
  625.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getIdCollaborazione()));
  626.                     else if(pt.getIdCollaborazione()!=null)
  627.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getIdCollaborazione()));
  628.                     else
  629.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getIdCollaborazione()));
  630.                    
  631.                     if(azione.getIdRiferimentoRichiesta()!=null)
  632.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getIdRiferimentoRichiesta()));
  633.                     else if(pt.getIdRiferimentoRichiesta()!=null)
  634.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getIdRiferimentoRichiesta()));
  635.                     else
  636.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getIdRiferimentoRichiesta()));

  637.                     if(azione.getConsegnaInOrdine()!=null)
  638.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getConsegnaInOrdine()));
  639.                     else if(pt.getConsegnaInOrdine()!=null)
  640.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getConsegnaInOrdine()));
  641.                     else
  642.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getConsegnaInOrdine()));

  643.                     if(azione.getScadenza()!=null)
  644.                         updateStmt.setString(index++, azione.getScadenza());
  645.                     else if(pt.getScadenza()!=null)
  646.                         updateStmt.setString(index++, pt.getScadenza());
  647.                     else
  648.                         updateStmt.setString(index++, as.getScadenza());

  649.                     if(azione.getProfiloCollaborazione()!=null)
  650.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getProfiloCollaborazione()));
  651.                     else if(pt.getProfiloCollaborazione()!=null)
  652.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(pt.getProfiloCollaborazione()));
  653.                     else
  654.                         updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(as.getProfiloCollaborazione()));
  655.                 }
  656.                 updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getStyle()));
  657.                 updateStmt.setString(index++, azione.getSoapAction());
  658.                 if(azione.getMessageInput()!=null){
  659.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getMessageInput().getUse()));
  660.                     updateStmt.setString(index++, azione.getMessageInput().getSoapNamespace());
  661.                 }else{
  662.                     updateStmt.setString(index++, null);
  663.                     updateStmt.setString(index++, null);
  664.                 }
  665.                 if(azione.getMessageOutput()!=null){
  666.                     updateStmt.setString(index++, DriverRegistroServiziDB_LIB.getValue(azione.getMessageOutput().getUse()));
  667.                     updateStmt.setString(index++, azione.getMessageOutput().getSoapNamespace());
  668.                 }else{
  669.                     updateStmt.setString(index++, null);
  670.                     updateStmt.setString(index++, null);
  671.                 }

  672.                 updateStmt.setString(index++, azione.getCorrelataServizio());
  673.                 updateStmt.setString(index++, azione.getCorrelata());

  674.                 updateStmt.setLong(index++, idPortType);
  675.                 updateStmt.setString(index++, azione.getNome());
  676.                 n = updateStmt.executeUpdate();

  677.                 DriverRegistroServiziDB_LIB.log.debug("CRUDAzionePortType type = " + type + " row affected =" + n);
  678.                 // log.debug("CRUDAzione UPDATE :
  679.                 // \n"+formatSQLString(updateQuery,wsdlImplementativoErogatore,wsdlImplementativoFruitore,
  680.                 // idServizio,idSoggettoFruitore,idConnettore));

  681.                 break;

  682.             case DELETE:
  683.                 // delete

  684.                 // message-part
  685.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverRegistroServiziDB_LIB.tipoDB);
  686.                 sqlQueryObject.addDeleteTable(CostantiDB.PORT_TYPE_AZIONI_OPERATION_MESSAGES);
  687.                 sqlQueryObject.addWhereCondition("id_port_type_azione=?");
  688.                 sqlQueryObject.setANDLogicOperator(true);
  689.                 updateQuery = sqlQueryObject.createSQLDelete();
  690.                 DriverRegistroServiziDB_LIB.log.debug("CRUDAzione DELETE MESSAGES:\n"+DriverRegistroServiziDB_LIB.formatSQLString(updateQuery,azione.getId()));
  691.                 updateStmt = con.prepareStatement(updateQuery);
  692.                 updateStmt.setLong(1, azione.getId());
  693.                 n = updateStmt.executeUpdate();
  694.                 updateStmt.close();

  695.                 // ProtocolProperties
  696.                 DriverRegistroServiziDB_LIB.CRUDProtocolProperty(CostantiDB.DELETE, null,
  697.                         azione.getId(), ProprietariProtocolProperty.OPERATION, con, DriverRegistroServiziDB_LIB.tipoDB, driverBYOK);
  698.                
  699.                 // azioni
  700.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverRegistroServiziDB_LIB.tipoDB);
  701.                 sqlQueryObject.addDeleteTable(CostantiDB.PORT_TYPE_AZIONI);
  702.                 sqlQueryObject.addWhereCondition("id_port_type=?");
  703.                 sqlQueryObject.addWhereCondition("nome=?");
  704.                 sqlQueryObject.setANDLogicOperator(true);
  705.                 updateQuery = sqlQueryObject.createSQLDelete();
  706.                 DriverRegistroServiziDB_LIB.log.debug("CRUDAzione DELETE AZIONI:\n"+DriverRegistroServiziDB_LIB.formatSQLString(updateQuery,idPortType,azione.getNome()));
  707.                 updateStmt = con.prepareStatement(updateQuery);
  708.                 updateStmt.setLong(1, idPortType);
  709.                 updateStmt.setString(2, azione.getNome());
  710.                 n = updateStmt.executeUpdate();

  711.                 DriverRegistroServiziDB_LIB.log.debug("CRUDAzionePortType type = " + type + " row affected =" + n);

  712.                 break;
  713.             }



  714.             if (CostantiDB.CREATE == type) {
  715.                 selectRS = selectStmt.executeQuery();
  716.                 if (selectRS.next()) {

  717.                     azione.setId(selectRS.getLong("id"));
  718.                     azione.setIdPortType(idPortType);

  719.                     // creo message-part
  720.                     DriverRegistroServiziDB_accordiSoapLIB.CRUDMessageAzionePortType(CostantiDB.CREATE, azione, con);

  721.                     // ProtocolProperties
  722.                     DriverRegistroServiziDB_LIB.CRUDProtocolProperty(type, azione.getProtocolPropertyList(),
  723.                             azione.getId(), ProprietariProtocolProperty.OPERATION, con, DriverRegistroServiziDB_LIB.tipoDB, driverBYOK);
  724.                    
  725.                     return azione.getId();

  726.                 }
  727.             }

  728.             return n;

  729.         } catch (SQLException se) {
  730.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB_LIB::CRUDAzionePortType] SQLException : " + se.getMessage(),se);
  731.         } catch (Exception se) {
  732.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB_LIB::CRUDAzionePortType] Exception : " + se.getMessage(),se);
  733.         } finally {
  734.             JDBCUtilities.closeResources(selectRS, selectStmt);
  735.             JDBCUtilities.closeResources(updateStmt);
  736.         }
  737.     }


  738.     public static void CRUDMessageAzionePortType(int type, Operation azione, Connection con) throws DriverRegistroServiziException {
  739.         PreparedStatement updateStmt = null;
  740.         String updateQuery;
  741.         PreparedStatement selectStmt = null;
  742.         ResultSet selectRS = null;
  743.         if (azione.getId() <= 0)
  744.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB_LIB::CRUDMessageAzionePortType] ID Operation Port Type non valida.");

  745.         try {
  746.             switch (type) {
  747.             case CREATE:
  748.                 // create
  749.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverRegistroServiziDB_LIB.tipoDB);
  750.                 sqlQueryObject.addInsertTable(CostantiDB.PORT_TYPE_AZIONI_OPERATION_MESSAGES);
  751.                 sqlQueryObject.addInsertField("id_port_type_azione", "?");
  752.                 sqlQueryObject.addInsertField("input_message", "?");
  753.                 sqlQueryObject.addInsertField("name", "?");
  754.                 sqlQueryObject.addInsertField("element_name", "?");
  755.                 sqlQueryObject.addInsertField("element_namespace", "?");
  756.                 sqlQueryObject.addInsertField("type_name", "?");
  757.                 sqlQueryObject.addInsertField("type_namespace", "?");
  758.                 updateQuery = sqlQueryObject.createSQLInsert();


  759.                 // message input
  760.                 if(azione.getMessageInput()!=null){
  761.                     for(int i=0; i<azione.getMessageInput().sizePartList(); i++){
  762.                         updateStmt = con.prepareStatement(updateQuery);
  763.                         MessagePart part = azione.getMessageInput().getPart(i);

  764.                         updateStmt.setLong(1, azione.getId());
  765.                         updateStmt.setInt(2, 1);
  766.                         updateStmt.setString(3, part.getName());
  767.                         updateStmt.setString(4, part.getElementName());
  768.                         updateStmt.setString(5, part.getElementNamespace());
  769.                         updateStmt.setString(6, part.getTypeName());
  770.                         updateStmt.setString(7, part.getTypeNamespace());

  771.                         DriverRegistroServiziDB_LIB.log.debug("Aggiungo part element input  ["+part.getName()+"] per azione ["+azione.getNome()+"]");

  772.                         DriverRegistroServiziDB_LIB.log.debug("CRUDMessageAzionePortType CREATE :\n"+updateQuery);
  773.                         updateStmt.executeUpdate();
  774.                         updateStmt.close();
  775.                     }
  776.                 }

  777.                 // message output
  778.                 if(azione.getMessageOutput()!=null){
  779.                     for(int i=0; i<azione.getMessageOutput().sizePartList(); i++){
  780.                         updateStmt = con.prepareStatement(updateQuery);
  781.                         MessagePart part = azione.getMessageOutput().getPart(i);

  782.                         updateStmt.setLong(1, azione.getId());
  783.                         updateStmt.setInt(2, 0);
  784.                         updateStmt.setString(3, part.getName());
  785.                         updateStmt.setString(4, part.getElementName());
  786.                         updateStmt.setString(5, part.getElementNamespace());
  787.                         updateStmt.setString(6, part.getTypeName());
  788.                         updateStmt.setString(7, part.getTypeNamespace());

  789.                         DriverRegistroServiziDB_LIB.log.debug("Aggiungo part element output ["+part.getName()+"] per azione ["+azione.getNome()+"]");

  790.                         DriverRegistroServiziDB_LIB.log.debug("CRUDMessageAzionePortType CREATE :\n"+updateQuery);
  791.                         updateStmt.executeUpdate();
  792.                         updateStmt.close();
  793.                     }
  794.                 }

  795.                 break;

  796.             case UPDATE:
  797.                 // update
  798.                 //
  799.                 throw new Exception("Non implementato");

  800.             case DELETE:
  801.                 // delete

  802.                 sqlQueryObject = SQLObjectFactory.createSQLQueryObject(DriverRegistroServiziDB_LIB.tipoDB);
  803.                 sqlQueryObject.addDeleteTable(CostantiDB.PORT_TYPE_AZIONI_OPERATION_MESSAGES);
  804.                 sqlQueryObject.addWhereCondition("id_port_type_azione=?");
  805.                 sqlQueryObject.setANDLogicOperator(true);
  806.                 updateQuery = sqlQueryObject.createSQLDelete();
  807.                 updateStmt = con.prepareStatement(updateQuery);

  808.                 updateStmt.setLong(1, azione.getId());
  809.                 long n = updateStmt.executeUpdate();
  810.                 updateStmt.close();

  811.                 DriverRegistroServiziDB_LIB.log.debug("CRUDMessageAzionePortType type = " + type + " row affected =" + n);
  812.                 // log.debug("CRUDAzione DELETE :
  813.                 // \n"+formatSQLString(updateQuery,idServizio,idSoggettoFruitore,idConnettore));

  814.                 break;
  815.             }


  816.         } catch (SQLException se) {
  817.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB_LIB::CRUDMessageAzionePortType] SQLException : " + se.getMessage(),se);
  818.         } catch (Exception se) {
  819.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB_LIB::CRUDMessageAzionePortType] Exception : " + se.getMessage(),se);
  820.         } finally {
  821.             JDBCUtilities.closeResources(selectRS, selectStmt);
  822.             JDBCUtilities.closeResources(updateStmt);
  823.         }
  824.     }

  825.    
  826. }