@Test public void testNodeToRootNodeTypeScoped() throws Exception { TestUtil.withInMemoryRepo(session -> { TestUtil.installCndFromURL(session, getClass().getResource("/sling_nodetypes.cnd")); final NamespaceMapping mapping = new NamespaceMapping(new SessionNamespaceResolver(session)); Node node1 = JcrUtils.getOrCreateByPath("/test/node1", "nt:folder", session); node1.addMixin("mix:title"); node1.addMixin("sling:Resource"); node1.addMixin("sling:ResourceSuperType"); ChecklistExporter mixExporter = new ChecklistExporter.Builder().withNodeTypeFilters( Rules.fromJsonArray(arr(key("type", "include").key("pattern", "mix:.*")) .get())).build(); ChecklistExporter slingExporter = new ChecklistExporter.Builder().withNodeTypeFilters( Rules.fromJsonArray(arr(key("type", "include").key("pattern", "sling:.*")) .get())).build(); ChecklistExporter rtExporter = new ChecklistExporter.Builder().withNodeTypeFilters( Rules.fromJsonArray(arr(key("type", "include").key("pattern", "sling:Resource")) .get())).build(); ForcedRoot mixRoot = mixExporter.nodeToRoot(node1, mapping).orElse(null); assertNotNull("mixRoot should not be null", mixRoot); assertTrue("mixRoot should contain mix:title mixin", mixRoot.getMixinTypes().contains("mix:title")); assertFalse("mixRoot should not contain sling:Resource mixin", mixRoot.getMixinTypes().contains("sling:Resource")); assertFalse("mixRoot should not contain sling:ResourceSuperType mixin", mixRoot.getMixinTypes().contains("sling:ResourceSuperType")); ForcedRoot slingRoot = slingExporter.nodeToRoot(node1, mapping).orElse(null); assertNotNull("slingRoot should not be null", slingRoot); assertFalse("slingRoot should not contain mix:title mixin", slingRoot.getMixinTypes().contains("mix:title")); assertTrue("slingRoot should contain sling:Resource mixin", slingRoot.getMixinTypes().contains("sling:Resource")); assertTrue("slingRoot should contain sling:ResourceSuperType mixin", slingRoot.getMixinTypes().contains("sling:ResourceSuperType")); ForcedRoot rtRoot = rtExporter.nodeToRoot(node1, mapping).orElse(null); assertNotNull("rtRoot should not be null", rtRoot); assertNull("rtRoot primaryType should be null", rtRoot.getPrimaryType()); assertFalse("rtRoot should not contain mix:title mixin", rtRoot.getMixinTypes().contains("mix:title")); assertTrue("rtRoot should contain sling:Resource mixin", rtRoot.getMixinTypes().contains("sling:Resource")); assertFalse("rtRoot should not contain sling:ResourceSuperType mixin", rtRoot.getMixinTypes().contains("sling:ResourceSuperType")); }); }
Optional<ForcedRoot> nodeToRoot(final Node node, final NamespaceMapping mapping) throws RepositoryException { if (Rules.lastMatch(pathScopes, node.getPath()).isExclude()) { return Optional.empty(); } ForcedRoot forcedRoot = new ForcedRoot(); forcedRoot.setPath(node.getPath()); final String primaryType = node.getPrimaryNodeType().getName(); if (Rules.lastMatch(nodeTypeFilters, QName.parseQName(mapping, QName.Type.NODETYPE, primaryType).toString()).isInclude()) { forcedRoot.setPrimaryType(primaryType); } final List<String> mixinTypes = Stream.of(node.getMixinNodeTypes()) .map(compose1(NodeType::getName, qName -> QName.parseQName(mapping, QName.Type.NODETYPE, qName).toString())) .filter(name -> Rules.lastMatch(nodeTypeFilters, name).isInclude()) .collect(Collectors.toList()); forcedRoot.setMixinTypes(mixinTypes); return Optional.of(forcedRoot); }
ChecklistExporter { Optional<ForcedRoot> nodeToRoot(final Node node, final NamespaceMapping mapping) throws RepositoryException { if (Rules.lastMatch(pathScopes, node.getPath()).isExclude()) { return Optional.empty(); } ForcedRoot forcedRoot = new ForcedRoot(); forcedRoot.setPath(node.getPath()); final String primaryType = node.getPrimaryNodeType().getName(); if (Rules.lastMatch(nodeTypeFilters, QName.parseQName(mapping, QName.Type.NODETYPE, primaryType).toString()).isInclude()) { forcedRoot.setPrimaryType(primaryType); } final List<String> mixinTypes = Stream.of(node.getMixinNodeTypes()) .map(compose1(NodeType::getName, qName -> QName.parseQName(mapping, QName.Type.NODETYPE, qName).toString())) .filter(name -> Rules.lastMatch(nodeTypeFilters, name).isInclude()) .collect(Collectors.toList()); forcedRoot.setMixinTypes(mixinTypes); return Optional.of(forcedRoot); } }
ChecklistExporter { Optional<ForcedRoot> nodeToRoot(final Node node, final NamespaceMapping mapping) throws RepositoryException { if (Rules.lastMatch(pathScopes, node.getPath()).isExclude()) { return Optional.empty(); } ForcedRoot forcedRoot = new ForcedRoot(); forcedRoot.setPath(node.getPath()); final String primaryType = node.getPrimaryNodeType().getName(); if (Rules.lastMatch(nodeTypeFilters, QName.parseQName(mapping, QName.Type.NODETYPE, primaryType).toString()).isInclude()) { forcedRoot.setPrimaryType(primaryType); } final List<String> mixinTypes = Stream.of(node.getMixinNodeTypes()) .map(compose1(NodeType::getName, qName -> QName.parseQName(mapping, QName.Type.NODETYPE, qName).toString())) .filter(name -> Rules.lastMatch(nodeTypeFilters, name).isInclude()) .collect(Collectors.toList()); forcedRoot.setMixinTypes(mixinTypes); return Optional.of(forcedRoot); } private  ChecklistExporter(final List<Op> operations,
                              final List<String> exportTypeDefs,
                              final List<Rule> pathScopes,
                              final List<Rule> nodeTypeFilters,
                              final List<JcrNs> jcrNamespaces); }
