Search in sources :

Example 16 with WikiManagerException

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;
}
Also used : WikiCreatingEvent(org.xwiki.bridge.event.WikiCreatingEvent) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiCreatedEvent(org.xwiki.bridge.event.WikiCreatedEvent) XWikiContext(com.xpn.xwiki.XWikiContext) WikiCreateFailedEvent(org.xwiki.bridge.event.WikiCreateFailedEvent) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor)

Example 17 with WikiManagerException

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);
    }
}
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 18 with WikiManagerException

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

Example 19 with WikiManagerException

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());
}
Also used : WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiCreationRequest(org.xwiki.platform.wiki.creationjob.WikiCreationRequest) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) Test(org.junit.Test)

Example 20 with WikiManagerException

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;
}
Also used : WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) XWikiContext(com.xpn.xwiki.XWikiContext) WikiDescriptorBuilderException(org.xwiki.wiki.internal.descriptor.builder.WikiDescriptorBuilderException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException)

Aggregations

WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)40 WikiDescriptor (org.xwiki.wiki.descriptor.WikiDescriptor)17 Test (org.junit.Test)13 XWikiContext (com.xpn.xwiki.XWikiContext)12 AccessDeniedException (org.xwiki.security.authorization.AccessDeniedException)11 XWiki (com.xpn.xwiki.XWiki)7 XWikiException (com.xpn.xwiki.XWikiException)7 WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)6 WikiTemplateManagerException (org.xwiki.wiki.template.WikiTemplateManagerException)6 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)5 WikiPropertyGroupException (org.xwiki.wiki.properties.WikiPropertyGroupException)5 BaseObject (com.xpn.xwiki.objects.BaseObject)4 WikiCreationException (org.xwiki.platform.wiki.creationjob.WikiCreationException)4 WikiTemplatePropertyGroup (org.xwiki.wiki.template.WikiTemplatePropertyGroup)4 ExtensionId (org.xwiki.extension.ExtensionId)3 DocumentReference (org.xwiki.model.reference.DocumentReference)3 WikiReference (org.xwiki.model.reference.WikiReference)3 Query (org.xwiki.query.Query)3 QueryException (org.xwiki.query.QueryException)3 DefaultWikiDescriptor (org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor)3