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