use of org.xwiki.platform.wiki.creationjob.WikiCreationException 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.platform.wiki.creationjob.WikiCreationException in project xwiki-platform by xwiki.
the class WikiCreationJobScriptServices method createWiki.
/**
* Asynchronously create a wiki.
*
* @param request creation wiki request containing all information about the wiki to create
* @return the creationjob that creates the wiki
*/
public Job createWiki(WikiCreationRequest request) {
try {
// Verify that the user has the CREATE_WIKI right
XWikiContext xcontext = xcontextProvider.get();
WikiReference mainWikiReference = new WikiReference(wikiDescriptorManager.getMainWikiId());
authorizationManager.checkAccess(Right.CREATE_WIKI, xcontext.getUserReference(), mainWikiReference);
// Verify that if an extension id is provided, this extension is authorized.
if (request.getExtensionId() != null) {
if (!isAuthorizedExtension(request.getExtensionId())) {
throw new WikiCreationException(String.format("The extension [%s] is not authorized.", request.getExtensionId()));
}
}
return wikiCreator.createWiki(request);
} catch (WikiCreationException e) {
setLastError(e);
logger.warn("Failed to create a new wiki.", e);
} catch (AccessDeniedException e) {
setLastError(e);
}
return null;
}
use of org.xwiki.platform.wiki.creationjob.WikiCreationException in project xwiki-platform by xwiki.
the class ExtensionInstallerTest method installExtensionWithException.
@Test
public void installExtensionWithException() throws Exception {
// Test
WikiCreationException caughtException = null;
try {
mocker.getComponentUnderTest().installExtension("wikiId", new ExtensionId("extensionId", "version"));
} catch (WikiCreationException e) {
caughtException = e;
}
// Verify
assertNotNull(caughtException);
assertEquals("Failed to install the extension [extensionId/version] on the wiki [wikiId].", caughtException.getMessage());
assertTrue(caughtException.getCause() instanceof ComponentLookupException);
}
use of org.xwiki.platform.wiki.creationjob.WikiCreationException in project xwiki-platform by xwiki.
the class WikiCreationJobTest method runInternalWithException.
@Test
public void runInternalWithException() throws Exception {
// Mocks
WikiCreationStep step1 = mock(WikiCreationStep.class);
mocker.registerComponent(WikiCreationStep.class, "step1", step1);
when(step1.getOrder()).thenReturn(100);
WikiCreationException exception = new WikiCreationException("Error in the step");
doThrow(exception).when(step1).execute(any(WikiCreationRequest.class));
// Test
WikiCreationRequest request = new WikiCreationRequest();
request.setId(Arrays.asList("myrequest"));
request.setWikiId("wikiId");
mocker.getComponentUnderTest().start(request);
// Verify
verify(mocker.getMockedLogger()).error(any(Marker.class), eq("Exception thrown during job execution"), eq(new WikiCreationException("Failed to execute creation steps on the wiki [wikiId].", exception)));
}
use of org.xwiki.platform.wiki.creationjob.WikiCreationException in project xwiki-platform by xwiki.
the class AddUsersStepTest method executeWhenException.
@Test
public void executeWhenException() throws Exception {
WikiCreationRequest request = new WikiCreationRequest();
request.setWikiId("wikiId");
List<String> members = new ArrayList<>();
request.setMembers(members);
Exception exception = new WikiUserManagerException("Execption in WikiUserManager.");
doThrow(exception).when(wikiUserManager).addMembers(anyCollection(), any());
// Test
WikiCreationException caughtException = null;
try {
mocker.getComponentUnderTest().execute(request);
} catch (WikiCreationException e) {
caughtException = e;
}
// Verify
assertNotNull(caughtException);
assertEquals("Failed to add members to the wiki [wikiId].", caughtException.getMessage());
assertEquals(exception, caughtException.getCause());
}
Aggregations