Skip to content

Commit 619c17d

Browse files
steph-ieffamvins01-4science
authored andcommitted
Merged in task/dspace-cris-2024_02_x/DSC-2823 (pull request DSpace#5726)
[DSC-2823] record statistics for download presigned URL Approved-by: Vincenzo Mecca
2 parents d32fae8 + 4043566 commit 619c17d

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,14 @@ public ResponseEntity<?> getPresignedUrl(@PathVariable UUID uuid,
324324
return null;
325325
}
326326

327+
// Fire a download/view event for Solr statistics
328+
eventService.fireEvent(
329+
new UsageEvent(
330+
UsageEvent.Action.VIEW,
331+
request,
332+
context,
333+
bitstream));
334+
327335
try {
328336
String presignedUrl = bitstreamStorageService.getPresignedUrl(context, bitstream);
329337
if (StringUtils.isBlank(presignedUrl)) {

dspace-server-webapp/src/test/java/org/dspace/app/rest/BitstreamRestControllerIT.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,6 +1800,33 @@ public void testGetPresignedUrl_BitstreamNotFound() throws Exception {
18001800
.andExpect(status().isNotFound());
18011801
}
18021802

1803+
@Test
1804+
public void testGetPresignedUrl_LogsStatisticsEvent() throws Exception {
1805+
// Grant READ access to eperson
1806+
context.turnOffAuthorisationSystem();
1807+
createResourcePolicy(context, eperson, null)
1808+
.withAction(READ)
1809+
.withDspaceObject(bitstream)
1810+
.build();
1811+
context.restoreAuthSystemState();
1812+
1813+
// Verify no stats records exist yet
1814+
checkNumberOfStatsRecords(bitstream, 0);
1815+
1816+
String authToken = getAuthToken(eperson.getEmail(), password);
1817+
getClient(authToken)
1818+
.perform(get("/api/core/bitstreams/" + bitstream.getID() + "/signedurl"));
1819+
1820+
// Verify that a statistics record was logged
1821+
checkNumberOfStatsRecords(bitstream, 1);
1822+
1823+
// Call again to verify it increments
1824+
getClient(authToken)
1825+
.perform(get("/api/core/bitstreams/" + bitstream.getID() + "/signedurl"));
1826+
1827+
checkNumberOfStatsRecords(bitstream, 2);
1828+
}
1829+
18031830
@Test
18041831
public void testGetPresignedUrl_PresignedUrlNotAvailable() throws Exception {
18051832
// Grant READ access to eperson

0 commit comments

Comments
 (0)