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

File EntityRequest.java

 

Coverage histogram

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

Code metrics

4
13
8
1
151
57
10
0.77
1.62
8
1.25

Classes

Class Line # Actions
EntityRequest 36 13 0% 10 1
0.9696%
 

Contributing tests

This file is covered by 67 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.api.AbstractCheckRightsRequest;
28    import org.xwiki.model.reference.EntityReference;
29   
30    /**
31    * A generic job request that targets multiple entities.
32    *
33    * @version $Id: 46c2a6231c563e1461d83fd5fd82580deb61a33b $
34    * @since 7.2M1
35    */
 
36    public class EntityRequest extends AbstractCheckRightsRequest
37    {
38    /**
39    * Serialization identifier.
40    */
41    private static final long serialVersionUID = 1L;
42   
43    /**
44    * @see #getJobType()
45    */
46    private static final String PROPERTY_JOB_TYPE = "job.type";
47   
48    /**
49    * @see #getEntityReferences()
50    */
51    private static final String PROPERTY_ENTITY_REFERENCES = "entityReferences";
52   
53    /**
54    * @see #getEntityParameters(EntityReference)
55    */
56    private static final String PROPERTY_ENTITY_PARAMETERS = "entityParameters";
57   
58    /**
59    * @see #isDeep()
60    */
61    private static final String PROPERTY_DEEP = "deep";
62   
63    /**
64    * @return the type of job that should perform this request; this is useful when different jobs use the same type of
65    * request
66    * @deprecated since 9.2RC1, use {@link EntityJobStatus#getJobType()} instead
67    */
 
68  8 toggle @Deprecated
69    public String getJobType()
70    {
71  8 return getProperty(PROPERTY_JOB_TYPE);
72    }
73   
74    /**
75    * Sets the type of job that should perform this request. This is useful when different jobs use the same type of
76    * request.
77    *
78    * @param jobType the type of job that should perform this request
79    * @deprecated
80    */
 
81  157 toggle @Deprecated
82    public void setJobType(String jobType)
83    {
84  157 setProperty(PROPERTY_JOB_TYPE, jobType);
85    }
86   
87    /**
88    * @return the collection of entity references that are targeted by this request
89    */
 
90  422 toggle public Collection<EntityReference> getEntityReferences()
91    {
92  422 return getProperty(PROPERTY_ENTITY_REFERENCES);
93    }
94   
95    /**
96    * Sets the collection of entity references that are targeted by this request.
97    *
98    * @param entityReferences a collection of entity references
99    */
 
100  258 toggle public void setEntityReferences(Collection<EntityReference> entityReferences)
101    {
102  258 setProperty(PROPERTY_ENTITY_REFERENCES, entityReferences);
103    }
104   
105    /**
106    * @return {@code true} if the operation should target child entities also (i.e. go deep into the entity hierarchy),
107    * {@code false} otherwise
108    */
 
109  259 toggle public boolean isDeep()
110    {
111  259 return getProperty(PROPERTY_DEEP, false);
112    }
113   
114    /**
115    * Sets whether the operation should target child entities also (i.e. go deep into the entity hierarchy) or not.
116    *
117    * @param deep {@code true} to include the child entities, {@code false} otherwise
118    */
 
119  58 toggle public void setDeep(boolean deep)
120    {
121  58 setProperty(PROPERTY_DEEP, deep);
122    }
123   
124    /**
125    * @param entityReference one of the entity references that are the target of this request
126    * @return the custom parameters associated to the specified target entity
127    */
 
128  40 toggle public Map<String, String> getEntityParameters(EntityReference entityReference)
129    {
130  40 Map<String, String> entityParameters =
131    getProperty(PROPERTY_ENTITY_PARAMETERS, Collections.<EntityReference, Map<String, String>>emptyMap())
132    .get(entityReference);
133  40 return entityParameters == null ? Collections.emptyMap() : entityParameters;
134    }
135   
136    /**
137    * Associates custom parameters to a target entity.
138    *
139    * @param entityReference one of the target entities
140    * @param entityParameters the custom parameters to associate to the specified target entity
141    */
 
142  5 toggle public void setEntityParameters(EntityReference entityReference, Map<String, String> entityParameters)
143    {
144  5 Map<EntityReference, Map<String, String>> paramsPerEntity = getProperty(PROPERTY_ENTITY_PARAMETERS);
145  5 if (paramsPerEntity == null) {
146  5 paramsPerEntity = new HashMap<>();
147  5 setProperty(PROPERTY_ENTITY_PARAMETERS, paramsPerEntity);
148    }
149  5 paramsPerEntity.put(entityReference, entityParameters);
150    }
151    }