1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.extension.distribution.internal.job.step

File AbstractDistributionStep.java

 

Coverage histogram

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

Code metrics

8
18
10
1
122
78
15
0.83
1.8
10
1.5

Classes

Class Line # Actions
AbstractDistributionStep 33 18 0% 15 6
0.833333383.3%
 

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.extension.distribution.internal.job.step;
21   
22    import javax.inject.Inject;
23    import javax.inject.Provider;
24   
25    import org.xwiki.extension.distribution.internal.job.DistributionJob;
26    import org.xwiki.extension.distribution.internal.job.DistributionJobStatus;
27    import org.xwiki.job.annotation.Serializable;
28    import org.xwiki.rendering.block.Block;
29    import org.xwiki.template.TemplateManager;
30    import org.xwiki.wiki.descriptor.WikiDescriptorManager;
31   
32    @Serializable
 
33    public abstract class AbstractDistributionStep implements DistributionStep
34    {
35    @Inject
36    protected transient TemplateManager renderer;
37   
38    @Inject
39    protected transient Provider<WikiDescriptorManager> wikiDescriptorManagerProvider;
40   
41    private final String stepId;
42   
43    protected DistributionJob distributionJob;
44   
45    private State state;
46   
 
47  12 toggle public AbstractDistributionStep(String stepId)
48    {
49  12 this.stepId = stepId;
50    }
51   
 
52  12 toggle @Override
53    public void initialize(DistributionJob distributionJob)
54    {
55  12 this.distributionJob = distributionJob;
56   
57    // Remember previous state
58  12 DistributionJobStatus< ? > previousStatus = this.distributionJob.getPreviousStatus();
59   
60  12 if (previousStatus != null
61    && previousStatus.getDistributionExtension().equals(
62    this.distributionJob.getStatus().getDistributionExtension())) {
63  8 DistributionStep previousStep = previousStatus.getStep(getId());
64   
65  8 if (previousStep != null) {
66  8 setState(previousStep.getState());
67    }
68    }
69   
70    // Custom preparation
71   
72  12 if (getState() == null) {
73  2 prepare();
74    }
75    }
76   
 
77  43 toggle @Override
78    public String getId()
79    {
80  43 return this.stepId;
81    }
82   
 
83  52 toggle @Override
84    public State getState()
85    {
86  52 return this.state;
87    }
88   
 
89  16 toggle @Override
90    public void setState(State stepState)
91    {
92  16 this.state = stepState;
93    }
94   
 
95  5 toggle protected String getWiki()
96    {
97  5 return this.distributionJob.getRequest().getWiki();
98    }
99   
 
100  1 toggle protected boolean isMainWiki()
101    {
102  1 return this.wikiDescriptorManagerProvider.get().getMainWikiId().equals(getWiki());
103    }
104   
 
105  2 toggle protected String getNamespace()
106    {
107  2 String wiki = getWiki();
108   
109  2 return wiki == null ? null : "wiki:" + getWiki();
110    }
111   
 
112  0 toggle protected String getTemplate()
113    {
114  0 return "distribution/" + getId() + ".wiki";
115    }
116   
 
117  0 toggle @Override
118    public Block execute()
119    {
120  0 return this.renderer.executeNoException(getTemplate());
121    }
122    }