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.plugins.unittree.business.unit;
35  
36  import java.util.HashMap;
37  import java.util.Map;
38  
39  import javax.validation.constraints.NotNull;
40  
41  import fr.paris.lutece.portal.service.rbac.RBACResource;
42  
43  /**
44   *
45   * Unit
46   *
47   */
48  public class Unit implements RBACResource
49  {
50      public static final String RESOURCE_TYPE = "UNIT_TYPE";
51      public static final int ID_ROOT = 0;
52      public static final int ID_NULL = -1;
53      private int _nIdUnit;
54      @NotNull
55      private int _nIdParent;
56      @NotNull
57      private String _strLabel;
58      @NotNull
59      private String _strDescription;
60  
61      private String sirensiret;
62  
63      private String numero;
64  
65      private String voie;
66  
67      private String codepostal;
68  
69      private String ville;
70  
71      private TypeUnit typeunit;
72  
73      private String pays;
74  
75      private Map<String, IUnitAttribute> _mapAttributes = new HashMap<String, IUnitAttribute>( );
76  
77      public enum TypeUnit
78      {
79          VILLE,
80          CONCESSIONNAIRE
81      }
82  
83      /**
84       * Get the id unit
85       * 
86       * @return the id unit
87       */
88      public int getIdUnit( )
89      {
90          return _nIdUnit;
91      }
92  
93      /**
94       * Set the id unit
95       * 
96       * @param nIdUnit
97       *            the id unit
98       */
99      public void setIdUnit( int nIdUnit )
100     {
101         _nIdUnit = nIdUnit;
102     }
103 
104     /**
105      * Get the label
106      * 
107      * @return the label
108      */
109     public String getLabel( )
110     {
111         return _strLabel;
112     }
113 
114     /**
115      * Set the label
116      * 
117      * @param strLabel
118      *            the label
119      */
120     public void setLabel( String strLabel )
121     {
122         _strLabel = strLabel;
123     }
124 
125     /**
126      * Get the description
127      * 
128      * @return the description
129      */
130     public String getDescription( )
131     {
132         return _strDescription;
133     }
134 
135     /**
136      * Set the description
137      * 
138      * @param strDescription
139      *            the description
140      */
141     public void setDescription( String strDescription )
142     {
143         _strDescription = strDescription;
144     }
145 
146     /**
147      * Set the id parent
148      * 
149      * @param nIdParent
150      *            the nIdParent to set
151      */
152     public void setIdParent( int nIdParent )
153     {
154         this._nIdParent = nIdParent;
155     }
156 
157     /**
158      * Get the id parent
159      * 
160      * @return the nIdParent
161      */
162     public int getIdParent( )
163     {
164         return _nIdParent;
165     }
166 
167     /**
168      * Check if the unit is the root unit
169      * 
170      * @return true if the unit is the root unit, false otherwise
171      */
172     public boolean isRoot( )
173     {
174         return _nIdUnit == ID_ROOT;
175     }
176 
177     /**
178      * Get the attribute from a given key
179      * 
180      * @param <T>
181      *            the class of the attribute
182      * @param strKey
183      *            the key of the attribute
184      * @return the attribute
185      */
186     public <T> IUnitAttribute<T> getAttribute( String strKey )
187     {
188         return (IUnitAttribute<T>) _mapAttributes.get( strKey );
189     }
190 
191     /**
192      * Add an attribute
193      * 
194      * @param attribute
195      *            the attribute to add
196      */
197     public void addAttribute( IUnitAttribute<?> attribute )
198     {
199         _mapAttributes.put( attribute.getAttributeName( ), attribute );
200     }
201 
202     /**
203      * {@inheritDoc}
204      */
205     @Override
206     public String getResourceId( )
207     {
208         return Integer.toString( _nIdUnit );
209     }
210 
211     /**
212      * {@inheritDoc}
213      */
214     @Override
215     public String getResourceTypeCode( )
216     {
217         return RESOURCE_TYPE;
218     }
219 
220     public String getSirensiret( )
221     {
222         return sirensiret;
223     }
224 
225     public void setSirensiret( String sirentsiret )
226     {
227         this.sirensiret = sirentsiret;
228     }
229 
230     public String getNumero( )
231     {
232         return numero;
233     }
234 
235     public void setNumero( String numero )
236     {
237         this.numero = numero;
238     }
239 
240     public String getVoie( )
241     {
242         return voie;
243     }
244 
245     public void setVoie( String voie )
246     {
247         this.voie = voie;
248     }
249 
250     public String getCodepostal( )
251     {
252         return codepostal;
253     }
254 
255     public void setCodepostal( String codePostal )
256     {
257         this.codepostal = codePostal;
258     }
259 
260     public String getVille( )
261     {
262         return ville;
263     }
264 
265     public void setVille( String ville )
266     {
267         this.ville = ville;
268     }
269 
270     public TypeUnit getTypeunit( )
271     {
272         return typeunit;
273     }
274 
275     public void setTypeunit( TypeUnit type )
276     {
277         this.typeunit = type;
278     }
279 
280     public String getPays( )
281     {
282         return this.pays;
283     }
284 
285     public void setPays( String pays )
286     {
287         this.pays = pays;
288     }
289 
290 }