DynamicExtendedInfoDiagnosticoControlloTraffico.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.pdd.logger.diagnostica;

  21. import java.util.HashMap;
  22. import java.util.Map;

  23. import org.openspcoop2.core.commons.CoreException;
  24. import org.openspcoop2.pdd.core.controllo_traffico.GeneratoreMessaggiErrore;
  25. import org.openspcoop2.pdd.logger.record.CostantiDati;

  26. /**    
  27.  * DynamicExtendedInfoDiagnosticoControlloTraffico
  28.  *
  29.  * @author Poli Andrea (poli@link.it)
  30.  * @author $Author$
  31.  * @version $Rev$, $Date$
  32.  */
  33. public class DynamicExtendedInfoDiagnosticoControlloTraffico {

  34.     private DynamicExtendedInfoDiagnosticoControlloTraffico() {}
  35.    
  36.     public static final int NUMERO_TEMPLATE_DINAMICI_ERRORI_GENERICI = 4; // sono i diagnostici emessi dai moduli ricezione contenuti o buste
  37.     public static final int NUMERO_TEMPLATE_DINAMICI_DETTAGLI_SINGOLO_ERRORE = 10; // sono i diagnostici di "appoggio" registrati nel modulo 'all' utilizzati per generare l'errore
  38.     // NOTA: siccome tanto viene salvato direttamente il diagnostico emesso dai moduli ricezione contenuti o buste non sembra necessario salvare i singoli dettagli visto che sono giĆ  nell'errore generico
  39.    
  40.     private static final boolean SAVE_SINGLE_VALUE_OF_MESSAGE_ERROR = false;
  41.    
  42.     public static Map<String, String> convertToProperties(String value) throws CoreException{
  43.         if(value.contains(CostantiMappingDiagnostici.DIAGNOSTIC_WITH_DYNAMIC_INFO_SEPARATOR)){
  44.            
  45.             String [] tmp = value.split(CostantiMappingDiagnostici.DIAGNOSTIC_WITH_DYNAMIC_INFO_SEPARATOR);
  46.             if(tmp==null || tmp.length<=0){
  47.                 throw new CoreException("Split value ["+value+"] with ["+CostantiMappingDiagnostici.DIAGNOSTIC_WITH_DYNAMIC_INFO_SEPARATOR+"] failed");
  48.             }
  49.             int numeroTemplateDinamici = NUMERO_TEMPLATE_DINAMICI_ERRORI_GENERICI;
  50.             if(SAVE_SINGLE_VALUE_OF_MESSAGE_ERROR){
  51.                 numeroTemplateDinamici+=NUMERO_TEMPLATE_DINAMICI_DETTAGLI_SINGOLO_ERRORE;
  52.             }
  53.             if(tmp.length!=numeroTemplateDinamici){
  54.                 throw new CoreException("Split value ["+value+"] with ["+CostantiMappingDiagnostici.DIAGNOSTIC_WITH_DYNAMIC_INFO_SEPARATOR+
  55.                         "] failed (expected:"+numeroTemplateDinamici+" found:"+tmp.length+")");
  56.             }
  57.            
  58.             return convertToProperties(tmp);
  59.            
  60.         }
  61.         throw new CoreException("Value is null");
  62.     }
  63.     private static Map<String, String> convertToProperties(String [] tmp) {
  64.         Map<String, String> map = new HashMap<>();
  65.        
  66.         for (int i = 0; i < tmp.length; i++) {
  67.            
  68.             String v = tmp[i];
  69.             if(v==null || (v.length()==1 && CostantiDati.NON_PRESENTE.equals(v))){
  70.                 continue;
  71.             }
  72.            
  73.             if(i==0)
  74.                 map.put(GeneratoreMessaggiErrore.TEMPLATE_POLICY_ACTIVE_ID,v);
  75.             else if(i==1)
  76.                 map.put(GeneratoreMessaggiErrore.TEMPLATE_POLICY_VIOLATA_MOTIVO,v);
  77.             else if(i==2)
  78.                 map.put(GeneratoreMessaggiErrore.TEMPLATE_POLICY_FILTRATA_MOTIVO,v);
  79.             else if(i==3)
  80.                 map.put(GeneratoreMessaggiErrore.TEMPLATE_POLICY_NON_APPLICABILE_MOTIVO,v);
  81.            
  82.             if(SAVE_SINGLE_VALUE_OF_MESSAGE_ERROR){
  83.                 fillError(map, i, v);
  84.             }
  85.            
  86.         }
  87.        
  88.         return map;
  89.     }
  90.     private static void fillError(Map<String, String> map, int i, String v) {
  91.         if(i==4)
  92.             map.put(GeneratoreMessaggiErrore.TEMPLATE_POLICY_VALORE_SOGLIA,v);
  93.         else if(i==5)
  94.             map.put(GeneratoreMessaggiErrore.TEMPLATE_POLICY_TIPOLOGIA_TEMPO_MEDIO,v);
  95.         else if(i==6)
  96.             map.put(GeneratoreMessaggiErrore.TEMPLATE_POLICY_VALORE_RILEVATO,v);
  97.         else if(i==7)
  98.             map.put(GeneratoreMessaggiErrore.TEMPLATE_POLICY_AVG_TIME_RILEVATO,v);
  99.         else if(i==8)
  100.             map.put(GeneratoreMessaggiErrore.TEMPLATE_POLICY_VALORE_SOGLIA_DEGRADO_PRESTAZIONALE,v);
  101.         else if(i==9)
  102.             map.put(GeneratoreMessaggiErrore.TEMPLATE_POLICY_GRUPPO,v);
  103.         else if(i==10)
  104.             map.put(GeneratoreMessaggiErrore.TEMPLATE_POLICY_INTERVALLO_TEMPORALE,v);
  105.         else if(i==11)
  106.             map.put(GeneratoreMessaggiErrore.TEMPLATE_POLICY_NOME_ALLARME,v);
  107.         else if(i==12)
  108.             map.put(GeneratoreMessaggiErrore.TEMPLATE_POLICY_STATO_ALLARME,v);
  109.         else if(i==13)
  110.             map.put(GeneratoreMessaggiErrore.TEMPLATE_POLICY_STATO_ALLARME_ATTESO,v);
  111.     }
  112. }