71214: checkstyle & javadoc

This commit is contained in:
Marie Verdonck
2020-06-11 11:27:30 +02:00
parent 16df8f38f9
commit 2b0a3664ca
5 changed files with 107 additions and 16 deletions

View File

@@ -120,12 +120,13 @@ public class StatisticsRestController implements InitializingBean {
@RequestMapping(method = RequestMethod.GET, value = "/usagereports")
public PagedModel<SearchEventResource> getUsageReports() {
throw new RepositoryMethodNotImplementedException("No implementation found; Method not allowed!", "getUsageReports");
throw new RepositoryMethodNotImplementedException("No implementation found; Method not allowed!",
"getUsageReports");
}
@RequestMapping(method = RequestMethod.GET, value = "/usagereports/{uuid_id}")
public UsageReportRest getUsageReport(@PathVariable(name = "uuid_id") String uuidObjectReportId,
HttpServletRequest request)
HttpServletRequest request)
throws ParseException, SolrServerException, IOException {
if (StringUtils.countMatches(uuidObjectReportId, "_") != 1) {
throw new IllegalArgumentException("Must end in objectUUID_reportId, example: " +

View File

@@ -22,7 +22,6 @@ 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;
@@ -45,19 +44,15 @@ public class UsageReportRestRepository extends AbstractDSpaceRestRepository {
@Autowired
private DSpaceObjectUtils dspaceObjectUtil;
@Autowired
private ItemService itemService;
/**
* TODO
* Creates the stat different stat usage report based on the report id.
* If the report id or the object uuid is invalid, an exception is thrown.
*
* @param context
* @param uuid
* @param reportId
* @return
* @throws ParseException
* @throws SolrServerException
* @throws IOException
* @param context DSpace context
* @param uuid DSpace object UUID we want a stat usage report on
* @param reportId Type of usage report requested
* @return Rest object containing the stat usage report, see {@link UsageReportRest}
*/
public UsageReportRest createUsageReport(Context context, UUID uuid, String reportId)
throws ParseException, SolrServerException, IOException {
@@ -99,6 +94,14 @@ public class UsageReportRestRepository extends AbstractDSpaceRestRepository {
}
}
/**
* Create a stat usage report for the amount of TotalVisit on a DSO, containing one point with the amount of
* views on the DSO in. If there are no views on the DSO this point contains views=0.
*
* @param context DSpace context
* @param dso DSO we want usage report with TotalVisits on the DSO
* @return Rest object containing the TotalVisits usage report of the given DSO
*/
private UsageReportRest resolveTotalVisits(Context context, DSpaceObject dso)
throws SQLException, IOException, ParseException, SolrServerException {
Dataset dataset = this.getDSOStatsDataset(context, dso, 0, dso.getType());
@@ -117,6 +120,15 @@ public class UsageReportRestRepository extends AbstractDSpaceRestRepository {
return usageReportRest;
}
/**
* Create a stat usage report for the amount of TotalVisitPerMonth on a DSO, containing one point for each month
* with the views on that DSO in that month with the range -6 months to now. If there are no views on the DSO
* in a month, the point on that month contains views=0.
*
* @param context DSpace context
* @param dso DSO we want usage report with TotalVisitsPerMonth to the DSO
* @return Rest object containing the TotalVisits usage report on the given DSO
*/
private UsageReportRest resolveTotalVisitsPerMonth(Context context, DSpaceObject dso)
throws SQLException, IOException, ParseException, SolrServerException {
StatisticsTable statisticsTable = new StatisticsTable(new StatisticsDataVisits(dso));
@@ -139,6 +151,19 @@ public class UsageReportRestRepository extends AbstractDSpaceRestRepository {
return usageReportRest;
}
/**
* Create a stat usage report for the amount of TotalDownloads on the files of an Item or of a Bitstream,
* containing a point for each bitstream of the item that has been visited at least once or one point for the
* bitstream containing the amount of times that bitstream has been visited (even if 0)
* If the item has no bitstreams, or no bitstreams that have ever been downloaded/visited, then it contains an
* empty list of points=[]
* If the given UUID is for DSO that is neither a Bitstream nor an Item, an exception is thrown.
*
* @param context DSpace context
* @param dso Item/Bitstream we want usage report on with TotalDownloads of the Item's bitstreams or of the
* bitstream itself
* @return Rest object containing the TotalDownloads usage report on the given Item/Bitstream
*/
private UsageReportRest resolveTotalDownloads(Context context, DSpaceObject dso)
throws SQLException, SolrServerException, ParseException, IOException {
if (dso instanceof org.dspace.content.Bitstream) {
@@ -161,6 +186,16 @@ public class UsageReportRestRepository extends AbstractDSpaceRestRepository {
throw new IllegalArgumentException("TotalDownloads report only available for items and bitstreams");
}
/**
* Create a stat usage report for the TopCountries that have visited the given DSO. If there have been no visits, or
* no visits with a valid Geolite determined country (based on IP), this report contains an empty list of points=[].
* The list of points is limited to the top 100 countries, and each point contains the country name, its iso code
* and the amount of views on the given DSO from that country.
*
* @param context DSpace context
* @param dso DSO we want usage report of the TopCountries on the given DSO
* @return Rest object containing the TopCountries usage report on the given DSO
*/
private UsageReportRest resolveTopCountries(Context context, DSpaceObject dso)
throws SQLException, IOException, ParseException, SolrServerException {
Dataset dataset = this.getTypeStatsDataset(context, dso, "countryCode", 1);
@@ -175,6 +210,16 @@ public class UsageReportRestRepository extends AbstractDSpaceRestRepository {
return usageReportRest;
}
/**
* Create a stat usage report for the TopCities that have visited the given DSO. If there have been no visits, or
* no visits with a valid Geolite determined city (based on IP), this report contains an empty list of points=[].
* The list of points is limited to the top 100 cities, and each point contains the city name and the amount of
* views on the given DSO from that city.
*
* @param context DSpace context
* @param dso DSO we want usage report of the TopCities on the given DSO
* @return Rest object containing the TopCities usage report on the given DSO
*/
private UsageReportRest resolveTopCities(Context context, DSpaceObject dso)
throws SQLException, IOException, ParseException, SolrServerException {
Dataset dataset = this.getTypeStatsDataset(context, dso, "city", 1);
@@ -189,6 +234,16 @@ public class UsageReportRestRepository extends AbstractDSpaceRestRepository {
return usageReportRest;
}
/**
* Retrieves the stats dataset of a given DSO, of given type, with a given facetMinCount limit (usually either 0
* or 1, 0 if we want a data point even though the facet data point has 0 matching results).
*
* @param context DSpace context
* @param dso DSO we want the stats dataset of
* @param facetMinCount Minimum amount of results on a facet data point for it to be added to dataset
* @param dsoType Type of DSO we want the stats dataset of
* @return Stats dataset with the given filters.
*/
private Dataset getDSOStatsDataset(Context context, DSpaceObject dso, int facetMinCount, int dsoType)
throws SQLException, IOException, ParseException, SolrServerException {
StatisticsListing statsList = new StatisticsListing(new StatisticsDataVisits(dso));
@@ -198,6 +253,18 @@ public class UsageReportRestRepository extends AbstractDSpaceRestRepository {
return statsList.getDataset(context, facetMinCount);
}
/**
* Retrieves the stats dataset of a given dso, with a given axisType (example countryCode, city), which
* corresponds to a solr field, and a given facetMinCount limit (usually either 0 or 1, 0 if we want a data point
* even though the facet data point has 0 matching results).
*
* @param context DSpace context
* @param dso DSO we want the stats dataset of
* @param typeAxisString String of the type we want on the axis of the dataset (corresponds to solr field),
* examples: countryCode, city
* @param facetMinCount Minimum amount of results on a facet data point for it to be added to dataset
* @return Stats dataset with the given type on the axis, of the given DSO and with given facetMinCount
*/
private Dataset getTypeStatsDataset(Context context, DSpaceObject dso, String typeAxisString, int facetMinCount)
throws SQLException, IOException, ParseException, SolrServerException {
StatisticsListing statListing = new StatisticsListing(new StatisticsDataVisits(dso));

View File

@@ -519,7 +519,7 @@ public class UsageReportRestRepositoryIT extends AbstractControllerIntegrationTe
.andExpect(status().is(HttpStatus.BAD_REQUEST.value()));
}
// Create expected points from -6 months to now, with a view in current month
// Create expected points from -6 months to now, with given number of views in current month
private List<UsageReportPointRest> getListOfVisitsPerMonthsPoints(int viewsLastMonth) {
List<UsageReportPointRest> expectedPoints = new ArrayList<>();
int nrOfMonthsBack = 6;

View File

@@ -28,13 +28,27 @@ public class UsageReportMatcher {
private UsageReportMatcher() {
}
/**
* Matcher for the usage report on just id and report-type
*
* @param id Id to match if of json of UsageReport
* @param reportType ReportType to match if of json of UsageReport
* @return The matcher
*/
private static Matcher<? super Object> matchUsageReport(String id, String reportType) {
return allOf(
hasJsonPath("$.id", is(id)),
hasJsonPath("$.report-type", is(reportType))
);
hasJsonPath("$.report-type", is(reportType)));
}
/**
* Matcher for the usage report including the {@link UsageReportPointRest} points
*
* @param id Id to match if of json of UsageReport
* @param reportType ReportType to match if of json of UsageReport
* @param points List of points to match to the json of UsageReport's list of points
* @return The matcher
*/
public static Matcher<? super Object> matchUsageReport(String id, String reportType,
List<UsageReportPointRest> points) {
return allOf(

View File

@@ -11,6 +11,7 @@ import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.is;
import org.dspace.app.rest.model.UsageReportPointRest;
import org.hamcrest.Matcher;
/**
@@ -23,6 +24,14 @@ public class UsageReportPointMatcher {
private UsageReportPointMatcher() {
}
/**
* Matcher for the usage report points (see {@link UsageReportPointRest})
*
* @param id Id to match if of json of UsageReportPoint
* @param type Type to match if of json of UsageReportPoint
* @param views Nr of views, is in the values key-value pair of values of UsageReportPoint with key "views"
* @return The matcher
*/
public static Matcher<? super Object> matchUsageReportPoint(String id, String type, int views) {
return allOf(
hasJsonPath("$.id", is(id)),