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

File EntityRequest.java

 

Coverage histogram

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

Code metrics

4
17
12
1
199
74
14
0.82
1.42
12
1.17

Classes

Class Line # Actions
EntityRequest 37 17 0% 14 1
0.96969797%
 

Contributing tests

This file is covered by 48 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.refactoring.job;
21   
22    import java.util.Collection;
23    import java.util.Collections;
24    import java.util.HashMap;
25    import java.util.Map;
26   
27    import org.xwiki.job.AbstractRequest;
28    import org.xwiki.model.reference.DocumentReference;
29    import org.xwiki.model.reference.EntityReference;
30   
31    /**
32    * A generic job request that targets multiple entities.
33    *
34    * @version $Id: 17e8a4286d9e2a054cb9469223f48893596b577e $
35    * @since 7.2M1
36    */
 
37    public class EntityRequest extends AbstractRequest
38    {
39    /**
40    * Serialization identifier.
41    */
42    private static final long serialVersionUID = 1L;
43   
44    /**
45    * @see #getJobType()
46    */
47    private static final String PROPERTY_JOB_TYPE = "job.type";
48   
49    /**
50    * @see #getUserReference()
51    */
52    private static final String PROPERTY_USER_REFERENCE = "user.reference";
53   
54    /**
55    * @see #isCheckRights()
56    */
57    private static final String PROPERTY_CHECK_RIGHTS = "checkrights";
58   
59    /**
60    * @see #getEntityReferences()
61    */
62    private static final String PROPERTY_ENTITY_REFERENCES = "entityReferences";
63   
64    /**
65    * @see #getEntityParameters(EntityReference)
66    */
67    private static final String PROPERTY_ENTITY_PARAMETERS = "entityParameters";
68   
69    /**
70    * @see #isDeep()
71    */
72    private static final String PROPERTY_DEEP = "deep";
73   
74    /**
75    * @return the type of job that should perform this request; this is useful when different jobs use the same type of
76    * request
77    */
 
78  6 toggle public String getJobType()
79    {
80  6 return getProperty(PROPERTY_JOB_TYPE);
81    }
82   
83    /**
84    * Sets the type of job that should perform this request. This is useful when different jobs use the same type of
85    * request.
86    *
87    * @param jobType the type of job that should perform this request
88    */
 
89  47 toggle public void setJobType(String jobType)
90    {
91  47 setProperty(PROPERTY_JOB_TYPE, jobType);
92    }
93   
94    /**
95    * @return {@code true} in case the job should check if the user specified by {@link #getUserReference()} is
96    * authorized to perform the actions implied by this request, {@code false} otherwise
97    */
 
98  74 toggle public boolean isCheckRights()
99    {
100  74 return getProperty(PROPERTY_CHECK_RIGHTS, true);
101    }
102   
103    /**
104    * Sets whether the job should check or not if the user specified by {@link #getUserReference()} is authorized to
105    * perform the actions implied by this request.
106    *
107    * @param checkRights {@code true} to check if {@link #getUserReference()} is authorized to perform this request,
108    * {@code false} to perform this request without checking rights
109    */
 
110  101 toggle public void setCheckRights(boolean checkRights)
111    {
112  101 setProperty(PROPERTY_CHECK_RIGHTS, checkRights);
113    }
114   
115    /**
116    * @return the user that should be used to perform this request; this user must be authorized to perform the actions
117    * implied by this request if {@link #isCheckRights()} is {@code true}.
118    */
 
119  119 toggle public DocumentReference getUserReference()
120    {
121  119 return getProperty(PROPERTY_USER_REFERENCE);
122    }
123   
124    /**
125    * Sets the user that should be used to perform this request. This user must be authorized to perform the actions
126    * implied by this request if {@link #isCheckRights()} is {@code true}.
127    *
128    * @param userReference the user reference
129    */
 
130  95 toggle public void setUserReference(DocumentReference userReference)
131    {
132  95 setProperty(PROPERTY_USER_REFERENCE, userReference);
133    }
134   
135    /**
136    * @return the collection of entity references that are targeted by this request
137    */
 
138  163 toggle public Collection<EntityReference> getEntityReferences()
139    {
140  163 return getProperty(PROPERTY_ENTITY_REFERENCES);
141    }
142   
143    /**
144    * Sets the collection of entity references that are targeted by this request.
145    *
146    * @param entityReferences a collection of entity references
147    */
 
148  102 toggle public void setEntityReferences(Collection<EntityReference> entityReferences)
149    {
150  102 setProperty(PROPERTY_ENTITY_REFERENCES, entityReferences);
151    }
152   
153    /**
154    * @return {@code true} if the operation should target child entities also (i.e. go deep into the entity hierarchy),
155    * {@code false} otherwise
156    */
 
157  60 toggle public boolean isDeep()
158    {
159  60 return getProperty(PROPERTY_DEEP, false);
160    }
161   
162    /**
163    * Sets whether the operation should target child entities also (i.e. go deep into the entity hierarchy) or not.
164    *
165    * @param deep {@code true} to include the child entities, {@code false} otherwise
166    */
 
167  25 toggle public void setDeep(boolean deep)
168    {
169  25 setProperty(PROPERTY_DEEP, deep);
170    }
171   
172    /**
173    * @param entityReference one of the entity references that are the target of this request
174    * @return the custom parameters associated to the specified target entity
175    */
 
176  8 toggle public Map<String, String> getEntityParameters(EntityReference entityReference)
177    {
178  8 Map<String, String> entityParameters =
179    getProperty(PROPERTY_ENTITY_PARAMETERS, Collections.<EntityReference, Map<String, String>>emptyMap()).get(
180    entityReference);
181  8 return entityParameters == null ? Collections.emptyMap() : entityParameters;
182    }
183   
184    /**
185    * Associates custom parameters to a target entity.
186    *
187    * @param entityReference one of the target entities
188    * @param entityParameters the custom parameters to associate to the specified target entity
189    */
 
190  2 toggle public void setEntityParameters(EntityReference entityReference, Map<String, String> entityParameters)
191    {
192  2 Map<EntityReference, Map<String, String>> paramsPerEntity = getProperty(PROPERTY_ENTITY_PARAMETERS);
193  2 if (paramsPerEntity == null) {
194  2 paramsPerEntity = new HashMap<>();
195  2 setProperty(PROPERTY_ENTITY_PARAMETERS, paramsPerEntity);
196    }
197  2 paramsPerEntity.put(entityReference, entityParameters);
198    }
199    }