Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose export formats in native API #10739

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

julian-schneider
Copy link

What this PR does / why we need it: The PR adds a method that exposes the full list of available exporters (display- and format names). This is especially useful for instances that have added custom formats.

Which issue(s) this PR closes: I know no pre-existing issues for this.

Suggestions on how to test this: New method found here: /api/info/exportFormats

Does this PR introduce a user interface change? If mockups are available, please link/include them here: No, just API and documentation changes.

API answer looks like this:

{
  "status": "OK",
  "data": [
    {
      "displayName": "OAI_ORE",
      "formatName": "OAI_ORE"
    },
    {
      "displayName": "DataCite",
      "formatName": "Datacite"
    },
    {
      "displayName": "Dublin Core",
      "formatName": "oai_dc"
    },
    {
      "displayName": "OpenAIRE",
      "formatName": "oai_datacite"
    },
    {
      "displayName": "Schema.org JSON-LD",
      "formatName": "schema.org"
    },
    {
      "displayName": "DDI",
      "formatName": "ddi"
    },
    {
      "displayName": "Dublin Core",
      "formatName": "dcterms"
    },
    {
      "displayName": "DDI HTML Codebook",
      "formatName": "html"
    },
    {
      "displayName": "JSON",
      "formatName": "dataverse_json"
    },
    {
      "displayName": "DDI",
      "formatName": "oai_ddi"
    }
  ]
}

Rendered docs entry looks like this:
image

Is there a release notes update needed for this change?:
New API method for listing the available exporters. Found at /api/info/exportFormats, produces display names and format names.

@pdurbin pdurbin added Size: 3 A percentage of a sprint. 2.1 hours. Type: Feature a feature request labels Aug 2, 2024
Copy link
Member

@pdurbin pdurbin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@julian-schneider good idea! Thanks for the pull request. I left you some comments.

