diff --git a/doc/release-notes/11912-edit-template-apis b/doc/release-notes/11912-edit-template-apis new file mode 100644 index 00000000000..91324f38330 --- /dev/null +++ b/doc/release-notes/11912-edit-template-apis @@ -0,0 +1,23 @@ +## New Endpoint: PUT `/dataverses/{templateId}/metadata` + +A new endpoint has been implemented to edit the metadata and field instructions for a given template. + +### Functionality +- Updates the metadata and field instructions for a template based on a json file provided. +- You must have edit dataverse permission in the collection in order to use this endpoint. + +## New Endpoint: PUT `/dataverses/{templateId}/licenseTerms` + +A new endpoint has been implemented to edit the license or custom terms of use for a given template. + +### Functionality +- Updates the license or custom terms of use for a template based on a json file provided. +- You must have edit dataverse permission in the collection in order to use this endpoint. + +## New Endpoint: PUT `/dataverses/{templateId}/access` + +A new endpoint has been implemented to edit the terms of access for a given template. + +### Functionality +- Updates the terms of access for a template based on a json file provided. +- You must have edit dataverse permission in the collection in order to use this endpoint. diff --git a/doc/sphinx-guides/source/_static/api/template-update-access.json b/doc/sphinx-guides/source/_static/api/template-update-access.json new file mode 100644 index 00000000000..e2d86de3283 --- /dev/null +++ b/doc/sphinx-guides/source/_static/api/template-update-access.json @@ -0,0 +1,13 @@ +{ + "customTermsOfAccess": { + "fileAccessRequest": false, + "termsOfAccess": "Here are the terms...", + "dataAccessPlace": "dataAccessPlace", + "originalArchive": "originalArchive", + "availabilityStatus": "availabilityStatus", + "contactForAccess": "contactForAccess", + "sizeOfCollection": "sizeOfCollection", + "studyCompletion": "studyCompletion", + "confidentialityDeclaration": "confidentialityDeclaration" + } +} diff --git a/doc/sphinx-guides/source/_static/api/template-update-license.json b/doc/sphinx-guides/source/_static/api/template-update-license.json new file mode 100644 index 00000000000..455f4c9d9bd --- /dev/null +++ b/doc/sphinx-guides/source/_static/api/template-update-license.json @@ -0,0 +1 @@ +{ "name": "CC BY 4.0" } diff --git a/doc/sphinx-guides/source/_static/api/template-update-metadata.json b/doc/sphinx-guides/source/_static/api/template-update-metadata.json new file mode 100644 index 00000000000..46e201a05f9 --- /dev/null +++ b/doc/sphinx-guides/source/_static/api/template-update-metadata.json @@ -0,0 +1,30 @@ +{ + "name": "Dataverse template - edited", + "fields": [ + { + "typeName": "author", + "value": [ + { + "authorName": { + "typeName": "authorName", + "value": "Brady, Tom" + }, + "authorAffiliation": { + "typeName": "authorIdentifierScheme", + "value": "ORCID" + } + } + ] + } + ], + "instructions": [ + { + "instructionField": "author", + "instructionText": "The author data, edited" + }, + { + "instructionField": "subtitle", + "instructionText": "Instructions for subtitle" + } + ] +} diff --git a/doc/sphinx-guides/source/_static/api/template-update-terms.json b/doc/sphinx-guides/source/_static/api/template-update-terms.json new file mode 100644 index 00000000000..5cf166a83c4 --- /dev/null +++ b/doc/sphinx-guides/source/_static/api/template-update-terms.json @@ -0,0 +1,12 @@ +{ + "customTerms": { + "termsOfUse": "testTermsOfUse", + "confidentialityDeclaration": "testConfidentialityDeclaration", + "specialPermissions": "testSpecialPermissions", + "restrictions": "testRestrictions", + "citationRequirements": "testCitationRequirements", + "depositorRequirements": "testDepositorRequirements", + "conditions": "testConditions", + "disclaimer": "testDisclaimer" + } +} diff --git a/doc/sphinx-guides/source/api/native-api.rst b/doc/sphinx-guides/source/api/native-api.rst index eab71f8623b..6be96c3f8a7 100644 --- a/doc/sphinx-guides/source/api/native-api.rst +++ b/doc/sphinx-guides/source/api/native-api.rst @@ -1639,6 +1639,69 @@ The fully expanded example above (without environment variables) looks like this curl -H "X-Dataverse-key: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" -X POST "https://demo.dataverse.org/api/dataverses/1/templates" --upload-file dataverse-template.json +Update the Metadata and Instructions of a Template +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Updates the metadata and instructions of a template with a given ``id``. + +To update the template, you must send a JSON file. Your JSON file might look like :download:`template-update-metadata.json <../_static/api/template-update-metadata.json>` which you would send to the Dataverse installation like this: + +.. code-block:: bash + + export API_TOKEN=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx + export SERVER_URL=https://demo.dataverse.org + export ID=1 + + curl -H "X-Dataverse-key: $API_TOKEN" -X PUT "$SERVER_URL/api/dataverses/{ID}/metadata" --upload-file template-update-metadata.json + +The fully expanded example above (without environment variables) looks like this: + +.. code-block:: bash + + curl -H "X-Dataverse-key: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" -X PUT "https://demo.dataverse.org/api/dataverses/1/metadata" --upload-file template-update-metadata.json + +Update the License or Terms Of Use of a Template +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Updates the license or custom terms of use of a template with a given ``id``. + +To update the template, you must send a JSON file containing either the name of an active license or custom terms of use. Your JSON file might look like :download:`template-update-license.json <../_static/api/template-update-license.json>` or :download:`template-update-terms.json <../_static/api/template-update-terms.json>` which you would send to the Dataverse installation like this: + +.. code-block:: bash + + export API_TOKEN=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx + export SERVER_URL=https://demo.dataverse.org + export ID=1 + + curl -H "X-Dataverse-key: $API_TOKEN" -X PUT "$SERVER_URL/api/dataverses/{ID}/licenseTerms" --upload-file template-update-license.json + +The fully expanded example above (without environment variables) looks like this: + +.. code-block:: bash + + curl -H "X-Dataverse-key: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" -X PUT "https://demo.dataverse.org/api/dataverses/1/licenseTerms" --upload-file template-update-license.json + +Update the Terms Of Access of a Template +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Updates the terms of access of a template with a given ``id``. + +To update the template, you must send a JSON file containing either the name of an active license or custom terms of use. Your JSON file might look like :download:`template-update-access.json <../_static/api/template-update-access.json>` which you would send to the Dataverse installation like this: + +.. code-block:: bash + + export API_TOKEN=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx + export SERVER_URL=https://demo.dataverse.org + export ID=1 + + curl -H "X-Dataverse-key: $API_TOKEN" -X PUT "$SERVER_URL/api/dataverses/{ID}/access" --upload-file template-update-access.json + +The fully expanded example above (without environment variables) looks like this: + +.. code-block:: bash + + curl -H "X-Dataverse-key: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" -X PUT "https://demo.dataverse.org/api/dataverses/1/access" --upload-file template-update-access.json + Set a Default Template for a Collection ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/src/main/java/edu/harvard/iq/dataverse/api/AbstractApiBean.java b/src/main/java/edu/harvard/iq/dataverse/api/AbstractApiBean.java index 2ee5730153e..ffa9ae27f31 100644 --- a/src/main/java/edu/harvard/iq/dataverse/api/AbstractApiBean.java +++ b/src/main/java/edu/harvard/iq/dataverse/api/AbstractApiBean.java @@ -242,6 +242,9 @@ String getWrappedMessageWhenJson() { @EJB GuestbookResponseServiceBean gbRespSvc; + + @EJB + TemplateServiceBean templateSvc; @Inject FailedPIDResolutionLoggingServiceBean fprLogService; @@ -370,8 +373,18 @@ protected Dataverse findDataverseOrDie( String dvIdtf ) throws WrappedResponse { } return dv; } + + protected Template findTemplateOrDie(Long templateId) throws WrappedResponse { + + Template template = templateSvc.find(templateId); + if (template == null) { + throw new WrappedResponse( + error(Response.Status.NOT_FOUND, "Can't find template with identifier='" + templateId + "'")); + } + return template; + } - protected Template findTemplateOrDie(Long templateId, Dataverse dataverse) throws WrappedResponse { + protected Template findAllTemplatesOrDie(Long templateId, Dataverse dataverse) throws WrappedResponse { List