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

Add displayOrder, typeClass and isRequired fields to DatasetFieldType payload #10225

Merged
merged 5 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions doc/release-notes/10216-metadatablocks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
The API endpoint `/api/metadatablocks/{block_id}` has been extended to include the following fields:

- `isRequired` - Whether or not this field is required
- `displayOrder`: The display order of the field in create/edit forms
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,8 @@ public static JsonObjectBuilder json(DatasetFieldType fld) {
fieldsBld.add("multiple", fld.isAllowMultiples());
fieldsBld.add("isControlledVocabulary", fld.isControlledVocabulary());
fieldsBld.add("displayFormat", fld.getDisplayFormat());
fieldsBld.add("isRequired", fld.isRequired());
fieldsBld.add("displayOrder", fld.getDisplayOrder());
if (fld.isControlledVocabulary()) {
// If the field has a controlled vocabulary,
// add all values to the resulting JSON
Expand Down
10 changes: 6 additions & 4 deletions src/test/java/edu/harvard/iq/dataverse/api/MetadataBlocksIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ void testGetCitationBlock() {
getCitationBlock.prettyPrint();
getCitationBlock.then().assertThat()
.statusCode(OK.getStatusCode())
.body("data.fields.subject.controlledVocabularyValues[0]", CoreMatchers.is("Agricultural Sciences"));
.body("data.fields.subject.controlledVocabularyValues[0]", CoreMatchers.is("Agricultural Sciences"))
.body("data.fields.title.displayOrder", CoreMatchers.is(0))
.body("data.fields.title.isRequired", CoreMatchers.is(true));
}

@Test
Expand All @@ -37,18 +39,18 @@ void testDatasetWithAllDefaultMetadata() {
", response=" + createUser.prettyPrint());
String apiToken = UtilIT.getApiTokenFromResponse(createUser);
assumeFalse(apiToken == null || apiToken.isBlank());

Response createCollection = UtilIT.createRandomDataverse(apiToken);
assumeTrue(createCollection.statusCode() < 300,
"code=" + createCollection.statusCode() +
", response=" + createCollection.prettyPrint());
String dataverseAlias = UtilIT.getAliasFromResponse(createCollection);
assumeFalse(dataverseAlias == null || dataverseAlias.isBlank());

// when
String pathToJsonFile = "scripts/api/data/dataset-create-new-all-default-fields.json";
Response createDataset = UtilIT.createDatasetViaNativeApi(dataverseAlias, pathToJsonFile, apiToken);

// then
assertEquals(CREATED.getStatusCode(), createDataset.statusCode(),
"code=" + createDataset.statusCode() +
Expand Down
Loading