StatisticsInfoUtils.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 org.openspcoop2.core.statistiche.StatisticaInfo;
  22. import org.openspcoop2.core.statistiche.constants.TipoIntervalloStatistico;
  23. import org.openspcoop2.core.statistiche.dao.IStatisticaInfoService;
  24. import org.openspcoop2.core.statistiche.dao.IStatisticaInfoServiceSearch;

  25. import java.util.Date;

  26. import org.slf4j.Logger;
  27. import org.openspcoop2.generic_project.exception.ExpressionException;
  28. import org.openspcoop2.generic_project.exception.ExpressionNotImplementedException;
  29. import org.openspcoop2.generic_project.exception.MultipleResultException;
  30. import org.openspcoop2.generic_project.exception.NotFoundException;
  31. import org.openspcoop2.generic_project.exception.NotImplementedException;
  32. import org.openspcoop2.generic_project.exception.ServiceException;
  33. import org.openspcoop2.generic_project.expression.IExpression;

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

  42.    
  43.     public static Date readDataUltimaGenerazioneStatistiche(IStatisticaInfoServiceSearch statisticaInfoSearchDAO,TipoIntervalloStatistico tipoStatistica,Logger logger) throws NotFoundException  {



  44.         try{
  45.             IExpression expr = statisticaInfoSearchDAO.newExpression();

  46.             expr.equals(StatisticaInfo.model().TIPO_STATISTICA, tipoStatistica);

  47.             StatisticaInfo info = statisticaInfoSearchDAO.find(expr);

  48.             return info.getDataUltimaGenerazione();

  49.         } catch (ServiceException e){
  50.             logger.error(e.getMessage(), e);
  51.         } catch (NotImplementedException e) {
  52.             logger.error(e.getMessage(), e);
  53.         } catch (ExpressionNotImplementedException e) {
  54.             logger.error(e.getMessage(), e);
  55.         } catch (ExpressionException e) {
  56.             logger.error(e.getMessage(), e);
  57.         } catch (NotFoundException e) {
  58.             logger.error(e.getMessage(), e);
  59.         } catch (MultipleResultException e) {
  60.             logger.error(e.getMessage(), e);
  61.         }

  62.         return new Date(0);

  63.     }
  64.    
  65.     public static  void updateDataUltimaGenerazioneStatistiche(IStatisticaInfoServiceSearch statisticaInfoSearchDAO,IStatisticaInfoService statisticaInfoDAO,
  66.             TipoIntervalloStatistico tipoStatistica,Logger logger,Date date) throws Exception{

  67.         try{
  68.             IExpression expr = statisticaInfoSearchDAO.newExpression();

  69.             expr.equals(StatisticaInfo.model().TIPO_STATISTICA, tipoStatistica);

  70.             StatisticaInfo info = statisticaInfoSearchDAO.find(expr);

  71.             info.setDataUltimaGenerazione(date);

  72.             statisticaInfoDAO.update(info);


  73.         } catch (ServiceException e){
  74.             logger.error(e.getMessage(), e);
  75.         } catch (NotImplementedException e) {
  76.             logger.error(e.getMessage(), e);
  77.         } catch (ExpressionNotImplementedException e) {
  78.             logger.error(e.getMessage(), e);
  79.         } catch (ExpressionException e) {
  80.             logger.error(e.getMessage(), e);
  81.         } catch (NotFoundException e) {
  82.             logger.error(e.getMessage(), e);

  83.             // non ho trovato nessuna data valida, inserisco l'ultima generata

  84.             StatisticaInfo info = new StatisticaInfo();
  85.             info.setDataUltimaGenerazione(date);
  86.             info.setTipoStatistica(tipoStatistica);

  87.             statisticaInfoDAO.create(info);

  88.         } catch (MultipleResultException e) {
  89.             logger.error(e.getMessage(), e);
  90.         }

  91.     }
  92.    
  93. }