@Test void getBackLinkedReferences() throws Exception { DocumentReference documentReference = new DocumentReference("alice", Arrays.asList("Path", "To"), "Page"); List<DocumentReference> backLinks = Arrays.asList(new DocumentReference("bob", "One", "Two")); when(xwiki.getStore().loadBacklinks(documentReference, true, this.xcontext)).thenReturn(backLinks); this.xcontext.setWikiId("carol"); assertEquals(backLinks, this.modelBridge.getBackLinkedReferences(documentReference, "bob")); verify(this.xcontext).setWikiId("bob"); verify(this.xcontext).setWikiId("carol"); }
@Override public List<DocumentReference> getBackLinkedReferences(DocumentReference documentReference, String wikiId) { XWikiContext xcontext = this.xcontextProvider.get(); String previousWikiId = xcontext.getWikiId(); try { xcontext.setWikiId(wikiId); return xcontext.getWiki().getStore().loadBacklinks(documentReference, true, xcontext); } catch (XWikiException e) { this.logger.error("Failed to retrieve the back-links for document [{}] on wiki [{}].", documentReference, wikiId, e); return Collections.emptyList(); } finally { xcontext.setWikiId(previousWikiId); } }
DefaultModelBridge implements ModelBridge { @Override public List<DocumentReference> getBackLinkedReferences(DocumentReference documentReference, String wikiId) { XWikiContext xcontext = this.xcontextProvider.get(); String previousWikiId = xcontext.getWikiId(); try { xcontext.setWikiId(wikiId); return xcontext.getWiki().getStore().loadBacklinks(documentReference, true, xcontext); } catch (XWikiException e) { this.logger.error("Failed to retrieve the back-links for document [{}] on wiki [{}].", documentReference, wikiId, e); return Collections.emptyList(); } finally { xcontext.setWikiId(previousWikiId); } } }
DefaultModelBridge implements ModelBridge { @Override public List<DocumentReference> getBackLinkedReferences(DocumentReference documentReference, String wikiId) { XWikiContext xcontext = this.xcontextProvider.get(); String previousWikiId = xcontext.getWikiId(); try { xcontext.setWikiId(wikiId); return xcontext.getWiki().getStore().loadBacklinks(documentReference, true, xcontext); } catch (XWikiException e) { this.logger.error("Failed to retrieve the back-links for document [{}] on wiki [{}].", documentReference, wikiId, e); return Collections.emptyList(); } finally { xcontext.setWikiId(previousWikiId); } }  }
DefaultModelBridge implements ModelBridge { @Override public List<DocumentReference> getBackLinkedReferences(DocumentReference documentReference, String wikiId) { XWikiContext xcontext = this.xcontextProvider.get(); String previousWikiId = xcontext.getWikiId(); try { xcontext.setWikiId(wikiId); return xcontext.getWiki().getStore().loadBacklinks(documentReference, true, xcontext); } catch (XWikiException e) { this.logger.error("Failed to retrieve the back-links for document [{}] on wiki [{}].", documentReference, wikiId, e); return Collections.emptyList(); } finally { xcontext.setWikiId(previousWikiId); } }  @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> getBackLinkedReferences(DocumentReference documentReference, String wikiId) { XWikiContext xcontext = this.xcontextProvider.get(); String previousWikiId = xcontext.getWikiId(); try { xcontext.setWikiId(wikiId); return xcontext.getWiki().getStore().loadBacklinks(documentReference, true, xcontext); } catch (XWikiException e) { this.logger.error("Failed to retrieve the back-links for document [{}] on wiki [{}].", documentReference, wikiId, e); return Collections.emptyList(); } finally { xcontext.setWikiId(previousWikiId); } }  @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);  }