From 19e3e51d7a0b219460df02c0f6c6a20d59507a96 Mon Sep 17 00:00:00 2001 From: Philip Durbin Date: Tue, 13 Aug 2024 16:38:20 -0400 Subject: [PATCH] use proper JSON-LD for dataset type #10517 --- .../api/dataset-create-software.jsonld | 2 +- .../iq/dataverse/util/json/JSONLDUtil.java | 24 +++++-------------- .../iq/dataverse/util/json/JsonLDTerm.java | 2 ++ 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/doc/sphinx-guides/source/_static/api/dataset-create-software.jsonld b/doc/sphinx-guides/source/_static/api/dataset-create-software.jsonld index e5c93f58c03..6f072967dc8 100644 --- a/doc/sphinx-guides/source/_static/api/dataset-create-software.jsonld +++ b/doc/sphinx-guides/source/_static/api/dataset-create-software.jsonld @@ -12,5 +12,5 @@ "https://dataverse.org/schema/citation/dsDescription": { "https://dataverse.org/schema/citation/dsDescriptionValue": "Darwin's finches (also known as the Galápagos finches) are a group of about fifteen species of passerine birds." }, - "datasetType": "software" + "https://dataverse.org/schema/core#datasetType": "software" } diff --git a/src/main/java/edu/harvard/iq/dataverse/util/json/JSONLDUtil.java b/src/main/java/edu/harvard/iq/dataverse/util/json/JSONLDUtil.java index c1ec6f2f0ca..380cef6aa9d 100644 --- a/src/main/java/edu/harvard/iq/dataverse/util/json/JSONLDUtil.java +++ b/src/main/java/edu/harvard/iq/dataverse/util/json/JSONLDUtil.java @@ -98,26 +98,14 @@ public static Dataset updateDatasetMDFromJsonLD(Dataset ds, String jsonLDBody, //Store the metadatalanguage if sent - the caller needs to check whether it is allowed (as with any GlobalID) ds.setMetadataLanguage(jsonld.getString(JsonLDTerm.schemaOrg("inLanguage").getUrl(),null)); - try (StringReader rdr = new StringReader(jsonLDBody)) { - try (JsonReader jsonReader = Json.createReader(rdr)) { - JsonObject jsonObject = jsonReader.readObject(); - String datasetTypeIn = jsonObject.getString("datasetType", null); - logger.fine("datasetTypeIn: " + datasetTypeIn); - DatasetType defaultDatasetType = datasetTypeSvc.getByName(DatasetType.DEFAULT_DATASET_TYPE); - if (datasetTypeIn == null) { - ds.setDatasetType(defaultDatasetType); - } else { - DatasetType datasetType = datasetTypeSvc.getByName(datasetTypeIn); - if (datasetType != null) { - ds.setDatasetType(datasetType); - } else { - throw new BadRequestException("Invalid dataset type: " + datasetTypeIn); - } - } - } + String datasetTypeIn = jsonld.getString(JsonLDTerm.datasetType.getUrl(), DatasetType.DEFAULT_DATASET_TYPE); + DatasetType datasetType = datasetTypeSvc.getByName(datasetTypeIn); + if (datasetType != null) { + ds.setDatasetType(datasetType); + } else { + throw new BadRequestException("Invalid dataset type: " + datasetTypeIn); } - dsv = updateDatasetVersionMDFromJsonLD(dsv, jsonld, metadataBlockSvc, datasetFieldSvc, append, migrating, licenseSvc); dsv.setDataset(ds); diff --git a/src/main/java/edu/harvard/iq/dataverse/util/json/JsonLDTerm.java b/src/main/java/edu/harvard/iq/dataverse/util/json/JsonLDTerm.java index 3193f762538..3166fa9dbfa 100644 --- a/src/main/java/edu/harvard/iq/dataverse/util/json/JsonLDTerm.java +++ b/src/main/java/edu/harvard/iq/dataverse/util/json/JsonLDTerm.java @@ -52,6 +52,8 @@ public class JsonLDTerm { public static JsonLDTerm fileCount = JsonLDTerm.DVCore("fileCount"); public static JsonLDTerm maxFileSize = JsonLDTerm.DVCore("maxFileSize"); + public static JsonLDTerm datasetType = JsonLDTerm.DVCore("datasetType"); + public JsonLDTerm(JsonLDNamespace namespace, String term) { this.namespace = namespace; this.term = term;