use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.
the class DefaultModelBridge method getHierarchicalParent.
private DocumentReference getHierarchicalParent(DocumentReference documentReference) {
final String spaceHomePage = entityReferenceProvider.getDefaultReference(EntityType.DOCUMENT).getName();
EntityReference parentOfTheSpace = documentReference.getLastSpaceReference().getParent();
boolean pageIsNotTerminal = documentReference.getName().equals(spaceHomePage);
// The parent should be A.B.WebHome
if (pageIsNotTerminal && parentOfTheSpace.getType() == EntityType.SPACE) {
return new DocumentReference(spaceHomePage, new SpaceReference(parentOfTheSpace));
}
// The parent should be Main.WebHome
if (pageIsNotTerminal && parentOfTheSpace.getType() == EntityType.WIKI) {
return new DocumentReference(spaceHomePage, new SpaceReference(entityReferenceProvider.getDefaultReference(EntityType.SPACE).getName(), documentReference.getWikiReference()));
}
// The parent should be A.WebHome
return new DocumentReference(spaceHomePage, documentReference.getLastSpaceReference());
}
use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.
the class DefaultLinkRefactoringTest method updateRelativeLinksAcrossWikis.
@Test
public void updateRelativeLinksAcrossWikis() throws Exception {
DocumentReference oldReference = new DocumentReference("wiki1", "A", "B");
DocumentReference newReference = new DocumentReference("wiki2", "X", "Y");
XWikiDocument newDocument = mock(XWikiDocument.class);
when(this.xcontext.getWiki().getDocument(newReference, this.xcontext)).thenReturn(newDocument);
when(newDocument.getDocumentReference()).thenReturn(newReference);
when(newDocument.getSyntax()).thenReturn(Syntax.XWIKI_2_1);
this.mocker.registerMockComponent(BlockRenderer.class, Syntax.XWIKI_2_1.toIdString());
XDOM xdom = mock(XDOM.class);
when(newDocument.getXDOM()).thenReturn(xdom);
ResourceReference docLinkReference = new ResourceReference("C", ResourceType.DOCUMENT);
LinkBlock docLinkBlock = new LinkBlock(Collections.<Block>emptyList(), docLinkReference, false);
ResourceReference spaceLinkReference = new ResourceReference("Z", ResourceType.SPACE);
LinkBlock spaceLinkBlock = new LinkBlock(Collections.<Block>emptyList(), spaceLinkReference, false);
when(xdom.getBlocks(any(), eq(Block.Axes.DESCENDANT))).thenReturn(Arrays.<Block>asList(docLinkBlock, spaceLinkBlock));
DocumentReference originalDocLinkReference = new DocumentReference("C", oldReference.getLastSpaceReference());
when(this.resourceReferenceResolver.resolve(docLinkReference, null, oldReference)).thenReturn(originalDocLinkReference);
DocumentReference newDocLinkReference = new DocumentReference("C", newReference.getLastSpaceReference());
when(this.resourceReferenceResolver.resolve(docLinkReference, null, newReference)).thenReturn(newDocLinkReference);
SpaceReference originalSpaceReference = new SpaceReference("wiki1", "Z");
when(this.resourceReferenceResolver.resolve(spaceLinkReference, null, oldReference)).thenReturn(originalSpaceReference);
SpaceReference newSpaceReference = new SpaceReference("wiki2", "Z");
when(this.resourceReferenceResolver.resolve(spaceLinkReference, null, newReference)).thenReturn(newSpaceReference);
when(this.compactEntityReferenceSerializer.serialize(originalDocLinkReference, newReference)).thenReturn("wiki1:A.C");
when(this.compactEntityReferenceSerializer.serialize(originalSpaceReference, newReference)).thenReturn("wiki1:Z");
this.mocker.getComponentUnderTest().updateRelativeLinks(oldReference, newReference);
// Document link block is updated.
assertEquals("wiki1:A.C", docLinkBlock.getReference().getReference());
assertEquals(ResourceType.DOCUMENT, docLinkBlock.getReference().getType());
// Space link is also updated, since they were referring entities on a different wiki.
assertEquals("wiki1:Z", spaceLinkBlock.getReference().getReference());
assertEquals(ResourceType.SPACE, spaceLinkBlock.getReference().getType());
verifyDocumentSave(newDocument, "Updated the relative links.", true);
}
use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.
the class DefaultLinkRefactoringTest method updateRelativeLinks.
@Test
public void updateRelativeLinks() throws Exception {
DocumentReference oldReference = new DocumentReference("wiki", "A", "B");
DocumentReference newReference = new DocumentReference("wiki", "X", "Y");
XWikiDocument newDocument = mock(XWikiDocument.class);
when(this.xcontext.getWiki().getDocument(newReference, this.xcontext)).thenReturn(newDocument);
when(newDocument.getDocumentReference()).thenReturn(newReference);
when(newDocument.getSyntax()).thenReturn(Syntax.XWIKI_2_1);
this.mocker.registerMockComponent(BlockRenderer.class, Syntax.XWIKI_2_1.toIdString());
XDOM xdom = mock(XDOM.class);
when(newDocument.getXDOM()).thenReturn(xdom);
ResourceReference docLinkReference = new ResourceReference("C", ResourceType.DOCUMENT);
LinkBlock docLinkBlock = new LinkBlock(Collections.<Block>emptyList(), docLinkReference, false);
ResourceReference spaceLinkReference = new ResourceReference("Z", ResourceType.SPACE);
LinkBlock spaceLinkBlock = new LinkBlock(Collections.<Block>emptyList(), spaceLinkReference, false);
when(xdom.getBlocks(any(), eq(Block.Axes.DESCENDANT))).thenReturn(Arrays.<Block>asList(docLinkBlock, spaceLinkBlock));
DocumentReference originalDocLinkReference = new DocumentReference("C", oldReference.getLastSpaceReference());
when(this.resourceReferenceResolver.resolve(docLinkReference, null, oldReference)).thenReturn(originalDocLinkReference);
DocumentReference newDocLinkReference = new DocumentReference("C", newReference.getLastSpaceReference());
when(this.resourceReferenceResolver.resolve(docLinkReference, null, newReference)).thenReturn(newDocLinkReference);
SpaceReference originalSpaceReference = new SpaceReference("wiki", "Z");
when(this.resourceReferenceResolver.resolve(spaceLinkReference, null, oldReference)).thenReturn(originalSpaceReference);
when(this.resourceReferenceResolver.resolve(spaceLinkReference, null, newReference)).thenReturn(originalSpaceReference);
when(this.compactEntityReferenceSerializer.serialize(originalDocLinkReference, newReference)).thenReturn("A.C");
this.mocker.getComponentUnderTest().updateRelativeLinks(oldReference, newReference);
// Document link block is updated.
assertEquals("A.C", docLinkBlock.getReference().getReference());
assertEquals(ResourceType.DOCUMENT, docLinkBlock.getReference().getType());
// Space link block stays the same, since they were on the same wiki.
assertEquals("Z", spaceLinkBlock.getReference().getReference());
assertEquals(ResourceType.SPACE, spaceLinkBlock.getReference().getType());
verifyDocumentSave(newDocument, "Updated the relative links.", true);
}
use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.
the class DefaultLinkRefactoringTest method renameNonTerminalToTerminalDocumentLinks.
@Test
public void renameNonTerminalToTerminalDocumentLinks() throws Exception {
DocumentReference documentReference = new DocumentReference("wiki", "Space", "Page");
XWikiDocument document = mock(XWikiDocument.class);
when(this.xcontext.getWiki().getDocument(documentReference, this.xcontext)).thenReturn(document);
when(document.getDocumentReference()).thenReturn(documentReference);
when(document.getSyntax()).thenReturn(Syntax.XWIKI_2_1);
this.mocker.registerMockComponent(BlockRenderer.class, Syntax.XWIKI_2_1.toIdString());
// From a non-terminal document to a terminal document.
DocumentReference oldLinkTarget = new DocumentReference("wiki", "A", "WebHome");
DocumentReference newLinkTarget = new DocumentReference("wiki", "X", "Y");
XDOM xdom = mock(XDOM.class);
when(document.getXDOM()).thenReturn(xdom);
ResourceReference docLinkReference = new ResourceReference("A.WebHome", ResourceType.DOCUMENT);
LinkBlock documentLinkBlock = new LinkBlock(Collections.<Block>emptyList(), docLinkReference, false);
ResourceReference spaceLinkReference = new ResourceReference("A", ResourceType.SPACE);
LinkBlock spaceLinkBlock = new LinkBlock(Collections.<Block>emptyList(), spaceLinkReference, false);
when(xdom.getBlocks(any(), eq(Block.Axes.DESCENDANT))).thenReturn(Arrays.<Block>asList(documentLinkBlock, spaceLinkBlock));
// Doc link
when(this.resourceReferenceResolver.resolve(docLinkReference, null, documentReference)).thenReturn(oldLinkTarget);
when(this.defaultReferenceDocumentReferenceResolver.resolve(oldLinkTarget)).thenReturn(oldLinkTarget);
when(this.compactEntityReferenceSerializer.serialize(newLinkTarget, documentReference)).thenReturn("X.Y");
// Space link
SpaceReference spaceReference = oldLinkTarget.getLastSpaceReference();
when(this.resourceReferenceResolver.resolve(spaceLinkReference, null, documentReference)).thenReturn(spaceReference);
when(this.defaultReferenceDocumentReferenceResolver.resolve(spaceReference)).thenReturn(oldLinkTarget);
when(this.compactEntityReferenceSerializer.serialize(newLinkTarget.getLastSpaceReference(), documentReference)).thenReturn("X");
this.mocker.getComponentUnderTest().renameLinks(documentReference, oldLinkTarget, newLinkTarget);
// Note that both resulting renamed back-links are of type document. (i.e. the space link was converted to a doc
// link)
assertEquals("X.Y", documentLinkBlock.getReference().getReference());
assertEquals(ResourceType.DOCUMENT, documentLinkBlock.getReference().getType());
assertEquals("X.Y", spaceLinkBlock.getReference().getReference());
assertEquals(ResourceType.DOCUMENT, spaceLinkBlock.getReference().getType());
verifyDocumentSave(document, "Renamed back-links.", false);
}
use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.
the class DefaultModelBridgeTest method configure.
@Before
public void configure() throws Exception {
when(this.xcontext.getWiki()).thenReturn(xwiki);
Provider<XWikiContext> xcontextProvider = this.mocker.getInstance(XWikiContext.TYPE_PROVIDER);
when(xcontextProvider.get()).thenReturn(this.xcontext);
EntityReferenceProvider entityReferenceProvider = this.mocker.getInstance(EntityReferenceProvider.class);
when(entityReferenceProvider.getDefaultReference(EntityType.DOCUMENT)).thenReturn(new DocumentReference("what", "ever", "WebHome"));
when(entityReferenceProvider.getDefaultReference(EntityType.SPACE)).thenReturn(new SpaceReference("whatever", "Main"));
}
Aggregations