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