@GET
@Path("exportFormats")
public Response getExportFormats() {
JsonArrayBuilder responseModel = Json.createArrayBuilder();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you consider returning an object instead? Just this week I pushed a commit to return MPCONFIG options via API and I played with returning an array but ended up liking object better. Here's the code: 771d85a

I'm suggesting something like this:

{
  "status": "OK",
  "data": {
    "OAI_ORE": {
      "displayName": "OAI_ORE"
    },
    "oai_dc": {
      "displayName": "Dublin Core"
    }
  }
}

Alternatively, perhaps you could add a second endpoint for getting info about a single export format (e.g. /api/info/exportFormats/oai_dc). That way you can easily get info on that format instead of having to search through an array to find the element that matches oai_dc.

Just some thoughts! 😄 Maybe the array is actually better.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah an object is probably better, especially with the increased amount of properties, so I switched this in cc99729

@Path("exportFormats")
public Response getExportFormats() {
JsonArrayBuilder responseModel = Json.createArrayBuilder();
ExportService.getInstance().getExportersLabels().forEach(labels -> responseModel.add(Json.createObjectBuilder().add("displayName", labels[0]).add("formatName", labels[1])));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is displayName and formatName enough? While we're doing this, should we add isHarvestable, mediaType, and isAvailableToUsers (isVisibleInUserInterface might be better)?

For XML exporters there even these methods:

public String getXMLNameSpace();

public String getXMLSchemaLocation();

public String getXMLSchemaVersion();

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In cc99729 the additional properties you mentioned have been added, thanks for the recommendation!

@@ -4618,6 +4618,25 @@ The fully expanded example above (without environment variables) looks like this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs look great. Can you please add a release note snippet? Please see https://guides.dataverse.org/en/6.3/developers/version-control.html#writing-a-release-note-snippet

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has been added in 3f81981.

Get Export Formats
~~~~~~~~~~~~~~~~~~~~~~~~~~~

Get the available export formats. The response contains a list of objects each containing the display name and format name for an available exporter.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this include external exporters? I assume so. Can we please mention they are included as well?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know, all exporters, standard and custom, are managed by the ExportService, and are consequently all listed. I improved the docs in 3b2c8e5.

ExportService.getInstance().getExportersLabels().forEach(labels -> responseModel.add(Json.createObjectBuilder().add("displayName", labels[0]).add("formatName", labels[1])));
return ok(responseModel);
}

private Response getSettingResponseByKey(SettingsServiceBean.Key key) {
String setting = settingsService.getValueForKey(key);
if (setting != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll just put this comment at the bottom. An API test would be nice. I can help you get started if you need it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A basic API test has been added in 95d34c8, which compares the response to what should be expected from a Dataverse installation with the default set of exporters. Is this what you had in mind?

@julian-schneider
Copy link
Author

Thanks for your feedback @pdurbin - I will be absent for two weeks, so some time will pass before I revise this. See you then!

@julian-schneider
Copy link
Author

The response is now an object, and contains more properties per format, as suggested.

New response looks like this:

(expand response)
{
  "status": "OK",
  "data": {
    "OAI_ORE": {
      "displayName": "OAI_ORE",
      "mediaType": "application/json",
      "isHarvestable": false,
      "isVisibleInUserInterface": true
    },
    "Datacite": {
      "displayName": "DataCite",
      "mediaType": "application/xml",
      "isHarvestable": true,
      "isVisibleInUserInterface": true,
      "XMLNameSpace": "http://datacite.org/schema/kernel-3",
      "XMLSchemaLocation": "http://datacite.org/schema/kernel-3 http://schema.datacite.org/meta/kernel-3/metadata.xsd",
      "XMLSchemaVersion": "3.0"
    },
    "oai_dc": {
      "displayName": "Dublin Core",
      "mediaType": "application/xml",
      "isHarvestable": true,
      "isVisibleInUserInterface": false,
      "XMLNameSpace": "http://www.openarchives.org/OAI/2.0/oai_dc/",
      "XMLSchemaLocation": "http://www.openarchives.org/OAI/2.0/oai_dc.xsd",
      "XMLSchemaVersion": "2.0"
    },
    "oai_datacite": {
      "displayName": "OpenAIRE",
      "mediaType": "application/xml",
      "isHarvestable": true,
      "isVisibleInUserInterface": true,
      "XMLNameSpace": "http://datacite.org/schema/kernel-4",
      "XMLSchemaLocation": "http://schema.datacite.org/meta/kernel-4.1/metadata.xsd",
      "XMLSchemaVersion": "4.1"
    },
    "schema.org": {
      "displayName": "Schema.org JSON-LD",
      "mediaType": "application/json",
      "isHarvestable": false,
      "isVisibleInUserInterface": true
    },
    "ddi": {
      "displayName": "DDI",
      "mediaType": "application/xml",
      "isHarvestable": false,
      "isVisibleInUserInterface": true,
      "XMLNameSpace": "ddi:codebook:2_5",
      "XMLSchemaLocation": "https://ddialliance.org/Specification/DDI-Codebook/2.5/XMLSchema/codebook.xsd",
      "XMLSchemaVersion": "2.5"
    },
    "dcterms": {
      "displayName": "Dublin Core",
      "mediaType": "application/xml",
      "isHarvestable": false,
      "isVisibleInUserInterface": true,
      "XMLNameSpace": "http://purl.org/dc/terms/",
      "XMLSchemaLocation": "http://dublincore.org/schemas/xmls/qdc/dcterms.xsd",
      "XMLSchemaVersion": "2.0"
    },
    "html": {
      "displayName": "DDI HTML Codebook",
      "mediaType": "text/html",
      "isHarvestable": false,
      "isVisibleInUserInterface": true
    },
    "dataverse_json": {
      "displayName": "JSON",
      "mediaType": "application/json",
      "isHarvestable": true,
      "isVisibleInUserInterface": true
    },
    "oai_ddi": {
      "displayName": "DDI",
      "mediaType": "application/xml",
      "isHarvestable": true,
      "isVisibleInUserInterface": false,
      "XMLNameSpace": "ddi:codebook:2_5",
      "XMLSchemaLocation": "https://ddialliance.org/Specification/DDI-Codebook/2.5/XMLSchema/codebook.xsd",
      "XMLSchemaVersion": "2.5"
    }
  }
}
New docs look like this:

Screenshot from 2024-08-28 11-05-16

@julian-schneider
Copy link
Author

@pdurbin I believe I have addressed all the feedback you gave, have a nice day!

@coveralls
Copy link

Coverage Status

coverage: 20.76% (+0.02%) from 20.741%
when pulling 3f81981 on julian-schneider:expose-export-formats
into 0d27957 on IQSS:develop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Size: 3 A percentage of a sprint. 2.1 hours. Type: Feature a feature request
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants