You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by kw...@apache.org on 2021/11/11 09:14:10 UTC

[jackrabbit-filevault] branch bugfix/JCRVLT-549 updated (83d3d66 -> 35c39cc)

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

kwin pushed a change to branch bugfix/JCRVLT-549
in repository https://gitbox.apache.org/repos/asf/jackrabbit-filevault.git.


 discard 83d3d66  JCRVLT-549 consider node name constraints
     new 35c39cc  JCRVLT-549 consider node name constraints

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (83d3d66)
            \
             N -- N -- N   refs/heads/bugfix/JCRVLT-549 (35c39cc)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXImporter.java  | 1 -
 1 file changed, 1 deletion(-)

[jackrabbit-filevault] 01/01: JCRVLT-549 consider node name constraints

Posted by kw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kwin pushed a commit to branch bugfix/JCRVLT-549
in repository https://gitbox.apache.org/repos/asf/jackrabbit-filevault.git

commit 35c39cca0f66c01caaf90e3f4000bef134261b02
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Thu Nov 11 10:13:22 2021 +0100

    JCRVLT-549 consider node name constraints
    
    simplify type checking
---
 .../vault/fs/impl/io/DocViewSAXImporter.java       | 55 ++++++++++++----------
 .../{MandatoryNode.java => MandatoryNodeIT.java}   |  2 +-
 2 files changed, 32 insertions(+), 25 deletions(-)

diff --git a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXImporter.java b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXImporter.java
index d3f1807..c6a00c9 100644
--- a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXImporter.java
+++ b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXImporter.java
@@ -27,7 +27,6 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.NoSuchElementException;
 import java.util.Set;
 import java.util.UUID;
 import java.util.Optional;
@@ -1266,12 +1265,25 @@ public class DocViewSAXImporter extends RejectingEntityDefaultHandler implements
                         } else {
                             if (wspFilter.getImportMode(path) == ImportMode.REPLACE) {
 
+                                boolean shouldRemoveChild = true;
                                 // check if child is not protected
                                 if (child.getDefinition().isProtected()) {
+                                    shouldRemoveChild = false;
                                     log.debug("Refuse to delete protected child node: {}", path);
-                                } else if (child.getDefinition().isMandatory() && !hasSiblingWithSameType(child)) {
-                                    log.debug("Refuse to delete mandatory child node: {}", path);
-                                } else {
+                                } else if (child.getDefinition().isMandatory()) {
+                                    // get relevant child node definition from parent's effective node type
+                                    EffectiveNodeType ent = EffectiveNodeType.ofNode(child.getParent());
+                                    Optional<NodeDefinition> childNodeDefinition = ent.getApplicableChildNodeDefinition(child.getName(), child.getPrimaryNodeType());
+                                    if (!childNodeDefinition.isPresent()) {
+                                        // this should never happen as then child.getDefinition().isMandatory() would have returned false in the first place...
+                                        throw new IllegalStateException("Could not find applicable child node definition for mandatory child node " + child.getPath());
+                                    } else {
+                                        if (!hasSiblingWithPrimaryTypesAndName(child, childNodeDefinition.get().getRequiredPrimaryTypes(), childNodeDefinition.get().getName())) {
+                                            log.debug("Refuse to delete mandatory child node: {}", path);
+                                        }
+                                    }
+                                } 
+                                if (shouldRemoveChild) {
                                     importInfo.onDeleted(path);
                                     child.remove();
                                 }
@@ -1298,29 +1310,24 @@ public class DocViewSAXImporter extends RejectingEntityDefaultHandler implements
         }
     }
 
-    private boolean hasSiblingWithSameType(Node child) throws RepositoryException {
-
-        Node parent = child.getParent();
-
-        try {
-            EffectiveNodeType ent = EffectiveNodeType.ofNode(parent);
-            String typeName = ent.getApplicableChildNodeDefinition(child.getName(), child.getPrimaryNodeType()).get().getName();
-
-            NodeIterator iter = parent.getNodes();
-            while (iter.hasNext()) {
-                Node sibling = iter.nextNode();
-                if (!sibling.isSame(child)) {
-                    Optional<NodeDefinition> childDef = ent.getApplicableChildNodeDefinition(sibling.getName(),
-                            sibling.getPrimaryNodeType());
-                    try {
-                        if (typeName.equals(childDef.get().getName())) {
-                            return true;
-                        }
-                    } catch (NoSuchElementException ignored) {
+    private boolean hasSiblingWithPrimaryTypesAndName(Node child, NodeType[] requiredPrimaryNodeTypes, String requiredName) throws RepositoryException {
+        NodeIterator iter = child.getParent().getNodes();
+        while (iter.hasNext()) {
+            Node sibling = iter.nextNode();
+            if (!sibling.isSame(child)) {
+                NodeType stype = sibling.getPrimaryNodeType();
+                boolean allmatch = true;
+                // check type: due to inheritance multiple primary node types need to be checked
+                for (NodeType requiredPrimaryNodeType : requiredPrimaryNodeTypes) {
+                    allmatch &= stype.isNodeType(requiredPrimaryNodeType.getName());
+                }
+                // check name
+                if (requiredName.equals("*") || requiredName.equals(child.getName())) {
+                    if (allmatch) {
+                        return true;
                     }
                 }
             }
-        } catch (NoSuchElementException ignored) {
         }
         return false;
     }
diff --git a/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/MandatoryNode.java b/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/MandatoryNodeIT.java
similarity index 98%
rename from vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/MandatoryNode.java
rename to vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/MandatoryNodeIT.java
index 510c5dc..d8b832a 100644
--- a/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/MandatoryNode.java
+++ b/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/MandatoryNodeIT.java
@@ -24,7 +24,7 @@ import org.apache.jackrabbit.vault.packaging.PackageException;
 import org.junit.Test;
 
 
-public class MandatoryNode extends IntegrationTestBase {
+public class MandatoryNodeIT extends IntegrationTestBase {
  
     @Test
     public void testMultipleMandatoryChildNodesReplace()