geonetwork / core-geonetwork

GeoNetwork is a catalog application to manage spatially referenced resources. It provides powerful metadata editing and search functions as well as an interactive web map viewer. It is currently used in numerous Spatial Data Infrastructure initiatives across the world.
http://geonetwork-opensource.org/
GNU General Public License v2.0
423 stars 489 forks source link

Bug with adding resource in working copy if deletes occurred on draft. #8452

Open ianwallen opened 1 day ago

ianwallen commented 1 day ago

Describe the bug Getting error when trying to upload resource on a new working copy.

To Reproduce 1 - create a new record. 2 - upload a new resource i.e. filename test.png 3 - if supported upload resource again and overwrite. If overwrite not supported (depends on filestore used) then delete the file and re-add the file. Do this several times. i.e. 3 times to simulate a users replacing the file with several versions during the editing process. 4 - save the record and approve the record 5 - create a working copy 6 - upload the test.png file again (may need to delete and upload)

You will get something like the following

image

Expected behavior Expecting the upload to work.

Additional context The bug seems to be related to the following code

https://github.com/geonetwork/core-geonetwork/blob/5b01f640fc4c4853cb1d1cdd75544577d087f125/core/src/main/java/org/fao/geonet/kernel/datamanager/draft/DraftMetadataUtils.java#L667-L682

It seems that when the copy is being done, it does not set the delete date field. So all delete dates are set to null which can causes some duplicates. Not sure if it should be excluding the records with a deleted date (not null) or if it should include the deleted date in the copy?

With the current logic, the deleted dates are copied and set to null which then causes duplicates when the following is called

https://github.com/geonetwork/core-geonetwork/blob/5b01f640fc4c4853cb1d1cdd75544577d087f125/services/src/main/java/org/fao/geonet/services/resources/handlers/DefaultResourceRemoveHandler.java#L73

So should we add image Or should we modify image to exclude records where deleted date is not null?

josegar74 commented 4 hours ago

@ianwallen, I would check for the first solution, to keep the original information, as probably when the draft is approved, the table for the approved version is replaced with the version from the draft.