Update metadata-patch.md to describe replace operation better#304
Update metadata-patch.md to describe replace operation better#304
replace operation better#304Conversation
|
@atarix83 or @abollini : If you have a chance, I'd appreciate your review on this small change to our REST Contract. I'm trying to better document the |
There was a problem hiding this comment.
The updated description is clear and explicates intended usage of PATCH add to replace values.
However, based on testing with a DSpace 7 -based installation, this does not reflect the present behaviour of the REST API. Instead, when calling PATCH add just one value is added and other values are shifted, not replaced - even if one uses path /metadata/field.name instead of single value /metadata/field.name/n.
Example: consider a community that has dc.title values
[{"value": "Artikkelit","language": "fi","place": 0}, {"value": "Articles","language": "en","place": 1}]
Then, using e.g. https://github.com/the-library-code/dspace-rest-python try to update values
d.api_patch(url=...,operation=DSpaceClient.PatchOperation.ADD, path='/metadata/dc.title', value= [ { "value": "Artikkelit (new)", "language": "fi" }, { "value": "Articles (new)", "language": "en" }])
This results to PATCH add API request that has path /metadata/dc.title and json array as value. However, this results to following structure:
[
{"value": "Artikkelit (new)","language": "fi","place": 0},
{"value": "Artikkelit","language": "fi","place": 1},
{"value": "Articles","language": "en","place": 2}
]
I.e. only one value is added and old values are shifted! So, the note about replacing values with add should probably be rephrased - or bug fixed such that the API complies with the contract.
Assuming that
https://github.com/DSpace/DSpace/blob/main/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/patch/operation/DSpaceObjectMetadataAddOperation.java is responsible for PATCH add it seems to contain only functionality to add one value at a time.
Compare with https://github.com/DSpace/DSpace/blob/main/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/patch/operation/DSpaceObjectMetadataReplaceOperation.java that has more complex logic in place - even without suggested DSpace/DSpace#9610 "multiple values" addition.
Because of this DSpace/dspace-angular#3078 requires metadata remove operation first if implemented with multiple add operations instead of one "multiple values" replace call.
This PR is based on the discussion in DSpace/DSpace#9610 (comment)
Per RFC Section 4.3 (replace) and RFC section 4.1 (add), we recommend using the
addoperation (with an array of values) to replace all values. Thereplaceoperation should only be used to replace individual values.This small PR corrects some incorrect documentation in our REST Contract