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

File DefaultExtensionPlan.java

 

Coverage histogram

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

Code metrics

2
15
6
1
117
57
7
0.47
2.5
6
1.17

Classes

Class Line # Actions
DefaultExtensionPlan 43 15 0% 7 4
0.8260869482.6%
 

Contributing tests

This file is covered by 103 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.extension.job.plan.internal;
21   
22    import java.util.Collection;
23    import java.util.LinkedHashSet;
24    import java.util.Set;
25   
26    import org.xwiki.extension.job.ExtensionRequest;
27    import org.xwiki.extension.job.plan.ExtensionPlan;
28    import org.xwiki.extension.job.plan.ExtensionPlanAction;
29    import org.xwiki.extension.job.plan.ExtensionPlanNode;
30    import org.xwiki.extension.job.plan.ExtensionPlanTree;
31    import org.xwiki.job.AbstractJobStatus;
32    import org.xwiki.job.event.status.JobStatus;
33    import org.xwiki.logging.LoggerManager;
34    import org.xwiki.observation.ObservationManager;
35   
36    /**
37    * A plan of extension related actions to perform.
38    *
39    * @param <R>
40    * @version $Id: 603b62c2255edb2c008d5030dd04483f0b065ebe $
41    * @since 4.0M1
42    */
 
43    public class DefaultExtensionPlan<R extends ExtensionRequest> extends AbstractJobStatus<R> implements ExtensionPlan
44    {
45    /**
46    * @see #getTree()
47    */
48    // TODO: find a way to serialize before making DefaultExtensionPlan Serializable (the main issue is the Extension
49    // objects in the nodes)
50    protected transient ExtensionPlanTree tree;
51   
52    /**
53    * @param request the request provided when started the job
54    * @param observationManager the observation manager component
55    * @param loggerManager the logger manager component
56    * @param tree the tree representation of the plan, it's not copied but taken as it it to allow filling it from
57    * outside
58    * @param parentJobStatus the status of the parent job (i.e. the status of the job that started this one); pass
59    * {@code null} if this job hasn't been started by another job (i.e. if this is not a sub-job)
60    */
 
61  236 toggle public DefaultExtensionPlan(R request, ObservationManager observationManager, LoggerManager loggerManager,
62    ExtensionPlanTree tree, JobStatus parentJobStatus)
63    {
64  236 super(request, parentJobStatus, observationManager, loggerManager);
65   
66  236 this.tree = tree;
67    }
68   
69    /**
70    * @param extensions the list of fill with actions
71    * @param nodes of branch of the tree representation of the plan
72    */
 
73  736 toggle private void fillExtensionActions(Set<ExtensionPlanAction> extensions, Collection<ExtensionPlanNode> nodes)
74    {
75  736 for (ExtensionPlanNode node : nodes) {
76  452 fillExtensionActions(extensions, node.getChildren());
77   
78  452 extensions.add(node.getAction());
79    }
80    }
81   
 
82  51 toggle @Override
83    public ExtensionPlanTree getTree()
84    {
85  51 return this.tree;
86    }
87   
88    /**
89    * @param tree the tree
90    */
 
91  9 toggle public void setTree(ExtensionPlanTree tree)
92    {
93  9 this.tree = tree;
94    }
95   
 
96  284 toggle @Override
97    public Collection<ExtensionPlanAction> getActions()
98    {
99  284 if (getState() != State.FINISHED) {
100  0 Set<ExtensionPlanAction> extensions = new LinkedHashSet<ExtensionPlanAction>();
101  0 fillExtensionActions(extensions, this.tree);
102   
103  0 return extensions;
104    } else {
105  284 Set<ExtensionPlanAction> actionsCache = new LinkedHashSet<ExtensionPlanAction>();
106  284 fillExtensionActions(actionsCache, this.tree);
107   
108  284 return actionsCache;
109    }
110    }
111   
 
112  410 toggle @Override
113    public String toString()
114    {
115  410 return this.tree.toString();
116    }
117    }