@Test void getDocumentReferences(MockitoComponentManager componentManager) throws Exception { SpaceReference spaceReference = new SpaceReference("wiki", "Space"); Query query = mock(Query.class); QueryManager queryManager = componentManager.getInstance(QueryManager.class); when(queryManager.createQuery(any(), any())).thenReturn(query); EntityReferenceSerializer<String> localEntityReferenceSerializer = componentManager.getInstance(EntityReferenceSerializer.TYPE_STRING, "local"); when(localEntityReferenceSerializer.serialize(spaceReference)).thenReturn("Space"); when(query.execute()).thenReturn(Arrays.<Object>asList("Page")); DocumentReferenceResolver<String> explicitDocumentReferenceResolver = componentManager.getInstance(DocumentReferenceResolver.TYPE_STRING, "explicit"); DocumentReference documentReference = new DocumentReference("Page", spaceReference); when(explicitDocumentReferenceResolver.resolve("Page", spaceReference)).thenReturn(documentReference); assertEquals(Arrays.asList(documentReference), this.modelBridge.getDocumentReferences(spaceReference)); verify(query).setWiki(spaceReference.getWikiReference().getName()); verify(query).bindValue("space", "Space"); verify(query).bindValue("spacePrefix", "Space.%"); }
@Override public List<DocumentReference> getDocumentReferences(SpaceReference spaceReference) { try { String statement = "select distinct(doc.fullName) from XWikiDocument as doc " + "where doc.space = :space or doc.space like :spacePrefix escape '/'"; Query query = this.queryManager.createQuery(statement, Query.HQL); query.setWiki(spaceReference.getWikiReference().getName()); String localSpaceReference = this.localEntityReferenceSerializer.serialize(spaceReference); query.bindValue("space", localSpaceReference); String spacePrefix = LIKE_SPECIAL_CHARS.matcher(localSpaceReference).replaceAll("/$1"); query.bindValue("spacePrefix", spacePrefix + ".%"); List<DocumentReference> descendants = new ArrayList<>(); for (Object fullName : query.execute()) { descendants.add(this.explicitDocumentReferenceResolver.resolve((String) fullName, spaceReference)); } return descendants; } catch (Exception e) { this.logger.error("Failed to retrieve the documents from [{}].", spaceReference, e); return Collections.emptyList(); } }
DefaultModelBridge implements ModelBridge { @Override public List<DocumentReference> getDocumentReferences(SpaceReference spaceReference) { try { String statement = "select distinct(doc.fullName) from XWikiDocument as doc " + "where doc.space = :space or doc.space like :spacePrefix escape '/'"; Query query = this.queryManager.createQuery(statement, Query.HQL); query.setWiki(spaceReference.getWikiReference().getName()); String localSpaceReference = this.localEntityReferenceSerializer.serialize(spaceReference); query.bindValue("space", localSpaceReference); String spacePrefix = LIKE_SPECIAL_CHARS.matcher(localSpaceReference).replaceAll("/$1"); query.bindValue("spacePrefix", spacePrefix + ".%"); List<DocumentReference> descendants = new ArrayList<>(); for (Object fullName : query.execute()) { descendants.add(this.explicitDocumentReferenceResolver.resolve((String) fullName, spaceReference)); } return descendants; } catch (Exception e) { this.logger.error("Failed to retrieve the documents from [{}].", spaceReference, e); return Collections.emptyList(); } } }
DefaultModelBridge implements ModelBridge { @Override public List<DocumentReference> getDocumentReferences(SpaceReference spaceReference) { try { String statement = "select distinct(doc.fullName) from XWikiDocument as doc " + "where doc.space = :space or doc.space like :spacePrefix escape '/'"; Query query = this.queryManager.createQuery(statement, Query.HQL); query.setWiki(spaceReference.getWikiReference().getName()); String localSpaceReference = this.localEntityReferenceSerializer.serialize(spaceReference); query.bindValue("space", localSpaceReference); String spacePrefix = LIKE_SPECIAL_CHARS.matcher(localSpaceReference).replaceAll("/$1"); query.bindValue("spacePrefix", spacePrefix + ".%"); List<DocumentReference> descendants = new ArrayList<>(); for (Object fullName : query.execute()) { descendants.add(this.explicitDocumentReferenceResolver.resolve((String) fullName, spaceReference)); } return descendants; } catch (Exception e) { this.logger.error("Failed to retrieve the documents from [{}].", spaceReference, e); return Collections.emptyList(); } }  }
DefaultModelBridge implements ModelBridge { @Override public List<DocumentReference> getDocumentReferences(SpaceReference spaceReference) { try { String statement = "select distinct(doc.fullName) from XWikiDocument as doc " + "where doc.space = :space or doc.space like :spacePrefix escape '/'"; Query query = this.queryManager.createQuery(statement, Query.HQL); query.setWiki(spaceReference.getWikiReference().getName()); String localSpaceReference = this.localEntityReferenceSerializer.serialize(spaceReference); query.bindValue("space", localSpaceReference); String spacePrefix = LIKE_SPECIAL_CHARS.matcher(localSpaceReference).replaceAll("/$1"); query.bindValue("spacePrefix", spacePrefix + ".%"); List<DocumentReference> descendants = new ArrayList<>(); for (Object fullName : query.execute()) { descendants.add(this.explicitDocumentReferenceResolver.resolve((String) fullName, spaceReference)); } return descendants; } catch (Exception e) { this.logger.error("Failed to retrieve the documents from [{}].", spaceReference, e); return Collections.emptyList(); } }  @Override boolean create(DocumentReference documentReference); @Override boolean copy(DocumentReference source, DocumentReference destination); @Override boolean delete(DocumentReference reference); @Override boolean delete(DocumentReference reference, boolean skipRecycleBin); @Override boolean removeLock(DocumentReference reference); @Override void createRedirect(DocumentReference oldReference, DocumentReference newReference); @Override boolean canOverwriteSilently(DocumentReference documentReference); @Override boolean exists(DocumentReference reference); @Override List<DocumentReference> getBackLinkedReferences(DocumentReference documentReference, String wikiId); @Override List<DocumentReference> getDocumentReferences(SpaceReference spaceReference); @Override boolean updateParentField(final DocumentReference oldParentReference,
        final DocumentReference newParentReference); @Override DocumentReference setContextUserReference(DocumentReference userReference); @Override void update(DocumentReference documentReference, Map<String, String> parameters); @Override boolean restoreDeletedDocument(long deletedDocumentId, AbstractCheckRightsRequest request); @Override List<Long> getDeletedDocumentIds(String batchId); @Override boolean permanentlyDeleteDocument(long deletedDocumentId, AbstractCheckRightsRequest request); @Override boolean permanentlyDeleteAllDocuments(PermanentlyDeleteJob deleteJob, AbstractCheckRightsRequest request); @Override boolean rename(DocumentReference source, DocumentReference destination); }
