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
428 stars 489 forks source link

Metadata workflow - publish a draft metadata doesn't update the status in the search index #8341

Closed josegar74 closed 2 months ago

josegar74 commented 2 months ago

Describe the bug

Publishing a draft metadata (without approving it previously) changes the metadata status to Approved, but does not update the status in the search index, so it appears in the metadata page as Draft. Triggering the metadata reindex manually updates the status.

To Reproduce

Steps to reproduce the behavior:

  1. Login as administrator user.
  2. Enable the metadata workflow.
  3. Create a metadata
  4. In the metadata page, select Manage record > Publish
  5. The metadata status is still displayed as Draft, even if refreshing the page.
  6. Select Manage record > Index record and refresh the page. The status is displayed as Approved

Expected behavior After the publication, the metadata status in the page is updated to Approved, without requiring a manual reindex of the metadata.

josegar74 commented 2 months ago

@ianwallen, @wangf1122 this issue is related to this change:

https://github.com/geonetwork/core-geonetwork/commit/10feefff1294cd5b8a51f6a0df2ea9529d8bea40#diff-1760d4f471f27322126aee9c5666eb0d79fd27ab4a2ee485ff2acbbde047a251R124

The ApprovePublishedRecord listener previously reindexed the metadata, but with that change doesn't do it anymore.

Either we need to update that line or trigger manually a reindex after https://github.com/geonetwork/core-geonetwork/blob/c9164d0e1f1106f5a9d26dca81962b954508a533/listeners/src/main/java/org/fao/geonet/listener/metadata/draft/ApprovePublishedRecord.java#L98

Do you remember why was removed the reindex in that line?

wangf1122 commented 2 months ago

@josegar74 @ianwallen

I remember it was done in this pull request https://github.com/geonetwork/core-geonetwork/pull/7514

Its doing opposite here as the index was updated prematurely in the middle of the transaction. If there is something failing (which we customized some listener in our environment), the index updated as next status and confused the user.

I can ran some test and confirm it

josegar74 commented 2 months ago

Thanks @wangf1122, with the default listener if you try the test case, you should be able to reproduce the problem.

josegar74 commented 2 months ago

@wangf1122 Maybe an option can be to do a manual reindex at the end of https://github.com/geonetwork/core-geonetwork/blob/c9164d0e1f1106f5a9d26dca81962b954508a533/listeners/src/main/java/org/fao/geonet/listener/metadata/draft/ApprovePublishedRecord.java#L80C17-L80C30 if does not occur an exception.

wangf1122 commented 2 months ago

@josegar74

I did the pull request, https://github.com/geonetwork/core-geonetwork/pull/8344

The proposed change will fix the issue. There are two issues here

1) The status updating happens in this https://github.com/geonetwork/core-geonetwork/blob/c9164d0e1f1106f5a9d26dca81962b954508a533/listeners/src/main/java/org/fao/geonet/listener/metadata/draft/ApprovePublishedRecord.java#L114-L124 which is another thread from the execution API https://github.com/geonetwork/core-geonetwork/blob/c9164d0e1f1106f5a9d26dca81962b954508a533/services/src/main/java/org/fao/geonet/api/records/MetadataSharingApi.java#L1218

Upon the status updating, the index should be updated accordingly

2) The ui is lack of refreshing mechanism to get the latest metadata status to the page. I also added such UI small fix.

You can take a look of the change and test it