Skip to content

Instantly share code, notes, and snippets.

@raprasad
Last active April 6, 2016 21:17
Show Gist options
  • Save raprasad/fbea82705b999b7a6328254cb31de9cf to your computer and use it in GitHub Desktop.
Save raprasad/fbea82705b999b7a6328254cb31de9cf to your computer and use it in GitHub Desktop.
Metadata Updates in Dataverse

Purpose

In preparing to add File Level metadata to Dataverse these are notes on several places where experience has shown that the API could be improved.

Adding an Email value to a Dataset's Metadata

Expected code (java)

newDatasetVersion.addEmailContact("[email protected]");

Current code (Dataverse)

  • high barrier of entry to collaborators
  • time-consuming
  • hard to maintain
 DatasetFieldType emailDatasetFieldType = datasetFieldService.findByNameOpt(DatasetFieldConstant.datasetContact);
    DatasetField emailDatasetField = DatasetField.createNewEmptyDatasetField(emailDatasetFieldType, datasetVersion);
    for (DatasetField childField : emailDatasetField.getDatasetFieldCompoundValues().get(0).getChildDatasetFields()) {
        if (DatasetFieldConstant.datasetContactEmail.equals(childField.getDatasetFieldType().getName())) {
            childField.getSingleValue().setValue(user.getDisplayInfo().getEmailAddress());
        }
    }
    datasetVersion.getDatasetFields().add(emailDatasetField);

Current Native API: Adding JSON via Dataverse

This example shows the JSON required for adding two authors and their affilations

Expected JSON (not Dataverse)

{
"author": [
    {
      "authorName": "Smith, Robert",
      "authorAffiliation": "The Smiths",
    },
    {
      "authorName": "Kew, Susie",
      "authorAffiliation": "Creedence Clearwater Revival",
    }
  ]
 }

This is the JSON expected by Dataverse

This is what the JSON looks like for adding two authors and their affiliations.

No one uses this because of the complexity

  • Note: This was written as a favor to the Dataverse team to help them save test data when the DB was dropped
{
            "typeName": "author",
            "multiple": true,
            "typeClass": "compound",
            "value": [
              {
                "authorName": {
                  "typeName": "authorName",
                  "multiple": false,
                  "typeClass": "primitive",
                  "value": "Smith, Robert"
                },
                "authorAffiliation": {
                  "typeName": "authorAffiliation",
                  "multiple": false,
                  "typeClass": "primitive",
                  "value": "The Smiths"
                }
              },
              {
                "authorName": {
                  "typeName": "authorName",
                  "multiple": false,
                  "typeClass": "primitive",
                  "value": "Kew, Susie"
                },
                "authorAffiliation": {
                  "typeName": "authorAffiliation",
                  "multiple": false,
                  "typeClass": "primitive",
                  "value": "Creedence Clearwater Revival"
                }
              }]

References:

Native API: JSON output

Java code to create JSON output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment