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

File DocumentStatsStoreItem.java

 

Coverage histogram

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

Code metrics

6
21
3
1
128
58
8
0.38
7
3
2.67

Classes

Class Line # Actions
DocumentStatsStoreItem 40 21 0% 8 30
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.DocumentStats;
31    import com.xpn.xwiki.stats.impl.StatsUtil.PeriodType;
32    import com.xpn.xwiki.store.XWikiHibernateStore;
33   
34    /**
35    * Store document statistics into the database.
36    *
37    * @version $Id: 1679b897e27f224e91cec737297ae1c0f2ad552b $
38    * @since 1.4M2
39    */
 
40    public class DocumentStatsStoreItem extends AbstractStatsStoreItem
41    {
42    /**
43    * Logging tools.
44    */
45    private static final Logger LOGGER = LoggerFactory.getLogger(DocumentStatsStoreItem.class);
46   
47    /**
48    * The action made on provided wiki/space/document.
49    */
50    private String action;
51   
52    /**
53    * Is this part of a user visit.
54    */
55    private boolean isVisit;
56   
57    /**
58    * Create new instance of {@link DocumentStatsStoreItem}.
59    *
60    * @param name can be:
61    * <ul>
62    * <li>"" for the entire wiki.</li>
63    * <li>the space name.</li>
64    * <li>the full document name.</li>
65    * </ul>
66    * @param periodDate the period date.
67    * @param periodType the period type.
68    * @param action the action made on provided wiki/space/document.
69    * @param isVisit is this part of a user visit.
70    * @param context the XWiki context.
71    */
 
72  0 toggle public DocumentStatsStoreItem(String name, Date periodDate, PeriodType periodType, String action, boolean isVisit,
73    XWikiContext context)
74    {
75  0 super(name, periodDate, periodType, context);
76   
77  0 this.action = action;
78  0 this.isVisit = isVisit;
79    }
80   
 
81  0 toggle @Override
82    public String getId()
83    {
84  0 return String.format("%s %s %s %s", getClass(), this.name, this.action, this.period);
85    }
86   
 
87  0 toggle @Override
88    public void storeInternal(List<XWikiStatsStoreItem> stats)
89    {
90  0 DocumentStatsStoreItem lastItem = (DocumentStatsStoreItem) stats.get(stats.size() - 1);
91   
92  0 XWikiHibernateStore store = this.context.getWiki().getHibernateStore();
93  0 if (store == null) {
94  0 return;
95    }
96   
97  0 DocumentStats documentStat =
98    new DocumentStats(lastItem.name, lastItem.action, lastItem.periodDate, lastItem.periodType);
99   
100    // Load old statistics object from database
101  0 try {
102    // TODO Fix use of deprecated call.
103  0 store.loadXWikiCollection(documentStat, this.context, true);
104    } catch (XWikiException e) {
105  0 if (LOGGER.isDebugEnabled()) {
106  0 LOGGER.debug("Failed to load document statistics object [{}]", getId(), e);
107    }
108    }
109   
110    // Increment counters
111  0 documentStat.setIntValue("pageViews", documentStat.getPageViews() + stats.size());
112  0 for (XWikiStatsStoreItem statItem : stats) {
113  0 DocumentStatsStoreItem docStat = (DocumentStatsStoreItem) statItem;
114   
115  0 if (docStat.isVisit) {
116  0 documentStat.incVisits();
117    }
118    }
119   
120    // Re-save statistics object
121  0 try {
122    // TODO Fix use of deprecated call.
123  0 store.saveXWikiCollection(documentStat, this.context, true);
124    } catch (XWikiException e) {
125  0 LOGGER.error("Failed to save document statistics object [{}]", getId(), e);
126    }
127    }
128    }