2727import org .dspace .core .Constants ;
2828import org .dspace .core .Context ;
2929import org .dspace .handle .service .HandleService ;
30+ import org .dspace .services .ConfigurationService ;
3031import org .dspace .statistics .Dataset ;
3132import org .dspace .statistics .content .DatasetDSpaceObjectGenerator ;
3233import org .dspace .statistics .content .DatasetTimeGenerator ;
4647@ Component
4748public 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 }
0 commit comments