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

File AbstractRequest.java

 

Coverage histogram

../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

4
27
25
1
259
134
27
1
1.08
25
1.08

Classes

Class Line # Actions
AbstractRequest 39 27 0% 27 4
0.928571492.9%
 

Contributing tests

This file is covered by 288 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.job;
21   
22    import java.io.Serializable;
23    import java.util.ArrayList;
24    import java.util.Arrays;
25    import java.util.Collection;
26    import java.util.Collections;
27    import java.util.HashMap;
28    import java.util.List;
29    import java.util.Map;
30   
31    import org.xwiki.job.event.status.JobStatus;
32   
33    /**
34    * Base class for {@link Request} implementations.
35    *
36    * @version $Id: b0be4b1a70476224fe1187d76bbdbd9725e5377d $
37    * @since 4.0M1
38    */
 
39    public abstract class AbstractRequest implements Request
40    {
41    /**
42    * Serialization identifier.
43    */
44    private static final long serialVersionUID = 1L;
45   
46    /**
47    * @see #getId()
48    */
49    private List<String> id;
50   
51    /**
52    * The properties.
53    */
54    private Map<String, Object> properties = new HashMap<>();
55   
56    /**
57    * @see #isVerbose()
58    */
59    private boolean verbose = true;
60   
61    private Boolean statusLogIsolated;
62   
63    private Boolean statusSerialized;
64   
65    /**
66    * Default constructor.
67    */
 
68  220480 toggle public AbstractRequest()
69    {
70   
71    }
72   
73    /**
74    * @param request the request to copy
75    */
 
76  204 toggle public AbstractRequest(Request request)
77    {
78  204 setId(request.getId());
79   
80  204 for (String key : request.getPropertyNames()) {
81  994 setProperty(key, request.getProperty(key));
82    }
83    }
84   
 
85  319778 toggle @Override
86    public List<String> getId()
87    {
88  319788 return this.id;
89    }
90   
91    /**
92    * @param id the identifier used to access the job
93    * @since 4.1M2
94    */
 
95  35023 toggle public void setId(List<String> id)
96    {
97  35023 this.id = id != null ? new ArrayList<>(id) : null;
98    }
99   
100    /**
101    * @param id the identifier used to access the job
102    */
 
103  1 toggle public void setId(String id)
104    {
105  1 setId(Arrays.asList(id));
106    }
107   
108    /**
109    * @param id the id elements
110    * @since 8.4RC1
111    */
 
112  43 toggle public void setId(String... id)
113    {
114  43 this.id = Arrays.asList(id);
115    }
116   
 
117  361 toggle @Override
118    public boolean isRemote()
119    {
120  361 return this.<Boolean>getProperty(PROPERTY_REMOTE, false);
121    }
122   
123    /**
124    * @param remote indicate if the job has been triggered by a remote event
125    */
 
126  3 toggle public void setRemote(boolean remote)
127    {
128  3 setProperty(PROPERTY_REMOTE, remote);
129    }
130   
 
131  331 toggle @Override
132    public boolean isInteractive()
133    {
134  331 return this.<Boolean>getProperty(PROPERTY_INTERACTIVE, false);
135    }
136   
137    /**
138    * @param interactive indicate if the job is allowed to ask questions if it it should be fully automated (i.e. use
139    * default answers)
140    */
 
141  244 toggle public void setInteractive(boolean interactive)
142    {
143  244 setProperty(PROPERTY_INTERACTIVE, interactive);
144    }
145   
146    /**
147    * @param key the name of the property
148    * @param value the value of the property
149    */
 
150  59763 toggle public void setProperty(String key, Object value)
151    {
152  59762 this.properties.put(key, value);
153    }
154   
155    /**
156    * @param key the name of the property
157    * @return the previous value associated to the passed key
158    * @param <T> the type of the value
159    * @since 4.2M2
160    */
 
161  0 toggle public <T> T removeProperty(String key)
162    {
163  0 return (T) this.properties.remove(key);
164    }
165   
 
166  65027 toggle @Override
167    public <T> T getProperty(String key)
168    {
169  65025 return getProperty(key, null);
170    }
171   
 
172  68023 toggle @Override
173    public <T> T getProperty(String key, T def)
174    {
175  68026 Object value = this.properties.get(key);
176   
177  68027 return value != null ? (T) value : def;
178    }
179   
 
180  214 toggle @Override
181    public Collection<String> getPropertyNames()
182    {
183  214 return this.properties.keySet();
184    }
185   
 
186  0 toggle @Override
187    public boolean containsProperty(String key)
188    {
189  0 return this.properties.containsKey(key);
190    }
191   
 
192  49612 toggle @Override
193    public boolean isVerbose()
194    {
195  49611 return this.verbose;
196    }
197   
198    /**
199    * @param verbose true if the job should log informations about what is going on.
200    * @since 5.4RC1
201    */
 
202  220060 toggle public void setVerbose(boolean verbose)
203    {
204  220060 this.verbose = verbose;
205    }
206   
 
207  44025 toggle @Override
208    public Boolean isStatusLogIsolated()
209    {
210  44026 return this.statusLogIsolated;
211    }
212   
213    /**
214    * @param statusLogIsolated true if the log should be isolated from standard output, null to fallback on
215    * {@link JobStatus#isIsolated()}
216    * @since 10.0
217    */
 
218  4 toggle public void setStatusLogIsolated(Boolean statusLogIsolated)
219    {
220  4 this.statusLogIsolated = statusLogIsolated;
221    }
222   
 
223  21603 toggle @Override
224    public Boolean isStatusSerialized()
225    {
226  21603 return this.statusSerialized;
227    }
228   
229    /**
230    * @param statusSerialized true if the job status should be serialized, null to fallback on
231    * {@link JobStatus#isSerialized()}
232    * @since 10.0
233    */
 
234  4 toggle public void setStatusSerialized(Boolean statusSerialized)
235    {
236  4 this.statusSerialized = statusSerialized;
237    }
238   
 
239  21974 toggle @Override
240    public Map<String, Serializable> getContext()
241    {
242  21973 return getProperty(PROPERTY_CONTEXT);
243    }
244   
 
245  55441 toggle @Override
246    public void setContext(Map<String, Serializable> context)
247    {
248  55441 setProperty(PROPERTY_CONTEXT, context);
249    }
250   
251    /**
252    * @return the map of properties in an unmodifiableMap.
253    * @since 10.11
254    */
 
255  4 toggle public Map<String, Object> getProperties()
256    {
257  4 return Collections.unmodifiableMap(properties);
258    }
259    }