View Javadoc
1   /*
2    * Copyright (c) 2002-2022, 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.util.ReferenceItem;
38  
39  import java.util.ArrayList;
40  import java.util.Collection;
41  import java.util.Locale;
42  
43  /**
44   * This class represents business objects feature group
45   */
46  public class FeatureGroup
47  {
48      // ///////////////////////////////////////////////////////////////////////////////
49      // Constants
50      private static final String EMPTY_STRING = "";
51  
52      // ///////////////////////////////////////////////////////////////////////////////
53      // Variables
54      private String _strId;
55      private String _strDescriptionKey;
56      private String _strLabelKey;
57      private String _strIcon;
58      private int _nOrder;
59      private Collection<Right> _aFeaturesList = new ArrayList<>( );
60      private Locale _locale;
61  
62      /**
63       * Sets the locale to use
64       *
65       * @param locale
66       *            the locale to use
67       */
68      public void setLocale( Locale locale )
69      {
70          _locale = locale;
71      }
72  
73      /**
74       * Returns the identifier of this feature group
75       *
76       * @return the identifier of this feature group
77       */
78      public String getId( )
79      {
80          return _strId;
81      }
82  
83      /**
84       * Sets the identifier of the feature group to the specified string.
85       *
86       * @param strId
87       *            the new identifier
88       */
89      public void setId( String strId )
90      {
91          _strId = strId;
92      }
93  
94      /**
95       * Returns the label of this feature group.
96       *
97       * @return the feature group label
98       */
99      public String getLabelKey( )
100     {
101         return _strLabelKey;
102     }
103 
104     /**
105      * Returns the label of this feature group.
106      * 
107      * @return the feature group label
108      */
109     public String getLabel( )
110     {
111         String strLocalizedLabel = I18nService.getLocalizedString( _strLabelKey, _locale );
112         if ( !strLocalizedLabel.isEmpty( ) )
113         {
114             return strLocalizedLabel;
115         }
116         else
117         {
118             return _strLabelKey;
119         }
120     }
121 
122     /**
123      * Sets the label of the feature group to the specified string.
124      *
125      * @param strLabelKey
126      *            the new label
127      */
128     public void setLabelKey( String strLabelKey )
129     {
130         _strLabelKey = ( strLabelKey == null ) ? EMPTY_STRING : strLabelKey;
131     }
132 
133     /**
134      * Returns the order of this feature group.
135      *
136      * @return the feature group order
137      */
138     public int getOrder( )
139     {
140         return _nOrder;
141     }
142 
143     /**
144      * Sets the order of the feature group to the specified int.
145      *
146      * @param nOrder
147      *            the new level
148      */
149     public void setOrder( int nOrder )
150     {
151         _nOrder = nOrder;
152     }
153 
154     /**
155      * Returns the description of this feature group.
156      *
157      * @return the feature group description
158      */
159     public String getDescriptionKey( )
160     {
161         return _strDescriptionKey;
162     }
163 
164     /**
165      * Returns the description of this feature group.
166      *
167      * @return the feature group description
168      */
169     public String getDescription( )
170     {
171         String strLocalizedDescription = I18nService.getLocalizedString( _strDescriptionKey, _locale );
172         if ( !strLocalizedDescription.isEmpty( ) )
173         {
174             return strLocalizedDescription;
175         }
176         else
177         {
178             return _strDescriptionKey;
179         }
180     }
181 
182     /**
183      * Sets the description of the feature group to the specified string.
184      *
185      * @param strDescriptionKey
186      *            the new description
187      */
188     public void setDescriptionKey( String strDescriptionKey )
189     {
190         _strDescriptionKey = ( strDescriptionKey == null ) ? EMPTY_STRING : strDescriptionKey;
191     }
192 
193     /**
194      * Add a feature to the group
195      * 
196      * @param right
197      *            The feature to add
198      */
199     public void addFeature( Right right )
200     {
201         _aFeaturesList.add( right );
202     }
203 
204     /**
205      * Tells whether or not the feature list is empty
206      * 
207      * @return _aFeaturesList
208      */
209     public boolean isEmpty( )
210     {
211         return _aFeaturesList.isEmpty( );
212     }
213 
214     /**
215      * Returns all features affected to the group
216      * 
217      * @return a collection
218      */
219     public Collection<Right> getFeatures( )
220     {
221         return _aFeaturesList;
222     }
223 
224     /**
225      * Returns a reference item for the feature group
226      * 
227      * @return a reference item
228      */
229     public ReferenceItem getReferenceItem( )
230     {
231         ReferenceItemnceItem.html#ReferenceItem">ReferenceItem item = new ReferenceItem( );
232         item.setCode( _strId );
233         item.setName( getLabel( ) );
234         item.setChecked( true );
235         return item;
236     }
237 
238     /**
239      * Returns the icon of this feature group.
240      *
241      * @return the feature group icon
242      */
243     public String getIcon( )
244     {
245         return _strIcon;
246     }
247 
248     /**
249      * Sets the icon of the feature group to the specified string.
250      *
251      * @param strIcon
252      *            the new icon
253      */
254     public void setIcon( String strIcon )
255     {
256         _strIcon = ( strIcon == null ) ? EMPTY_STRING : strIcon;
257     }
258     
259 }