1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.wiki.template.internal

File TemplateWikiProvisioningJob.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

2
15
2
1
96
56
4
0.27
7.5
2
2

Classes

Class Line # Actions
TemplateWikiProvisioningJob 51 15 0% 4 19
0.00%
 

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 org.xwiki.wiki.template.internal;
21   
22    import javax.inject.Inject;
23    import javax.inject.Named;
24    import javax.inject.Provider;
25   
26    import org.xwiki.bridge.event.WikiCopiedEvent;
27    import org.xwiki.bridge.event.WikiProvisionedEvent;
28    import org.xwiki.bridge.event.WikiProvisioningEvent;
29    import org.xwiki.bridge.event.WikiProvisioningFailedEvent;
30    import org.xwiki.component.annotation.Component;
31    import org.xwiki.component.annotation.InstantiationStrategy;
32    import org.xwiki.component.descriptor.ComponentInstantiationStrategy;
33    import org.xwiki.job.AbstractJob;
34    import org.xwiki.job.DefaultJobStatus;
35    import org.xwiki.wiki.manager.WikiManagerException;
36    import org.xwiki.wiki.provisioning.WikiCopier;
37    import org.xwiki.wiki.provisioning.WikiProvisioningJob;
38    import org.xwiki.wiki.provisioning.WikiProvisioningJobRequest;
39   
40    import com.xpn.xwiki.XWikiContext;
41   
42    /**
43    * Component that createAndExecuteJob a wiki with the content of a template wiki.
44    *
45    * @since 5.3M2
46    * @version $Id: d6bb0b98ae5f12f0298c04842e2c53495a135269 $
47    */
48    @Component
49    @InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP)
50    @Named(TemplateWikiProvisioningJob.JOBTYPE)
 
51    public class TemplateWikiProvisioningJob extends
52    AbstractJob<WikiProvisioningJobRequest, DefaultJobStatus<WikiProvisioningJobRequest>> implements WikiProvisioningJob
53    {
54    /**
55    * The id of the job.
56    */
57    public static final String JOBTYPE = "wikiprovisioning.template";
58   
59    @Inject
60    private WikiCopier wikiCopier;
61   
62    @Inject
63    private Provider<XWikiContext> xcontextProvider;
64   
 
65  0 toggle @Override
66    protected void runInternal() throws Exception
67    {
68  0 WikiProvisioningJobRequest request = getRequest();
69  0 if (!(request.getProvisioningJobParameter() instanceof String)) {
70  0 throw new Exception("The provisioning parameter is not a valid String.");
71    }
72   
73  0 XWikiContext xcontext = xcontextProvider.get();
74  0 String wikiId = request.getWikiId();
75  0 String templateId = (String) request.getProvisioningJobParameter();
76   
77    // Set the user actually doing the action in the context
78  0 xcontext.setUserReference(request.getProvisioningUser());
79   
80  0 try {
81  0 observationManager.notify(new WikiProvisioningEvent(wikiId), wikiId, xcontext);
82  0 wikiCopier.copyDocuments(templateId, wikiId, false);
83  0 observationManager.notify(new WikiProvisionedEvent(wikiId), wikiId, xcontext);
84  0 observationManager.notify(new WikiCopiedEvent(templateId, wikiId), templateId, xcontext);
85    } catch (WikiManagerException e) {
86  0 logger.error("Failed to provision wiki [{}] from template [{}].", wikiId, templateId, e);
87  0 observationManager.notify(new WikiProvisioningFailedEvent(wikiId), wikiId, xcontext);
88    }
89    }
90   
 
91  0 toggle @Override
92    public String getType()
93    {
94  0 return JOBTYPE;
95    }
96    }