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

File RefererStatsStoreItem.java

 

Coverage histogram

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

Code metrics

4
16
3
1
109
50
7
0.44
5.33
3
2.33

Classes

Class Line # Actions
RefererStatsStoreItem 40 16 0% 7 23
0.00%
 

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.xwiki;
21   
22    import java.util.Date;
23    import java.util.List;
24   
25    import org.slf4j.Logger;
26    import org.slf4j.LoggerFactory;
27   
28    import com.xpn.xwiki.XWikiContext;
29    import com.xpn.xwiki.XWikiException;
30    import com.xpn.xwiki.stats.impl.RefererStats;
31    import com.xpn.xwiki.stats.impl.StatsUtil.PeriodType;
32    import com.xpn.xwiki.store.XWikiHibernateStore;
33   
34    /**
35    * Store referer statistics into the database.
36    *
37    * @version $Id: 0c74cb73a41dd81281de01ab4c31e2353cc16f82 $
38    * @since 1.4M2
39    */
 
40    public class RefererStatsStoreItem extends AbstractStatsStoreItem
41    {
42    /**
43    * Logging tools.
44    */
45    private static final Logger LOGGER = LoggerFactory.getLogger(RefererStatsStoreItem.class);
46   
47    /**
48    * The referer.
49    */
50    private String referer;
51   
52    /**
53    * Create new instance of {@link RefererStatsStoreItem}.
54    *
55    * @param name the full name of the document.
56    * @param periodDate the period date.
57    * @param periodType the period type.
58    * @param referer the referer.
59    * @param context the XWiki context.
60    */
 
61  0 toggle public RefererStatsStoreItem(String name, Date periodDate, PeriodType periodType, String referer,
62    XWikiContext context)
63    {
64  0 super(name, periodDate, periodType, context);
65   
66  0 this.referer = referer;
67    }
68   
 
69  0 toggle @Override
70    public String getId()
71    {
72  0 return String.format("%s %s %s %s", getClass(), this.name, this.referer, this.period);
73    }
74   
 
75  0 toggle @Override
76    public void storeInternal(List<XWikiStatsStoreItem> stats)
77    {
78  0 RefererStatsStoreItem lastItem = (RefererStatsStoreItem) stats.get(stats.size() - 1);
79   
80  0 XWikiHibernateStore store = this.context.getWiki().getHibernateStore();
81  0 if (store == null) {
82  0 return;
83    }
84   
85  0 RefererStats refererStat =
86    new RefererStats(lastItem.name, lastItem.referer, lastItem.periodDate, lastItem.periodType);
87   
88    // Load old statistics object from database
89  0 try {
90    // TODO Fix use of deprecated call.
91  0 store.loadXWikiCollection(refererStat, this.context, true);
92    } catch (XWikiException e) {
93  0 if (LOGGER.isDebugEnabled()) {
94  0 LOGGER.debug("Failed to load referer statictics object [" + getId() + "]");
95    }
96    }
97   
98    // Increment counters
99  0 refererStat.setIntValue("pageViews", refererStat.getPageViews() + stats.size());
100   
101    // Re-save statistics object
102  0 try {
103    // TODO Fix use of deprecated call.
104  0 store.saveXWikiCollection(refererStat, this.context, true);
105    } catch (XWikiException e) {
106  0 LOGGER.error("Failed to save referer statictics object [" + getId() + "]");
107    }
108    }
109    }