-
Notifications
You must be signed in to change notification settings - Fork 536
11912 edit template api #12159
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
base: develop
Are you sure you want to change the base?
11912 edit template api #12159
Changes from all commits
6bc880d
c2124bc
9cd0905
a314c7b
f7c0424
cefb654
a905b7c
84c50cc
2fb6083
ede1c84
9bdcae5
1afe95b
d8b484f
f40d44d
2840982
23f08a9
8ce04ec
38fba3c
9776524
0b7f7e5
61d0594
92463aa
2c2e6a8
deb8f28
c8fb718
68e82e6
8f93821
49f60c8
3052ce5
0eba7d0
4916813
414f0ca
6fbc176
d3f5e0c
9893ca1
27ce2fb
cbec678
d098c2e
7f6c9fa
055ae30
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,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. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| { "name": "CC BY 4.0" } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" | ||
| } | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "customTerms": { | ||
| "termsOfUse": "testTermsOfUse", | ||
| "confidentialityDeclaration": "testConfidentialityDeclaration", | ||
| "specialPermissions": "testSpecialPermissions", | ||
| "restrictions": "testRestrictions", | ||
| "citationRequirements": "testCitationRequirements", | ||
| "depositorRequirements": "testDepositorRequirements", | ||
| "conditions": "testConditions", | ||
| "disclaimer": "testDisclaimer" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ | |
| import edu.harvard.iq.dataverse.engine.command.DataverseRequest; | ||
| import edu.harvard.iq.dataverse.engine.command.exception.CommandException; | ||
| import edu.harvard.iq.dataverse.engine.command.impl.*; | ||
| import edu.harvard.iq.dataverse.license.License; | ||
| import edu.harvard.iq.dataverse.pidproviders.PidProvider; | ||
| import edu.harvard.iq.dataverse.pidproviders.PidUtil; | ||
| import edu.harvard.iq.dataverse.settings.JvmSettings; | ||
|
|
@@ -72,6 +73,7 @@ | |
| import jakarta.ws.rs.WebApplicationException; | ||
| import jakarta.ws.rs.core.Context; | ||
| import jakarta.ws.rs.core.HttpHeaders; | ||
| import static jakarta.ws.rs.core.Response.Status.BAD_REQUEST; | ||
| import jakarta.ws.rs.core.StreamingOutput; | ||
| import org.glassfish.jersey.media.multipart.FormDataBodyPart; | ||
| import org.glassfish.jersey.media.multipart.FormDataContentDisposition; | ||
|
|
@@ -2016,9 +2018,9 @@ public Response getTemplate(@Context ContainerRequestContext crc, @PathParam("id | |
| public Response createTemplate(@Context ContainerRequestContext crc, String body, @PathParam("identifier") String dvIdtf) { | ||
| try { | ||
| Dataverse dataverse = findDataverseOrDie(dvIdtf); | ||
| NewTemplateDTO newTemplateDTO; | ||
| TemplateDTO newTemplateDTO; | ||
| try { | ||
| newTemplateDTO = NewTemplateDTO.fromRequestBody(body, jsonParser()); | ||
| newTemplateDTO = TemplateDTO.fromRequestBody(body, jsonParser()); | ||
| } catch (JsonParseException ex) { | ||
| return error(Status.BAD_REQUEST, MessageFormat.format(BundleUtil.getStringFromBundle("dataverse.createTemplate.error.jsonParseMetadataFields"), ex.getMessage())); | ||
| } | ||
|
|
@@ -2030,6 +2032,112 @@ public Response createTemplate(@Context ContainerRequestContext crc, String body | |
| return e.getResponse(); | ||
| } | ||
| } | ||
|
|
||
| @PUT | ||
| @AuthRequired | ||
| @Path("{templateId}/metadata") | ||
| public Response updateTemplateMetadata(@Context ContainerRequestContext crc, String body, @PathParam("templateId") Long templateId, @QueryParam("replace") boolean replaceData) { | ||
| try { | ||
| Template template = findTemplateOrDie(templateId); | ||
| Dataverse dataverse = template.getDataverse(); | ||
|
|
||
| JsonObject json = JsonUtil.getJsonObject(body); | ||
|
|
||
| /* | ||
| You can also set a new name for your template in the json | ||
| */ | ||
|
|
||
| if (json.containsKey("name") && !json.getString("name").isBlank()) { | ||
| template.setName(json.getString("name")); | ||
| } | ||
|
|
||
|
|
||
| List<DatasetField> updatedFields = new ArrayList<>(); | ||
| //if it doesn't contain fields, instructions or name it better have a single dataset field | ||
| //to be updated | ||
| if (json.getJsonArray("fields") == null) { | ||
| if (!json.containsKey("instructions") && !json.containsKey("name")){ | ||
| updatedFields.add(jsonParser().parseField(json, Boolean.FALSE, replaceData)); | ||
| } | ||
| } else { | ||
| updatedFields = jsonParser().parseMultipleFields(json, replaceData); | ||
| } | ||
|
|
||
| Map<String, String> instructionsMap = jsonParser().parseRequestBodyInstructionsMap(json); | ||
|
|
||
| Template updated = execCommand(new UpdateTemplateFieldsCommand(template, dataverse, updatedFields, instructionsMap, replaceData, createDataverseRequest(getRequestUser(crc)))); | ||
|
|
||
| return created("/dataverses/template/" + updated.getId(), jsonTemplate(updated)); | ||
| } catch (JsonParseException ex) { | ||
| logger.log(Level.SEVERE, "Semantic error parsing dataset update Json: " + ex.getMessage(), ex); | ||
| return error(Response.Status.BAD_REQUEST, BundleUtil.getStringFromBundle("datasets.api.editMetadata.error.parseUpdate", List.of(ex.getMessage()))); | ||
|
|
||
|
|
||
| } catch (WrappedResponse e) { | ||
| return e.getResponse(); | ||
| } | ||
| } | ||
|
|
||
| @PUT | ||
| @AuthRequired | ||
| @Path("{templateId}/licenseTerms") | ||
| public Response updateTemplateLicenseTerms(@Context ContainerRequestContext crc, LicenseUpdateRequest requestBody, @PathParam("templateId") Long templateId, @QueryParam("replace") boolean replaceData) { | ||
| try { | ||
| Template template = findTemplateOrDie(templateId); | ||
| Dataverse dataverse = template.getDataverse(); | ||
|
|
||
| if (requestBody.getName() != null && !requestBody.getName().isBlank()) { | ||
| String licenseName = requestBody.getName(); | ||
| License license = licenseSvc.getByNameOrUri(licenseName); | ||
|
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. Probably out of scope - this method is supposed to allow using a name or URI (which is actually meant as an identifier) but using LicenseUpdateRequest limits this to a name. It's the same for the Datasets method so this PR isn't introducing anything new, but supporting URIs would be a useful addition at some point. |
||
| if (license == null) { | ||
| return notFound(BundleUtil.getStringFromBundle("datasets.api.updateLicense.licenseNotFound", List.of(licenseName))); | ||
| } | ||
|
|
||
| execCommand(new UpdateTemplateLicenseCommand(createDataverseRequest(getRequestUser(crc)), template, dataverse, license)); | ||
| return ok(BundleUtil.getStringFromBundle("dataverses.api.update.template.license.success")); | ||
| } else if (requestBody.getCustomTerms() != null) { | ||
| CustomTermsDTO customTerms = requestBody.getCustomTerms(); | ||
| execCommand(new UpdateTemplateLicenseCommand(createDataverseRequest(getRequestUser(crc)), template, dataverse, customTerms.toTermsOfUseAndAccess())); | ||
| return ok(BundleUtil.getStringFromBundle("dataverses.api.update.template.license.success")); | ||
| } else { | ||
| return badRequest(BundleUtil.getStringFromBundle("datasets.api.updateLicense.licenseNameIsEmpty")); | ||
| } | ||
|
|
||
| } catch (WrappedResponse e) { | ||
| return e.getResponse(); | ||
| } | ||
| } | ||
|
|
||
| @PUT | ||
| @AuthRequired | ||
| @Path("{templateId}/access") | ||
| public Response updateTemplateTermsOfAccess(@Context ContainerRequestContext crc, String jsonBody, @PathParam("templateId") Long templateId) { | ||
| try { | ||
|
|
||
| boolean publicInstall = settingsSvc.isTrueForKey(SettingsServiceBean.Key.PublicInstall, false); | ||
|
|
||
| Template template = findTemplateOrDie(templateId); | ||
|
|
||
| JsonObject json = JsonUtil.getJsonObject(jsonBody); | ||
|
|
||
| TermsOfUseAndAccess toua = jsonParser().parseTermsOfAccess(json); | ||
|
|
||
| if (publicInstall && (toua.isFileAccessRequest() || !toua.getTermsOfAccess().isEmpty())){ | ||
|
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. isBlank for consistency? is null possible? |
||
| return error(BAD_REQUEST, "Setting File Access Request or Terms of Access is not permitted on a public installation."); | ||
| } | ||
|
|
||
| execCommand(new UpdateTemplateTermsOfAccessCommand(createDataverseRequest(getRequestUser(crc)), template, template.getDataverse(), toua )); | ||
|
|
||
| return ok(BundleUtil.getStringFromBundle("dataverses.api.update.template.access.success")); | ||
|
|
||
| } catch (JsonParseException ex) { | ||
| logger.log(Level.SEVERE, "Semantic error parsing template terms update Json: " + ex.getMessage(), ex); | ||
| return error(Response.Status.BAD_REQUEST, BundleUtil.getStringFromBundle("datasets.api.editMetadata.error.parseUpdate", List.of(ex.getMessage()))); | ||
| } catch (WrappedResponse ex) { | ||
| logger.log(Level.SEVERE, "Update terms of access error: " + ex.getMessage(), ex); | ||
| return ex.getResponse(); | ||
| } | ||
| } | ||
|
|
||
| @POST | ||
| @AuthRequired | ||
|
|
@@ -2041,7 +2149,7 @@ public Response setDefaultTemplate(@Context ContainerRequestContext crc, | |
| try { | ||
|
|
||
| Dataverse dataverse = findDataverseOrDie(dvId); | ||
| Template template = findTemplateOrDie(templateId, dataverse); | ||
| Template template = findTemplateInDataverseOrParentsOrDie(templateId, dataverse); | ||
| DataverseRequest dvReq = createDataverseRequest(getRequestUser(crc)); | ||
| SetDefaultTemplateCommand command = new SetDefaultTemplateCommand(template, dvReq, dataverse); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a nit: a json parsing error is syntactic not semantic - maybe just "Error parsing..."