AllarmiUtils.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.util.ArrayList;
  22. import java.util.HashMap;
  23. import java.util.List;
  24. import java.util.Map;

  25. import org.apache.commons.lang.StringUtils;
  26. import org.openspcoop2.core.allarmi.Allarme;
  27. import org.openspcoop2.core.allarmi.AllarmeFiltro;
  28. import org.openspcoop2.core.allarmi.constants.StatoAllarme;
  29. import org.openspcoop2.core.allarmi.constants.TipoAllarme;
  30. import org.openspcoop2.core.allarmi.utils.AllarmiConverterUtils;
  31. import org.openspcoop2.core.id.IDServizio;
  32. import org.openspcoop2.core.id.IDSoggetto;
  33. import org.openspcoop2.core.plugins.constants.TipoPlugin;
  34. import org.openspcoop2.monitor.engine.alarm.AlarmEngineConfig;
  35. import org.openspcoop2.monitor.engine.alarm.wrapper.ConfigurazioneAllarmeBean;
  36. import org.openspcoop2.monitor.engine.dynamic.DynamicFactory;
  37. import org.openspcoop2.monitor.engine.dynamic.IDynamicLoader;
  38. import org.openspcoop2.monitor.sdk.condition.Context;
  39. import org.openspcoop2.monitor.sdk.plugins.IAlarmProcessing;
  40. import org.openspcoop2.protocol.engine.ProtocolFactoryManager;
  41. import org.openspcoop2.protocol.engine.utils.NamingUtils;
  42. import org.openspcoop2.protocol.sdk.IProtocolFactory;
  43. import org.openspcoop2.utils.beans.BeanUtils;
  44. import org.openspcoop2.utils.transport.http.HttpConstants;
  45. import org.openspcoop2.utils.transport.http.HttpRequest;
  46. import org.openspcoop2.utils.transport.http.HttpRequestMethod;
  47. import org.openspcoop2.utils.transport.http.HttpResponse;
  48. import org.openspcoop2.utils.transport.http.HttpUtilities;
  49. import org.slf4j.Logger;

  50. /**    
  51.  * AllarmiUtils
  52.  *
  53.  * @author Poli Andrea (poli@link.it)
  54.  * @author $Author$
  55.  * @version $Rev$, $Date$
  56.  */
  57. public class AllarmiUtils {

  58.    
  59.     /***
  60.      *
  61.      * Restituisce true se i tipi indicati sono compatibili, false altrimenti.
  62.      *
  63.      * @param filtro
  64.      * @return
  65.      */
  66.     public static boolean controllaTipiIndicatiNelFiltro(AllarmeFiltro filtro, String valoreQualsiasi) throws Exception{

  67.         String tipoMittente = filtro.getTipoFruitore();
  68.         String tipoDestinatario = filtro.getTipoErogatore();
  69.         String tipoServizio = filtro.getTipoServizio();

  70.         List<String> protocolloMittente = new ArrayList<>();
  71.         List<String> protocolloDestinatario = new ArrayList<>();
  72.         List<String> protocolloServizio = new ArrayList<>();


  73.         try{

  74.             // 1. Carico i tipi disponibili per mittente, destinatario e servizio, se uno dei tre non e' stato scelto ('*') la lista risultera' vuota
  75.             if(!tipoDestinatario.equals(valoreQualsiasi) ){
  76.                 IProtocolFactory<?> protocolFactory = ProtocolFactoryManager.getInstance().getProtocolFactoryByOrganizationType(tipoDestinatario);
  77.                 protocolloDestinatario.add(protocolFactory.getProtocol());
  78.                 //              tipiDisponibiliDestinatario = protocolFactory.createProtocolConfiguration().getTipiSoggetti();
  79.             }

  80.             if(!tipoMittente.equals(valoreQualsiasi)){
  81.                 IProtocolFactory<?> protocolFactory = ProtocolFactoryManager.getInstance().getProtocolFactoryByOrganizationType(tipoMittente);
  82.                 protocolloMittente.add(protocolFactory.getProtocol());
  83.                 //              tipiDisponibiliMittente = protocolFactory.createProtocolConfiguration().getTipiSoggetti();
  84.             }

  85.             if(!tipoServizio.equals(valoreQualsiasi)){
  86.                 IProtocolFactory<?> protocolFactory = ProtocolFactoryManager.getInstance().getProtocolFactoryByServiceType(tipoServizio);
  87.                 protocolloServizio.add(protocolFactory.getProtocol());
  88.                 //              tipiDisponibiliServizio = protocolFactory.createProtocolConfiguration().getTipiServizi();
  89.             }

  90.             // Inserisco tutti i tipi trovati in una mappa, se i tre tipi sono compatibili, l'elenco delle chiavi coincide con la dimensione delle liste di quelli settati.
  91.             Map<String, String> mappaProtocolli = new HashMap<>();
  92.             if(protocolloServizio != null && protocolloServizio.size() > 0)
  93.                 for (String tipo : protocolloServizio) {
  94.                     if(!mappaProtocolli.containsKey(tipo))
  95.                         mappaProtocolli.put(tipo, tipo);
  96.                 }

  97.             if(protocolloMittente != null && protocolloMittente.size() > 0)
  98.                 for (String tipo : protocolloMittente) {
  99.                     if(!mappaProtocolli.containsKey(tipo))
  100.                         mappaProtocolli.put(tipo, tipo);
  101.                 }

  102.             if(protocolloDestinatario != null && protocolloDestinatario.size() > 0)
  103.                 for (String tipo : protocolloDestinatario) {
  104.                     if(!mappaProtocolli.containsKey(tipo))
  105.                         mappaProtocolli.put(tipo, tipo);
  106.                 }  

  107.             // controllo di validita  
  108.             if(protocolloDestinatario.size() > 0 && protocolloDestinatario.size() != mappaProtocolli.keySet().size())
  109.                 return false;

  110.             if(protocolloMittente.size() > 0 && protocolloMittente.size() != mappaProtocolli.keySet().size())
  111.                 return false;

  112.             if(protocolloServizio.size() > 0 && protocolloServizio.size() != mappaProtocolli.keySet().size())
  113.                 return false;

  114.             return true;
  115.         }catch(Exception e){
  116.             throw e;
  117.         }
  118.     }
  119.    
  120.     private static HttpRequest buildHttpRequest(AlarmEngineConfig allarmiConfig, String url, HttpRequestMethod method, byte [] content, String contentType) {
  121.         HttpRequest request = new HttpRequest();
  122.         request.setUrl(url);
  123.         request.setContent(content);
  124.         request.setMethod(method);
  125.         request.setContentType(contentType);
  126.         request.setUsername(allarmiConfig.getActiveAlarm_serviceUrl_manager_username());
  127.         request.setPassword(allarmiConfig.getActiveAlarm_serviceUrl_manager_password());
  128.        
  129.         request.setConnectTimeout(allarmiConfig.getActiveAlarm_serviceUrl_connectionTimeout());
  130.         request.setReadTimeout(allarmiConfig.getActiveAlarm_serviceUrl_readConnectionTimeout());
  131.        
  132.         if(allarmiConfig.isActiveAlarm_serviceUrl_https()) {
  133.             request.setHostnameVerifier(allarmiConfig.isActiveAlarm_serviceUrl_https_verificaHostName());
  134.             if(allarmiConfig.isActiveAlarm_serviceUrl_https_autenticazioneServer()) {
  135.                 request.setTrustStorePath(allarmiConfig.getActiveAlarm_serviceUrl_https_truststorePath());
  136.                 request.setTrustStoreType(allarmiConfig.getActiveAlarm_serviceUrl_https_truststoreType());
  137.                 request.setTrustStorePassword(allarmiConfig.getActiveAlarm_serviceUrl_https_truststorePassword());
  138.             }
  139.             else {
  140.                 request.setTrustAllCerts(true);
  141.             }
  142.         }
  143.         return request;
  144.     }
  145.    
  146.     public static void sendToAllarmi(AlarmEngineConfig allarmiConfig, List<String> post_urls, List<String> post_contents, Logger log) throws Exception{
  147.         if(post_urls!=null && post_urls.size()>0){
  148.             for (int i = 0; i < post_urls.size(); i++) {
  149.                 String url = post_urls.get(i);
  150.                 String content = post_contents.get(i);

  151.                 log.debug("Invoke ["+url+"] ...");
  152.                 HttpRequest request = buildHttpRequest(allarmiConfig, url, HttpRequestMethod.POST, content.getBytes(), HttpConstants.CONTENT_TYPE_JSON);                
  153.                 HttpResponse response = HttpUtilities.httpInvoke(request);
  154.                 if(response.getContent()!=null){
  155.                     log.debug("Invoked ["+url+"] Status["+response.getResultHTTPOperation()+"] Message["+new String(response.getContent())+"]");    
  156.                 }
  157.                 else{
  158.                     log.debug("Invoked ["+url+"] Status["+response.getResultHTTPOperation()+"]");
  159.                 }
  160.                 if(response.getResultHTTPOperation()>202){
  161.                     throw new Exception("Error occurs during invoke url["+url+"] Status["+response.getResultHTTPOperation()+"] Message["+new String(response.getContent())+"]");    
  162.                 }  
  163.             }
  164.         }
  165.     }
  166.    
  167.     public static String sendToAllarme(AlarmEngineConfig allarmiConfig, String get_url, Logger log) throws Exception{

  168.         log.debug("Invoke ["+get_url+"] ...");
  169.         HttpRequest request = buildHttpRequest(allarmiConfig, get_url, HttpRequestMethod.GET, null, null);              
  170.         HttpResponse response = HttpUtilities.httpInvoke(request);
  171.         String responseS = null;
  172.         if(response.getContent()!=null){
  173.             responseS = new String(response.getContent());
  174.             log.debug("Invoked ["+get_url+"] Status["+response.getResultHTTPOperation()+"] Payload["+responseS+"]");    
  175.         }
  176.         else{
  177.             log.debug("Invoked ["+get_url+"] Status["+response.getResultHTTPOperation()+"]");
  178.             responseS = "";
  179.         }
  180.         if(response.getResultHTTPOperation()>202){
  181.             throw new Exception("Error occurs during invoke url["+get_url+"] Status["+response.getResultHTTPOperation()+"] Payload["+responseS+"]");    
  182.         }
  183.         else {
  184.             return responseS;
  185.         }

  186.     }
  187.    
  188.     public static void notifyStateActiveThread(boolean isAdd, boolean modificatoStato, boolean modificatoAckwoldegment,
  189.             ConfigurazioneAllarmeBean oldAllarmePrimaModifica, ConfigurazioneAllarmeBean allarme, Logger log, AlarmEngineConfig allarmiConfig) throws Exception{
  190.         if(TipoAllarme.PASSIVO.equals(allarme.getTipoAllarme())){
  191.             // NOTA: il tipo di allarme non è modificabile.
  192.             log.debug("Allarme ["+allarme.getNome()+"] è passivo. Non viene attivato alcun thread");
  193.             return;
  194.         }
  195.        
  196.         String prefixUrl = allarmiConfig.getActiveAlarm_serviceUrl();
  197.         if(prefixUrl.endsWith("/")==false){
  198.             prefixUrl = prefixUrl + "/";
  199.         }
  200.         prefixUrl = prefixUrl + "gestione/attivi/"+allarme.getNome();
  201.         List<String> post_urls = new ArrayList<>();
  202.         List<String> post_contents = new ArrayList<>();
  203.         if(isAdd){
  204.             if(allarme.getEnabled()==1){
  205.                 // start allarme
  206.                 post_urls.add(prefixUrl);
  207.                 post_contents.add("{\"operazione\": \"start\"}");
  208.             }
  209.         }
  210.         else{
  211.             // Se è stato modificato solo lo stato non richiede un stop/restart
  212.             boolean equals = false;
  213.             StringBuilder bfDiff = null;
  214.             if(oldAllarmePrimaModifica!=null){
  215.                
  216.                 List<String> fieldEsclusi = new ArrayList<>();
  217.                 fieldEsclusi.add("id");
  218.                 if(modificatoStato){
  219.                     fieldEsclusi.add("stato");
  220.                     fieldEsclusi.add("_value_stato");
  221.                     fieldEsclusi.add("precedenteStato");
  222.                     fieldEsclusi.add("_value_precedenteStato");
  223.                     fieldEsclusi.add("dettaglioStato");
  224.                 }
  225.                 if(modificatoAckwoldegment){
  226.                     fieldEsclusi.add("acknowledged");
  227.                 }
  228.                
  229.                 // i metodi equals e diff non funzionano in caso di extends
  230.                
  231.                 Allarme old = new Allarme();
  232.                 BeanUtils.copy(old, oldAllarmePrimaModifica, null);
  233.                
  234.                 Allarme attuale = new Allarme();
  235.                 BeanUtils.copy(attuale, allarme, null);
  236.                
  237.                 equals = attuale.equals(old, fieldEsclusi);
  238.                 if(!equals){
  239.                     bfDiff = new StringBuilder();
  240.                     attuale.diff(old, bfDiff, false, fieldEsclusi);
  241.                 }
  242.             }
  243.             if(equals){        
  244.                 if(modificatoStato){
  245.                     StatoAllarme statoAllarme = AllarmiConverterUtils.toStatoAllarme(allarme.getStato());
  246.                     post_urls.add(prefixUrl+"/stato");
  247.                     switch (statoAllarme) {
  248.                     case OK:
  249.                         post_contents.add("{\"stato\": \"OK\"}");
  250.                         break;
  251.                     case WARNING:
  252.                         post_contents.add("{\"stato\": \"WARNING\"}");
  253.                         break;
  254.                     case ERROR:
  255.                         post_contents.add("{\"stato\": \"ERROR\"}");
  256.                         break;
  257.                     }
  258.                 }
  259.                 if(modificatoAckwoldegment){
  260.                     post_urls.add(prefixUrl+"/acknoledgement");
  261.                     if(allarme.getAcknowledged()==1){
  262.                         post_contents.add("{\"acknoledgement\": true}");
  263.                     }
  264.                     else{
  265.                         post_contents.add("{\"acknoledgement\": false}");
  266.                     }
  267.                 }
  268.                 //else{
  269.                 // non è cambiato nulla
  270.                 //}
  271.             }
  272.             else{
  273.                 if(bfDiff!=null){  
  274.                     log.debug("Rilevata modifica, diff: "+bfDiff.toString());
  275.                 }
  276.                
  277.                 if(allarme.getEnabled()==0){
  278.                     // stop allarme
  279.                     post_urls.add(prefixUrl);
  280.                     post_contents.add("{\"operazione\": \"stop\"}");
  281.                 }
  282.                 else{
  283.                     // restart allarme
  284.                     post_urls.add(prefixUrl);
  285.                     post_contents.add("{\"operazione\": \"restart\"}");
  286.                 }
  287.             }
  288.         }
  289.         AllarmiUtils.sendToAllarmi(allarmiConfig, post_urls, post_contents, log);
  290.     }
  291.    
  292.     public static void stopActiveThreads(List<String> allarmi, Logger log, AlarmEngineConfig allarmiConfig) throws Exception{
  293.        
  294.         List<String> post_urls = new ArrayList<>();
  295.         List<String> post_contents = new ArrayList<>();
  296.         if(!allarmi.isEmpty()) {
  297.             for (String nomeAllarme : allarmi) {
  298.                
  299.                 String prefixUrl = allarmiConfig.getActiveAlarm_serviceUrl();
  300.                 if(prefixUrl.endsWith("/")==false){
  301.                     prefixUrl = prefixUrl + "/";
  302.                 }
  303.                 prefixUrl = prefixUrl + "gestione/attivi/"+nomeAllarme;
  304.                 post_urls.add(prefixUrl);
  305.                 post_contents.add("{\"operazione\": \"stop\"}");
  306.                
  307.             }
  308.         }
  309.        
  310.         if(!post_urls.isEmpty()) {
  311.             AllarmiUtils.sendToAllarmi(allarmiConfig, post_urls, post_contents, log);
  312.         }
  313.        
  314.     }
  315.    
  316.     public static void startActiveThread(ConfigurazioneAllarmeBean allarme, Logger log, AlarmEngineConfig allarmiConfig) throws Exception{
  317.         _manageActiveThreads(allarme, log, allarmiConfig, "start");
  318.     }
  319.     public static void restartActiveThread(ConfigurazioneAllarmeBean allarme, Logger log, AlarmEngineConfig allarmiConfig) throws Exception{
  320.         _manageActiveThreads(allarme, log, allarmiConfig, "restart");  
  321.     }
  322.     public static void stopActiveThread(ConfigurazioneAllarmeBean allarme, Logger log, AlarmEngineConfig allarmiConfig) throws Exception{
  323.         _manageActiveThreads(allarme, log, allarmiConfig, "stop");  
  324.     }
  325.     public static void _manageActiveThreads(ConfigurazioneAllarmeBean allarme, Logger log, AlarmEngineConfig allarmiConfig, String operazione) throws Exception{
  326.        
  327.         List<String> post_urls = new ArrayList<>();
  328.         List<String> post_contents = new ArrayList<>();
  329.                
  330.         String prefixUrl = allarmiConfig.getActiveAlarm_serviceUrl();
  331.         if(prefixUrl.endsWith("/")==false){
  332.             prefixUrl = prefixUrl + "/";
  333.         }
  334.         prefixUrl = prefixUrl + "gestione/attivi/"+allarme.getNome();
  335.         post_urls.add(prefixUrl);
  336.         post_contents.add("{\"operazione\": \""+operazione+"\"}");
  337.                
  338.         AllarmiUtils.sendToAllarmi(allarmiConfig, post_urls, post_contents, log);
  339.        
  340.     }
  341.    
  342.     public static boolean existsActiveThread(ConfigurazioneAllarmeBean allarme, Logger log, AlarmEngineConfig allarmiConfig) throws Exception{
  343.         if(TipoAllarme.PASSIVO.equals(allarme.getTipoAllarme())){
  344.             // NOTA: il tipo di allarme non è modificabile.
  345.             log.debug("Allarme ["+allarme.getNome()+"] è passivo. Non contiene una immagine");
  346.             return false;
  347.         }
  348.        
  349.         String prefixUrl = allarmiConfig.getActiveAlarm_serviceUrl();
  350.         if(prefixUrl.endsWith("/")==false){
  351.             prefixUrl = prefixUrl + "/";
  352.         }
  353.         prefixUrl = prefixUrl + "gestione/attivi/"+allarme.getNome()+"/image";
  354.         log.debug("Invoke ["+prefixUrl+"] ...");
  355.         HttpRequest request = buildHttpRequest(allarmiConfig, prefixUrl, HttpRequestMethod.GET, null, null);                
  356.         HttpResponse response = HttpUtilities.httpInvoke(request);
  357.         return response.getResultHTTPOperation()==200;
  358.     }
  359.    
  360.     public static String getActiveThreadImage(ConfigurazioneAllarmeBean allarme, Logger log, AlarmEngineConfig allarmiConfig) throws Exception{
  361.         if(TipoAllarme.PASSIVO.equals(allarme.getTipoAllarme())){
  362.             // NOTA: il tipo di allarme non è modificabile.
  363.             log.debug("Allarme ["+allarme.getNome()+"] è passivo. Non contiene una immagine");
  364.             return "L'allarme è passivo";
  365.         }
  366.        
  367.         String prefixUrl = allarmiConfig.getActiveAlarm_serviceUrl();
  368.         if(prefixUrl.endsWith("/")==false){
  369.             prefixUrl = prefixUrl + "/";
  370.         }
  371.         prefixUrl = prefixUrl + "gestione/attivi/"+allarme.getNome()+"/image";
  372.         return AllarmiUtils.sendToAllarme(allarmiConfig, prefixUrl.toString(), log);
  373.     }
  374.    
  375.     public static void refreshActiveThreadState(ConfigurazioneAllarmeBean allarme, Logger log, AlarmEngineConfig allarmiConfig) throws Exception{
  376.         if(TipoAllarme.PASSIVO.equals(allarme.getTipoAllarme())){
  377.             // NOTA: il tipo di allarme non è modificabile.
  378.             log.debug("Allarme ["+allarme.getNome()+"] è passivo. Non contiene una immagine");
  379.             return;
  380.         }
  381.        
  382.         String prefixUrl = allarmiConfig.getActiveAlarm_serviceUrl();
  383.         if(prefixUrl.endsWith("/")==false){
  384.             prefixUrl = prefixUrl + "/";
  385.         }
  386.         prefixUrl = prefixUrl + "gestione/attivi/"+allarme.getNome()+"/refresh";
  387.         AllarmiUtils.sendToAllarme(allarmiConfig, prefixUrl.toString(), log);
  388.     }
  389.    
  390.     public static String getActiveThreadImages(Logger log, AlarmEngineConfig allarmiConfig) throws Exception{

  391.         String prefixUrl = allarmiConfig.getActiveAlarm_serviceUrl();
  392.         if(prefixUrl.endsWith("/")==false){
  393.             prefixUrl = prefixUrl + "/";
  394.         }
  395.         prefixUrl = prefixUrl + "gestione/attivi/image";
  396.         return AllarmiUtils.sendToAllarme(allarmiConfig, prefixUrl.toString(), log);
  397.     }
  398.    
  399.     public static void startActiveThreads(Logger log, AlarmEngineConfig allarmiConfig) throws Exception{
  400.         _manageActiveThreads(log, allarmiConfig, "start");  
  401.     }
  402.     public static void restartActiveThreads(Logger log, AlarmEngineConfig allarmiConfig) throws Exception{
  403.         _manageActiveThreads(log, allarmiConfig, "restart");    
  404.     }
  405.     public static void stopActiveThreads(Logger log, AlarmEngineConfig allarmiConfig) throws Exception{
  406.         _manageActiveThreads(log, allarmiConfig, "stop");  
  407.     }
  408.     public static void _manageActiveThreads(Logger log, AlarmEngineConfig allarmiConfig, String operazione) throws Exception{
  409.        
  410.         List<String> post_urls = new ArrayList<>();
  411.         List<String> post_contents = new ArrayList<>();
  412.                
  413.         String prefixUrl = allarmiConfig.getActiveAlarm_serviceUrl();
  414.         if(prefixUrl.endsWith("/")==false){
  415.             prefixUrl = prefixUrl + "/";
  416.         }
  417.         prefixUrl = prefixUrl + "gestione/attivi";
  418.         post_urls.add(prefixUrl);
  419.         post_contents.add("{\"operazione\": \""+operazione+"\"}");
  420.                
  421.         AllarmiUtils.sendToAllarmi(allarmiConfig, post_urls, post_contents, log);
  422.        
  423.     }
  424.    
  425.     public static String getTipoNomeMittente(AllarmeFiltro configurazioneFiltro) {
  426.         if (configurazioneFiltro != null && StringUtils.isNotEmpty(configurazioneFiltro.getNomeFruitore()) && !"*".equals(configurazioneFiltro.getNomeFruitore())) {
  427.             String res = configurazioneFiltro.getTipoFruitore() + "/" + configurazioneFiltro.getNomeFruitore();
  428.             return res;
  429.         }
  430.         return null;
  431.     }
  432.    
  433.     public static String getTipoNomeDestinatario(AllarmeFiltro configurazioneFiltro) {
  434.         if (configurazioneFiltro != null && StringUtils.isNotEmpty(configurazioneFiltro.getNomeErogatore()) && !"*".equals(configurazioneFiltro.getNomeErogatore())) {
  435.             String res = configurazioneFiltro.getTipoErogatore() + "/" + configurazioneFiltro.getNomeErogatore();
  436.             return res;
  437.         }
  438.         return null;
  439.     }
  440.    
  441.    
  442.     @SuppressWarnings("deprecation")
  443.     public static String getTipoNomeServizio(AllarmeFiltro configurazioneFiltro, Logger log, boolean controlloAllarmiFiltroApiSoggettoErogatore) {
  444.         if (configurazioneFiltro != null && StringUtils.isNotEmpty(configurazioneFiltro.getNomeServizio()) && !"*".equals(configurazioneFiltro.getNomeServizio())) {
  445.            
  446.             IDServizio idServizio = new IDServizio();
  447.             idServizio.setNome(configurazioneFiltro.getNomeServizio());
  448.             idServizio.setTipo(configurazioneFiltro.getTipoServizio());
  449.             idServizio.setVersione(configurazioneFiltro.getVersioneServizio());
  450.             String res;
  451.             try {
  452.                 if(controlloAllarmiFiltroApiSoggettoErogatore) {
  453.                     IDSoggetto erogatore = new IDSoggetto(configurazioneFiltro.getTipoErogatore(), configurazioneFiltro.getNomeErogatore());
  454.                     idServizio.setSoggettoErogatore(erogatore );
  455.                    
  456.                     res = NamingUtils.getLabelAccordoServizioParteSpecifica(idServizio);
  457.                 }
  458.                 else {
  459.                     res = NamingUtils.getLabelAccordoServizioParteSpecificaSenzaErogatore(idServizio );
  460.                 }
  461.                 return res;
  462.             } catch (Exception e) {
  463.                 log.error(e.getMessage(),e);
  464.             }
  465.         }
  466.         return null;
  467.     }
  468.    
  469.     public static String getAzione(AllarmeFiltro configurazioneFiltro) {
  470.         if (configurazioneFiltro != null && StringUtils.isNotEmpty(configurazioneFiltro.getAzione()) && !"*".equals(configurazioneFiltro.getAzione())) {
  471.             String res = configurazioneFiltro.getAzione();
  472.             return res;
  473.         }
  474.         return null;
  475.     }
  476.    
  477.     private static String normalizeLabelPlugin(ConfigurazioneAllarmeBean allarme){
  478.         String nome = allarme.getPlugin().getLabel();
  479.         StringBuilder bf = new StringBuilder();
  480.        
  481.         String [] tmp = nome.split(" ");
  482.         for (int i = 0; i < tmp.length; i++) {
  483.             String t = tmp[i].trim();
  484.             if(t==null || t.length()<1){
  485.                 continue;
  486.             }
  487.             if(Character.isDigit(t.charAt(0))){
  488.                 bf.append(t);
  489.             }
  490.             else{
  491.                 bf.append((t.charAt(0)+"").toUpperCase());
  492.                 if(t.length()>1){
  493.                     bf.append(t.substring(1, t.length()));
  494.                 }
  495.             }
  496.         }
  497.        
  498.         return bf.toString();
  499.     }
  500.    
  501.     public static String costruisciAliasAllarme(ConfigurazioneAllarmeBean allarme, Logger log, Context context){
  502.        
  503.         StringBuilder bf = new StringBuilder();
  504.         bf.append(normalizeLabelPlugin(allarme));
  505.        
  506.         // Ci viene Concatenato anche il Filtro (non dovrebbe più servire)
  507.         /*
  508.         AllarmeFiltro configurazioneFiltro = allarme.getFiltro();
  509.         if(AllarmiUtils.getTipoNomeMittente(configurazioneFiltro)!=null){
  510.             bf.append("_M-");
  511.             bf.append(AllarmiUtils.getTipoNomeMittente(configurazioneFiltro));
  512.         }
  513.         if(AllarmiUtils.getTipoNomeDestinatario(configurazioneFiltro)!=null){
  514.             bf.append("_D-");
  515.             bf.append(AllarmiUtils.getTipoNomeDestinatario(configurazioneFiltro));
  516.         }
  517.         if(AllarmiUtils.getTipoNomeServizio(configurazioneFiltro)!=null){
  518.             bf.append("_S-");
  519.             bf.append(AllarmiUtils.getTipoNomeServizio(configurazioneFiltro));
  520.         }
  521.         if(AllarmiUtils.getAzione(configurazioneFiltro)!=null){
  522.             bf.append("_A-");
  523.             bf.append(AllarmiUtils.getAzione(configurazioneFiltro));
  524.         }
  525.         /*/
  526.        
  527.         String nome = bf.toString();
  528.        
  529.         String p = "";
  530.         String s = "";
  531.         try{
  532.             if(allarme!=null && allarme.getPlugin()!=null && allarme.getPlugin().getClassName()!=null){
  533.                 IDynamicLoader dl = DynamicFactory.getInstance().newDynamicLoader(TipoPlugin.ALLARME, allarme.getTipo(), allarme.getPlugin().getClassName(), log);
  534.                 IAlarmProcessing alarm = (IAlarmProcessing) dl.newInstance();
  535.                 p = alarm.getAutomaticPrefixName(context);
  536.                 //System.out.println("P ["+p+"]");
  537.                 s = alarm.getAutomaticSuffixName(context);
  538.                 //System.out.println("S ["+s+"]");
  539.             }
  540.                
  541.         }catch(Exception e){
  542.             log.error(e.getMessage(), e);
  543.         }
  544.        
  545.         if(p==null){
  546.             p = "";
  547.         }
  548.         if(s==null){
  549.             s = "";
  550.         }
  551.         return p+nome+s;
  552.     }
  553.    
  554.     public static String getLabelStato(StatoAllarme stato){
  555.         if(stato!=null){
  556.             switch (stato) {
  557.             case OK:
  558.                 return "Ok";
  559.             case WARNING:
  560.                 return "Warning";
  561.             case ERROR:
  562.                 return "Error";
  563.             }
  564.         }
  565.         return null;
  566.     }
  567. }