StatsGenerator.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.core.monitor.rs.server.api.impl.utils;

  21. import org.openspcoop2.core.commons.CoreException;
  22. import org.openspcoop2.generic_project.exception.NotFoundException;
  23. import org.openspcoop2.utils.service.context.IContext;
  24. import org.openspcoop2.web.monitor.core.bean.UserDetailsBean;
  25. import org.openspcoop2.web.monitor.statistiche.dao.ConfigurazioniGeneraliService;
  26. import org.openspcoop2.web.monitor.statistiche.dao.StatisticheGiornaliereService;
  27. import org.openspcoop2.web.monitor.statistiche.servlet.ReportExporter;

  28. /**
  29.  * StatsGenerator
  30.  *
  31.  * @author $Author$
  32.  * @version $Rev$, $Date$
  33.  *
  34.  */
  35. public class StatsGenerator {

  36.     public static byte[] generateReport(HttpRequestWrapper request, IContext context, StatisticheGiornaliereService statisticheService) throws CoreException, NotFoundException {
  37.        
  38.         HttpResponseWrapper wrapper = new HttpResponseWrapper(context.getServletResponse());
  39.        
  40.         try {
  41.             UserDetailsBean user = new UserDetailsBean();
  42.             SearchFormUtilities utilities = new SearchFormUtilities();
  43.             user.setUtente(utilities.getUtente(context));
  44.            
  45.             ReportExporter.generaStatistiche(request, wrapper, user, statisticheService);
  46.         }
  47.         catch(NotFoundException notFound) {
  48.             throw notFound;
  49.         }
  50.         catch(Exception e) {
  51.             throw new CoreException(e.getMessage(), e);
  52.         }
  53.    
  54.         byte[] report = wrapper.toByteArray();
  55.         if(report==null || report.length<=0) {
  56.             throw new NotFoundException("Empty Report");
  57.         }
  58.         return report;
  59.     }
  60.    
  61.     public static byte[] generateReport(HttpRequestWrapper request, IContext context, ConfigurazioniGeneraliService configurazioniService) throws CoreException, NotFoundException {
  62.        
  63.         HttpResponseWrapper wrapper = new HttpResponseWrapper(context.getServletResponse());
  64.        
  65.         try {
  66.             UserDetailsBean user = new UserDetailsBean();
  67.             SearchFormUtilities utilities = new SearchFormUtilities();
  68.             user.setUtente(utilities.getUtente(context));
  69.            
  70.             ReportExporter.generaConfigurazione(request, wrapper, user, configurazioniService);
  71.         }
  72.         catch(NotFoundException notFound) {
  73.             throw notFound;
  74.         }
  75.         catch(Exception e) {
  76.             throw new CoreException(e.getMessage(), e);
  77.         }
  78.    
  79.         byte[] report = wrapper.toByteArray();
  80.         if(report==null || report.length<=0) {
  81.             throw new NotFoundException("Empty Report");
  82.         }
  83.         return report;
  84.     }
  85.    
  86. }