You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by en...@apache.org on 2022/06/30 23:41:42 UTC
[sling-org-apache-sling-jcr-repoinit] branch master updated: SLING-10740 implemention for create path with properties (#27)
This is an automated email from the ASF dual-hosted git repository.
enorman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-repoinit.git
The following commit(s) were added to refs/heads/master by this push:
new d9d50ab SLING-10740 implemention for create path with properties (#27)
d9d50ab is described below
commit d9d50ab951814733fb44cff5427077c335f08349
Author: Eric Norman <en...@apache.org>
AuthorDate: Thu Jun 30 16:41:38 2022 -0700
SLING-10740 implemention for create path with properties (#27)
---
bnd.bnd | 2 +-
.../apache/sling/jcr/repoinit/impl/AclVisitor.java | 9 +++++
.../apache/sling/jcr/repoinit/CreatePathsTest.java | 44 ++++++++++++++++++++--
3 files changed, 50 insertions(+), 5 deletions(-)
diff --git a/bnd.bnd b/bnd.bnd
index bf53079..e49236d 100644
--- a/bnd.bnd
+++ b/bnd.bnd
@@ -3,4 +3,4 @@ Import-Package:\
org.apache.jackrabbit.oak.spi.security.principal;version="[1.5,3)",\
*
Provide-Capability: osgi.implementation;osgi.implementation="org.apache.sling.jcr.repoinit";version:Version="8.1"
-Require-Capability: org.apache.sling.repoinit.language;filter:="(version>=8.4)"
+Require-Capability: org.apache.sling.repoinit.language;filter:="(version>=8.5)"
diff --git a/src/main/java/org/apache/sling/jcr/repoinit/impl/AclVisitor.java b/src/main/java/org/apache/sling/jcr/repoinit/impl/AclVisitor.java
index c202f4e..1b9aafe 100644
--- a/src/main/java/org/apache/sling/jcr/repoinit/impl/AclVisitor.java
+++ b/src/main/java/org/apache/sling/jcr/repoinit/impl/AclVisitor.java
@@ -33,6 +33,7 @@ import org.apache.sling.repoinit.parser.operations.CreatePath;
import org.apache.sling.repoinit.parser.operations.DeleteAclPrincipalBased;
import org.apache.sling.repoinit.parser.operations.DeleteAclPrincipals;
import org.apache.sling.repoinit.parser.operations.PathSegmentDefinition;
+import org.apache.sling.repoinit.parser.operations.PropertyLine;
import org.apache.sling.repoinit.parser.operations.DeleteAclPaths;
import org.apache.sling.repoinit.parser.operations.RemoveAcePaths;
import org.apache.sling.repoinit.parser.operations.RemoveAcePrincipalBased;
@@ -41,6 +42,7 @@ import org.apache.sling.repoinit.parser.operations.RestrictionClause;
import org.apache.sling.repoinit.parser.operations.SetAclPaths;
import org.apache.sling.repoinit.parser.operations.SetAclPrincipalBased;
import org.apache.sling.repoinit.parser.operations.SetAclPrincipals;
+import org.apache.sling.repoinit.parser.operations.SetProperties;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -201,6 +203,13 @@ class AclVisitor extends DoNothingVisitor {
}
parentPath += "/" + psd.getSegment();
}
+ List<PropertyLine> propertyLines = cp.getPropertyLines();
+ if (!propertyLines.isEmpty()) {
+ // delegate to the NodePropertiesVisitor to set the properties
+ SetProperties sp = new SetProperties(Collections.singletonList(parentPath), propertyLines);
+ NodePropertiesVisitor npv = new NodePropertiesVisitor(session);
+ npv.visitSetProperties(sp);
+ }
try {
session.save();
} catch (Exception e) {
diff --git a/src/test/java/org/apache/sling/jcr/repoinit/CreatePathsTest.java b/src/test/java/org/apache/sling/jcr/repoinit/CreatePathsTest.java
index edcc692..0405cf3 100644
--- a/src/test/java/org/apache/sling/jcr/repoinit/CreatePathsTest.java
+++ b/src/test/java/org/apache/sling/jcr/repoinit/CreatePathsTest.java
@@ -16,12 +16,17 @@
*/
package org.apache.sling.jcr.repoinit;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
+import java.util.UUID;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
+import javax.jcr.ValueFactory;
import org.apache.sling.commons.testing.jcr.RepositoryUtil;
import org.apache.sling.jcr.repoinit.impl.TestUtil;
@@ -31,9 +36,6 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
/** Test the creation of paths with specific node types */
public class CreatePathsTest {
@@ -41,7 +43,11 @@ public class CreatePathsTest {
public final SlingContext context = new SlingContext(ResourceResolverType.JCR_OAK);
private TestUtil U;
-
+
+ private static final String TEST_ID = UUID.randomUUID().toString();
+ private static final String NS_PREFIX = CreatePathsTest.class.getSimpleName();
+ private static final String NS_URI = "uri:" + NS_PREFIX + ":" + TEST_ID;
+
@Before
public void setup() throws RepositoryException, IOException {
U = new TestUtil(context);
@@ -150,4 +156,34 @@ public class CreatePathsTest {
U.parseAndExecute("create path " + fullPath);
assertTrue(U.adminSession.propertyExists(fullPath));
}
+
+ /**
+ * SLING-10740 create path statement for node type with a mandatory property
+ */
+ @Test
+ public void createPathWithMandatoryProperty() throws Exception {
+ // register a nodetype with a required property
+ U = new TestUtil(context);
+ U.parseAndExecute("register namespace (" + NS_PREFIX + ") " + NS_URI);
+ String registerNodetypeCndStatement = "register nodetypes\n"
+ + "<<===\n"
+ + "<< <" + NS_PREFIX + "='" + NS_URI + "'>\n"
+ + "<< [" + NS_PREFIX + ":foo]\n"
+ + "<< - displayName (String) mandatory\n"
+ + "===>>\n";
+ U.parseAndExecute(registerNodetypeCndStatement);
+
+ // create the path with the mandatory property populated
+ final String path = String.format("/one(%s:foo)", NS_PREFIX);
+ String createPathCndStatement = "create path " + path + " with properties\n"
+ + " default displayName{String} to \"Hello\"\n"
+ + "end\n";
+ U.parseAndExecute(createPathCndStatement);
+
+ //verify it worked
+ U.assertNodeExists("/one");
+ ValueFactory vf = U.adminSession.getValueFactory();
+ U.assertSVPropertyExists("/one", "displayName", vf.createValue("Hello"));
+ }
+
}