Skip to content
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

Update db search and replace to support working copies #8514

Conversation

tylerjmchugh
Copy link
Contributor

@tylerjmchugh tylerjmchugh commented Nov 25, 2024

Currently the db search and replace API does not support working copies. This means that when we try to create a working copy and apply the search and replace on it, the working copy is ignored and the change is applied directly to the approved version.

This PR aims to fix this by implementing the following logic:

  • If the record is a draft
    • Update the draft record
  • If the record is approved (with no working copy)
    • Update the approved record
  • If the record is approved (with a working copy)
    • Update the working copy

Checklist

  • I have read the contribution guidelines
  • Pull request provided for main branch, backports managed with label
  • Good housekeeping of code, cleaning up comments, tests, and documentation
  • Clean commit history broken into understandable chucks, avoiding big commits with hundreds of files, cautious of reformatting and whitespace changes
  • Clean commit messages, longer verbose messages are encouraged
  • API Changes are identified in commit messages
  • Testing provided for features or enhancements using automatic tests
  • User documentation provided for new features or enhancements in manual
  • Build documentation provided for development instructions in README.md files
  • Library management using pom.xml dependency management. Update build documentation with intended library use and library tutorials or documentation

@tylerjmchugh tylerjmchugh force-pushed the main-search-and-replace-on-working-copies branch from 5bcd1ee to e0c2829 Compare November 26, 2024 15:33
@tylerjmchugh tylerjmchugh changed the title Update db search and replace to allow replacements on working copies Update db search and replace to support working copies Nov 26, 2024
@tylerjmchugh tylerjmchugh marked this pull request as ready for review November 26, 2024 16:18
@josegar74 josegar74 added this to the 4.4.7 milestone Nov 28, 2024
Copy link
Member

@josegar74 josegar74 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tylerjmchugh I got a bizarre case with the working copy:

  • Created a metadata with a contact individual name Jose and approved it.

  • Edited it to create a working copy and changed the title to distinguish the metadata in batch edit XML preview.

  • Replaced Jose with Jose 1: updates the value in the working copy, but not in the approved version (correct).

The preview XML shows the correct replaced value, but the metadata title is the approved one. It seems the preview doesn't use the working copy. This should be checked.

  • I updated again the metadata to change Jose 1 to Jose 2, but then the working copy is updated with the approved version value Jose instead of Jose 2

@tylerjmchugh
Copy link
Contributor Author

tylerjmchugh commented Nov 28, 2024

@josegar74

The preview XML shows the correct replaced value, but the metadata title is the approved one. It seems the preview doesn't use the working copy. This should be checked.

I updated again the metadata to change Jose 1 to Jose 2, but then the working copy is updated with the approved version value Jose instead of Jose 2

It seems the search and replace logic was applying the changes to the correct version but behind the scenes it was searching for the UUID on the MetadataRepository to get the updated metadata rather than using an IMetadataUtils method. I updated the draft repository to include the search and replace methods like the metadata repository has and implemented it in IMetadataUtils.

These issues now seem to be resolved but I see a unit test is now failing for the regex replace. I will look into this.

@tylerjmchugh
Copy link
Contributor Author

Fixed the unit test failure and issues with regex. Ready for review.

@ianwallen ianwallen added the bug label Nov 29, 2024
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Member

@josegar74 josegar74 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested the changes and works fine.

@josegar74 josegar74 merged commit cd74d3b into geonetwork:main Dec 10, 2024
7 of 8 checks passed
@geonetworkbuild
Copy link
Collaborator

The backport to 4.2.x failed:

The process '/usr/bin/git' failed with exit code 1
stderr
The previous cherry-pick is now empty, possibly due to conflict resolution.
If you wish to commit it anyway, use:

    git commit --allow-empty

Otherwise, please use 'git cherry-pick --skip'

stdout
[backport-8514-to-4.2.x 2df3c6bb68] Update db search and replace API to allow replacements on working copies
 Author: tylerjmchugh <[email protected]>
 Date: Tue Nov 26 10:33:04 2024 -0500
 1 file changed, 16 insertions(+), 3 deletions(-)
[backport-8514-to-4.2.x 8bd68ca3e7] Remove param
 Author: tylerjmchugh <[email protected]>
 Date: Tue Nov 26 12:16:30 2024 -0500
 1 file changed, 3 insertions(+), 16 deletions(-)
On branch backport-8514-to-4.2.x
You are currently cherry-picking commit f9b67accf7.
  (all conflicts fixed: run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

nothing to commit, working tree clean

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-4.2.x 4.2.x
# Navigate to the new working tree
cd .worktrees/backport-4.2.x
# Create a new branch
git switch --create backport-8514-to-4.2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick e0c2829e33a1d0935bf3624bf020060505fa522b,c8ac524846b521fb34dc762ec64724bb73852ec1,f9b67accf76db0d0574d58eece5bf772cf3ae9ac,3b817274da8a4c34b1056fabb14450f1d42ef21b,f49e6f71dfcfcb932e7569ba12f52503e5025c42,762120e03c21fc3cbbbe3bf1a3ea5569449a53b0,8d09f1cd244a266111b6120c6fd61fb5777b3cb2,debe4396fc36c0bfb65d7afb14051f3a8ea1fa04,3be79184dba6a972da59602f87129f358a74a7fe
# Push it to GitHub
git push --set-upstream origin backport-8514-to-4.2.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-4.2.x

Then, create a pull request where the base branch is 4.2.x and the compare/head branch is backport-8514-to-4.2.x.

ianwallen pushed a commit to ianwallen/core-geonetwork that referenced this pull request Dec 10, 2024
…es (geonetwork#8514)

* Update db search and replace API to allow replacements on working copies

* Remove param

* retrigger checks

* retrigger checks

* Update db search and replace preview API to allow replacements on working copies

* Update search and replace logic to use the correct repository

* Remove unused import

* Update selectOneWithSearchAndReplace to fallback to non-draft repository

* Fix calling wrong method
ianwallen added a commit that referenced this pull request Dec 10, 2024
…es (#8514) (#8552)

* Update db search and replace API to allow replacements on working copies

* Remove param

* retrigger checks

* retrigger checks

* Update db search and replace preview API to allow replacements on working copies

* Update search and replace logic to use the correct repository

* Remove unused import

* Update selectOneWithSearchAndReplace to fallback to non-draft repository

* Fix calling wrong method

Co-authored-by: tylerjmchugh <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants