Search in sources :

Example 96 with SpaceReference

use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.

the class DefaultReferenceSpaceReferenceResolverTest method testResolveWithExplicitSpaceReference.

@Test
public void testResolveWithExplicitSpaceReference() {
    SpaceReference reference = this.resolver.resolve(null, new SpaceReference("space", new WikiReference("wiki")));
    Assert.assertEquals("space", reference.getName());
    Assert.assertEquals("wiki", reference.getWikiReference().getName());
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) WikiReference(org.xwiki.model.reference.WikiReference) Test(org.junit.Test)

Example 97 with SpaceReference

use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.

the class ModelScriptServiceTest method createSpaceReference.

@Test
public void createSpaceReference() {
    Assert.assertEquals(new SpaceReference("space", new WikiReference("wiki")), this.service.createSpaceReference("space", this.service.createWikiReference("wiki")));
    SpaceReference spaceReference = new SpaceReference("C", new SpaceReference("B", new SpaceReference("A", new WikiReference("wiki"))));
    Assert.assertEquals(spaceReference, this.service.createSpaceReference(Arrays.asList("A", "B", "C"), this.service.createWikiReference("wiki")));
    Assert.assertEquals(spaceReference, this.service.createSpaceReference(spaceReference.getName(), (SpaceReference) spaceReference.getParent()));
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) WikiReference(org.xwiki.model.reference.WikiReference) Test(org.junit.Test)

Example 98 with SpaceReference

use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.

the class DefaultSpaceReferenceProvider method get.

@Override
public SpaceReference get() {
    if (this.cachedReference == null) {
        EntityReference reference = this.provider.getDefaultReference(EntityType.SPACE);
        // Add wikis
        reference = reference.appendParent(this.wikiReferenceProvider.get());
        this.cachedReference = new SpaceReference(reference);
    }
    return this.cachedReference;
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) EntityReference(org.xwiki.model.reference.EntityReference)

Example 99 with SpaceReference

use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.

the class XWikiHibernateStore method maybeMakeSpaceHidden.

private void maybeMakeSpaceHidden(SpaceReference spaceReference, String modifiedDocument, Session session) {
    XWikiSpace space = loadXWikiSpace(spaceReference, session);
    // The space is supposed to exist
    if (space == null) {
        this.logger.warn("Space [{}] does not exist. Usually means the spaces table is not in sync with the documents table.", spaceReference);
        return;
    }
    // If the space is already hidden return
    if (space.isHidden()) {
        return;
    }
    if (calculateHiddenStatus(spaceReference, modifiedDocument, session)) {
        // Make the space hidden
        space.setHidden(true);
        session.update(space);
        // Update space parent
        if (spaceReference.getParent() instanceof SpaceReference) {
            maybeMakeSpaceHidden((SpaceReference) spaceReference.getParent(), modifiedDocument, session);
        }
    }
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) XWikiSpace(com.xpn.xwiki.doc.XWikiSpace)

Example 100 with SpaceReference

use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.

the class XWikiHibernateStore method maybeDeleteXWikiSpace.

private void maybeDeleteXWikiSpace(SpaceReference spaceReference, String deletedDocument, Session session) {
    if (countAllDocuments(spaceReference, session, "fullName <> ? AND (language IS NULL OR language = '')", deletedDocument) == 0) {
        // The document was the last document in the space
        XWikiSpace space = new XWikiSpace(spaceReference, this);
        session.delete(space);
        // Update parent
        if (spaceReference.getParent() instanceof SpaceReference) {
            maybeDeleteXWikiSpace((SpaceReference) spaceReference.getParent(), deletedDocument, session);
        }
    } else {
        // Update space hidden property if needed
        maybeMakeSpaceHidden(spaceReference, deletedDocument, session);
    }
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) XWikiSpace(com.xpn.xwiki.doc.XWikiSpace)

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