Skip to content

Commit

Permalink
Merge pull request #10225 from IQSS/10216-metadatablocks-payload-exte…
Browse files Browse the repository at this point in the history
…nsion

Add displayOrder, typeClass and isRequired fields to DatasetFieldType payload
  • Loading branch information
stevenwinship authored Jan 22, 2024
2 parents 1122462 + 0f4a455 commit e8af210
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions doc/release-notes/10216-metadatablocks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
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
- `typeClass`: The type class of this field ("controlledVocabulary", "compound", or "primitive")
Original file line number Diff line number Diff line change
Expand Up @@ -565,11 +565,14 @@ public static JsonObjectBuilder json(DatasetFieldType fld) {
fieldsBld.add("displayName", fld.getDisplayName());
fieldsBld.add("title", fld.getTitle());
fieldsBld.add("type", fld.getFieldType().toString());
fieldsBld.add("typeClass", typeClassString(fld));
fieldsBld.add("watermark", fld.getWatermark());
fieldsBld.add("description", fld.getDescription());
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
11 changes: 7 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,10 @@ 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.typeClass", CoreMatchers.is("primitive"))
.body("data.fields.title.isRequired", CoreMatchers.is(true));
}

@Test
Expand All @@ -37,18 +40,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

0 comments on commit e8af210

Please sign in to comment.