Search in sources :

Example 31 with WikiManagerException

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

the class DefaultWikiDescriptorDocumentHelper method getAllXWikiServerClassDocumentNames.

@Override
public List<String> getAllXWikiServerClassDocumentNames() throws WikiManagerException {
    WikiDescriptorManager wikiDescriptorManager = wikiDescriptorManagerProvider.get();
    try {
        Query query = this.queryManager.createQuery("from doc.object(XWiki.XWikiServerClass) as descriptor where doc.name like 'XWikiServer%' " + "and doc.fullName <> 'XWiki.XWikiServerClassTemplate'", Query.XWQL);
        query.setWiki(wikiDescriptorManager.getMainWikiId());
        query.addFilter(componentManager.<QueryFilter>getInstance(QueryFilter.class, "unique"));
        return query.execute();
    } catch (Exception e) {
        throw new WikiManagerException("Failed to locate XWiki.XWikiServerClass documents", e);
    }
}
Also used : QueryFilter(org.xwiki.query.QueryFilter) Query(org.xwiki.query.Query) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) XWikiException(com.xpn.xwiki.XWikiException) QueryException(org.xwiki.query.QueryException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException)

Example 32 with WikiManagerException

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

the class SaveWikiMetaDataStep method execute.

@Override
public void execute(WikiCreationRequest request) throws WikiCreationException {
    try {
        String wikiId = request.getWikiId();
        // Meta data about the wiki
        WikiDescriptor descriptor = wikiDescriptorManager.getById(wikiId);
        descriptor.setDescription(request.getDescription());
        descriptor.setPrettyName(request.getPrettyName());
        descriptor.setOwnerId(request.getOwnerId());
        wikiDescriptorManager.saveDescriptor(descriptor);
        // Meta data about the templates
        wikiTemplateManager.setTemplate(wikiId, request.isTemplate());
        // Meta data about the users
        wikiUserManager.setUserScope(wikiId, request.getUserScope());
        wikiUserManager.setMembershipType(wikiId, request.getMembershipType());
    } catch (WikiManagerException | WikiTemplateManagerException | WikiUserManagerException e) {
        throw new WikiCreationException(String.format("Failed to set metadata to the wiki [%s].", request.getWikiId()), e);
    }
}
Also used : WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiUserManagerException(org.xwiki.wiki.user.WikiUserManagerException) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) WikiTemplateManagerException(org.xwiki.wiki.template.WikiTemplateManagerException)

Example 33 with WikiManagerException

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

the class DefaultWikiCreator method create.

@Override
public WikiDescriptor create(String wikiId, String wikiAlias) throws WikiManagerException {
    XWikiContext context = xcontextProvider.get();
    XWiki xwiki = context.getWiki();
    // Create database/schema
    try {
        xwiki.getStore().createWiki(wikiId, context);
    } catch (Exception e) {
        throw new WikiManagerException(localizationManager.getTranslationPlain("wiki.databasecreation", wikiId), e);
    }
    // Create the descriptor
    // Since XWiki#updateDatabase is generating documents it needs the wiki to actually exist
    // from XWiki point of view as otherwise various codes are going to be lost
    WikiDescriptor descriptor = createDescriptor(wikiId, wikiAlias);
    // Init database/schema
    try {
        xwiki.initializeWiki(wikiId, true, context);
    } catch (Exception e) {
        throw new WikiManagerException(localizationManager.getTranslationPlain("wiki.databaseupdate", wikiId), e);
    }
    return descriptor;
}
Also used : WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) WikiDescriptorBuilderException(org.xwiki.wiki.internal.descriptor.builder.WikiDescriptorBuilderException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) DefaultWikiDescriptor(org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor)

Example 34 with WikiManagerException

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

the class DefaultWikiCreator method createDescriptor.

private WikiDescriptor createDescriptor(String wikiId, String wikiAlias) throws WikiManagerException {
    // Create the descriptor
    WikiDescriptor descriptor = new DefaultWikiDescriptor(wikiId, wikiAlias);
    try {
        // Build the document
        wikiDescriptorBuilder.save(descriptor);
        // Reload the descriptor from the cache because it should have been seen by the DescriptorListener.
        descriptor = wikiDescriptorManager.getById(wikiId);
    } catch (WikiDescriptorBuilderException e) {
        throw new WikiManagerException("Failed to build the descriptor document.", e);
    }
    return descriptor;
}
Also used : WikiDescriptorBuilderException(org.xwiki.wiki.internal.descriptor.builder.WikiDescriptorBuilderException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) DefaultWikiDescriptor(org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor) DefaultWikiDescriptor(org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor)

Example 35 with WikiManagerException

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

the class DefaultWikiManager method idAvailable.

@Override
public boolean idAvailable(String wikiId) throws WikiManagerException {
    // Get the store
    XWikiContext xcontext = xcontextProvider.get();
    XWiki xwiki = xcontext.getWiki();
    // Get the forbidden list
    String wikiForbiddenList = xcontextProvider.get().getWiki().Param("xwiki.virtual.reserved_wikis");
    try {
        return !wikiDescriptorManager.exists(wikiId) && !Util.contains(wikiId, wikiForbiddenList, ", ") && xwiki.getStore().isWikiNameAvailable(wikiId, xcontext);
    } catch (XWikiException e) {
        throw new WikiManagerException("Fail to look at the databases.");
    }
}
Also used : 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