Skip to content

Commit

Permalink
use proper JSON-LD for dataset type #10517
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed Aug 13, 2024
1 parent 1a834de commit 19e3e51
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
24 changes: 6 additions & 18 deletions src/main/java/edu/harvard/iq/dataverse/util/json/JSONLDUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 19e3e51

Please sign in to comment.