You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by jo...@apache.org on 2025/09/07 13:08:01 UTC

(jackrabbit-filevault) branch JCRVLT-817-check-for-protected-properties-only-once created (now b97307d1)

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

joerghoh pushed a change to branch JCRVLT-817-check-for-protected-properties-only-once
in repository https://gitbox.apache.org/repos/asf/jackrabbit-filevault.git


      at b97307d1 JCRVLT-817 check only once for protected properties

This branch includes the following new commits:

     new b97307d1 JCRVLT-817 check only once for protected properties

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.



(jackrabbit-filevault) 01/01: JCRVLT-817 check only once for protected properties

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

joerghoh pushed a commit to branch JCRVLT-817-check-for-protected-properties-only-once
in repository https://gitbox.apache.org/repos/asf/jackrabbit-filevault.git

commit b97307d141887959fbff0ad1fc92039bf0a20a62
Author: Joerg Hoh <jh...@adobe.com>
AuthorDate: Sun Sep 7 15:07:20 2025 +0200

    JCRVLT-817 check only once for protected properties
---
 vault-core/.DS_Store                               | Bin 0 -> 8196 bytes
 .../vault/fs/impl/io/DocViewImporter.java          |  60 +++++++++++++--------
 2 files changed, 38 insertions(+), 22 deletions(-)

diff --git a/vault-core/.DS_Store b/vault-core/.DS_Store
new file mode 100644
index 00000000..9cad092b
Binary files /dev/null and b/vault-core/.DS_Store differ
diff --git a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewImporter.java b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewImporter.java
index ad742dd4..71d0e083 100644
--- a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewImporter.java
+++ b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewImporter.java
@@ -34,6 +34,7 @@ import java.util.Optional;
 import java.util.Set;
 import java.util.TimeZone;
 import java.util.UUID;
+import java.util.stream.Collectors;
 
 import javax.jcr.ImportUUIDBehavior;
 import javax.jcr.Item;
@@ -1078,11 +1079,10 @@ public class DocViewImporter implements DocViewParserHandler {
                 }
             }
             EffectiveNodeType effectiveNodeType = EffectiveNodeType.ofNode(node);
-            // logging for uncovered protected properties
-            logIgnoredProtectedProperties(effectiveNodeType, node.getPath(), ni.getProperties(), PROTECTED_PROPERTIES_CONSIDERED_FOR_UPDATED_NODES);
+            Collection<DocViewProperty2> unprotectedProperties = removeProtectedProperties(effectiveNodeType, node.getPath(), ni.getProperties(), PROTECTED_PROPERTIES_CONSIDERED_FOR_UPDATED_NODES);
             
             // add/modify properties contained in package
-            if (setUnprotectedProperties(effectiveNodeType, node, ni, importMode == ImportMode.REPLACE|| importMode == ImportMode.UPDATE || importMode == ImportMode.UPDATE_PROPERTIES, vs)) {
+            if (setUnprotectedProperties(effectiveNodeType, node, ni,unprotectedProperties, importMode == ImportMode.REPLACE|| importMode == ImportMode.UPDATE || importMode == ImportMode.UPDATE_PROPERTIES, vs)) {
                 updatedNode = node;
             }
         }
