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

File VisitStatsStoreItem.java

 

Coverage histogram

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

Code metrics

6
19
3
1
107
53
8
0.42
6.33
3
2.67

Classes

Class Line # Actions
VisitStatsStoreItem 40 19 0% 8 28
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.StatsUtil.PeriodType;
31    import com.xpn.xwiki.stats.impl.VisitStats;
32    import com.xpn.xwiki.store.XWikiHibernateStore;
33   
34    /**
35    * Store visit statistics into the database.
36    *
37    * @version $Id: 273c3780f64e7288731343c4bc91af5c40f612d6 $
38    * @since 1.4M2
39    */
 
40    public class VisitStatsStoreItem extends AbstractStatsStoreItem
41    {
42    /**
43    * Logging tools.
44    */
45    private static final Logger LOGGER = LoggerFactory.getLogger(VisitStatsStoreItem.class);
46   
47    /**
48    * The {@link VisitStats} object to store.
49    */
50    private VisitStats visitStats;
51   
52    /**
53    * Create new instance of {@link VisitStatsStoreItem}.
54    *
55    * @param visitStats the {@link VisitStats} object to store.
56    * @param context the XWiki context.
57    */
 
58  0 toggle public VisitStatsStoreItem(VisitStats visitStats, XWikiContext context)
59    {
60  0 super(visitStats.getName(), new Date(), PeriodType.MONTH, context);
61  0 this.period = visitStats.getPeriod();
62   
63  0 this.visitStats = (VisitStats) visitStats.clone();
64    }
65   
 
66  0 toggle @Override
67    public String getId()
68    {
69  0 return String.format("%s %s %s %s", getClass(), this.visitStats.getName(), this.visitStats.getUniqueID(),
70    this.visitStats.getCookie());
71    }
72   
 
73  0 toggle @Override
74    public void storeInternal(List<XWikiStatsStoreItem> stats)
75    {
76  0 VisitStatsStoreItem firstItem = (VisitStatsStoreItem) stats.get(0);
77  0 VisitStats oldVisitStats = firstItem.visitStats.getOldObject();
78   
79  0 VisitStatsStoreItem lastItem = (VisitStatsStoreItem) stats.get(stats.size() - 1);
80  0 VisitStats newVisitStats = lastItem.visitStats;
81   
82  0 XWikiHibernateStore store = this.context.getWiki().getHibernateStore();
83  0 if (store == null) {
84  0 return;
85    }
86   
87  0 try {
88    // In case we have store the old object then we need to remove it before saving the
89    // other one because the ID info have changed
90  0 if (oldVisitStats != null) {
91  0 try {
92    // TODO Fix use of deprecated call.
93  0 store.deleteXWikiCollection(oldVisitStats, this.context, true, true);
94    } catch (Exception e) {
95  0 if (LOGGER.isWarnEnabled()) {
96  0 LOGGER.error("Failed to delete old visit statistics object from database [{}]", getId(), e);
97    }
98    }
99    }
100   
101    // TODO Fix use of deprecated call.
102  0 store.saveXWikiCollection(newVisitStats, this.context, true);
103    } catch (XWikiException e) {
104  0 LOGGER.error("Failed to save visit statistics object [{}]", getId(), e);
105    }
106    }
107    }