StatisticsForceIndexConfig.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.statistic;

  21. import java.io.File;
  22. import java.io.FileInputStream;
  23. import java.io.IOException;
  24. import java.io.InputStream;
  25. import java.util.ArrayList;
  26. import java.util.List;
  27. import java.util.Properties;

  28. import org.openspcoop2.core.transazioni.Transazione;
  29. import org.openspcoop2.generic_project.expression.Index;
  30. import org.openspcoop2.utils.UtilsException;
  31. import org.openspcoop2.utils.properties.InstanceProperties;

  32. /**
  33.  * StatisticsForceIndexConfig
  34.  *
  35.  * @author Poli Andrea (apoli@link.it)
  36.  * @author $Author$
  37.  * @version $Rev$, $Date$
  38.  */
  39. public class StatisticsForceIndexConfig {

  40.     /** Lista di indici forzati */
  41.     private List<Index> transazioniForceIndexGroupByNumeroDimensione = null;
  42.     private List<Index> transazioniForceIndexGroupByLatenze = null;
  43.     private List<Index> transazioniForceIndexGroupByCustomNumeroDimensione = null;
  44.     private List<Index> transazioniForceIndexGroupByCustomLatenze = null;
  45.    
  46.     public StatisticsForceIndexConfig(){}
  47.    
  48.     private static final String P_REPO = "statistiche.generazione.forceIndex.repository";
  49.     private static final String P_GROUPBY_NUMERO_DIMENSIONE = "statistiche.generazione.forceIndex.groupBy.numero_dimensione";
  50.     private static final String P_GROUPBY_LATENZA = "statistiche.generazione.forceIndex.groupBy.latenza";
  51.     private static final String P_GROUPBY_CUSTOM_NUMERO_DIMENSIONE = "statistiche.generazione.forceIndex.groupBy.custom.numero_dimensione";
  52.     private static final String P_GROUPBY_CUSTOM_LATENZA = "statistiche.generazione.forceIndex.groupBy.custom.latenza";
  53.    
  54.     public StatisticsForceIndexConfig(Properties p) throws IOException {
  55.        
  56.         String tmpRepo = p.getProperty(StatisticsForceIndexConfig.P_REPO);
  57.         Properties pRepoExternal = this.getExternalRepository(tmpRepo);

  58.         String groupByNumeroDimensione = p.getProperty(StatisticsForceIndexConfig.P_GROUPBY_NUMERO_DIMENSIONE);
  59.         if(groupByNumeroDimensione!=null){
  60.             groupByNumeroDimensione = groupByNumeroDimensione.trim();
  61.         }
  62.         this.transazioniForceIndexGroupByNumeroDimensione = this.getIndexList(StatisticsForceIndexConfig.P_GROUPBY_NUMERO_DIMENSIONE, groupByNumeroDimensione, pRepoExternal);
  63.        
  64.         String groupByLatenza = p.getProperty(StatisticsForceIndexConfig.P_GROUPBY_LATENZA);
  65.         if(groupByLatenza!=null){
  66.             groupByLatenza = groupByLatenza.trim();
  67.         }
  68.         this.transazioniForceIndexGroupByLatenze = this.getIndexList(StatisticsForceIndexConfig.P_GROUPBY_LATENZA, groupByLatenza, pRepoExternal);
  69.        
  70.         String groupCustomByNumeroDimensione = p.getProperty(StatisticsForceIndexConfig.P_GROUPBY_CUSTOM_NUMERO_DIMENSIONE);
  71.         if(groupCustomByNumeroDimensione!=null){
  72.             groupCustomByNumeroDimensione = groupCustomByNumeroDimensione.trim();
  73.         }
  74.         this.transazioniForceIndexGroupByCustomNumeroDimensione = this.getIndexList(StatisticsForceIndexConfig.P_GROUPBY_CUSTOM_NUMERO_DIMENSIONE, groupCustomByNumeroDimensione, pRepoExternal);
  75.        
  76.         String groupCustomByLatenza = p.getProperty(StatisticsForceIndexConfig.P_GROUPBY_CUSTOM_LATENZA);
  77.         if(groupCustomByLatenza!=null){
  78.             groupCustomByLatenza = groupCustomByLatenza.trim();
  79.         }
  80.         this.transazioniForceIndexGroupByCustomLatenze = this.getIndexList(StatisticsForceIndexConfig.P_GROUPBY_CUSTOM_LATENZA, groupCustomByLatenza, pRepoExternal);
  81.        
  82.     }
  83.    
  84.     public StatisticsForceIndexConfig(InstanceProperties p) throws IOException, UtilsException {
  85.        
  86.         String tmpRepo = p.getValueConvertEnvProperties(StatisticsForceIndexConfig.P_REPO);
  87.         Properties pRepoExternal = this.getExternalRepository(tmpRepo);
  88.        
  89.         String groupByNumeroDimensione = p.getValueConvertEnvProperties(StatisticsForceIndexConfig.P_GROUPBY_NUMERO_DIMENSIONE);
  90.         if(groupByNumeroDimensione!=null){
  91.             groupByNumeroDimensione = groupByNumeroDimensione.trim();
  92.         }
  93.         this.transazioniForceIndexGroupByNumeroDimensione = this.getIndexList(StatisticsForceIndexConfig.P_GROUPBY_NUMERO_DIMENSIONE, groupByNumeroDimensione, pRepoExternal);
  94.        
  95.         String groupByLatenza = p.getValueConvertEnvProperties(StatisticsForceIndexConfig.P_GROUPBY_LATENZA);
  96.         if(groupByLatenza!=null){
  97.             groupByLatenza = groupByLatenza.trim();
  98.         }
  99.         this.transazioniForceIndexGroupByLatenze = this.getIndexList(StatisticsForceIndexConfig.P_GROUPBY_LATENZA, groupByLatenza, pRepoExternal);
  100.        
  101.         String groupCustomByNumeroDimensione = p.getValueConvertEnvProperties(StatisticsForceIndexConfig.P_GROUPBY_CUSTOM_NUMERO_DIMENSIONE);
  102.         if(groupCustomByNumeroDimensione!=null){
  103.             groupCustomByNumeroDimensione = groupCustomByNumeroDimensione.trim();
  104.         }
  105.         this.transazioniForceIndexGroupByCustomNumeroDimensione = this.getIndexList(StatisticsForceIndexConfig.P_GROUPBY_CUSTOM_NUMERO_DIMENSIONE, groupCustomByNumeroDimensione, pRepoExternal);
  106.        
  107.         String groupCustomByLatenza = p.getValueConvertEnvProperties(StatisticsForceIndexConfig.P_GROUPBY_CUSTOM_LATENZA);
  108.         if(groupCustomByLatenza!=null){
  109.             groupCustomByLatenza = groupCustomByLatenza.trim();
  110.         }
  111.         this.transazioniForceIndexGroupByCustomLatenze = this.getIndexList(StatisticsForceIndexConfig.P_GROUPBY_CUSTOM_LATENZA, groupCustomByLatenza, pRepoExternal);
  112.        
  113.     }
  114.    
  115.     private Properties getExternalRepository(String tmpRepo) throws IOException{
  116.         Properties pRepoExternal = null;
  117.         if(tmpRepo!=null){
  118.             File f = new File(tmpRepo);
  119.             try (InputStream is = f.exists() ? new FileInputStream(f) : StatisticsForceIndexConfig.class.getResourceAsStream(tmpRepo)){ // provo a cercarlo nel classpath se non e' un file esistente
  120.                 if(is!=null){
  121.                     pRepoExternal = new Properties();
  122.                     pRepoExternal.load(is);
  123.                 }
  124.             }
  125.         }
  126.         return  pRepoExternal;
  127.     }
  128.    
  129.     private List<Index> getIndexList(String propertyName,String propertyValue, Properties externalRepository) {
  130.        
  131.         String s = null;
  132.         if(externalRepository!=null){
  133.             String tmp = externalRepository.getProperty(propertyName);
  134.             if(tmp!=null){
  135.                 s = tmp.trim();
  136.             }
  137.         }
  138.         if(s==null){
  139.             // provo a cercarlo nel file monitor
  140.             s = propertyValue;
  141.         }
  142.        
  143.         List<Index> l = null;
  144.         if(s!=null){
  145.             l = new ArrayList<>();
  146.             if(s.contains(",")){
  147.                 String [] split = s.split(",");
  148.                 for (int i = 0; i < split.length; i++) {
  149.                     l.add(new Index(Transazione.model(),split[i]));
  150.                 }
  151.             }
  152.             else{
  153.                 l.add(new Index(Transazione.model(),s));
  154.             }
  155.             return l;
  156.         }
  157.         return l;
  158.     }
  159.    

  160.     public List<Index> getTransazioniForceIndexGroupByNumeroDimensione() {
  161.         return this.transazioniForceIndexGroupByNumeroDimensione;
  162.     }

  163.     public void setTransazioniForceIndexGroupByNumeroDimensione(
  164.             List<Index> transazioniForceIndexGroupByNumeroDimensione) {
  165.         this.transazioniForceIndexGroupByNumeroDimensione = transazioniForceIndexGroupByNumeroDimensione;
  166.     }

  167.     public List<Index> getTransazioniForceIndexGroupByLatenze() {
  168.         return this.transazioniForceIndexGroupByLatenze;
  169.     }

  170.     public void setTransazioniForceIndexGroupByLatenze(List<Index> transazioniForceIndexGroupByLatenze) {
  171.         this.transazioniForceIndexGroupByLatenze = transazioniForceIndexGroupByLatenze;
  172.     }
  173.    
  174.     public List<Index> getTransazioniForceIndexGroupByCustomNumeroDimensione() {
  175.         return this.transazioniForceIndexGroupByCustomNumeroDimensione;
  176.     }

  177.     public void setTransazioniForceIndexGroupByCustomNumeroDimensione(
  178.             List<Index> transazioniForceIndexGroupByCustomNumeroDimensione) {
  179.         this.transazioniForceIndexGroupByCustomNumeroDimensione = transazioniForceIndexGroupByCustomNumeroDimensione;
  180.     }

  181.     public List<Index> getTransazioniForceIndexGroupByCustomLatenze() {
  182.         return this.transazioniForceIndexGroupByCustomLatenze;
  183.     }

  184.     public void setTransazioniForceIndexGroupByCustomLatenze(List<Index> transazioniForceIndexGroupByCustomLatenze) {
  185.         this.transazioniForceIndexGroupByCustomLatenze = transazioniForceIndexGroupByCustomLatenze;
  186.     }


  187. }