@@ -1181,9 +1181,8 @@ public class DocViewImporter implements DocViewParserHandler {
             Node node = getNodeByIdOrName(parentNode, ni, importUuidBehavior == ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
             EffectiveNodeType effectiveNodeType = EffectiveNodeType.ofNode(node);
 
-            // logging for uncovered protected properties
-            logIgnoredProtectedProperties(effectiveNodeType, node.getPath(), ni.getProperties(), PROTECTED_PROPERTIES_CONSIDERED_FOR_NEW_NODES);
-            setUnprotectedProperties(effectiveNodeType, node, ni, true, null);
+            Collection<DocViewProperty2> unprotectedProperties = removeProtectedProperties(effectiveNodeType, node.getPath(), ni.getProperties(), PROTECTED_PROPERTIES_CONSIDERED_FOR_NEW_NODES);
+            setUnprotectedProperties(effectiveNodeType, node, ni, unprotectedProperties, true, null);
             // remove mix referenceable if it was temporarily added
             if (addMixRef) {
                 node.removeMixin(JcrConstants.MIX_REFERENCEABLE);
@@ -1211,20 +1210,26 @@ public class DocViewImporter implements DocViewParserHandler {
         }
     }
 
-    private void logIgnoredProtectedProperties(EffectiveNodeType effectiveNodeType, String nodePath, Collection<DocViewProperty2> properties, Set<Name> importedProtectedProperties) {
-        // logging for protected properties which are not considered during import
-        properties.stream()
-            .filter(p -> p.getStringValue().isPresent() 
-                    && !importedProtectedProperties.contains(p.getName()))
-            .forEach(p -> {
-                try {
-                    if (isPropertyProtected(effectiveNodeType, p)) {
-                       log.warn("Ignore protected property '{}' on node '{}'", npResolver.getJCRName(p.getName()), nodePath);
+    // filter out all protected properties and log for a subset of them
+    private Collection<DocViewProperty2> removeProtectedProperties(EffectiveNodeType effectiveNodeType, String nodePath, Collection<DocViewProperty2> properties, Set<Name> importedProtectedProperties) {
+        return properties.stream()
+                .filter(p -> {
+                    try {
+                        if (isPropertyProtected(effectiveNodeType, p)) {
+                            // remove all protected properties
+                            if (p.getStringValue().isPresent() && !importedProtectedProperties.contains(p.getName())) {
+                                // log only those properties, which are not protected by the JCR standard because of special meaning
+                                log.warn("Ignore protected property '{}' on node '{}'", npResolver.getJCRName(p.getName()), nodePath);
+                            }
+                            return false;
+                        } else {
+                            return true; // pass on non-protected properties
+                        }
+                    } catch (RepositoryException e) {
+                        throw new IllegalStateException("Error retrieving protected status of properties", e);
                     }
-                } catch (RepositoryException e) {
-                    throw new IllegalStateException("Error retrieving protected status of properties", e);
-                }
-            });
+                })
+                .collect(Collectors.toList());
     }
 
     /**
@@ -1269,7 +1274,18 @@ public class DocViewImporter implements DocViewParserHandler {
         return node;
     }
 
-    private boolean setUnprotectedProperties(@NotNull EffectiveNodeType effectiveNodeType, @NotNull Node node, @NotNull DocViewNode2 ni, boolean overwriteExistingProperties, @Nullable VersioningState vs) throws RepositoryException {
+    /**
+     * Persist all unprotected properties
+     * @param effectiveNodeType
+     * @param node the node to set the properties to
+     * @param ni the DocViewNode to persist
+     * @param unprotectedProperties the unprotected properties to persist
+     * @param overwriteExistingProperties 
+     * @param vs
+     * @return
+     * @throws RepositoryException
+     */
+    private boolean setUnprotectedProperties(@NotNull EffectiveNodeType effectiveNodeType, @NotNull Node node, @NotNull DocViewNode2 ni, @NotNull Collection<DocViewProperty2> unprotectedProperties, boolean overwriteExistingProperties, @Nullable VersioningState vs) throws RepositoryException {
         boolean isAtomicCounter = false;
         for (String mixin : ni.getMixinTypes()) {
             if ("mix:atomicCounter".equals(mixin)) {
@@ -1279,9 +1295,9 @@ public class DocViewImporter implements DocViewParserHandler {
 
         boolean modified = false;
         // add properties
-        for (DocViewProperty2 prop : ni.getProperties()) {
+        for (DocViewProperty2 prop : unprotectedProperties) {
             String name = npResolver.getJCRName(prop.getName());
-            if (prop != null && !isPropertyProtected(effectiveNodeType, prop) && (overwriteExistingProperties || !node.hasProperty(name)) && wspFilter.includesProperty(node.getPath() + "/" + name)) {
+            if (prop != null && (overwriteExistingProperties || !node.hasProperty(name)) && wspFilter.includesProperty(node.getPath() + "/" + name)) {
                 // check if property is allowed
                 try {
                     modified |= prop.apply(node);