1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.stats.impl

File VisitStats.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

4
34
25
2
310
131
27
0.79
1.36
12.5
1.08

Classes

Class Line # Actions
VisitStats 33 34 0% 27 63
0.00%
VisitStats.Property 40 0 - 0 0
-1.0 -
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package com.xpn.xwiki.stats.impl;
21   
22    import java.util.Date;
23   
24    import org.apache.commons.lang3.StringUtils;
25   
26    import com.xpn.xwiki.stats.impl.StatsUtil.PeriodType;
27   
28    /**
29    * The visit statistics database object.
30    *
31    * @version $Id: f92efeee2a26813fb1e3634e9d7ccc6c2b61cfaa $
32    */
 
33    public class VisitStats extends XWikiStats
34    {
35    /**
36    * The properties of visit statistics object.
37    *
38    * @version $Id: f92efeee2a26813fb1e3634e9d7ccc6c2b61cfaa $
39    */
 
40    public enum Property
41    {
42    /**
43    * The name of the property containing the number of saved pages during this visit.
44    */
45    pageSaves,
46   
47    /**
48    * The name of the property containing the number of downloaded pages during this visit.
49    */
50    downloads,
51   
52    /**
53    * The name of the property containing the starting date of the user visit.
54    */
55    startDate,
56   
57    /**
58    * The name of the property containing the ending date of the user visit.
59    */
60    endDate,
61   
62    /**
63    * The name of the property containing the unique id of the user visit.
64    */
65    uniqueID,
66   
67    /**
68    * The name of the property containing the cookie id of the user.
69    */
70    cookie,
71   
72    /**
73    * The name of the property containing the IP address of the user.
74    */
75    ip,
76   
77    /**
78    * The name of the property containing the user agent of the user.
79    */
80    userAgent
81    }
82   
83    /**
84    * The previous visit object.
85    */
86    protected VisitStats oldObject;
87   
88    /**
89    * Default {@link VisitStats} constructor.
90    */
 
91  0 toggle public VisitStats()
92    {
93    }
94   
95    /**
96    * @param user the user name.
97    * @param uniqueID the visit object unique id.
98    * @param cookie the cookie id.
99    * @param ip the IP of the user.
100    * @param userAgent the user agent of the user.
101    * @param startDate the starting date of the visit.
102    * @param periodType the type of the period.
103    */
 
104  0 toggle public VisitStats(String user, String uniqueID, String cookie, String ip, String userAgent,
105    Date startDate, PeriodType periodType)
106    {
107  0 super(startDate, periodType);
108   
109  0 setName(user);
110  0 setStartDate(startDate);
111  0 setUniqueID(uniqueID);
112  0 setCookie(cookie);
113  0 setIP(ip);
114  0 setUserAgent(userAgent);
115    }
116   
117    /**
118    * Store previous object to be able to remove it from the database later.
119    *
120    * @param vobject the previous object.
121    */
 
122  0 toggle public void rememberOldObject(VisitStats vobject)
123    {
124  0 if (this.oldObject == null) {
125  0 this.oldObject = vobject;
126    }
127    }
128   
129    /**
130    * Set old visit object to null.
131    */
 
132  0 toggle public void unrememberOldObject()
133    {
134  0 this.oldObject = null;
135    }
136   
137    /**
138    * @return the previous visit object.
139    */
 
140  0 toggle public VisitStats getOldObject()
141    {
142  0 return this.oldObject;
143    }
144   
145    /**
146    * @return the number of saved pages during this visit.
147    */
 
148  0 toggle public int getPageSaves()
149    {
150  0 return getIntValue(Property.pageSaves.toString());
151    }
152   
153    /**
154    * @param pageSaves the number of saved pages during this visit.
155    */
 
156  0 toggle public void setPageSaves(int pageSaves)
157    {
158  0 setIntValue(Property.pageSaves.toString(), pageSaves);
159    }
160   
161    /**
162    * Add 1 to the number of saved pages during this visit.
163    */
 
164  0 toggle public void incPageSaves()
165    {
166  0 setIntValue(Property.pageSaves.toString(), getPageSaves() + 1);
167    }
168   
169    /**
170    * @return the number of downloaded pages during this visit.
171    */
 
172  0 toggle public int getDownloads()
173    {
174  0 return getIntValue(Property.downloads.toString());
175    }
176   
177    /**
178    * @param downloads the number of downloaded pages during this visit.
179    */
 
180  0 toggle public void setDownloads(int downloads)
181    {
182  0 setIntValue(Property.downloads.toString(), downloads);
183    }
184   
185    /**
186    * Add 1 to the number of downloaded pages during this visit.
187    */
 
188  0 toggle public void incDownloads()
189    {
190  0 setIntValue(Property.downloads.toString(), getDownloads() + 1);
191    }
192   
193    /**
194    * @return the starting date of the user visit.
195    */
 
196  0 toggle public Date getStartDate()
197    {
198  0 return getDateValue(Property.startDate.toString());
199    }
200   
201    /**
202    * @param startDate the starting date of the user visit.
203    */
 
204  0 toggle public void setStartDate(Date startDate)
205    {
206  0 setDateValue(Property.startDate.toString(), startDate);
207    }
208   
209    /**
210    * @return the ending date of the user visit.
211    */
 
212  0 toggle public Date getEndDate()
213    {
214  0 return getDateValue(Property.endDate.toString());
215    }
216   
217    /**
218    * @param endDate the ending date of the user visit.
219    */
 
220  0 toggle public void setEndDate(Date endDate)
221    {
222  0 setDateValue(Property.endDate.toString(), endDate);
223    }
224   
225    /**
226    * @return the unique id of the user visit.
227    */
 
228  0 toggle public String getUniqueID()
229    {
230  0 return getStringValue(Property.uniqueID.toString());
231    }
232   
233    /**
234    * @param uniqueID the unique id of the user visit.
235    */
 
236  0 toggle public void setUniqueID(String uniqueID)
237    {
238    // Changing the unique ID is changing the number
239  0 if (getStartDate() != null) {
240  0 String nb = uniqueID + getStartDate().getTime();
241  0 setNumber(nb.hashCode());
242    }
243   
244  0 setStringValue(Property.uniqueID.toString(), uniqueID);
245    }
246   
247    /**
248    * @return the cookie id of the user.
249    */
 
250  0 toggle public String getCookie()
251    {
252  0 return getStringValue(Property.cookie.toString());
253    }
254   
255    /**
256    * @param cookie the cookie id of the user.
257    */
 
258  0 toggle public void setCookie(String cookie)
259    {
260  0 setStringValue(Property.cookie.toString(), StringUtils.defaultString(cookie));
261    }
262   
263    /**
264    * @return the IP address of the user.
265    */
 
266  0 toggle public String getIP()
267    {
268  0 return getStringValue(Property.ip.toString());
269    }
270   
271    /**
272    * @param ip the IP address of the user.
273    */
 
274  0 toggle public void setIP(String ip)
275    {
276  0 setStringValue(Property.ip.toString(), ip);
277    }
278   
279    /**
280    * @return the user agent of the user.
281    */
 
282  0 toggle public String getUserAgent()
283    {
284  0 return getStringValue(Property.userAgent.toString());
285    }
286   
287    /**
288    * @param userAgent the user agent of the user.
289    */
 
290  0 toggle public void setUserAgent(String userAgent)
291    {
292  0 setStringValue(Property.userAgent.toString(), StringUtils.defaultString(userAgent));
293    }
294   
295    /**
296    * @return the user name.
297    */
 
298  0 toggle public String getUser()
299    {
300  0 return getName();
301    }
302   
303    /**
304    * @param user the user name.
305    */
 
306  0 toggle public void setUser(String user)
307    {
308  0 setName(user);
309    }
310    }