AllarmiDriverUtils.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.alarm.utils;

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

  24. import org.openspcoop2.core.allarmi.Allarme;
  25. import org.openspcoop2.core.allarmi.AllarmeHistory;
  26. import org.openspcoop2.core.allarmi.constants.RuoloPorta;
  27. import org.openspcoop2.core.commons.ISearch;
  28. import org.openspcoop2.core.id.IDServizio;
  29. import org.openspcoop2.core.id.IDServizioApplicativo;
  30. import org.openspcoop2.core.id.IDSoggetto;
  31. import org.openspcoop2.generic_project.exception.ServiceException;
  32. import org.openspcoop2.monitor.engine.alarm.wrapper.ConfigurazioneAllarmeBean;
  33. import org.openspcoop2.monitor.engine.alarm.wrapper.ConfigurazioneAllarmeHistoryBean;
  34. import org.openspcoop2.core.plugins.Plugin;
  35. import org.openspcoop2.core.plugins.constants.TipoPlugin;
  36. import org.openspcoop2.core.plugins.utils.PluginsDriverUtils;
  37. import org.slf4j.Logger;

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

  46.     public static List<ConfigurazioneAllarmeBean> allarmiList(ISearch ricerca, RuoloPorta ruoloPorta, String nomePorta, Connection con, Logger log, String tipoDB) throws ServiceException {
  47.         String nomeMetodo = "allarmiList";
  48.            
  49.         List<ConfigurazioneAllarmeBean> lista = new ArrayList<ConfigurazioneAllarmeBean>();
  50.        
  51.         try {
  52.            
  53.             List<Allarme> findAll = org.openspcoop2.core.allarmi.utils.AllarmiDriverUtils.allarmiList(ricerca, ruoloPorta, nomePorta, con, log, tipoDB);
  54.            
  55.             if(findAll != null && findAll.size() > 0){
  56.                
  57.                 for (Allarme al : findAll) {
  58.                    
  59.                     Plugin plugin = PluginsDriverUtils.getPlugin(TipoPlugin.ALLARME.getValue(), al.getTipo(), true, con, log, tipoDB);
  60.                    
  61.                     lista.add(new ConfigurazioneAllarmeBean(al, plugin));
  62.                 }
  63.             }

  64.             return lista;

  65.         } catch (Exception qe) {
  66.             throw new ServiceException("[DriverConfigurazioneDB::" + nomeMetodo + "] Errore : " + qe.getMessage(),qe);
  67.         }
  68.     }
  69.    
  70.     public static ConfigurazioneAllarmeBean getAllarme(Long id, Connection con, Logger log, String tipoDB) throws ServiceException {
  71.         String nomeMetodo = "getAllarme";
  72.        
  73.         try {
  74.             Allarme al = org.openspcoop2.core.allarmi.utils.AllarmiDriverUtils.getAllarme(id, con, log, tipoDB);
  75.             Plugin plugin = PluginsDriverUtils.getPlugin(TipoPlugin.ALLARME.getValue(), al.getTipo(), true, con, log, tipoDB);
  76.             return new ConfigurazioneAllarmeBean(al, plugin);
  77.         } catch (Exception qe) {
  78.             throw new ServiceException("[DriverConfigurazioneDB::" + nomeMetodo + "] Errore : " + qe.getMessage(),qe);
  79.         }
  80.     }
  81.     public static ConfigurazioneAllarmeBean getAllarme(String nome, Connection con, Logger log, String tipoDB) throws ServiceException {
  82.         String nomeMetodo = "getAllarmeByNome";
  83.        
  84.         try {
  85.             Allarme al = org.openspcoop2.core.allarmi.utils.AllarmiDriverUtils.getAllarme(nome, con, log, tipoDB);
  86.             Plugin plugin = PluginsDriverUtils.getPlugin(TipoPlugin.ALLARME.getValue(), al.getTipo(), true, con, log, tipoDB);
  87.             return new ConfigurazioneAllarmeBean(al, plugin);
  88.         } catch (Exception qe) {
  89.             throw new ServiceException("[DriverConfigurazioneDB::" + nomeMetodo + "] Errore : " + qe.getMessage(),qe);
  90.         }
  91.     }
  92.     public static ConfigurazioneAllarmeBean getAllarme(Allarme allarme, Connection con, Logger log, String tipoDB) throws ServiceException {
  93.         String nomeMetodo = "convertAllarme";
  94.        
  95.         try {
  96.             Plugin plugin = PluginsDriverUtils.getPlugin(TipoPlugin.ALLARME.getValue(), allarme.getTipo(), true, con, log, tipoDB);
  97.             return new ConfigurazioneAllarmeBean(allarme, plugin);
  98.         } catch (Exception qe) {
  99.             throw new ServiceException("[DriverConfigurazioneDB::" + nomeMetodo + "] Errore : " + qe.getMessage(),qe);
  100.         }
  101.     }

  102.     public static List<ConfigurazioneAllarmeHistoryBean> allarmiHistoryList(ISearch ricerca, Long idAllarme, Connection con, Logger log, String tipoDB) throws ServiceException {
  103.         String nomeMetodo = "allarmiHistoryList";
  104.        
  105.         List<ConfigurazioneAllarmeHistoryBean> lista = new ArrayList<ConfigurazioneAllarmeHistoryBean>();
  106.        
  107.         try {
  108.             List<AllarmeHistory> findAll = org.openspcoop2.core.allarmi.utils.AllarmiDriverUtils.allarmiHistoryList(ricerca, idAllarme, con, log, tipoDB);
  109.            
  110.             if(findAll != null && findAll.size() > 0){
  111.                 for (AllarmeHistory al : findAll) {
  112.                     lista.add(new ConfigurazioneAllarmeHistoryBean(al));
  113.                 }
  114.             }

  115.             return lista;

  116.         } catch (Exception qe) {
  117.             throw new ServiceException("[DriverConfigurazioneDB::" + nomeMetodo + "] Errore : " + qe.getMessage(),qe);
  118.         }
  119.     }
  120.    
  121.     public static List<ConfigurazioneAllarmeBean> configurazioneAllarmiList(ISearch ricerca, RuoloPorta ruoloPorta, String nomePorta,
  122.             Connection con, Logger log, String tipoDB,
  123.             String nomeMetodo,
  124.             IDSoggetto filtroSoggettoFruitore, IDServizioApplicativo filtroApplicativoFruitore,String filtroRuoloFruitore,
  125.             IDSoggetto filtroSoggettoErogatore, String filtroRuoloErogatore,
  126.             IDServizio filtroServizioAzione, String filtroRuolo) throws ServiceException{
  127.        
  128.         List<ConfigurazioneAllarmeBean> lista = new ArrayList<ConfigurazioneAllarmeBean>();
  129.        
  130.         try {
  131.            
  132.             List<Allarme> findAll = org.openspcoop2.core.allarmi.utils.AllarmiDriverUtils.configurazioneAllarmiList(ricerca, ruoloPorta, nomePorta,
  133.                     con, log, tipoDB,
  134.                     nomeMetodo,
  135.                     filtroSoggettoFruitore, filtroApplicativoFruitore, filtroRuoloFruitore,
  136.                     filtroSoggettoErogatore, filtroRuoloErogatore,
  137.                     filtroServizioAzione, filtroRuolo);
  138.            
  139.             if(findAll != null && findAll.size() > 0){
  140.                
  141.                 for (Allarme al : findAll) {
  142.                    
  143.                     Plugin plugin = PluginsDriverUtils.getPlugin(TipoPlugin.ALLARME.getValue(), al.getTipo(), true, con, log, tipoDB);
  144.                    
  145.                     lista.add(new ConfigurazioneAllarmeBean(al, plugin));
  146.                 }
  147.             }

  148.             return lista;

  149.         } catch (Exception qe) {
  150.             throw new ServiceException("[DriverConfigurazioneDB::" + nomeMetodo + "] Errore : " + qe.getMessage(),qe);
  151.         }
  152.     }
  153. }