SearchServiceLibraryReader.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.ricerche.ConfigurazioneRicerca;
  25. import org.openspcoop2.monitor.engine.config.ricerche.dao.IConfigurazioneRicercaServiceSearch;

  26. import java.sql.Connection;
  27. import java.util.List;

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

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

  46.     private Connection connection;
  47.     private DAOFactory daoFactory = null;
  48.     private ServiceManagerProperties daoFactoryServiceManagerPropertiesPluginsRicerche = null;
  49.     private Logger daoFactoryLogger = null;
  50.        
  51.     private org.openspcoop2.monitor.engine.config.ricerche.dao.IServiceManager serviceManagerPluginsRicerche;
  52.        
  53.     private boolean debug;
  54.    
  55.     public SearchServiceLibraryReader(Connection connection,
  56.             DAOFactory daoFactory, ServiceManagerProperties daoFactoryServiceManagerPropertiesPluginsRicerche,
  57.             Logger daoFactoryLogger, boolean debug){
  58.         this.connection = connection;
  59.         this.daoFactory = daoFactory;
  60.         this.daoFactoryServiceManagerPropertiesPluginsRicerche = daoFactoryServiceManagerPropertiesPluginsRicerche;
  61.         this.daoFactoryLogger = daoFactoryLogger;
  62.         this.debug = debug;
  63.     }
  64.     public SearchServiceLibraryReader(org.openspcoop2.monitor.engine.config.ricerche.dao.IServiceManager serviceManagerPluginsRicerche, boolean debug){
  65.         this.serviceManagerPluginsRicerche = serviceManagerPluginsRicerche;
  66.         this.debug = debug;
  67.     }
  68.    
  69.     public SearchServiceLibrary readConfigurazioneRicerche(BasicServiceLibrary basicServiceLibrary, Logger log) throws Exception{
  70.        
  71.         SearchServiceLibrary searchServiceLibrary = new SearchServiceLibrary();
  72.         searchServiceLibrary.setBasicServiceLibrary(basicServiceLibrary);
  73.            
  74.         String azione = basicServiceLibrary.getAzione();
  75.         String portType = basicServiceLibrary.getPortType();
  76.         IDAccordo idAccordo = basicServiceLibrary.getIdAccordoServizioParteComune();
  77.        
  78.         // ** Verifico se esiste una azione conforme a quella arrivata.**
  79.         List<ConfigurazioneRicerca> searchActionLibrary = null;
  80.         if(basicServiceLibrary.getServiceActionLibrary()!=null){
  81.             // Accedo alla sezione di ricerca per l'azione
  82.             try{
  83.                 searchActionLibrary = this.getServiceActionSearchLibrary(basicServiceLibrary.getServiceActionLibrary());
  84.             }catch(NotFoundException notFound){
  85.                 // non e' stata configurata una libreria di servizio per l'azione specifica
  86.                 if(this.debug){
  87.                     log.debug("Non risulta configurata una ricerca personalizzata per l'azione specifica ["+azione+"] per la libreria di servizio ["+portType+"] dell'accordo ["+idAccordo.toString()+"]",notFound);
  88.                 }
  89.             }
  90.         }
  91.         searchServiceLibrary.setSearchActionLibrary(searchActionLibrary);
  92.        
  93.         // ** Recupero informazioni per azione '*'
  94.         List<ConfigurazioneRicerca> searchActionAllLibrary = null;
  95.         try{
  96.             searchActionAllLibrary = this.getServiceActionSearchLibrary(basicServiceLibrary.getServiceActionAllLibrary());
  97.         }catch(NotFoundException notFound){
  98.             // non e' stata configurata una libreria di servizio per l'azione specifica
  99.             if(this.debug){
  100.                 log.debug("Non risulta configurata una ricerca personalizzata per l'azione specifica ["+"*"+"] per la libreria di servizio ["+portType+"] dell'accordo ["+idAccordo.toString()+"]",notFound);
  101.             }
  102.         }
  103.         searchServiceLibrary.setSearchActionAllLibrary(searchActionAllLibrary);
  104.        
  105.         return searchServiceLibrary;
  106.     }
  107.    
  108.     private List<ConfigurazioneRicerca> getServiceActionSearchLibrary(ConfigurazioneServizioAzione serviceActionLibrary) throws DAOFactoryException, ServiceException, NotImplementedException, NotFoundException, MultipleResultException, ExpressionNotImplementedException, ExpressionException {
  109.        
  110.         boolean autoCommit = true;
  111.        
  112.         org.openspcoop2.monitor.engine.config.ricerche.dao.IServiceManager serviceManager = this.serviceManagerPluginsRicerche;
  113.         if(serviceManager==null){
  114.             serviceManager = (org.openspcoop2.monitor.engine.config.ricerche.dao.IServiceManager) this.daoFactory.getServiceManager(
  115.                     org.openspcoop2.monitor.engine.config.ricerche.utils.ProjectInfo.getInstance(),
  116.                     this.connection, autoCommit,
  117.                         this.daoFactoryServiceManagerPropertiesPluginsRicerche, this.daoFactoryLogger);
  118.             if(serviceManager instanceof org.openspcoop2.monitor.engine.config.ricerche.dao.jdbc.JDBCServiceManager)
  119.                 ((org.openspcoop2.monitor.engine.config.ricerche.dao.jdbc.JDBCServiceManager)serviceManager).getJdbcProperties().setShowSql(this.debug);
  120.         }
  121.        
  122.         IConfigurazioneRicercaServiceSearch serviceSearch = serviceManager.getConfigurazioneRicercaServiceSearch();
  123.        
  124.         IPaginatedExpression pagExpr = serviceSearch.newPaginatedExpression();
  125.         pagExpr.and();
  126.         pagExpr.
  127.             equals(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO.ACCORDO,
  128.                     serviceActionLibrary.getIdConfigurazioneServizio().getAccordo());
  129.         pagExpr.
  130.             equals(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO.TIPO_SOGGETTO_REFERENTE,
  131.                     serviceActionLibrary.getIdConfigurazioneServizio().getTipoSoggettoReferente());
  132.         pagExpr.
  133.             equals(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO.NOME_SOGGETTO_REFERENTE,
  134.                     serviceActionLibrary.getIdConfigurazioneServizio().getNomeSoggettoReferente());
  135.         pagExpr.
  136.             equals(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO.VERSIONE,
  137.                     serviceActionLibrary.getIdConfigurazioneServizio().getVersione());
  138.         pagExpr.
  139.             equals(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO.SERVIZIO,
  140.                     serviceActionLibrary.getIdConfigurazioneServizio().getServizio());
  141.         pagExpr.
  142.             equals(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.AZIONE,
  143.                     serviceActionLibrary.getAzione());

  144.         return serviceSearch.findAll(pagExpr);
  145.        
  146.     }
  147.    
  148. }