Enumerate Wikis in Java Component

Hi,

I try to enumerate all Wikis of the current XWiki instance in a ApplicationStartedEvent. Is there a API I could call to get all wikis? Or must I use the rest Interface of the Wiki to enumerate the Wikis? Or a configuration option to get the Information?

I try to write a Component that’s start all subwikis and the main wiki on startup. It works very good with the exception that I don’t know the subwiki Names.

Thanks
Zwixx

You can use the org.xwiki.wiki.descriptor.WikiDescriptorManager component (module xwiki-platform-wiki-api) for this kind of things.

Thanks, that’s really simple.

For someone who try to use the XWikiDescriptorManager too, it is not available if I used ApplicationStarted-Event:

org.xwiki.wiki.manager.WikiManagerException: Failed to get wiki ids
at org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptorManager.getAllIds(DefaultWikiDescriptorManager.java:107)

My solution that I’m working on is now, that’s I waiting for the ApplicationStarted-Event, create a timer that’s starts the main wiki (if it’s ready) then I use the XWikiDescriptorManager and read all subwikis.

That’s not a really good solution, but I don’t found any event that is fired “if the wiki is really ready”.

That would be org.xwiki.bridge.event.ApplicationReadyEvent :slight_smile: (in xwiki-platform-bridge module).

No, that’s fired after the main wiki is started. I thought in the first moment the same, but if the main wiki is not started, it is not fired.

It’s fired when the DB is ready. If you want something fired before the DB is ready (but then you won’t be able to use any API that requires the DB) then it’s ApplicationStartedEvent.

It’s fired when, among other things, the database is ready to be used. If you need to manipulate the database you will need to wait for this event.

Yes, but the database is not ready at the moment the wiki in started. It’s ready when the first wiki is started.

The logs of my test system (the bold logging messages are of the Component I write):

2020-11-06 16:18:17,678 [main] INFO o.x.s.s.i.EmbeddedSolr - Started embedded Solr server.
!!! construtor call !!!
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.thoughtworks.xstream.converters.reflection.FieldDictionary (file:/L:/Programm/xwiki-platform-distribution-jetty-hsqldb-12.9/webapps/xwiki/WEB-INF/lib/xstream-1.4.13.jar) to field java.util.Collections$UnmodifiableMap.serialVersionUID
WARNING: Please consider reporting this to the maintainers of com.thoughtworks.xstream.converters.reflection.FieldDictionary
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2020-11-06 16:18:18,579 [main] INFO o.x.s.f.i.FilesystemStoreTools - Using filesystem store directory [L:\Programm\xwiki-platform-distribution-jetty-hsqldb-12.9\data\store\file]
2020-11-06 16:18:19.775:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@202b0582{XWiki,/xwiki,file:///L:/Programm/xwiki-platform-distribution-jetty-hsqldb-12.9/webapps/xwiki/,AVAILABLE}{L:\Programm\xwiki-platform-distribution-jetty-hsqldb-12.9\jetty/…/webapps/xwiki}
2020-11-06 16:18:19.778:INFO:oejs.RequestLogWriter:main: Opened L:\Programm\xwiki-platform-distribution-jetty-hsqldb-12.9\data\logs\2020_11_06.request.log
2020-11-06 16:18:19.789:INFO:oejs.AbstractConnector:main: Started ServerConnector@654f0d9c{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
2020-11-06 16:18:19.789:INFO:oejs.Server:main: Started @34888ms
2020-11-06 16:18:19.789:INFO:oxtjl.NotifyListener:main: ----------------------------------
2020-11-06 16:18:24.320:INFO:oxtjl.NotifyListener:main: Server gestartet, k├Ânnen Sie nun http://Lanyia:8080/ in Ihrem Browser ├Âffnen, um auf Ihr Wiki zuzugreifen.
2020-11-06 16:18:24.320:INFO:oxtjl.NotifyListener:main: ----------------------------------

Start of the wiki stops here. If I visit http://Lanyia:8080/ the following occurs:

2020-11-06 16:19:11,931 [XWiki initialization] INFO .HibernateDataMigrationManager - Storage schema updates and data migrations are enabled
2020-11-06 16:19:12,158 [XWiki initialization] INFO .HibernateDataMigrationManager - No data migration to apply for wiki [xwiki] currently in version [120901000]
2020-11-06 16:19:12,158 [XWiki initialization] INFO .HibernateDataMigrationManager - Checking Hibernate mapping and updating schema if needed for wiki [xwiki]
2020-11-06 16:19:12,342 [XWiki initialization] INFO .HibernateDataMigrationManager - No data migration to apply for wiki [wowcharaktere] currently in version [120901000]
2020-11-06 16:19:12,342 [XWiki initialization] INFO .HibernateDataMigrationManager - Checking Hibernate mapping and updating schema if needed for wiki [wowcharaktere]
2020-11-06 16:19:19,975 [XWiki initialization] WARN d.f.x.StartListener - Initialisiere Wiki-Starter…
Wikis:
wowcharaktere
xwiki
2020-11-06 16:19:19,986 [org.xwiki.search.solr.internal.job.IndexerJob@60d6730f([solr, indexer])] INFO o.x.s.s.i.j.IndexerJob - Starting job of type [solr.indexer] with identifier [[solr, indexer]]
2020-11-06 16:19:20,812 [org.xwiki.search.solr.internal.job.IndexerJob@60d6730f([solr, indexer])] INFO o.x.s.s.i.j.IndexerJob - 0 documents added, 0 deleted and 0 updated during the synchronization of the Solr index.
2020-11-06 16:19:20,813 [org.xwiki.search.solr.internal.job.IndexerJob@60d6730f([solr, indexer])] INFO o.x.s.s.i.j.IndexerJob - Finished job of type [solr.indexer] with identifier [[solr, indexer]]

I really don’t understand what you mean.

When your listener is called with ApplicationReadyEvent you can use the DB. That’s what this event is used for 99% of the time.

yes, but it’s never called if I don’t initialize a single wiki. The log (see above) stops at:

2020-11-06 16:18:19.789:INFO:oxtjl.NotifyListener:main: ----------------------------------
2020-11-06 16:18:24.320:INFO:oxtjl.NotifyListener:main: Server gestartet, k├Ânnen Sie nun http://Lanyia:8080/ in Ihrem Browser ├Âffnen, um auf Ihr Wiki zuzugreifen.
2020-11-06 16:18:24.320:INFO:oxtjl.NotifyListener:main: ----------------------------------

And nothing is happened anymore. If I visit this url, the database is started and the Event is fired. Then I could use the methods to enumerate the wikis. So I must first use a ApplicationStartedEvent to initialize the main wiki. Then call the method and initialize all subwikis.

I think what you’re missing is that a wiki (whether the main wiki or a subwiki) is initialized by the first user request to it.

Yes, so my idea is to initialize the main wiki with an timer. And then, when the database is ready, initialize the subwikis in the ApplicationReadyEvent. In this event I know the subwikis and could call them.

That’s not a good solution, but it works.

Related: Loading...

My not really good solution. But it works:for me. Maybe someone can use this too.