View Javadoc
1   /*
2    * Copyright (c) 2002-2014, Mairie de 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  /**
45   * This class represents business objects right
46   */
47  public class Right implements Localizable, Comparable<Right>, Serializable
48  {
49      private static final long serialVersionUID = 4075896005615205007L;
50  
51      /////////////////////////////////////////////////////////////////////////////////
52      // Constants
53      private static final String EMPTY_STRING = "";
54      private String _strId;
55      private String _strNameKey;
56      private String _strDescriptionKey;
57      private int _nLevel;
58      private String _strUrl;
59      private String _strPluginName;
60      private String _strFeatureGroup;
61      private String _strIconUrl;
62      private String _strDocumentationUrl;
63      private Locale _locale;
64      private int _nIdOrder;
65  
66      /**
67       * Set the local used by this right
68       * @param locale the local to use
69       */
70      @Override
71      public void setLocale( Locale locale )
72      {
73          _locale = locale;
74      }
75  
76      /**
77       * Returns the identifier of this right
78       *
79       * @return the identifier of this right
80       */
81      public String getId(  )
82      {
83          return _strId;
84      }
85  
86      /**
87       * Sets the identifier of the right to the specified string.
88       *
89       * @param strId the new identifier
90       */
91      public void setId( String strId )
92      {
93          _strId = strId;
94      }
95  
96      /**
97       * Returns the name of this right.
98       *
99       * @return the right name
100      */
101     public String getNameKey(  )
102     {
103         return _strNameKey;
104     }
105 
106     /**
107      * Returns the name of this right.
108      *
109      * @return the right name
110      */
111     public String getName(  )
112     {
113         return I18nService.getLocalizedString( _strNameKey, _locale );
114     }
115 
116     /**
117      * Sets the name of the right to the specified string.
118      *
119      * @param strNameKey the new name
120      */
121     public void setNameKey( String strNameKey )
122     {
123         _strNameKey = ( strNameKey == null ) ? EMPTY_STRING : strNameKey;
124     }
125 
126     /**
127      * Returns the level of this right.
128      *
129      * @return the right level
130      */
131     public int getLevel(  )
132     {
133         return _nLevel;
134     }
135 
136     /**
137      * Sets the level of the right to the specified int.
138      *
139      * @param nLevel the new level
140      */
141     public void setLevel( int nLevel )
142     {
143         _nLevel = nLevel;
144     }
145 
146     /**
147      * Returns the url of the jsp component which manages this right.
148      *
149      * @return the right url function
150      */
151     public String getUrl(  )
152     {
153         return _strUrl;
154     }
155 
156     /**
157      * Sets the url of the right to the specified string.
158      *
159      * @param strUrl the new url
160      */
161     public void setUrl( String strUrl )
162     {
163         _strUrl = strUrl;
164     }
165 
166     /**
167      * Returns the description of this right.
168      *
169      * @return the right description
170      */
171     public String getDescriptionKey(  )
172     {
173         return _strDescriptionKey;
174     }
175 
176     /**
177      * Returns the description of this right.
178      *
179      * @return the right description
180      */
181     public String getDescription(  )
182     {
183         return I18nService.getLocalizedString( _strDescriptionKey, _locale );
184     }
185 
186     /**
187      * Sets the description of the right to the specified string.
188      *
189      * @param strDescriptionKey the new description
190      */
191     public void setDescriptionKey( String strDescriptionKey )
192     {
193         _strDescriptionKey = ( strDescriptionKey == null ) ? EMPTY_STRING : strDescriptionKey;
194     }
195 
196     /**
197      * Returns the isUpdatable tag of this right ( 1 if the right is updatable, 0 if not ).
198      *
199      * @return the is_upda
200      */
201     public String getPluginName(  )
202     {
203         return _strPluginName;
204     }
205 
206     /**
207      * Sets the name of the right to the specified string.
208      *
209      * @param strPluginName the new name
210      */
211     public void setPluginName( String strPluginName )
212     {
213         _strPluginName = ( strPluginName == null ) ? EMPTY_STRING : strPluginName;
214     }
215 
216     /**
217      * Returns the feature group of this right.
218      *
219      * @return the right feature group
220          * @since 1.1.1
221      */
222     public String getFeatureGroup(  )
223     {
224         return _strFeatureGroup;
225     }
226 
227     /**
228      * Sets the feature group of the right to the specified string.
229      *
230      * @param strFeatureGroup the new feature group
231          * @since 1.1.1
232      */
233     public void setFeatureGroup( String strFeatureGroup )
234     {
235         _strFeatureGroup = strFeatureGroup;
236     }
237 
238     /**
239      * Returns the url of the icon associated to the right.
240      *
241      * @return the icon url
242      */
243     public String getIconUrl(  )
244     {
245         return _strIconUrl;
246     }
247 
248     /**
249      * Sets the url of the icon associated to the right.
250      *
251      * @param strIconUrl the new url
252      */
253     public void setIconUrl( String strIconUrl )
254     {
255         _strIconUrl = strIconUrl;
256     }
257 
258     /**
259      * Returns the url of the documentation associated to the right.
260      *
261      * @return the _strDocumentationUrl
262      */
263     public String getDocumentationUrl(  )
264     {
265         return _strDocumentationUrl;
266     }
267 
268     /**
269      * Sets the url of the documentation associated to the right.
270      *
271      * @param strDocumentationUrl the _strDocumentationUrl to set
272      */
273     public void setDocumentationUrl( String strDocumentationUrl )
274     {
275         _strDocumentationUrl = strDocumentationUrl;
276     }
277 
278     /**
279      * Get the right order
280      * @return the _order
281      */
282     public int getOrder(  )
283     {
284         return _nIdOrder;
285     }
286 
287     /**
288      * Set the right order in feature group
289      * @param nOrder the _order to set
290      */
291     public void setOrder( int nOrder )
292     {
293         this._nIdOrder = nOrder;
294     }
295 
296     /**
297      * Compare the right with the specified right
298      * @param o The right to be compared with the instanced right
299      * @return The result of comparison
300      */
301     @Override
302     public int compareTo( Right o )
303     {
304         if ( this.getOrder(  ) > o.getOrder(  ) )
305         {
306             return 1;
307         }
308         else if ( this.getOrder(  ) < o.getOrder(  ) )
309         {
310             return -1;
311         }
312         else
313         {
314             return this.getId(  ).compareTo( o.getId(  ) );
315         }
316     }
317 
318     /**
319      * {@inheritDoc}
320      */
321     @Override
322     public boolean equals( Object o )
323     {
324         if ( !( o instanceof Right ) )
325         {
326             return false;
327         }
328 
329         return compareTo( (Right) o ) == 0;
330     }
331 
332     /**
333      * {@inheritDoc}
334      */
335     @Override
336     public int hashCode(  )
337     {
338         int nIdHash = ( getId(  ) == null ) ? 0 : getId(  ).hashCode(  );
339 
340         return ( getOrder(  ) * 100 ) + nIdHash;
341     }
342 }