Search in sources :

Example 11 with WikiDescriptor

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

the class WikiManagerScriptServiceTest method saveDescriptorWhenDescriptorDidNotExistAndIAmGlobalAdmin.

@Test
public void saveDescriptorWhenDescriptorDidNotExistAndIAmGlobalAdmin() throws Exception {
    when(this.authorizationManager.hasAccess(Right.ADMIN, currentUserRef, new WikiReference("mainWiki"))).thenReturn(true);
    WikiDescriptor descriptor = new WikiDescriptor("wikiId", "wikiAlias");
    boolean result = mocker.getComponentUnderTest().saveDescriptor(descriptor);
    assertTrue(result);
    // Verify the rights have been checked
    verify(authorizationManager).hasAccess(eq(Right.ADMIN), eq(currentUserRef), eq(new WikiReference("mainWiki")));
    // The descriptor has been saved
    verify(wikiDescriptorManager).saveDescriptor(descriptor);
}
Also used : WikiReference(org.xwiki.model.reference.WikiReference) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) Test(org.junit.Test)

Example 12 with WikiDescriptor

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

the class WikiManagerScriptServiceTest method getByAliasError.

@Test
public void getByAliasError() throws Exception {
    Exception exception = new WikiManagerException("error in getByAlias");
    when(wikiDescriptorManager.getByAlias("wikiAlias")).thenThrow(exception);
    WikiDescriptor result = mocker.getComponentUnderTest().getByAlias("wikiAlias");
    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 13 with WikiDescriptor

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

the class DefaultWikiTemplateManager method setTemplate.

@Override
public void setTemplate(String wikiId, boolean value) throws WikiTemplateManagerException {
    try {
        // Get the descriptor
        WikiDescriptor descriptor = wikiDescriptorManager.getById(wikiId);
        // Get the property group
        WikiTemplatePropertyGroup group = (WikiTemplatePropertyGroup) descriptor.getPropertyGroup(WikiTemplatePropertyGroupProvider.GROUP_NAME);
        // Set the value
        group.setTemplate(value);
        // Save the property groups
        templateWikiPropertyGroupProvider.save(group, wikiId);
    } catch (WikiPropertyGroupException e) {
        throw new WikiTemplateManagerException(String.format("Failed to save the property group [%s]", WikiTemplatePropertyGroupProvider.GROUP_NAME), e);
    } catch (WikiManagerException e) {
        throw new WikiTemplateManagerException(String.format(errorMessageNoDescriptor, wikiId), e);
    }
}
Also used : WikiTemplatePropertyGroup(org.xwiki.wiki.template.WikiTemplatePropertyGroup) WikiPropertyGroupException(org.xwiki.wiki.properties.WikiPropertyGroupException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) WikiTemplateManagerException(org.xwiki.wiki.template.WikiTemplateManagerException)

Example 14 with WikiDescriptor

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

the class DefaultWikiTemplateManager method createWikiFromTemplate.

@Override
public WikiProvisioningJob createWikiFromTemplate(String newWikiId, String newWikiAlias, String templateId, String ownerId, boolean failOnExist) throws WikiTemplateManagerException {
    try {
        // First, create the new wiki
        WikiDescriptor descriptor = wikiManager.create(newWikiId, newWikiAlias, failOnExist);
        // Set the owner
        descriptor.setOwnerId(ownerId);
        wikiDescriptorManager.saveDescriptor(descriptor);
        // finally, we apply the template to the new wiki
        return applyTemplate(newWikiId, templateId);
    } catch (WikiManagerException e) {
        throw new WikiTemplateManagerException(e.getMessage(), e);
    }
}
Also used : WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) WikiTemplateManagerException(org.xwiki.wiki.template.WikiTemplateManagerException)

Example 15 with WikiDescriptor

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

the class DefaultWikiTemplateManager method getTemplates.

@Override
public Collection<WikiDescriptor> getTemplates() throws WikiTemplateManagerException {
    List<WikiDescriptor> result = new ArrayList<WikiDescriptor>();
    try {
        Query query = this.queryManager.createQuery("from doc.object(WikiManager.WikiTemplateClass) as descriptor where doc.name like 'XWikiServer%' " + "and descriptor.iswikitemplate = 1", Query.XWQL);
        query.setWiki(xcontextProvider.get().getMainXWiki());
        List<String> documentNames = query.execute();
        if (documentNames != null && !documentNames.isEmpty()) {
            for (String documentName : documentNames) {
                String id = documentName.substring("XWiki.XWikiServer".length()).toLowerCase();
                result.add(wikiDescriptorManager.getById(id));
            }
        }
    } catch (Exception e) {
        throw new WikiTemplateManagerException("Failed to locate XWiki.XWikiServerClass documents", e);
    }
    return result;
}
Also used : Query(org.xwiki.query.Query) ArrayList(java.util.ArrayList) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) WikiProvisioningJobException(org.xwiki.wiki.provisioning.WikiProvisioningJobException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiPropertyGroupException(org.xwiki.wiki.properties.WikiPropertyGroupException) WikiTemplateManagerException(org.xwiki.wiki.template.WikiTemplateManagerException) WikiTemplateManagerException(org.xwiki.wiki.template.WikiTemplateManagerException)

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