You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ba...@apache.org on 2023/10/11 07:18:49 UTC

[jackrabbit-oak] branch issue/oak-9459 updated: OAK-9459: ConstraintViolationException in VersionManagerImplRestore when target node has a property definition unknown by the frozen node

This is an automated email from the ASF dual-hosted git repository.

baedke pushed a commit to branch issue/oak-9459
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git


The following commit(s) were added to refs/heads/issue/oak-9459 by this push:
     new 0241a28248 OAK-9459: ConstraintViolationException in VersionManagerImplRestore when target node has a property definition unknown by the frozen node
0241a28248 is described below

commit 0241a282486832395e33a0905414cd2ac3c26444
Author: Manfred Baedke <ma...@gmail.com>
AuthorDate: Tue Oct 10 16:29:31 2023 +0200

    OAK-9459: ConstraintViolationException in VersionManagerImplRestore when target node has a property definition unknown by the frozen node
    
    Fixed by retrieving the property definitions before setting the node types.
---
 .../oak/plugins/version/VersionableState.java      | 43 ++++++++++++++++------
 oak-jcr/pom.xml                                    |  1 -
 2 files changed, 31 insertions(+), 13 deletions(-)

diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionableState.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionableState.java
index 70602e82f2..70598b2c61 100644
--- a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionableState.java
+++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionableState.java
@@ -44,8 +44,10 @@ import static org.apache.jackrabbit.oak.plugins.version.Utils.primaryTypeOf;
 import static org.apache.jackrabbit.oak.plugins.version.Utils.uuidFromNode;
 
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import javax.jcr.RepositoryException;
@@ -285,8 +287,32 @@ class VersionableState {
                                @NotNull NodeBuilder dest,
                                @NotNull VersionSelector selector)
             throws RepositoryException, CommitFailedException {
-        // 15.7.2 Restoring Type and Identifier
-        restoreFrozenTypeAndUUID(frozen, dest);
+        //OAK-9459: if the NodeState is not empty, retrieve OPVs before restoring types to avoid constraint violations
+        boolean frozenTypeRestored = false;
+        if (!dest.hasProperty(JCR_PRIMARYTYPE)) {
+            // empty NodeState
+            // 15.7.2 Restoring Type and Identifier
+            restoreFrozenTypeAndUUID(frozen, dest);
+            frozenTypeRestored = true;
+        }
+        HashMap<PropertyState, Integer> opvs = new HashMap<>();
+        for (PropertyState p : dest.getProperties()) {
+            String propName = p.getName();
+            if (BASIC_PROPERTIES.contains(propName)) {
+                continue;
+            }
+            if (frozen.hasProperty(propName)) {
+                continue;
+            }
+            int action = getOPV(dest, p);
+            if (action == COPY || action == VERSION || action == ABORT || action == INITIALIZE || action == COMPUTE) {
+                opvs.put(p, action);
+            }
+        }
+        if (!frozenTypeRestored) {
+            // 15.7.2 Restoring Type and Identifier
+            restoreFrozenTypeAndUUID(frozen, dest);
+        }
         // 15.7.3 Restoring Properties
         for (PropertyState p : frozen.getProperties()) {
             if (BASIC_FROZEN_PROPERTIES.contains(p.getName())) {
@@ -298,19 +324,12 @@ class VersionableState {
                 dest.setProperty(p);
             }
         }
-        for (PropertyState p : dest.getProperties()) {
+        for (Map.Entry<PropertyState, Integer> entry : opvs.entrySet()) {
+            PropertyState p = entry.getKey();
+            int action = entry.getValue();
             String propName = p.getName();
-            if (BASIC_PROPERTIES.contains(propName)) {
-                continue;
-            }
-            if (frozen.hasProperty(propName)) {
-                continue;
-            }
-            int action = getOPV(dest, p);
             if (action == COPY || action == VERSION || action == ABORT) {
                 dest.removeProperty(propName);
-            } else if (action == IGNORE) {
-                // no action
             } else if (action == INITIALIZE) {
                 resetToDefaultValue(dest, p);
             } else if (action == COMPUTE) {
diff --git a/oak-jcr/pom.xml b/oak-jcr/pom.xml
index 6748ca36e8..186c6b1e4e 100644
--- a/oak-jcr/pom.xml
+++ b/oak-jcr/pom.xml
@@ -85,7 +85,6 @@
       org.apache.jackrabbit.test.api.version.VersionHistoryTest#testMerge
       org.apache.jackrabbit.test.api.version.RestoreTest#testRestoreLabel
       org.apache.jackrabbit.test.api.version.RestoreTest#testRestoreLabelJcr2
-      org.apache.jackrabbit.test.api.version.RestoreTest#testRestoreRemovesMixin <!-- OAK-9459 -->
       org.apache.jackrabbit.test.api.version.WorkspaceRestoreTest
       org.apache.jackrabbit.test.api.version.MergeCancelMergeTest
       org.apache.jackrabbit.test.api.version.MergeCheckedoutSubNodeTest