GestorePdDThread.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.web.ctrlstat.gestori;

  21. import java.sql.Connection;
  22. import java.sql.Timestamp;
  23. import java.util.ArrayList;
  24. import java.util.List;

  25. import javax.jms.JMSException;
  26. import javax.jms.ObjectMessage;
  27. import javax.jms.Queue;
  28. import javax.jms.QueueConnection;
  29. import javax.jms.QueueConnectionFactory;
  30. import javax.jms.QueueReceiver;
  31. import javax.jms.QueueSession;
  32. import javax.xml.ws.BindingProvider;

  33. import org.openspcoop2.core.config.IdPortaApplicativa;
  34. import org.openspcoop2.core.config.IdPortaDelegata;
  35. import org.openspcoop2.core.config.IdServizioApplicativo;
  36. import org.openspcoop2.core.config.IdSoggetto;
  37. import org.openspcoop2.core.config.PortaApplicativa;
  38. import org.openspcoop2.core.config.PortaDelegata;
  39. import org.openspcoop2.core.config.ServizioApplicativo;
  40. import org.openspcoop2.core.config.Soggetto;
  41. import org.openspcoop2.core.config.driver.DriverConfigurazioneNotFound;
  42. import org.openspcoop2.core.config.ws.client.portaapplicativa.all.PortaApplicativaSoap11Service;
  43. import org.openspcoop2.core.config.ws.client.portadelegata.all.PortaDelegataSoap11Service;
  44. import org.openspcoop2.core.config.ws.client.servizioapplicativo.all.ServizioApplicativoSoap11Service;
  45. import org.openspcoop2.core.config.ws.client.soggetto.all.SoggettoSoap11Service;
  46. import org.openspcoop2.core.id.IDPortaApplicativa;
  47. import org.openspcoop2.core.id.IDPortaDelegata;
  48. import org.openspcoop2.core.id.IDServizioApplicativo;
  49. import org.openspcoop2.core.id.IDSoggetto;
  50. import org.openspcoop2.pdd.config.OpenSPCoop2ConfigurationException;
  51. import org.openspcoop2.utils.Utilities;
  52. import org.openspcoop2.utils.transport.jms.ExceptionListenerJMS;
  53. import org.openspcoop2.web.ctrlstat.config.ConsoleProperties;
  54. import org.openspcoop2.web.ctrlstat.config.DatasourceProperties;
  55. import org.openspcoop2.web.ctrlstat.core.ControlStationCoreException;
  56. import org.openspcoop2.web.ctrlstat.core.ControlStationLogger;
  57. import org.openspcoop2.web.ctrlstat.core.DBManager;
  58. import org.openspcoop2.web.ctrlstat.core.QueueManager;
  59. import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
  60. import org.openspcoop2.web.ctrlstat.costanti.OperationsParameter;
  61. import org.openspcoop2.web.ctrlstat.costanti.TipoOggettoDaSmistare;
  62. import org.openspcoop2.web.ctrlstat.dao.PdDControlStation;
  63. import org.openspcoop2.web.ctrlstat.servlet.pa.PorteApplicativeCore;
  64. import org.openspcoop2.web.ctrlstat.servlet.pd.PorteDelegateCore;
  65. import org.openspcoop2.web.ctrlstat.servlet.pdd.PddCore;
  66. import org.openspcoop2.web.ctrlstat.servlet.sa.ServiziApplicativiCore;
  67. import org.openspcoop2.web.ctrlstat.servlet.soggetti.SoggettiCore;
  68. import org.openspcoop2.web.lib.queue.ClassQueue;
  69. import org.openspcoop2.web.lib.queue.ClassQueueException;
  70. import org.openspcoop2.web.lib.queue.costanti.OperationStatus;
  71. import org.openspcoop2.web.lib.queue.costanti.Operazione;
  72. import org.openspcoop2.web.lib.queue.costanti.TipoOperazione;
  73. import org.openspcoop2.web.lib.queue.dao.FilterParameter;
  74. import org.openspcoop2.web.lib.queue.dao.Operation;
  75. import org.openspcoop2.web.lib.queue.dao.Parameter;
  76. import org.slf4j.Logger;

  77. /**
  78.  * GestorePdDThread
  79.  *
  80.  * @author Andrea Poli (apoli@link.it)
  81.  * @author Stefano Corallo (corallo@link.it)
  82.  * @author Sandra Giangrandi (sandra@link.it)
  83.  * @author $Author$
  84.  * @version $Rev$, $Date$
  85.  *
  86.  */
  87. public class GestorePdDThread extends GestoreGeneral {

  88.     private ConsoleProperties consoleProperties;
  89.     private DatasourceProperties datasourceProperties;
  90.    
  91.     /** Logger utilizzato per debug. */
  92.     private Logger log = null;

  93.     /** run */
  94.     private boolean stop = false;
  95.     private boolean isRunning = false;
  96.     public boolean isRunning() {
  97.         return this.isRunning;
  98.     }

  99.     /** Back End Connector */
  100.     // private BackendConnector backEndConnector;
  101.     private PddCore pddCore;
  102.     private SoggettiCore soggettiCore;
  103.     private PorteApplicativeCore paCore;
  104.     private PorteDelegateCore pdCore;
  105.     private ServiziApplicativiCore saCore;

  106.     /** Nome della coda (che corrisponde al nome del pdd) */
  107.     private String pddName;

  108.     private String nomeThread;

  109.     // JMS
  110.     private QueueReceiver receiver = null;
  111.     private Queue queue = null;
  112.     private QueueConnectionFactory qcf = null;
  113.     private QueueConnection qc = null;
  114.     private QueueSession qs = null;

  115.     // DB
  116.     private DBManager dbm;
  117.     private Connection con;

  118.     private boolean singlePdD = false;

  119.     /** Web Service */
  120.     private org.openspcoop2.core.config.ws.client.portaapplicativa.all.PortaApplicativaSoap11Service portaApplicativaService;
  121.     private org.openspcoop2.core.config.ws.client.portadelegata.all.PortaDelegataSoap11Service portaDelegataService;
  122.     private org.openspcoop2.core.config.ws.client.servizioapplicativo.all.ServizioApplicativoSoap11Service servizioApplicativoService;
  123.     private org.openspcoop2.core.config.ws.client.soggetto.all.SoggettoSoap11Service soggettoService;
  124.    
  125.     private org.openspcoop2.core.config.ws.client.portaapplicativa.all.PortaApplicativa portaApplicativaPort;
  126.     private org.openspcoop2.core.config.ws.client.portadelegata.all.PortaDelegata portaDelegataPort;
  127.     private org.openspcoop2.core.config.ws.client.servizioapplicativo.all.ServizioApplicativo servizioApplicativoPort;
  128.     private org.openspcoop2.core.config.ws.client.soggetto.all.Soggetto soggettoPort;

  129.     private ExceptionListenerJMS exceptionListenerJMS = new ExceptionListenerJMS();

  130.     /** Costruttore
  131.      * @throws OpenSPCoop2ConfigurationException */
  132.     public GestorePdDThread(String nomeCoda) throws OpenSPCoop2ConfigurationException {

  133.         this.log = ControlStationLogger.getGestorePddLogger();

  134.         // setto il nome della coda
  135.         this.pddName = nomeCoda;

  136.         this.nomeThread = "GestorePDD[" + this.pddName + "]";
  137.        
  138.         this.consoleProperties = ConsoleProperties.getInstance();
  139.         this.datasourceProperties = DatasourceProperties.getInstance();

  140.     }

  141.     /**
  142.      * Metodo che fa partire il Thread.
  143.      *
  144.      * @since 0.4
  145.      */
  146.     @Override
  147.     public void run() {

  148.         this.isRunning = true;
  149.        
  150.         try {
  151.             this.initGestore();

  152.             if (this.singlePdD) {
  153.                 this.log.warn(this.nomeThread + " non avviato: govwayConsole avviata in singlePdD mode.");
  154.                 return;
  155.             }

  156.             this.dbm = DBManager.getInstance();
  157.         } catch (GestoreNonAttivoException e) {
  158.             this.log.warn("Inizializzazione Gestore non effettuata : " + e.getMessage());
  159.             this.stop = true;
  160.         } catch (Exception e) {
  161.             this.log.error("Inizializzazione Gestore Fallita : " + e.getMessage(), e);
  162.             this.stop = true;
  163.         }

  164.         // Avvio Gestione Pdd
  165.         boolean riconnessioneConErrore = false;
  166.         while (this.stop == false) {
  167.            
  168.             ClassQueue operationManager = null;
  169.             Operation operation = null;
  170.             try {

  171.                 // riconnessione precedente non riuscita.....
  172.                 if (riconnessioneConErrore) {
  173.                     throw new JMSException("RiconnessioneJMS non riuscita...");
  174.                 }

  175.                 // Controllo ExceptionListenerJMS
  176.                 if (this.exceptionListenerJMS.isConnessioneCorrotta()) {
  177.                     this.log.error("ExceptionJMSListener ha rilevato una connessione jms corrotta", this.exceptionListenerJMS.getException());
  178.                     throw new JMSException("ExceptionJMSListener ha rilevato una connessione jms corrotta: " + this.exceptionListenerJMS.getException().getMessage());
  179.                 }

  180.                 this.log.info(this.nomeThread + ": Ricezione operazione...");
  181.                 ObjectMessage richiesta = null;
  182.                 while (this.stop == false) {
  183.                     richiesta = (ObjectMessage) this.receiver.receive(CostantiControlStation.INTERVALLO_RECEIVE);
  184.                     if (richiesta != null) {
  185.                         break;
  186.                     }
  187.                 }
  188.                 if (this.stop == true) {
  189.                     break;
  190.                 }

  191.                 // Attendo tempi di delay (TransazioneSimilXA)
  192.                 Utilities.sleep(CostantiControlStation.INTERVALLO_TRANSAZIONE_XA);

  193.                 // Ricezione Operazione
  194.                 Object objOp;
  195.                 try {
  196.                     objOp = (Object) richiesta.getObject();
  197.                 } catch (Exception e) {
  198.                     this.log.error(this.nomeThread + ": Ricevuta richiesta con tipo errato:" + e.toString());
  199.                     this.qs.commit();
  200.                     continue;
  201.                 }
  202.                 String idOperazione = richiesta.getStringProperty("ID");

  203.                 int idOp = (int) Integer.parseInt(objOp.toString());
  204.                 if (idOp == 0) {
  205.                     this.log.error(this.nomeThread + ": Ricevuta richiesta con parametri scorretti.");
  206.                     this.qs.commit();
  207.                     continue;
  208.                 }

  209.                 this.log.info(CostantiControlStation.OPERATIONS_DELIMITER+"GestorePDD: Ricevuta richiesta di operazione con ID: " + idOperazione + " id_operation [" + idOp + "]");

  210.                 this.con = this.dbm.getConnection();

  211.                 // Prendo i dati dell'operazione
  212.                 String tipoOperazioneParam = "", tipoOperazioneCRUDParam = "", singleSu = "";
  213.                 int deleted = 0;
  214.                 operationManager = new ClassQueue(this.con, this.datasourceProperties.getTipoDatabase());
  215.                 try {
  216.                     operation = operationManager.getOperation(idOp);
  217.                 } catch (Exception e) {
  218.                     this.log.error("Impossibile recuperare l'operation con id=" + idOp, e);
  219.                     this.qs.rollback();
  220.                     this.dbm.releaseConnection(this.con);
  221.                     continue;
  222.                 }

  223.                 tipoOperazioneParam = operation.getTipo();
  224.                 tipoOperazioneCRUDParam = operation.getOperation();
  225.                 singleSu = operation.getSuperUser();
  226.                 deleted = operation.isDeleted() ? 1 : 0;

  227.                 // Operazione in gestione
  228.                 GestioneOperazione operazioneInGestione = new GestioneOperazione(this.dbm, this.con, this.qs, operation, operationManager, this.log, tipoOperazioneCRUDParam, this.nomeThread);

  229.                 // Oggetto in Gestione
  230.                 String oggettoDaSmistare = operation.getParameterValue(OperationsParameter.OGGETTO.getNome());
  231.                 if (oggettoDaSmistare == null || "".equals(oggettoDaSmistare)) {
  232.                     operazioneInGestione.invalid("Ricevuta operazione con parametri scorretti (oggetto:" + oggettoDaSmistare + ") non valida");
  233.                     continue;
  234.                 }
  235.                 TipoOggettoDaSmistare tipoOggettoDaSmistare = null;
  236.                 try{
  237.                     tipoOggettoDaSmistare = TipoOggettoDaSmistare.valueOf(oggettoDaSmistare);
  238.                     if(tipoOggettoDaSmistare==null){
  239.                         throw new Exception("Conversione in Enumeration non riuscita");
  240.                     }
  241.                 }catch(Exception e){
  242.                     this.log.error("Ricevuta operazione con parametri scorretti (oggetto:" + oggettoDaSmistare + ") non valida: "+e.getMessage(), e);
  243.                     operazioneInGestione.invalid("Ricevuta operazione con parametri scorretti (oggetto:" + oggettoDaSmistare + ") non valida: "+e.getMessage());
  244.                     continue;
  245.                 }

  246.                 // Check valori operazioni
  247.                 if ((tipoOperazioneParam == null) || tipoOperazioneParam.equals("") || (tipoOperazioneCRUDParam == null) || tipoOperazioneCRUDParam.equals("") || (singleSu == null) || singleSu.equals("")) {
  248.                     operazioneInGestione.invalid("Ricevuta operazione con parametri scorretti :" + operation.toString());
  249.                     continue;
  250.                 }
  251.                
  252.                 // Operazione CRUD      
  253.                 Operazione tipoOperazioneCRUD = null;
  254.                 try{
  255.                     tipoOperazioneCRUD = Operazione.valueOf(tipoOperazioneCRUDParam);
  256.                     if(tipoOperazioneCRUD==null){
  257.                         throw new Exception("Conversione in Enumeration non riuscita");
  258.                     }
  259.                 }catch(Exception e){
  260.                     this.log.error("Ricevuta operazione con parametri scorretti (tipoOperazioneCRUD:" + tipoOperazioneCRUDParam + ") non valida: "+e.getMessage(), e);
  261.                     operazioneInGestione.invalid("Ricevuta operazione con parametri scorretti (tipoOperazioneCRUD:" + tipoOperazioneCRUDParam + ") non valida: "+e.getMessage());
  262.                     continue;
  263.                 }
  264.                
  265.                 // Operazione Queue
  266.                 TipoOperazione tipoOperazione = null;
  267.                 try{
  268.                     tipoOperazione = TipoOperazione.valueOf(tipoOperazioneParam);
  269.                     if(tipoOperazione==null){
  270.                         throw new Exception("Conversione in Enumeration non riuscita");
  271.                     }
  272.                 }catch(Exception e){
  273.                     this.log.error("Ricevuta operazione con parametri scorretti (tipoOperazione:" + tipoOperazioneParam + ") non valida: "+e.getMessage(), e);
  274.                     operazioneInGestione.invalid("Ricevuta operazione con parametri scorretti (tipoOperazione:" + tipoOperazioneParam + ") non valida: "+e.getMessage());
  275.                     continue;
  276.                 }
  277.                

  278.                 this.log.debug("Ricevuta Operation:" + operation.toString());

  279.                 // ID Table
  280.                 int idTable = -1;
  281.                 String idTableString = null;
  282.                 try {
  283.                     idTableString = operation.getParameterValue(OperationsParameter.ID_TABLE.getNome());
  284.                     idTable = Integer.parseInt(idTableString);
  285.                     if (idTable <= 0)
  286.                         throw new Exception("IDTable <= 0");
  287.                 } catch (Exception e) {
  288.                     operazioneInGestione.invalid("Ricevuta operazione con parametri scorretti (idTable[" + idTableString + "]) non valida: " + e.getMessage());
  289.                     continue;
  290.                 }

  291.                 if (!TipoOggettoDaSmistare.soggetto.equals(tipoOggettoDaSmistare) &&
  292.                         !TipoOggettoDaSmistare.pa.equals(tipoOggettoDaSmistare) &&
  293.                         !TipoOggettoDaSmistare.pd.equals(tipoOggettoDaSmistare) &&
  294.                         !TipoOggettoDaSmistare.servizioApplicativo.equals(tipoOggettoDaSmistare)  ) {
  295.                     operazioneInGestione.invalid("Ricevuta operazione con parametri scorretti (oggetto:" + tipoOggettoDaSmistare.name() + ")");
  296.                     continue;
  297.                 }
  298.                

  299.                 /* ----- filtro per mantenimento ordine operazioni ----- */
  300.                 List<FilterParameter> filtroOrdine = new ArrayList<FilterParameter>();

  301.                 FilterParameter idTableFiltro = new FilterParameter();
  302.                 idTableFiltro.addFilterParameter(new Parameter(OperationsParameter.ID_TABLE.getNome(), idTable + ""));
  303.                 filtroOrdine.add(idTableFiltro);

  304.                 if (TipoOggettoDaSmistare.soggetto.equals(tipoOggettoDaSmistare)) {

  305.                     // Chiave primaria per il soggetto e' tipo e nome
  306.                     String tipoSoggFiltro = operation.getParameterValue(OperationsParameter.TIPO_SOGGETTO.getNome());
  307.                     String nomeSoggFiltro = operation.getParameterValue(OperationsParameter.NOME_SOGGETTO.getNome());
  308.                     FilterParameter soggettoFiltro = new FilterParameter();
  309.                     soggettoFiltro.addFilterParameter(new Parameter(OperationsParameter.TIPO_SOGGETTO.getNome(), tipoSoggFiltro));
  310.                     soggettoFiltro.addFilterParameter(new Parameter(OperationsParameter.NOME_SOGGETTO.getNome(), nomeSoggFiltro));
  311.                     filtroOrdine.add(soggettoFiltro);

  312.                     // OLD valori per tipo e nome se abbiamo una operazione di
  313.                     // change
  314.                     if (Operazione.change.equals(tipoOperazioneCRUD)) {
  315.                         String oldTipoSogg = operation.getParameterValue(OperationsParameter.OLD_TIPO_SOGGETTO.getNome());
  316.                         String oldNomeSogg = operation.getParameterValue(OperationsParameter.OLD_NOME_SOGGETTO.getNome());
  317.                         FilterParameter soggettoOldFiltro = new FilterParameter();
  318.                         soggettoOldFiltro.addFilterParameter(new Parameter(OperationsParameter.OLD_TIPO_SOGGETTO.getNome(), oldTipoSogg));
  319.                         soggettoOldFiltro.addFilterParameter(new Parameter(OperationsParameter.OLD_NOME_SOGGETTO.getNome(), oldNomeSogg));
  320.                         filtroOrdine.add(soggettoOldFiltro);
  321.                     }
  322.                 } else if (TipoOggettoDaSmistare.pa.equals(tipoOggettoDaSmistare)) {

  323.                     // Chiave primaria che identifica una pa sono il nome e il soggetto proprietario
  324.                     String nomePAFiltro = operation.getParameterValue(OperationsParameter.NOME_PA.getNome());
  325.                     String tipoSoggFiltro = operation.getParameterValue(OperationsParameter.TIPO_SOGGETTO.getNome());
  326.                     String nomeSoggFiltro = operation.getParameterValue(OperationsParameter.NOME_SOGGETTO.getNome());
  327.                     FilterParameter paFiltro = new FilterParameter();
  328.                     paFiltro.addFilterParameter(new Parameter(OperationsParameter.NOME_PA.getNome(), nomePAFiltro));
  329.                     paFiltro.addFilterParameter(new Parameter(OperationsParameter.TIPO_SOGGETTO.getNome(), tipoSoggFiltro));
  330.                     paFiltro.addFilterParameter(new Parameter(OperationsParameter.NOME_SOGGETTO.getNome(), nomeSoggFiltro));
  331.                     filtroOrdine.add(paFiltro);
  332.                    
  333.                     // OLD valori per tipo e nome soggetto proprietario o per
  334.                     // nome PA
  335.                     // se abbiamo una operazione di change
  336.                     if ((Operazione.change.equals(tipoOperazioneCRUD))) {
  337.                         String oldNomePAFiltro = operation.getParameterValue(OperationsParameter.OLD_NOME_PA.getNome());
  338.                         String oldTipoProprietarioFiltro = operation.getParameterValue(OperationsParameter.OLD_TIPO_SOGGETTO.getNome());
  339.                         String oldNomeProprietarioFiltro = operation.getParameterValue(OperationsParameter.OLD_NOME_SOGGETTO.getNome());

  340.                         FilterParameter proprietarioOldFiltro = new FilterParameter();
  341.                         proprietarioOldFiltro.addFilterParameter(new Parameter(OperationsParameter.NOME_PA.getNome(), nomePAFiltro));
  342.                         proprietarioOldFiltro.addFilterParameter(new Parameter(OperationsParameter.OLD_TIPO_SOGGETTO.getNome(), oldTipoProprietarioFiltro));
  343.                         proprietarioOldFiltro.addFilterParameter(new Parameter(OperationsParameter.OLD_NOME_SOGGETTO.getNome(), oldNomeProprietarioFiltro));
  344.                         filtroOrdine.add(proprietarioOldFiltro);

  345.                         FilterParameter nomeOldFiltro = new FilterParameter();
  346.                         nomeOldFiltro.addFilterParameter(new Parameter(OperationsParameter.OLD_NOME_PA.getNome(), oldNomePAFiltro));
  347.                         nomeOldFiltro.addFilterParameter(new Parameter(OperationsParameter.TIPO_SOGGETTO.getNome(), tipoSoggFiltro));
  348.                         nomeOldFiltro.addFilterParameter(new Parameter(OperationsParameter.NOME_SOGGETTO.getNome(), nomeSoggFiltro));
  349.                         filtroOrdine.add(nomeOldFiltro);

  350.                         FilterParameter oldFiltro = new FilterParameter();
  351.                         oldFiltro.addFilterParameter(new Parameter(OperationsParameter.OLD_NOME_PA.getNome(), oldNomePAFiltro));
  352.                         oldFiltro.addFilterParameter(new Parameter(OperationsParameter.OLD_TIPO_SOGGETTO.getNome(), oldTipoProprietarioFiltro));
  353.                         oldFiltro.addFilterParameter(new Parameter(OperationsParameter.OLD_NOME_SOGGETTO.getNome(), oldNomeProprietarioFiltro));
  354.                         filtroOrdine.add(oldFiltro);
  355.                     }
  356.                    
  357.                 } else if (TipoOggettoDaSmistare.pd.equals(tipoOggettoDaSmistare)) {

  358.                     // Chiave primaria che identifica una pd sono il nome e il soggetto proprietario
  359.                     String nomePDFiltro = operation.getParameterValue(OperationsParameter.NOME_PD.getNome());
  360.                     String tipoSoggFiltro = operation.getParameterValue(OperationsParameter.TIPO_SOGGETTO.getNome());
  361.                     String nomeSoggFiltro = operation.getParameterValue(OperationsParameter.NOME_SOGGETTO.getNome());
  362.                     FilterParameter pdFiltro = new FilterParameter();
  363.                     pdFiltro.addFilterParameter(new Parameter(OperationsParameter.NOME_PD.getNome(), nomePDFiltro));
  364.                     pdFiltro.addFilterParameter(new Parameter(OperationsParameter.TIPO_SOGGETTO.getNome(), tipoSoggFiltro));
  365.                     pdFiltro.addFilterParameter(new Parameter(OperationsParameter.NOME_SOGGETTO.getNome(), nomeSoggFiltro));
  366.                     filtroOrdine.add(pdFiltro);

  367.                     // OLD valori per tipo e nome soggetto proprietario o per
  368.                     // nome PD
  369.                     // se abbiamo una operazione di change
  370.                     if ((Operazione.change.equals(tipoOperazioneCRUD))) {
  371.                         String oldNomePDFiltro = operation.getParameterValue(OperationsParameter.OLD_NOME_PD.getNome());
  372.                         String oldTipoProprietarioFiltro = operation.getParameterValue(OperationsParameter.OLD_TIPO_SOGGETTO.getNome());
  373.                         String oldNomeProprietarioFiltro = operation.getParameterValue(OperationsParameter.OLD_NOME_SOGGETTO.getNome());

  374.                         FilterParameter proprietarioOldFiltro = new FilterParameter();
  375.                         proprietarioOldFiltro.addFilterParameter(new Parameter(OperationsParameter.NOME_PD.getNome(), nomePDFiltro));
  376.                         proprietarioOldFiltro.addFilterParameter(new Parameter(OperationsParameter.OLD_TIPO_SOGGETTO.getNome(), oldTipoProprietarioFiltro));
  377.                         proprietarioOldFiltro.addFilterParameter(new Parameter(OperationsParameter.OLD_NOME_SOGGETTO.getNome(), oldNomeProprietarioFiltro));
  378.                         filtroOrdine.add(proprietarioOldFiltro);

  379.                         FilterParameter nomeOldFiltro = new FilterParameter();
  380.                         nomeOldFiltro.addFilterParameter(new Parameter(OperationsParameter.OLD_NOME_PD.getNome(), oldNomePDFiltro));
  381.                         nomeOldFiltro.addFilterParameter(new Parameter(OperationsParameter.TIPO_SOGGETTO.getNome(), tipoSoggFiltro));
  382.                         nomeOldFiltro.addFilterParameter(new Parameter(OperationsParameter.NOME_SOGGETTO.getNome(), nomeSoggFiltro));
  383.                         filtroOrdine.add(nomeOldFiltro);

  384.                         FilterParameter oldFiltro = new FilterParameter();
  385.                         oldFiltro.addFilterParameter(new Parameter(OperationsParameter.OLD_NOME_PD.getNome(), oldNomePDFiltro));
  386.                         oldFiltro.addFilterParameter(new Parameter(OperationsParameter.OLD_TIPO_SOGGETTO.getNome(), oldTipoProprietarioFiltro));
  387.                         oldFiltro.addFilterParameter(new Parameter(OperationsParameter.OLD_NOME_SOGGETTO.getNome(), oldNomeProprietarioFiltro));
  388.                         filtroOrdine.add(oldFiltro);
  389.                     }
  390.                 } else if (TipoOggettoDaSmistare.servizioApplicativo.equals(tipoOggettoDaSmistare)) {

  391.                     // Chiave che indentifica il servizio applicativo sono nome
  392.                     // e soggetto proprietario
  393.                     String nomeServizioApplicativoFiltro = operation.getParameterValue(OperationsParameter.NOME_SERVIZIO_APPLICATIVO.getNome());
  394.                     String tipoSoggettoFiltro = operation.getParameterValue(OperationsParameter.TIPO_SOGGETTO.getNome());
  395.                     String nomeSoggettoFiltro = operation.getParameterValue(OperationsParameter.NOME_SOGGETTO.getNome());
  396.                     FilterParameter saFiltro = new FilterParameter();
  397.                     saFiltro.addFilterParameter(new Parameter(OperationsParameter.NOME_SERVIZIO_APPLICATIVO.getNome(), nomeServizioApplicativoFiltro));
  398.                     saFiltro.addFilterParameter(new Parameter(OperationsParameter.TIPO_SOGGETTO.getNome(), tipoSoggettoFiltro));
  399.                     saFiltro.addFilterParameter(new Parameter(OperationsParameter.NOME_SOGGETTO.getNome(), nomeSoggettoFiltro));
  400.                     filtroOrdine.add(saFiltro);

  401.                     // OLD valori per tipo e nome soggetto proprietario o per
  402.                     // nome ServizioApplicativo
  403.                     // se abbiamo una operazione di change
  404.                     if ((Operazione.change.equals(tipoOperazioneCRUD))) {
  405.                         String oldNomeSAFiltro = operation.getParameterValue(OperationsParameter.OLD_NOME_SERVIZIO_APPLICATIVO.getNome());
  406.                         String oldTipoProprietarioFiltro = operation.getParameterValue(OperationsParameter.OLD_TIPO_SOGGETTO.getNome());
  407.                         String oldNomeProprietarioFiltro = operation.getParameterValue(OperationsParameter.OLD_NOME_SOGGETTO.getNome());

  408.                         FilterParameter proprietarioOldFiltro = new FilterParameter();
  409.                         proprietarioOldFiltro.addFilterParameter(new Parameter(OperationsParameter.NOME_SERVIZIO_APPLICATIVO.getNome(), nomeServizioApplicativoFiltro));
  410.                         proprietarioOldFiltro.addFilterParameter(new Parameter(OperationsParameter.OLD_TIPO_SOGGETTO.getNome(), oldTipoProprietarioFiltro));
  411.                         proprietarioOldFiltro.addFilterParameter(new Parameter(OperationsParameter.OLD_NOME_SOGGETTO.getNome(), oldNomeProprietarioFiltro));
  412.                         filtroOrdine.add(proprietarioOldFiltro);

  413.                         FilterParameter nomeOldFiltro = new FilterParameter();
  414.                         nomeOldFiltro.addFilterParameter(new Parameter(OperationsParameter.OLD_NOME_SERVIZIO_APPLICATIVO.getNome(), oldNomeSAFiltro));
  415.                         nomeOldFiltro.addFilterParameter(new Parameter(OperationsParameter.TIPO_SOGGETTO.getNome(), tipoSoggettoFiltro));
  416.                         nomeOldFiltro.addFilterParameter(new Parameter(OperationsParameter.NOME_SOGGETTO.getNome(), nomeSoggettoFiltro));
  417.                         filtroOrdine.add(nomeOldFiltro);

  418.                         FilterParameter oldFiltro = new FilterParameter();
  419.                         oldFiltro.addFilterParameter(new Parameter(OperationsParameter.OLD_NOME_SERVIZIO_APPLICATIVO.getNome(), oldNomeSAFiltro));
  420.                         oldFiltro.addFilterParameter(new Parameter(OperationsParameter.OLD_TIPO_SOGGETTO.getNome(), oldTipoProprietarioFiltro));
  421.                         oldFiltro.addFilterParameter(new Parameter(OperationsParameter.OLD_NOME_SOGGETTO.getNome(), oldNomeProprietarioFiltro));
  422.                         filtroOrdine.add(oldFiltro);
  423.                     }
  424.                    
  425.                 } else {
  426.                     operazioneInGestione.invalid("Ricevuta operazione con oggetto non conosciuto dal Gestore (oggetto:" + tipoOggettoDaSmistare.name() + ")");
  427.                     continue;
  428.                 }

  429.                 operationManager.setOperazioniPrecedentiByFilterSearch(operation, filtroOrdine.toArray(new FilterParameter[0]), false, tipoOggettoDaSmistare.name());
  430.                 if (operation.sizeOperazioniPrecedentiAncoraDaGestireList() > 0) {
  431.                     StringBuilder operazioniPrecedenti = new StringBuilder();
  432.                     for (int i = 0; i < operation.sizeOperazioniPrecedentiAncoraDaGestireList(); i++) {
  433.                         operazioniPrecedenti.append("\n" + operation.getOperazionePrecedenteAncoraDaGestire(i).toString());
  434.                     }
  435.                     operazioneInGestione.error("Ricevuta operazione su una entita' di cui esistono operazioni attivate precedentementi ancora in coda:\n" + operazioniPrecedenti.toString());
  436.                     continue;
  437.                 }

  438.                 /* ----- Fine filtro per mantenimento ordine operazioni ----- */

  439.                 // Se l'operazione e' stata marcata come deleted, la rimuovo
  440.                 // dalla coda (basta fare il commit)
  441.                 String statoOperazioneCancellata = "";
  442.                 if (deleted == 1) {

  443.                     operazioneInGestione.delete();
  444.                     statoOperazioneCancellata = " (L'operazione non e' stata propagata, possiede una stato 'deleted')";

  445.                 } else {

  446.                     // Effettuo filtro di altre modifiche con stesso
  447.                     // idOperazione
  448.                     if (Operazione.change.equals(tipoOperazioneCRUD)) {
  449.                        
  450.                         List<Operation> listFilteredOperations = filterOperations(idOperazione, operationManager, operation, this.qs, this.queue, this.log);

  451.                         if (listFilteredOperations.size() > 0) {
  452.                             StringBuilder bf = new StringBuilder();
  453.                             for (Operation operationFiltered : listFilteredOperations) {
  454.                                 if(bf.length()>0){
  455.                                     bf.append(",");
  456.                                 }
  457.                                 bf.append(operationFiltered.getId());
  458.                             }
  459.                             this.log.debug(getName() + ": Filtrate [" + listFilteredOperations.size() + "] operation con stessa property jms ['ID'="+idOperazione+"] (ids: "+bf.toString()+")");
  460.                         }
  461.                     }


  462.                     // OPERAZIONE CHE RIGUARDA IL SOGGETTO
  463.                     if (TipoOggettoDaSmistare.soggetto.equals(tipoOggettoDaSmistare)) {

  464.                         String oldTipoSoggetto = operation.getParameterValue(OperationsParameter.OLD_TIPO_SOGGETTO.getNome());
  465.                         String oldNomeSoggetto = operation.getParameterValue(OperationsParameter.OLD_NOME_SOGGETTO.getNome());
  466.                         String tipoSogg = operation.getParameterValue(OperationsParameter.TIPO_SOGGETTO.getNome());
  467.                         String nomeSogg = operation.getParameterValue(OperationsParameter.NOME_SOGGETTO.getNome());

  468.                         // Ottengo nuova immagine del soggetto
  469.                         // Soggetto soggetto = null;
  470.                         Soggetto soggetto = null;

  471.                         try {
  472.                             // soggetto =
  473.                             // backEndConnector.getDatiSoggetto(idTable);
  474.                             if (Operazione.add.equals(tipoOperazioneCRUD)) {

  475.                                 try {
  476.                                     soggetto = this.soggettiCore.getSoggetto(idTable);
  477.                                 } catch (DriverConfigurazioneNotFound de) {
  478.                                     operazioneInGestione.waitBeforeInvalid("Soggetto non esistente nel database della govwayConsole: " + de.toString());
  479.                                     continue;
  480.                                 } catch (Exception e) {
  481.                                     operazioneInGestione.error("Riscontrato errore durante la get dell'immagine del soggetto: " + e.toString(), e);
  482.                                     continue;
  483.                                 }

  484.                                 this.soggettoPort.create(soggetto);

  485.                             } else if (Operazione.change.equals(tipoOperazioneCRUD)) {

  486.                                 try {
  487.                                     soggetto = this.soggettiCore.getSoggetto(idTable);
  488.                                 } catch (DriverConfigurazioneNotFound de) {
  489.                                     operazioneInGestione.waitBeforeInvalid("Soggetto non esistente nel database della govwayConsole: " + de.toString());
  490.                                     continue;
  491.                                 } catch (Exception e) {
  492.                                     operazioneInGestione.error("Riscontrato errore durante la get dell'immagine del soggetto: " + e.toString(), e);
  493.                                     continue;
  494.                                 }
  495.                                 if(oldTipoSoggetto!=null && oldNomeSoggetto!=null){
  496.                                     IDSoggetto oldIDSoggettoForUpdate = new IDSoggetto(oldTipoSoggetto, oldNomeSoggetto);
  497.                                     soggetto.setOldIDSoggettoForUpdate(oldIDSoggettoForUpdate);
  498.                                 }

  499.                                 IdSoggetto idSoggetto = new IdSoggetto();
  500.                                 if(oldTipoSoggetto!=null)
  501.                                     idSoggetto.setTipo(oldTipoSoggetto);
  502.                                 else
  503.                                     idSoggetto.setTipo(tipoSogg);
  504.                                 if(oldNomeSoggetto!=null)
  505.                                     idSoggetto.setNome(oldNomeSoggetto);
  506.                                 else
  507.                                     idSoggetto.setNome(nomeSogg);
  508.                                
  509.                                 this.soggettoPort.update(idSoggetto,soggetto);

  510.                             } else if (Operazione.del.equals(tipoOperazioneCRUD)) {
  511.                                
  512.                                 IdSoggetto idSoggetto = new IdSoggetto();
  513.                                 idSoggetto.setTipo(tipoSogg);
  514.                                 idSoggetto.setNome(nomeSogg);

  515.                                 this.soggettoPort.deleteById(idSoggetto);

  516.                             }

  517.                         } catch (Exception e) {
  518.                             soggetto = null;
  519.                             operazioneInGestione.error("Riscontrato errore durante operazione su soggetto: " + e.toString(), e);
  520.                             continue;
  521.                         }

  522.                     }

  523.                     // OPERAZIONE CHE RIGUARDA LA PORTA APPLICATIVA
  524.                     if (TipoOggettoDaSmistare.pa.equals(tipoOggettoDaSmistare)) {

  525.                         String nomePA = operation.getParameterValue(OperationsParameter.NOME_PA.getNome());
  526.                         String oldNomePA = operation.getParameterValue(OperationsParameter.OLD_NOME_PA.getNome());

  527.                         // Ottengo nuova immagine della porta applicativa
  528.                         PortaApplicativa pa = null;
  529.                         try {
  530.                             // pa = backEndConnector.getDatiPA(idTable);
  531.                             if (Operazione.add.equals(tipoOperazioneCRUD)) {

  532.                                 try {
  533.                                     pa = this.paCore.getPortaApplicativa(idTable);
  534.                                 } catch (DriverConfigurazioneNotFound de) {
  535.                                     operazioneInGestione.waitBeforeInvalid("Porta Applicativa non esistente nel database della govwayConsole: " + de.toString());
  536.                                     continue;
  537.                                 } catch (Exception e) {
  538.                                     operazioneInGestione.error("Riscontrato errore durante la get dell'immagine della Porta Applicativa: " + e.toString(), e);
  539.                                     continue;
  540.                                 }

  541.                                 this.portaApplicativaPort.create(pa);

  542.                             } else if (Operazione.change.equals(tipoOperazioneCRUD)) {

  543.                                 try {
  544.                                     pa = this.paCore.getPortaApplicativa(idTable);
  545.                                 } catch (DriverConfigurazioneNotFound de) {
  546.                                     operazioneInGestione.waitBeforeInvalid("Porta Applicativa non esistente nel database della govwayConsole: " + de.toString());
  547.                                     continue;
  548.                                 } catch (Exception e) {
  549.                                     operazioneInGestione.error("Riscontrato errore durante la get dell'immagine della Porta Applicativa: " + e.toString(), e);
  550.                                     continue;
  551.                                 }

  552.                                 // soggetto proprietario
  553.                                 Soggetto soggettoProprietario = null;
  554.                                 try {
  555.                                     soggettoProprietario = this.soggettiCore.getSoggetto(pa.getIdSoggetto());
  556.                                 } catch (DriverConfigurazioneNotFound de) {
  557.                                     operazioneInGestione.waitBeforeInvalid("Soggetto proprietario non esistente nel database della govwayConsole: " + de.toString());
  558.                                     continue;
  559.                                 } catch (Exception e) {
  560.                                     operazioneInGestione.error("Riscontrato errore durante la get dell'immagine del Soggetto proprietario: " + e.toString(), e);
  561.                                     continue;
  562.                                 }
  563.                                 pa.setTipoSoggettoProprietario(soggettoProprietario.getTipo());
  564.                                 pa.setNomeSoggettoProprietario(soggettoProprietario.getNome());
  565.                                
  566.                                 // vecchi dati per update
  567.                                 if(oldNomePA!=null){
  568.                                     IDPortaApplicativa oldIDPortaApplicativaForUpdate = new IDPortaApplicativa();
  569.                                     oldIDPortaApplicativaForUpdate.setNome(oldNomePA);
  570.                                     pa.setOldIDPortaApplicativaForUpdate(oldIDPortaApplicativaForUpdate);
  571.                                 }
  572.                                
  573.                                 IdPortaApplicativa idPA = new IdPortaApplicativa();
  574.                                 if(oldNomePA!=null){
  575.                                     idPA.setNome(oldNomePA);
  576.                                 }
  577.                                 else{
  578.                                     idPA.setNome(pa.getNome());
  579.                                 }
  580.                                
  581.                                 this.portaApplicativaPort.update(idPA, pa);
  582.                                
  583.                             } else if (Operazione.del.equals(tipoOperazioneCRUD)) {

  584.                                 IdPortaApplicativa idPA = new IdPortaApplicativa();
  585.                                 idPA.setNome(nomePA);
  586.                                 this.portaApplicativaPort.deleteById(idPA);

  587.                             }
  588.                         } catch (Exception e) {
  589.                             operazioneInGestione.error("Riscontrato errore durante operazione su Porta Applicativa: " + e.toString(), e);
  590.                             continue;
  591.                         }

  592.                     }

  593.                     // OPERAZIONE CHE RIGUARDA LA PORTA DELEGATA
  594.                     if (TipoOggettoDaSmistare.pd.equals(tipoOggettoDaSmistare)) {

  595.                         String nomePD = operation.getParameterValue(OperationsParameter.NOME_PD.getNome());
  596.                         String oldNomePD = operation.getParameterValue(OperationsParameter.OLD_NOME_PD.getNome());
  597.                         // Ottengo nuova immagine della porta delegata
  598.                         PortaDelegata pd = null;
  599.                         try {
  600.                             // pd = backEndConnector.getDatiPD(idTable);

  601.                             if (Operazione.add.equals(tipoOperazioneCRUD)) {

  602.                                 try {
  603.                                     pd = this.pdCore.getPortaDelegata(idTable);
  604.                                 } catch (DriverConfigurazioneNotFound de) {
  605.                                     operazioneInGestione.waitBeforeInvalid("Porta Delegata non esistente nel database della govwayConsole: " + de.toString());
  606.                                     continue;
  607.                                 } catch (Exception e) {
  608.                                     operazioneInGestione.error("Riscontrato errore durante la get dell'immagine della Porta Delegata: " + e.toString(), e);
  609.                                     continue;
  610.                                 }

  611.                                 Soggetto soggettoProprietario = null;
  612.                                 try {
  613.                                     soggettoProprietario = this.soggettiCore.getSoggetto(pd.getIdSoggetto());
  614.                                 } catch (DriverConfigurazioneNotFound de) {
  615.                                     operazioneInGestione.waitBeforeInvalid("Soggetto proprietario non esistente nel database della govwayConsole: " + de.toString());
  616.                                     continue;
  617.                                 } catch (Exception e) {
  618.                                     operazioneInGestione.error("Riscontrato errore durante la get dell'immagine del Soggetto proprietario: " + e.toString(), e);
  619.                                     continue;
  620.                                 }

  621.                                 pd.setTipoSoggettoProprietario(soggettoProprietario.getTipo());
  622.                                 pd.setNomeSoggettoProprietario(soggettoProprietario.getNome());

  623.                                 this.portaDelegataPort.create(pd);

  624.                             } else if (Operazione.change.equals(tipoOperazioneCRUD)) {

  625.                                 try {
  626.                                     pd = this.pdCore.getPortaDelegata(idTable);
  627.                                 } catch (DriverConfigurazioneNotFound de) {
  628.                                     operazioneInGestione.waitBeforeInvalid("Porta Delegata non esistente nel database della govwayConsole: " + de.toString());
  629.                                     continue;
  630.                                 } catch (Exception e) {
  631.                                     operazioneInGestione.error("Riscontrato errore durante la get dell'immagine della Porta Delegata: " + e.toString(), e);
  632.                                     continue;
  633.                                 }

  634.                                 // soggetto proprietario
  635.                                 Soggetto soggettoProprietario = null;
  636.                                 try {
  637.                                     soggettoProprietario = this.soggettiCore.getSoggetto(pd.getIdSoggetto());
  638.                                 } catch (DriverConfigurazioneNotFound de) {
  639.                                     operazioneInGestione.waitBeforeInvalid("Soggetto proprietario non esistente nel database della govwayConsole: " + de.toString());
  640.                                     continue;
  641.                                 } catch (Exception e) {
  642.                                     operazioneInGestione.error("Riscontrato errore durante la get dell'immagine del Soggetto proprietario: " + e.toString(), e);
  643.                                     continue;
  644.                                 }
  645.                                 pd.setTipoSoggettoProprietario(soggettoProprietario.getTipo());
  646.                                 pd.setNomeSoggettoProprietario(soggettoProprietario.getNome());
  647.                                
  648.                                 // vecchi dati per update
  649.                                 if(oldNomePD!=null){
  650.                                     IDPortaDelegata oldIDPortaDelegataForUpdate = new IDPortaDelegata();
  651.                                     oldIDPortaDelegataForUpdate.setNome(oldNomePD);
  652.                                     pd.setOldIDPortaDelegataForUpdate(oldIDPortaDelegataForUpdate);
  653.                                 }
  654.                                
  655.                                 IdPortaDelegata idPD = new IdPortaDelegata();
  656.                                 if(oldNomePD!=null){
  657.                                     idPD.setNome(oldNomePD);
  658.                                 }
  659.                                 else{
  660.                                     idPD.setNome(pd.getNome());
  661.                                 }
  662.                                
  663.                                 this.portaDelegataPort.update(idPD, pd);


  664.                             } else if (Operazione.del.equals(tipoOperazioneCRUD)) {

  665.                                 IdPortaDelegata idPD = new IdPortaDelegata();
  666.                                 idPD.setNome(nomePD);
  667.                                
  668.                                 this.portaDelegataPort.deleteById(idPD);
  669.                                
  670.                             }

  671.                         } catch (Exception e) {
  672.                             operazioneInGestione.error("Riscontrato errore durante operazione su Porta Delegata: " + e.toString(), e);
  673.                             continue;
  674.                         }

  675.                     }

  676.                     // OPERAZIONE CHE RIGUARDA IL SERVIZIOAPPLICATIVO
  677.                     if (TipoOggettoDaSmistare.servizioApplicativo.equals(tipoOggettoDaSmistare)) {

  678.                         String nomeServizioApplicativo = operation.getParameterValue(OperationsParameter.NOME_SERVIZIO_APPLICATIVO.getNome());
  679.                         String oldNomeServizioApplicativo = operation.getParameterValue(OperationsParameter.OLD_NOME_SERVIZIO_APPLICATIVO.getNome());
  680.                         String tipoSoggetto = operation.getParameterValue(OperationsParameter.TIPO_SOGGETTO.getNome());
  681.                         String nomeSoggetto = operation.getParameterValue(OperationsParameter.NOME_SOGGETTO.getNome());
  682.                         String oldTipoSoggetto = operation.getParameterValue(OperationsParameter.OLD_TIPO_SOGGETTO.getNome());
  683.                         String oldNomeSoggetto = operation.getParameterValue(OperationsParameter.OLD_NOME_SOGGETTO.getNome());

  684.                         // Ottengo nuova immagine del servizioApplicativo
  685.                         ServizioApplicativo servizioApplicativo = null;
  686.                         try {
  687.                             // s =
  688.                             // backEndConnector.getDatiServizioApplicativo(idTable);

  689.                             if (Operazione.add.equals(tipoOperazioneCRUD)) {

  690.                                 try {
  691.                                     servizioApplicativo = this.saCore.getServizioApplicativo(idTable);
  692.                                 } catch (DriverConfigurazioneNotFound de) {
  693.                                     operazioneInGestione.waitBeforeInvalid("Servizio Applicativo non esistente nel database della govwayConsole: " + de.toString());
  694.                                     continue;
  695.                                 } catch (Exception e) {
  696.                                     operazioneInGestione.error("Riscontrato errore durante la get dell'immagine del Servizio Applicativo: " + e.toString(), e);
  697.                                     continue;
  698.                                 }

  699.                                 this.servizioApplicativoPort.create(servizioApplicativo);

  700.                             } else if (Operazione.change.equals(tipoOperazioneCRUD)) {

  701.                                 try {
  702.                                     servizioApplicativo = this.saCore.getServizioApplicativo(idTable);
  703.                                 } catch (DriverConfigurazioneNotFound de) {
  704.                                     operazioneInGestione.waitBeforeInvalid("Servizio Applicativo non esistente nel database della govwayConsole: " + de.toString());
  705.                                     continue;
  706.                                 } catch (Exception e) {
  707.                                     operazioneInGestione.error("Riscontrato errore durante la get dell'immagine del Servizio Applicativo: " + e.toString(), e);
  708.                                     continue;
  709.                                 }
  710.                                
  711.                                 IDServizioApplicativo oldIDServizioApplicativoForUpdate = new IDServizioApplicativo();
  712.                                 oldIDServizioApplicativoForUpdate.setIdSoggettoProprietario(new IDSoggetto());
  713.                                 servizioApplicativo.setOldIDServizioApplicativoForUpdate(oldIDServizioApplicativoForUpdate);
  714.                                
  715.                                 oldIDServizioApplicativoForUpdate.setNome(nomeServizioApplicativo);
  716.                                 if (tipoSoggetto != null && !tipoSoggetto.equals(""))
  717.                                     oldIDServizioApplicativoForUpdate.getIdSoggettoProprietario().setTipo(tipoSoggetto);
  718.                                 if (nomeSoggetto != null && !nomeSoggetto.equals(""))
  719.                                     oldIDServizioApplicativoForUpdate.getIdSoggettoProprietario().setNome(nomeSoggetto);
  720.                                
  721.                                 // vecchi dati per update
  722.                                 oldIDServizioApplicativoForUpdate.setNome(oldNomeServizioApplicativo);
  723.                                
  724.                                 if(oldTipoSoggetto!=null && oldNomeSoggetto!=null){
  725.                                     // Check se operazione di change che  l'operazione di modifica del soggetto non sia ancora in rollback.
  726.                                     // Se sussite, aspetto l'operazione.
  727.                                     FilterParameter filtro = operazioneInGestione.getFilterChangeIDSoggetto(tipoSoggetto,
  728.                                             nomeSoggetto,oldTipoSoggetto,oldNomeSoggetto);                                      
  729.                                     if(operazioneInGestione.existsOperationNotCompleted("change", operation.getHostname(), filtro)){
  730.                                         oldIDServizioApplicativoForUpdate.getIdSoggettoProprietario().setTipo(oldTipoSoggetto);
  731.                                         oldIDServizioApplicativoForUpdate.getIdSoggettoProprietario().setNome(oldNomeSoggetto);
  732.                                         this.log.debug("ChangeServizioApplicativo: operazione change ID Soggetto non ancora completata: utilizzo OLD nome");
  733.                                     }else{
  734.                                         this.log.debug("ChangeServizioApplicativo: operazione change ID Soggetto completata: utilizzo nome");
  735.                                     }
  736.                                 }
  737.                                
  738.                                 IdServizioApplicativo idSA = new IdServizioApplicativo();
  739.                                 if(oldIDServizioApplicativoForUpdate!=null && oldIDServizioApplicativoForUpdate.getNome()!=null){
  740.                                     idSA.setNome(oldIDServizioApplicativoForUpdate.getNome());
  741.                                 }
  742.                                 else{
  743.                                     idSA.setNome(servizioApplicativo.getNome());
  744.                                 }
  745.                                 idSA.setIdSoggetto(new IdSoggetto());
  746.                                 if(oldIDServizioApplicativoForUpdate.getIdSoggettoProprietario()!=null &&
  747.                                         oldIDServizioApplicativoForUpdate.getIdSoggettoProprietario().getTipo()!=null){
  748.                                     idSA.getIdSoggetto().setTipo(oldIDServizioApplicativoForUpdate.getIdSoggettoProprietario().getTipo());
  749.                                 }
  750.                                 else{
  751.                                     idSA.getIdSoggetto().setTipo(servizioApplicativo.getTipoSoggettoProprietario());
  752.                                 }
  753.                                 if(oldIDServizioApplicativoForUpdate.getIdSoggettoProprietario()!=null &&
  754.                                         oldIDServizioApplicativoForUpdate.getIdSoggettoProprietario().getNome()!=null){
  755.                                     idSA.getIdSoggetto().setNome(oldIDServizioApplicativoForUpdate.getIdSoggettoProprietario().getNome());
  756.                                 }
  757.                                 else{
  758.                                     idSA.getIdSoggetto().setNome(servizioApplicativo.getNomeSoggettoProprietario());
  759.                                 }
  760.                                
  761.                                 this.servizioApplicativoPort.update(idSA, servizioApplicativo);

  762.                             } else if (Operazione.del.equals(tipoOperazioneCRUD)) {

  763.                                 IdServizioApplicativo idSA = new IdServizioApplicativo();
  764.                                 idSA.setNome(nomeServizioApplicativo);
  765.                                 idSA.setIdSoggetto(new IdSoggetto());
  766.                                 idSA.getIdSoggetto().setTipo(tipoSoggetto);
  767.                                 idSA.getIdSoggetto().setNome(nomeSoggetto);
  768.                                
  769.                                 this.servizioApplicativoPort.deleteById(idSA);

  770.                             }

  771.                         } catch (Exception e) {
  772.                             operazioneInGestione.error("Riscontrato errore durante operazione su Servizio Applicativo: " + e.toString(), e);
  773.                             continue;
  774.                         }

  775.                     }

  776.                     // Se arrivo qui, significa che l'operazione non ha dato
  777.                     // errore,
  778.                     // aggiorno il db
  779.                     operazioneInGestione.success("Done.");
  780.                 }

  781.                 this.log.info(this.nomeThread + ": Operazione [" + idOperazione + "] completata"+statoOperazioneCancellata);

  782.             } catch (JMSException e) {
  783.                 try {
  784.                     this.qs.rollback();
  785.                 } catch (Exception er) {
  786.                 }

  787.                 this.log.error(this.nomeThread + ": Riscontrato errore durante la gestione di una richiesta: " + e.toString());
  788.                 this.log.debug(this.nomeThread + " : Eccezione :", e);
  789.                 try {
  790.                     Utilities.sleep(5000);
  791.                     this.log.debug(this.nomeThread + ": Re-Inizializzazione Receiver ...");
  792.                     try {
  793.                         this.receiver.close();
  794.                     } catch (Exception eclose) {
  795.                     }
  796.                     try {
  797.                         this.qs.close();
  798.                     } catch (Exception eclose) {
  799.                     }
  800.                     try {
  801.                         this.qc.close();
  802.                     } catch (Exception eclose) {
  803.                     }
  804.                     this.qc = this.qcf.createQueueConnection();
  805.                     // Ripristino stato Exception Listener
  806.                     if (this.exceptionListenerJMS.isConnessioneCorrotta()) {
  807.                         this.exceptionListenerJMS.setConnessioneCorrotta(false);
  808.                         this.exceptionListenerJMS.setException(null);
  809.                     }
  810.                     this.qc.setExceptionListener(this.exceptionListenerJMS);
  811.                     this.qs = this.qc.createQueueSession(true, -1);
  812.                     this.receiver = this.qs.createReceiver(this.queue);
  813.                     this.qc.start();
  814.                     this.log.debug(this.nomeThread + ": Re-Inizializzazione Receiver effettuata.");
  815.                     riconnessioneConErrore = false;
  816.                 } catch (Exception er) {
  817.                     this.log.error(this.nomeThread + ": Re-Inizializzazione Receiver non effettuata:" + er.toString());
  818.                     riconnessioneConErrore = true;
  819.                 }
  820.             } catch (ClassQueueException e) {
  821.                 try {
  822.                     if(operation!=null) {
  823.                         operation.setStatus(OperationStatus.ERROR);
  824.                         operation.setDetails(e.toString());
  825.                         operation.setTimeExecute(new Timestamp(System.currentTimeMillis()));
  826.                         operationManager.updateOperation(operation);
  827.                     }
  828.                     this.qs.rollback();
  829.                 } catch (Exception er) {
  830.                 }
  831.                 this.log.error("GestorePdD-"+this.pddName+": Riscontrato errore durante operazione sulla coda: " + e.toString(), e);
  832.             } catch (Exception e) {
  833.                 try {
  834.                     this.qs.rollback();
  835.                 } catch (Exception er) {
  836.                 }

  837.                 this.log.error(this.nomeThread + ": Riscontrato errore durante la gestione di una richiesta: " + e.toString());
  838.                 this.log.debug(this.nomeThread + " : Eccezione :", e);
  839.             } finally {
  840.                 try {
  841.                     this.dbm.releaseConnection(this.con);
  842.                 } catch (Exception eLogger) {
  843.                 }
  844.             }
  845.         }

  846.         // Chiusura connessione
  847.         try {
  848.             if (this.receiver != null) {
  849.                 this.receiver.close();
  850.             }
  851.             if (this.qs != null) {
  852.                 this.qs.rollback();
  853.                 this.qs.close();
  854.             }
  855.             if (this.qc != null) {
  856.                 this.qc.stop();
  857.                 this.qc.close();
  858.             }
  859.         } catch (Exception e) {
  860.             try {
  861.                 this.log.error(this.nomeThread + ": Riscontrato errore durante la chiusura del Thread: " + e.toString());
  862.             } catch (Exception eLogger) {
  863.             }
  864.         }

  865.         this.isRunning = false;
  866.         this.log.debug(this.nomeThread +" Thread terminato");
  867.     }

  868.     @Override
  869.     public void initGestore() throws Exception {

  870.         // Controllo se dbmanager inizializzato
  871.         // Il DBManager viene inizializzato nell'InitListener
  872.         if (!DBManager.isInitialized()) {
  873.             this.log.info("Inizializzazione di " + this.getClass().getSimpleName() + " non riuscito perche' DBManager non INIZIALIZZATO");
  874.             throw new Exception("Inizializzazione di " + this.getClass().getSimpleName() + "FALLITA");
  875.         }
  876.        
  877.         String pddQueuePrefix = this.consoleProperties.getGestioneCentralizzataPrefissoNomeCodaConfigurazionePdd();
  878.         boolean enginePDD = this.consoleProperties.isGestioneCentralizzataSincronizzazionePdd();
  879.         this.singlePdD = this.consoleProperties.isSinglePdD();
  880.        
  881.         if (enginePDD == false) {
  882.             //this.log.info("Motore di sincronizzazione verso le Porte di Dominio non attivo.");
  883.             throw new GestoreNonAttivoException("Motore di sincronizzazione verso le Porte di Dominio non attivo.");
  884.         }

  885.         // Leggo informazioni per queue.properties
  886.         // Init JMS
  887.         // readQueueProperties(cfName, cfProp);

  888.         QueueManager queueMan = QueueManager.getInstance();
  889.         if (queueMan == null) {
  890.             this.log.debug("Impossibile avviare " + this.getClass().getSimpleName() + "QueueManager non inizializzato.");
  891.             throw new Exception("Impossibile avviare " + this.getClass().getSimpleName() + "QueueManager non inizializzato.");
  892.         }
  893.         boolean trovato = false;
  894.         int i = 0;
  895.         this.log.debug("Inizializzazione Receiver [" + this.nomeThread + "] ...");
  896.         while (!trovato && (i < 600000)) {
  897.             try {
  898.                 // InitialContext ctx = new InitialContext(cfProp);
  899.                 // queue = (Queue) ctx.lookup(pddQueuePrefix + queueName);
  900.                 // qcf = (QueueConnectionFactory) ctx.lookup(cfName);

  901.                 this.queue = queueMan.getQueue(pddQueuePrefix + this.pddName);
  902.                 this.qcf = queueMan.getQueueConnectionFactory();
  903.                 this.qc = this.qcf.createQueueConnection();
  904.                 this.qc.setExceptionListener(this.exceptionListenerJMS);
  905.                 this.qs = this.qc.createQueueSession(true, -1);
  906.                 this.receiver = this.qs.createReceiver(this.queue);
  907.                 this.qc.start();
  908.                 // ctx.close();
  909.                 this.log.debug("GestorePdD: Inizializzazione Receiver [" + this.nomeThread + "] effettuata.");
  910.                 trovato = true;
  911.             } catch (Exception e) {
  912.                 i = i + 10000;
  913.                 Utilities.sleep(10000);
  914.                 this.log.debug("Ritento Inizializzazione Receiver [" + this.nomeThread + "] ... causa: " + e.getMessage());
  915.             }
  916.         }

  917.         if (!trovato) {
  918.             this.log.error("Inizializzazione Receiver [" + this.nomeThread + "] non effettuata");
  919.             throw new Exception("Inizializzazione Receiver [" + this.nomeThread + "] non effettuata");
  920.         }

  921.        
  922.         // Init ControlStationCore
  923.         try {
  924.             this.pddCore = new PddCore();
  925.             this.soggettiCore = new SoggettiCore(this.pddCore);
  926.             this.paCore = new PorteApplicativeCore(this.pddCore);
  927.             this.pdCore = new PorteDelegateCore(this.pddCore);
  928.             this.saCore = new ServiziApplicativiCore(this.pddCore);

  929.             this.log.debug("GestorePdD-"+this.pddName+": Inizializzato Core. ");
  930.            
  931.         } catch (Exception e) {
  932.             this.log.error("Riscontrato Errore durante l'inizializzazione di ControlStationCore.", e);
  933.             this.log.info("GestorePdD-"+this.pddName+" non avviato.");
  934.             throw new ControlStationCoreException("Riscontrato Errore durante l'inizializzazione di ControlStationCore.", e);
  935.         }
  936.        
  937.        
  938.         // Init WebServiceCore
  939.         try {
  940.             String ipPdd = null;
  941.             String protocollo = null;
  942.             int porta = 80;
  943.             try {
  944.                 // ipPdd = backEndConnector.getIPPdd(queueName);
  945.                 PdDControlStation pdd = this.pddCore.getPdDControlStation(this.pddName);
  946.                 ipPdd = pdd.getIpGestione();
  947.                 protocollo = pdd.getProtocolloGestione();
  948.                 porta = pdd.getPortaGestione();

  949.                 if (ipPdd == null || protocollo == null || porta <= 0)
  950.                     throw new Exception("Parametri Porta di Dominio non validi.");

  951.             } catch (Exception e) {
  952.                 this.log.error("Riscontrato errore durante la get dell'ip del pdd(" + this.pddName + "): " + e.toString(), e);
  953.                 throw new Exception("Riscontrato errore durante la get dell'ip del pdd(" + this.pddName + "): " + e.toString(), e);
  954.             }
  955.             String prefixUrl = protocollo + "://" + ipPdd + ":" + porta + "/";
  956.            
  957.             // ws
  958.             this.portaApplicativaService = new PortaApplicativaSoap11Service();
  959.             this.portaDelegataService = new PortaDelegataSoap11Service();
  960.             this.servizioApplicativoService = new ServizioApplicativoSoap11Service();
  961.             this.soggettoService = new SoggettoSoap11Service();
  962.            
  963.             this.portaApplicativaPort = this.portaApplicativaService.getPortaApplicativaPortSoap11();
  964.             this.portaDelegataPort = this.portaDelegataService.getPortaDelegataPortSoap11();
  965.             this.servizioApplicativoPort = this.servizioApplicativoService.getServizioApplicativoPortSoap11();
  966.             this.soggettoPort = this.soggettoService.getSoggettoPortSoap11();
  967.            
  968.             ((BindingProvider)this.portaApplicativaPort).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
  969.                     prefixUrl+this.consoleProperties.getGestioneCentralizzataWSConfigurazioneEndpointSuffixPortaApplicativa());
  970.             ((BindingProvider)this.portaDelegataPort).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
  971.                     prefixUrl+this.consoleProperties.getGestioneCentralizzataWSConfigurazioneEndpointSuffixPortaDelegata());
  972.             ((BindingProvider)this.servizioApplicativoPort).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
  973.                     prefixUrl+this.consoleProperties.getGestioneCentralizzataWSConfigurazioneEndpointSuffixServizioApplicativo());
  974.             ((BindingProvider)this.soggettoPort).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
  975.                     prefixUrl+this.consoleProperties.getGestioneCentralizzataWSConfigurazioneEndpointSuffixSoggetto());
  976.            
  977.             ((BindingProvider)this.portaApplicativaPort).getRequestContext().put("schema-validation-enabled", true);
  978.             ((BindingProvider)this.portaDelegataPort).getRequestContext().put("schema-validation-enabled", true);
  979.             ((BindingProvider)this.servizioApplicativoPort).getRequestContext().put("schema-validation-enabled", true);
  980.             ((BindingProvider)this.soggettoPort).getRequestContext().put("schema-validation-enabled", true);
  981.            
  982.             String username = this.consoleProperties.getGestioneCentralizzataWSConfigurazioneCredenzialiBasicUsername();
  983.             String password = this.consoleProperties.getGestioneCentralizzataWSConfigurazioneCredenzialiBasicPassword();
  984.             if(username !=null && password!=null){
  985.                 // to use Basic HTTP Authentication:
  986.                
  987.                 ((BindingProvider)this.portaApplicativaPort).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
  988.                 ((BindingProvider)this.portaApplicativaPort).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
  989.                
  990.                 ((BindingProvider)this.portaDelegataPort).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
  991.                 ((BindingProvider)this.portaDelegataPort).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
  992.                
  993.                 ((BindingProvider)this.servizioApplicativoPort).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
  994.                 ((BindingProvider)this.servizioApplicativoPort).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
  995.                
  996.                 ((BindingProvider)this.soggettoPort).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
  997.                 ((BindingProvider)this.soggettoPort).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
  998.             }
  999.            
  1000.             this.log.debug("GestorePdD-"+this.pddName+": Inizializzato WebService. PortaApplicativa: " + this.portaApplicativaService.getClass().getSimpleName());
  1001.             this.log.debug("GestorePdD-"+this.pddName+": Inizializzato WebService. PortaDelegata: " + this.portaDelegataService.getClass().getSimpleName());
  1002.             this.log.debug("GestorePdD-"+this.pddName+": Inizializzato WebService. ServizioApplicativo: " + this.servizioApplicativoService.getClass().getSimpleName());
  1003.             this.log.debug("GestorePdD-"+this.pddName+": Inizializzato WebService. Soggetto: " + this.soggettoService.getClass().getSimpleName());
  1004.            
  1005.         } catch (Exception e) {
  1006.             this.log.error("Riscontrato Errore durante la connessione al WebService.", e);
  1007.             this.log.info("GestorePdD-"+this.pddName+" non avviato.");
  1008.             throw new Exception("Riscontrato Errore durante la connessione al WebService.", e);
  1009.         }
  1010.        
  1011.     }

  1012.     @Override
  1013.     public void stopGestore() {
  1014.         this.stop = true;
  1015.     }

  1016.     @Override
  1017.     protected String getName() {
  1018.         return this.nomeThread;
  1019.     }
  1020. }