use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.
the class EntityJobTest method visitDocuments.
@Test
public void visitDocuments() {
DocumentReference alice = new DocumentReference("foo", "Alice", "WebHome");
DocumentReference alicePrefs = new DocumentReference("WebPreferences", alice.getLastSpaceReference());
DocumentReference aliceBio = new DocumentReference("Bio", alice.getLastSpaceReference());
DocumentReference bob = new DocumentReference("foo", Arrays.asList("Alice", "Bob"), "WebHome");
DocumentReference bobPrefs = new DocumentReference("WebPreferences", bob.getLastSpaceReference());
DocumentReference bobBio = new DocumentReference("Bio", bob.getLastSpaceReference());
DocumentReference carolBio = new DocumentReference("bar", Arrays.asList("Users", "Carol"), "Bio");
SpaceReference spaceReference = mock(SpaceReference.class);
when(this.modelBridge.getDocumentReferences(spaceReference)).thenReturn(Arrays.asList(alice, alicePrefs, aliceBio, bob, bobPrefs, bobBio, carolBio));
NoopEntityJob job = new NoopEntityJob();
initialize(job, new EntityRequest());
final List<DocumentReference> documentReferences = new ArrayList<>();
job.visitDocuments(spaceReference, new Visitor<DocumentReference>() {
@Override
public void visit(DocumentReference documentReference) {
documentReferences.add(documentReference);
}
});
// Space preferences documents are handled after their siblings.
assertEquals(Arrays.asList(carolBio, aliceBio, bobBio, bob, bobPrefs, alice, alicePrefs), documentReferences);
}
use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.
the class SeparatePageRating method getPageReference.
/**
* Generate page name from the container page We add Rating and getUniquePageName will add us a counter to our page.
*
* @param documentRef reference to the document with which the rating is associated
* @return a reference to the document in which the rating is stored
*/
private DocumentReference getPageReference(DocumentReference documentRef) throws XWikiException {
XWikiDocument doc = context.getWiki().getDocument(documentRef, context);
String ratingsSpace = ratingsManager.getRatingsSpaceName(documentRef);
String pageSufix = "R";
boolean hasRatingsSpaceForeachSpace = ratingsManager.hasRatingsSpaceForeachSpace(documentRef);
SpaceReference spaceReference = doc.getDocumentReference().getLastSpaceReference();
spaceReference.replaceParent(spaceReference.getWikiReference(), this.context.getWikiReference());
if (hasRatingsSpaceForeachSpace) {
spaceReference = new SpaceReference(spaceReference.getName() + ratingsSpace, spaceReference.getParent());
String uniqueName = getUniquePageName(ratingsSpace, doc.getName(), pageSufix, true);
return new DocumentReference(uniqueName, spaceReference);
} else if (ratingsSpace == null) {
String uniqueName = getUniquePageName(doc.getSpace(), doc.getName() + pageSufix, "", true);
return new DocumentReference(uniqueName, spaceReference);
} else {
String uniqueName = getUniquePageName(ratingsSpace, doc.getSpace() + "_" + doc.getName(), pageSufix, true);
return new DocumentReference(context.getWikiId(), ratingsSpace, uniqueName);
}
}
use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.
the class DefaultRatingsConfiguration method getConfigurationDocument.
/**
* Get configuration document.
*
* @param documentReference the documentReference for which to return the configuration document
* @return the configuration document
*/
public XWikiDocument getConfigurationDocument(DocumentReference documentReference) {
SpaceReference lastSpaceReference = documentReference.getLastSpaceReference();
while (lastSpaceReference.getType() == EntityType.SPACE) {
DocumentReference configurationDocumentReference = new DocumentReference(RatingsManager.RATINGS_CONFIG_SPACE_PAGE, lastSpaceReference);
XWikiDocument spaceConfigurationDocument = getDocument((EntityReference) configurationDocumentReference);
if (spaceConfigurationDocument != null && spaceConfigurationDocument.getXObject(RatingsManager.RATINGS_CONFIG_CLASSREFERENCE) != null) {
return spaceConfigurationDocument;
}
if (lastSpaceReference.getParent().getType() == EntityType.SPACE) {
lastSpaceReference = new SpaceReference(lastSpaceReference.getParent());
} else {
break;
}
}
XWikiDocument globalConfigurationDocument = getDocument(RatingsManager.RATINGS_CONFIG_GLOBAL_REFERENCE);
return globalConfigurationDocument;
}
use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.
the class XWikiLinkLabelGeneratorTest method generateWhithPageNameWithPercent.
@Test
public void generateWhithPageNameWithPercent() throws Exception {
ResourceReference resourceReference = new DocumentResourceReference("HelloWorld");
DocumentReference documentReference = new DocumentReference("wiki", "space", "page%t");
EntityReferenceResolver<ResourceReference> resourceReferenceResolver = this.mocker.getInstance(new DefaultParameterizedType(null, EntityReferenceResolver.class, ResourceReference.class));
when(resourceReferenceResolver.resolve(resourceReference, EntityType.DOCUMENT)).thenReturn(documentReference);
DocumentAccessBridge dab = this.mocker.getInstance(DocumentAccessBridge.class);
DocumentModelBridge dmb = mock(DocumentModelBridge.class);
when(dab.getTranslatedDocumentInstance(documentReference)).thenReturn(dmb);
when(dmb.getTitle()).thenReturn("my title");
EntityReferenceSerializer<String> localSerializer = this.mocker.getInstance(EntityReferenceSerializer.TYPE_STRING, "local");
when(localSerializer.serialize(new SpaceReference("wiki", "space"))).thenReturn("space");
assertEquals("%l%la%n%na%N%NA " + "[wiki:space.page%t] space page%t page%t page%t (my title) " + "[wiki:space.page%t] space page%t page%t page%t (my title)", this.mocker.getComponentUnderTest().generate(resourceReference));
}
use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.
the class XWikiLinkLabelGeneratorTest method generateWhenDocumentTitleIsNull.
@Test
public void generateWhenDocumentTitleIsNull() throws Exception {
ResourceReference resourceReference = new DocumentResourceReference("HelloWorld");
DocumentReference documentReference = new DocumentReference("xwiki", "Main", "HelloWorld");
EntityReferenceResolver<ResourceReference> resourceReferenceResolver = this.mocker.getInstance(new DefaultParameterizedType(null, EntityReferenceResolver.class, ResourceReference.class));
when(resourceReferenceResolver.resolve(resourceReference, EntityType.DOCUMENT)).thenReturn(documentReference);
DocumentAccessBridge dab = this.mocker.getInstance(DocumentAccessBridge.class);
DocumentModelBridge dmb = mock(DocumentModelBridge.class);
when(dab.getTranslatedDocumentInstance(documentReference)).thenReturn(dmb);
when(dmb.getTitle()).thenReturn(null);
EntityReferenceSerializer<String> localSerializer = this.mocker.getInstance(EntityReferenceSerializer.TYPE_STRING, "local");
when(localSerializer.serialize(new SpaceReference("xwiki", "Main"))).thenReturn("Main");
assertEquals("%l%la%n%na%N%NA " + "[xwiki:Main.HelloWorld] Main HelloWorld Hello World Hello World (HelloWorld) " + "[xwiki:Main.HelloWorld] Main HelloWorld Hello World Hello World (HelloWorld)", this.mocker.getComponentUnderTest().generate(resourceReference));
}
Aggregations