DefaultModelBridge implements ModelBridge { @Override public List<DocumentReference> getDocumentReferences(SpaceReference spaceReference) { try { String statement = "select distinct(doc.fullName) from XWikiDocument as doc " + "where doc.space = :space or doc.space like :spacePrefix escape '/'"; Query query = this.queryManager.createQuery(statement, Query.HQL); query.setWiki(spaceReference.getWikiReference().getName()); String localSpaceReference = this.localEntityReferenceSerializer.serialize(spaceReference); query.bindValue("space", localSpaceReference); String spacePrefix = LIKE_SPECIAL_CHARS.matcher(localSpaceReference).replaceAll("/$1"); query.bindValue("spacePrefix", spacePrefix + ".%"); List<DocumentReference> descendants = new ArrayList<>(); for (Object fullName : query.execute()) { descendants.add(this.explicitDocumentReferenceResolver.resolve((String) fullName, spaceReference)); } return descendants; } catch (Exception e) { this.logger.error("Failed to retrieve the documents from [{}].", spaceReference, e); return Collections.emptyList(); } }  @Override boolean create(DocumentReference documentReference); @Override boolean copy(DocumentReference source, DocumentReference destination); @Override boolean delete(DocumentReference reference); @Override boolean delete(DocumentReference reference, boolean skipRecycleBin); @Override boolean removeLock(DocumentReference reference); @Override void createRedirect(DocumentReference oldReference, DocumentReference newReference); @Override boolean canOverwriteSilently(DocumentReference documentReference); @Override boolean exists(DocumentReference reference); @Override List<DocumentReference> getBackLinkedReferences(DocumentReference documentReference, String wikiId); @Override List<DocumentReference> getDocumentReferences(SpaceReference spaceReference); @Override boolean updateParentField(final DocumentReference oldParentReference,
        final DocumentReference newParentReference); @Override DocumentReference setContextUserReference(DocumentReference userReference); @Override void update(DocumentReference documentReference, Map<String, String> parameters); @Override boolean restoreDeletedDocument(long deletedDocumentId, AbstractCheckRightsRequest request); @Override List<Long> getDeletedDocumentIds(String batchId); @Override boolean permanentlyDeleteDocument(long deletedDocumentId, AbstractCheckRightsRequest request); @Override boolean permanentlyDeleteAllDocuments(PermanentlyDeleteJob deleteJob, AbstractCheckRightsRequest request); @Override boolean rename(DocumentReference source, DocumentReference destination);  }