anchela commented on code in PR #41:
URL: 
https://github.com/apache/sling-org-apache-sling-jcr-repoinit/pull/41#discussion_r1049651725


##########
src/main/java/org/apache/sling/jcr/repoinit/impl/NodeVisitor.java:
##########
@@ -57,18 +59,33 @@ public void visitCreatePath(CreatePath cp) {
             String parentPath = parentPathBuilder.toString();
             final String fullPath = String.format("%s/%s", parentPath, 
psd.getSegment());
             try {
-                if (session.itemExists(fullPath)) {
-                    log.info("Path already exists, nothing to do (and not 
checking its primary type for now): {}", fullPath);
-                } else {
+                final Node node;
+                if (session.nodeExists(fullPath)) {
+                    log.info("Node at {} already exists, checking/adjusting 
its types", fullPath);
+                    node = session.getNode(fullPath);
+                    if (psd.getPrimaryType() != null && 
!node.getPrimaryNodeType().getName().equals(psd.getPrimaryType())) {
+                        log.info("Adjusting primary type of node {} to {}", 
fullPath, psd.getPrimaryType());
+                        node.setPrimaryType(psd.getPrimaryType());
+                    }
+                } else if (!session.propertyExists(fullPath)) {
                     final Node parent = parentPath.equals("") ? 
session.getRootNode() : session.getNode(parentPath);
                     log.info("Creating node {} with primary type {}", 
fullPath, psd.getPrimaryType());
-                    Node node = addChildNode(parent, psd);
-                    List<String> mixins = psd.getMixins();
-                    if (mixins != null) {
-                        log.info("Adding mixins {} to node {}", mixins, 
fullPath);
-                        for (String mixin : mixins) {
-                            node.addMixin(mixin);
-                        }
+                    node = addChildNode(parent, psd);
+                    
+                } else {
+                    throw new RepoInitException("There is a property with the 
name of the to be created node already at " + fullPath + ", therefore bailing 
out here as potentially not supported by the underlying JCR");
+                }
+                List<String> mixinsToAdd = new ArrayList<>(psd.getMixins());
+                // don't add mixins already set on the node

Review Comment:
   no particular issue.... just seems unrelated to the original ticket and i am 
usually extra careful not to mix different issues.
   if you wanted change the semantic of the create path to enforce all node 
types, you might as well have to remove mixins that are not declared but 
present... but that would definitely cause regressions.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@sling.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to