IndexPathServiceImpl implements IndexPathService { @Override public Iterable<String> getIndexPaths() { NodeState nodeType = NodeStateUtils.getNode(nodeStore.getRoot(), "/oak:index/nodetype"); checkState("property".equals(nodeType.getString("type")), "nodetype index at " + "/oak:index/nodetype is found to be disabled. Cannot determine the paths of all indexes"); boolean indxDefnTypeIndexed = Iterables.contains(nodeType.getNames(DECLARING_NODE_TYPES), INDEX_DEFINITIONS_NODE_TYPE); if (!indxDefnTypeIndexed) { log.warn("{} is not found to be indexed as part of nodetype index. Non root indexes would " + "not be listed", INDEX_DEFINITIONS_NODE_TYPE); NodeState oakIndex = nodeStore.getRoot().getChildNode("oak:index"); return transform(filter(oakIndex.getChildNodeEntries(), cne -> INDEX_DEFINITIONS_NODE_TYPE.equals(cne.getNodeState().getName(JCR_PRIMARYTYPE))), cne -> PathUtils.concat("/oak:index", cne.getName())); } return () -> { Iterator<IndexRow> itr = getIndex().query(createFilter(INDEX_DEFINITIONS_NODE_TYPE), nodeStore.getRoot()); return transform(itr, input -> input.getPath()); }; } IndexPathServiceImpl();  IndexPathServiceImpl(NodeStore nodeStore);  IndexPathServiceImpl(NodeStore nodeStore, MountInfoProvider mountInfoProvider); @Override Iterable<String> getIndexPaths();  }
@Test public void noErrorIfQueryDefinitionsNotIndexed() throws Exception{ Set<String> paths = Sets.newHashSet(indexPathService.getIndexPaths()); assertThat(paths, hasItem("/oak:index/uuid")); }
@Test(expected = IllegalStateException.class) public void errorIfNodetypeIndexDisabled() throws Exception{ Tree tree = root.getTree("/oak:index/nodetype"); tree.setProperty("type", "disabled"); root.commit(); indexPathService.getIndexPaths(); }
@Test public void nodeTypeIndexed() throws Exception{ enableIndexDefinitionIndex(); Set<String> paths = Sets.newHashSet(indexPathService.getIndexPaths()); assertThat(paths, hasItem("/oak:index/uuid")); assertThat(paths, hasItem("/oak:index/nodetype")); assertThat(paths, hasItem("/oak:index/reference")); }
@Test public void indexInSubTree() throws Exception{ enableIndexDefinitionIndex(); Tree tree = root.getTree("/").addChild("a").addChild("b"); Tree fooIndex = tree.addChild("oak:index").addChild("fooIndex"); fooIndex.setProperty(JcrConstants.JCR_PRIMARYTYPE, INDEX_DEFINITIONS_NODE_TYPE, Type.NAME); fooIndex.setProperty("type", "disabled"); root.commit(); Set<String> paths = Sets.newHashSet(indexPathService.getIndexPaths()); assertThat(paths, hasItem("/a/b/oak:index/fooIndex")); }