Skip to content

Commit

Permalink
Merge pull request #10985 from IQSS/10984-returnDatasetFieldTypes
Browse files Browse the repository at this point in the history
Fix bug related to returnDatasetFieldTypes in Dataverses.listMetadataBlocks endpoint
  • Loading branch information
ofahimIQSS authored Nov 4, 2024
2 parents bf47f6b + f317ab0 commit 80a9312
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,10 @@ public List<DatasetFieldType> findAllDisplayedOnCreateInMetadataBlock(MetadataBl
}

public List<DatasetFieldType> findAllInMetadataBlockAndDataverse(MetadataBlock metadataBlock, Dataverse dataverse, boolean onlyDisplayedOnCreate) {
if (!dataverse.isMetadataBlockRoot() && dataverse.getOwner() != null) {
return findAllInMetadataBlockAndDataverse(metadataBlock, dataverse.getOwner(), onlyDisplayedOnCreate);
}

CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
CriteriaQuery<DatasetFieldType> criteriaQuery = criteriaBuilder.createQuery(DatasetFieldType.class);

Expand Down
11 changes: 11 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 @@ -916,6 +916,17 @@ public void testListMetadataBlocks() {
createDataverseResponse.then().assertThat().statusCode(CREATED.getStatusCode());
String dataverseAlias = UtilIT.getAliasFromResponse(createDataverseResponse);

// New Dataverse should return just the citation block and its displayOnCreate fields when onlyDisplayedOnCreate=true and returnDatasetFieldTypes=true
Response listMetadataBlocks = UtilIT.listMetadataBlocks(dataverseAlias, true, true, apiToken);
listMetadataBlocks.prettyPrint();
listMetadataBlocks.then().assertThat().statusCode(OK.getStatusCode());
listMetadataBlocks.then().assertThat()
.statusCode(OK.getStatusCode())
.body("data.size()", equalTo(1))
.body("data[0].name", is("citation"))
.body("data[0].fields.title.displayOnCreate", equalTo(true))
.body("data[0].fields.size()", is(28));

Response setMetadataBlocksResponse = UtilIT.setMetadataBlocks(dataverseAlias, Json.createArrayBuilder().add("citation").add("astrophysics"), apiToken);
setMetadataBlocksResponse.then().assertThat().statusCode(OK.getStatusCode());

Expand Down

0 comments on commit 80a9312

Please sign in to comment.