Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

10286 add owner info #10322

Merged
merged 30 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8abeaf0
#10286 add breadcrumbs to dataset api
sekmiller Feb 8, 2024
9fdebb3
Merge branch 'develop' into 10286-add-owner-info
sekmiller Feb 8, 2024
572b9cb
#10286 move owner type to beginning
sekmiller Feb 8, 2024
889e942
#10286 update pathparam name/terms
sekmiller Feb 8, 2024
6e51bbc
#10286 add owner array to file api
sekmiller Feb 9, 2024
43f61e6
#10286 add owner array to view dv
sekmiller Feb 12, 2024
43f8706
Merge branch 'develop' into 10286-add-owner-info
sekmiller Feb 12, 2024
1898c14
#10286 add test for get ds api
sekmiller Feb 12, 2024
a828fd1
#10286 add integration tests
sekmiller Feb 14, 2024
9fd7c48
Merge branch 'develop' into 10286-add-owner-info
sekmiller Feb 14, 2024
923f02e
#10286 delete test data
sekmiller Feb 14, 2024
5ba6a1a
Merge branch 'develop' into 10286-add-owner-info
sekmiller Feb 14, 2024
d3482af
Merge branch 'develop' into 10286-add-owner-info
sekmiller Feb 14, 2024
0244b1e
Merge branch 'develop' into 10286-add-owner-info
sekmiller Feb 20, 2024
314e2eb
#10286 changes from CR
sekmiller Feb 21, 2024
78d7283
#10286 minor cleanup
sekmiller Feb 22, 2024
a752ba7
#10286 separate version from identifier
sekmiller Feb 22, 2024
951077f
#10286 fix copy paste error
sekmiller Feb 22, 2024
f9429bb
Merge branch 'develop' into 10286-add-owner-info
sekmiller Feb 23, 2024
4709cd0
#10286 merge cleanup
sekmiller Feb 23, 2024
4789d2e
#10286 more merge fixes
sekmiller Feb 26, 2024
6a4af15
#10286 prevent double owner array; fix test
sekmiller Feb 26, 2024
14a817c
#10286 add release note
sekmiller Feb 26, 2024
a34d1ec
Update native-api.rst
sekmiller Feb 26, 2024
b17d3d9
Merge branch '10286-add-owner-info' of https://github.com/IQSS/datave…
sekmiller Feb 26, 2024
3751638
#10286 remove debug code
sekmiller Feb 26, 2024
34c0f67
#10286 code cleanup
sekmiller Feb 27, 2024
ae132a3
Revert "Update native-api.rst"
sekmiller Feb 27, 2024
da77732
#10286 one more test
sekmiller Feb 27, 2024
9790d23
Update native-api.rst
sekmiller Feb 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/main/java/edu/harvard/iq/dataverse/api/Datasets.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,12 @@ public interface DsVersionHandler<T> {
@GET
@AuthRequired
@Path("{id}")
public Response getDataset(@Context ContainerRequestContext crc, @PathParam("id") String id, @Context UriInfo uriInfo, @Context HttpHeaders headers, @Context HttpServletResponse response) {
public Response getDataset(@Context ContainerRequestContext crc, @PathParam("id") String id, @Context UriInfo uriInfo, @Context HttpHeaders headers, @Context HttpServletResponse response, @QueryParam("returnOwners") Boolean returnOwners) {
MellyGray marked this conversation as resolved.
Show resolved Hide resolved
return response( req -> {
final Dataset retrieved = execCommand(new GetDatasetCommand(req, findDatasetOrDie(id)));
final DatasetVersion latest = execCommand(new GetLatestAccessibleDatasetVersionCommand(req, retrieved));
final JsonObjectBuilder jsonbuilder = json(retrieved);
Boolean includeOwners = returnOwners == null ? false : returnOwners;
Copy link
Contributor

@GPortas GPortas Feb 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can directly use the primitive boolean type: @QueryParam("returnOwners") boolean returnOwners

And thus avoid the null check. If the query param is not set in the URL, false is the default value.

Same for other endpoints in this PR.

final JsonObjectBuilder jsonbuilder = json(retrieved, includeOwners);
//Report MDC if this is a released version (could be draft if user has access, or user may not have access at all and is not getting metadata beyond the minimum)
if((latest != null) && latest.isReleased()) {
MakeDataCountLoggingServiceBean.MakeDataCountEntry entry = new MakeDataCountEntry(uriInfo, headers, dvRequestService, retrieved);
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/edu/harvard/iq/dataverse/api/Dataverses.java
Original file line number Diff line number Diff line change
Expand Up @@ -610,10 +610,12 @@ private Dataset parseDataset(String datasetJson) throws WrappedResponse {
@GET
@AuthRequired
@Path("{identifier}")
public Response viewDataverse(@Context ContainerRequestContext crc, @PathParam("identifier") String idtf) {
public Response viewDataverse(@Context ContainerRequestContext crc, @PathParam("identifier") String idtf, @QueryParam("returnOwners") Boolean returnOwners) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be consistent with method naming in other places, why not rename the endpoint method from "viewDataverse" to "getDataverse"?

Boolean includeOwners = returnOwners == null ? false : returnOwners;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can avoid this using boolean primitive, as I mentioned in the first review.

return response(req -> ok(
json(execCommand(new GetDataverseCommand(req, findDataverseOrDie(idtf))),
settingsService.isTrueForKey(SettingsServiceBean.Key.ExcludeEmailFromExport, false)
settingsService.isTrueForKey(SettingsServiceBean.Key.ExcludeEmailFromExport, false),
includeOwners
)), getRequestUser(crc));
}

Expand Down
16 changes: 9 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,20 @@ 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;
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 +567,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
75 changes: 68 additions & 7 deletions src/main/java/edu/harvard/iq/dataverse/util/json/JsonPrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import jakarta.ejb.Singleton;
import jakarta.json.JsonArray;
import jakarta.json.JsonObject;
import java.math.BigDecimal;

/**
* Convert objects to Json.
Expand Down Expand Up @@ -257,11 +258,11 @@ public static JsonObjectBuilder json(Workflow wf){
}

public static JsonObjectBuilder json(Dataverse dv) {
return json(dv, false);
return json(dv, false, false);
}

//TODO: Once we upgrade to Java EE 8 we can remove objects from the builder, and this email removal can be done in a better place.
public static JsonObjectBuilder json(Dataverse dv, Boolean hideEmail) {
public static JsonObjectBuilder json(Dataverse dv, Boolean hideEmail, Boolean includeOwners) {
JsonObjectBuilder bld = jsonObjectBuilder()
.add("id", dv.getId())
.add("alias", dv.getAlias())
Expand All @@ -270,7 +271,9 @@ public static JsonObjectBuilder json(Dataverse dv, Boolean hideEmail) {
if(!hideEmail) {
bld.add("dataverseContacts", JsonPrinter.json(dv.getDataverseContacts()));
}

if (includeOwners){
bld.add("ownerArray", getOwnersFromDvObject(dv));
}
bld.add("permissionRoot", dv.isPermissionRoot())
.add("description", dv.getDescription())
.add("dataverseType", dv.getDataverseType().name());
Expand Down Expand Up @@ -303,6 +306,46 @@ public static JsonArrayBuilder json(List<DataverseContact> dataverseContacts) {
}
return jsonArrayOfContacts;
}

public static JsonArrayBuilder getOwnersFromDvObject(DvObject dvObject) {

List <DvObject> ownerList = new ArrayList();
MellyGray marked this conversation as resolved.
Show resolved Hide resolved
dvObject = dvObject.getOwner(); // We're going to ignore the object itself
while (dvObject != null) {
ownerList.add(dvObject);
dvObject = dvObject.getOwner();
}

JsonArrayBuilder jsonArrayOfOwners = Json.createArrayBuilder();

for (DvObject dvo : ownerList){
JsonObjectBuilder ownerObject = jsonObjectBuilder();
if (dvo.isInstanceofDataverse()){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would extract the type check to a separate method to improve readability, and try to use a switch statement instead of these ifs. As far as I know a dvObject can't be of more than one type, and by having these ifs without else ifs it seems that a dvObject can have multiple types which is confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I simplified it here because since we're ignoring the object itself we can only have a Dataverse or a Dataset

ownerObject.add("type", "DATAVERSE");
}
if (dvo.isInstanceofDataset()){
ownerObject.add("type", "DATASET");
}
if (dvo.isInstanceofDataFile()){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an indentation issue in this line

ownerObject.add("type", "DATAFILE");
}
if (dvo.isInstanceofDataverse()){
Dataverse in = (Dataverse) dvo;
ownerObject.add("identifier", in.getAlias());
Copy link

@MellyGray MellyGray Feb 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be beneficial to include the version as well to the ownerObject, because for a file, its owner might be the dataset doi:10.5072/FK2/WTBMGC with version=2.0, but its owner is not the same dataset at an earlier version such as 1.0, because the file was added in a later version. I hope I'm making myself clear

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the logic for including a version number, but since we're omitting the base object from the isPartOf it can only apply to Files, however there's no endpoint for getting a file by its version like there is for dataset - the current result is that if I use the getFileData (@path("{id}")) it gets me the latest available version

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MellyGray @GPortas I think I need #10280 to be completed before I can finish this the way it needs to be finished.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sekmiller , I was testing the last changes. identifier includes both the identifier and the version, this can complicate parsing and utilizing these distinct pieces of information separately. I suggest separating the version information from the DOI identifier

{
  "type": DvObjectType.DATASET,
  "identifier": "doi:10.5072/FK2/HEGZLV",
  "version": "DRAFT",  // New dedicated property for version information
  "displayName": "First Dataset",
  "isPartOf": {
    "type": DvObjectType.DATAVERSE,
    "identifier": "root",
    "displayName": "Root"
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I can do that. The reason I had put them together is that the url for the dataset page currently looks like this: http://localhost:8080/dataset.xhtml?persistentId=doi:10.5072/FK2/UE0DKV&version=2.0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, @sekmiller! I see where you're coming from, but we're aiming to follow an API-first approach to decouple the API implementation from the UI use cases, ensuring our API remains flexible for various applications. We don't know who is going to consume this endpoint, so we should keep these two pieces of information separate to allow them to be used independently. Thanks for implementing the suggestion

}
if (dvo.isInstanceofDataset() || dvo.isInstanceofDataFile() ){
if (dvo.getIdentifier() != null){
Dataset ds = (Dataset) dvo;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can get here if dvo is a DataFile and it has a global ID right? so the cast might fail. I don't think it is needed though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the logic so that it doesn't need to cast or decide whether there's a dataset or datafile - basically for the purposes of "isPartOf" we're ignoring the object itself so we're never dealing with files.

ownerObject.add("identifier", ds.getGlobalId().asString());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be confusing and lead to casting / response parsing errors on the API consumer side that the value of "identifier" can be the numeric id or the persistent id. I think it would be better to add different fields to avoid confusion: "identifier" and "persistentIdentifier" or similar, being the second one present only if it exists.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GPortas I was just trying to keep it consistent across types - like I use identifier for Dataverses even though it's really 'alias' - so if there's no global/persistent id should I call it 'id' as in table id?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed I will add persistentIdentifier to the dataset object. For collections I will assign 'alias' to identifier and for datasets I will assign the table id to 'identifier'

} else {
ownerObject.add("identifier", dvo.getId());
}
}
ownerObject.add("displayName", dvo.getDisplayName());
jsonArrayOfOwners.add(ownerObject);
}
return jsonArrayOfOwners;
}

public static JsonObjectBuilder json( DataverseTheme theme ) {
final NullSafeJsonBuilder baseObject = jsonObjectBuilder()
Expand All @@ -326,8 +369,12 @@ public static JsonObjectBuilder json(BuiltinUser user) {
.add("id", user.getId())
.add("userName", user.getUserName());
}

public static JsonObjectBuilder json(Dataset ds){
return json(ds, false);
}

public static JsonObjectBuilder json(Dataset ds) {
public static JsonObjectBuilder json(Dataset ds, Boolean includeOwners) {
JsonObjectBuilder bld = jsonObjectBuilder()
.add("id", ds.getId())
.add("identifier", ds.getIdentifier())
Expand All @@ -340,6 +387,9 @@ public static JsonObjectBuilder json(Dataset ds) {
if (DvObjectContainer.isMetadataLanguageSet(ds.getMetadataLanguage())) {
bld.add("metadataLanguage", ds.getMetadataLanguage());
}
if (includeOwners){
bld.add("ownerArray", getOwnersFromDvObject(ds));
}
return bld;
}

Expand Down Expand Up @@ -592,8 +642,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 @@ -608,7 +662,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 @@ -627,7 +681,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 @@ -703,6 +761,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
41 changes: 41 additions & 0 deletions src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -1887,6 +1887,47 @@ public void testDeleteDatasetWhileFileIngesting() {
.statusCode(FORBIDDEN.getStatusCode());

}

@Test
public void testGetIncludeOwnerArray() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public void testGetIncludeOwnerArray() {
public void testGetDatasetOwners() {

Just to be consistent with the other test method names.


Response createUser = UtilIT.createRandomUser();
createUser.then().assertThat()
.statusCode(OK.getStatusCode());
String username = UtilIT.getUsernameFromResponse(createUser);
String apiToken = UtilIT.getApiTokenFromResponse(createUser);

Response createDataverseResponse = UtilIT.createRandomDataverse(apiToken);
createDataverseResponse.prettyPrint();
createDataverseResponse.then().assertThat()
.statusCode(CREATED.getStatusCode());
String dataverseAlias = UtilIT.getAliasFromResponse(createDataverseResponse);

Response createDatasetResponse = UtilIT.createRandomDatasetViaNativeApi(dataverseAlias, apiToken);
createDatasetResponse.prettyPrint();
createDatasetResponse.then().assertThat()
.statusCode(CREATED.getStatusCode());
Integer datasetId = JsonPath.from(createDatasetResponse.body().asString()).getInt("data.id");
String persistentId = JsonPath.from(createDatasetResponse.body().asString()).getString("data.persistentId");
logger.info("Dataset created with id " + datasetId + " and persistent id " + persistentId);

Response getDatasetWithOwners = UtilIT.getDatasetWithOwners(persistentId, apiToken, true);
getDatasetWithOwners.prettyPrint();
getDatasetWithOwners.then().assertThat().body("data.ownerArray[0].identifier", equalTo(dataverseAlias));

Response destroyDatasetResponse = UtilIT.destroyDataset(datasetId, apiToken);
assertEquals(200, destroyDatasetResponse.getStatusCode());

Response deleteDataverseResponse = UtilIT.deleteDataverse(dataverseAlias, apiToken);
assertEquals(200, deleteDataverseResponse.getStatusCode());

Response deleteUserResponse = UtilIT.deleteUser(username);
assertEquals(200, deleteUserResponse.getStatusCode());

}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not critical but I would avoid adding more blank spaces than necessary.




/**
* In order for this test to pass you must have the Data Capture Module (
Expand Down
28 changes: 28 additions & 0 deletions src/test/java/edu/harvard/iq/dataverse/api/DataversesIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,34 @@ public void testMinimalDataverse() throws FileNotFoundException {
deleteDataverse.prettyPrint();
deleteDataverse.then().assertThat().statusCode(OK.getStatusCode());
}


@Test
public void testGetDataverseOwners() throws FileNotFoundException {
Response createUser = UtilIT.createRandomUser();
createUser.prettyPrint();
String username = UtilIT.getUsernameFromResponse(createUser);
String apiToken = UtilIT.getApiTokenFromResponse(createUser);
Response createDataverse1Response = UtilIT.createRandomDataverse(apiToken);

createDataverse1Response.prettyPrint();
createDataverse1Response.then().assertThat().statusCode(CREATED.getStatusCode());

String first = UtilIT.getAliasFromResponse(createDataverse1Response);

Response getWithOwnersFirst = UtilIT.getDataverseWithOwners(first, apiToken, true);
getWithOwnersFirst.prettyPrint();

Response createLevel1a = UtilIT.createSubDataverse(UtilIT.getRandomDvAlias() + "-level1a", null, apiToken, first);
createLevel1a.prettyPrint();
String level1a = UtilIT.getAliasFromResponse(createLevel1a);

Response getWithOwners = UtilIT.getDataverseWithOwners(level1a, apiToken, true);
getWithOwners.prettyPrint();

getWithOwners.then().assertThat().body("data.ownerArray[0].identifier", equalTo(first));

}

/**
* A regular user can create a Dataverse Collection and access its
Expand Down
69 changes: 69 additions & 0 deletions src/test/java/edu/harvard/iq/dataverse/api/FilesIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,75 @@ public void testGetFileInfo() {
assertEquals(200, deleteUserResponse.getStatusCode());
}

@Test
public void testGetFileOwners() {
Response createUser = UtilIT.createRandomUser();
String username = UtilIT.getUsernameFromResponse(createUser);
String apiToken = UtilIT.getApiTokenFromResponse(createUser);
Response makeSuperUser = UtilIT.makeSuperUser(username);
String dataverseAlias = createDataverseGetAlias(apiToken);


Response createDatasetResponse = UtilIT.createRandomDatasetViaNativeApi(dataverseAlias, apiToken);
createDatasetResponse.prettyPrint();
Integer datasetId = JsonPath.from(createDatasetResponse.body().asString()).getInt("data.id");

String datasetPid = UtilIT.getDatasetPersistentIdFromResponse(createDatasetResponse);

createUser = UtilIT.createRandomUser();
String apiTokenRegular = UtilIT.getApiTokenFromResponse(createUser);

msg("Add a non-tabular file");
String pathToFile = "scripts/search/data/binary/trees.png";
Response addResponse = UtilIT.uploadFileViaNative(datasetId.toString(), pathToFile, apiToken);

String dataFileId = addResponse.getBody().jsonPath().getString("data.files[0].dataFile.id");
msgt("datafile id: " + dataFileId);

addResponse.prettyPrint();

Response getFileDataResponse = UtilIT.getFileWithOwners(dataFileId, apiToken, true);

getFileDataResponse.prettyPrint();
getFileDataResponse.then().assertThat()
.body("data.label", equalTo("trees.png"))
.body("data.dataFile.filename", equalTo("trees.png"))
.body("data.dataFile.contentType", equalTo("image/png"))
.body("data.dataFile.filesize", equalTo(8361))
.statusCode(OK.getStatusCode());

getFileDataResponse.then().assertThat().body("data.dataFile.ownerArray[0].identifier", equalTo(datasetPid));

// -------------------------
// Publish dataverse and dataset
// -------------------------
msg("Publish dataverse and dataset");
Response publishDataversetResp = UtilIT.publishDataverseViaSword(dataverseAlias, apiToken);
publishDataversetResp.then().assertThat()
.statusCode(OK.getStatusCode());

Response publishDatasetResp = UtilIT.publishDatasetViaNativeApi(datasetId, "major", apiToken);
publishDatasetResp.then().assertThat()
.statusCode(OK.getStatusCode());
//regular user should get to see file data
getFileDataResponse = UtilIT.getFileData(dataFileId, apiTokenRegular);
getFileDataResponse.then().assertThat()
.statusCode(OK.getStatusCode());

//cleanup

Response destroyDatasetResponse = UtilIT.destroyDataset(datasetId, apiToken);
assertEquals(200, destroyDatasetResponse.getStatusCode());

Response deleteDataverseResponse = UtilIT.deleteDataverse(dataverseAlias, apiToken);
assertEquals(200, deleteDataverseResponse.getStatusCode());

Response deleteUserResponse = UtilIT.deleteUser(username);
assertEquals(200, deleteUserResponse.getStatusCode());


}

@Test
public void testValidateDDI_issue6027() throws InterruptedException {
msgt("testValidateDDI_issue6027");
Expand Down
Loading
Loading