Search in sources :

Example 1 with WikiCreationException

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);
    }
}
Also used : WikiProvisioningFailedEvent(org.xwiki.bridge.event.WikiProvisioningFailedEvent) WikiCopiedEvent(org.xwiki.bridge.event.WikiCopiedEvent) WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException)

Example 2 with WikiCreationException

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;
}
Also used : AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) XWikiContext(com.xpn.xwiki.XWikiContext) WikiReference(org.xwiki.model.reference.WikiReference)

Example 3 with WikiCreationException

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);
}
Also used : WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) ExtensionId(org.xwiki.extension.ExtensionId) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) Test(org.junit.Test)

Example 4 with WikiCreationException

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)));
}
Also used : WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) WikiCreationRequest(org.xwiki.platform.wiki.creationjob.WikiCreationRequest) Marker(org.slf4j.Marker) WikiCreationStep(org.xwiki.platform.wiki.creationjob.WikiCreationStep) Test(org.junit.Test)

Example 5 with WikiCreationException

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());
}
Also used : WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) WikiUserManagerException(org.xwiki.wiki.user.WikiUserManagerException) WikiCreationRequest(org.xwiki.platform.wiki.creationjob.WikiCreationRequest) ArrayList(java.util.ArrayList) WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) WikiUserManagerException(org.xwiki.wiki.user.WikiUserManagerException) Test(org.junit.Test)

Aggregations

WikiCreationException (org.xwiki.platform.wiki.creationjob.WikiCreationException)12 Test (org.junit.Test)7 WikiCreationRequest (org.xwiki.platform.wiki.creationjob.WikiCreationRequest)6 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)4 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)3 WikiProvisioningFailedEvent (org.xwiki.bridge.event.WikiProvisioningFailedEvent)2 ExtensionId (org.xwiki.extension.ExtensionId)2 WikiCreationStep (org.xwiki.platform.wiki.creationjob.WikiCreationStep)2 WikiDescriptor (org.xwiki.wiki.descriptor.WikiDescriptor)2 WikiUserManagerException (org.xwiki.wiki.user.WikiUserManagerException)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 ArrayList (java.util.ArrayList)1 Marker (org.slf4j.Marker)1 WikiCopiedEvent (org.xwiki.bridge.event.WikiCopiedEvent)1 WikiProvisioningEvent (org.xwiki.bridge.event.WikiProvisioningEvent)1 InstallRequest (org.xwiki.extension.job.InstallRequest)1 InstallJob (org.xwiki.extension.job.internal.InstallJob)1 JobException (org.xwiki.job.JobException)1 WikiReference (org.xwiki.model.reference.WikiReference)1 AccessDeniedException (org.xwiki.security.authorization.AccessDeniedException)1