ChecklistExporter { Optional<ForcedRoot> nodeToRoot(final Node node, final NamespaceMapping mapping) throws RepositoryException { if (Rules.lastMatch(pathScopes, node.getPath()).isExclude()) { return Optional.empty(); } ForcedRoot forcedRoot = new ForcedRoot(); forcedRoot.setPath(node.getPath()); final String primaryType = node.getPrimaryNodeType().getName(); if (Rules.lastMatch(nodeTypeFilters, QName.parseQName(mapping, QName.Type.NODETYPE, primaryType).toString()).isInclude()) { forcedRoot.setPrimaryType(primaryType); } final List<String> mixinTypes = Stream.of(node.getMixinNodeTypes()) .map(compose1(NodeType::getName, qName -> QName.parseQName(mapping, QName.Type.NODETYPE, qName).toString())) .filter(name -> Rules.lastMatch(nodeTypeFilters, name).isInclude()) .collect(Collectors.toList()); forcedRoot.setMixinTypes(mixinTypes); return Optional.of(forcedRoot); } private  ChecklistExporter(final List<Op> operations,
                              final List<String> exportTypeDefs,
                              final List<Rule> pathScopes,
                              final List<Rule> nodeTypeFilters,
                              final List<JcrNs> jcrNamespaces); void updateChecklist(final WriterOpener writerOpener,
                                final Session session,
                                final Checklist checklist,
                                final ForcedRootUpdatePolicy updatePolicy); List<ForcedRoot> findRoots(final Session session); }
ChecklistExporter { Optional<ForcedRoot> nodeToRoot(final Node node, final NamespaceMapping mapping) throws RepositoryException { if (Rules.lastMatch(pathScopes, node.getPath()).isExclude()) { return Optional.empty(); } ForcedRoot forcedRoot = new ForcedRoot(); forcedRoot.setPath(node.getPath()); final String primaryType = node.getPrimaryNodeType().getName(); if (Rules.lastMatch(nodeTypeFilters, QName.parseQName(mapping, QName.Type.NODETYPE, primaryType).toString()).isInclude()) { forcedRoot.setPrimaryType(primaryType); } final List<String> mixinTypes = Stream.of(node.getMixinNodeTypes()) .map(compose1(NodeType::getName, qName -> QName.parseQName(mapping, QName.Type.NODETYPE, qName).toString())) .filter(name -> Rules.lastMatch(nodeTypeFilters, name).isInclude()) .collect(Collectors.toList()); forcedRoot.setMixinTypes(mixinTypes); return Optional.of(forcedRoot); } private  ChecklistExporter(final List<Op> operations,
                              final List<String> exportTypeDefs,
                              final List<Rule> pathScopes,
                              final List<Rule> nodeTypeFilters,
                              final List<JcrNs> jcrNamespaces); void updateChecklist(final WriterOpener writerOpener,
                                final Session session,
                                final Checklist checklist,
                                final ForcedRootUpdatePolicy updatePolicy); List<ForcedRoot> findRoots(final Session session); static final ForcedRootUpdatePolicy DEFAULT_UPDATE_POLICY; static final String COVARIANT_PREFIX; }