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

File ProvisionWikiStep.java

 

Coverage histogram

../../../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

2
22
4
1
120
78
8
0.36
5.5
4
2

Classes

Class Line # Actions
ProvisionWikiStep 52 22 0% 8 4
0.8571428785.7%
 

Contributing tests

This file is covered by 4 tests. .

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.platform.wiki.creationjob.internal.steps;
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.observation.ObservationManager;
34    import org.xwiki.platform.wiki.creationjob.WikiCreationRequest;
35    import org.xwiki.platform.wiki.creationjob.WikiCreationStep;
36    import org.xwiki.platform.wiki.creationjob.WikiCreationException;
37    import org.xwiki.platform.wiki.creationjob.internal.ExtensionInstaller;
38    import org.xwiki.wiki.provisioning.WikiCopier;
39    import org.xwiki.wiki.manager.WikiManagerException;
40   
41    import com.xpn.xwiki.XWikiContext;
42   
43    /**
44    * Step that provision a new empty wiki with a template or an extension.
45    *
46    * @version $Id: cda93fc0124eb637f6d0c5e4d3157606101ba307 $
47    * @since 7.0M2
48    */
49    @Component
50    @InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP)
51    @Named("provision")
 
52    public class ProvisionWikiStep implements WikiCreationStep
53    {
54    @Inject
55    private WikiCopier wikiCopier;
56   
57    @Inject
58    private ExtensionInstaller extensionInstaller;
59   
60    @Inject
61    private ObservationManager observationManager;
62   
63    @Inject
64    private Provider<XWikiContext> xcontextProvider;
65   
 
66  6 toggle @Override
67    public void execute(WikiCreationRequest request) throws WikiCreationException
68    {
69  6 try {
70  6 if (request.getWikiSource() == null) {
71    // No source is defined, we let the wiki empty and DW will do the rest
72  0 return;
73    }
74  6 switch (request.getWikiSource()) {
75  3 case EXTENSION:
76  3 sendWikiProvisioningEvent(request);
77   
78  3 extensionInstaller.installExtension(request.getWikiId(), request.getExtensionId());
79   
80  2 sendWikiProvisionedEvent(request);
81  2 break;
82  3 case TEMPLATE:
83  3 sendWikiProvisioningEvent(request);
84   
85  3 wikiCopier.copyDocuments(request.getTemplateId(), request.getWikiId(), false);
86  3 observationManager.notify(new WikiCopiedEvent(request.getTemplateId(), request.getWikiId()),
87    request.getTemplateId(), xcontextProvider.get());
88   
89  3 sendWikiProvisionedEvent(request);
90  3 break;
91  0 default:
92    // No source is defined, we let the wiki empty and DW will do the rest
93  0 break;
94    }
95    } catch (WikiManagerException | WikiCreationException e) {
96  1 observationManager.notify(new WikiProvisioningFailedEvent(request.getWikiId()), request.getWikiId(),
97    xcontextProvider.get());
98  1 throw new WikiCreationException(String.format("Failed to provision the wiki [%s].",
99    request.getWikiId()), e);
100    }
101    }
102   
 
103  6 toggle private void sendWikiProvisioningEvent(WikiCreationRequest request)
104    {
105  6 observationManager.notify(new WikiProvisioningEvent(request.getWikiId()), request.getWikiId(),
106    xcontextProvider.get());
107    }
108   
 
109  5 toggle private void sendWikiProvisionedEvent(WikiCreationRequest request)
110    {
111  5 observationManager.notify(new WikiProvisionedEvent(request.getWikiId()), request.getWikiId(),
112    xcontextProvider.get());
113    }
114   
 
115  13 toggle @Override
116    public int getOrder()
117    {
118  13 return 3000;
119    }
120    }