Search in sources :

Example 11 with WikiManagerException

use of org.xwiki.wiki.manager.WikiManagerException in project xwiki-platform by xwiki.

the class DefaultWikiTemplateManager method createWikiFromTemplate.

@Override
public WikiProvisioningJob createWikiFromTemplate(String newWikiId, String newWikiAlias, String templateId, String ownerId, boolean failOnExist) throws WikiTemplateManagerException {
    try {
        // First, create the new wiki
        WikiDescriptor descriptor = wikiManager.create(newWikiId, newWikiAlias, failOnExist);
        // Set the owner
        descriptor.setOwnerId(ownerId);
        wikiDescriptorManager.saveDescriptor(descriptor);
        // finally, we apply the template to the new wiki
        return applyTemplate(newWikiId, templateId);
    } catch (WikiManagerException e) {
        throw new WikiTemplateManagerException(e.getMessage(), e);
    }
}
Also used : WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) WikiTemplateManagerException(org.xwiki.wiki.template.WikiTemplateManagerException)

Example 12 with WikiManagerException

use of org.xwiki.wiki.manager.WikiManagerException in project xwiki-platform by xwiki.

the class TemplateWikiProvisioningJob method runInternal.

@Override
protected void runInternal() throws Exception {
    WikiProvisioningJobRequest request = getRequest();
    if (!(request.getProvisioningJobParameter() instanceof String)) {
        throw new Exception("The provisioning parameter is not a valid String.");
    }
    XWikiContext xcontext = xcontextProvider.get();
    String wikiId = request.getWikiId();
    String templateId = (String) request.getProvisioningJobParameter();
    // Set the user actually doing the action in the context
    xcontext.setUserReference(request.getProvisioningUser());
    try {
        observationManager.notify(new WikiProvisioningEvent(wikiId), wikiId, xcontext);
        wikiCopier.copyDocuments(templateId, wikiId, false);
        observationManager.notify(new WikiProvisionedEvent(wikiId), wikiId, xcontext);
        observationManager.notify(new WikiCopiedEvent(templateId, wikiId), templateId, xcontext);
    } catch (WikiManagerException e) {
        logger.error("Failed to provision wiki [{}] from template [{}].", wikiId, templateId, e);
        observationManager.notify(new WikiProvisioningFailedEvent(wikiId), wikiId, xcontext);
    }
}
Also used : WikiProvisioningFailedEvent(org.xwiki.bridge.event.WikiProvisioningFailedEvent) WikiProvisionedEvent(org.xwiki.bridge.event.WikiProvisionedEvent) WikiCopiedEvent(org.xwiki.bridge.event.WikiCopiedEvent) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiProvisioningEvent(org.xwiki.bridge.event.WikiProvisioningEvent) WikiProvisioningJobRequest(org.xwiki.wiki.provisioning.WikiProvisioningJobRequest) XWikiContext(com.xpn.xwiki.XWikiContext) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException)

Example 13 with WikiManagerException

use of org.xwiki.wiki.manager.WikiManagerException in project xwiki-platform by xwiki.

the class WikiTemplatePropertyGroupProvider method save.

@Override
public void save(WikiPropertyGroup group, String wikiId) throws WikiPropertyGroupException {
    XWikiContext context = xcontextProvider.get();
    XWiki xwiki = context.getWiki();
    WikiTemplatePropertyGroup templateGroup = (WikiTemplatePropertyGroup) group;
    try {
        XWikiDocument descriptorDocument = wikiDescriptorDocumentHelper.getDocumentFromWikiId(wikiId);
        BaseObject object = descriptorDocument.getXObject(WikiTemplateClassDocumentInitializer.SERVER_CLASS, true, context);
        object.setIntValue(WikiTemplateClassDocumentInitializer.FIELD_ISWIKITEMPLATE, templateGroup.isTemplate() ? 1 : 0);
        // The document must have a creator
        if (descriptorDocument.getCreatorReference() == null) {
            descriptorDocument.setCreatorReference(context.getUserReference());
        }
        // The document must have an author
        if (descriptorDocument.getAuthorReference() == null) {
            descriptorDocument.setAuthorReference(context.getUserReference());
        }
        xwiki.saveDocument(descriptorDocument, String.format("Changed property group [%s].", GROUP_NAME), context);
    } catch (WikiManagerException e) {
        throw new WikiPropertyGroupException(String.format(ERROR_MESSAGE_NO_DESCRIPTOR_DOCUMENT, wikiId), e);
    } catch (XWikiException e) {
        throw new WikiPropertyGroupException("Unable to save descriptor document.", e);
    }
}
Also used : WikiTemplatePropertyGroup(org.xwiki.wiki.template.WikiTemplatePropertyGroup) WikiPropertyGroupException(org.xwiki.wiki.properties.WikiPropertyGroupException) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) XWikiException(com.xpn.xwiki.XWikiException) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 14 with WikiManagerException

use of org.xwiki.wiki.manager.WikiManagerException in project xwiki-platform by xwiki.

the class WikiTemplateManagerScriptTest method setTemplateErrorWithDescriptorManager.

@Test
public void setTemplateErrorWithDescriptorManager() throws Exception {
    Exception exception = new WikiManagerException("error in getById");
    when(wikiDescriptorManager.getById("wikiId")).thenThrow(exception);
    boolean result = mocker.getComponentUnderTest().setTemplate("wikiId", true);
    assertFalse(result);
    assertEquals(exception, mocker.getComponentUnderTest().getLastError());
    verify(mocker.getMockedLogger()).error("Failed to get the descriptor of the wiki [wikiId].", exception);
}
Also used : WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiTemplateManagerException(org.xwiki.wiki.template.WikiTemplateManagerException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) Test(org.junit.Test)

Example 15 with WikiManagerException

use of org.xwiki.wiki.manager.WikiManagerException in project xwiki-platform by xwiki.

the class DefaultWikiDeleter method delete.

@Override
public void delete(String wikiId) throws WikiManagerException {
    XWikiContext context = xcontextProvider.get();
    XWiki xwiki = context.getWiki();
    // Check if we try to delete the main wiki
    if (wikiId.equals(wikiDescriptorManager.getMainWikiId())) {
        throw new WikiManagerException("It's not allowed to delete the main wiki!");
    }
    // Delete the database
    try {
        xwiki.getStore().deleteWiki(wikiId, context);
    } catch (XWikiException e) {
        throw new WikiManagerException(String.format("Error deleting the database [%s]", wikiId), e);
    }
    // Delete the descriptor document
    try {
        XWikiDocument descriptorDocument = descriptorDocumentHelper.getDocumentFromWikiId(wikiId);
        xwiki.deleteDocument(descriptorDocument, context);
    } catch (XWikiException e) {
        throw new WikiManagerException(String.format("Error deleting the Wiki Descriptor Document for database [%s]", wikiId), e);
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) XWikiException(com.xpn.xwiki.XWikiException)

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