View Javadoc
1   /*******************************************************************************
2    *   Gisgraphy Project 
3    * 
4    *   This library is free software; you can redistribute it and/or
5    *   modify it under the terms of the GNU Lesser General Public
6    *   License as published by the Free Software Foundation; either
7    *   version 2.1 of the License, or (at your option) any later version.
8    * 
9    *   This library is distributed in the hope that it will be useful,
10   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   *   Lesser General Public License for more details.
13   * 
14   *   You should have received a copy of the GNU Lesser General Public
15   *   License along with this library; if not, write to the Free Software
16   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
17   * 
18   *  Copyright 2008  Gisgraphy project 
19   *  David Masclet <davidmasclet@gisgraphy.com>
20   *  
21   *  
22   *******************************************************************************/
23  package com.gisgraphy.webapp.action;
24  
25  import java.util.List;
26  
27  import org.springframework.beans.factory.annotation.Required;
28  
29  import com.gisgraphy.domain.repository.IStatsUsageDao;
30  import com.gisgraphy.service.IStatsUsageService;
31  import com.gisgraphy.stats.StatsUsage;
32  import com.opensymphony.xwork2.Action;
33  import com.opensymphony.xwork2.ActionSupport;
34  
35  /**
36   * stats Action
37   * 
38   * @author <a href="mailto:david.masclet@gisgraphy.com">David Masclet</a>
39   */
40  public class StatsAction extends ActionSupport {
41  
42      /**
43       * Default serialId
44       */
45      private static final long serialVersionUID = -9018894533914543310L;
46  
47      private IStatsUsageDao statsUsageDao;
48  
49      private List<StatsUsage> statsUsages;
50      
51      private Long totalUsage;
52  
53      /**
54       * @return the statsUsages
55       */
56      public List<StatsUsage> getStatsUsages() {
57  	return statsUsages;
58      }
59  
60      /**
61       * @param statsUsageDao
62       *                the statsUsageDao to set
63       */
64      @Required
65      public void setStatsUsageDao(IStatsUsageDao statsUsageDao) {
66  	this.statsUsageDao = statsUsageDao;
67      }
68  
69      /*
70       * (non-Javadoc)
71       * 
72       * @see com.opensymphony.xwork2.ActionSupport#execute()
73       */
74      @Override
75      public String execute() throws Exception {
76  	statsUsages = statsUsageDao.getAll();
77  	totalUsage = 0L;
78  	for (StatsUsage statsUsage: statsUsages){
79  	    totalUsage = totalUsage + statsUsage.getUsage();
80  	}
81  	return Action.SUCCESS;
82      }
83  
84      /**
85       * @return the totalUsage
86       */
87      public Long getTotalUsage() {
88          return totalUsage;
89      }
90      
91      public int getFlushFrequency(){
92  	return IStatsUsageService.FLUSH_THRESHOLD;
93      }
94  
95  }