1 /*
2 * Copyright (c) 2002-2025, City of Paris
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice
10 * and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright notice
13 * and the following disclaimer in the documentation and/or other materials
14 * provided with the distribution.
15 *
16 * 3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 *
32 * License 1.0
33 */
34 package fr.paris.lutece.portal.business.right;
35
36 import fr.paris.lutece.portal.service.i18n.I18nService;
37 import fr.paris.lutece.portal.service.i18n.Localizable;
38
39 import java.io.Serializable;
40
41 import java.util.Locale;
42
43 /**
44 * This class represents business objects right
45 */
46 public class Right implements Localizable, Comparable<Right>, Serializable
47 {
48 private static final long serialVersionUID = 4075896005615205007L;
49
50 // ///////////////////////////////////////////////////////////////////////////////
51 // Constants
52 private static final String EMPTY_STRING = "";
53 private String _strId;
54 private String _strNameKey;
55 private String _strDescriptionKey;
56 private int _nLevel;
57 private String _strUrl;
58 private String _strPluginName;
59 private String _strFeatureGroup;
60 private String _strIconUrl;
61 private String _strDocumentationUrl;
62 private Locale _locale;
63 private int _nIdOrder;
64 private boolean _bIsExternalFeature;
65
66 /**
67 * Set the local used by this right
68 *
69 * @param locale
70 * the local to use
71 */
72 @Override
73 public void setLocale( Locale locale )
74 {
75 _locale = locale;
76 }
77
78 /**
79 * Returns the identifier of this right
80 *
81 * @return the identifier of this right
82 */
83 public String getId( )
84 {
85 return _strId;
86 }
87
88 /**
89 * Sets the identifier of the right to the specified string.
90 *
91 * @param strId
92 * the new identifier
93 */
94 public void setId( String strId )
95 {
96 _strId = strId;
97 }
98
99 /**
100 * Returns the name of this right.
101 *
102 * @return the right name
103 */
104 public String getNameKey( )
105 {
106 return _strNameKey;
107 }
108
109 /**
110 * Returns the name of this right if the i18n key exists; else return the i18n key.
111 *
112 * @return the right name
113 */
114 public String getName( )
115 {
116 String strReturn = I18nService.getLocalizedString( _strNameKey, _locale );
117 if ( !strReturn.equals( "" ) )
118 {
119 return I18nService.getLocalizedString( _strNameKey, _locale );
120 }
121 return _strNameKey;
122 }
123
124 /**
125 * Sets the name of the right to the specified string.
126 *
127 * @param strNameKey
128 * the new name
129 */
130 public void setNameKey( String strNameKey )
131 {
132 _strNameKey = ( strNameKey == null ) ? EMPTY_STRING : strNameKey;
133 }
134
135 /**
136 * Returns the level of this right.
137 *
138 * @return the right level
139 */
140 public int getLevel( )
141 {
142 return _nLevel;
143 }
144
145 /**
146 * Sets the level of the right to the specified int.
147 *
148 * @param nLevel
149 * the new level
150 */
151 public void setLevel( int nLevel )
152 {
153 _nLevel = nLevel;
154 }
155
156 /**
157 * Returns the url of the jsp component which manages this right.
158 *
159 * @return the right url function
160 */
161 public String getUrl( )
162 {
163 return _strUrl;
164 }
165
166 /**
167 * Sets the url of the right to the specified string.
168 *
169 * @param strUrl
170 * the new url
171 */
172 public void setUrl( String strUrl )
173 {
174 _strUrl = strUrl;
175 }
176
177 /**
178 * Returns the description of this right.
179 *
180 * @return the right description
181 */
182 public String getDescriptionKey( )
183 {
184 return _strDescriptionKey;
185 }
186
187 /**
188 * Returns the description of this right if the i18nk exists; else return the key.
189 *
190 * @return the right description
191 */
192 public String getDescription( )
193 {
194 String strReturn = I18nService.getLocalizedString( _strDescriptionKey, _locale );
195 if ( !strReturn.equals( "" ) )
196 {
197 return I18nService.getLocalizedString( _strDescriptionKey, _locale );
198 }
199 return _strDescriptionKey;
200 }
201
202 /**
203 * Sets the description of the right to the specified string.
204 *
205 * @param strDescriptionKey
206 * the new description
207 */
208 public void setDescriptionKey( String strDescriptionKey )
209 {
210 _strDescriptionKey = ( strDescriptionKey == null ) ? EMPTY_STRING : strDescriptionKey;
211 }
212
213 /**
214 * Returns the isUpdatable tag of this right ( 1 if the right is updatable, 0 if not ).
215 *
216 * @return the is_upda
217 */
218 public String getPluginName( )
219 {
220 return _strPluginName;
221 }
222
223 /**
224 * Sets the name of the right to the specified string.
225 *
226 * @param strPluginName
227 * the new name
228 */
229 public void setPluginName( String strPluginName )
230 {
231 _strPluginName = ( strPluginName == null ) ? EMPTY_STRING : strPluginName;
232 }
233
234 /**
235 * Returns the feature group of this right.
236 *
237 * @return the right feature group
238 * @since 1.1.1
239 */
240 public String getFeatureGroup( )
241 {
242 return _strFeatureGroup;
243 }
244
245 /**
246 * Sets the feature group of the right to the specified string.
247 *
248 * @param strFeatureGroup
249 * the new feature group
250 * @since 1.1.1
251 */
252 public void setFeatureGroup( String strFeatureGroup )
253 {
254 _strFeatureGroup = strFeatureGroup;
255 }
256
257 /**
258 * Returns the url of the icon associated to the right.
259 *
260 * @return the icon url
261 */
262 public String getIconUrl( )
263 {
264 return _strIconUrl;
265 }
266
267 /**
268 * Sets the url of the icon associated to the right.
269 *
270 * @param strIconUrl
271 * the new url
272 */
273 public void setIconUrl( String strIconUrl )
274 {
275 _strIconUrl = strIconUrl;
276 }
277
278 /**
279 * Returns the url of the documentation associated to the right.
280 *
281 * @return the _strDocumentationUrl
282 */
283 public String getDocumentationUrl( )
284 {
285 return _strDocumentationUrl;
286 }
287
288 /**
289 * Sets the url of the documentation associated to the right.
290 *
291 * @param strDocumentationUrl
292 * the _strDocumentationUrl to set
293 */
294 public void setDocumentationUrl( String strDocumentationUrl )
295 {
296 _strDocumentationUrl = strDocumentationUrl;
297 }
298
299 /**
300 * Get the right order
301 *
302 * @return the _order
303 */
304 public int getOrder( )
305 {
306 return _nIdOrder;
307 }
308
309 /**
310 * Set the right order in feature group
311 *
312 * @param nOrder
313 * the _order to set
314 */
315 public void setOrder( int nOrder )
316 {
317 this._nIdOrder = nOrder;
318 }
319
320 /**
321 * Get the external feature boolean
322 *
323 * @return the _isExternalFeature
324 */
325 public boolean isExternalFeature( )
326 {
327 return _bIsExternalFeature;
328 }
329
330 /**
331 * Set the external feature boolean
332 *
333 * @param bExternalFeature
334 * the _isExternalFeature to set
335 */
336 public void setExternalFeature( boolean bExternalFeature )
337 {
338 this._bIsExternalFeature = bExternalFeature;
339 }
340
341 /**
342 * Compare the right with the specified right
343 *
344 * @param o
345 * The right to be compared with the instanced right
346 * @return The result of comparison
347 */
348 @Override
349 public int compareTo( Right o )
350 {
351 if ( this.getOrder( ) > o.getOrder( ) )
352 {
353 return 1;
354 }
355 else
356 if ( this.getOrder( ) < o.getOrder( ) )
357 {
358 return -1;
359 }
360 else
361 {
362 return this.getId( ).compareTo( o.getId( ) );
363 }
364 }
365
366 /**
367 * {@inheritDoc}
368 */
369 @Override
370 public boolean equals( Object o )
371 {
372 if ( !( o instanceof Right ) )
373 {
374 return false;
375 }
376
377 return compareTo( (Right) o ) == 0;
378 }
379
380 /**
381 * {@inheritDoc}
382 */
383 @Override
384 public int hashCode( )
385 {
386 int nIdHash = ( getId( ) == null ) ? 0 : getId( ).hashCode( );
387
388 return ( getOrder( ) * 100 ) + nIdHash;
389 }
390 }