mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 15:03:18 +00:00
71214: - Usage Reports TotalVisitPerMonth fixed (facet works with range not date any more)
- settable facetMinCount to get month points with no views - TotalDownloads added
This commit is contained in:
@@ -842,18 +842,18 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
|
||||
}
|
||||
|
||||
@Override
|
||||
public void query(String query, int max)
|
||||
public void query(String query, int max, int facetMinCount)
|
||||
throws SolrServerException, IOException {
|
||||
query(query, null, null, 0, max, null, null, null, null, null, false);
|
||||
query(query, null, null, 0, max, null, null, null, null, null, false, facetMinCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectCount[] queryFacetField(String query,
|
||||
String filterQuery, String facetField, int max, boolean showTotal,
|
||||
List<String> facetQueries)
|
||||
List<String> facetQueries, int facetMinCount)
|
||||
throws SolrServerException, IOException {
|
||||
QueryResponse queryResponse = query(query, filterQuery, facetField,
|
||||
0, max, null, null, null, facetQueries, null, false);
|
||||
0, max, null, null, null, facetQueries, null, false, facetMinCount);
|
||||
if (queryResponse == null) {
|
||||
return new ObjectCount[0];
|
||||
}
|
||||
@@ -887,50 +887,55 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
|
||||
@Override
|
||||
public ObjectCount[] queryFacetDate(String query,
|
||||
String filterQuery, int max, String dateType, String dateStart,
|
||||
String dateEnd, boolean showTotal, Context context)
|
||||
String dateEnd, boolean showTotal, Context context, int facetMinCount)
|
||||
throws SolrServerException, IOException {
|
||||
QueryResponse queryResponse = query(query, filterQuery, null, 0, max,
|
||||
dateType, dateStart, dateEnd, null, null, false);
|
||||
dateType, dateStart, dateEnd, null, null, false, facetMinCount);
|
||||
if (queryResponse == null) {
|
||||
return new ObjectCount[0];
|
||||
}
|
||||
|
||||
FacetField dateFacet = queryResponse.getFacetDate("time");
|
||||
// TODO: check if this cannot crash I checked it, it crashed!!!
|
||||
// Create an array for our result
|
||||
ObjectCount[] result = new ObjectCount[dateFacet.getValueCount()
|
||||
+ (showTotal ? 1 : 0)];
|
||||
// Run over our datefacet & store all the values
|
||||
for (int i = 0; i < dateFacet.getValues().size(); i++) {
|
||||
FacetField.Count dateCount = dateFacet.getValues().get(i);
|
||||
result[i] = new ObjectCount();
|
||||
result[i].setCount(dateCount.getCount());
|
||||
result[i].setValue(getDateView(dateCount.getName(), dateType, context));
|
||||
List<RangeFacet> rangeFacets = queryResponse.getFacetRanges();
|
||||
for (RangeFacet rangeFacet: rangeFacets) {
|
||||
if (rangeFacet.getName().equalsIgnoreCase("time")) {
|
||||
RangeFacet timeFacet = rangeFacet;
|
||||
// Create an array for our result
|
||||
ObjectCount[] result = new ObjectCount[timeFacet.getCounts().size()
|
||||
+ (showTotal ? 1 : 0)];
|
||||
// Run over our datefacet & store all the values
|
||||
for (int i = 0; i < timeFacet.getCounts().size(); i++) {
|
||||
RangeFacet.Count dateCount = (RangeFacet.Count) timeFacet.getCounts().get(i);
|
||||
result[i] = new ObjectCount();
|
||||
result[i].setCount(dateCount.getCount());
|
||||
result[i].setValue(getDateView(dateCount.getValue(), dateType, context));
|
||||
}
|
||||
if (showTotal) {
|
||||
result[result.length - 1] = new ObjectCount();
|
||||
result[result.length - 1].setCount(queryResponse.getResults()
|
||||
.getNumFound());
|
||||
// TODO: Make sure that this total is gotten out of the msgs.xml
|
||||
result[result.length - 1].setValue("total");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
if (showTotal) {
|
||||
result[result.length - 1] = new ObjectCount();
|
||||
result[result.length - 1].setCount(queryResponse.getResults()
|
||||
.getNumFound());
|
||||
// TODO: Make sure that this total is gotten out of the msgs.xml
|
||||
result[result.length - 1].setValue("total");
|
||||
}
|
||||
return result;
|
||||
return new ObjectCount[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Integer> queryFacetQuery(String query,
|
||||
String filterQuery, List<String> facetQueries)
|
||||
public Map<String, Integer> queryFacetQuery(String query, String filterQuery, List<String> facetQueries,
|
||||
int facetMinCount)
|
||||
throws SolrServerException, IOException {
|
||||
QueryResponse response = query(query, filterQuery, null, 0, 1, null, null,
|
||||
null, facetQueries, null, false);
|
||||
null, facetQueries, null, false, facetMinCount);
|
||||
return response.getFacetQuery();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectCount queryTotal(String query, String filterQuery)
|
||||
public ObjectCount queryTotal(String query, String filterQuery, int facetMinCount)
|
||||
throws SolrServerException, IOException {
|
||||
QueryResponse queryResponse = query(query, filterQuery, null, 0, -1, null,
|
||||
null, null, null, null, false);
|
||||
null, null, null, null, false, facetMinCount);
|
||||
ObjectCount objCount = new ObjectCount();
|
||||
objCount.setCount(queryResponse.getResults().getNumFound());
|
||||
|
||||
@@ -985,7 +990,8 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
|
||||
@Override
|
||||
public QueryResponse query(String query, String filterQuery,
|
||||
String facetField, int rows, int max, String dateType, String dateStart,
|
||||
String dateEnd, List<String> facetQueries, String sort, boolean ascending)
|
||||
String dateEnd, List<String> facetQueries, String sort, boolean ascending,
|
||||
int facetMinCount)
|
||||
throws SolrServerException, IOException {
|
||||
if (solr == null) {
|
||||
return null;
|
||||
@@ -993,20 +999,20 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
|
||||
|
||||
// System.out.println("QUERY");
|
||||
SolrQuery solrQuery = new SolrQuery().setRows(rows).setQuery(query)
|
||||
.setFacetMinCount(1);
|
||||
.setFacetMinCount(facetMinCount);
|
||||
addAdditionalSolrYearCores(solrQuery);
|
||||
|
||||
// Set the date facet if present
|
||||
if (dateType != null) {
|
||||
solrQuery.setParam("facet.date", "time")
|
||||
solrQuery.setParam("facet.range", "time")
|
||||
.
|
||||
// EXAMPLE: NOW/MONTH+1MONTH
|
||||
setParam("facet.date.end",
|
||||
setParam("f.time.facet.range.end",
|
||||
"NOW/" + dateType + dateEnd + dateType).setParam(
|
||||
"facet.date.gap", "+1" + dateType)
|
||||
"f.time.facet.range.gap", "+1" + dateType)
|
||||
.
|
||||
// EXAMPLE: NOW/MONTH-" + nbMonths + "MONTHS
|
||||
setParam("facet.date.start",
|
||||
setParam("f.time.facet.range.start",
|
||||
"NOW/" + dateType + dateStart + dateType + "S")
|
||||
.setFacet(true);
|
||||
}
|
||||
|
@@ -68,11 +68,11 @@ public class StatisticsBSAdapter {
|
||||
switch (visitType) {
|
||||
case ITEM_VISITS:
|
||||
return solrLoggerService
|
||||
.queryTotal("type: " + Constants.ITEM + " AND id: " + item.getID(), resolveFilterQueries())
|
||||
.queryTotal("type: " + Constants.ITEM + " AND id: " + item.getID(), resolveFilterQueries(), 0)
|
||||
.getCount();
|
||||
case BITSTREAM_VISITS:
|
||||
return solrLoggerService.queryTotal("type: " + Constants.BITSTREAM + " AND owningItem: " + item.getID(),
|
||||
resolveFilterQueries()).getCount();
|
||||
resolveFilterQueries(), 0).getCount();
|
||||
case TOTAL_VISITS:
|
||||
return getNumberOfVisits(ITEM_VISITS, item) + getNumberOfVisits(BITSTREAM_VISITS, item);
|
||||
default:
|
||||
|
@@ -115,13 +115,14 @@ public abstract class StatisticsData {
|
||||
* Run the accumulated query and return its results.
|
||||
*
|
||||
* @param context The relevant DSpace Context.
|
||||
* @param facetMinCount Minimum count of results facet must have to return a result
|
||||
* @return accumulated query results
|
||||
* @throws SQLException An exception that provides information on a database access error or other errors.
|
||||
* @throws SolrServerException Exception from the Solr server to the solrj Java client.
|
||||
* @throws IOException A general class of exceptions produced by failed or interrupted I/O operations.
|
||||
* @throws ParseException if the dataset cannot be parsed
|
||||
*/
|
||||
public abstract Dataset createDataset(Context context) throws SQLException,
|
||||
public abstract Dataset createDataset(Context context, int facetMinCount) throws SQLException,
|
||||
SolrServerException, IOException, ParseException;
|
||||
|
||||
}
|
||||
|
@@ -50,7 +50,7 @@ public class StatisticsDataSearches extends StatisticsData {
|
||||
|
||||
|
||||
@Override
|
||||
public Dataset createDataset(Context context)
|
||||
public Dataset createDataset(Context context, int facetMinCount)
|
||||
throws SQLException, SolrServerException, IOException, ParseException {
|
||||
// Check if we already have one.
|
||||
// If we do then give it back.
|
||||
@@ -85,7 +85,7 @@ public class StatisticsDataSearches extends StatisticsData {
|
||||
|
||||
ObjectCount[] topCounts = solrLoggerService
|
||||
.queryFacetField(query, fqBuffer.toString(), typeGenerator.getType(), typeGenerator.getMax(),
|
||||
(typeGenerator.isPercentage() || typeGenerator.isIncludeTotal()), null);
|
||||
(typeGenerator.isPercentage() || typeGenerator.isIncludeTotal()), null, 0);
|
||||
long totalCount = -1;
|
||||
if (typeGenerator.isPercentage() && 0 < topCounts.length) {
|
||||
//Retrieve the total required to calculate the percentage
|
||||
@@ -133,14 +133,15 @@ public class StatisticsDataSearches extends StatisticsData {
|
||||
queryString = "\"\"";
|
||||
}
|
||||
|
||||
ObjectCount totalPageViews = getTotalPageViews("query:" + queryString, defaultFilterQuery);
|
||||
ObjectCount totalPageViews = getTotalPageViews("query:" + queryString, defaultFilterQuery
|
||||
, facetMinCount);
|
||||
dataset.addValueToMatrix(i, 3, pageViewFormat
|
||||
.format((float) totalPageViews.getCount() / queryCount.getCount()));
|
||||
}
|
||||
}
|
||||
} else if (typeGenerator.getMode() == DatasetSearchGenerator.Mode.SEARCH_OVERVIEW_TOTAL) {
|
||||
//Retrieve the total counts !
|
||||
ObjectCount totalCount = solrLoggerService.queryTotal(query, getSearchFilterQuery());
|
||||
ObjectCount totalCount = solrLoggerService.queryTotal(query, getSearchFilterQuery(), facetMinCount);
|
||||
|
||||
//Retrieve the filtered count by using the default filter query
|
||||
StringBuilder fqBuffer = new StringBuilder(defaultFilterQuery);
|
||||
@@ -149,7 +150,7 @@ public class StatisticsDataSearches extends StatisticsData {
|
||||
}
|
||||
fqBuffer.append(getSearchFilterQuery());
|
||||
|
||||
ObjectCount totalFiltered = solrLoggerService.queryTotal(query, fqBuffer.toString());
|
||||
ObjectCount totalFiltered = solrLoggerService.queryTotal(query, fqBuffer.toString(), facetMinCount);
|
||||
|
||||
|
||||
fqBuffer = new StringBuilder(defaultFilterQuery);
|
||||
@@ -159,7 +160,7 @@ public class StatisticsDataSearches extends StatisticsData {
|
||||
fqBuffer.append("statistics_type:")
|
||||
.append(SolrLoggerServiceImpl.StatisticsType.SEARCH_RESULT.text());
|
||||
|
||||
ObjectCount totalPageViews = getTotalPageViews(query, defaultFilterQuery);
|
||||
ObjectCount totalPageViews = getTotalPageViews(query, defaultFilterQuery, facetMinCount);
|
||||
|
||||
dataset = new Dataset(1, 3);
|
||||
dataset.setRowLabel(0, "");
|
||||
@@ -221,7 +222,7 @@ public class StatisticsDataSearches extends StatisticsData {
|
||||
return query;
|
||||
}
|
||||
|
||||
protected ObjectCount getTotalPageViews(String query, String defaultFilterQuery)
|
||||
protected ObjectCount getTotalPageViews(String query, String defaultFilterQuery, int facetMinCount)
|
||||
throws SolrServerException, IOException {
|
||||
StringBuilder fqBuffer;
|
||||
fqBuffer = new StringBuilder(defaultFilterQuery);
|
||||
@@ -232,7 +233,7 @@ public class StatisticsDataSearches extends StatisticsData {
|
||||
|
||||
|
||||
//Retrieve the number of page views by this query !
|
||||
return solrLoggerService.queryTotal(query, fqBuffer.toString());
|
||||
return solrLoggerService.queryTotal(query, fqBuffer.toString(), facetMinCount);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -58,7 +58,7 @@ import org.dspace.statistics.util.LocationUtils;
|
||||
* <li>Add a {@link DatasetDSpaceObjectGenerator} for the appropriate object type.</li>
|
||||
* <li>Add other generators as required to get the statistic you want.</li>
|
||||
* <li>Add {@link org.dspace.statistics.content.filter filters} as required.</li>
|
||||
* <li>{@link #createDataset(Context)} will run the query and return a result matrix.
|
||||
* <li>{@link #createDataset(Context, int)} will run the query and return a result matrix.
|
||||
* Subsequent calls skip the query and return the same matrix.</li>
|
||||
* </ol>
|
||||
*
|
||||
@@ -117,7 +117,7 @@ public class StatisticsDataVisits extends StatisticsData {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dataset createDataset(Context context) throws SQLException,
|
||||
public Dataset createDataset(Context context, int facetMinCount) throws SQLException,
|
||||
SolrServerException, ParseException, IOException {
|
||||
// Check if we already have one.
|
||||
// If we do then give it back.
|
||||
@@ -214,7 +214,8 @@ public class StatisticsDataVisits extends StatisticsData {
|
||||
// We are asking from our current query all the visits faceted by date
|
||||
ObjectCount[] results = solrLoggerService
|
||||
.queryFacetDate(query, filterQuery, dataSetQuery.getMax(), dateFacet.getDateType(),
|
||||
dateFacet.getStartDate(), dateFacet.getEndDate(), showTotal, context);
|
||||
dateFacet.getStartDate(), dateFacet.getEndDate(), showTotal, context,
|
||||
facetMinCount);
|
||||
dataset = new Dataset(1, results.length);
|
||||
// Now that we have our results put em in a matrix
|
||||
for (int j = 0; j < results.length; j++) {
|
||||
@@ -230,15 +231,15 @@ public class StatisticsDataVisits extends StatisticsData {
|
||||
// the datasettimequery
|
||||
ObjectCount[] maxObjectCounts = solrLoggerService
|
||||
.queryFacetField(query, filterQuery, dataSetQuery.getFacetField(), dataSetQuery.getMax(),
|
||||
false, null);
|
||||
false, null, facetMinCount);
|
||||
for (int j = 0; j < maxObjectCounts.length; j++) {
|
||||
ObjectCount firstCount = maxObjectCounts[j];
|
||||
String newQuery = dataSetQuery.getFacetField() + ": " + ClientUtils
|
||||
.escapeQueryChars(firstCount.getValue()) + " AND " + query;
|
||||
ObjectCount[] maxDateFacetCounts = solrLoggerService
|
||||
.queryFacetDate(newQuery, filterQuery, dataSetQuery.getMax(), dateFacet.getDateType(),
|
||||
dateFacet.getStartDate(), dateFacet.getEndDate(), showTotal, context);
|
||||
|
||||
dateFacet.getStartDate(), dateFacet.getEndDate(), showTotal, context,
|
||||
facetMinCount);
|
||||
|
||||
// Make sure we have a dataSet
|
||||
if (dataset == null) {
|
||||
@@ -283,7 +284,7 @@ public class StatisticsDataVisits extends StatisticsData {
|
||||
|
||||
ObjectCount[] topCounts1 = null;
|
||||
// if (firsDataset.getQueries().size() == 1) {
|
||||
topCounts1 = queryFacetField(firsDataset, firsDataset.getQueries().get(0).getQuery(), filterQuery);
|
||||
topCounts1 = queryFacetField(firsDataset, firsDataset.getQueries().get(0).getQuery(), filterQuery, facetMinCount);
|
||||
// } else {
|
||||
// TODO: do this
|
||||
// }
|
||||
@@ -292,7 +293,7 @@ public class StatisticsDataVisits extends StatisticsData {
|
||||
DatasetQuery secondDataSet = datasetQueries.get(1);
|
||||
// Now do the second one
|
||||
ObjectCount[] topCounts2 = queryFacetField(secondDataSet, secondDataSet.getQueries().get(0).getQuery(),
|
||||
filterQuery);
|
||||
filterQuery, facetMinCount);
|
||||
// Now that have results for both of them lets do x.y queries
|
||||
List<String> facetQueries = new ArrayList<String>();
|
||||
for (ObjectCount count2 : topCounts2) {
|
||||
@@ -325,7 +326,7 @@ public class StatisticsDataVisits extends StatisticsData {
|
||||
}
|
||||
|
||||
Map<String, Integer> facetResult = solrLoggerService
|
||||
.queryFacetQuery(query, filterQuery, facetQueries);
|
||||
.queryFacetQuery(query, filterQuery, facetQueries, facetMinCount);
|
||||
|
||||
|
||||
// TODO: the show total
|
||||
@@ -704,12 +705,12 @@ public class StatisticsDataVisits extends StatisticsData {
|
||||
|
||||
|
||||
protected ObjectCount[] queryFacetField(DatasetQuery dataset, String query,
|
||||
String filterQuery)
|
||||
String filterQuery, int facetMinCount)
|
||||
throws SolrServerException, IOException {
|
||||
String facetType = dataset.getFacetField() == null ? "id" : dataset
|
||||
.getFacetField();
|
||||
return solrLoggerService.queryFacetField(query, filterQuery, facetType,
|
||||
dataset.getMax(), false, null);
|
||||
dataset.getMax(), false, null, facetMinCount);
|
||||
}
|
||||
|
||||
public static class DatasetQuery {
|
||||
|
@@ -65,7 +65,7 @@ public class StatisticsDataWorkflow extends StatisticsData {
|
||||
|
||||
|
||||
@Override
|
||||
public Dataset createDataset(Context context)
|
||||
public Dataset createDataset(Context context, int facetMinCount)
|
||||
throws SQLException, SolrServerException, IOException, ParseException {
|
||||
// Check if we already have one.
|
||||
// If we do then give it back.
|
||||
@@ -92,16 +92,16 @@ public class StatisticsDataWorkflow extends StatisticsData {
|
||||
DatasetTypeGenerator typeGenerator = (DatasetTypeGenerator) datasetGenerator;
|
||||
ObjectCount[] topCounts = solrLoggerService
|
||||
.queryFacetField(query, defaultFilterQuery, typeGenerator.getType(), typeGenerator.getMax(),
|
||||
typeGenerator.isIncludeTotal(), null);
|
||||
typeGenerator.isIncludeTotal(), null, facetMinCount);
|
||||
|
||||
//Retrieve our total field counts
|
||||
Map<String, Long> totalFieldCounts = new HashMap<String, Long>();
|
||||
if (averageMonths != -1) {
|
||||
totalFieldCounts = getTotalFacetCounts(typeGenerator);
|
||||
totalFieldCounts = getTotalFacetCounts(typeGenerator, facetMinCount);
|
||||
}
|
||||
long monthDifference = 1;
|
||||
if (getOldestWorkflowItemDate() != null) {
|
||||
monthDifference = getMonthsDifference(new Date(), getOldestWorkflowItemDate());
|
||||
if (getOldestWorkflowItemDate(facetMinCount) != null) {
|
||||
monthDifference = getMonthsDifference(new Date(), getOldestWorkflowItemDate(facetMinCount));
|
||||
}
|
||||
|
||||
dataset = new Dataset(topCounts.length, (averageMonths != -1 ? 3 : 2));
|
||||
@@ -168,10 +168,10 @@ public class StatisticsDataWorkflow extends StatisticsData {
|
||||
* @throws org.apache.solr.client.solrj.SolrServerException passed through.
|
||||
* @throws java.io.IOException passed through.
|
||||
*/
|
||||
protected Map<String, Long> getTotalFacetCounts(DatasetTypeGenerator typeGenerator)
|
||||
protected Map<String, Long> getTotalFacetCounts(DatasetTypeGenerator typeGenerator, int facetMinCount)
|
||||
throws SolrServerException, IOException {
|
||||
ObjectCount[] objectCounts = solrLoggerService
|
||||
.queryFacetField(getQuery(), null, typeGenerator.getType(), -1, false, null);
|
||||
.queryFacetField(getQuery(), null, typeGenerator.getType(), -1, false, null, facetMinCount);
|
||||
Map<String, Long> result = new HashMap<>();
|
||||
for (ObjectCount objectCount : objectCounts) {
|
||||
result.put(objectCount.getValue(), objectCount.getCount());
|
||||
@@ -179,14 +179,14 @@ public class StatisticsDataWorkflow extends StatisticsData {
|
||||
return result;
|
||||
}
|
||||
|
||||
protected Date getOldestWorkflowItemDate()
|
||||
protected Date getOldestWorkflowItemDate(int facetMinCount)
|
||||
throws SolrServerException, IOException {
|
||||
ConfigurationService configurationService = DSpaceServicesFactory.getInstance().getConfigurationService();
|
||||
String workflowStartDate = configurationService.getProperty("usage-statistics.workflow-start-date");
|
||||
if (workflowStartDate == null) {
|
||||
//Query our solr for it !
|
||||
QueryResponse oldestRecord = solrLoggerService
|
||||
.query(getQuery(), null, null, 1, 0, null, null, null, null, "time", true);
|
||||
.query(getQuery(), null, null, 1, 0, null, null, null, null, "time", true, facetMinCount);
|
||||
if (0 < oldestRecord.getResults().getNumFound()) {
|
||||
SolrDocument solrDocument = oldestRecord.getResults().get(0);
|
||||
Date oldestDate = (Date) solrDocument.getFieldValue("time");
|
||||
|
@@ -83,8 +83,9 @@ public abstract class StatisticsDisplay {
|
||||
return statisticsData.getDataset();
|
||||
}
|
||||
|
||||
public Dataset getDataset(Context context) throws SQLException, SolrServerException, IOException, ParseException {
|
||||
return statisticsData.createDataset(context);
|
||||
public Dataset getDataset(Context context, int facetMinCount) throws SQLException, SolrServerException, IOException,
|
||||
ParseException {
|
||||
return statisticsData.createDataset(context, facetMinCount);
|
||||
}
|
||||
|
||||
public void addCss(String style) {
|
||||
|
@@ -116,7 +116,7 @@ public interface SolrLoggerService {
|
||||
List<String> fieldNames, List<List<Object>> fieldValuesList)
|
||||
throws SolrServerException, IOException;
|
||||
|
||||
public void query(String query, int max)
|
||||
public void query(String query, int max, int facetMinCount)
|
||||
throws SolrServerException, IOException;
|
||||
|
||||
/**
|
||||
@@ -130,13 +130,14 @@ public interface SolrLoggerService {
|
||||
* @param showTotal a boolean determining whether the total amount should be given
|
||||
* back as the last element of the array
|
||||
* @param facetQueries list of facet queries
|
||||
* @param facetMinCount Minimum count of results facet must have to return a result
|
||||
* @return an array containing our results
|
||||
* @throws SolrServerException Exception from the Solr server to the solrj Java client.
|
||||
* @throws java.io.IOException passed through.
|
||||
*/
|
||||
public ObjectCount[] queryFacetField(String query,
|
||||
String filterQuery, String facetField, int max, boolean showTotal,
|
||||
List<String> facetQueries)
|
||||
List<String> facetQueries, int facetMinCount)
|
||||
throws SolrServerException, IOException;
|
||||
|
||||
/**
|
||||
@@ -154,25 +155,27 @@ public interface SolrLoggerService {
|
||||
* @param showTotal a boolean determining whether the total amount should be given
|
||||
* back as the last element of the array
|
||||
* @param context The relevant DSpace Context.
|
||||
* @param facetMinCount Minimum count of results facet must have to return a result
|
||||
* @return and array containing our results
|
||||
* @throws SolrServerException Exception from the Solr server to the solrj Java client.
|
||||
* @throws java.io.IOException passed through.
|
||||
*/
|
||||
public ObjectCount[] queryFacetDate(String query,
|
||||
String filterQuery, int max, String dateType, String dateStart,
|
||||
String dateEnd, boolean showTotal, Context context)
|
||||
String dateEnd, boolean showTotal, Context context, int facetMinCount)
|
||||
throws SolrServerException, IOException;
|
||||
|
||||
public Map<String, Integer> queryFacetQuery(String query,
|
||||
String filterQuery, List<String> facetQueries)
|
||||
public Map<String, Integer> queryFacetQuery(String query, String filterQuery, List<String> facetQueries,
|
||||
int facetMinCount)
|
||||
throws SolrServerException, IOException;
|
||||
|
||||
public ObjectCount queryTotal(String query, String filterQuery)
|
||||
public ObjectCount queryTotal(String query, String filterQuery, int facetMinCount)
|
||||
throws SolrServerException, IOException;
|
||||
|
||||
public QueryResponse query(String query, String filterQuery,
|
||||
String facetField, int rows, int max, String dateType, String dateStart,
|
||||
String dateEnd, List<String> facetQueries, String sort, boolean ascending)
|
||||
String dateEnd, List<String> facetQueries, String sort, boolean ascending,
|
||||
int facetMinCount)
|
||||
throws SolrServerException, IOException;
|
||||
|
||||
/**
|
||||
|
@@ -132,9 +132,7 @@ public class StatisticsRestController implements InitializingBean {
|
||||
"1911e8a4-6939-490c-b58b-a5d70f8d91fb_TopCountries");
|
||||
}
|
||||
UUID uuidObject = UUID.fromString(StringUtils.substringBefore(uuidObjectReportId, "_"));
|
||||
// TODO check if valid object uuid
|
||||
String reportId = StringUtils.substringAfter(uuidObjectReportId, "_");
|
||||
// TODO check if valid report id
|
||||
Context context = ContextUtil.obtainContext(request);
|
||||
|
||||
UsageReportRest usageReportRest = usageReportRestRepository.createUsageReport(context, uuidObject, reportId);
|
||||
|
@@ -7,9 +7,6 @@
|
||||
*/
|
||||
package org.dspace.app.rest.model;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This class serves as a REST representation of a City data Point of a {@link UsageReportRest} from the DSpace
|
||||
* statistics
|
||||
@@ -19,32 +16,6 @@ import java.util.Map;
|
||||
public class UsageReportPointCityRest extends UsageReportPointRest {
|
||||
public static final String NAME = "city";
|
||||
|
||||
private String id;
|
||||
private Map<String, Integer> values;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Map<String, Integer> getValues() {
|
||||
return values;
|
||||
}
|
||||
|
||||
public void addValue(String key, Integer value) {
|
||||
if (values == null) {
|
||||
values = new HashMap<>();
|
||||
}
|
||||
values.put(key, value);
|
||||
}
|
||||
|
||||
public void setValues(Map<String, Integer> values) {
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return NAME;
|
||||
|
@@ -7,9 +7,6 @@
|
||||
*/
|
||||
package org.dspace.app.rest.model;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.dspace.statistics.util.LocationUtils;
|
||||
|
||||
/**
|
||||
@@ -22,40 +19,19 @@ public class UsageReportPointCountryRest extends UsageReportPointRest {
|
||||
public static final String NAME = "country";
|
||||
|
||||
private String label;
|
||||
private String id;
|
||||
private Map<String, Integer> values;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
this.label = LocationUtils.getCountryName(id);
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
this.id = LocationUtils.getCountryCode(label);
|
||||
super.id = LocationUtils.getCountryCode(label);
|
||||
}
|
||||
|
||||
public Map<String, Integer> getValues() {
|
||||
return values;
|
||||
}
|
||||
|
||||
public void addValue(String key, Integer value) {
|
||||
if (values == null) {
|
||||
values = new HashMap<>();
|
||||
}
|
||||
values.put(key, value);
|
||||
}
|
||||
|
||||
public void setValues(Map<String, Integer> values) {
|
||||
this.values = values;
|
||||
@Override
|
||||
public void setId(String id) {
|
||||
super.id = id;
|
||||
this.label = LocationUtils.getCountryName(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -7,9 +7,6 @@
|
||||
*/
|
||||
package org.dspace.app.rest.model;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This class serves as a REST representation of a Date (month) data Point of a {@link UsageReportRest} from the DSpace
|
||||
* statistics
|
||||
@@ -19,32 +16,6 @@ import java.util.Map;
|
||||
public class UsageReportPointDateRest extends UsageReportPointRest {
|
||||
public static final String NAME = "date";
|
||||
|
||||
private String id;
|
||||
private Map<String, Integer> values;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Map<String, Integer> getValues() {
|
||||
return values;
|
||||
}
|
||||
|
||||
public void addValue(String key, Integer value) {
|
||||
if (values == null) {
|
||||
values = new HashMap<>();
|
||||
}
|
||||
values.put(key, value);
|
||||
}
|
||||
|
||||
public void setValues(Map<String, Integer> values) {
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return NAME;
|
||||
|
@@ -7,9 +7,6 @@
|
||||
*/
|
||||
package org.dspace.app.rest.model;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This class serves as a REST representation of a TotalVisit data Point of a DSO's {@link UsageReportRest} from the
|
||||
* DSpace statistics
|
||||
@@ -19,31 +16,6 @@ import java.util.Map;
|
||||
public class UsageReportPointDsoTotalVisitsRest extends UsageReportPointRest {
|
||||
|
||||
private String type;
|
||||
private String id;
|
||||
private Map<String, Integer> values;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Map<String, Integer> getValues() {
|
||||
return values;
|
||||
}
|
||||
|
||||
public void addValue(String key, Integer value) {
|
||||
if (values == null) {
|
||||
values = new HashMap<>();
|
||||
}
|
||||
values.put(key, value);
|
||||
}
|
||||
|
||||
public void setValues(Map<String, Integer> values) {
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
|
@@ -7,6 +7,9 @@
|
||||
*/
|
||||
package org.dspace.app.rest.model;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.dspace.app.rest.StatisticsRestController;
|
||||
|
||||
/**
|
||||
@@ -17,6 +20,8 @@ import org.dspace.app.rest.StatisticsRestController;
|
||||
public class UsageReportPointRest extends BaseObjectRest<String> {
|
||||
public static final String NAME = "point";
|
||||
public static final String CATEGORY = RestModel.STATISTICS;
|
||||
protected String id;
|
||||
private Map<String, Integer> values;
|
||||
|
||||
public String getCategory() {
|
||||
return CATEGORY;
|
||||
@@ -29,4 +34,27 @@ public class UsageReportPointRest extends BaseObjectRest<String> {
|
||||
public String getType() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
public Map<String, Integer> getValues() {
|
||||
return values;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void addValue(String key, Integer value) {
|
||||
if (values == null) {
|
||||
values = new HashMap<>();
|
||||
}
|
||||
values.put(key, value);
|
||||
}
|
||||
|
||||
public void setValues(Map<String, Integer> values) {
|
||||
this.values = values;
|
||||
}
|
||||
}
|
||||
|
@@ -47,6 +47,9 @@ public class UsageReportRest extends BaseObjectRest<String> {
|
||||
}
|
||||
|
||||
public List<UsageReportPointRest> getPoints() {
|
||||
if (points == null) {
|
||||
points = new ArrayList<>();
|
||||
}
|
||||
return points;
|
||||
}
|
||||
|
||||
|
@@ -15,7 +15,6 @@ import java.util.UUID;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.solr.client.solrj.SolrServerException;
|
||||
import org.dspace.app.rest.exception.DSpaceBadRequestException;
|
||||
import org.dspace.app.rest.exception.RepositoryMethodNotImplementedException;
|
||||
import org.dspace.app.rest.model.UsageReportPointCityRest;
|
||||
import org.dspace.app.rest.model.UsageReportPointCountryRest;
|
||||
import org.dspace.app.rest.model.UsageReportPointDateRest;
|
||||
@@ -23,6 +22,8 @@ import org.dspace.app.rest.model.UsageReportPointDsoTotalVisitsRest;
|
||||
import org.dspace.app.rest.model.UsageReportRest;
|
||||
import org.dspace.app.rest.utils.DSpaceObjectUtils;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.content.service.ItemService;
|
||||
import org.dspace.core.Constants;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.statistics.Dataset;
|
||||
import org.dspace.statistics.content.DatasetDSpaceObjectGenerator;
|
||||
@@ -44,6 +45,8 @@ public class UsageReportRestRepository extends AbstractDSpaceRestRepository {
|
||||
|
||||
@Autowired
|
||||
private DSpaceObjectUtils dspaceObjectUtil;
|
||||
@Autowired
|
||||
private ItemService itemService;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
@@ -60,6 +63,9 @@ public class UsageReportRestRepository extends AbstractDSpaceRestRepository {
|
||||
throws ParseException, SolrServerException, IOException {
|
||||
try {
|
||||
DSpaceObject dso = dspaceObjectUtil.findDSpaceObject(context, uuid);
|
||||
if (dso == null) {
|
||||
throw new IllegalArgumentException("No DSO found with this UUID: " + uuid);
|
||||
}
|
||||
UsageReportRest usageReportRest;
|
||||
switch (reportId) {
|
||||
case "TotalVisits":
|
||||
@@ -71,7 +77,9 @@ public class UsageReportRestRepository extends AbstractDSpaceRestRepository {
|
||||
usageReportRest.setReportType("TotalVisitsPerMonth");
|
||||
break;
|
||||
case "TotalDownloads":
|
||||
throw new RepositoryMethodNotImplementedException("TODO", "TotalDownloads");
|
||||
usageReportRest = resolveTotalDownloads(context, dso);
|
||||
usageReportRest.setReportType("TotalDownloads");
|
||||
break;
|
||||
case "TopCountries":
|
||||
usageReportRest = resolveTopCountries(context, dso);
|
||||
usageReportRest.setReportType("TopCountries");
|
||||
@@ -93,20 +101,19 @@ public class UsageReportRestRepository extends AbstractDSpaceRestRepository {
|
||||
|
||||
private UsageReportRest resolveTotalVisits(Context context, DSpaceObject dso)
|
||||
throws SQLException, IOException, ParseException, SolrServerException {
|
||||
StatisticsListing statListing = new StatisticsListing(new StatisticsDataVisits(dso));
|
||||
DatasetDSpaceObjectGenerator dsoAxis = new DatasetDSpaceObjectGenerator();
|
||||
dsoAxis.addDsoChild(dso.getType(), 10, false, -1);
|
||||
statListing.addDatasetGenerator(dsoAxis);
|
||||
Dataset dataset = statListing.getDataset(context);
|
||||
Dataset dataset = this.getDSOStatsDataset(context, dso, 0, dso.getType());
|
||||
|
||||
UsageReportRest usageReportRest = new UsageReportRest();
|
||||
for (int i = 0; i < dataset.getColLabels().size(); i++) {
|
||||
UsageReportPointDsoTotalVisitsRest totalVisitPoint = new UsageReportPointDsoTotalVisitsRest();
|
||||
totalVisitPoint.setType(StringUtils.substringAfterLast(dso.getClass().getName().toLowerCase(), "."));
|
||||
totalVisitPoint.setId(dso.getID().toString());
|
||||
totalVisitPoint.addValue("views", Integer.valueOf(dataset.getMatrix()[0][i]));
|
||||
usageReportRest.addPoint(totalVisitPoint);
|
||||
UsageReportPointDsoTotalVisitsRest totalVisitPoint = new UsageReportPointDsoTotalVisitsRest();
|
||||
totalVisitPoint.setType(StringUtils.substringAfterLast(dso.getClass().getName().toLowerCase(), "."));
|
||||
totalVisitPoint.setId(dso.getID().toString());
|
||||
if (dataset.getColLabels().size() > 0) {
|
||||
totalVisitPoint.addValue("views", Integer.valueOf(dataset.getMatrix()[0][0]));
|
||||
} else {
|
||||
totalVisitPoint.addValue("views", 0);
|
||||
}
|
||||
|
||||
usageReportRest.addPoint(totalVisitPoint);
|
||||
return usageReportRest;
|
||||
}
|
||||
|
||||
@@ -120,7 +127,7 @@ public class UsageReportRestRepository extends AbstractDSpaceRestRepository {
|
||||
DatasetDSpaceObjectGenerator dsoAxis = new DatasetDSpaceObjectGenerator();
|
||||
dsoAxis.addDsoChild(dso.getType(), 10, false, -1);
|
||||
statisticsTable.addDatasetGenerator(dsoAxis);
|
||||
Dataset dataset = statisticsTable.getDataset(context);
|
||||
Dataset dataset = statisticsTable.getDataset(context, 0);
|
||||
|
||||
UsageReportRest usageReportRest = new UsageReportRest();
|
||||
for (int i = 0; i < dataset.getColLabels().size(); i++) {
|
||||
@@ -132,9 +139,36 @@ public class UsageReportRestRepository extends AbstractDSpaceRestRepository {
|
||||
return usageReportRest;
|
||||
}
|
||||
|
||||
private UsageReportRest resolveTotalDownloads(Context context, DSpaceObject dso)
|
||||
throws SQLException, SolrServerException, ParseException, IOException {
|
||||
if (dso instanceof org.dspace.content.Bitstream) {
|
||||
return this.resolveTotalVisits(context, dso);
|
||||
}
|
||||
|
||||
if (dso instanceof org.dspace.content.Item) {
|
||||
// Make sure our item has at least one bitstream
|
||||
org.dspace.content.Item item = (org.dspace.content.Item) dso;
|
||||
// if (itemService.hasUploadedFiles(item)) {
|
||||
// }
|
||||
|
||||
Dataset dataset = this.getDSOStatsDataset(context, dso, 1, Constants.BITSTREAM);
|
||||
|
||||
UsageReportRest usageReportRest = new UsageReportRest();
|
||||
for (int i = 0; i < dataset.getColLabels().size(); i++) {
|
||||
UsageReportPointDsoTotalVisitsRest totalDownloadsPoint = new UsageReportPointDsoTotalVisitsRest();
|
||||
totalDownloadsPoint.setType("bitstream");
|
||||
totalDownloadsPoint.setId(dataset.getColLabels().get(i));
|
||||
totalDownloadsPoint.addValue("views", Integer.valueOf(dataset.getMatrix()[0][i]));
|
||||
usageReportRest.addPoint(totalDownloadsPoint);
|
||||
}
|
||||
return usageReportRest;
|
||||
}
|
||||
throw new IllegalArgumentException("TotalDownloads report only available for items and bitstreams");
|
||||
}
|
||||
|
||||
private UsageReportRest resolveTopCountries(Context context, DSpaceObject dso)
|
||||
throws SQLException, IOException, ParseException, SolrServerException {
|
||||
Dataset dataset = this.getTypeStatsDataset(context, dso, "countryCode");
|
||||
Dataset dataset = this.getTypeStatsDataset(context, dso, "countryCode", 1);
|
||||
|
||||
UsageReportRest usageReportRest = new UsageReportRest();
|
||||
for (int i = 0; i < dataset.getColLabels().size(); i++) {
|
||||
@@ -148,7 +182,7 @@ public class UsageReportRestRepository extends AbstractDSpaceRestRepository {
|
||||
|
||||
private UsageReportRest resolveTopCities(Context context, DSpaceObject dso)
|
||||
throws SQLException, IOException, ParseException, SolrServerException {
|
||||
Dataset dataset = this.getTypeStatsDataset(context, dso, "city");
|
||||
Dataset dataset = this.getTypeStatsDataset(context, dso, "city", 1);
|
||||
|
||||
UsageReportRest usageReportRest = new UsageReportRest();
|
||||
for (int i = 0; i < dataset.getColLabels().size(); i++) {
|
||||
@@ -160,7 +194,16 @@ public class UsageReportRestRepository extends AbstractDSpaceRestRepository {
|
||||
return usageReportRest;
|
||||
}
|
||||
|
||||
private Dataset getTypeStatsDataset(Context context, DSpaceObject dso, String typeAxisString)
|
||||
private Dataset getDSOStatsDataset(Context context, DSpaceObject dso, int facetMinCount, int dsoType)
|
||||
throws SQLException, IOException, ParseException, SolrServerException {
|
||||
StatisticsListing statsList = new StatisticsListing(new StatisticsDataVisits(dso));
|
||||
DatasetDSpaceObjectGenerator dsoAxis = new DatasetDSpaceObjectGenerator();
|
||||
dsoAxis.addDsoChild(dsoType, 10, false, -1);
|
||||
statsList.addDatasetGenerator(dsoAxis);
|
||||
return statsList.getDataset(context, facetMinCount);
|
||||
}
|
||||
|
||||
private Dataset getTypeStatsDataset(Context context, DSpaceObject dso, String typeAxisString, int facetMinCount)
|
||||
throws SQLException, IOException, ParseException, SolrServerException {
|
||||
StatisticsListing statListing = new StatisticsListing(new StatisticsDataVisits(dso));
|
||||
DatasetTypeGenerator typeAxis = new DatasetTypeGenerator();
|
||||
@@ -168,6 +211,6 @@ public class UsageReportRestRepository extends AbstractDSpaceRestRepository {
|
||||
// TODO make max nr of top countries/cities a request para? Must be set
|
||||
typeAxis.setMax(100);
|
||||
statListing.addDatasetGenerator(typeAxis);
|
||||
return statListing.getDataset(context);
|
||||
return statListing.getDataset(context, facetMinCount);
|
||||
}
|
||||
}
|
||||
|
@@ -729,7 +729,7 @@ public class BitstreamRestControllerIT extends AbstractControllerIntegrationTest
|
||||
|
||||
// Find all hits/views of bitstream
|
||||
ObjectCount objectCount = solrLoggerService.queryTotal("type:" + Constants.BITSTREAM +
|
||||
" AND id:" + bitstream.getID(), null);
|
||||
" AND id:" + bitstream.getID(), null, 1);
|
||||
assertEquals(expectedNumberOfStatsRecords, objectCount.getCount());
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user