Search in sources :

Example 16 with SpaceReference

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);
}
Also used : EntityRequest(org.xwiki.refactoring.job.EntityRequest) SpaceReference(org.xwiki.model.reference.SpaceReference) ArrayList(java.util.ArrayList) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 17 with SpaceReference

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);
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) SpaceReference(org.xwiki.model.reference.SpaceReference) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 18 with SpaceReference

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;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) SpaceReference(org.xwiki.model.reference.SpaceReference) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 19 with SpaceReference

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));
}
Also used : DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) EntityReferenceResolver(org.xwiki.model.reference.EntityReferenceResolver) SpaceReference(org.xwiki.model.reference.SpaceReference) DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge) ResourceReference(org.xwiki.rendering.listener.reference.ResourceReference) DocumentResourceReference(org.xwiki.rendering.listener.reference.DocumentResourceReference) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) DocumentResourceReference(org.xwiki.rendering.listener.reference.DocumentResourceReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 20 with SpaceReference

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));
}
Also used : DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) EntityReferenceResolver(org.xwiki.model.reference.EntityReferenceResolver) SpaceReference(org.xwiki.model.reference.SpaceReference) DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge) ResourceReference(org.xwiki.rendering.listener.reference.ResourceReference) DocumentResourceReference(org.xwiki.rendering.listener.reference.DocumentResourceReference) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) DocumentResourceReference(org.xwiki.rendering.listener.reference.DocumentResourceReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Aggregations

SpaceReference (org.xwiki.model.reference.SpaceReference)142 DocumentReference (org.xwiki.model.reference.DocumentReference)96 Test (org.junit.Test)83 WikiReference (org.xwiki.model.reference.WikiReference)58 EntityReference (org.xwiki.model.reference.EntityReference)24 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)21 ArrayList (java.util.ArrayList)11 ResourceReference (org.xwiki.rendering.listener.reference.ResourceReference)11 XWikiException (com.xpn.xwiki.XWikiException)9 QueryRestrictionGroup (com.celements.search.lucene.query.QueryRestrictionGroup)8 Expectations (org.jmock.Expectations)8 XWikiContext (com.xpn.xwiki.XWikiContext)7 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)7 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)7 ComponentManager (org.xwiki.component.manager.ComponentManager)7 NamespacedComponentManager (org.xwiki.component.manager.NamespacedComponentManager)7 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)7 EntityReferenceResolver (org.xwiki.model.reference.EntityReferenceResolver)7 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)7 DocumentResourceReference (org.xwiki.rendering.listener.reference.DocumentResourceReference)7