1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.extension.job.plan.internal

File DefaultExtensionPlan.java

 

Coverage histogram

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

Code metrics

2
15
6
1
118
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 110 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: c700baf7efd31110a97a655528ec4e160428310f $
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 jobType the type of the job
54    * @param request the request provided when started the job
55    * @param observationManager the observation manager component
56    * @param loggerManager the logger manager component
57    * @param tree the tree representation of the plan, it's not copied but taken as it it to allow filling it from
58    * outside
59    * @param parentJobStatus the status of the parent job (i.e. the status of the job that started this one); pass
60    * {@code null} if this job hasn't been started by another job (i.e. if this is not a sub-job)
61    */
 
62  273 toggle public DefaultExtensionPlan(String jobType, R request, ObservationManager observationManager,
63    LoggerManager loggerManager, ExtensionPlanTree tree, JobStatus parentJobStatus)
64    {
65  273 super(jobType, request, parentJobStatus, observationManager, loggerManager);
66   
67  273 this.tree = tree;
68    }
69   
70    /**
71    * @param extensions the list of fill with actions
72    * @param nodes of branch of the tree representation of the plan
73    */
 
74  25682 toggle private void fillExtensionActions(Set<ExtensionPlanAction> extensions, Collection<ExtensionPlanNode> nodes)
75    {
76  25682 for (ExtensionPlanNode node : nodes) {
77  25396 fillExtensionActions(extensions, node.getChildren());
78   
79  25396 extensions.add(node.getAction());
80    }
81    }
82   
 
83  63 toggle @Override
84    public ExtensionPlanTree getTree()
85    {
86  63 return this.tree;
87    }
88   
89    /**
90    * @param tree the tree
91    */
 
92  9 toggle public void setTree(ExtensionPlanTree tree)
93    {
94  9 this.tree = tree;
95    }
96   
 
97  286 toggle @Override
98    public Collection<ExtensionPlanAction> getActions()
99    {
100  286 if (getState() != State.FINISHED) {
101  0 Set<ExtensionPlanAction> extensions = new LinkedHashSet<ExtensionPlanAction>();
102  0 fillExtensionActions(extensions, this.tree);
103   
104  0 return extensions;
105    } else {
106  286 Set<ExtensionPlanAction> actionsCache = new LinkedHashSet<ExtensionPlanAction>();
107  286 fillExtensionActions(actionsCache, this.tree);
108   
109  286 return actionsCache;
110    }
111    }
112   
 
113  1412 toggle @Override
114    public String toString()
115    {
116  1412 return this.tree.toString();
117    }
118    }