@Test public void testNodeToRootPathScoped() throws Exception { TestUtil.withInMemoryRepo(session -> { final NamespaceMapping mapping = new NamespaceMapping(new SessionNamespaceResolver(session)); TestUtil.installCndFromURL(session, getClass().getResource("/sling_nodetypes.cnd")); Node node1 = JcrUtils.getOrCreateByPath("/test_include/node1", "nt:folder", session); Node node2 = JcrUtils.getOrCreateByPath("/test_exclude/node2", "nt:folder", session); ChecklistExporter exporter = new ChecklistExporter.Builder() .withScopePaths(Rules .fromJsonArray(arr(key("type", "include").key("pattern", "/test_include(/.*)?")) .get())).build(); ForcedRoot root1 = exporter.nodeToRoot(node1, mapping).orElse(null); assertNotNull("root1 should not be null", root1); ForcedRoot root2 = exporter.nodeToRoot(node2, mapping).orElse(null); assertNull("root2 should be null", root2); }); }
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; }