Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Added the ability to set and view the guestbookRoot setting of a collection via these APIs

Any GET call that returns a Collection or List of Collections will include "guestbookRoot": true or false
`Create Dataverse: POST /api/dataverse/{id}`
`Update Dataverse: PUT /api/dataverse/{id}`
(by adding "guestbookRoot" the Json body)
4 changes: 3 additions & 1 deletion doc/sphinx-guides/source/_static/api/dataverse-complete.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
],
"affiliation": "Scientific Research University",
"description": "We do all the science.",
"dataverseType": "LABORATORY"
"dataverseType": "LABORATORY",
"datasetFileCountLimit": 10,
"guestbookRoot": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class DataverseDTO {
private List<DataverseContact> dataverseContacts;
private Dataverse.DataverseType dataverseType;
private Integer datasetFileCountLimit;
private Boolean guestbookRoot;

public String getAlias() {
return alias;
Expand Down Expand Up @@ -69,4 +70,12 @@ public Dataverse.DataverseType getDataverseType() {
public void setDataverseType(Dataverse.DataverseType dataverseType) {
this.dataverseType = dataverseType;
}

public Boolean getGuestbookRoot() {
return guestbookRoot;
}

public void setGuestbookRoot(Boolean guestbookRoot) {
this.guestbookRoot = guestbookRoot;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ private void updateDataverseFromDTO(Dataverse dataverse, DataverseDTO dto) {
if (dto.getDatasetFileCountLimit() != null) {
dataverse.setDatasetFileCountLimit(dto.getDatasetFileCountLimit());
}
if (dto.getGuestbookRoot() != null) {
dataverse.setGuestbookRoot(dto.getGuestbookRoot());
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@
if (jobj.containsKey("requireFilesToPublishDataset")) {
dv.setRequireFilesToPublishDataset(jobj.getBoolean("requireFilesToPublishDataset"));
}
if (jobj.containsKey("guestbookRoot")) {

Check failure on line 147 in src/main/java/edu/harvard/iq/dataverse/util/json/JsonParser.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "guestbookRoot" 4 times.

See more on https://sonarcloud.io/project/issues?id=IQSS_dataverse&issues=AZ_8fBX1fHkNYAeYVm_0&open=AZ_8fBX1fHkNYAeYVm_0&pullRequest=12611
dv.setGuestbookRoot(jobj.getBoolean("guestbookRoot"));
}

/* We decided that subject is not user set, but gotten from the subject of the dataverse's
datasets - leavig this code in for now, in case we need to go back to it at some point
Expand Down Expand Up @@ -205,6 +208,9 @@
if (jsonObject.containsKey("datasetFileCountLimit")) {
dataverseDTO.setDatasetFileCountLimit(Integer.valueOf(jsonObject.getInt("datasetFileCountLimit")));
}
if (jsonObject.containsKey("guestbookRoot")) {
dataverseDTO.setGuestbookRoot(jsonObject.getBoolean("guestbookRoot"));
}

return dataverseDTO;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ public static JsonObjectBuilder json(Dataverse dv, Boolean hideEmail, Boolean re
if (dv.getFilePIDsEnabled() != null) {
bld.add("filePIDsEnabled", dv.getFilePIDsEnabled());
}
bld.add("guestbookRoot", dv.isGuestbookRoot());
bld.add("effectiveRequiresFilesToPublishDataset", dv.getEffectiveRequiresFilesToPublishDataset());
bld.add("isReleased", dv.isReleased());

Expand Down
12 changes: 7 additions & 5 deletions src/test/java/edu/harvard/iq/dataverse/api/DataversesIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -1766,7 +1766,7 @@ public void testUpdateDataverse() throws JsonParseException {
updateDataverseResponse = UtilIT.updateDataverse(
testDataverseAlias, newAlias, newName, newAffiliation, newDataverseType, newContactEmails, newInputLevelNames,
null, newMetadataBlockNames, apiToken,
Boolean.TRUE, Boolean.TRUE, null
Boolean.TRUE, Boolean.TRUE, null, null
);
updateDataverseResponse.then().assertThat()
.statusCode(BAD_REQUEST.getStatusCode())
Expand All @@ -1776,7 +1776,7 @@ public void testUpdateDataverse() throws JsonParseException {
updateDataverseResponse = UtilIT.updateDataverse(
testDataverseAlias, newAlias, newName, newAffiliation, newDataverseType, newContactEmails, newInputLevelNames,
newFacetIds, null, apiToken,
Boolean.TRUE, Boolean.TRUE, null
Boolean.TRUE, Boolean.TRUE, null, null
);
updateDataverseResponse.then().assertThat()
.statusCode(BAD_REQUEST.getStatusCode())
Expand Down Expand Up @@ -1877,6 +1877,7 @@ public void testUpdateDataverse() throws JsonParseException {

// Update the dataverse without setting metadata blocks, facets, or input levels
// Do NOT ignore the missing data so the metadata blocks, facets, and input levels are deleted and inherited from the parent
// Also testing Guestbook Root
updateDataverseResponse = UtilIT.updateDataverse(
newAlias,
newAlias,
Expand All @@ -1888,9 +1889,10 @@ public void testUpdateDataverse() throws JsonParseException {
null,
null,
apiToken,
Boolean.TRUE, Boolean.TRUE, null
Boolean.TRUE, Boolean.TRUE, null, Boolean.TRUE
);
updateDataverseResponse.then().assertThat().statusCode(OK.getStatusCode());
updateDataverseResponse.then().assertThat().body("data.guestbookRoot", equalTo(true));

// Assert that the metadata blocks are inherited from the parent
listMetadataBlocksResponse = UtilIT.listMetadataBlocks(newAlias, false, false, apiToken);
Expand Down Expand Up @@ -2713,7 +2715,7 @@ public void testCreateAndGetTemplates() throws JsonParseException {
dataverseAlias, dataverseAlias, newName, newAffiliation, newDataverseType, newContactEmails,
newInputLevelNames,
null, newMetadataBlockNames, apiToken,
Boolean.FALSE, Boolean.FALSE, null);
Boolean.FALSE, Boolean.FALSE, null, null);

updateDataverseResponse.then().assertThat()
.statusCode(OK.getStatusCode());
Expand Down Expand Up @@ -2942,7 +2944,7 @@ public void testUpdateTemplates() throws JsonParseException {
dataverseAlias, dataverseAlias, newName, newAffiliation, newDataverseType, newContactEmails,
newInputLevelNames,
null, newMetadataBlockNames, apiToken,
Boolean.FALSE, Boolean.FALSE, null);
Boolean.FALSE, Boolean.FALSE, null, null);

updateDataverseResponse.then().assertThat()
.statusCode(OK.getStatusCode());
Expand Down
11 changes: 8 additions & 3 deletions src/test/java/edu/harvard/iq/dataverse/api/UtilIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ static Response updateDataverse(String alias,
String apiToken) {

return updateDataverse(alias, newAlias, newName, newAffiliation, newDataverseType, newContactEmails,
newInputLevelNames, newFacetIds, newMetadataBlockNames, apiToken, null, null, null);
newInputLevelNames, newFacetIds, newMetadataBlockNames, apiToken, null, null, null, null);
}

static Response updateDataverse(String alias,
Expand All @@ -465,7 +465,8 @@ static Response updateDataverse(String alias,
String apiToken,
Boolean inheritMetadataBlocksFromParent,
Boolean inheritFacetsFromParent,
Integer datasetFileCountLimit) {
Integer datasetFileCountLimit,
Boolean guestbookRoot) {
JsonArrayBuilder contactArrayBuilder = JsonUtil.createArrayBuilder();
for(String contactEmail : newContactEmails) {
contactArrayBuilder.add(JsonUtil.createObjectBuilder().add("contactEmail", contactEmail));
Expand All @@ -481,6 +482,9 @@ static Response updateDataverse(String alias,
if (datasetFileCountLimit != null) {
jsonBuilder.add("datasetFileCountLimit", datasetFileCountLimit);
}
if (guestbookRoot != null) {
jsonBuilder.add("guestbookRoot", guestbookRoot);
}

updateDataverseRequestJsonWithMetadataBlocksConfiguration(newInputLevelNames, newFacetIds, newMetadataBlockNames,
inheritMetadataBlocksFromParent, inheritFacetsFromParent, jsonBuilder);
Expand All @@ -505,7 +509,8 @@ static Response updateDataverse(String alias, Dataverse dv, String apiToken) {
apiToken,
null,
null,
dv.isDatasetFileCountLimitSet(dv.getDatasetFileCountLimit()) ? dv.getDatasetFileCountLimit() : -1);
dv.isDatasetFileCountLimitSet(dv.getDatasetFileCountLimit()) ? dv.getDatasetFileCountLimit() : -1,
null);
}

private static void updateDataverseRequestJsonWithMetadataBlocksConfiguration(String[] inputLevelNames,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package edu.harvard.iq.dataverse.api.dto;

import edu.harvard.iq.dataverse.Dataverse;
import edu.harvard.iq.dataverse.DataverseContact;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class DataverseDTOTest {

Check warning on line 12 in src/test/java/edu/harvard/iq/dataverse/api/dto/DataverseDTOTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove redundant visibility modifiers from this test class and its methods.

See more on https://sonarcloud.io/project/issues?id=IQSS_dataverse&issues=AZ_8tb9qfWOu3SFpBbgZ&open=AZ_8tb9qfWOu3SFpBbgZ&pullRequest=12611

@Test
public void testDataverseDTO() {
DataverseDTO dv = new DataverseDTO();
List<DataverseContact> dataverseContacts = new ArrayList<>();
dataverseContacts.add(new DataverseContact());
dataverseContacts.add(new DataverseContact());
dv.setGuestbookRoot(Boolean.FALSE);
dv.setAffiliation("affiliation");
dv.setDataverseType(Dataverse.DataverseType.JOURNALS);
dv.setDataverseContacts(dataverseContacts);
dv.setDescription("description");
dv.setName("name");
dv.setAlias("alias");
dv.setDatasetFileCountLimit(Integer.MAX_VALUE);

assertEquals(Boolean.FALSE, dv.getGuestbookRoot());
assertEquals("affiliation", dv.getAffiliation());
assertEquals("description", dv.getDescription());
assertEquals("name", dv.getName());
assertEquals("alias", dv.getAlias());
assertEquals(Integer.MAX_VALUE, dv.getDatasetFileCountLimit());
assertEquals(2,dv.getDataverseContacts().size());
}
}
Loading