StatisticsServiceLibraryReader.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.monitor.engine.config;

  21. import org.openspcoop2.core.commons.dao.DAOFactory;
  22. import org.openspcoop2.core.commons.dao.DAOFactoryException;
  23. import org.openspcoop2.core.plugins.ConfigurazioneServizioAzione;
  24. import org.openspcoop2.monitor.engine.config.statistiche.ConfigurazioneStatistica;
  25. import org.openspcoop2.monitor.engine.config.statistiche.dao.IConfigurazioneStatisticaServiceSearch;
  26. import org.openspcoop2.monitor.engine.config.transazioni.ConfigurazioneTransazioneRisorsaContenuto;
  27. import org.openspcoop2.monitor.engine.config.transazioni.ConfigurazioneTransazioneStato;

  28. import java.sql.Connection;
  29. import java.util.List;

  30. import org.slf4j.Logger;
  31. import org.openspcoop2.core.id.IDAccordo;
  32. import org.openspcoop2.generic_project.exception.ExpressionException;
  33. import org.openspcoop2.generic_project.exception.ExpressionNotImplementedException;
  34. import org.openspcoop2.generic_project.exception.MultipleResultException;
  35. import org.openspcoop2.generic_project.exception.NotFoundException;
  36. import org.openspcoop2.generic_project.exception.NotImplementedException;
  37. import org.openspcoop2.generic_project.exception.ServiceException;
  38. import org.openspcoop2.generic_project.expression.IPaginatedExpression;
  39. import org.openspcoop2.generic_project.utils.ServiceManagerProperties;

  40. /**
  41.  * StatisticsServiceLibraryReader
  42.  *
  43.  * @author Poli Andrea (apoli@link.it)
  44.  * @author $Author$
  45.  * @version $Rev$, $Date$
  46.  */
  47. public class StatisticsServiceLibraryReader {

  48.     private Connection connection;
  49.     private DAOFactory daoFactory = null;
  50.     private ServiceManagerProperties daoFactoryServiceManagerPropertiesPluginsStatistiche = null;
  51.     private Logger daoFactoryLogger = null;
  52.        
  53.     private org.openspcoop2.monitor.engine.config.statistiche.dao.IServiceManager serviceManagerPluginsStatistiche;
  54.        
  55.     private boolean debug;
  56.    
  57.     public StatisticsServiceLibraryReader(Connection connection,
  58.             DAOFactory daoFactory, ServiceManagerProperties daoFactoryServiceManagerPropertiesPluginsStatistiche,
  59.             Logger daoFactoryLogger, boolean debug){
  60.         this.connection = connection;
  61.         this.daoFactory = daoFactory;
  62.         this.daoFactoryServiceManagerPropertiesPluginsStatistiche = daoFactoryServiceManagerPropertiesPluginsStatistiche;
  63.         this.daoFactoryLogger = daoFactoryLogger;
  64.         this.debug = debug;
  65.     }
  66.     public StatisticsServiceLibraryReader(org.openspcoop2.monitor.engine.config.statistiche.dao.IServiceManager serviceManagerPluginsStatistiche, boolean debug){
  67.         this.serviceManagerPluginsStatistiche = serviceManagerPluginsStatistiche;
  68.         this.debug = debug;
  69.     }
  70.    
  71.     public StatisticsServiceLibrary readConfigurazioneStatistiche(BasicServiceLibrary basicServiceLibrary,  TransactionServiceLibrary transactionServiceLibrary, Logger log) throws Exception{
  72.        
  73.         StatisticsServiceLibrary searchServiceLibrary = new StatisticsServiceLibrary();
  74.         searchServiceLibrary.setBasicServiceLibrary(basicServiceLibrary);
  75.            
  76.         String azione = basicServiceLibrary.getAzione();
  77.         String portType = basicServiceLibrary.getPortType();
  78.         IDAccordo idAccordo = basicServiceLibrary.getIdAccordoServizioParteComune();
  79.        
  80.         // ** Verifico se sono stati definiti degli stati (in tal caso indico di registrare il plugins)
  81.         searchServiceLibrary.setPluginStatiTransazioniEnabled(false);
  82.         if(transactionServiceLibrary!=null){
  83.             List<ConfigurazioneTransazioneStato> stati = transactionServiceLibrary.mergeServiceActionTransactionLibrary_states();
  84.             if(stati!=null && stati.size()>0){
  85.                 searchServiceLibrary.setPluginStatiTransazioniEnabled(true);
  86.             }
  87.         }
  88.        
  89.         // ** Verifico se sono stati definiti delle risorse (in tal caso indico di registrare il plugins)
  90.         if(transactionServiceLibrary!=null){
  91.             List<ConfigurazioneTransazioneRisorsaContenuto> risorse = transactionServiceLibrary.mergeServiceActionTransactionLibrary_resources();
  92.             for (ConfigurazioneTransazioneRisorsaContenuto configurazioneTransazioneRisorsaContenuto : risorse) {
  93.                 if(configurazioneTransazioneRisorsaContenuto.isStatEnabled()){
  94.                     searchServiceLibrary.getPluginRisorseTransazioni().add(configurazioneTransazioneRisorsaContenuto.getNome());
  95.                 }
  96.             }
  97.         }
  98.        
  99.        
  100.         // ** Verifico se esiste una azione conforme a quella arrivata.**
  101.         List<ConfigurazioneStatistica> searchActionLibrary = null;
  102.         if(basicServiceLibrary.getServiceActionLibrary()!=null){
  103.             // Accedo alla sezione di statistica per l'azione
  104.             try{
  105.                 searchActionLibrary = this.getServiceActionSearchLibrary(basicServiceLibrary.getServiceActionLibrary());
  106.             }catch(NotFoundException notFound){
  107.                 // non e' stata configurata una libreria di servizio per l'azione specifica
  108.                 if(this.debug){
  109.                     log.debug("Non risulta configurata una statistica personalizzata per l'azione specifica ["+azione+"] per la libreria di servizio ["+portType+"] dell'accordo ["+idAccordo.toString()+"]",notFound);
  110.                 }
  111.             }
  112.         }
  113.         searchServiceLibrary.setStatisticsActionLibrary(searchActionLibrary);
  114.        
  115.         // ** Recupero informazioni per azione '*'
  116.         List<ConfigurazioneStatistica> searchActionAllLibrary = null;
  117.         try{
  118.             searchActionAllLibrary = this.getServiceActionSearchLibrary(basicServiceLibrary.getServiceActionAllLibrary());
  119.         }catch(NotFoundException notFound){
  120.             // non e' stata configurata una libreria di servizio per l'azione specifica
  121.             if(this.debug){
  122.                 log.debug("Non risulta configurata una statistica personalizzata per l'azione specifica ["+"*"+"] per la libreria di servizio ["+portType+"] dell'accordo ["+idAccordo.toString()+"]",notFound);
  123.             }
  124.         }
  125.         searchServiceLibrary.setStatisticsActionAllLibrary(searchActionAllLibrary);
  126.        
  127.         return searchServiceLibrary;
  128.     }
  129.    
  130.     private List<ConfigurazioneStatistica> getServiceActionSearchLibrary(ConfigurazioneServizioAzione serviceActionLibrary) throws DAOFactoryException, ServiceException, NotImplementedException, NotFoundException, MultipleResultException, ExpressionNotImplementedException, ExpressionException {
  131.        
  132.         boolean autoCommit = true;
  133.        
  134.         org.openspcoop2.monitor.engine.config.statistiche.dao.IServiceManager serviceManager = this.serviceManagerPluginsStatistiche;
  135.         if(serviceManager==null){
  136.             serviceManager = (org.openspcoop2.monitor.engine.config.statistiche.dao.IServiceManager) this.daoFactory.getServiceManager(
  137.                     org.openspcoop2.monitor.engine.config.statistiche.utils.ProjectInfo.getInstance(),
  138.                     this.connection, autoCommit,
  139.                         this.daoFactoryServiceManagerPropertiesPluginsStatistiche, this.daoFactoryLogger);
  140.             if(serviceManager instanceof org.openspcoop2.monitor.engine.config.statistiche.dao.jdbc.JDBCServiceManager)
  141.                 ((org.openspcoop2.monitor.engine.config.statistiche.dao.jdbc.JDBCServiceManager)serviceManager).getJdbcProperties().setShowSql(this.debug);
  142.         }
  143.        
  144.         IConfigurazioneStatisticaServiceSearch serviceSearch = serviceManager.getConfigurazioneStatisticaServiceSearch();
  145.        
  146.         IPaginatedExpression pagExpr = serviceSearch.newPaginatedExpression();
  147.         pagExpr.and();
  148.         pagExpr.
  149.             equals(ConfigurazioneStatistica.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO.ACCORDO,
  150.                     serviceActionLibrary.getIdConfigurazioneServizio().getAccordo());
  151.         pagExpr.
  152.             equals(ConfigurazioneStatistica.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO.TIPO_SOGGETTO_REFERENTE,
  153.                     serviceActionLibrary.getIdConfigurazioneServizio().getTipoSoggettoReferente());
  154.         pagExpr.
  155.             equals(ConfigurazioneStatistica.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO.NOME_SOGGETTO_REFERENTE,
  156.                     serviceActionLibrary.getIdConfigurazioneServizio().getNomeSoggettoReferente());
  157.         pagExpr.
  158.             equals(ConfigurazioneStatistica.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO.VERSIONE,
  159.                     serviceActionLibrary.getIdConfigurazioneServizio().getVersione());
  160.         pagExpr.
  161.             equals(ConfigurazioneStatistica.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO.SERVIZIO,
  162.                     serviceActionLibrary.getIdConfigurazioneServizio().getServizio());
  163.         pagExpr.
  164.             equals(ConfigurazioneStatistica.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.AZIONE,
  165.                     serviceActionLibrary.getAzione());

  166.         return serviceSearch.findAll(pagExpr);
  167.        
  168.     }
  169.    
  170. }