kwin commented on code in PR #41: URL: https://github.com/apache/sling-org-apache-sling-jcr-repoinit/pull/41#discussion_r1049625048
########## 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: Well, not really unrelated because the idea is to set both mixins and primary type on existing nodes. The idea was to have some kind of (maybe premature) optimization here, and to allow for better logging (to distinguish between mixins already set and mixins added through repoinit). -- 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