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

File AbstractRequest.java

 

Coverage histogram

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

Code metrics

4
20
18
1
198
97
20
1
1.11
18
1.11

Classes

Class Line # Actions
AbstractRequest 35 20 0% 20 4
0.904761990.5%
 

Contributing tests

This file is covered by 214 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.util.ArrayList;
23    import java.util.Arrays;
24    import java.util.Collection;
25    import java.util.HashMap;
26    import java.util.List;
27    import java.util.Map;
28   
29    /**
30    * Base class for {@link Request} implementations.
31    *
32    * @version $Id: a87e81183b5ca040af19e37e1effbfe7123762e6 $
33    * @since 4.0M1
34    */
 
35    public abstract class AbstractRequest implements Request
36    {
37    /**
38    * Serialization identifier.
39    */
40    private static final long serialVersionUID = 1L;
41   
42    /**
43    * @see #getId()
44    */
45    private List<String> id;
46   
47    /**
48    * The properties.
49    */
50    private Map<String, Object> properties = new HashMap<String, Object>();
51   
52    /**
53    * @see #isVerbose()
54    */
55    private boolean verbose = true;
56   
57    /**
58    * Default constructor.
59    */
 
60  481 toggle public AbstractRequest()
61    {
62   
63    }
64   
65    /**
66    * @param request the request to copy
67    */
 
68  190 toggle public AbstractRequest(Request request)
69    {
70  190 setId(request.getId());
71   
72  190 for (String key : request.getPropertyNames()) {
73  924 setProperty(key, request.getProperty(key));
74    }
75    }
76   
 
77  6427 toggle @Override
78    public List<String> getId()
79    {
80  6427 return this.id;
81    }
82   
83    /**
84    * @param id the identifier used to access the job
85    * @since 4.1M2
86    */
 
87  565 toggle public void setId(List<String> id)
88    {
89  565 this.id = id != null ? new ArrayList<String>(id) : null;
90    }
91   
92    /**
93    * @param id the identifier used to access the job
94    */
 
95  1 toggle public void setId(String id)
96    {
97  1 setId(Arrays.asList(id));
98    }
99   
100    /**
101    * @param id the id elements
102    * @since 8.4RC1
103    */
 
104  32 toggle public void setId(String... id)
105    {
106  32 this.id = Arrays.asList(id);
107    }
108   
 
109  141 toggle @Override
110    public boolean isRemote()
111    {
112  141 return this.<Boolean>getProperty(PROPERTY_REMOTE, false);
113    }
114   
115    /**
116    * @param remote indicate if the job has been triggered by a remote event
117    */
 
118  1 toggle public void setRemote(boolean remote)
119    {
120  1 setProperty(PROPERTY_REMOTE, remote);
121    }
122   
 
123  82 toggle @Override
124    public boolean isInteractive()
125    {
126  82 return this.<Boolean>getProperty(PROPERTY_INTERACTIVE, false);
127    }
128   
129    /**
130    * @param interactive indicate if the job is allowed to ask questions if it it should be fully automated (i.e. use
131    * default answers)
132    */
 
133  124 toggle public void setInteractive(boolean interactive)
134    {
135  124 setProperty(PROPERTY_INTERACTIVE, interactive);
136    }
137   
138    /**
139    * @param key the name of the property
140    * @param value the value of the property
141    */
 
142  2911 toggle public void setProperty(String key, Object value)
143    {
144  2911 this.properties.put(key, value);
145    }
146   
147    /**
148    * @param key the name of the property
149    * @return the previous value associated to the passed key
150    * @param <T> the type of the value
151    * @since 4.2M2
152    */
 
153  0 toggle public <T> T removeProperty(String key)
154    {
155  0 return (T) this.properties.remove(key);
156    }
157   
 
158  6168 toggle @Override
159    public <T> T getProperty(String key)
160    {
161  6168 return getProperty(key, null);
162    }
163   
 
164  6859 toggle @Override
165    public <T> T getProperty(String key, T def)
166    {
167  6859 Object value = this.properties.get(key);
168   
169  6859 return value != null ? (T) value : def;
170    }
171   
 
172  190 toggle @Override
173    public Collection<String> getPropertyNames()
174    {
175  190 return this.properties.keySet();
176    }
177   
 
178  0 toggle @Override
179    public boolean containsProperty(String key)
180    {
181  0 return this.properties.containsKey(key);
182    }
183   
 
184  1351 toggle @Override
185    public boolean isVerbose()
186    {
187  1351 return this.verbose;
188    }
189   
190    /**
191    * @param verbose true if the job should log informations about what is going on.
192    * @since 5.4RC1
193    */
 
194  5 toggle public void setVerbose(boolean verbose)
195    {
196  5 this.verbose = verbose;
197    }
198    }