Search in sources :

Example 21 with WikiDescriptor

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

the class DefaultWikiManager method copy.

@Override
public WikiDescriptor copy(String fromWikiId, String newWikiId, String newWikiAlias, boolean copyHistory, boolean copyRecycleBin, boolean failOnExist) throws WikiManagerException {
    WikiDescriptor newWiki = create(newWikiId, newWikiAlias, failOnExist);
    wikiCopier.copyDocuments(fromWikiId, newWikiId, copyHistory);
    if (copyRecycleBin) {
        wikiCopier.copyDeletedDocuments(fromWikiId, newWikiId);
    }
    observationManager.notify(new WikiCopiedEvent(fromWikiId, newWikiId), fromWikiId, xcontextProvider.get());
    return newWiki;
}
Also used : WikiCopiedEvent(org.xwiki.bridge.event.WikiCopiedEvent) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor)

Example 22 with WikiDescriptor

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

the class DefaultWikiManager method create.

@Override
public WikiDescriptor create(String wikiId, String wikiAlias, boolean failOnExist) throws WikiManagerException {
    // Check that the wiki Id is available
    if (failOnExist && !idAvailable(wikiId)) {
        throw new WikiManagerException(String.format("wiki id [%s] is already used and is thus not available", wikiId));
    }
    XWikiContext context = xcontextProvider.get();
    WikiDescriptor descriptor;
    try {
        // Send the begin event
        observationManager.notify(new WikiCreatingEvent(wikiId), wikiId, context);
        // Create the wiki
        descriptor = wikiCreator.create(wikiId, wikiAlias);
        // Send the end event
        observationManager.notify(new WikiCreatedEvent(wikiId), wikiId, context);
    } catch (WikiManagerException e) {
        // Send the failed event
        observationManager.notify(new WikiCreateFailedEvent(wikiId), wikiId, context);
        // Throw the exception
        throw e;
    }
    return descriptor;
}
Also used : WikiCreatingEvent(org.xwiki.bridge.event.WikiCreatingEvent) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiCreatedEvent(org.xwiki.bridge.event.WikiCreatedEvent) XWikiContext(com.xpn.xwiki.XWikiContext) WikiCreateFailedEvent(org.xwiki.bridge.event.WikiCreateFailedEvent) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor)

Example 23 with WikiDescriptor

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

the class SaveWikiMetaDataStepTest method execute.

@Test
public void execute() throws Exception {
    WikiCreationRequest request = new WikiCreationRequest();
    request.setWikiId("wikiId");
    request.setDescription("description");
    request.setPrettyName("pretty name");
    request.setOwnerId("ownerId");
    request.setTemplate(false);
    request.setUserScope(UserScope.GLOBAL_ONLY);
    request.setMembershipType(MembershipType.INVITE);
    request.setWikiSource(WikiSource.EXTENSION);
    ExtensionId extensionId = new ExtensionId("id", "version");
    request.setExtensionId(extensionId);
    // Mock
    WikiDescriptor descriptor = new WikiDescriptor("wikiId", "alias");
    when(wikiDescriptorManager.getById("wikiId")).thenReturn(descriptor);
    // Test
    mocker.getComponentUnderTest().execute(request);
    // Verify
    assertEquals("description", descriptor.getDescription());
    assertEquals("pretty name", descriptor.getPrettyName());
    assertEquals("ownerId", descriptor.getOwnerId());
    verify(wikiDescriptorManager).saveDescriptor(descriptor);
    verify(wikiTemplateManager).setTemplate("wikiId", false);
    verify(wikiUserManager).setUserScope("wikiId", UserScope.GLOBAL_ONLY);
    verify(wikiUserManager).setMembershipType("wikiId", MembershipType.INVITE);
}
Also used : WikiCreationRequest(org.xwiki.platform.wiki.creationjob.WikiCreationRequest) ExtensionId(org.xwiki.extension.ExtensionId) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) Test(org.junit.Test)

Example 24 with WikiDescriptor

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

the class SaveWikiMetaDataStepTest method executeWithException.

@Test
public void executeWithException() throws Exception {
    WikiCreationRequest request = new WikiCreationRequest();
    request.setWikiId("wikiId");
    // Mock
    WikiDescriptor descriptor = new WikiDescriptor("wikiId", "alias");
    when(wikiDescriptorManager.getById("wikiId")).thenReturn(descriptor);
    Exception exception = new WikiManagerException("Exception on WikiManager.");
    doThrow(exception).when(wikiDescriptorManager).saveDescriptor(descriptor);
    // Test
    WikiCreationException caughtException = null;
    try {
        mocker.getComponentUnderTest().execute(request);
    } catch (WikiCreationException e) {
        caughtException = e;
    }
    // Verify
    assertEquals("Failed to set metadata to the wiki [wikiId].", caughtException.getMessage());
    assertEquals(exception, caughtException.getCause());
}
Also used : WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiCreationRequest(org.xwiki.platform.wiki.creationjob.WikiCreationRequest) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) Test(org.junit.Test)

Example 25 with WikiDescriptor

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

the class SaveWikiMetaDataStepTest method executeWhenSourceIsTemplate.

@Test
public void executeWhenSourceIsTemplate() throws Exception {
    WikiCreationRequest request = new WikiCreationRequest();
    request.setWikiId("wikiId");
    request.setTemplate(false);
    request.setUserScope(UserScope.LOCAL_ONLY);
    request.setMembershipType(MembershipType.OPEN);
    request.setWikiSource(WikiSource.TEMPLATE);
    // Mock
    WikiDescriptor descriptor = new WikiDescriptor("wikiId", "alias");
    when(wikiDescriptorManager.getById("wikiId")).thenReturn(descriptor);
    // Test
    mocker.getComponentUnderTest().execute(request);
    // Verify
    verify(wikiDescriptorManager).saveDescriptor(descriptor);
    verify(wikiUserManager).setUserScope("wikiId", UserScope.LOCAL_ONLY);
    verify(wikiUserManager).setMembershipType("wikiId", MembershipType.OPEN);
}
Also used : WikiCreationRequest(org.xwiki.platform.wiki.creationjob.WikiCreationRequest) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) Test(org.junit.Test)

Aggregations

WikiDescriptor (org.xwiki.wiki.descriptor.WikiDescriptor)60 Test (org.junit.Test)40 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)28 AccessDeniedException (org.xwiki.security.authorization.AccessDeniedException)17 WikiReference (org.xwiki.model.reference.WikiReference)11 XWikiContext (com.xpn.xwiki.XWikiContext)9 WikiTemplateManagerException (org.xwiki.wiki.template.WikiTemplateManagerException)9 ArrayList (java.util.ArrayList)7 DocumentReference (org.xwiki.model.reference.DocumentReference)6 WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)6 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)5 BaseObject (com.xpn.xwiki.objects.BaseObject)5 DefaultWikiDescriptor (org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor)5 WikiCreationRequest (org.xwiki.platform.wiki.creationjob.WikiCreationRequest)3 AuthorizationException (org.xwiki.security.authorization.AuthorizationException)3 WikiCopiedEvent (org.xwiki.bridge.event.WikiCopiedEvent)2 WikiCreatedEvent (org.xwiki.bridge.event.WikiCreatedEvent)2 WikiCreatingEvent (org.xwiki.bridge.event.WikiCreatingEvent)2 WikiCreationException (org.xwiki.platform.wiki.creationjob.WikiCreationException)2 WikiDescriptorBuilderException (org.xwiki.wiki.internal.descriptor.builder.WikiDescriptorBuilderException)2