Skip to content

Commit 19e3e51

Browse files
committed
use proper JSON-LD for dataset type #10517
1 parent 1a834de commit 19e3e51

File tree

3 files changed

+9
-19
lines changed

3 files changed

+9
-19
lines changed

doc/sphinx-guides/source/_static/api/dataset-create-software.jsonld

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
"https://dataverse.org/schema/citation/dsDescription": {
1313
"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."
1414
},
15-
"datasetType": "software"
15+
"https://dataverse.org/schema/core#datasetType": "software"
1616
}

src/main/java/edu/harvard/iq/dataverse/util/json/JSONLDUtil.java

+6-18
Original file line numberDiff line numberDiff line change
@@ -98,26 +98,14 @@ public static Dataset updateDatasetMDFromJsonLD(Dataset ds, String jsonLDBody,
9898
//Store the metadatalanguage if sent - the caller needs to check whether it is allowed (as with any GlobalID)
9999
ds.setMetadataLanguage(jsonld.getString(JsonLDTerm.schemaOrg("inLanguage").getUrl(),null));
100100

101-
try (StringReader rdr = new StringReader(jsonLDBody)) {
102-
try (JsonReader jsonReader = Json.createReader(rdr)) {
103-
JsonObject jsonObject = jsonReader.readObject();
104-
String datasetTypeIn = jsonObject.getString("datasetType", null);
105-
logger.fine("datasetTypeIn: " + datasetTypeIn);
106-
DatasetType defaultDatasetType = datasetTypeSvc.getByName(DatasetType.DEFAULT_DATASET_TYPE);
107-
if (datasetTypeIn == null) {
108-
ds.setDatasetType(defaultDatasetType);
109-
} else {
110-
DatasetType datasetType = datasetTypeSvc.getByName(datasetTypeIn);
111-
if (datasetType != null) {
112-
ds.setDatasetType(datasetType);
113-
} else {
114-
throw new BadRequestException("Invalid dataset type: " + datasetTypeIn);
115-
}
116-
}
117-
}
101+
String datasetTypeIn = jsonld.getString(JsonLDTerm.datasetType.getUrl(), DatasetType.DEFAULT_DATASET_TYPE);
102+
DatasetType datasetType = datasetTypeSvc.getByName(datasetTypeIn);
103+
if (datasetType != null) {
104+
ds.setDatasetType(datasetType);
105+
} else {
106+
throw new BadRequestException("Invalid dataset type: " + datasetTypeIn);
118107
}
119108

120-
121109
dsv = updateDatasetVersionMDFromJsonLD(dsv, jsonld, metadataBlockSvc, datasetFieldSvc, append, migrating, licenseSvc);
122110
dsv.setDataset(ds);
123111

src/main/java/edu/harvard/iq/dataverse/util/json/JsonLDTerm.java

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public class JsonLDTerm {
5252
public static JsonLDTerm fileCount = JsonLDTerm.DVCore("fileCount");
5353
public static JsonLDTerm maxFileSize = JsonLDTerm.DVCore("maxFileSize");
5454

55+
public static JsonLDTerm datasetType = JsonLDTerm.DVCore("datasetType");
56+
5557
public JsonLDTerm(JsonLDNamespace namespace, String term) {
5658
this.namespace = namespace;
5759
this.term = term;

0 commit comments

Comments
 (0)