@Test public void getChildDocuments() throws Exception { assertEquals(Collections.emptyList(), this.documentTreeNode.getChildDocuments(terminalDocumentReference, 0, 10)); this.documentTreeNode.getProperties().put("showTerminalDocuments", false); Query queryNonTerminalPagesByName = mock(Query.class, "nonTerminalPagesOrderedByTitle"); String statement = "select reference, 0 as terminal from XWikiSpace page order by lower(name), name"; when(this.queryManager.createQuery(statement, Query.HQL)).thenReturn(queryNonTerminalPagesByName); when(queryNonTerminalPagesByName.addFilter(this.documentReferenceResolverFilter)) .thenReturn(queryNonTerminalPagesByName); DocumentReference childReference = new DocumentReference("wiki", Arrays.asList("Path.To.Page"), "Alice"); when(queryNonTerminalPagesByName.execute()).thenReturn(Collections.singletonList(childReference)); assertEquals(Collections.singletonList(childReference), this.documentTreeNode.getChildDocuments(documentReference, 5, 3)); verify(queryNonTerminalPagesByName).setWiki("wiki"); verify(queryNonTerminalPagesByName).setOffset(5); verify(queryNonTerminalPagesByName).setLimit(3); verify(queryNonTerminalPagesByName).addFilter(this.childPageFilter); verify(queryNonTerminalPagesByName).bindValue("parent", "Path.To.Page"); this.documentTreeNode.getProperties().put("orderBy", "title"); Query queryNonTerminalPagesByTitle = mock(Query.class, "nonTerminalPagesOrderedByTitle"); when(this.queryManager.getNamedQuery("nonTerminalPagesOrderedByTitle")) .thenReturn(queryNonTerminalPagesByTitle); childReference = new DocumentReference("wiki", Arrays.asList("Path.To.Page"), "Bob"); when(queryNonTerminalPagesByTitle.addFilter(this.documentReferenceResolverFilter)) .thenReturn(queryNonTerminalPagesByTitle); when(queryNonTerminalPagesByTitle.execute()).thenReturn(Collections.singletonList(childReference)); when(this.localizationContext.getCurrentLocale()).thenReturn(Locale.GERMAN); assertEquals(Collections.singletonList(childReference), this.documentTreeNode.getChildDocuments(documentReference, 0, 5)); verify(queryNonTerminalPagesByTitle).bindValue("locale", "de"); }
protected List<DocumentReference> getChildDocuments(DocumentReference documentReference, int offset, int limit) throws QueryException { if (!getDefaultDocumentName().equals(documentReference.getName())) { return Collections.emptyList(); } String orderBy = getOrderBy(); Query query; if (areTerminalDocumentsShown()) { if (FIELD_TITLE.equals(orderBy)) { query = this.queryManager.getNamedQuery("nestedPagesOrderedByTitle"); query.bindValue(PARAMETER_LOCALE, this.localizationContext.getCurrentLocale().toString()); } else { query = this.queryManager.getNamedQuery("nestedPagesOrderedByName"); } Set<String> excludedDocuments = getExcludedDocuments(documentReference.getParent()); if (!excludedDocuments.isEmpty()) { query.bindValue(PARAMETER_EXCLUDED_DOCUMENTS, excludedDocuments); query.addFilter(this.excludedDocumentFilter); } } else { if (FIELD_TITLE.equals(orderBy)) { query = this.queryManager.getNamedQuery("nonTerminalPagesOrderedByTitle"); query.bindValue(PARAMETER_LOCALE, this.localizationContext.getCurrentLocale().toString()); } else { query = this.queryManager.createQuery( "select reference, 0 as terminal from XWikiSpace page order by lower(name), name", Query.HQL); } } query.setWiki(documentReference.getWikiReference().getName()); query.setOffset(offset); query.setLimit(limit); query.addFilter(this.childPageFilter); query.bindValue("parent", this.localEntityReferenceSerializer.serialize(documentReference.getParent())); if (!areHiddenEntitiesShown()) { query.addFilter(this.hiddenPageFilter); } Set<String> excludedSpaces = getExcludedSpaces(documentReference.getParent()); if (!excludedSpaces.isEmpty()) { query.bindValue("excludedSpaces", excludedSpaces); query.addFilter(this.excludedSpaceFilter); } return query.addFilter(this.documentReferenceResolverFilter).execute(); }
DocumentTreeNode extends AbstractDocumentTreeNode implements Initializable { protected List<DocumentReference> getChildDocuments(DocumentReference documentReference, int offset, int limit) throws QueryException { if (!getDefaultDocumentName().equals(documentReference.getName())) { return Collections.emptyList(); } String orderBy = getOrderBy(); Query query; if (areTerminalDocumentsShown()) { if (FIELD_TITLE.equals(orderBy)) { query = this.queryManager.getNamedQuery("nestedPagesOrderedByTitle"); query.bindValue(PARAMETER_LOCALE, this.localizationContext.getCurrentLocale().toString()); } else { query = this.queryManager.getNamedQuery("nestedPagesOrderedByName"); } Set<String> excludedDocuments = getExcludedDocuments(documentReference.getParent()); if (!excludedDocuments.isEmpty()) { query.bindValue(PARAMETER_EXCLUDED_DOCUMENTS, excludedDocuments); query.addFilter(this.excludedDocumentFilter); } } else { if (FIELD_TITLE.equals(orderBy)) { query = this.queryManager.getNamedQuery("nonTerminalPagesOrderedByTitle"); query.bindValue(PARAMETER_LOCALE, this.localizationContext.getCurrentLocale().toString()); } else { query = this.queryManager.createQuery( "select reference, 0 as terminal from XWikiSpace page order by lower(name), name", Query.HQL); } } query.setWiki(documentReference.getWikiReference().getName()); query.setOffset(offset); query.setLimit(limit); query.addFilter(this.childPageFilter); query.bindValue("parent", this.localEntityReferenceSerializer.serialize(documentReference.getParent())); if (!areHiddenEntitiesShown()) { query.addFilter(this.hiddenPageFilter); } Set<String> excludedSpaces = getExcludedSpaces(documentReference.getParent()); if (!excludedSpaces.isEmpty()) { query.bindValue("excludedSpaces", excludedSpaces); query.addFilter(this.excludedSpaceFilter); } return query.addFilter(this.documentReferenceResolverFilter).execute(); } }
DocumentTreeNode extends AbstractDocumentTreeNode implements Initializable { protected List<DocumentReference> getChildDocuments(DocumentReference documentReference, int offset, int limit) throws QueryException { if (!getDefaultDocumentName().equals(documentReference.getName())) { return Collections.emptyList(); } String orderBy = getOrderBy(); Query query; if (areTerminalDocumentsShown()) { if (FIELD_TITLE.equals(orderBy)) { query = this.queryManager.getNamedQuery("nestedPagesOrderedByTitle"); query.bindValue(PARAMETER_LOCALE, this.localizationContext.getCurrentLocale().toString()); } else { query = this.queryManager.getNamedQuery("nestedPagesOrderedByName"); } Set<String> excludedDocuments = getExcludedDocuments(documentReference.getParent()); if (!excludedDocuments.isEmpty()) { query.bindValue(PARAMETER_EXCLUDED_DOCUMENTS, excludedDocuments); query.addFilter(this.excludedDocumentFilter); } } else { if (FIELD_TITLE.equals(orderBy)) { query = this.queryManager.getNamedQuery("nonTerminalPagesOrderedByTitle"); query.bindValue(PARAMETER_LOCALE, this.localizationContext.getCurrentLocale().toString()); } else { query = this.queryManager.createQuery( "select reference, 0 as terminal from XWikiSpace page order by lower(name), name", Query.HQL); } } query.setWiki(documentReference.getWikiReference().getName()); query.setOffset(offset); query.setLimit(limit); query.addFilter(this.childPageFilter); query.bindValue("parent", this.localEntityReferenceSerializer.serialize(documentReference.getParent())); if (!areHiddenEntitiesShown()) { query.addFilter(this.hiddenPageFilter); } Set<String> excludedSpaces = getExcludedSpaces(documentReference.getParent()); if (!excludedSpaces.isEmpty()) { query.bindValue("excludedSpaces", excludedSpaces); query.addFilter(this.excludedSpaceFilter); } return query.addFilter(this.documentReferenceResolverFilter).execute(); } DocumentTreeNode(); }
DocumentTreeNode extends AbstractDocumentTreeNode implements Initializable { protected List<DocumentReference> getChildDocuments(DocumentReference documentReference, int offset, int limit) throws QueryException { if (!getDefaultDocumentName().equals(documentReference.getName())) { return Collections.emptyList(); } String orderBy = getOrderBy(); Query query; if (areTerminalDocumentsShown()) { if (FIELD_TITLE.equals(orderBy)) { query = this.queryManager.getNamedQuery("nestedPagesOrderedByTitle"); query.bindValue(PARAMETER_LOCALE, this.localizationContext.getCurrentLocale().toString()); } else { query = this.queryManager.getNamedQuery("nestedPagesOrderedByName"); } Set<String> excludedDocuments = getExcludedDocuments(documentReference.getParent()); if (!excludedDocuments.isEmpty()) { query.bindValue(PARAMETER_EXCLUDED_DOCUMENTS, excludedDocuments); query.addFilter(this.excludedDocumentFilter); } } else { if (FIELD_TITLE.equals(orderBy)) { query = this.queryManager.getNamedQuery("nonTerminalPagesOrderedByTitle"); query.bindValue(PARAMETER_LOCALE, this.localizationContext.getCurrentLocale().toString()); } else { query = this.queryManager.createQuery( "select reference, 0 as terminal from XWikiSpace page order by lower(name), name", Query.HQL); } } query.setWiki(documentReference.getWikiReference().getName()); query.setOffset(offset); query.setLimit(limit); query.addFilter(this.childPageFilter); query.bindValue("parent", this.localEntityReferenceSerializer.serialize(documentReference.getParent())); if (!areHiddenEntitiesShown()) { query.addFilter(this.hiddenPageFilter); } Set<String> excludedSpaces = getExcludedSpaces(documentReference.getParent()); if (!excludedSpaces.isEmpty()) { query.bindValue("excludedSpaces", excludedSpaces); query.addFilter(this.excludedSpaceFilter); } return query.addFilter(this.documentReferenceResolverFilter).execute(); } DocumentTreeNode(); @Override void initialize(); }
DocumentTreeNode extends AbstractDocumentTreeNode implements Initializable { protected List<DocumentReference> getChildDocuments(DocumentReference documentReference, int offset, int limit) throws QueryException { if (!getDefaultDocumentName().equals(documentReference.getName())) { return Collections.emptyList(); } String orderBy = getOrderBy(); Query query; if (areTerminalDocumentsShown()) { if (FIELD_TITLE.equals(orderBy)) { query = this.queryManager.getNamedQuery("nestedPagesOrderedByTitle"); query.bindValue(PARAMETER_LOCALE, this.localizationContext.getCurrentLocale().toString()); } else { query = this.queryManager.getNamedQuery("nestedPagesOrderedByName"); } Set<String> excludedDocuments = getExcludedDocuments(documentReference.getParent()); if (!excludedDocuments.isEmpty()) { query.bindValue(PARAMETER_EXCLUDED_DOCUMENTS, excludedDocuments); query.addFilter(this.excludedDocumentFilter); } } else { if (FIELD_TITLE.equals(orderBy)) { query = this.queryManager.getNamedQuery("nonTerminalPagesOrderedByTitle"); query.bindValue(PARAMETER_LOCALE, this.localizationContext.getCurrentLocale().toString()); } else { query = this.queryManager.createQuery( "select reference, 0 as terminal from XWikiSpace page order by lower(name), name", Query.HQL); } } query.setWiki(documentReference.getWikiReference().getName()); query.setOffset(offset); query.setLimit(limit); query.addFilter(this.childPageFilter); query.bindValue("parent", this.localEntityReferenceSerializer.serialize(documentReference.getParent())); if (!areHiddenEntitiesShown()) { query.addFilter(this.hiddenPageFilter); } Set<String> excludedSpaces = getExcludedSpaces(documentReference.getParent()); if (!excludedSpaces.isEmpty()) { query.bindValue("excludedSpaces", excludedSpaces); query.addFilter(this.excludedSpaceFilter); } return query.addFilter(this.documentReferenceResolverFilter).execute(); } DocumentTreeNode(); @Override void initialize();  }