Skip to content

Commit 7617f99

Browse files
steph-ieffamvins01-4science
authored andcommitted
Merged in task/dspace-cris-2025_02_x/DSC-2823 (pull request DSpace#5727)
[DSC-2823] record statistics for download presigned URL Approved-by: Vincenzo Mecca
2 parents f1e8984 + da2da15 commit 7617f99

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
@@ -386,6 +386,14 @@ public ResponseEntity<?> getPresignedUrl(@PathVariable UUID uuid,
386386
return null;
387387
}
388388

389+
// Fire a download/view event for Solr statistics
390+
eventService.fireEvent(
391+
new UsageEvent(
392+
UsageEvent.Action.VIEW,
393+
request,
394+
context,
395+
bitstream));
396+
389397
try {
390398
String presignedUrl = bitstreamStorageService.getPresignedUrl(context, bitstream);
391399
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
@@ -1820,6 +1820,33 @@ public void testGetPresignedUrl_BitstreamNotFound() throws Exception {
18201820
.andExpect(status().isNotFound());
18211821
}
18221822

1823+
@Test
1824+
public void testGetPresignedUrl_LogsStatisticsEvent() throws Exception {
1825+
// Grant READ access to eperson
1826+
context.turnOffAuthorisationSystem();
1827+
createResourcePolicy(context, eperson, null)
1828+
.withAction(READ)
1829+
.withDspaceObject(bitstream)
1830+
.build();
1831+
context.restoreAuthSystemState();
1832+
1833+
// Verify no stats records exist yet
1834+
checkNumberOfStatsRecords(bitstream, 0);
1835+
1836+
String authToken = getAuthToken(eperson.getEmail(), password);
1837+
getClient(authToken)
1838+
.perform(get("/api/core/bitstreams/" + bitstream.getID() + "/signedurl"));
1839+
1840+
// Verify that a statistics record was logged
1841+
checkNumberOfStatsRecords(bitstream, 1);
1842+
1843+
// Call again to verify it increments
1844+
getClient(authToken)
1845+
.perform(get("/api/core/bitstreams/" + bitstream.getID() + "/signedurl"));
1846+
1847+
checkNumberOfStatsRecords(bitstream, 2);
1848+
}
1849+
18231850
@Test
18241851
public void testGetPresignedUrl_PresignedUrlNotAvailable() throws Exception {
18251852
// Grant READ access to eperson

0 commit comments

Comments
 (0)