Search in sources :

Example 16 with InitializationException

use of org.xwiki.component.phase.InitializationException in project xwiki-platform by xwiki.

the class FilesystemStoreTools method initialize.

@Override
public void initialize() throws InitializationException {
    try {
        this.storageDir = new File(this.environment.getPermanentDirectory(), STORAGE_DIR_NAME).getCanonicalFile();
    } catch (IOException e) {
        throw new InitializationException("Invalid permanent directory", e);
    }
    if (config.cleanOnStartup()) {
        final File dir = this.storageDir;
        new Thread(() -> deleteEmptyDirs(dir, 0)).start();
    }
}
Also used : IOException(java.io.IOException) InitializationException(org.xwiki.component.phase.InitializationException) File(java.io.File)

Example 17 with InitializationException

use of org.xwiki.component.phase.InitializationException in project xwiki-platform by xwiki.

the class DefaultWatchListNotificationCache method initialize.

/**
 * Init watchlist store. Get all the intervals/jobs present in the wiki. Create the list of subscribers.
 *
 * @throws InitializationException if problems occur
 */
@Override
public void initialize() throws InitializationException {
    XWikiContext context = contextProvider.get();
    // Initialize the intervals cache.
    try {
        intervals = new ArrayList<String>();
        if (xwikiProperties.getProperty("watchlist.realtime.enabled", false)) {
            // If the realtime notification feature is explicitly enabled (temporarily disabled by default), then
            // propose/use it as possible notification interval option.
            intervals.add(REALTIME_INTERVAL_ID);
        }
        // Get all the watchlist job documents from the main wiki.
        Query jobDocumentsQuery = queryManager.getNamedQuery("getWatchlistJobDocuments");
        // Make double sure we run the query on the main wiki, since that is where the jobs are defined.
        jobDocumentsQuery.setWiki(context.getWikiId());
        List<String> jobDocumentNames = jobDocumentsQuery.execute();
        // TODO: Sort them by cron expression.
        // Add them to the list of intervals.
        intervals.addAll(jobDocumentNames);
    } catch (Exception e) {
        throw new InitializationException("Failed to initialize the cache of watchlist intervals.", e);
    }
    // Initialize the subscribers cache.
    for (String jobDocumentName : intervals) {
        initSubscribersCache(jobDocumentName);
    }
}
Also used : Query(org.xwiki.query.Query) XWikiContext(com.xpn.xwiki.XWikiContext) InitializationException(org.xwiki.component.phase.InitializationException) InitializationException(org.xwiki.component.phase.InitializationException)

Example 18 with InitializationException

use of org.xwiki.component.phase.InitializationException in project xwiki-platform by xwiki.

the class DefaultIconSetCacheTest method initializeWhenError.

@Test
public void initializeWhenError() throws Exception {
    DefaultIconSetCache cache = mocker.getComponentUnderTest();
    CacheFactory cacheFactory = mock(CacheFactory.class);
    when(cacheManager.getCacheFactory()).thenReturn(cacheFactory);
    Exception exception = new CacheException("ERROR");
    when(cacheFactory.newCache(any(CacheConfiguration.class))).thenThrow(exception);
    Exception exceptionCaught = null;
    try {
        cache.initialize();
    } catch (InitializationException e) {
        exceptionCaught = e;
    }
    assertNotNull(exceptionCaught);
    assertEquals("Failed to initialize the IconSet Cache.", exceptionCaught.getMessage());
    assertEquals(exception, exceptionCaught.getCause());
}
Also used : CacheException(org.xwiki.cache.CacheException) CacheFactory(org.xwiki.cache.CacheFactory) InitializationException(org.xwiki.component.phase.InitializationException) InitializationException(org.xwiki.component.phase.InitializationException) CacheException(org.xwiki.cache.CacheException) CacheConfiguration(org.xwiki.cache.config.CacheConfiguration) Test(org.junit.Test)

Example 19 with InitializationException

use of org.xwiki.component.phase.InitializationException in project xwiki-platform by xwiki.

the class DocumentTreeNode method initialize.

@Override
public void initialize() throws InitializationException {
    String[] nonLeafChildNodeTypes = new String[] { "translations", "attachments", "classProperties", "objects" };
    ComponentManager contextComponentManager = this.contextComponentManagerProvider.get();
    try {
        for (String nonLeafChildNodeType : nonLeafChildNodeTypes) {
            TreeNode treeNode = contextComponentManager.getInstance(TreeNode.class, nonLeafChildNodeType);
            this.nonLeafChildNodes.put(nonLeafChildNodeType, treeNode);
        }
    } catch (ComponentLookupException e) {
        throw new InitializationException("Failed to lookup the child components.", e);
    }
}
Also used : TreeNode(org.xwiki.tree.TreeNode) ComponentManager(org.xwiki.component.manager.ComponentManager) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) InitializationException(org.xwiki.component.phase.InitializationException)

Example 20 with InitializationException

use of org.xwiki.component.phase.InitializationException in project xwiki-platform by xwiki.

the class XWikiCfgConfigurationSource method initialize.

@Override
public void initialize() throws InitializationException {
    this.configurationLocation = getConfigPath();
    InputStream xwikicfgis = loadConfiguration();
    if (xwikicfgis != null) {
        try {
            this.properties.load(xwikicfgis);
        } catch (Exception e) {
            this.logger.error("Failed to load configuration", e);
        }
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) InitializationException(org.xwiki.component.phase.InitializationException)

Aggregations

InitializationException (org.xwiki.component.phase.InitializationException)24 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)9 CacheException (org.xwiki.cache.CacheException)8 CacheConfiguration (org.xwiki.cache.config.CacheConfiguration)8 IOException (java.io.IOException)4 CacheFactory (org.xwiki.cache.CacheFactory)4 InputStream (java.io.InputStream)3 LRUEvictionConfiguration (org.xwiki.cache.eviction.LRUEvictionConfiguration)3 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)2 ComponentRepositoryException (org.xwiki.component.manager.ComponentRepositoryException)2 CompositeFilterStreamDescriptor (org.xwiki.filter.descriptor.CompositeFilterStreamDescriptor)2 FilterStreamDescriptor (org.xwiki.filter.descriptor.FilterStreamDescriptor)2 EntityReference (org.xwiki.model.reference.EntityReference)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiException (com.xpn.xwiki.XWikiException)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 StringReader (java.io.StringReader)1 Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1