Search in sources :

Example 1 with WikiTemplateManagerException

use of org.xwiki.wiki.template.WikiTemplateManagerException 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 2 with WikiTemplateManagerException

use of org.xwiki.wiki.template.WikiTemplateManagerException 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 3 with WikiTemplateManagerException

use of org.xwiki.wiki.template.WikiTemplateManagerException 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)

Example 4 with WikiTemplateManagerException

use of org.xwiki.wiki.template.WikiTemplateManagerException in project xwiki-platform by xwiki.

the class WikiTemplateManagerScriptTest method setTemplateErrorWithTemplateManager.

@Test
public void setTemplateErrorWithTemplateManager() throws Exception {
    WikiDescriptor wikiDescriptor = new WikiDescriptor("wikiId", "wikiAlias");
    when(wikiDescriptorManager.getById("wikiId")).thenReturn(wikiDescriptor);
    Exception exception = new WikiTemplateManagerException("error in setTemplate");
    doThrow(exception).when(wikiTemplateManager).setTemplate("wikiId", true);
    boolean result = mocker.getComponentUnderTest().setTemplate("wikiId", true);
    assertFalse(result);
    assertEquals(exception, mocker.getComponentUnderTest().getLastError());
    verify(mocker.getMockedLogger()).error("Failed to set the template value [true] for the wiki [wikiId].", exception);
}
Also used : WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) WikiTemplateManagerException(org.xwiki.wiki.template.WikiTemplateManagerException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) WikiTemplateManagerException(org.xwiki.wiki.template.WikiTemplateManagerException) Test(org.junit.Test)

Example 5 with WikiTemplateManagerException

use of org.xwiki.wiki.template.WikiTemplateManagerException in project xwiki-platform by xwiki.

the class WikiTemplateManagerScriptTest method createWikiFromTemplateError.

@Test
public void createWikiFromTemplateError() throws Exception {
    Exception exception = new WikiTemplateManagerException("error in createWikiFromTemplate.");
    when(wikiTemplateManager.createWikiFromTemplate("newWikiId", "newWikiAlias", "templateId", "ownerId", true)).thenThrow(exception);
    // Test
    boolean result = mocker.getComponentUnderTest().createWikiFromTemplate("newWikiId", "newWikiAlias", "templateId", "ownerId", true);
    // Verify
    assertFalse(result);
    assertEquals(exception, mocker.getComponentUnderTest().getLastError());
    verify(mocker.getMockedLogger()).error("Failed to create the wiki from the template.", exception);
}
Also used : WikiTemplateManagerException(org.xwiki.wiki.template.WikiTemplateManagerException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) WikiTemplateManagerException(org.xwiki.wiki.template.WikiTemplateManagerException) Test(org.junit.Test)

Aggregations

WikiTemplateManagerException (org.xwiki.wiki.template.WikiTemplateManagerException)12 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)11 WikiDescriptor (org.xwiki.wiki.descriptor.WikiDescriptor)8 AccessDeniedException (org.xwiki.security.authorization.AccessDeniedException)7 Test (org.junit.Test)5 XWikiContext (com.xpn.xwiki.XWikiContext)2 ArrayList (java.util.ArrayList)2 WikiReference (org.xwiki.model.reference.WikiReference)2 WikiPropertyGroupException (org.xwiki.wiki.properties.WikiPropertyGroupException)2 WikiTemplatePropertyGroup (org.xwiki.wiki.template.WikiTemplatePropertyGroup)2 JobStatus (org.xwiki.job.event.status.JobStatus)1 WikiCreationException (org.xwiki.platform.wiki.creationjob.WikiCreationException)1 Query (org.xwiki.query.Query)1 WikiProvisioningJobException (org.xwiki.wiki.provisioning.WikiProvisioningJobException)1 WikiUserManagerException (org.xwiki.wiki.user.WikiUserManagerException)1