DriverRegistroServiziDB_accordiSoapDriver.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 java.sql.Connection;
  22. import java.sql.PreparedStatement;
  23. import java.sql.ResultSet;
  24. import java.util.ArrayList;
  25. import java.util.List;

  26. import org.openspcoop2.core.commons.DBUtils;
  27. import org.openspcoop2.core.commons.ISearch;
  28. import org.openspcoop2.core.commons.Liste;
  29. import org.openspcoop2.core.constants.CostantiDB;
  30. import org.openspcoop2.core.constants.ProprietariProtocolProperty;
  31. import org.openspcoop2.core.id.IDPortType;
  32. import org.openspcoop2.core.id.IDServizio;
  33. import org.openspcoop2.core.id.IDSoggetto;
  34. import org.openspcoop2.core.registry.AccordoServizioParteComune;
  35. import org.openspcoop2.core.registry.Azione;
  36. import org.openspcoop2.core.registry.Message;
  37. import org.openspcoop2.core.registry.MessagePart;
  38. import org.openspcoop2.core.registry.Operation;
  39. import org.openspcoop2.core.registry.PortType;
  40. import org.openspcoop2.core.registry.ProtocolProperty;
  41. import org.openspcoop2.core.registry.constants.CostantiRegistroServizi;
  42. import org.openspcoop2.core.registry.driver.DriverRegistroServiziException;
  43. import org.openspcoop2.core.registry.driver.DriverRegistroServiziNotFound;
  44. import org.openspcoop2.utils.date.DateManager;
  45. import org.openspcoop2.utils.jdbc.JDBCUtilities;
  46. import org.openspcoop2.utils.sql.ISQLQueryObject;
  47. import org.openspcoop2.utils.sql.SQLObjectFactory;

  48. /**
  49.  * DriverRegistroServiziDB_accordiDriver
  50.  *
  51.  *
  52.  * @author Sandra Giangrandi (sandra@link.it)
  53.  * @author Stefano Corallo (corallo@link.it)
  54.  * @author $Author$
  55.  * @version $Rev$, $Date$
  56.  */
  57. public class DriverRegistroServiziDB_accordiSoapDriver {

  58.     private DriverRegistroServiziDB driver = null;
  59.    
  60.     protected DriverRegistroServiziDB_accordiSoapDriver(DriverRegistroServiziDB driver) {
  61.         this.driver = driver;
  62.     }
  63.    
  64.     protected void readPortTypes(AccordoServizioParteComune as,Connection conParam) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{
  65.         // Aggiungo port type

  66.         Connection con = null;
  67.         PreparedStatement stm = null;
  68.         ResultSet rs = null;
  69.         String sqlQuery = null;

  70.         try {
  71.             this.driver.logDebug("operazione atomica = " + this.driver.atomica);
  72.             // prendo la connessione dal pool
  73.             if(conParam!=null)
  74.                 con = conParam;
  75.             else if (this.driver.atomica)
  76.                 con = this.driver.getConnectionFromDatasource("readPortTypes");
  77.             else
  78.                 con = this.driver.globalConnection;

  79.             if(as.getId()==null || as.getId()<=0)
  80.                 throw new Exception("Accordo id non definito");

  81.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  82.             sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE);
  83.             sqlQueryObject.addSelectField("*");
  84.             sqlQueryObject.addWhereCondition("id_accordo = ?");
  85.             sqlQueryObject.setANDLogicOperator(true);
  86.             sqlQueryObject.addOrderBy("nome");
  87.             sqlQueryObject.setSortType(true);
  88.             sqlQuery = sqlQueryObject.createSQLQuery();
  89.             stm = con.prepareStatement(sqlQuery);
  90.             stm.setLong(1, as.getId());

  91.             this.driver.logDebug("eseguo query : " + DriverRegistroServiziDB_LIB.formatSQLString(sqlQuery, as.getId()));
  92.             rs = stm.executeQuery();

  93.             while (rs.next()) {

  94.                 PortType pt = new PortType();

  95.                 String tmp = rs.getString("nome");
  96.                 pt.setNome(((tmp == null || tmp.equals("")) ? null : tmp));

  97.                 tmp = rs.getString("descrizione");
  98.                 pt.setDescrizione(((tmp == null || tmp.equals("")) ? null : tmp));

  99.                 tmp = rs.getString("profilo_collaborazione");
  100.                 pt.setProfiloCollaborazione(DriverRegistroServiziDB_LIB.getEnumProfiloCollaborazione(((tmp == null || tmp.equals("")) ? null : tmp)));

  101.                 tmp = rs.getString("filtro_duplicati");
  102.                 pt.setFiltroDuplicati(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(((tmp == null || tmp.equals("")) ? null : tmp)));

  103.                 tmp = rs.getString("conferma_ricezione");
  104.                 pt.setConfermaRicezione(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(((tmp == null || tmp.equals("")) ? null : tmp)));

  105.                 tmp = rs.getString("identificativo_collaborazione");
  106.                 pt.setIdCollaborazione(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(((tmp == null || tmp.equals("")) ? null : tmp)));

  107.                 tmp = rs.getString("id_riferimento_richiesta");
  108.                 pt.setIdRiferimentoRichiesta(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(((tmp == null || tmp.equals("")) ? null : tmp)));
  109.                
  110.                 tmp = rs.getString("consegna_in_ordine");
  111.                 pt.setConsegnaInOrdine(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(((tmp == null || tmp.equals("")) ? null : tmp)));

  112.                 tmp = rs.getString("scadenza");
  113.                 pt.setScadenza(((tmp == null || tmp.equals("")) ? null : tmp));

  114.                 tmp = rs.getString("profilo_pt");
  115.                 if (tmp == null || tmp.equals(""))
  116.                     pt.setProfiloPT(CostantiRegistroServizi.PROFILO_AZIONE_DEFAULT);
  117.                 else
  118.                     pt.setProfiloPT(tmp);

  119.                 tmp = rs.getString("soap_style");
  120.                 pt.setStyle(DriverRegistroServiziDB_LIB.getEnumBindingStyle(((tmp == null || tmp.equals("")) ? null : tmp)));

  121.                 tmp = rs.getString("message_type");
  122.                 pt.setMessageType(DriverRegistroServiziDB_LIB.getEnumMessageType((tmp == null || tmp.equals("")) ? null : tmp));
  123.                
  124.                 pt.setIdAccordo(as.getId());

  125.                 long idPortType = rs.getLong("id");
  126.                 pt.setId(idPortType);

  127.                 // Aggiungo azioni a port type
  128.                 this.readAzioniPortTypes(pt,con);

  129.                 // Protocol Properties
  130.                 try{
  131.                     List<ProtocolProperty> listPP = DriverRegistroServiziDB_LIB.getListaProtocolProperty(idPortType, ProprietariProtocolProperty.PORT_TYPE, con,
  132.                             this.driver.tipoDB, this.driver.getDriverUnwrapBYOK());
  133.                     if(listPP!=null && !listPP.isEmpty()){
  134.                         for (ProtocolProperty protocolProperty : listPP) {
  135.                             pt.addProtocolProperty(protocolProperty);
  136.                         }
  137.                     }
  138.                 }catch(DriverRegistroServiziNotFound dNotFound){
  139.                     // ignore
  140.                 }
  141.                
  142.                 as.addPortType(pt);

  143.             }
  144.             rs.close();
  145.             stm.close();

  146.         }catch (DriverRegistroServiziNotFound e) {
  147.             throw e;
  148.         }catch (Exception se) {
  149.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB::readPortTypes] Exception :" + se.getMessage(),se);
  150.         } finally {

  151.             JDBCUtilities.closeResources(rs, stm);

  152.             this.driver.closeConnection(conParam, con);

  153.         }
  154.     }

  155.     private void readAzioniPortTypes(PortType pt,Connection conParam) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{
  156.         // Aggiungo port type

  157.         Connection con = null;
  158.         PreparedStatement stm = null;
  159.         ResultSet rs = null;
  160.         String sqlQuery = null;

  161.         try {
  162.             this.driver.logDebug("operazione atomica = " + this.driver.atomica);
  163.             // prendo la connessione dal pool
  164.             if(conParam!=null)
  165.                 con = conParam;
  166.             else if (this.driver.atomica)
  167.                 con = this.driver.getConnectionFromDatasource("readAzioniPortTypes");
  168.             else
  169.                 con = this.driver.globalConnection;

  170.             if(pt.getId()==null || pt.getId()<=0)
  171.                 throw new Exception("Port Type id non definito");

  172.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  173.             sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE_AZIONI);
  174.             sqlQueryObject.addSelectField("*");
  175.             sqlQueryObject.addWhereCondition("id_port_type = ?");
  176.             sqlQueryObject.setANDLogicOperator(true);
  177.             sqlQueryObject.addOrderBy("nome");
  178.             sqlQueryObject.setSortType(true);
  179.             sqlQuery = sqlQueryObject.createSQLQuery();
  180.             stm = con.prepareStatement(sqlQuery);
  181.             stm.setLong(1, pt.getId());

  182.             this.driver.logDebug("eseguo query : " + DriverRegistroServiziDB_LIB.formatSQLString(sqlQuery, pt.getId()));

  183.             rs = stm.executeQuery();

  184.             org.openspcoop2.core.registry.Operation azionePT = null;
  185.             while (rs.next()) {

  186.                 azionePT = new org.openspcoop2.core.registry.Operation();

  187.                 String tmp = rs.getString("conferma_ricezione");
  188.                 azionePT.setConfermaRicezione(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(((tmp == null || tmp.equals("")) ? null : tmp)));

  189.                 tmp = rs.getString("consegna_in_ordine");
  190.                 azionePT.setConsegnaInOrdine(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(((tmp == null || tmp.equals("")) ? null : tmp)));

  191.                 tmp = rs.getString("filtro_duplicati");
  192.                 azionePT.setFiltroDuplicati(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(((tmp == null || tmp.equals("")) ? null : tmp)));

  193.                 tmp = rs.getString("identificativo_collaborazione");
  194.                 azionePT.setIdCollaborazione(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(((tmp == null || tmp.equals("")) ? null : tmp)));

  195.                 tmp = rs.getString("id_riferimento_richiesta");
  196.                 azionePT.setIdRiferimentoRichiesta(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(((tmp == null || tmp.equals("")) ? null : tmp)));
  197.                
  198.                 tmp = rs.getString("nome");
  199.                 azionePT.setNome(((tmp == null || tmp.equals("")) ? null : tmp));

  200.                 tmp = rs.getString("scadenza");
  201.                 azionePT.setScadenza(((tmp == null || tmp.equals("")) ? null : tmp));

  202.                 tmp = rs.getString("profilo_collaborazione");
  203.                 azionePT.setProfiloCollaborazione(DriverRegistroServiziDB_LIB.getEnumProfiloCollaborazione(((tmp == null || tmp.equals("")) ? null : tmp)));

  204.                 tmp = rs.getString("correlata_servizio");
  205.                 azionePT.setCorrelataServizio(((tmp == null || tmp.equals("")) ? null : tmp));

  206.                 tmp = rs.getString("correlata");
  207.                 azionePT.setCorrelata(((tmp == null || tmp.equals("")) ? null : tmp));

  208.                 tmp = rs.getString("profilo_pt_azione");
  209.                 if (tmp == null || tmp.equals(""))
  210.                     azionePT.setProfAzione(CostantiRegistroServizi.PROFILO_AZIONE_DEFAULT);
  211.                 else
  212.                     azionePT.setProfAzione(tmp);

  213.                 tmp = rs.getString("soap_style");
  214.                 azionePT.setStyle(DriverRegistroServiziDB_LIB.getEnumBindingStyle(((tmp == null || tmp.equals("")) ? null : tmp)));

  215.                 tmp = rs.getString("soap_action");
  216.                 azionePT.setSoapAction(((tmp == null || tmp.equals("")) ? null : tmp));

  217.                 azionePT.setIdPortType(pt.getId());

  218.                 long idAzionePortType = rs.getLong("id");
  219.                 azionePT.setId(idAzionePortType);

  220.                 // Aggiungo messages nell'azione del port type
  221.                 this.readMessagesAzioniPortTypes(azionePT,con);

  222.                 String msgInput = rs.getString("soap_use_msg_input");
  223.                 if(azionePT.getMessageInput()!=null || msgInput!=null){
  224.                     if(azionePT.getMessageInput()==null){
  225.                         azionePT.setMessageInput(new Message());
  226.                     }
  227.                     azionePT.getMessageInput().setUse(DriverRegistroServiziDB_LIB.getEnumBindingUse(((msgInput == null || msgInput.equals("")) ? null : msgInput)));
  228.                     tmp = rs.getString("soap_namespace_msg_input");
  229.                     azionePT.getMessageInput().setSoapNamespace(((tmp == null || tmp.equals("")) ? null : tmp));
  230.                 }

  231.                 String msgOutput = rs.getString("soap_use_msg_output");
  232.                 if(azionePT.getMessageOutput()!=null || msgOutput!=null){
  233.                     if(azionePT.getMessageOutput()==null){
  234.                         azionePT.setMessageOutput(new Message());
  235.                     }
  236.                      
  237.                     azionePT.getMessageOutput().setUse(DriverRegistroServiziDB_LIB.getEnumBindingUse(((msgOutput == null || msgOutput.equals("")) ? null : msgOutput)));
  238.                     tmp = rs.getString("soap_namespace_msg_output");
  239.                     azionePT.getMessageOutput().setSoapNamespace(((tmp == null || tmp.equals("")) ? null : tmp));
  240.                 }

  241.                 // Protocol Properties
  242.                 try{
  243.                     List<ProtocolProperty> listPP = DriverRegistroServiziDB_LIB.getListaProtocolProperty(idAzionePortType, ProprietariProtocolProperty.OPERATION, con,
  244.                             this.driver.tipoDB, this.driver.getDriverUnwrapBYOK());
  245.                     if(listPP!=null && !listPP.isEmpty()){
  246.                         for (ProtocolProperty protocolProperty : listPP) {
  247.                             azionePT.addProtocolProperty(protocolProperty);
  248.                         }
  249.                     }
  250.                 }catch(DriverRegistroServiziNotFound dNotFound){
  251.                     // ignore
  252.                 }
  253.                
  254.                 pt.addAzione(azionePT);

  255.             }
  256.             rs.close();
  257.             stm.close();

  258.         }catch (DriverRegistroServiziNotFound e) {
  259.             throw e;
  260.         }catch (Exception se) {
  261.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB::readAzioniPortTypes] Exception :" + se.getMessage(),se);
  262.         } finally {

  263.             JDBCUtilities.closeResources(rs, stm);

  264.             this.driver.closeConnection(conParam, con);
  265.         }
  266.     }

  267.     private void readMessagesAzioniPortTypes(Operation azionePT,Connection conParam) throws DriverRegistroServiziException,DriverRegistroServiziNotFound{
  268.         // Aggiungo port type

  269.         Connection con = null;
  270.         PreparedStatement stm = null;
  271.         ResultSet rs = null;
  272.         String sqlQuery = null;

  273.         try {
  274.             this.driver.logDebug("operazione atomica = " + this.driver.atomica);
  275.             // prendo la connessione dal pool
  276.             if(conParam!=null)
  277.                 con = conParam;
  278.             else if (this.driver.atomica)
  279.                 con = this.driver.getConnectionFromDatasource("readMessagesAzioniPortTypes");
  280.             else
  281.                 con = this.driver.globalConnection;

  282.             if(azionePT.getId()==null || azionePT.getId()<=0)
  283.                 throw new Exception("Port Type azione id non definito");

  284.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  285.             sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE_AZIONI_OPERATION_MESSAGES);
  286.             sqlQueryObject.addSelectField("*");
  287.             sqlQueryObject.addWhereCondition("id_port_type_azione = ?");
  288.             sqlQueryObject.setANDLogicOperator(true);
  289.             sqlQuery = sqlQueryObject.createSQLQuery();
  290.             stm = con.prepareStatement(sqlQuery);
  291.             stm.setLong(1, azionePT.getId());

  292.             this.driver.logDebug("eseguo query : " + DriverRegistroServiziDB_LIB.formatSQLString(sqlQuery, azionePT.getId()));

  293.             rs = stm.executeQuery();

  294.             org.openspcoop2.core.registry.Message messageInputPart = null;
  295.             org.openspcoop2.core.registry.Message messageOutputPart = null;
  296.             while (rs.next()) {

  297.                 boolean isInputMessage = false;
  298.                 if(rs.getInt("input_message")==1)
  299.                     isInputMessage = true;

  300.                 MessagePart part = new MessagePart();

  301.                 String name = rs.getString("name");
  302.                 name = ((name == null || name.equals("")) ? null : name);
  303.                 part.setName(name);

  304.                 String elementName = rs.getString("element_name");
  305.                 elementName = ((elementName == null || elementName.equals("")) ? null : elementName);
  306.                 part.setElementName(elementName);

  307.                 String elementNamespace = rs.getString("element_namespace");
  308.                 elementNamespace = ((elementNamespace == null || elementNamespace.equals("")) ? null : elementNamespace);
  309.                 part.setElementNamespace(elementNamespace);

  310.                 String typeName = rs.getString("type_name");
  311.                 typeName = ((typeName == null || typeName.equals("")) ? null : typeName);
  312.                 part.setTypeName(typeName);

  313.                 String typeNamespace = rs.getString("type_namespace");
  314.                 typeNamespace = ((typeNamespace == null || typeNamespace.equals("")) ? null : typeNamespace);
  315.                 part.setTypeNamespace(typeNamespace);

  316.                 long idMessage = rs.getLong("id");
  317.                 part.setId(idMessage);

  318.                 if(isInputMessage){

  319.                     if(messageInputPart==null)
  320.                         messageInputPart = new org.openspcoop2.core.registry.Message();
  321.                     messageInputPart.addPart(part);

  322.                 }else{

  323.                     if(messageOutputPart==null)
  324.                         messageOutputPart = new org.openspcoop2.core.registry.Message();
  325.                     messageOutputPart.addPart(part);

  326.                 }

  327.             }

  328.             if(messageInputPart!=null){
  329.                 azionePT.setMessageInput(messageInputPart);
  330.             }
  331.             if(messageOutputPart!=null){
  332.                 azionePT.setMessageOutput(messageOutputPart);
  333.             }

  334.             rs.close();
  335.             stm.close();

  336.         }catch (DriverRegistroServiziNotFound e) {
  337.             throw e;
  338.         }catch (Exception se) {
  339.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB::readMessagesAzioniPortTypes] Exception :" + se.getMessage(),se);
  340.         } finally {

  341.             JDBCUtilities.closeResources(rs, stm);

  342.             this.driver.closeConnection(conParam, con);

  343.         }
  344.     }
  345.    
  346.    
  347.    
  348.     protected PortType getPortType(long id) throws DriverRegistroServiziException {
  349.         String nomeMetodo = "getPortType(long)";

  350.         Connection con = null;
  351.         PreparedStatement stmt = null;
  352.         ResultSet rs = null;
  353.         String queryString;

  354.         if (this.driver.atomica) {
  355.             try {
  356.                 con = this.driver.getConnectionFromDatasource("getPortType");

  357.             } catch (Exception e) {
  358.                 throw new DriverRegistroServiziException("[DriverRegistroServiziDB::" + nomeMetodo + "] Exception accedendo al datasource :" + e.getMessage(), e);

  359.             }

  360.         } else {
  361.             con = this.driver.globalConnection;
  362.         }

  363.         this.driver.logDebug("operazione this.driver.atomica = " + this.driver.atomica);

  364.         try {

  365.             // Controllo che il pdd non sia in uso
  366.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  367.             sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE);
  368.             sqlQueryObject.setANDLogicOperator(true);
  369.             sqlQueryObject.addWhereCondition(CostantiDB.PORT_TYPE+".id=?");
  370.             queryString = sqlQueryObject.createSQLQuery();
  371.             stmt = con.prepareStatement(queryString);
  372.             stmt.setLong(1, id);

  373.             rs = stmt.executeQuery();
  374.             PortType pt = null;
  375.             if (rs.next()) {
  376.                 pt = new PortType();
  377.                 String tmp = rs.getString("nome");
  378.                 pt.setNome(((tmp == null || tmp.equals("")) ? null : tmp));

  379.                 tmp = rs.getString("descrizione");
  380.                 pt.setDescrizione(((tmp == null || tmp.equals("")) ? null : tmp));

  381.                 tmp = rs.getString("profilo_collaborazione");
  382.                 pt.setProfiloCollaborazione(DriverRegistroServiziDB_LIB.getEnumProfiloCollaborazione(((tmp == null || tmp.equals("")) ? null : tmp)));

  383.                 tmp = rs.getString("filtro_duplicati");
  384.                 pt.setFiltroDuplicati(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(((tmp == null || tmp.equals("")) ? null : tmp)));

  385.                 tmp = rs.getString("conferma_ricezione");
  386.                 pt.setConfermaRicezione(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(((tmp == null || tmp.equals("")) ? null : tmp)));

  387.                 tmp = rs.getString("identificativo_collaborazione");
  388.                 pt.setIdCollaborazione(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(((tmp == null || tmp.equals("")) ? null : tmp)));
  389.                
  390.                 tmp = rs.getString("id_riferimento_richiesta");
  391.                 pt.setIdRiferimentoRichiesta(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(((tmp == null || tmp.equals("")) ? null : tmp)));

  392.                 tmp = rs.getString("consegna_in_ordine");
  393.                 pt.setConsegnaInOrdine(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(((tmp == null || tmp.equals("")) ? null : tmp)));

  394.                 tmp = rs.getString("scadenza");
  395.                 pt.setScadenza(((tmp == null || tmp.equals("")) ? null : tmp));

  396.                 tmp = rs.getString("profilo_pt");
  397.                 if (tmp == null || tmp.equals(""))
  398.                     pt.setProfiloPT(CostantiRegistroServizi.PROFILO_AZIONE_DEFAULT);
  399.                 else
  400.                     pt.setProfiloPT(tmp);

  401.                 tmp = rs.getString("soap_style");
  402.                 pt.setStyle(DriverRegistroServiziDB_LIB.getEnumBindingStyle(((tmp == null || tmp.equals("")) ? null : tmp)));

  403.                 pt.setIdAccordo(rs.getLong("id_accordo"));

  404.                 long idPortType = rs.getLong("id");
  405.                 pt.setId(idPortType);

  406.                 // Aggiungo azioni a port type
  407.                 this.readAzioniPortTypes(pt,con);
  408.             }

  409.             return pt;

  410.         } catch (Exception se) {
  411.             throw new DriverRegistroServiziException("[DriverRegistroServiziException::" + nomeMetodo + "] Exception: " + se.getMessage(),se);
  412.         } finally {
  413.             // Chiudo statement and resultset
  414.             JDBCUtilities.closeResources(rs, stmt);
  415.            
  416.             this.driver.closeConnection(con);
  417.         }
  418.     }
  419.    
  420.    
  421.     protected List<PortType> accordiPorttypeCompatibiliList(long idAccordo,boolean isErogazione, ISearch ricerca) throws DriverRegistroServiziException {
  422.         String nomeMetodo = "accordiPorttypeCompatibiliList";
  423.         int idLista = Liste.ACCORDI_PORTTYPE;
  424.         int offset;
  425.         int limit;
  426.         String search;
  427.         String queryString;

  428.         limit = ricerca.getPageSize(idLista);
  429.         offset = ricerca.getIndexIniziale(idLista);
  430.         search = (org.openspcoop2.core.constants.Costanti.SESSION_ATTRIBUTE_VALUE_RICERCA_UNDEFINED.equals(ricerca.getSearchString(idLista)) ? "" : ricerca.getSearchString(idLista));
  431.         ricerca.getSearchString(idLista);

  432.         Connection con = null;
  433.         PreparedStatement stmt = null;
  434.         ResultSet risultato = null;

  435.         ArrayList<PortType> lista = new ArrayList<PortType>();

  436.         if (this.driver.atomica) {
  437.             try {
  438.                 con = this.driver.getConnectionFromDatasource("accordiPorttypeCompatibiliList");

  439.             } catch (Exception e) {
  440.                 throw new DriverRegistroServiziException("[DriverRegistroServiziDB::" + nomeMetodo + "] Exception accedendo al datasource :" + e.getMessage(),e);

  441.             }

  442.         } else
  443.             con = this.driver.globalConnection;

  444.         this.driver.logDebug("operazione this.driver.atomica = " + this.driver.atomica);

  445.         try {

  446.             ISQLQueryObject sqlquery = DriverRegistroServiziDB_accordiLIB.getSQLRicercaServiziValidiByIdAccordo(isErogazione);
  447.             sqlquery.setANDLogicOperator(true);
  448.             if (!search.equals("")) {
  449.                 //query con search
  450.                 sqlquery.addSelectCountField("*", "cont");
  451.                 sqlquery.addWhereLikeCondition("nome", search, true, true);
  452.                 sqlquery.setANDLogicOperator(true);
  453.                 queryString = sqlquery.createSQLQuery();
  454.             } else {
  455.                 sqlquery.addSelectCountField("*", "cont");
  456.                 queryString = sqlquery.createSQLQuery();
  457.             }
  458.             stmt = con.prepareStatement(queryString);
  459.             stmt.setLong(1,idAccordo);
  460.             risultato = stmt.executeQuery();
  461.             if (risultato.next())
  462.                 ricerca.setNumEntries(idLista,risultato.getInt("cont"));
  463.             risultato.close();
  464.             stmt.close();


  465.             //resetto query
  466.             sqlquery = DriverRegistroServiziDB_accordiLIB.getSQLRicercaServiziValidiByIdAccordo(isErogazione);
  467.             sqlquery.setANDLogicOperator(true);
  468.             // ricavo le entries
  469.             if (limit == 0) // con limit
  470.                 limit = ISQLQueryObject.LIMIT_DEFAULT_VALUE;
  471.             if (!search.equals("")) { // con search

  472.                 sqlquery.addSelectField("id_accordo");
  473.                 sqlquery.addSelectField("nome");
  474.                 sqlquery.addSelectField("descrizione");
  475.                 sqlquery.addSelectField("profilo_collaborazione");
  476.                 sqlquery.addSelectField("filtro_duplicati");
  477.                 sqlquery.addSelectField("conferma_ricezione");
  478.                 sqlquery.addSelectField("identificativo_collaborazione");
  479.                 sqlquery.addSelectField("id_riferimento_richiesta");
  480.                 sqlquery.addSelectField("consegna_in_ordine");
  481.                 sqlquery.addSelectField("scadenza");
  482.                 sqlquery.addSelectField("profilo_pt");
  483.                 sqlquery.addSelectField("soap_style");
  484.                 sqlquery.addSelectField("id");

  485.                 sqlquery.addWhereLikeCondition("nome", search, true, true);
  486.                 sqlquery.setANDLogicOperator(true);
  487.                 sqlquery.addOrderBy("nome");
  488.                 sqlquery.setSortType(true);
  489.                 sqlquery.setLimit(limit);
  490.                 sqlquery.setOffset(offset);
  491.                 queryString = sqlquery.createSQLQuery();
  492.             } else {
  493.                 // senza search
  494.                 sqlquery.addSelectField("id_accordo");
  495.                 sqlquery.addSelectField("nome");
  496.                 sqlquery.addSelectField("descrizione");
  497.                 sqlquery.addSelectField("profilo_collaborazione");
  498.                 sqlquery.addSelectField("filtro_duplicati");
  499.                 sqlquery.addSelectField("conferma_ricezione");
  500.                 sqlquery.addSelectField("identificativo_collaborazione");
  501.                 sqlquery.addSelectField("id_riferimento_richiesta");
  502.                 sqlquery.addSelectField("consegna_in_ordine");
  503.                 sqlquery.addSelectField("scadenza");
  504.                 sqlquery.addSelectField("profilo_pt");
  505.                 sqlquery.addSelectField("soap_style");
  506.                 sqlquery.addSelectField("id");

  507.                 sqlquery.addOrderBy("nome");
  508.                 sqlquery.setSortType(true);
  509.                 sqlquery.setLimit(limit);
  510.                 sqlquery.setOffset(offset);
  511.                 queryString = sqlquery.createSQLQuery();
  512.             }
  513.             stmt = con.prepareStatement(queryString);
  514.             stmt.setLong(1, idAccordo);
  515.             risultato = stmt.executeQuery();

  516.             PortType pt;
  517.             while (risultato.next()) {
  518.                 pt = new PortType();

  519.                 String tmp = risultato.getString("nome");
  520.                 pt.setNome(((tmp == null || tmp.equals("")) ? null : tmp));
  521.                 tmp = risultato.getString("descrizione");
  522.                 pt.setDescrizione(((tmp == null || tmp.equals("")) ? null : tmp));
  523.                 tmp = risultato.getString("profilo_collaborazione");
  524.                 pt.setProfiloCollaborazione(DriverRegistroServiziDB_LIB.getEnumProfiloCollaborazione(((tmp == null || tmp.equals("")) ? null : tmp)));
  525.                 tmp = risultato.getString("filtro_duplicati");
  526.                 pt.setFiltroDuplicati(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(((tmp == null || tmp.equals("")) ? null : tmp)));
  527.                 tmp = risultato.getString("conferma_ricezione");
  528.                 pt.setConfermaRicezione(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(((tmp == null || tmp.equals("")) ? null : tmp)));
  529.                 tmp = risultato.getString("identificativo_collaborazione");
  530.                 pt.setIdCollaborazione(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(((tmp == null || tmp.equals("")) ? null : tmp)));
  531.                 tmp = risultato.getString("id_riferimento_richiesta");
  532.                 pt.setIdRiferimentoRichiesta(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(((tmp == null || tmp.equals("")) ? null : tmp)));
  533.                 tmp = risultato.getString("consegna_in_ordine");
  534.                 pt.setConsegnaInOrdine(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(((tmp == null || tmp.equals("")) ? null : tmp)));
  535.                 tmp = risultato.getString("scadenza");
  536.                 pt.setScadenza(((tmp == null || tmp.equals("")) ? null : tmp));
  537.                 tmp = risultato.getString("profilo_pt");
  538.                 if (tmp == null || tmp.equals(""))
  539.                     pt.setProfiloPT(CostantiRegistroServizi.PROFILO_AZIONE_DEFAULT);
  540.                 else
  541.                     pt.setProfiloPT(tmp);
  542.                 tmp = risultato.getString("soap_style");
  543.                 pt.setStyle(DriverRegistroServiziDB_LIB.getEnumBindingStyle(((tmp == null || tmp.equals("")) ? null : tmp)));
  544.                 pt.setIdAccordo(risultato.getLong("id_accordo"));
  545.                 long idPortType = risultato.getLong("id");
  546.                 pt.setId(idPortType);

  547.                 this.readAzioniPortTypes(pt, con);

  548.                 lista.add(pt);              
  549.             }

  550.             return lista;

  551.         } catch (Exception se) {

  552.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB::" + nomeMetodo + "] Exception: " + se.getMessage(),se);
  553.         } finally {
  554.             //Chiudo statement and resultset
  555.             JDBCUtilities.closeResources(risultato, stmt);
  556.            
  557.             this.driver.closeConnection(con);
  558.         }
  559.     }
  560.    
  561.    
  562.     protected void updatePortType(org.openspcoop2.core.registry.PortType portType, String user) throws DriverRegistroServiziException {

  563.         if (portType == null)
  564.             throw new DriverRegistroServiziException("Il port-type non puo' essere null.");

  565.         String nome = portType.getNome();
  566.         if (nome == null || nome.equals(""))
  567.             throw new DriverRegistroServiziException("Il nome del port-type non e' valido.");

  568.         Connection connection = null;
  569.         PreparedStatement stm = null;
  570.         PreparedStatement updateStmt = null;
  571.         ResultSet rs =null;

  572.         boolean error = false;

  573.         if (this.driver.atomica) {
  574.             try {
  575.                 connection = this.driver.getConnectionFromDatasource("updatePortType");
  576.                 connection.setAutoCommit(false);
  577.             } catch (Exception e) {
  578.                 throw new DriverRegistroServiziException("DriverRegistroServiziDB::updatePortType] Exception accedendo al datasource :" + e.getMessage(),e);

  579.             }

  580.         } else
  581.             connection = this.driver.globalConnection;

  582.         this.driver.logDebug("operazione atomica = " + this.driver.atomica);

  583.         try {

  584.             // NOTA: questo metodo viene chiamato solo quando si vogliono aggiornare le azioni

  585.             //Prendo l'accordo per gestire il caso di "usa profilo accordo"
  586.             AccordoServizioParteComune as = this.driver.getAccordoServizioParteComune(portType.getIdAccordo(), connection);

  587.             if(portType.getId()==null || portType.getId()<=0){
  588.                 for (PortType ptCheck : as.getPortTypeList()) {
  589.                     if(ptCheck.getNome().equals(portType.getNome())){
  590.                         portType.setId(ptCheck.getId());
  591.                     }
  592.                 }
  593.             }
  594.             if(portType.getId()==null || portType.getId()<=0){
  595.                 throw new DriverRegistroServiziException("Id PortType undefined");
  596.             }
  597.                        
  598.             List<Long> idsOperation = new ArrayList<>();
  599.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  600.             sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE_AZIONI);
  601.             sqlQueryObject.addWhereCondition("id_port_type=?");
  602.             String queryString = sqlQueryObject.createSQLQuery();
  603.             stm = connection.prepareStatement(queryString);
  604.             stm.setLong(1, portType.getId());
  605.             rs=stm.executeQuery();
  606.             while(rs.next()){
  607.                 idsOperation.add(rs.getLong("id"));
  608.             }
  609.             rs.close();
  610.             stm.close();
  611.            
  612.             if(idsOperation!=null && !idsOperation.isEmpty()){
  613.                 for (Long id : idsOperation) {
  614.                     ISQLQueryObject sqlQueryObjectMessages = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  615.                     sqlQueryObjectMessages.addDeleteTable(CostantiDB.PORT_TYPE_AZIONI_OPERATION_MESSAGES);
  616.                     sqlQueryObjectMessages.addWhereCondition("id_port_type_azione=?");
  617.                     String updateString = sqlQueryObjectMessages.createSQLDelete();
  618.                     stm = connection.prepareStatement(updateString);
  619.                     stm.setLong(1, id);
  620.                     int n=stm.executeUpdate();
  621.                     stm.close();
  622.                     this.driver.logDebug("Cancellate "+n+" operation messages associate all'azione con id "+id+" del port type "+portType.getNome()+ " dell'accordo: "+as.getNome());
  623.                 }
  624.             }
  625.            
  626.             sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  627.             sqlQueryObject.addDeleteTable(CostantiDB.PORT_TYPE_AZIONI);
  628.             sqlQueryObject.addWhereCondition("id_port_type=?");
  629.             String updateString = sqlQueryObject.createSQLDelete();
  630.             stm = connection.prepareStatement(updateString);
  631.             stm.setLong(1, portType.getId());
  632.             int n=stm.executeUpdate();
  633.             stm.close();
  634.             this.driver.logDebug("Cancellate "+n+" azioni associate al portType "+portType.getNome()+ " dell'accordo: "+(as!=null ? as.getNome() : null));
  635.            
  636.             for (int i = 0; i < portType.sizeAzioneList(); i++) {
  637.                 Operation azione = portType.getAzione(i);          
  638.                 DriverRegistroServiziDB_accordiSoapLIB.CRUDAzionePortType(CostantiDB.CREATE,as,portType,azione, connection, portType.getId(),
  639.                         this.driver.getDriverWrapBYOK());
  640.             }
  641.             this.driver.logDebug("inserite " + portType.sizeAzioneList() + " azioni relative al port type["+portType.getNome()+"] id-porttype["+portType.getId()+"]");
  642.            
  643.             if(user!=null && as!=null && as.getId()!=null && as.getId().longValue()>0 ) {
  644.                 ISQLQueryObject sqlQueryObjectUpdate = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  645.                 sqlQueryObjectUpdate.addUpdateTable(CostantiDB.ACCORDI);
  646.                 sqlQueryObjectUpdate.addUpdateField("utente_ultima_modifica", "?");
  647.                 sqlQueryObjectUpdate.addUpdateField("data_ultima_modifica", "?");
  648.                 sqlQueryObjectUpdate.addWhereCondition("id=?");
  649.                 updateString = sqlQueryObjectUpdate.createSQLUpdate();
  650.                 stm = connection.prepareStatement(updateString);
  651.                 int index = 1;
  652.                 stm.setString(index++, user);
  653.                 stm.setTimestamp(index++, DateManager.getTimestamp());
  654.                 stm.setLong(index, as.getId().longValue());
  655.                 n=stm.executeUpdate();
  656.                 stm.close();
  657.                 this.driver.logDebug("Aggiornata "+n+" entry per l'operazione di ultima modifica dell'accordo: "+as.getNome());
  658.             }
  659.         }
  660.         catch (Exception se) {
  661.             this.driver.log.error(se.getMessage(),se);
  662.             error = true;
  663.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB::updatePortType] Exception [" + se.getMessage() + "].",se);
  664.         }finally {
  665.             JDBCUtilities.closeResources(rs, stm);
  666.             JDBCUtilities.closeResources(updateStmt);
  667.             this.driver.closeConnection(error,connection);
  668.         }

  669.     }
  670.    
  671.     protected List<Azione> accordiAzioniList(long idAccordo, ISearch ricerca) throws DriverRegistroServiziException{
  672.         String nomeMetodo = "accordiAzioniList";
  673.         int idLista = Liste.ACCORDI_AZIONI;
  674.         int offset;
  675.         int limit;
  676.         String search;
  677.         String queryString;

  678.         limit = ricerca.getPageSize(idLista);
  679.         offset = ricerca.getIndexIniziale(idLista);
  680.         search = (org.openspcoop2.core.constants.Costanti.SESSION_ATTRIBUTE_VALUE_RICERCA_UNDEFINED.equals(ricerca.getSearchString(idLista)) ? "" : ricerca.getSearchString(idLista));
  681.         ricerca.getSearchString(idLista);

  682.         Connection con = null;
  683.         PreparedStatement stmt = null;
  684.         ResultSet risultato = null;
  685.         ArrayList<Azione> lista = new ArrayList<>();

  686.         if (this.driver.atomica) {
  687.             try {
  688.                 con = this.driver.getConnectionFromDatasource("accordiAzioniList");
  689.             } catch (Exception e) {
  690.                 throw new DriverRegistroServiziException("[DriverRegistroServiziDB::" + nomeMetodo + "] Exception accedendo al datasource :" + e.getMessage(),e);

  691.             }

  692.         } else
  693.             con = this.driver.globalConnection;

  694.         this.driver.logDebug("operazione this.driver.atomica = " + this.driver.atomica);

  695.         try {

  696.             // ricavo il numero di entries totale
  697.             if (!search.equals("")) {
  698.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  699.                 sqlQueryObject.addFromTable(CostantiDB.ACCORDI_AZIONI);
  700.                 sqlQueryObject.addSelectCountField("*", "cont");
  701.                 sqlQueryObject.addWhereCondition("id_accordo = ?");
  702.                 sqlQueryObject.addWhereLikeCondition("nome", search, true, true);
  703.                 sqlQueryObject.setANDLogicOperator(true);
  704.                 queryString = sqlQueryObject.createSQLQuery();
  705.             } else {
  706.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  707.                 sqlQueryObject.addFromTable(CostantiDB.ACCORDI_AZIONI);
  708.                 sqlQueryObject.addSelectCountField("*", "cont");
  709.                 sqlQueryObject.addWhereCondition("id_accordo = ?");
  710.                 queryString = sqlQueryObject.createSQLQuery();
  711.             }
  712.             stmt = con.prepareStatement(queryString);
  713.             stmt.setLong(1, idAccordo);
  714.             risultato = stmt.executeQuery();
  715.             if (risultato.next())
  716.                 ricerca.setNumEntries(idLista,risultato.getInt(1));
  717.             risultato.close();
  718.             stmt.close();

  719.             // ricavo le entries
  720.             if (limit == 0) // con limit
  721.                 limit = ISQLQueryObject.LIMIT_DEFAULT_VALUE;
  722.             if (!search.equals("")) { // con search
  723.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  724.                 sqlQueryObject.addFromTable(CostantiDB.ACCORDI_AZIONI);
  725.                 sqlQueryObject.addSelectAliasField("id","idAzione");
  726.                 sqlQueryObject.addSelectField("nome");
  727.                 sqlQueryObject.addSelectField("conferma_ricezione");
  728.                 sqlQueryObject.addSelectField("consegna_in_ordine");
  729.                 sqlQueryObject.addSelectField("filtro_duplicati");
  730.                 sqlQueryObject.addSelectField("identificativo_collaborazione");
  731.                 sqlQueryObject.addSelectField("id_riferimento_richiesta");
  732.                 sqlQueryObject.addSelectField("scadenza");
  733.                 sqlQueryObject.addSelectField("profilo_collaborazione");
  734.                 sqlQueryObject.addSelectField("profilo_azione");
  735.                 sqlQueryObject.addSelectField("id_accordo");
  736.                 sqlQueryObject.addWhereCondition("id_accordo = ?");
  737.                 sqlQueryObject.addWhereLikeCondition("nome", search, true, true);
  738.                 sqlQueryObject.setANDLogicOperator(true);
  739.                 sqlQueryObject.addOrderBy("nome");
  740.                 sqlQueryObject.setSortType(true);
  741.                 sqlQueryObject.setLimit(limit);
  742.                 sqlQueryObject.setOffset(offset);
  743.                 queryString = sqlQueryObject.createSQLQuery();
  744.             } else {
  745.                 // senza search
  746.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  747.                 sqlQueryObject.addFromTable(CostantiDB.ACCORDI_AZIONI);
  748.                 sqlQueryObject.addSelectAliasField("id","idAzione");
  749.                 sqlQueryObject.addSelectField("nome");
  750.                 sqlQueryObject.addSelectField("conferma_ricezione");
  751.                 sqlQueryObject.addSelectField("consegna_in_ordine");
  752.                 sqlQueryObject.addSelectField("filtro_duplicati");
  753.                 sqlQueryObject.addSelectField("identificativo_collaborazione");
  754.                 sqlQueryObject.addSelectField("id_riferimento_richiesta");
  755.                 sqlQueryObject.addSelectField("scadenza");
  756.                 sqlQueryObject.addSelectField("profilo_collaborazione");
  757.                 sqlQueryObject.addSelectField("profilo_azione");
  758.                 sqlQueryObject.addSelectField("id_accordo");
  759.                 sqlQueryObject.addWhereCondition("id_accordo = ?");
  760.                 sqlQueryObject.addOrderBy("nome");
  761.                 sqlQueryObject.setSortType(true);
  762.                 sqlQueryObject.setLimit(limit);
  763.                 sqlQueryObject.setOffset(offset);
  764.                 queryString = sqlQueryObject.createSQLQuery();
  765.             }

  766.             stmt = con.prepareStatement(queryString);
  767.             stmt.setLong(1, idAccordo);
  768.             risultato = stmt.executeQuery();

  769.             Azione az;
  770.             while (risultato.next()) {

  771.                 az = new Azione();

  772.                 //az.setId(risultato.getLong("id_accordo"));  nn c'e' un id per questo oggetto

  773.                 //fix by stefano: Aggiunto campo idAzione alla query in modo da leggere l'id dell'oggetto azione
  774.                 az.setId(risultato.getLong("idAzione"));
  775.                 az.setNome(risultato.getString("nome"));
  776.                 az.setConfermaRicezione(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(risultato.getString("conferma_ricezione")));
  777.                 az.setConsegnaInOrdine(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(risultato.getString("consegna_in_ordine")));
  778.                 az.setFiltroDuplicati(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(risultato.getString("filtro_duplicati")));
  779.                 az.setIdCollaborazione(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(risultato.getString("identificativo_collaborazione")));
  780.                 az.setIdRiferimentoRichiesta(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(risultato.getString("id_riferimento_richiesta")));
  781.                 az.setScadenza(risultato.getString("scadenza"));
  782.                 az.setProfiloCollaborazione(DriverRegistroServiziDB_LIB.getEnumProfiloCollaborazione(risultato.getString("profilo_collaborazione")));
  783.                 az.setProfAzione(risultato.getString("profilo_azione"));
  784.                 lista.add(az);
  785.             }

  786.             return lista;

  787.         } catch (Exception qe) {
  788.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB::" + nomeMetodo + "] Errore : " + qe.getMessage(),qe);
  789.         } finally {

  790.             //Chiudo statement and resultset
  791.             JDBCUtilities.closeResources(risultato, stmt);

  792.             this.driver.closeConnection(con);
  793.         }
  794.     }

  795.     /**
  796.      * Recupera la lista di azioni dell'Accordo con id idAccordo, con il profilo di collaborazione specificato
  797.      * Il profilo di collaborazione viene ricercato nell'accordo di servizio se l'azione ha profilo di defaul
  798.      * altrimenti viene controllato il profilo di collaborazione dell'azione
  799.      * @param idAccordo
  800.      * @param profiloCollaborazione Opzionale
  801.      * @param ricerca
  802.      * @return Lista di {@link Azione} dell'accordo idAccordo con profilo di collaborazione 'profiloCollaborazione' se specificato altrimenti tutte.
  803.      * @throws DriverRegistroServiziException
  804.      */
  805.     protected List<Azione> accordiAzioniList(long idAccordo,String profiloCollaborazione, ISearch ricerca) throws DriverRegistroServiziException {
  806.         String nomeMetodo = "accordiAzioniList";
  807.         int idLista = Liste.ACCORDI_AZIONI;
  808.         int offset;
  809.         int limit;
  810.         String search;
  811.         String queryString;

  812.         limit = ricerca.getPageSize(idLista);
  813.         offset = ricerca.getIndexIniziale(idLista);
  814.         search = (org.openspcoop2.core.constants.Costanti.SESSION_ATTRIBUTE_VALUE_RICERCA_UNDEFINED.equals(ricerca.getSearchString(idLista)) ? "" : ricerca.getSearchString(idLista));
  815.         ricerca.getSearchString(idLista);

  816.         Connection con = null;
  817.         PreparedStatement stmt = null;
  818.         ResultSet risultato = null;
  819.         ArrayList<Azione> lista = new ArrayList<>();

  820.         if (this.driver.atomica) {
  821.             try {
  822.                 con = this.driver.getConnectionFromDatasource("accordiAzioniList");
  823.             } catch (Exception e) {
  824.                 throw new DriverRegistroServiziException("[DriverRegistroServiziDB::" + nomeMetodo + "] Exception accedendo al datasource :" + e.getMessage(),e);

  825.             }

  826.         } else
  827.             con = this.driver.globalConnection;

  828.         this.driver.logDebug("operazione this.driver.atomica = " + this.driver.atomica);

  829.         try {

  830.             /**
  831.              * SELECT a.id as idAccordo,aa.id,aa.nome
  832.              * from accordi as a, accordi_azioni as aa
  833.              * where a.id=aa.id_accordo
  834.              * and( (aa.profilo_azione='ridefinito' and aa.profilo_collaborazione='asincronoAsimmetrico') or a.profilo_collaborazione='asincronoAsimmetrico')
  835.              * and aa.id_accordo=12;
  836.              */
  837.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  838.             sqlQueryObject.addFromTable(CostantiDB.ACCORDI);
  839.             sqlQueryObject.addFromTable(CostantiDB.ACCORDI_AZIONI);
  840.             sqlQueryObject.addSelectCountField(CostantiDB.ACCORDI_AZIONI+".id", "cont");
  841.             sqlQueryObject.addWhereCondition(CostantiDB.ACCORDI_AZIONI+".id_accordo = "+CostantiDB.ACCORDI+".id");
  842.             sqlQueryObject.addWhereCondition(CostantiDB.ACCORDI_AZIONI+".id_accordo = ?");
  843.             //(aa.profilo_azione='ridefinito' and aa.profilo_collaborazione='asincronoAsimmetrico') or a.profilo_collaborazione='asincronoAsimmetrico')
  844.             sqlQueryObject.addWhereCondition(false,
  845.                     CostantiDB.ACCORDI_AZIONI+".profilo_collaborazione = ? AND "+CostantiDB.ACCORDI_AZIONI+".profilo_azione= ?",
  846.                     CostantiDB.ACCORDI+".profilo_collaborazione=?");
  847.             sqlQueryObject.setANDLogicOperator(true);

  848.             if (!search.equals("")) {
  849.                 sqlQueryObject.addWhereLikeCondition("nome", search, true, true);
  850.             }

  851.             queryString = sqlQueryObject.createSQLQuery();

  852.             stmt = con.prepareStatement(queryString);
  853.             stmt.setLong(1, idAccordo);
  854.             stmt.setString(2, profiloCollaborazione);
  855.             stmt.setString(3, CostantiRegistroServizi.PROFILO_AZIONE_RIDEFINITO);
  856.             stmt.setString(4, profiloCollaborazione);

  857.             risultato = stmt.executeQuery();
  858.             if (risultato.next())
  859.                 ricerca.setNumEntries(idLista,risultato.getInt(1));
  860.             risultato.close();
  861.             stmt.close();

  862.             // ricavo le entries
  863.             if (limit == 0) // con limit
  864.                 limit = ISQLQueryObject.LIMIT_DEFAULT_VALUE;

  865.             sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  866.             sqlQueryObject.addFromTable(CostantiDB.ACCORDI);
  867.             sqlQueryObject.addFromTable(CostantiDB.ACCORDI_AZIONI);

  868.             sqlQueryObject.addSelectField(CostantiDB.ACCORDI_AZIONI,"nome");
  869.             sqlQueryObject.addSelectField(CostantiDB.ACCORDI_AZIONI,"conferma_ricezione");
  870.             sqlQueryObject.addSelectField(CostantiDB.ACCORDI_AZIONI,"consegna_in_ordine");
  871.             sqlQueryObject.addSelectField(CostantiDB.ACCORDI_AZIONI,"filtro_duplicati");
  872.             sqlQueryObject.addSelectField(CostantiDB.ACCORDI_AZIONI,"identificativo_collaborazione");
  873.             sqlQueryObject.addSelectField(CostantiDB.ACCORDI_AZIONI,"id_riferimento_richiesta");
  874.             sqlQueryObject.addSelectField(CostantiDB.ACCORDI_AZIONI,"scadenza");
  875.             sqlQueryObject.addSelectField(CostantiDB.ACCORDI_AZIONI,"profilo_collaborazione");
  876.             sqlQueryObject.addSelectField(CostantiDB.ACCORDI_AZIONI,"profilo_azione");
  877.             sqlQueryObject.addSelectField(CostantiDB.ACCORDI_AZIONI,"id_accordo");
  878.             sqlQueryObject.addSelectField(CostantiDB.ACCORDI_AZIONI,"correlata");
  879.             //where
  880.             sqlQueryObject.addWhereCondition(CostantiDB.ACCORDI_AZIONI+".id_accordo = "+CostantiDB.ACCORDI+".id");
  881.             sqlQueryObject.addWhereCondition(CostantiDB.ACCORDI_AZIONI+".id_accordo = ?");
  882.             //(aa.profilo_azione='ridefinito' and aa.profilo_collaborazione='asincronoAsimmetrico') or a.profilo_collaborazione='asincronoAsimmetrico')
  883.             sqlQueryObject.addWhereCondition(false,
  884.                     CostantiDB.ACCORDI_AZIONI+".profilo_collaborazione = ? AND "+CostantiDB.ACCORDI_AZIONI+".profilo_azione= ?",
  885.                     CostantiDB.ACCORDI+".profilo_collaborazione=?");

  886.             sqlQueryObject.setANDLogicOperator(true);
  887.             sqlQueryObject.setLimit(limit);
  888.             sqlQueryObject.setOffset(offset);

  889.             sqlQueryObject.addOrderBy(CostantiDB.ACCORDI_AZIONI+".nome");

  890.             if (!search.equals("")) {
  891.                 sqlQueryObject.addWhereLikeCondition("nome", search, true, true);
  892.             }

  893.             queryString = sqlQueryObject.createSQLQuery();


  894.             stmt = con.prepareStatement(queryString);
  895.             stmt.setLong(1, idAccordo);
  896.             stmt.setString(2, profiloCollaborazione);
  897.             stmt.setString(3, CostantiRegistroServizi.PROFILO_AZIONE_RIDEFINITO);
  898.             stmt.setString(4, profiloCollaborazione);

  899.             risultato = stmt.executeQuery();

  900.             Azione az;
  901.             while (risultato.next()) {

  902.                 az = new Azione();

  903.                 //az.setId(risultato.getLong("id_accordo"));  nn c'e' un id per questo oggetto

  904.                 az.setNome(risultato.getString("nome"));
  905.                 az.setConfermaRicezione(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(risultato.getString("conferma_ricezione")));
  906.                 az.setConsegnaInOrdine(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(risultato.getString("consegna_in_ordine")));
  907.                 az.setFiltroDuplicati(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(risultato.getString("filtro_duplicati")));
  908.                 az.setIdCollaborazione(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(risultato.getString("identificativo_collaborazione")));
  909.                 az.setIdRiferimentoRichiesta(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(risultato.getString("id_riferimento_richiesta")));
  910.                 az.setScadenza(risultato.getString("scadenza"));
  911.                 az.setProfiloCollaborazione(DriverRegistroServiziDB_LIB.getEnumProfiloCollaborazione(risultato.getString("profilo_collaborazione")));
  912.                 az.setProfAzione(risultato.getString("profilo_azione"));
  913.                 az.setCorrelata(risultato.getString("correlata"));
  914.                 lista.add(az);
  915.             }

  916.             return lista;

  917.         } catch (Exception qe) {
  918.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB::" + nomeMetodo + "] Errore : " + qe.getMessage(),qe);
  919.         } finally {

  920.             //Chiudo statement and resultset
  921.             JDBCUtilities.closeResources(risultato, stmt);

  922.             this.driver.closeConnection(con);
  923.         }
  924.     }
  925.    
  926.     protected void deleteAzione(long idAccordo, String nomeAzione) throws DriverRegistroServiziException {
  927.         String nomeMetodo = "deleteAzione";
  928.         Connection con = null;
  929.         PreparedStatement stmt = null;

  930.         if (this.driver.atomica) {
  931.             try {
  932.                 con = this.driver.getConnectionFromDatasource("deleteAzione");

  933.             } catch (Exception e) {
  934.                 throw new DriverRegistroServiziException("[DriverRegistroServiziDB::" + nomeMetodo + "] Exception accedendo al datasource :" + e.getMessage(),e);

  935.             }

  936.         } else
  937.             con = this.driver.globalConnection;

  938.         this.driver.logDebug("operazione this.driver.atomica = " + this.driver.atomica);

  939.         try {
  940.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  941.             sqlQueryObject.addDeleteTable(CostantiDB.ACCORDI_AZIONI);
  942.             sqlQueryObject.addWhereCondition("id_accordo=?");
  943.             sqlQueryObject.addWhereCondition("nome=?");
  944.             sqlQueryObject.setANDLogicOperator(true);
  945.             String updateString = sqlQueryObject.createSQLDelete();
  946.             stmt = con.prepareStatement(updateString);
  947.             stmt.setLong(1, idAccordo);
  948.             stmt.setString(2, nomeAzione);
  949.             stmt.executeUpdate();
  950.             stmt.close();

  951.         } catch (Exception se) {
  952.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB::" + nomeMetodo + "] Exception: " + se.getMessage(),se);
  953.         } finally {
  954.             //Chiudo statement and resultset
  955.             JDBCUtilities.closeResources(stmt);
  956.            
  957.             this.driver.closeConnection(con);
  958.         }

  959.     }
  960.    
  961.     protected List<PortType> accordiPorttypeList(long idAccordo, ISearch ricerca) throws DriverRegistroServiziException {
  962.         String nomeMetodo = "accordiPorttypeList";
  963.         int idLista = Liste.ACCORDI_PORTTYPE;
  964.         int offset;
  965.         int limit;
  966.         String search;
  967.         String queryString;

  968.         limit = ricerca.getPageSize(idLista);
  969.         offset = ricerca.getIndexIniziale(idLista);
  970.         search = (org.openspcoop2.core.constants.Costanti.SESSION_ATTRIBUTE_VALUE_RICERCA_UNDEFINED.equals(ricerca.getSearchString(idLista)) ? "" : ricerca.getSearchString(idLista));
  971.         ricerca.getSearchString(idLista);

  972.         Connection con = null;
  973.         PreparedStatement stmt = null;
  974.         ResultSet risultato = null;

  975.         ArrayList<PortType> lista = new ArrayList<PortType>();

  976.         if (this.driver.atomica) {
  977.             try {
  978.                 con = this.driver.getConnectionFromDatasource("accordiPorttypeList");

  979.             } catch (Exception e) {
  980.                 throw new DriverRegistroServiziException("[DriverRegistroServiziDB::" + nomeMetodo + "] Exception accedendo al datasource :" + e.getMessage(),e);

  981.             }

  982.         } else
  983.             con = this.driver.globalConnection;

  984.         this.driver.logDebug("operazione this.driver.atomica = " + this.driver.atomica);

  985.         try {

  986.             if (!search.equals("")) {
  987.                 //query con search
  988.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  989.                 sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE);
  990.                 sqlQueryObject.addSelectCountField("*", "cont");
  991.                 sqlQueryObject.addWhereCondition("id_accordo = ?");
  992.                 sqlQueryObject.addWhereLikeCondition("nome", search, true, true);
  993.                 sqlQueryObject.setANDLogicOperator(true);
  994.                 queryString = sqlQueryObject.createSQLQuery();
  995.             } else {
  996.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  997.                 sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE);
  998.                 sqlQueryObject.addSelectCountField("*", "cont");
  999.                 sqlQueryObject.addWhereCondition("id_accordo = ?");
  1000.                 queryString = sqlQueryObject.createSQLQuery();
  1001.             }
  1002.             stmt = con.prepareStatement(queryString);
  1003.             stmt.setLong(1,idAccordo);
  1004.             risultato = stmt.executeQuery();
  1005.             if (risultato.next())
  1006.                 ricerca.setNumEntries(idLista,risultato.getInt("cont"));
  1007.             risultato.close();
  1008.             stmt.close();

  1009.             // ricavo le entries
  1010.             if (limit == 0) // con limit
  1011.                 limit = ISQLQueryObject.LIMIT_DEFAULT_VALUE;
  1012.             if (!search.equals("")) { // con search
  1013.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  1014.                 sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE);
  1015.                 sqlQueryObject.addSelectField("id");
  1016.                 sqlQueryObject.addSelectField("nome");
  1017.                 sqlQueryObject.addWhereCondition("id_accordo = ?");
  1018.                 sqlQueryObject.addWhereLikeCondition("nome", search, true, true);
  1019.                 sqlQueryObject.setANDLogicOperator(true);
  1020.                 sqlQueryObject.addOrderBy("nome");
  1021.                 sqlQueryObject.setSortType(true);
  1022.                 sqlQueryObject.setLimit(limit);
  1023.                 sqlQueryObject.setOffset(offset);
  1024.                 queryString = sqlQueryObject.createSQLQuery();
  1025.             } else {
  1026.                 // senza search
  1027.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  1028.                 sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE);
  1029.                 sqlQueryObject.addSelectField("id");
  1030.                 sqlQueryObject.addSelectField("nome");
  1031.                 sqlQueryObject.addWhereCondition("id_accordo = ?");
  1032.                 sqlQueryObject.addOrderBy("nome");
  1033.                 sqlQueryObject.setSortType(true);
  1034.                 sqlQueryObject.setLimit(limit);
  1035.                 sqlQueryObject.setOffset(offset);
  1036.                 queryString = sqlQueryObject.createSQLQuery();
  1037.             }
  1038.             stmt = con.prepareStatement(queryString);
  1039.             stmt.setLong(1, idAccordo);
  1040.             risultato = stmt.executeQuery();

  1041.             List<Long> listID = new ArrayList<Long>();
  1042.             while (risultato.next()) {
  1043.                
  1044.                 long idPortType = risultato.getLong("id");
  1045.                 listID.add(idPortType);
  1046.             }

  1047.             if(listID.size()>0) {
  1048.                 for (Long idPT : listID) {
  1049.                     lista.add(this.getPortType(idPT));
  1050.                 }
  1051.             }
  1052.            
  1053.             return lista;

  1054.         } catch (Exception se) {

  1055.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB::" + nomeMetodo + "] Exception: " + se.getMessage(),se);
  1056.         } finally {
  1057.             //Chiudo statement and resultset
  1058.             JDBCUtilities.closeResources(risultato, stmt);
  1059.            
  1060.             this.driver.closeConnection(con);
  1061.         }
  1062.     }

  1063.     protected List<PortType> accordiPorttypeList(long idAccordo, String profiloCollaborazione, ISearch ricerca) throws DriverRegistroServiziException {
  1064.         String nomeMetodo = "accordiPorttypeList";
  1065.         int idLista = Liste.ACCORDI_PORTTYPE;
  1066.         int offset;
  1067.         int limit;
  1068.         String search;
  1069.         String queryString;

  1070.         limit = ricerca.getPageSize(idLista);
  1071.         offset = ricerca.getIndexIniziale(idLista);
  1072.         search = (org.openspcoop2.core.constants.Costanti.SESSION_ATTRIBUTE_VALUE_RICERCA_UNDEFINED.equals(ricerca.getSearchString(idLista)) ? "" : ricerca.getSearchString(idLista));
  1073.         ricerca.getSearchString(idLista);

  1074.         Connection con = null;
  1075.         PreparedStatement stmt = null;
  1076.         ResultSet risultato = null;

  1077.         ArrayList<PortType> lista = new ArrayList<PortType>();

  1078.         if (this.driver.atomica) {
  1079.             try {
  1080.                 con = this.driver.getConnectionFromDatasource("accordiPorttypeList");

  1081.             } catch (Exception e) {
  1082.                 throw new DriverRegistroServiziException("[DriverRegistroServiziDB::" + nomeMetodo + "] Exception accedendo al datasource :" + e.getMessage(),e);

  1083.             }

  1084.         } else
  1085.             con = this.driver.globalConnection;

  1086.         this.driver.logDebug("operazione this.driver.atomica = " + this.driver.atomica);

  1087.         try {

  1088.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  1089.             sqlQueryObject.addFromTable(CostantiDB.ACCORDI);
  1090.             sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE);
  1091.             sqlQueryObject.addSelectCountField("*", "cont");
  1092.             sqlQueryObject.setANDLogicOperator(true);
  1093.             sqlQueryObject.addWhereCondition(CostantiDB.PORT_TYPE+".id_accordo = "+CostantiDB.ACCORDI+".id");
  1094.             sqlQueryObject.addWhereCondition(CostantiDB.PORT_TYPE+".id_accordo = ?");
  1095.             if(profiloCollaborazione!=null){
  1096.                 sqlQueryObject.addWhereCondition(false,
  1097.                         CostantiDB.ACCORDI+".profilo_collaborazione=?"
  1098.                         ,CostantiDB.PORT_TYPE+".profilo_collaborazione = ? AND "+CostantiDB.PORT_TYPE+".profilo_pt= ?");
  1099.             }
  1100.             if (!search.equals("")) {
  1101.                 //query con search
  1102.                 sqlQueryObject.addWhereLikeCondition("nome", search, true, true);
  1103.             }
  1104.             queryString = sqlQueryObject.createSQLQuery();
  1105.             stmt = con.prepareStatement(queryString);
  1106.             stmt.setLong(1,idAccordo);
  1107.             if(profiloCollaborazione!=null){
  1108.                 stmt.setString(2,profiloCollaborazione);
  1109.                 stmt.setString(3,profiloCollaborazione);
  1110.                 stmt.setString(4,CostantiRegistroServizi.PROFILO_AZIONE_RIDEFINITO);
  1111.             }
  1112.             risultato = stmt.executeQuery();
  1113.             if (risultato.next())
  1114.                 ricerca.setNumEntries(idLista,risultato.getInt("cont"));
  1115.             risultato.close();
  1116.             stmt.close();

  1117.             // ricavo le entries
  1118.             if (limit == 0) // con limit
  1119.                 limit = ISQLQueryObject.LIMIT_DEFAULT_VALUE;

  1120.             sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  1121.             sqlQueryObject.addFromTable(CostantiDB.ACCORDI);
  1122.             sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE);
  1123.             sqlQueryObject.addSelectField(CostantiDB.PORT_TYPE, "id_accordo");
  1124.             sqlQueryObject.addSelectField(CostantiDB.PORT_TYPE, "nome");
  1125.             sqlQueryObject.addSelectField(CostantiDB.PORT_TYPE, "descrizione");
  1126.             sqlQueryObject.addSelectField(CostantiDB.PORT_TYPE, "profilo_collaborazione");
  1127.             sqlQueryObject.addSelectField(CostantiDB.PORT_TYPE, "filtro_duplicati");
  1128.             sqlQueryObject.addSelectField(CostantiDB.PORT_TYPE, "conferma_ricezione");
  1129.             sqlQueryObject.addSelectField(CostantiDB.PORT_TYPE, "identificativo_collaborazione");
  1130.             sqlQueryObject.addSelectField(CostantiDB.PORT_TYPE, "id_riferimento_richiesta");
  1131.             sqlQueryObject.addSelectField(CostantiDB.PORT_TYPE, "consegna_in_ordine");
  1132.             sqlQueryObject.addSelectField(CostantiDB.PORT_TYPE, "scadenza");
  1133.             sqlQueryObject.addSelectField(CostantiDB.PORT_TYPE, "profilo_pt");
  1134.             sqlQueryObject.addSelectField(CostantiDB.PORT_TYPE, "soap_style");
  1135.             sqlQueryObject.addSelectField(CostantiDB.PORT_TYPE, "id");
  1136.             sqlQueryObject.setANDLogicOperator(true);
  1137.             sqlQueryObject.addWhereCondition(CostantiDB.PORT_TYPE+".id_accordo = "+CostantiDB.ACCORDI+".id");
  1138.             sqlQueryObject.addWhereCondition(CostantiDB.PORT_TYPE+".id_accordo = ?");
  1139.             if(profiloCollaborazione!=null){
  1140.                 sqlQueryObject.addWhereCondition(false,
  1141.                         CostantiDB.ACCORDI+".profilo_collaborazione=?"
  1142.                         ,CostantiDB.PORT_TYPE+".profilo_collaborazione = ? AND "+CostantiDB.PORT_TYPE+".profilo_pt= ?");
  1143.             }
  1144.             if (!search.equals("")) { // con search
  1145.                 sqlQueryObject.addWhereLikeCondition("nome", search, true, true);
  1146.             }
  1147.             sqlQueryObject.addOrderBy(CostantiDB.PORT_TYPE+".nome");
  1148.             sqlQueryObject.setSortType(true);
  1149.             sqlQueryObject.setLimit(limit);
  1150.             sqlQueryObject.setOffset(offset);
  1151.             queryString = sqlQueryObject.createSQLQuery();
  1152.             stmt = con.prepareStatement(queryString);
  1153.             stmt.setLong(1, idAccordo);
  1154.             if(profiloCollaborazione!=null){
  1155.                 stmt.setString(2,profiloCollaborazione);
  1156.                 stmt.setString(3,profiloCollaborazione);
  1157.                 stmt.setString(4,CostantiRegistroServizi.PROFILO_AZIONE_RIDEFINITO);
  1158.             }
  1159.             risultato = stmt.executeQuery();

  1160.             PortType pt;
  1161.             while (risultato.next()) {
  1162.                 pt = new PortType();

  1163.                 String tmp = risultato.getString("nome");
  1164.                 pt.setNome(((tmp == null || tmp.equals("")) ? null : tmp));
  1165.                 tmp = risultato.getString("descrizione");
  1166.                 pt.setDescrizione(((tmp == null || tmp.equals("")) ? null : tmp));
  1167.                 tmp = risultato.getString("profilo_collaborazione");
  1168.                 pt.setProfiloCollaborazione(DriverRegistroServiziDB_LIB.getEnumProfiloCollaborazione(((tmp == null || tmp.equals("")) ? null : tmp)));
  1169.                 tmp = risultato.getString("filtro_duplicati");
  1170.                 pt.setFiltroDuplicati(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(((tmp == null || tmp.equals("")) ? null : tmp)));
  1171.                 tmp = risultato.getString("conferma_ricezione");
  1172.                 pt.setConfermaRicezione(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(((tmp == null || tmp.equals("")) ? null : tmp)));
  1173.                 tmp = risultato.getString("identificativo_collaborazione");
  1174.                 pt.setIdCollaborazione(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(((tmp == null || tmp.equals("")) ? null : tmp)));
  1175.                 tmp = risultato.getString("id_riferimento_richiesta");
  1176.                 pt.setIdRiferimentoRichiesta(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(((tmp == null || tmp.equals("")) ? null : tmp)));
  1177.                 tmp = risultato.getString("consegna_in_ordine");
  1178.                 pt.setConsegnaInOrdine(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(((tmp == null || tmp.equals("")) ? null : tmp)));
  1179.                 tmp = risultato.getString("scadenza");
  1180.                 pt.setScadenza(((tmp == null || tmp.equals("")) ? null : tmp));
  1181.                 tmp = risultato.getString("profilo_pt");
  1182.                 if (tmp == null || tmp.equals(""))
  1183.                     pt.setProfiloPT(CostantiRegistroServizi.PROFILO_AZIONE_DEFAULT);
  1184.                 else
  1185.                     pt.setProfiloPT(tmp);
  1186.                 tmp = risultato.getString("soap_style");
  1187.                 pt.setStyle(DriverRegistroServiziDB_LIB.getEnumBindingStyle(((tmp == null || tmp.equals("")) ? null : tmp)));
  1188.                 pt.setIdAccordo(risultato.getLong("id_accordo"));
  1189.                 long idPortType = risultato.getLong("id");
  1190.                 pt.setId(idPortType);
  1191.                 lista.add(pt);
  1192.             }

  1193.             return lista;

  1194.         } catch (Exception se) {

  1195.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB::" + nomeMetodo + "] Exception: " + se.getMessage(),se);
  1196.         } finally {
  1197.             //Chiudo statement and resultset
  1198.             JDBCUtilities.closeResources(risultato, stmt);
  1199.            
  1200.             this.driver.closeConnection(con);
  1201.         }
  1202.     }
  1203.    
  1204.     protected List<Operation> accordiPorttypeOperationList(long idPortType,String profiloCollaborazione, ISearch ricerca) throws DriverRegistroServiziException {
  1205.         String nomeMetodo = "accordiPorttypeOperationsList";
  1206.         int idLista = Liste.ACCORDI_PORTTYPE_AZIONI;
  1207.         int offset;
  1208.         int limit;
  1209.         String search;
  1210.         String queryString;

  1211.         limit = ricerca.getPageSize(idLista);
  1212.         offset = ricerca.getIndexIniziale(idLista);
  1213.         search = (org.openspcoop2.core.constants.Costanti.SESSION_ATTRIBUTE_VALUE_RICERCA_UNDEFINED.equals(ricerca.getSearchString(idLista)) ? "" : ricerca.getSearchString(idLista));
  1214.         ricerca.getSearchString(idLista);

  1215.         Connection con = null;
  1216.         PreparedStatement stmt = null;
  1217.         ResultSet risultato = null;

  1218.         ArrayList<Operation> lista = new ArrayList<Operation>();

  1219.         if (this.driver.atomica) {
  1220.             try {
  1221.                 con = this.driver.getConnectionFromDatasource("accordiPorttypeOperationList");

  1222.             } catch (Exception e) {
  1223.                 throw new DriverRegistroServiziException("[DriverRegistroServiziDB::" + nomeMetodo + "] Exception accedendo al datasource :" + e.getMessage(),e);

  1224.             }

  1225.         } else
  1226.             con = this.driver.globalConnection;

  1227.         this.driver.logDebug("operazione this.driver.atomica = " + this.driver.atomica);

  1228.         try {

  1229.             /*SELECT a.id,pt.nome,pta.nome
  1230.              * from accordi a,port_type pt,port_type_azioni pta
  1231.                 where a.id=pt.id_accordo and pt.id=pta.id_port_type
  1232.                 and
  1233.                 (
  1234.                     a.profilo_collaborazione='asincronoAsimmetrico'
  1235.                     OR (pt.profilo_pt='ridefinito' AND pt.profilo_collaborazione='asincronoAsimmetrico')
  1236.                     OR (pta.profilo_pt_azione='ridefinito' AND pta.profilo_collaborazione='asincronoAsimmetrico')
  1237.                 ));
  1238.              */
  1239.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  1240.             sqlQueryObject.addFromTable(CostantiDB.ACCORDI);
  1241.             sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE);
  1242.             sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE_AZIONI);
  1243.             //count
  1244.             sqlQueryObject.addSelectCountField(CostantiDB.PORT_TYPE_AZIONI+".id", "cont");
  1245.             //condizioni di join
  1246.             sqlQueryObject.setANDLogicOperator(true);

  1247.             sqlQueryObject.addWhereCondition(CostantiDB.PORT_TYPE+".id_accordo = "+CostantiDB.ACCORDI+".id");
  1248.             sqlQueryObject.addWhereCondition(CostantiDB.PORT_TYPE_AZIONI+".id_port_type = "+CostantiDB.PORT_TYPE+".id");
  1249.             sqlQueryObject.addWhereCondition(CostantiDB.PORT_TYPE+".id = ?");

  1250.             sqlQueryObject.addWhereCondition(false,
  1251.                     CostantiDB.ACCORDI+".profilo_collaborazione=?"
  1252.                     ,CostantiDB.PORT_TYPE+".profilo_collaborazione = ? AND "+CostantiDB.PORT_TYPE+".profilo_pt= ?"
  1253.                     ,CostantiDB.PORT_TYPE_AZIONI+".profilo_collaborazione = ? AND "+CostantiDB.PORT_TYPE_AZIONI+".profilo_pt_azione= ?");

  1254.             if (!search.equals("")) {
  1255.                 sqlQueryObject.addWhereLikeCondition("nome", search, true, true);
  1256.             }

  1257.             queryString = sqlQueryObject.createSQLQuery();

  1258.             stmt = con.prepareStatement(queryString);
  1259.             stmt.setLong(1,idPortType);
  1260.             stmt.setString(2,profiloCollaborazione);
  1261.             stmt.setString(3,profiloCollaborazione);
  1262.             stmt.setString(4,CostantiRegistroServizi.PROFILO_AZIONE_RIDEFINITO);
  1263.             stmt.setString(5,profiloCollaborazione);
  1264.             stmt.setString(6,CostantiRegistroServizi.PROFILO_AZIONE_RIDEFINITO);

  1265.             risultato = stmt.executeQuery();
  1266.             if (risultato.next())
  1267.                 ricerca.setNumEntries(idLista,risultato.getInt("cont"));
  1268.             risultato.close();
  1269.             stmt.close();

  1270.             // ricavo le entries
  1271.             if (limit == 0) // con limit
  1272.                 limit = ISQLQueryObject.LIMIT_DEFAULT_VALUE;


  1273.             sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  1274.             sqlQueryObject.addFromTable(CostantiDB.ACCORDI);
  1275.             sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE);
  1276.             sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE_AZIONI);
  1277.             //select
  1278.             sqlQueryObject.addSelectField(CostantiDB.PORT_TYPE_AZIONI,"id_port_type");
  1279.             sqlQueryObject.addSelectAliasField(CostantiDB.PORT_TYPE_AZIONI,"nome","nomePTAz");
  1280.             sqlQueryObject.addSelectAliasField(CostantiDB.PORT_TYPE_AZIONI,"profilo_collaborazione","profCollPTAz");
  1281.             sqlQueryObject.addSelectAliasField(CostantiDB.PORT_TYPE_AZIONI,"filtro_duplicati","filtro_duplicatiPTAz");
  1282.             sqlQueryObject.addSelectAliasField(CostantiDB.PORT_TYPE_AZIONI,"conferma_ricezione","conferma_ricezionePTAz");
  1283.             sqlQueryObject.addSelectAliasField(CostantiDB.PORT_TYPE_AZIONI,"identificativo_collaborazione","idCollPTAz");
  1284.             sqlQueryObject.addSelectAliasField(CostantiDB.PORT_TYPE_AZIONI,"id_riferimento_richiesta","idRifRichiestaPTAz");
  1285.             sqlQueryObject.addSelectAliasField(CostantiDB.PORT_TYPE_AZIONI,"consegna_in_ordine","consegna_in_ordinePTAz");
  1286.             sqlQueryObject.addSelectAliasField(CostantiDB.PORT_TYPE_AZIONI,"scadenza","scadenzaPTAz");
  1287.             sqlQueryObject.addSelectAliasField(CostantiDB.PORT_TYPE_AZIONI,"correlata","correlataPTAz");
  1288.             sqlQueryObject.addSelectAliasField(CostantiDB.PORT_TYPE_AZIONI,"correlata_servizio","correlataServizioPTAz");
  1289.             sqlQueryObject.addSelectField(CostantiDB.PORT_TYPE_AZIONI,"profilo_pt_azione");
  1290.             sqlQueryObject.addSelectAliasField(CostantiDB.PORT_TYPE_AZIONI,"id","idPTAz");
  1291.             //condizioni di join
  1292.             sqlQueryObject.setANDLogicOperator(true);

  1293.             sqlQueryObject.addWhereCondition(CostantiDB.PORT_TYPE+".id_accordo = "+CostantiDB.ACCORDI+".id");
  1294.             sqlQueryObject.addWhereCondition(CostantiDB.PORT_TYPE_AZIONI+".id_port_type = "+CostantiDB.PORT_TYPE+".id");
  1295.             sqlQueryObject.addWhereCondition(CostantiDB.PORT_TYPE+".id = ?");

  1296.             sqlQueryObject.addWhereCondition(false,
  1297.                     CostantiDB.ACCORDI+".profilo_collaborazione=?"
  1298.                     ,CostantiDB.PORT_TYPE+".profilo_collaborazione = ? AND "+CostantiDB.PORT_TYPE+".profilo_pt= ?"
  1299.                     ,CostantiDB.PORT_TYPE_AZIONI+".profilo_collaborazione = ? AND "+CostantiDB.PORT_TYPE_AZIONI+".profilo_pt_azione= ?");

  1300.             if (!search.equals("")) {
  1301.                 sqlQueryObject.addWhereLikeCondition("nome", search, true, true);
  1302.             }

  1303.             sqlQueryObject.addOrderBy(CostantiDB.PORT_TYPE_AZIONI+".nome");
  1304.             sqlQueryObject.setSortType(true);
  1305.             sqlQueryObject.setLimit(limit);
  1306.             sqlQueryObject.setOffset(offset);

  1307.             queryString = sqlQueryObject.createSQLQuery();

  1308.             this.driver.logDebug("Query: "+queryString);

  1309.             stmt = con.prepareStatement(queryString);
  1310.             stmt.setLong(1,idPortType);
  1311.             stmt.setString(2,profiloCollaborazione);
  1312.             stmt.setString(3,profiloCollaborazione);
  1313.             stmt.setString(4,CostantiRegistroServizi.PROFILO_AZIONE_RIDEFINITO);
  1314.             stmt.setString(5,profiloCollaborazione);
  1315.             stmt.setString(6,CostantiRegistroServizi.PROFILO_AZIONE_RIDEFINITO);


  1316.             risultato = stmt.executeQuery();
  1317.             Operation op;
  1318.             while (risultato.next()) {
  1319.                 op = new Operation();

  1320.                 String tmp = risultato.getString("nomePTAz");
  1321.                 op.setNome(((tmp == null || tmp.equals("")) ? null : tmp));
  1322.                 tmp = risultato.getString("profCollPTAz");
  1323.                 op.setProfiloCollaborazione(DriverRegistroServiziDB_LIB.getEnumProfiloCollaborazione(((tmp == null || tmp.equals("")) ? null : tmp)));
  1324.                 tmp = risultato.getString("filtro_duplicatiPTAz");
  1325.                 op.setFiltroDuplicati(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(((tmp == null || tmp.equals("")) ? null : tmp)));
  1326.                 tmp = risultato.getString("conferma_ricezionePTAz");
  1327.                 op.setConfermaRicezione(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(((tmp == null || tmp.equals("")) ? null : tmp)));
  1328.                 tmp = risultato.getString("idCollPTAz");
  1329.                 op.setIdCollaborazione(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(((tmp == null || tmp.equals("")) ? null : tmp)));
  1330.                 tmp = risultato.getString("idRifRichiestaPTAz");
  1331.                 op.setIdRiferimentoRichiesta(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(((tmp == null || tmp.equals("")) ? null : tmp)));
  1332.                 tmp = risultato.getString("consegna_in_ordinePTAz");
  1333.                 op.setConsegnaInOrdine(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(((tmp == null || tmp.equals("")) ? null : tmp)));
  1334.                 tmp = risultato.getString("scadenzaPTAz");
  1335.                 op.setScadenza(((tmp == null || tmp.equals("")) ? null : tmp));
  1336.                 tmp = risultato.getString("correlataPTAz");
  1337.                 op.setCorrelata(((tmp == null || tmp.equals("")) ? null : tmp));
  1338.                 tmp = risultato.getString("correlataServizioPTAz");
  1339.                 op.setCorrelataServizio(((tmp == null || tmp.equals("")) ? null : tmp));
  1340.                 tmp = risultato.getString("profilo_pt_azione");
  1341.                 if (tmp == null || tmp.equals(""))
  1342.                     op.setProfAzione(CostantiRegistroServizi.PROFILO_AZIONE_DEFAULT);
  1343.                 else
  1344.                     op.setProfAzione(tmp);
  1345.                 op.setIdPortType(risultato.getLong("id_port_type"));
  1346.                 long idOperation = risultato.getLong("idPTAz");
  1347.                 op.setId(idOperation);
  1348.                 lista.add(op);
  1349.             }

  1350.             return lista;

  1351.         } catch (Exception se) {
  1352.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB::" + nomeMetodo + "] Exception: " + se.getMessage(),se);
  1353.         } finally {
  1354.             //Chiudo statement and resultset
  1355.             JDBCUtilities.closeResources(risultato, stmt);
  1356.            
  1357.             this.driver.closeConnection(con);
  1358.         }
  1359.     }


  1360.     protected List<Operation> accordiPorttypeOperationList(long idPortType, ISearch ricerca) throws DriverRegistroServiziException {
  1361.         String nomeMetodo = "accordiPorttypeOperationsList";
  1362.         int idLista = Liste.ACCORDI_PORTTYPE_AZIONI;
  1363.         int offset;
  1364.         int limit;
  1365.         String search;
  1366.         String queryString;

  1367.         limit = ricerca.getPageSize(idLista);
  1368.         offset = ricerca.getIndexIniziale(idLista);
  1369.         search = (org.openspcoop2.core.constants.Costanti.SESSION_ATTRIBUTE_VALUE_RICERCA_UNDEFINED.equals(ricerca.getSearchString(idLista)) ? "" : ricerca.getSearchString(idLista));
  1370.         ricerca.getSearchString(idLista);

  1371.         Connection con = null;
  1372.         PreparedStatement stmt = null;
  1373.         ResultSet risultato = null;

  1374.         ArrayList<Operation> lista = new ArrayList<Operation>();

  1375.         if (this.driver.atomica) {
  1376.             try {
  1377.                 con = this.driver.getConnectionFromDatasource("accordiPorttypeOperationList");

  1378.             } catch (Exception e) {
  1379.                 throw new DriverRegistroServiziException("[DriverRegistroServiziDB::" + nomeMetodo + "] Exception accedendo al datasource :" + e.getMessage(),e);

  1380.             }

  1381.         } else
  1382.             con = this.driver.globalConnection;

  1383.         this.driver.logDebug("operazione this.driver.atomica = " + this.driver.atomica);

  1384.         try {

  1385.             if (!search.equals("")) {
  1386.                 //query con search
  1387.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  1388.                 sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE_AZIONI);
  1389.                 sqlQueryObject.addSelectCountField("*", "cont");
  1390.                 sqlQueryObject.addWhereCondition("id_port_type = ?");
  1391.                 sqlQueryObject.addWhereLikeCondition("nome", search, true, true);
  1392.                 sqlQueryObject.setANDLogicOperator(true);
  1393.                 queryString = sqlQueryObject.createSQLQuery();
  1394.             } else {
  1395.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  1396.                 sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE_AZIONI);
  1397.                 sqlQueryObject.addSelectCountField("*", "cont");
  1398.                 sqlQueryObject.addWhereCondition("id_port_type = ?");
  1399.                 queryString = sqlQueryObject.createSQLQuery();
  1400.             }
  1401.             stmt = con.prepareStatement(queryString);
  1402.             stmt.setLong(1,idPortType);
  1403.             risultato = stmt.executeQuery();
  1404.             if (risultato.next())
  1405.                 ricerca.setNumEntries(idLista,risultato.getInt("cont"));
  1406.             risultato.close();
  1407.             stmt.close();

  1408.             // ricavo le entries
  1409.             if (limit == 0) // con limit
  1410.                 limit = ISQLQueryObject.LIMIT_DEFAULT_VALUE;
  1411.             if (!search.equals("")) { // con search
  1412.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  1413.                 sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE_AZIONI);
  1414.                 sqlQueryObject.addSelectField("id_port_type");
  1415.                 sqlQueryObject.addSelectField("nome");
  1416.                 sqlQueryObject.addSelectField("profilo_collaborazione");
  1417.                 sqlQueryObject.addSelectField("filtro_duplicati");
  1418.                 sqlQueryObject.addSelectField("conferma_ricezione");
  1419.                 sqlQueryObject.addSelectField("identificativo_collaborazione");
  1420.                 sqlQueryObject.addSelectField("id_riferimento_richiesta");
  1421.                 sqlQueryObject.addSelectField("consegna_in_ordine");
  1422.                 sqlQueryObject.addSelectField("scadenza");
  1423.                 sqlQueryObject.addSelectField("profilo_pt_azione");
  1424.                 sqlQueryObject.addSelectField("id");
  1425.                 sqlQueryObject.addWhereCondition("id_port_type = ?");
  1426.                 sqlQueryObject.addWhereLikeCondition("nome", search, true, true);
  1427.                 sqlQueryObject.setANDLogicOperator(true);
  1428.                 sqlQueryObject.addOrderBy("nome");
  1429.                 sqlQueryObject.setSortType(true);
  1430.                 sqlQueryObject.setLimit(limit);
  1431.                 sqlQueryObject.setOffset(offset);
  1432.                 queryString = sqlQueryObject.createSQLQuery();
  1433.             } else {
  1434.                 // senza search
  1435.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  1436.                 sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE_AZIONI);
  1437.                 sqlQueryObject.addSelectField("id_port_type");
  1438.                 sqlQueryObject.addSelectField("nome");
  1439.                 sqlQueryObject.addSelectField("profilo_collaborazione");
  1440.                 sqlQueryObject.addSelectField("filtro_duplicati");
  1441.                 sqlQueryObject.addSelectField("conferma_ricezione");
  1442.                 sqlQueryObject.addSelectField("identificativo_collaborazione");
  1443.                 sqlQueryObject.addSelectField("id_riferimento_richiesta");
  1444.                 sqlQueryObject.addSelectField("consegna_in_ordine");
  1445.                 sqlQueryObject.addSelectField("scadenza");
  1446.                 sqlQueryObject.addSelectField("profilo_pt_azione");
  1447.                 sqlQueryObject.addSelectField("id");
  1448.                 sqlQueryObject.addWhereCondition("id_port_type = ?");
  1449.                 sqlQueryObject.addOrderBy("nome");
  1450.                 sqlQueryObject.setSortType(true);
  1451.                 sqlQueryObject.setLimit(limit);
  1452.                 sqlQueryObject.setOffset(offset);
  1453.                 queryString = sqlQueryObject.createSQLQuery();
  1454.             }
  1455.             stmt = con.prepareStatement(queryString);
  1456.             stmt.setLong(1, idPortType);
  1457.             risultato = stmt.executeQuery();

  1458.             Operation op;
  1459.             while (risultato.next()) {
  1460.                 op = new Operation();

  1461.                 String tmp = risultato.getString("nome");
  1462.                 op.setNome(((tmp == null || tmp.equals("")) ? null : tmp));
  1463.                 tmp = risultato.getString("profilo_collaborazione");
  1464.                 op.setProfiloCollaborazione(DriverRegistroServiziDB_LIB.getEnumProfiloCollaborazione(((tmp == null || tmp.equals("")) ? null : tmp)));
  1465.                 tmp = risultato.getString("filtro_duplicati");
  1466.                 op.setFiltroDuplicati(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(((tmp == null || tmp.equals("")) ? null : tmp)));
  1467.                 tmp = risultato.getString("conferma_ricezione");
  1468.                 op.setConfermaRicezione(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(((tmp == null || tmp.equals("")) ? null : tmp)));
  1469.                 tmp = risultato.getString("identificativo_collaborazione");
  1470.                 op.setIdCollaborazione(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(((tmp == null || tmp.equals("")) ? null : tmp)));
  1471.                 tmp = risultato.getString("id_riferimento_richiesta");
  1472.                 op.setIdRiferimentoRichiesta(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(((tmp == null || tmp.equals("")) ? null : tmp)));
  1473.                 tmp = risultato.getString("consegna_in_ordine");
  1474.                 op.setConsegnaInOrdine(DriverRegistroServiziDB_LIB.getEnumStatoFunzionalita(((tmp == null || tmp.equals("")) ? null : tmp)));
  1475.                 tmp = risultato.getString("scadenza");
  1476.                 op.setScadenza(((tmp == null || tmp.equals("")) ? null : tmp));
  1477.                 tmp = risultato.getString("profilo_pt_azione");
  1478.                 if (tmp == null || tmp.equals(""))
  1479.                     op.setProfAzione(CostantiRegistroServizi.PROFILO_AZIONE_DEFAULT);
  1480.                 else
  1481.                     op.setProfAzione(tmp);
  1482.                 op.setIdPortType(risultato.getLong("id_port_type"));
  1483.                 long idOperation = risultato.getLong("id");
  1484.                 op.setId(idOperation);
  1485.                 lista.add(op);
  1486.             }

  1487.             return lista;

  1488.         } catch (Exception se) {

  1489.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB::" + nomeMetodo + "] Exception: " + se.getMessage(),se);
  1490.         } finally {
  1491.             //Chiudo statement and resultset
  1492.             JDBCUtilities.closeResources(risultato, stmt);
  1493.            
  1494.             this.driver.closeConnection(con);
  1495.         }
  1496.     }
  1497.    
  1498.     protected List<MessagePart> accordiPorttypeOperationMessagePartList(long idOperation, boolean isInput, ISearch ricerca) throws DriverRegistroServiziException {
  1499.         String nomeMetodo = "accordiPorttypeOperationMessagePartList";
  1500.         int idLista = Liste.ACCORDI_PORTTYPE_AZIONI_MESSAGE_INPUT;
  1501.         if(!isInput)
  1502.             idLista = Liste.ACCORDI_PORTTYPE_AZIONI_MESSAGE_OUTPUT;
  1503.         int offset;
  1504.         int limit;
  1505.         String search;
  1506.         String queryString;

  1507.         limit = ricerca.getPageSize(idLista);
  1508.         offset = ricerca.getIndexIniziale(idLista);
  1509.         search = (org.openspcoop2.core.constants.Costanti.SESSION_ATTRIBUTE_VALUE_RICERCA_UNDEFINED.equals(ricerca.getSearchString(idLista)) ? "" : ricerca.getSearchString(idLista));
  1510.         ricerca.getSearchString(idLista);

  1511.         Connection con = null;
  1512.         PreparedStatement stmt = null;
  1513.         ResultSet risultato = null;

  1514.         ArrayList<MessagePart> lista = new ArrayList<MessagePart>();

  1515.         if (this.driver.atomica) {
  1516.             try {
  1517.                 con = this.driver.getConnectionFromDatasource("accordiPorttypeOperationMessagePartList");

  1518.             } catch (Exception e) {
  1519.                 throw new DriverRegistroServiziException("[DriverRegistroServiziDB::" + nomeMetodo + "] Exception accedendo al datasource :" + e.getMessage(),e);

  1520.             }

  1521.         } else
  1522.             con = this.driver.globalConnection;

  1523.         this.driver.logDebug("operazione this.driver.atomica = " + this.driver.atomica);

  1524.         try {

  1525.             if (!search.equals("")) {
  1526.                 //query con search
  1527.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  1528.                 sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE_AZIONI_OPERATION_MESSAGES);
  1529.                 sqlQueryObject.addSelectCountField("*", "cont");
  1530.                 sqlQueryObject.addWhereCondition("id_port_type_azione = ?");
  1531.                 if(isInput)
  1532.                     sqlQueryObject.addWhereCondition("input_message = 1");
  1533.                 else
  1534.                     sqlQueryObject.addWhereCondition("input_message != 1");
  1535.                 sqlQueryObject.addWhereLikeCondition("name", search, true, true);
  1536.                 sqlQueryObject.setANDLogicOperator(true);
  1537.                 queryString = sqlQueryObject.createSQLQuery();
  1538.             } else {
  1539.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  1540.                 sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE_AZIONI_OPERATION_MESSAGES);
  1541.                 sqlQueryObject.addSelectCountField("*", "cont");
  1542.                 sqlQueryObject.addWhereCondition("id_port_type_azione = ?");
  1543.                
  1544.                 if(isInput)
  1545.                     sqlQueryObject.addWhereCondition("input_message = 1");
  1546.                 else
  1547.                     sqlQueryObject.addWhereCondition("input_message != 1");
  1548.                 sqlQueryObject.setANDLogicOperator(true);
  1549.                 queryString = sqlQueryObject.createSQLQuery();
  1550.             }
  1551.             stmt = con.prepareStatement(queryString);
  1552.             stmt.setLong(1,idOperation);
  1553.             risultato = stmt.executeQuery();
  1554.             if (risultato.next())
  1555.                 ricerca.setNumEntries(idLista,risultato.getInt("cont"));
  1556.             risultato.close();
  1557.             stmt.close();

  1558.             // ricavo le entries
  1559.             if (limit == 0) // con limit
  1560.                 limit = ISQLQueryObject.LIMIT_DEFAULT_VALUE;
  1561.             if (!search.equals("")) { // con search
  1562.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  1563.                 sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE_AZIONI_OPERATION_MESSAGES);
  1564.                 sqlQueryObject.addSelectField("name");
  1565.                 sqlQueryObject.addSelectField("element_name");
  1566.                 sqlQueryObject.addSelectField("element_namespace");
  1567.                 sqlQueryObject.addSelectField("type_name");
  1568.                 sqlQueryObject.addSelectField("type_namespace");
  1569.                 sqlQueryObject.addSelectField("id");
  1570.                 sqlQueryObject.addWhereCondition("id_port_type_azione = ?");
  1571.                 if(isInput)
  1572.                     sqlQueryObject.addWhereCondition("input_message = 1");
  1573.                 else
  1574.                     sqlQueryObject.addWhereCondition("input_message != 1");
  1575.                 sqlQueryObject.addWhereLikeCondition("nome", search, true, true);
  1576.                 sqlQueryObject.setANDLogicOperator(true);
  1577.                 sqlQueryObject.addOrderBy("name");
  1578.                 sqlQueryObject.setSortType(true);
  1579.                 sqlQueryObject.setLimit(limit);
  1580.                 sqlQueryObject.setOffset(offset);
  1581.                 queryString = sqlQueryObject.createSQLQuery();
  1582.             } else {
  1583.                 // senza search
  1584.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  1585.                 sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE_AZIONI_OPERATION_MESSAGES);
  1586.                 sqlQueryObject.addSelectField("name");
  1587.                 sqlQueryObject.addSelectField("element_name");
  1588.                 sqlQueryObject.addSelectField("element_namespace");
  1589.                 sqlQueryObject.addSelectField("type_name");
  1590.                 sqlQueryObject.addSelectField("type_namespace");
  1591.                 sqlQueryObject.addSelectField("id");
  1592.                 sqlQueryObject.addWhereCondition("id_port_type_azione = ?");
  1593.                 if(isInput)
  1594.                     sqlQueryObject.addWhereCondition("input_message = 1");
  1595.                 else
  1596.                     sqlQueryObject.addWhereCondition("input_message != 1");
  1597.                 sqlQueryObject.setANDLogicOperator(true);
  1598.                 sqlQueryObject.addOrderBy("name");
  1599.                 sqlQueryObject.setSortType(true);
  1600.                 sqlQueryObject.setLimit(limit);
  1601.                 sqlQueryObject.setOffset(offset);
  1602.                 queryString = sqlQueryObject.createSQLQuery();
  1603.             }
  1604.             stmt = con.prepareStatement(queryString);
  1605.             stmt.setLong(1, idOperation);
  1606.             risultato = stmt.executeQuery();

  1607.            
  1608.             MessagePart mp;
  1609.            
  1610.             while (risultato.next()) {
  1611.                 mp = new MessagePart();

  1612.                 String tmp = risultato.getString("name");
  1613.                 mp.setName(((tmp == null || tmp.equals("")) ? null : tmp));
  1614.                 tmp = risultato.getString("element_name");
  1615.                 mp.setElementName(((tmp == null || tmp.equals("")) ? null : tmp));
  1616.                 tmp = risultato.getString("element_namespace");
  1617.                 mp.setElementNamespace(((tmp == null || tmp.equals("")) ? null : tmp));
  1618.                 tmp = risultato.getString("type_name");
  1619.                 mp.setTypeName(((tmp == null || tmp.equals("")) ? null : tmp));
  1620.                 tmp = risultato.getString("type_namespace");
  1621.                 mp.setTypeNamespace(((tmp == null || tmp.equals("")) ? null : tmp));
  1622.                 long idMessage = risultato.getLong("id");
  1623.                 mp.setId(idMessage);
  1624.                 lista.add(mp);
  1625.             }

  1626.             return lista;

  1627.         } catch (Exception se) {

  1628.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB::" + nomeMetodo + "] Exception: " + se.getMessage(),se);
  1629.         } finally {
  1630.             //Chiudo statement and resultset
  1631.             JDBCUtilities.closeResources(risultato, stmt);
  1632.            
  1633.             this.driver.closeConnection(con);
  1634.         }
  1635.     }
  1636.    
  1637.     /**
  1638.      * Controlla se l'azione e' usata come Azione correlata in qualche azione dell'accordo con id idAccordo
  1639.      * @param idAccordo
  1640.      * @param nomeAzione
  1641.      * @return true se se l'azione e' usata come Azione correlata in qualche azione dell'accordo con id idAccordo
  1642.      * @throws DriverRegistroServiziException
  1643.      */
  1644.     protected boolean isCorrelata(long idAccordo,String nomeAzione,String owner) throws DriverRegistroServiziException {
  1645.         String nomeMetodo = "isCorrelata";

  1646.         String queryString;

  1647.         Connection con = null;
  1648.         PreparedStatement stmt = null;
  1649.         ResultSet risultato = null;

  1650.         if (this.driver.atomica) {
  1651.             try {
  1652.                 con = this.driver.getConnectionFromDatasource("isCorrelata");

  1653.             } catch (Exception e) {
  1654.                 throw new DriverRegistroServiziException("[DriverRegistroServiziDB::" + nomeMetodo + "] Exception accedendo al datasource :" + e.getMessage(),e);

  1655.             }

  1656.         } else
  1657.             con = this.driver.globalConnection;

  1658.         this.driver.logDebug("operazione this.driver.atomica = " + this.driver.atomica);

  1659.         try {          

  1660.             // ricavo le entries

  1661.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  1662.             sqlQueryObject.addFromTable(CostantiDB.ACCORDI_AZIONI);
  1663.             sqlQueryObject.addSelectCountField("id", "tot");

  1664.             sqlQueryObject.addWhereCondition("id_accordo = ?");
  1665.             sqlQueryObject.addWhereCondition("correlata = ?");
  1666.             sqlQueryObject.addWhereCondition("nome <> ?");

  1667.             sqlQueryObject.setANDLogicOperator(true);

  1668.             queryString = sqlQueryObject.createSQLQuery();

  1669.             stmt = con.prepareStatement(queryString);
  1670.             stmt.setLong(1, idAccordo);
  1671.             stmt.setString(2, nomeAzione);
  1672.             stmt.setString(3, owner);

  1673.             risultato = stmt.executeQuery();

  1674.             int tot=0;
  1675.             if (risultato.next()) {
  1676.                 tot=risultato.getInt("tot");
  1677.             }
  1678.             risultato.close();

  1679.             return tot>0;


  1680.         } catch (Exception se) {

  1681.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB::" + nomeMetodo + "] Exception: " + se.getMessage(),se);
  1682.         } finally {
  1683.             //Chiudo statement and resultset
  1684.             JDBCUtilities.closeResources(risultato, stmt);
  1685.            
  1686.             this.driver.closeConnection(con);
  1687.         }
  1688.     }

  1689.     /**
  1690.      * Controlla se l'azione e' usata come Azione correlata in qualche azione dell'accordo con id idAccordo
  1691.      * @param idPortType
  1692.      * @param nomeCorrelata
  1693.      * @return true se l'azione e' usata come Azione correlata in qualche azione dell'accordo con id idAccordo
  1694.      * @throws DriverRegistroServiziException
  1695.      */
  1696.     protected boolean isOperationCorrelata(long idPortType,String nomeCorrelata,String owner) throws DriverRegistroServiziException {
  1697.         String nomeMetodo = "isOperationCorrelata";

  1698.         String queryString;

  1699.         Connection con = null;
  1700.         PreparedStatement stmt = null;
  1701.         ResultSet risultato = null;

  1702.         if (this.driver.atomica) {
  1703.             try {
  1704.                 con = this.driver.getConnectionFromDatasource("isOperationCorrelata");

  1705.             } catch (Exception e) {
  1706.                 throw new DriverRegistroServiziException("[DriverRegistroServiziDB::" + nomeMetodo + "] Exception accedendo al datasource :" + e.getMessage(),e);

  1707.             }

  1708.         } else
  1709.             con = this.driver.globalConnection;

  1710.         this.driver.logDebug("operazione this.driver.atomica = " + this.driver.atomica);

  1711.         try {          

  1712.             // ricavo le entries

  1713.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  1714.             sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE_AZIONI);
  1715.             sqlQueryObject.addSelectCountField("id", "tot");

  1716.             sqlQueryObject.addWhereCondition("id_port_type = ?");
  1717.             sqlQueryObject.addWhereCondition("correlata = ?");
  1718.             sqlQueryObject.addWhereCondition("nome <> ?");

  1719.             sqlQueryObject.setANDLogicOperator(true);

  1720.             queryString = sqlQueryObject.createSQLQuery();

  1721.             stmt = con.prepareStatement(queryString);
  1722.             stmt.setLong(1, idPortType);
  1723.             stmt.setString(2, nomeCorrelata);
  1724.             stmt.setString(3, owner);

  1725.             risultato = stmt.executeQuery();

  1726.             int tot=0;
  1727.             if (risultato.next()) {
  1728.                 tot=risultato.getInt("tot");
  1729.             }
  1730.             risultato.close();

  1731.             return tot>0;


  1732.         } catch (Exception se) {

  1733.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB::" + nomeMetodo + "] Exception: " + se.getMessage(),se);
  1734.         } finally {
  1735.             //Chiudo statement and resultset
  1736.             JDBCUtilities.closeResources(risultato, stmt);
  1737.            
  1738.             this.driver.closeConnection(con);
  1739.         }
  1740.     }

  1741.     protected boolean isOperationCorrelataDaAltraAzione(String nomePortType,long idPortType,String azioneDaVerificare,long idAzioneDaVerificare) throws DriverRegistroServiziException {
  1742.         return this.isOperationCorrelata(nomePortType, idPortType, azioneDaVerificare, idAzioneDaVerificare, false, true);
  1743.     }
  1744.     protected boolean isOperationCorrelataRichiesta(String nomePortType,long idPortType,String azioneDaVerificare,long idAzioneDaVerificare) throws DriverRegistroServiziException {
  1745.         return this.isOperationCorrelata(nomePortType, idPortType, azioneDaVerificare, idAzioneDaVerificare, true, false);
  1746.     }
  1747.     protected boolean isOperationCorrelata(String nomePortType,long idPortType,String azioneDaVerificare,long idAzioneDaVerificare) throws DriverRegistroServiziException {
  1748.         return this.isOperationCorrelata(nomePortType, idPortType, azioneDaVerificare, idAzioneDaVerificare, true, true);
  1749.     }
  1750.     private boolean isOperationCorrelata(String nomePortType,long idPortType,String azioneDaVerificare,long idAzioneDaVerificare,
  1751.             boolean checkCorrelazioneARichiesta,boolean checkCorrelazioneDaAltraAzione) throws DriverRegistroServiziException {
  1752.         String nomeMetodo = "isOperationCorrelata";

  1753.         String queryString;

  1754.         Connection con = null;
  1755.         PreparedStatement stmt = null;
  1756.         ResultSet risultato = null;

  1757.         if (this.driver.atomica) {
  1758.             try {
  1759.                 con = this.driver.getConnectionFromDatasource("isOperationCorrelata(nomePortType,id,azione,idAzione,check)");

  1760.             } catch (Exception e) {
  1761.                 throw new DriverRegistroServiziException("[DriverRegistroServiziDB::" + nomeMetodo + "] Exception accedendo al datasource :" + e.getMessage(),e);

  1762.             }

  1763.         } else
  1764.             con = this.driver.globalConnection;

  1765.         this.driver.logDebug("operazione this.driver.atomica = " + this.driver.atomica);

  1766.         try {          

  1767.             // VERIFICO CORRELAZIONE AD UNA RICHIESTA
  1768.             boolean correlataAdUnaRichiesta = false;
  1769.             if(checkCorrelazioneARichiesta){
  1770.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  1771.                 sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE_AZIONI);
  1772.                 sqlQueryObject.addSelectCountField("id", "tot");
  1773.                 // seleziono il port type
  1774.                 sqlQueryObject.addWhereCondition(CostantiDB.PORT_TYPE_AZIONI+".id_port_type = ?");
  1775.                 // seleziono l'azione
  1776.                 sqlQueryObject.addWhereCondition("nome = ?");
  1777.                 // verifico che l'azione non sia correlata ad una richiesta
  1778.                 sqlQueryObject.addWhereCondition(false,CostantiDB.PORT_TYPE_AZIONI+".correlata is not null",CostantiDB.PORT_TYPE_AZIONI+".correlata_servizio is not null");
  1779.                 sqlQueryObject.setANDLogicOperator(true);
  1780.                 queryString = sqlQueryObject.createSQLQuery();
  1781.                 this.driver.logDebug("VERIFICO CORRELAZIONE AD UNA RICHIESTA ["+idPortType+"] ["+azioneDaVerificare+"]: "+queryString);
  1782.                 stmt = con.prepareStatement(queryString);
  1783.                 stmt.setLong(1, idPortType);
  1784.                 stmt.setString(2, azioneDaVerificare);
  1785.                 risultato = stmt.executeQuery();
  1786.                 int tot=0;
  1787.                 if (risultato.next()) {
  1788.                     tot=risultato.getInt("tot");
  1789.                 }
  1790.                 risultato.close();
  1791.                 stmt.close();
  1792.                 correlataAdUnaRichiesta = tot>0;
  1793.                 this.driver.logDebug("VERIFICO CORRELAZIONE AD UNA RICHIESTA, risultato ["+tot+"]: "+correlataAdUnaRichiesta);
  1794.             }

  1795.             // VERIFICO CHE NON SIA CORRELATA DA UN'ALTRA AZIONE
  1796.             boolean correlataDaUnAltraAzione = false;
  1797.             if(checkCorrelazioneDaAltraAzione){

  1798.                 // Correlazione precisa: per asincrono simmetrico e asincrono asimmetrico con port type diversi
  1799.                 ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  1800.                 sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE_AZIONI);
  1801.                 sqlQueryObject.addSelectCountField("id", "tot");
  1802.                 sqlQueryObject.addWhereCondition(CostantiDB.PORT_TYPE_AZIONI+".id<>?");
  1803.                 sqlQueryObject.addWhereCondition(true,CostantiDB.PORT_TYPE_AZIONI+".correlata =?",CostantiDB.PORT_TYPE_AZIONI+".correlata_servizio =?");
  1804.                 sqlQueryObject.setANDLogicOperator(true);
  1805.                 queryString = sqlQueryObject.createSQLQuery();
  1806.                 stmt = con.prepareStatement(queryString);
  1807.                 this.driver.logDebug("VERIFICO CHE NON SIA CORRELATA DA UN'ALTRA AZIONE (AS e AA con PT diverso) ["+idAzioneDaVerificare+"] ["+azioneDaVerificare+"] ["+nomePortType+"]: "+queryString);
  1808.                 stmt.setLong(1, idAzioneDaVerificare);
  1809.                 stmt.setString(2, azioneDaVerificare);
  1810.                 stmt.setString(3, nomePortType);
  1811.                 risultato = stmt.executeQuery();
  1812.                 int tot=0;
  1813.                 if (risultato.next()) {
  1814.                     tot=risultato.getInt("tot");
  1815.                 }
  1816.                 risultato.close();
  1817.                 stmt.close();
  1818.                 correlataDaUnAltraAzione = tot>0;
  1819.                 this.driver.logDebug("VERIFICO CHE NON SIA CORRELATA DA UN'ALTRA AZIONE (AS e AA con PT diverso), risultato ["+tot+"]: "+correlataDaUnAltraAzione);

  1820.                 if(correlataDaUnAltraAzione==false){
  1821.                     // Correlazione sullo stesso port type
  1822.                     sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  1823.                     sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE_AZIONI);
  1824.                     sqlQueryObject.addSelectCountField("id", "tot");
  1825.                     sqlQueryObject.addWhereCondition(CostantiDB.PORT_TYPE_AZIONI+".id<>?");
  1826.                     sqlQueryObject.addWhereCondition(true,CostantiDB.PORT_TYPE_AZIONI+".correlata =?",CostantiDB.PORT_TYPE_AZIONI+".correlata_servizio is null",CostantiDB.PORT_TYPE_AZIONI+".id_port_type = ?");
  1827.                     sqlQueryObject.setANDLogicOperator(true);
  1828.                     queryString = sqlQueryObject.createSQLQuery();
  1829.                     stmt = con.prepareStatement(queryString);
  1830.                     this.driver.logDebug("VERIFICO CHE NON SIA CORRELATA DA UN'ALTRA AZIONE (AA con stesso port type) ["+idAzioneDaVerificare+"] ["+azioneDaVerificare+"] ["+nomePortType+"] ["+azioneDaVerificare+"] ["+idPortType+"]: "+queryString);
  1831.                     stmt.setLong(1, idAzioneDaVerificare);
  1832.                     stmt.setString(2, azioneDaVerificare);
  1833.                     stmt.setLong(3, idPortType);
  1834.                     risultato = stmt.executeQuery();
  1835.                     tot=0;
  1836.                     if (risultato.next()) {
  1837.                         tot=risultato.getInt("tot");
  1838.                     }
  1839.                     risultato.close();
  1840.                     stmt.close();
  1841.                     correlataDaUnAltraAzione = tot>0;
  1842.                     this.driver.logDebug("VERIFICO CHE NON SIA CORRELATA DA UN'ALTRA AZIONE (AA con stesso port type), risultato ["+tot+"]: "+correlataDaUnAltraAzione);
  1843.                 }
  1844.             }

  1845.             if(correlataAdUnaRichiesta){
  1846.                 return true;
  1847.             }
  1848.             else if(correlataDaUnAltraAzione){
  1849.                 return true;
  1850.             }
  1851.             else{
  1852.                 return false;
  1853.             }

  1854.         } catch (Exception se) {

  1855.             throw new DriverRegistroServiziException("[DriverRegistroServiziDB::" + nomeMetodo + "] Exception: " + se.getMessage(),se);
  1856.         } finally {
  1857.             //Chiudo statement and resultset
  1858.             JDBCUtilities.closeResources(risultato, stmt);
  1859.            
  1860.             this.driver.closeConnection(con);
  1861.         }
  1862.     }
  1863.    
  1864.     protected PortType getPortType(IDPortType idPT) throws DriverRegistroServiziException {
  1865.         String nomeMetodo = "getPortType";

  1866.         Connection con = null;

  1867.         if (this.driver.atomica) {
  1868.             try {
  1869.                 con = this.driver.getConnectionFromDatasource("getPortType");

  1870.             } catch (Exception e) {
  1871.                 throw new DriverRegistroServiziException("[DriverRegistroServiziDB::" + nomeMetodo + "] Exception accedendo al datasource :" + e.getMessage(), e);

  1872.             }

  1873.         } else {
  1874.             con = this.driver.globalConnection;
  1875.         }

  1876.         this.driver.logDebug("operazione this.driver.atomica = " + this.driver.atomica);

  1877.         try {
  1878.        
  1879.             return this.getPortType(DBUtils.getIdPortType(DBUtils.getIdAccordoServizioParteComune(idPT.getIdAccordo(), con, this.driver.tipoDB), idPT.getNome(), con));
  1880.            
  1881.         } catch (Exception se) {
  1882.             throw new DriverRegistroServiziException("[DriverRegistroServiziException::" + nomeMetodo + "] Exception: " + se.getMessage(),se);
  1883.         } finally {
  1884.             // Chiudo statement and resultset
  1885.            
  1886.             this.driver.closeConnection(con);
  1887.         }
  1888.        
  1889.     }


  1890.     protected List<IDServizio> getIdServiziWithPortType(IDPortType idPT) throws DriverRegistroServiziException,DriverRegistroServiziNotFound {
  1891.         String nomeMetodo = "getIdServiziWithPortType";

  1892.         Connection con = null;
  1893.         PreparedStatement stmt = null;
  1894.         ResultSet rs = null;
  1895.         String queryString;

  1896.         if (this.driver.atomica) {
  1897.             try {
  1898.                 con = this.driver.getConnectionFromDatasource("getIdServiziWithPortType");

  1899.             } catch (Exception e) {
  1900.                 throw new DriverRegistroServiziException("[DriverRegistroServiziDB::" + nomeMetodo + "] Exception accedendo al datasource :" + e.getMessage(), e);

  1901.             }

  1902.         } else {
  1903.             con = this.driver.globalConnection;
  1904.         }

  1905.         this.driver.logDebug("operazione this.driver.atomica = " + this.driver.atomica);

  1906.         List<IDServizio> idServizi = new ArrayList<IDServizio>();
  1907.         try {

  1908.             //recupero idAccordo
  1909.             long idAccordoLong = DBUtils.getIdAccordoServizioParteComune(idPT.getIdAccordo(), con, this.driver.tipoDB);
  1910.             // Controllo che il pdd non sia in uso
  1911.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  1912.             sqlQueryObject.addFromTable(CostantiDB.SERVIZI);
  1913.             sqlQueryObject.addFromTable(CostantiDB.SOGGETTI);
  1914.             sqlQueryObject.addSelectField("nome_servizio");
  1915.             sqlQueryObject.addSelectField("tipo_servizio");
  1916.             sqlQueryObject.addSelectField("versione_servizio");
  1917.             sqlQueryObject.addSelectField("nome_soggetto");
  1918.             sqlQueryObject.addSelectField("tipo_soggetto");
  1919.             sqlQueryObject.setANDLogicOperator(true);
  1920.             sqlQueryObject.addWhereCondition(CostantiDB.SERVIZI+".id_accordo=?");
  1921.             sqlQueryObject.addWhereCondition(CostantiDB.SERVIZI+".port_type=?");
  1922.             sqlQueryObject.addWhereCondition(CostantiDB.SERVIZI+".id_soggetto="+CostantiDB.SOGGETTI+".id");
  1923.             queryString = sqlQueryObject.createSQLQuery();
  1924.             stmt = con.prepareStatement(queryString);
  1925.             stmt.setLong(1, idAccordoLong);
  1926.             stmt.setString(2, idPT.getNome());

  1927.             rs = stmt.executeQuery();
  1928.             while (rs.next()) {
  1929.                 IDSoggetto soggettoErogatore = new IDSoggetto(rs.getString("tipo_soggetto"), rs.getString("nome_soggetto"));
  1930.                 IDServizio idServizio =
  1931.                         this.driver.idServizioFactory.getIDServizioFromValues(rs.getString("tipo_servizio"),
  1932.                                 rs.getString("nome_servizio"), soggettoErogatore, rs.getInt("versione_servizio"));
  1933.                 idServizi.add(idServizio);
  1934.             }

  1935.             if(idServizi.size()<=0){
  1936.                 throw new DriverRegistroServiziNotFound("Servizi non trovato che implementano il servizio "+idPT.getNome()+" dell'accordo di servizio "+idPT.getIdAccordo().toString());
  1937.             }
  1938.             else{
  1939.                 return idServizi;
  1940.             }

  1941.         }catch(DriverRegistroServiziNotFound dNot){
  1942.             throw dNot;
  1943.         }catch (Exception se) {
  1944.             throw new DriverRegistroServiziException("[DriverRegistroServiziException::" + nomeMetodo + "] Exception: " + se.getMessage(),se);
  1945.         } finally {
  1946.             // Chiudo statement and resultset
  1947.             JDBCUtilities.closeResources(rs, stmt);
  1948.            
  1949.             this.driver.closeConnection(con);
  1950.         }
  1951.     }
  1952.    
  1953.     protected boolean isUnicaAzioneInAccordi(String azione) throws DriverRegistroServiziException {
  1954.         String nomeMetodo = "isUnicaAzioneInAccordi";

  1955.         Connection con = null;
  1956.         PreparedStatement stmt = null;
  1957.         ResultSet rs = null;
  1958.         String queryString;

  1959.         if (this.driver.atomica) {
  1960.             try {
  1961.                 con = this.driver.getConnectionFromDatasource("isUnicaAzioneInAccordi");

  1962.             } catch (Exception e) {
  1963.                 throw new DriverRegistroServiziException("[DriverRegistroServiziDB::" + nomeMetodo + "] Exception accedendo al datasource :" + e.getMessage(), e);

  1964.             }

  1965.         } else {
  1966.             con = this.driver.globalConnection;
  1967.         }

  1968.         this.driver.logDebug("operazione this.atomica = " + this.driver.atomica);

  1969.         try {

  1970.             // AZIONI direttamente negli accordi
  1971.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  1972.             sqlQueryObject.addFromTable(CostantiDB.ACCORDI_AZIONI);
  1973.             sqlQueryObject.addSelectCountField("nome", "countAzioni");
  1974.             sqlQueryObject.addWhereCondition(CostantiDB.ACCORDI_AZIONI+".nome=?");
  1975.             queryString = sqlQueryObject.createSQLQuery();
  1976.             stmt = con.prepareStatement(queryString);
  1977.             stmt.setString(1, azione);
  1978.             rs = stmt.executeQuery();
  1979.             int count = 0;
  1980.             if(rs.next()){
  1981.                 count = rs.getInt("countAzioni");
  1982.             }
  1983.             else{
  1984.                 throw new Exception("Azione ["+azione+"] non trovata (rs.next fallita)");
  1985.             }
  1986.             rs.close();
  1987.             stmt.close();

  1988.             // AZIONI dei port types
  1989.             sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.driver.tipoDB);
  1990.             sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE_AZIONI);
  1991.             sqlQueryObject.addSelectCountField("nome", "countAzioni");
  1992.             sqlQueryObject.addWhereCondition(CostantiDB.PORT_TYPE_AZIONI+".nome=?");
  1993.             queryString = sqlQueryObject.createSQLQuery();
  1994.             stmt = con.prepareStatement(queryString);
  1995.             stmt.setString(1, azione);
  1996.             rs = stmt.executeQuery();
  1997.             if(rs.next()){
  1998.                 count = count + rs.getInt("countAzioni");
  1999.             }
  2000.             else{
  2001.                 throw new Exception("Azione ["+azione+"] non trovata (rs.next fallita pt)");
  2002.             }

  2003.             if(count<=0){
  2004.                 throw new Exception("Azione ["+azione+"] non trovata");
  2005.             }else{
  2006.                 return count==1;
  2007.             }

  2008.         }catch (Exception se) {
  2009.             throw new DriverRegistroServiziException("[DriverRegistroServiziException::" + nomeMetodo + "] Exception: " + se.getMessage(),se);
  2010.         } finally {
  2011.             // Chiudo statement and resultset
  2012.             JDBCUtilities.closeResources(rs, stmt);
  2013.            
  2014.             this.driver.closeConnection(con);
  2015.         }
  2016.     }
  2017. }