Skip to content

Commit 35a1eb2

Browse files
committed
add guestbookId to missing response message
1 parent 05a961e commit 35a1eb2

3 files changed

Lines changed: 13 additions & 8 deletions

File tree

src/main/java/edu/harvard/iq/dataverse/api/Access.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public BundleDownloadInstance datafileBundle(@Context ContainerRequestContext cr
147147
checkAuthorization(crc, df);
148148
User requestor = getRequestor(crc);
149149
if (checkGuestbookRequiredResponse(crc, uriInfo, df, gbrids)) {
150-
throw new BadRequestException(BundleUtil.getStringFromBundle("access.api.download.failure.guestbookResponseMissing"));
150+
throw new BadRequestException(BundleUtil.getStringFromBundle("access.api.download.failure.guestbookResponseMissing", getGuestbookIdFromDatafile(df)));
151151
}
152152

153153
if (gbrecs != true && df.isReleased()) {
@@ -252,7 +252,7 @@ public Response datafile(@Context ContainerRequestContext crc, @PathParam("fileI
252252
checkAuthorization(crc, df);
253253
User requestor = getRequestor(crc);
254254
if (checkGuestbookRequiredResponse(crc, uriInfo, df, gbrids)) {
255-
return error(BAD_REQUEST, BundleUtil.getStringFromBundle("access.api.download.failure.guestbookResponseMissing"));
255+
return error(BAD_REQUEST, BundleUtil.getStringFromBundle("access.api.download.failure.guestbookResponseMissing", getGuestbookIdFromDatafile(df)));
256256
}
257257

258258
if (gbrecs != true && df.isReleased()){
@@ -407,6 +407,11 @@ private String normalizeFileId(String fileId) {
407407
return fId;
408408
}
409409

410+
// for bundle arg list
411+
private List<String> getGuestbookIdFromDatafile(DataFile df) {
412+
return df != null && df.getOwner() != null && df.getOwner().getGuestbook() != null ? List.of(df.getOwner().getGuestbook().getId().toString()) : List.of();
413+
}
414+
410415
// Process the guestbook response from JSON and return a signedUrl to the matching GET call
411416
private Response processDatafileWithGuestbookResponse(ContainerRequestContext crc, HttpHeaders headers, String fileIds, UriInfo uriInfo, boolean gbrecs, String jsonBody) {
412417

@@ -435,7 +440,7 @@ private Response processDatafileWithGuestbookResponse(ContainerRequestContext cr
435440
MakeDataCountEntry entry = new MakeDataCountEntry(uriInfo, headers, dvRequestService, df);
436441
mdcLogService.logEntry(entry);
437442
} else {
438-
return error(BAD_REQUEST, BundleUtil.getStringFromBundle("access.api.download.failure.guestbookResponseMissing"));
443+
return error(BAD_REQUEST, BundleUtil.getStringFromBundle("access.api.download.failure.guestbookResponseMissing", getGuestbookIdFromDatafile(df)));
439444
}
440445
} else if (gbrecs != true && df.isReleased()) {
441446
// Write Guestbook record if not done previously and file is released
@@ -1031,7 +1036,7 @@ private Response downloadDatafiles(ContainerRequestContext crc, String body, boo
10311036
MakeDataCountEntry entry = new MakeDataCountEntry(uriInfo, headers, dvRequestService, df);
10321037
mdcLogService.logEntry(entry);
10331038
} else {
1034-
return error(BAD_REQUEST, BundleUtil.getStringFromBundle("access.api.download.failure.guestbookResponseMissing"));
1039+
return error(BAD_REQUEST, BundleUtil.getStringFromBundle("access.api.download.failure.guestbookResponseMissing", getGuestbookIdFromDatafile(df)));
10351040
}
10361041
} catch (JsonParseException | CommandException ex) {
10371042
List<String> args = Arrays.asList(df.getDisplayName(), ex.getLocalizedMessage());

src/main/java/propertyFiles/Bundle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2953,7 +2953,7 @@ access.api.exception.metadata.not.available.for.nontabular.file=This type of met
29532953
access.api.exception.metadata.restricted.no.permission=You do not have permission to download this file.
29542954
access.api.exception.version.not.found=Could not find requested dataset version.
29552955
access.api.exception.dataset.not.found=Could not find requested dataset.
2956-
access.api.download.failure.guestbookResponseMissing=You may not download this file without the required Guestbook response.
2956+
access.api.download.failure.guestbookResponseMissing=You may not download this file without the required Guestbook response for guestbookID {0}.
29572957
access.api.download.failure.guestbook.commandError=Problem trying download with guestbook response on {0} : {1}
29582958
access.api.download.failure.multipleDatasets=All files being downloaded must be from the same Dataset.
29592959

src/test/java/edu/harvard/iq/dataverse/api/FilesIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3978,7 +3978,7 @@ public void testDownloadFileWithGuestbookResponse() throws IOException, JsonPars
39783978
downloadResponse.prettyPrint();
39793979
downloadResponse.then().assertThat()
39803980
.body("status", equalTo(ApiConstants.STATUS_ERROR))
3981-
.body("message", equalTo(BundleUtil.getStringFromBundle("access.api.download.failure.guestbookResponseMissing")))
3981+
.body("message", equalTo(BundleUtil.getStringFromBundle("access.api.download.failure.guestbookResponseMissing", List.of(guestbook.getId().toString()))))
39823982
.statusCode(BAD_REQUEST.getStatusCode());
39833983
// With GuestbookResponse. Guest user doesn't have the required Name and Email. so this will still fail
39843984
downloadResponse = UtilIT.postDownloadFile(fileId4, guestbookResponse);
@@ -4004,7 +4004,7 @@ public void testDownloadFileWithGuestbookResponse() throws IOException, JsonPars
40044004
downloadResponse.prettyPrint();
40054005
downloadResponse.then().assertThat()
40064006
.body("status", equalTo(ApiConstants.STATUS_ERROR))
4007-
.body("message", equalTo(BundleUtil.getStringFromBundle("access.api.download.failure.guestbookResponseMissing")))
4007+
.body("message", equalTo(BundleUtil.getStringFromBundle("access.api.download.failure.guestbookResponseMissing", List.of(guestbook.getId().toString()))))
40084008
.statusCode(BAD_REQUEST.getStatusCode());
40094009

40104010
// Get Signed Download Url with guestbook response
@@ -4023,7 +4023,7 @@ public void testDownloadFileWithGuestbookResponse() throws IOException, JsonPars
40234023
downloadResponse.prettyPrint();
40244024
downloadResponse.then().assertThat()
40254025
.body("status", equalTo(ApiConstants.STATUS_ERROR))
4026-
.body("message", equalTo(BundleUtil.getStringFromBundle("access.api.download.failure.guestbookResponseMissing")))
4026+
.body("message", equalTo(BundleUtil.getStringFromBundle("access.api.download.failure.guestbookResponseMissing", List.of(guestbook.getId().toString()))))
40274027
.statusCode(BAD_REQUEST.getStatusCode());
40284028

40294029
// Download multiple files with guestbook response and fileIds in json

0 commit comments

Comments
 (0)