Skip to content

Commit 0920b47

Browse files
committed
make several usage statistics parameters configurable
1 parent 58e6327 commit 0920b47

File tree

2 files changed

+45
-12
lines changed

2 files changed

+45
-12
lines changed

dspace-server-webapp/src/main/java/org/dspace/app/rest/utils/UsageReportUtils.java

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.dspace.core.Constants;
2828
import org.dspace.core.Context;
2929
import org.dspace.handle.service.HandleService;
30+
import org.dspace.services.ConfigurationService;
3031
import org.dspace.statistics.Dataset;
3132
import org.dspace.statistics.content.DatasetDSpaceObjectGenerator;
3233
import org.dspace.statistics.content.DatasetTimeGenerator;
@@ -46,6 +47,9 @@
4647
@Component
4748
public class UsageReportUtils {
4849

50+
@Autowired
51+
private ConfigurationService configurationService;
52+
4953
@Autowired
5054
private HandleService handleService;
5155

@@ -135,13 +139,14 @@ public UsageReportRest createUsageReport(Context context, DSpaceObject dso, Stri
135139
*/
136140
private UsageReportRest resolveGlobalUsageReport(Context context)
137141
throws SQLException, IOException, ParseException, SolrServerException {
142+
int topItemsLimit = configurationService.getIntProperty("usage-statistics.topItemsLimit", 10);
143+
138144
StatisticsListing statListing = new StatisticsListing(
139145
new StatisticsDataVisits());
140146

141-
// Adding a new generator for our top 10 items without a name length delimiter
147+
// Adding a new generator for our top n items without a name length delimiter
142148
DatasetDSpaceObjectGenerator dsoAxis = new DatasetDSpaceObjectGenerator();
143-
// TODO make max nr of top items (views wise)? Must be set
144-
dsoAxis.addDsoChild(Constants.ITEM, 10, false, -1);
149+
dsoAxis.addDsoChild(Constants.ITEM, topItemsLimit, false, -1);
145150
statListing.addDatasetGenerator(dsoAxis);
146151

147152
Dataset dataset = statListing.getDataset(context, 1);
@@ -182,7 +187,7 @@ private UsageReportRest resolveTotalVisits(Context context, DSpaceObject dso)
182187
UsageReportPointDsoTotalVisitsRest totalVisitPoint = new UsageReportPointDsoTotalVisitsRest();
183188
totalVisitPoint.setType(StringUtils.substringAfterLast(dso.getClass().getName().toLowerCase(), "."));
184189
totalVisitPoint.setId(dso.getID().toString());
185-
if (dataset.getColLabels().size() > 0) {
190+
if (!dataset.getColLabels().isEmpty()) {
186191
totalVisitPoint.setLabel(dso.getName());
187192
totalVisitPoint.addValue("views", Integer.valueOf(dataset.getMatrix()[0][0]));
188193
} else {
@@ -205,10 +210,14 @@ private UsageReportRest resolveTotalVisits(Context context, DSpaceObject dso)
205210
*/
206211
private UsageReportRest resolveTotalVisitsPerMonth(Context context, DSpaceObject dso)
207212
throws SQLException, IOException, ParseException, SolrServerException {
213+
String startDateInterval =
214+
configurationService.getProperty("usage-statistics.startDateInterval", "-6");
215+
String endDateInterval =
216+
configurationService.getProperty("usage-statistics.endDateInterval", "+1");
217+
208218
StatisticsTable statisticsTable = new StatisticsTable(new StatisticsDataVisits(dso));
209219
DatasetTimeGenerator timeAxis = new DatasetTimeGenerator();
210-
// TODO month start and end as request para?
211-
timeAxis.setDateInterval("month", "-6", "+1");
220+
timeAxis.setDateInterval("month", startDateInterval, endDateInterval);
212221
statisticsTable.addDatasetGenerator(timeAxis);
213222
DatasetDSpaceObjectGenerator dsoAxis = new DatasetDSpaceObjectGenerator();
214223
dsoAxis.addDsoChild(dso.getType(), 10, false, -1);
@@ -275,7 +284,10 @@ private UsageReportRest resolveTotalDownloads(Context context, DSpaceObject dso)
275284
*/
276285
private UsageReportRest resolveTopCountries(Context context, DSpaceObject dso)
277286
throws SQLException, IOException, ParseException, SolrServerException {
278-
Dataset dataset = this.getTypeStatsDataset(context, dso, "countryCode", 1);
287+
int topCountriesLimit =
288+
configurationService.getIntProperty("usage-statistics.topCountriesLimit", 100);
289+
290+
Dataset dataset = this.getTypeStatsDataset(context, dso, "countryCode", topCountriesLimit, 1);
279291

280292
UsageReportRest usageReportRest = new UsageReportRest();
281293
for (int i = 0; i < dataset.getColLabels().size(); i++) {
@@ -299,7 +311,10 @@ private UsageReportRest resolveTopCountries(Context context, DSpaceObject dso)
299311
*/
300312
private UsageReportRest resolveTopCities(Context context, DSpaceObject dso)
301313
throws SQLException, IOException, ParseException, SolrServerException {
302-
Dataset dataset = this.getTypeStatsDataset(context, dso, "city", 1);
314+
int topCitiesLimit =
315+
configurationService.getIntProperty("usage-statistics.topCitiesLimit", 100);
316+
317+
Dataset dataset = this.getTypeStatsDataset(context, dso, "city", topCitiesLimit, 1);
303318

304319
UsageReportRest usageReportRest = new UsageReportRest();
305320
for (int i = 0; i < dataset.getColLabels().size(); i++) {
@@ -339,16 +354,17 @@ private Dataset getDSOStatsDataset(Context context, DSpaceObject dso, int facetM
339354
* @param dso DSO we want the stats dataset of
340355
* @param typeAxisString String of the type we want on the axis of the dataset (corresponds to solr field),
341356
* examples: countryCode, city
357+
* @param typeAxisMax Maximum amount of results to return in the dataset
342358
* @param facetMinCount Minimum amount of results on a facet data point for it to be added to dataset
343359
* @return Stats dataset with the given type on the axis, of the given DSO and with given facetMinCount
344360
*/
345-
private Dataset getTypeStatsDataset(Context context, DSpaceObject dso, String typeAxisString, int facetMinCount)
361+
private Dataset getTypeStatsDataset(Context context, DSpaceObject dso, String typeAxisString, int typeAxisMax,
362+
int facetMinCount)
346363
throws SQLException, IOException, ParseException, SolrServerException {
347364
StatisticsListing statListing = new StatisticsListing(new StatisticsDataVisits(dso));
348365
DatasetTypeGenerator typeAxis = new DatasetTypeGenerator();
349366
typeAxis.setType(typeAxisString);
350-
// TODO make max nr of top countries/cities a request para? Must be set
351-
typeAxis.setMax(100);
367+
typeAxis.setMax(typeAxisMax);
352368
statListing.addDatasetGenerator(typeAxis);
353369
return statListing.getDataset(context, facetMinCount);
354370
}

dspace/config/modules/usage-statistics.cfg

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,21 @@ usage-statistics.shardedByYear = false
6060
#anonymize_statistics.dns_mask = anonymized
6161

6262
# Only anonymize statistics records older than this threshold (expressed in days)
63-
#anonymize_statistics.time_threshold = 90
63+
#anonymize_statistics.time_threshold = 90
64+
65+
# Maximum number of items to display in the usage statistics report for an entire repository
66+
usage-statistics.topItemsLimit = 10
67+
68+
# Number of months to begin retrieving usage statistics for total visits per month of a DSpace object
69+
# For example, -6 means include the previous six months
70+
usage-statistics.startDateInterval = -6
71+
72+
# Number of months to end retrieving usage statistics for total visits per month of a DSpace object
73+
# For example, +1 means include the current month
74+
usage-statistics.endDateInterval = +1
75+
76+
# Maximum number of countries to display in the usage statistics reports
77+
usage-statistics.topCountriesLimit = 100
78+
79+
# Maximum number of cities to display in the usage statistics reports
80+
usage-statistics.topCitiesLimit = 100

0 commit comments

Comments
 (0)