-
Notifications
You must be signed in to change notification settings - Fork 535
Expose export formats in native API #10739
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
Changes from all commits
5d0352a
49dd83b
cc99729
3b2c8e5
95d34c8
3f81981
594acb7
dd4b4d7
6a033df
48d04e8
f3b72c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # New API method for listing the available exporters | ||
| Found at `/api/info/exportFormats`, produces an object with available format names as keys, and as values an object with various info about the exporter. See also #10739. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,12 +12,17 @@ | |
| import jakarta.ws.rs.Produces; | ||
| import org.apache.commons.io.IOUtils; | ||
|
|
||
| import edu.harvard.iq.dataverse.export.ExportService; | ||
| import edu.harvard.iq.dataverse.settings.JvmSettings; | ||
| import edu.harvard.iq.dataverse.settings.SettingsServiceBean; | ||
| import edu.harvard.iq.dataverse.util.BundleUtil; | ||
| import edu.harvard.iq.dataverse.util.SystemConfig; | ||
| import io.gdcc.spi.export.Exporter; | ||
| import io.gdcc.spi.export.ExportException; | ||
| import io.gdcc.spi.export.XMLExporter; | ||
| import jakarta.ejb.EJB; | ||
| import jakarta.json.Json; | ||
| import jakarta.json.JsonObjectBuilder; | ||
| import jakarta.json.JsonValue; | ||
| import jakarta.ws.rs.GET; | ||
| import jakarta.ws.rs.Path; | ||
|
|
@@ -92,6 +97,32 @@ public Response getZipDownloadLimit() { | |
| return ok(zipDownloadLimit); | ||
| } | ||
|
|
||
| @GET | ||
| @Path("exportFormats") | ||
| public Response getExportFormats() { | ||
| JsonObjectBuilder responseModel = Json.createObjectBuilder(); | ||
| ExportService instance = ExportService.getInstance(); | ||
| for (String[] labels : instance.getExportersLabels()) { | ||
| try { | ||
| Exporter exporter = instance.getExporter(labels[1]); | ||
|
Comment on lines
+105
to
+107
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This lookup seems a bit awkward but it's not your fault. I wonder if we should add a method to ExportService like this... ... so that it can be used like this in places like Info.java: But I dunno. Maybe there's a reason why we don't offer a "getExporters" method like this.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that the steps I had to use to get the exporters were a bit awkward. If you think it would be in scope, I can add a method like that to this PR.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, let's think about it outside this PR. You're welcome to create an issue, though, if you like! |
||
| JsonObjectBuilder exporterObject = Json.createObjectBuilder().add("displayName", labels[0]) | ||
| .add("mediaType", exporter.getMediaType()).add("isHarvestable", exporter.isHarvestable()) | ||
| .add("isVisibleInUserInterface", exporter.isAvailableToUsers()); | ||
| if (exporter instanceof XMLExporter xmlExporter) { | ||
| exporterObject.add("XMLNameSpace", xmlExporter.getXMLNameSpace()) | ||
| .add("XMLSchemaLocation", xmlExporter.getXMLSchemaLocation()) | ||
| .add("XMLSchemaVersion", xmlExporter.getXMLSchemaVersion()); | ||
| } | ||
| responseModel.add(labels[1], exporterObject); | ||
| } | ||
| catch (ExportException ex){ | ||
| logger.warning("Failed to get: " + labels[1]); | ||
| logger.warning(ex.getLocalizedMessage()); | ||
| } | ||
| } | ||
| return ok(responseModel); | ||
| } | ||
|
|
||
| private Response getSettingResponseByKey(SettingsServiceBean.Key key) { | ||
| String setting = settingsService.getValueForKey(key); | ||
| if (setting != null) { | ||
pdurbin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| { | ||
| "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-4", | ||
| "XMLSchemaLocation": "http://datacite.org/schema/kernel-4 http://schema.datacite.org/meta/kernel-4.5/metadata.xsd", | ||
| "XMLSchemaVersion": "4.5" | ||
| }, | ||
| "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 Codebook v2", | ||
| "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 Codebook v2", | ||
| "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" | ||
| } | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.