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);
}
}
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);
}
}
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;
}
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);
}
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);
}
Aggregations