use of org.xwiki.wiki.manager.WikiManagerException 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.manager.WikiManagerException in project xwiki-platform by xwiki.
the class ProvisionWikiStep method execute.
@Override
public void execute(WikiCreationRequest request) throws WikiCreationException {
try {
if (request.getWikiSource() == null) {
// No source is defined, we let the wiki empty and DW will do the rest
return;
}
switch(request.getWikiSource()) {
case EXTENSION:
sendWikiProvisioningEvent(request);
extensionInstaller.installExtension(request.getWikiId(), request.getExtensionId());
sendWikiProvisionedEvent(request);
break;
case TEMPLATE:
sendWikiProvisioningEvent(request);
wikiCopier.copyDocuments(request.getTemplateId(), request.getWikiId(), false);
observationManager.notify(new WikiCopiedEvent(request.getTemplateId(), request.getWikiId()), request.getTemplateId(), xcontextProvider.get());
sendWikiProvisionedEvent(request);
break;
default:
// No source is defined, we let the wiki empty and DW will do the rest
break;
}
} catch (WikiManagerException | WikiCreationException e) {
observationManager.notify(new WikiProvisioningFailedEvent(request.getWikiId()), request.getWikiId(), xcontextProvider.get());
throw new WikiCreationException(String.format("Failed to provision the wiki [%s].", request.getWikiId()), e);
}
}
use of org.xwiki.wiki.manager.WikiManagerException in project xwiki-platform by xwiki.
the class CreateWikiStepTest method executeWhenException.
@Test
public void executeWhenException() throws Exception {
WikiCreationRequest request = new WikiCreationRequest();
request.setWikiId("wikiId");
request.setAlias("wikiAlias");
request.setFailOnExist(true);
Exception exception = new WikiManagerException("Execption in WikiManager.");
doThrow(exception).when(wikiManager).create(any(), any(), anyBoolean());
// Test
WikiCreationException caughtException = null;
try {
mocker.getComponentUnderTest().execute(request);
} catch (WikiCreationException e) {
caughtException = e;
}
// Verify
assertNotNull(caughtException);
assertEquals("Failed to create the wiki [wikiId].", caughtException.getMessage());
assertEquals(exception, caughtException.getCause());
}
use of org.xwiki.wiki.manager.WikiManagerException 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.manager.WikiManagerException in project xwiki-platform by xwiki.
the class DefaultWikiDescriptorManager method getAllIds.
@Override
public Collection<String> getAllIds() throws WikiManagerException {
Collection<String> wikiIds = this.cache.getWikiIds();
if (wikiIds == null) {
List<String> documentNames;
try {
documentNames = this.descriptorDocumentHelperProvider.get().getAllXWikiServerClassDocumentNames();
} catch (Exception e) {
throw new WikiManagerException("Failed to get wiki ids", e);
}
wikiIds = new HashSet<String>(documentNames.size());
boolean foundMainWiki = false;
XWikiContext xcontext = this.xcontextProvider.get();
for (String documentName : documentNames) {
String wikId = this.descriptorDocumentHelperProvider.get().getWikiIdFromDocumentFullname(documentName);
wikiIds.add(wikId);
foundMainWiki |= xcontext.isMainWiki(wikId);
}
// Make sure we always return a descriptor for main wiki, even a virtual one
if (!foundMainWiki) {
wikiIds.add(getMainWikiId());
}
this.cache.setWikiIds(Collections.unmodifiableCollection(wikiIds));
}
return wikiIds;
}
Aggregations