use of org.xwiki.wiki.descriptor.WikiDescriptor in project xwiki-platform by xwiki.
the class DefaultWikiManager method copy.
@Override
public WikiDescriptor copy(String fromWikiId, String newWikiId, String newWikiAlias, boolean copyHistory, boolean copyRecycleBin, boolean failOnExist) throws WikiManagerException {
WikiDescriptor newWiki = create(newWikiId, newWikiAlias, failOnExist);
wikiCopier.copyDocuments(fromWikiId, newWikiId, copyHistory);
if (copyRecycleBin) {
wikiCopier.copyDeletedDocuments(fromWikiId, newWikiId);
}
observationManager.notify(new WikiCopiedEvent(fromWikiId, newWikiId), fromWikiId, xcontextProvider.get());
return newWiki;
}
use of org.xwiki.wiki.descriptor.WikiDescriptor in project xwiki-platform by xwiki.
the class DefaultWikiManager method create.
@Override
public WikiDescriptor create(String wikiId, String wikiAlias, boolean failOnExist) throws WikiManagerException {
// Check that the wiki Id is available
if (failOnExist && !idAvailable(wikiId)) {
throw new WikiManagerException(String.format("wiki id [%s] is already used and is thus not available", wikiId));
}
XWikiContext context = xcontextProvider.get();
WikiDescriptor descriptor;
try {
// Send the begin event
observationManager.notify(new WikiCreatingEvent(wikiId), wikiId, context);
// Create the wiki
descriptor = wikiCreator.create(wikiId, wikiAlias);
// Send the end event
observationManager.notify(new WikiCreatedEvent(wikiId), wikiId, context);
} catch (WikiManagerException e) {
// Send the failed event
observationManager.notify(new WikiCreateFailedEvent(wikiId), wikiId, context);
// Throw the exception
throw e;
}
return descriptor;
}
use of org.xwiki.wiki.descriptor.WikiDescriptor in project xwiki-platform by xwiki.
the class SaveWikiMetaDataStepTest method execute.
@Test
public void execute() throws Exception {
WikiCreationRequest request = new WikiCreationRequest();
request.setWikiId("wikiId");
request.setDescription("description");
request.setPrettyName("pretty name");
request.setOwnerId("ownerId");
request.setTemplate(false);
request.setUserScope(UserScope.GLOBAL_ONLY);
request.setMembershipType(MembershipType.INVITE);
request.setWikiSource(WikiSource.EXTENSION);
ExtensionId extensionId = new ExtensionId("id", "version");
request.setExtensionId(extensionId);
// Mock
WikiDescriptor descriptor = new WikiDescriptor("wikiId", "alias");
when(wikiDescriptorManager.getById("wikiId")).thenReturn(descriptor);
// Test
mocker.getComponentUnderTest().execute(request);
// Verify
assertEquals("description", descriptor.getDescription());
assertEquals("pretty name", descriptor.getPrettyName());
assertEquals("ownerId", descriptor.getOwnerId());
verify(wikiDescriptorManager).saveDescriptor(descriptor);
verify(wikiTemplateManager).setTemplate("wikiId", false);
verify(wikiUserManager).setUserScope("wikiId", UserScope.GLOBAL_ONLY);
verify(wikiUserManager).setMembershipType("wikiId", MembershipType.INVITE);
}
use of org.xwiki.wiki.descriptor.WikiDescriptor in project xwiki-platform by xwiki.
the class SaveWikiMetaDataStepTest method executeWithException.
@Test
public void executeWithException() throws Exception {
WikiCreationRequest request = new WikiCreationRequest();
request.setWikiId("wikiId");
// Mock
WikiDescriptor descriptor = new WikiDescriptor("wikiId", "alias");
when(wikiDescriptorManager.getById("wikiId")).thenReturn(descriptor);
Exception exception = new WikiManagerException("Exception on WikiManager.");
doThrow(exception).when(wikiDescriptorManager).saveDescriptor(descriptor);
// Test
WikiCreationException caughtException = null;
try {
mocker.getComponentUnderTest().execute(request);
} catch (WikiCreationException e) {
caughtException = e;
}
// Verify
assertEquals("Failed to set metadata to the wiki [wikiId].", caughtException.getMessage());
assertEquals(exception, caughtException.getCause());
}
use of org.xwiki.wiki.descriptor.WikiDescriptor in project xwiki-platform by xwiki.
the class SaveWikiMetaDataStepTest method executeWhenSourceIsTemplate.
@Test
public void executeWhenSourceIsTemplate() throws Exception {
WikiCreationRequest request = new WikiCreationRequest();
request.setWikiId("wikiId");
request.setTemplate(false);
request.setUserScope(UserScope.LOCAL_ONLY);
request.setMembershipType(MembershipType.OPEN);
request.setWikiSource(WikiSource.TEMPLATE);
// Mock
WikiDescriptor descriptor = new WikiDescriptor("wikiId", "alias");
when(wikiDescriptorManager.getById("wikiId")).thenReturn(descriptor);
// Test
mocker.getComponentUnderTest().execute(request);
// Verify
verify(wikiDescriptorManager).saveDescriptor(descriptor);
verify(wikiUserManager).setUserScope("wikiId", UserScope.LOCAL_ONLY);
verify(wikiUserManager).setMembershipType("wikiId", MembershipType.OPEN);
}
Aggregations