Search in sources :

Example 46 with WikiDescriptor

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

the class WikiManagerScriptServiceTest method getMainWikiDescriptorError.

@Test
public void getMainWikiDescriptorError() throws Exception {
    Exception exception = new WikiManagerException("error in getMainWikiDescriptor");
    when(wikiDescriptorManager.getMainWikiDescriptor()).thenThrow(exception);
    WikiDescriptor result = mocker.getComponentUnderTest().getMainWikiDescriptor();
    assertNull(result);
    assertEquals(exception, mocker.getComponentUnderTest().getLastError());
}
Also used : WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) Test(org.junit.Test)

Example 47 with WikiDescriptor

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

the class WikiManagerScriptServiceTest method saveDescriptorWhenIAmLocalAdminAndChangeOwner.

@Test
public void saveDescriptorWhenIAmLocalAdminAndChangeOwner() throws Exception {
    WikiDescriptor oldDescriptor = new WikiDescriptor("wikiId", "wikiAlias");
    oldDescriptor.setOwnerId("SomeUser");
    when(wikiDescriptorManager.getById(oldDescriptor.getId())).thenReturn(oldDescriptor);
    // Changing the owner.
    WikiDescriptor descriptor = new WikiDescriptor(oldDescriptor.getId(), "wikiAlias");
    descriptor.setOwnerId("SomeOtherUserOrMyself");
    boolean result = mocker.getComponentUnderTest().saveDescriptor(descriptor);
    assertFalse(result);
    // The right has been checked
    verify(authorizationManager).hasAccess(eq(Right.ADMIN), eq(currentUserRef), eq(new WikiReference("wikiId")));
    // The descriptor has not been saved
    verify(wikiDescriptorManager, never()).saveDescriptor(descriptor);
    Exception expectedException = new AccessDeniedException(currentUserRef, new WikiReference("wikiId"));
    assertEquals(expectedException.getMessage(), mocker.getComponentUnderTest().getLastError().getMessage());
    assertEquals(expectedException.getClass(), mocker.getComponentUnderTest().getLastError().getClass());
}
Also used : AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) WikiReference(org.xwiki.model.reference.WikiReference) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) Test(org.junit.Test)

Example 48 with WikiDescriptor

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

the class WikiManagerScriptServiceTest method getById.

@Test
public void getById() throws Exception {
    WikiDescriptor descriptor = new WikiDescriptor("wikiId", "wikiAlias");
    when(wikiDescriptorManager.getById("wikiId")).thenReturn(descriptor);
    WikiDescriptor result = mocker.getComponentUnderTest().getById("wikiId");
    assertEquals(descriptor, result);
}
Also used : WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) Test(org.junit.Test)

Example 49 with WikiDescriptor

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

the class SaveWikiMetaDataStep method execute.

@Override
public void execute(WikiCreationRequest request) throws WikiCreationException {
    try {
        String wikiId = request.getWikiId();
        // Meta data about the wiki
        WikiDescriptor descriptor = wikiDescriptorManager.getById(wikiId);
        descriptor.setDescription(request.getDescription());
        descriptor.setPrettyName(request.getPrettyName());
        descriptor.setOwnerId(request.getOwnerId());
        wikiDescriptorManager.saveDescriptor(descriptor);
        // Meta data about the templates
        wikiTemplateManager.setTemplate(wikiId, request.isTemplate());
        // Meta data about the users
        wikiUserManager.setUserScope(wikiId, request.getUserScope());
        wikiUserManager.setMembershipType(wikiId, request.getMembershipType());
    } catch (WikiManagerException | WikiTemplateManagerException | WikiUserManagerException e) {
        throw new WikiCreationException(String.format("Failed to set metadata to the wiki [%s].", request.getWikiId()), e);
    }
}
Also used : WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiUserManagerException(org.xwiki.wiki.user.WikiUserManagerException) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) WikiTemplateManagerException(org.xwiki.wiki.template.WikiTemplateManagerException)

Example 50 with WikiDescriptor

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

the class DefaultWikiCreator method create.

@Override
public WikiDescriptor create(String wikiId, String wikiAlias) throws WikiManagerException {
    XWikiContext context = xcontextProvider.get();
    XWiki xwiki = context.getWiki();
    // Create database/schema
    try {
        xwiki.getStore().createWiki(wikiId, context);
    } catch (Exception e) {
        throw new WikiManagerException(localizationManager.getTranslationPlain("wiki.databasecreation", wikiId), e);
    }
    // Create the descriptor
    // Since XWiki#updateDatabase is generating documents it needs the wiki to actually exist
    // from XWiki point of view as otherwise various codes are going to be lost
    WikiDescriptor descriptor = createDescriptor(wikiId, wikiAlias);
    // Init database/schema
    try {
        xwiki.initializeWiki(wikiId, true, context);
    } catch (Exception e) {
        throw new WikiManagerException(localizationManager.getTranslationPlain("wiki.databaseupdate", wikiId), e);
    }
    return descriptor;
}
Also used : WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) WikiDescriptorBuilderException(org.xwiki.wiki.internal.descriptor.builder.WikiDescriptorBuilderException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) DefaultWikiDescriptor(org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor)

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