Search in sources :

Example 6 with DefaultWikiDescriptor

use of org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor in project xwiki-platform by xwiki.

the class WikiDescriptorListener method onEvent.

@Override
public void onEvent(Event event, Object source, Object data) {
    XWikiDocument document = (XWikiDocument) source;
    // so then unregister them
    if (event instanceof DocumentDeletedEvent || event instanceof DocumentUpdatedEvent) {
        removeExistingDescriptor(document.getOriginalDocument());
    }
    // Register the new XWiki Server objects if any
    List<BaseObject> serverClassObjects = document.getXObjects(SERVER_CLASS);
    if (serverClassObjects != null && !serverClassObjects.isEmpty()) {
        DefaultWikiDescriptor descriptor = this.builder.buildDescriptorObject(serverClassObjects, document);
        if (descriptor != null) {
            this.cache.add(descriptor);
            this.cache.setWikiIds(null);
        }
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) DefaultWikiDescriptor(org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 7 with DefaultWikiDescriptor

use of org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor in project xwiki-platform by xwiki.

the class DefaultWikiDescriptorBuilder method buildDescriptorObject.

@Override
public DefaultWikiDescriptor buildDescriptorObject(List<BaseObject> serverClassObjects, XWikiDocument document) {
    List<BaseObject> normalizedServerClassObjects = normalizeServerClassObjects(serverClassObjects);
    BaseObject mainServerClassObject = normalizedServerClassObjects.remove(0);
    DefaultWikiDescriptor descriptor = extractWikiDescriptor(mainServerClassObject, document);
    if (descriptor != null) {
        // Create WikiAlias instances for the other XWikiServerClass objects
        for (BaseObject serverClassObject : normalizedServerClassObjects) {
            if (serverClassObject != null) {
                String descriptorAlias = extractWikiAlias(serverClassObject);
                descriptor.addAlias(descriptorAlias);
            }
        }
        // load properties
        descriptor.setMainPageReference(referenceResolver.resolve(mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_HOMEPAGE)));
        descriptor.setPrettyName(mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_WIKIPRETTYNAME));
        descriptor.setOwnerId(getFullReference(mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_OWNER), descriptor.getId()));
        descriptor.setDescription(mainServerClassObject.getStringValue(XWikiServerClassDocumentInitializer.FIELD_DESCRIPTION));
        // load the property groups
        try {
            WikiPropertyGroupManager wikiPropertyGroupManager = wikiPropertyGroupManagerProvider.get();
            wikiPropertyGroupManager.loadForDescriptor(descriptor);
        } catch (WikiPropertyGroupException e) {
            logger.error("Failed to load wiki property groups for wiki [{}].", descriptor.getId(), e);
        }
    }
    return descriptor;
}
Also used : WikiPropertyGroupException(org.xwiki.wiki.properties.WikiPropertyGroupException) WikiPropertyGroupManager(org.xwiki.wiki.internal.descriptor.properties.WikiPropertyGroupManager) DefaultWikiDescriptor(org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 8 with DefaultWikiDescriptor

use of org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor in project xwiki-platform by xwiki.

the class DefaultWikiCreatorTest method create.

@Test
public void create() throws Exception {
    // Other mocks
    DefaultWikiDescriptor descriptor = new DefaultWikiDescriptor("wikiid1", "wikialias1");
    XWikiDocument descriptorDocument = mock(XWikiDocument.class);
    when(wikiDescriptorBuilder.save(eq(descriptor))).thenReturn(descriptorDocument);
    when(wikiDescriptorManager.getById("wikiid1")).thenReturn(descriptor);
    when(store.isWikiNameAvailable(any(String.class), any(XWikiContext.class))).thenReturn(true);
    // Create
    WikiDescriptor newWikiDescriptor = this.mocker.getComponentUnderTest().create("wikiid1", "wikialias1");
    assertNotNull(newWikiDescriptor);
    // Verify that the wiki descriptor is an instance of DefaultWikiDescriptor
    assertTrue(newWikiDescriptor instanceof DefaultWikiDescriptor);
    // Verify that the wiki has been created
    verify(store).createWiki(eq("wikiid1"), any(XWikiContext.class));
    // Verify that the wiki has been updated
    verify(xwiki).initializeWiki(eq("wikiid1"), eq(true), any(XWikiContext.class));
    // Verify that the descriptor document has been saved
    verify(wikiDescriptorBuilder).save(eq(descriptor));
    // Verify that the descriptor has been reloaded after being saved
    assertTrue(descriptor == newWikiDescriptor);
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiContext(com.xpn.xwiki.XWikiContext) DefaultWikiDescriptor(org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor) DefaultWikiDescriptor(org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) Test(org.junit.Test)

Example 9 with DefaultWikiDescriptor

use of org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor in project xwiki-platform by xwiki.

the class DefaultWikiDeleterTest method deleteWiki.

@Test
public void deleteWiki() throws Exception {
    // Mock
    DefaultWikiDescriptor descriptor = new DefaultWikiDescriptor("wikiid", "wikialias");
    descriptor.addAlias("wikialias2");
    XWikiDocument descriptorDocument = mock(XWikiDocument.class);
    when(descriptorDocumentHelper.getDocumentFromWikiId("wikiid")).thenReturn(descriptorDocument);
    // Delete
    this.mocker.getComponentUnderTest().delete("wikiid");
    // Verify that the database has been deleted
    verify(store).deleteWiki(eq("wikiid"), any(XWikiContext.class));
    // Verify that the descriptor document has been deleted
    verify(xwiki).deleteDocument(eq(descriptorDocument), any(XWikiContext.class));
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiContext(com.xpn.xwiki.XWikiContext) DefaultWikiDescriptor(org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor) Test(org.junit.Test)

Example 10 with DefaultWikiDescriptor

use of org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor in project xwiki-platform by xwiki.

the class DefaultWikiManagerTest method copyWhenWikiAvailable.

@Test
public void copyWhenWikiAvailable() throws Exception {
    // The wiki does not already exist
    when(wikiDescriptorManager.exists("wikiid1")).thenReturn(false);
    // The new id is valid
    when(xwiki.Param("xwiki.virtual.reserved_wikis")).thenReturn("forbidden");
    // The wiki name is available
    when(store.isWikiNameAvailable(eq("wikiid1"), any(XWikiContext.class))).thenReturn(true);
    // Other mocks
    DefaultWikiDescriptor descriptor = new DefaultWikiDescriptor("wikiid1", "wikialias1");
    when(wikiCreator.create("wikiid1", "wikialias1")).thenReturn(descriptor);
    // Copy
    WikiDescriptor newWikiDescriptor = this.mocker.getComponentUnderTest().copy("wikiid", "wikiid1", "wikialias1", true, true, true);
    assertNotNull(newWikiDescriptor);
    // Verify that the wiki has been created
    verify(wikiCreator).create("wikiid1", "wikialias1");
    // Verify that the wiki has been copied
    verify(wikiCopier).copyDocuments(eq("wikiid"), eq("wikiid1"), eq(true));
    // Verify that deleted documents has been copied too
    verify(wikiCopier).copyDeletedDocuments(eq("wikiid"), eq("wikiid1"));
    // Verify that events has been sent
    verify(observationManager).notify(new WikiCopiedEvent("wikiid", "wikiid1"), "wikiid", xcontext);
}
Also used : WikiCopiedEvent(org.xwiki.bridge.event.WikiCopiedEvent) XWikiContext(com.xpn.xwiki.XWikiContext) DefaultWikiDescriptor(org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor) DefaultWikiDescriptor(org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) Test(org.junit.Test)

Aggregations

DefaultWikiDescriptor (org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor)14 Test (org.junit.Test)9 XWikiContext (com.xpn.xwiki.XWikiContext)5 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)5 BaseObject (com.xpn.xwiki.objects.BaseObject)5 WikiDescriptor (org.xwiki.wiki.descriptor.WikiDescriptor)4 DocumentDeletedEvent (org.xwiki.bridge.event.DocumentDeletedEvent)3 DocumentUpdatedEvent (org.xwiki.bridge.event.DocumentUpdatedEvent)3 ArrayList (java.util.ArrayList)2 WikiCreatingEvent (org.xwiki.bridge.event.WikiCreatingEvent)2 DocumentReference (org.xwiki.model.reference.DocumentReference)2 Event (org.xwiki.observation.event.Event)2 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)2 WikiCopiedEvent (org.xwiki.bridge.event.WikiCopiedEvent)1 WikiCreateFailedEvent (org.xwiki.bridge.event.WikiCreateFailedEvent)1 WikiCreatedEvent (org.xwiki.bridge.event.WikiCreatedEvent)1 WikiDescriptorBuilderException (org.xwiki.wiki.internal.descriptor.builder.WikiDescriptorBuilderException)1 WikiPropertyGroupManager (org.xwiki.wiki.internal.descriptor.properties.WikiPropertyGroupManager)1 WikiPropertyGroupException (org.xwiki.wiki.properties.WikiPropertyGroupException)1