1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.internal

File WikiInitializerJob.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

2
22
4
1
125
70
5
0.23
5.5
4
1.25

Classes

Class Line # Actions
WikiInitializerJob 47 22 0% 5 2
0.928571492.9%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package com.xpn.xwiki.internal;
21   
22    import javax.inject.Inject;
23    import javax.inject.Named;
24    import javax.inject.Provider;
25   
26    import org.xwiki.bridge.event.WikiReadyEvent;
27    import org.xwiki.component.annotation.Component;
28    import org.xwiki.component.annotation.InstantiationStrategy;
29    import org.xwiki.component.descriptor.ComponentInstantiationStrategy;
30    import org.xwiki.job.AbstractJob;
31    import org.xwiki.job.Request;
32    import org.xwiki.model.reference.DocumentReferenceResolver;
33    import org.xwiki.model.reference.EntityReference;
34    import org.xwiki.observation.ObservationManager;
35   
36    import com.xpn.xwiki.XWikiContext;
37   
38    /**
39    * Job dedicated to wiki initialization.
40    *
41    * @version $Id: a6d8c461782e57d49eda74ddc4c84676c37db5e8 $
42    * @since 8.4RC1
43    */
44    @Component
45    @InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP)
46    @Named(WikiInitializerJob.JOBTYPE)
 
47    public class WikiInitializerJob extends AbstractJob<WikiInitializerRequest, WikiInitializerJobStatus>
48    {
49    /**
50    * The id of the job.
51    */
52    public static final String JOBTYPE = "wiki.init";
53   
54    @Inject
55    private Provider<XWikiContext> xcontextProvider;
56   
57    @Inject
58    private ObservationManager observation;
59   
60    @Inject
61    @Named("current")
62    private DocumentReferenceResolver<EntityReference> resolver;
63   
 
64  32 toggle @Override
65    protected WikiInitializerRequest castRequest(Request request)
66    {
67  32 WikiInitializerRequest indexerRequest;
68  32 if (request instanceof WikiInitializerRequest) {
69  32 indexerRequest = (WikiInitializerRequest) request;
70    } else {
71  0 indexerRequest = new WikiInitializerRequest(request);
72    }
73   
74  32 return indexerRequest;
75    }
76   
 
77  32 toggle @Override
78    protected WikiInitializerJobStatus createNewStatus(WikiInitializerRequest request)
79    {
80  32 return new WikiInitializerJobStatus(request, this.observationManager, this.loggerManager);
81    }
82   
 
83  160 toggle @Override
84    public String getType()
85    {
86  160 return JOBTYPE;
87    }
88   
 
89  32 toggle @Override
90    protected void runInternal() throws Exception
91    {
92  32 String wikiId = getRequest().getWikiId();
93   
94  32 this.logger.info("Start initialization of wiki [{}]", wikiId);
95   
96  32 XWikiContext xcontext = this.xcontextProvider.get();
97   
98    // Set proper context
99  32 xcontext.setWikiId(wikiId);
100  32 xcontext.setOriginalWikiId(wikiId);
101   
102  32 this.progressManager.pushLevelProgress(3, this);
103   
104  32 try {
105  32 this.progressManager.startStep(this, "Initialize mandatory document");
106   
107    // Initialize mandatory document
108  32 xcontext.getWiki().initializeMandatoryDocuments(xcontext);
109   
110  32 this.progressManager.startStep(this, "Initialize plugins");
111   
112    // Initialize plugins
113  32 xcontext.getWiki().getPluginManager().virtualInit(xcontext);
114   
115  32 this.logger.info("Initialization if wiki [{}] done", wikiId);
116   
117  32 this.progressManager.startStep(this, "Call listeners");
118   
119    // Send event to notify listeners that the subwiki is ready
120  32 this.observation.notify(new WikiReadyEvent(wikiId), wikiId, xcontext);
121    } finally {
122  32 this.progressManager.popLevelProgress(this);
123    }
124    }
125    }