ConfigurazioneAllarmeBean.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.wrapper;

  21. import java.util.ArrayList;
  22. import java.util.List;

  23. import org.openspcoop2.core.allarmi.Allarme;
  24. import org.openspcoop2.core.plugins.Plugin;
  25. import org.openspcoop2.core.plugins.constants.TipoPlugin;
  26. import org.openspcoop2.monitor.engine.dynamic.DynamicFactory;
  27. import org.openspcoop2.monitor.engine.dynamic.IDynamicLoader;
  28. import org.openspcoop2.monitor.sdk.plugins.IAlarmProcessing;
  29. import org.openspcoop2.core.allarmi.constants.RuoloPorta;
  30. import org.openspcoop2.core.allarmi.constants.TipoAllarme;
  31. import org.openspcoop2.utils.LoggerWrapperFactory;
  32. import org.openspcoop2.utils.beans.BeanUtils;
  33. import org.openspcoop2.utils.beans.BlackListElement;
  34. import org.slf4j.Logger;

  35. /**
  36.  * ConfigurazioneAllarmeBean
  37.  *
  38.  * @author Giuliano Pintori (pintori@link.it)
  39.  * @author $Author$
  40.  * @version $Rev$, $Date$
  41.  */
  42. public class ConfigurazioneAllarmeBean extends Allarme{

  43.     /**
  44.      *
  45.      */
  46.     private static final long serialVersionUID = 1L;
  47.    
  48.     private Plugin plugin;
  49.     private String dettaglioAPI = null;
  50.     private String dettaglioFruitore = null;
  51.     private String dettaglioErogatore = null;
  52.        
  53.     public void setPlugin(Plugin plugin) {
  54.         this.plugin = plugin;
  55.     }
  56.     public Plugin getPlugin() {
  57.         return this.plugin;
  58.     }

  59.     public ConfigurazioneAllarmeBean() {
  60.         super();
  61.     }
  62.    
  63.     public ConfigurazioneAllarmeBean(Allarme allarme, Plugin plugin){
  64.         List<BlackListElement> metodiEsclusi = new ArrayList<BlackListElement>(
  65.                 0);
  66.         metodiEsclusi.add(new BlackListElement("setPlugin",
  67.                 Plugin.class));
  68.         metodiEsclusi.add(new BlackListElement("setDettaglioAPI",
  69.                 String.class));
  70.         metodiEsclusi.add(new BlackListElement("setDettaglioFruitore",
  71.                 String.class));
  72.         metodiEsclusi.add(new BlackListElement("setDettaglioErogatore",
  73.                 String.class));
  74.         metodiEsclusi.add(new BlackListElement("setExistsAlmostOneManuallyUpdateState",
  75.                 boolean.class));
  76.         metodiEsclusi.add(new BlackListElement("setExistsAlmostOneManuallyAckCriteria",
  77.                 boolean.class));
  78.        
  79.         BeanUtils.copy(this, allarme, metodiEsclusi);
  80.        
  81.         this.plugin = plugin;
  82.     }
  83.    
  84.     private static final int LIMIT_NOME = 80;
  85.     private static final int LIMIT = 100;
  86.    
  87.     public String getNomeAbbr(){
  88.         String tmp = this.getNome();
  89.            
  90.         if(tmp != null){
  91.             if(tmp.length() >= LIMIT_NOME)
  92.                 return tmp.substring(0, (LIMIT_NOME-3))+"...";
  93.         }
  94.        
  95.         return tmp;
  96.     }
  97.    
  98.     public String getDettaglioStatoAbbr(){
  99.         String tmp = this.getDettaglioStato();
  100.        
  101.         if(tmp != null){
  102.             if(tmp.length() >= LIMIT)
  103.                 return tmp.substring(0, (LIMIT-3))+"...";
  104.         }
  105.        
  106.         return tmp;
  107.     }
  108.    
  109.     public String getDettaglioStatoHtmlEscaped(){
  110.         String tmp = this.getDettaglioStato();
  111.        
  112.         if(tmp != null){
  113.             while(tmp.contains("\n")) {
  114.                 tmp = tmp.replace("\n", "<BR/>");
  115.             }
  116.         }
  117.        
  118.         return tmp;
  119.     }
  120.    
  121.     public String getDescrizioneAbbr(){
  122.         String tmp = this.getDescrizione();
  123.        
  124.         if(tmp != null){
  125.             if(tmp.length() >= LIMIT)
  126.                 return tmp.substring(0, (LIMIT-3))+"...";
  127.         }
  128.        
  129.         return tmp;
  130.     }
  131.    
  132.     public String getDettaglioAPI() {
  133.         if(this.dettaglioAPI == null) {
  134.             this.dettaglioAPI = "-";
  135.         }
  136.         return this.dettaglioAPI;
  137.     }
  138.    
  139.     public void setDettaglioAPI(String dettaglioAPI) {
  140.         this.dettaglioAPI = dettaglioAPI;
  141.     }
  142.    
  143.     public boolean isRuoloPortaApplicativa() {
  144.         boolean applicativa = false;
  145.        
  146.         if(this.getFiltro() != null && this.getFiltro().getRuoloPorta() != null) {
  147.             if(RuoloPorta.APPLICATIVA.equals(this.getFiltro().getRuoloPorta())) {
  148.                 applicativa = (this.getFiltro().getNomePorta()!=null);
  149.             }
  150.         }
  151.        
  152.         return applicativa;
  153.     }
  154.    
  155.     public boolean isRuoloPortaDelegata() {
  156.         boolean delegata = false;
  157.        
  158.         if(this.getFiltro() != null && this.getFiltro().getRuoloPorta() != null) {
  159.             if(RuoloPorta.DELEGATA.equals(this.getFiltro().getRuoloPorta())) {
  160.                 delegata = (this.getFiltro().getNomePorta()!=null);
  161.             }
  162.         }
  163.        
  164.         return delegata;
  165.     }
  166.    
  167.     public boolean isAllarmeConfigurazione() {
  168.         return !this.isRuoloPortaDelegata() && !this.isRuoloPortaApplicativa();
  169.     }
  170.     public String getDettaglioFruitore() {
  171.         return this.dettaglioFruitore;
  172.     }
  173.     public void setDettaglioFruitore(String dettaglioFruitore) {
  174.         this.dettaglioFruitore = dettaglioFruitore;
  175.     }
  176.     public String getDettaglioErogatore() {
  177.         return this.dettaglioErogatore;
  178.     }
  179.     public void setDettaglioErogatore(String dettaglioErogatore) {
  180.         this.dettaglioErogatore = dettaglioErogatore;
  181.     }
  182.    
  183.     public boolean isModalitaAttiva() {
  184.         boolean attivo = TipoAllarme.ATTIVO.equals(this.getTipoAllarme());
  185.         return attivo;
  186.     }
  187.    
  188.     private Boolean manuallyUpdateState = null;
  189.     public boolean isManuallyUpdateState() {
  190.         if(this.manuallyUpdateState == null) {
  191.             Logger log = LoggerWrapperFactory.getLogger(ConfigurazioneAllarmeBean.class);
  192.             try {
  193.                 IDynamicLoader dl = DynamicFactory.getInstance().newDynamicLoader(TipoPlugin.ALLARME, this.plugin.getTipo(), this.plugin.getClassName(), log);
  194.                 IAlarmProcessing alarm = (IAlarmProcessing) dl.newInstance();
  195.                 this.manuallyUpdateState = alarm.isManuallyUpdateState();
  196.             }catch(Throwable t) {
  197.                 log.error(t.getMessage(),t);
  198.                 this.manuallyUpdateState = false;
  199.             }
  200.         }
  201.         return this.manuallyUpdateState;
  202.     }
  203.    
  204.     private Boolean manuallyAckCriteria = null;
  205.     public boolean isManuallyAckCriteria() {
  206.         if(this.manuallyAckCriteria == null) {
  207.             Logger log = LoggerWrapperFactory.getLogger(ConfigurazioneAllarmeBean.class);
  208.             try {
  209.                 IDynamicLoader dl = DynamicFactory.getInstance().newDynamicLoader(TipoPlugin.ALLARME, this.plugin.getTipo(), this.plugin.getClassName(), log);
  210.                 IAlarmProcessing alarm = (IAlarmProcessing) dl.newInstance();
  211.                 this.manuallyAckCriteria = alarm.isManuallyAckCriteria();
  212.             }catch(Throwable t) {
  213.                 log.error(t.getMessage(),t);
  214.                 this.manuallyAckCriteria = false;
  215.             }
  216.         }
  217.         return this.manuallyAckCriteria;
  218.     }
  219.    
  220.     // Informazione necessaria per la visualizzazione nella lista della console di monitoraggio
  221.     private boolean existsAlmostOneManuallyUpdateState = true;
  222.     public void setExistsAlmostOneManuallyUpdateState(boolean existsAlmostOneManuallyUpdateState) {
  223.         this.existsAlmostOneManuallyUpdateState = existsAlmostOneManuallyUpdateState;
  224.     }
  225.     public boolean isExistsAlmostOneManuallyUpdateState() {
  226.         return this.existsAlmostOneManuallyUpdateState;
  227.     }
  228.    
  229.     private boolean existsAlmostOneManuallyAckCriteria = true;
  230.     public void setExistsAlmostOneManuallyAckCriteria(boolean existsAlmostOneManuallyAckCriteria) {
  231.         this.existsAlmostOneManuallyAckCriteria = existsAlmostOneManuallyAckCriteria;
  232.     }
  233.     public boolean isExistsAlmostOneManuallyAckCriteria() {
  234.         return this.existsAlmostOneManuallyAckCriteria;
  235.     }
  236.    
  237.  }