Skip to content

Commit

Permalink
#10286 add owner array to file api
Browse files Browse the repository at this point in the history
  • Loading branch information
sekmiller committed Feb 9, 2024
1 parent 889e942 commit 6e51bbc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
17 changes: 10 additions & 7 deletions src/main/java/edu/harvard/iq/dataverse/api/Files.java
Original file line number Diff line number Diff line change
Expand Up @@ -504,18 +504,21 @@ public Response updateFileMetadata(@Context ContainerRequestContext crc, @FormDa
@GET
@AuthRequired
@Path("{id}/draft")
public Response getFileDataDraft(@Context ContainerRequestContext crc, @PathParam("id") String fileIdOrPersistentId, @Context UriInfo uriInfo, @Context HttpHeaders headers, @Context HttpServletResponse response) throws WrappedResponse, Exception {
return getFileDataResponse(getRequestUser(crc), fileIdOrPersistentId, uriInfo, headers, response, true);
public Response getFileDataDraft(@Context ContainerRequestContext crc, @PathParam("id") String fileIdOrPersistentId, @Context UriInfo uriInfo, @Context HttpHeaders headers, @Context HttpServletResponse response, @QueryParam("returnOwners") Boolean returnOwners) throws WrappedResponse, Exception {
Boolean includeOwners = returnOwners == null ? false : returnOwners;
return getFileDataResponse(getRequestUser(crc), fileIdOrPersistentId, uriInfo, headers, response, true, includeOwners);
}

@GET
@AuthRequired
@Path("{id}")
public Response getFileData(@Context ContainerRequestContext crc, @PathParam("id") String fileIdOrPersistentId, @Context UriInfo uriInfo, @Context HttpHeaders headers, @Context HttpServletResponse response) throws WrappedResponse, Exception {
return getFileDataResponse(getRequestUser(crc), fileIdOrPersistentId, uriInfo, headers, response, false);
public Response getFileData(@Context ContainerRequestContext crc, @PathParam("id") String fileIdOrPersistentId, @Context UriInfo uriInfo, @Context HttpHeaders headers, @Context HttpServletResponse response, @QueryParam("returnOwners") Boolean returnOwners) throws WrappedResponse, Exception {
Boolean includeOwners = returnOwners == null ? false : returnOwners;
System.out.print("includeOwners: " + includeOwners);
return getFileDataResponse(getRequestUser(crc), fileIdOrPersistentId, uriInfo, headers, response, false, includeOwners);
}

private Response getFileDataResponse(User user, String fileIdOrPersistentId, UriInfo uriInfo, HttpHeaders headers, HttpServletResponse response, boolean draft ){
private Response getFileDataResponse(User user, String fileIdOrPersistentId, UriInfo uriInfo, HttpHeaders headers, HttpServletResponse response, boolean draft, boolean includeOwners ){

DataverseRequest req;
try {
Expand Down Expand Up @@ -565,10 +568,10 @@ private Response getFileDataResponse(User user, String fileIdOrPersistentId, Uri
MakeDataCountLoggingServiceBean.MakeDataCountEntry entry = new MakeDataCountLoggingServiceBean.MakeDataCountEntry(uriInfo, headers, dvRequestService, df);
mdcLogService.logEntry(entry);
}

return Response.ok(Json.createObjectBuilder()
.add("status", ApiConstants.STATUS_OK)
.add("data", json(fm)).build())
.add("data", json(fm, includeOwners)).build())
.type(MediaType.APPLICATION_JSON)
.build();
}
Expand Down
17 changes: 14 additions & 3 deletions src/main/java/edu/harvard/iq/dataverse/util/json/JsonPrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,12 @@ public static JsonObjectBuilder json(DatasetFieldType fld) {

return fieldsBld;
}

public static JsonObjectBuilder json(FileMetadata fmd){
return json(fmd, false);
}

public static JsonObjectBuilder json(FileMetadata fmd) {
public static JsonObjectBuilder json(FileMetadata fmd, Boolean includeOwners) {
return jsonObjectBuilder()
// deprecated: .add("category", fmd.getCategory())
// TODO: uh, figure out what to do here... it's deprecated
Expand All @@ -655,7 +659,7 @@ public static JsonObjectBuilder json(FileMetadata fmd) {
.add("version", fmd.getVersion())
.add("datasetVersionId", fmd.getDatasetVersion().getId())
.add("categories", getFileCategories(fmd))
.add("dataFile", JsonPrinter.json(fmd.getDataFile(), fmd, false));
.add("dataFile", JsonPrinter.json(fmd.getDataFile(), fmd, false, includeOwners));
}

public static JsonObjectBuilder json(AuxiliaryFile auxFile) {
Expand All @@ -674,7 +678,11 @@ public static JsonObjectBuilder json(DataFile df) {
return JsonPrinter.json(df, null, false);
}

public static JsonObjectBuilder json(DataFile df, FileMetadata fileMetadata, boolean forExportDataProvider) {
public static JsonObjectBuilder json(DataFile df, FileMetadata fileMetadata, boolean forExportDataProvider){
return json(df, fileMetadata, forExportDataProvider, false);
}

public static JsonObjectBuilder json(DataFile df, FileMetadata fileMetadata, boolean forExportDataProvider, Boolean includeOwners) {
// File names are no longer stored in the DataFile entity;
// (they are instead in the FileMetadata (as "labels") - this way
// the filename can change between versions...
Expand Down Expand Up @@ -750,6 +758,9 @@ public static JsonObjectBuilder json(DataFile df, FileMetadata fileMetadata, boo
? JsonPrinter.jsonVarGroup(fileMetadata.getVarGroups())
: null);
}
if (includeOwners){
builder.add("ownerArray", getOwnersFromDvObject(df));
}
return builder;
}

Expand Down

0 comments on commit 6e51bbc

Please sign in to comment.