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.pluginwizard.business.model;
35  
36  import fr.paris.lutece.plugins.pluginwizard.service.ModelService;
37  import fr.paris.lutece.plugins.pluginwizard.util.Utils;
38  
39  import com.fasterxml.jackson.annotation.JsonIgnore;
40  
41  import java.io.Serializable;
42  
43  import javax.validation.constraints.NotEmpty;
44  import javax.validation.constraints.Pattern;
45  
46  /**
47   * This is the business class for the object Attribute
48   */
49  public class Attribute implements Serializable
50  {
51      /**
52       * 
53       */
54      private static final long serialVersionUID = 1L;
55      // Variables declarations
56      private int _nIdAttribute;
57      private int _nAttributeTypeId;
58      @NotEmpty( message = "pluginwizard.error.attribute.name.notEmpty" )
59      @Pattern( regexp = "[a-z_]*", message = "pluginwizard.error.attribute.name.pattern" )
60      private String _strAttributeName;
61      private int _nMaxLength;
62      private boolean _bNotNull;
63  
64      /**
65       * Returns the IdAttribute
66       * 
67       * @return The IdAttribute
68       */
69      public int getId( )
70      {
71          return _nIdAttribute;
72      }
73  
74      /**
75       * Sets the IdAttribute
76       * 
77       * @param nIdAttribute
78       *            The IdAttribute
79       */
80      public void setId( int nIdAttribute )
81      {
82          _nIdAttribute = nIdAttribute;
83      }
84  
85      /**
86       * Returns the AttributeTypeId
87       * 
88       * @return The AttributeTypeId
89       */
90      public int getAttributeTypeId( )
91      {
92          return _nAttributeTypeId;
93      }
94  
95      /**
96       * Sets the AttributeTypeId
97       * 
98       * @param nAttributeTypeId
99       *            The AttributeTypeId
100      */
101     public void setAttributeTypeId( int nAttributeTypeId )
102     {
103         _nAttributeTypeId = nAttributeTypeId;
104     }
105 
106     /**
107      * Returns the AttributeName
108      * 
109      * @return The AttributeName
110      */
111     public String getAttributeName( )
112     {
113         return _strAttributeName;
114     }
115 
116     /**
117      * Sets the AttributeName
118      * 
119      * @param strAttributeName
120      *            The AttributeName
121      */
122     public void setAttributeName( String strAttributeName )
123     {
124         _strAttributeName = strAttributeName;
125     }
126 
127     /**
128      * Returns the Type
129      *
130      * @return The Type
131      */
132     @JsonIgnore
133     public String getType( )
134     {
135         return ModelService.getAttributeType( _nAttributeTypeId );
136     }
137 
138     /**
139      * Returns the Name
140      * 
141      * @return The Name
142      */
143     @JsonIgnore
144     public String getName( )
145     {
146         return Utils.getProperName( _strAttributeName );
147     }
148 
149     /**
150      * Returns the Name
151      * 
152      * @return The Name
153      */
154     @JsonIgnore
155     public String getLabelName( )
156     {
157         return _strAttributeName.substring( 0, 1 ).toUpperCase( ) + _strAttributeName.substring( 1 ).replace( "_", " " );
158     }
159 
160     /**
161      * Returns the VariableName
162      * 
163      * @return The VariableName
164      */
165     @JsonIgnore
166     public String getVariableName( )
167     {
168         return ModelService.getAttributePrefix( _nAttributeTypeId ) + Utils.getProperName( _strAttributeName );
169     }
170 
171     /**
172      * Returns the type description
173      * 
174      * @return The type description
175      */
176     @JsonIgnore
177     public String getTypeDescription( )
178     {
179         return ModelService.getAttributeTypeDescription( _nAttributeTypeId );
180     }
181 
182     /**
183      * Returns the Param Name
184      * 
185      * @return The Param VariableName
186      */
187     @JsonIgnore
188     public String getParamName( )
189     {
190         return _strAttributeName.toLowerCase( );
191     }
192 
193     /**
194      * Returns the java name of the attribute
195      * 
196      * @return The java name
197      */
198     @JsonIgnore
199     public String getJavaName( )
200     {
201         return Utils.getProperName( _strAttributeName ).substring( 0, 1 ).toLowerCase( ) + Utils.getProperName( _strAttributeName ).substring( 1 );
202     }
203 
204     /**
205      * @return the maxLength
206      */
207     public int getMaxLength( )
208     {
209         return _nMaxLength;
210     }
211 
212     /**
213      * @param maxLength
214      *            the maxLength to set
215      */
216     public void setMaxLength( int maxLength )
217     {
218         _nMaxLength = maxLength;
219     }
220 
221     /**
222      * Returns the bNotNull
223      * 
224      * @return The NotNull
225      */
226     public boolean getNotNull( )
227     {
228         return _bNotNull;
229     }
230 
231     /**
232      * Sets the Description
233      * 
234      * @param bNotNull
235      *            The Description
236      */
237     public void setNotNull( boolean bNotNull )
238     {
239         _bNotNull = bNotNull;
240     }
241 
242     /**
243      * Returns the Constraint
244      *
245      * @return The Constraint
246      */
247     @JsonIgnore
248     public String getConstraint( )
249     {
250         return ModelService.getAttributeConstraint( _nAttributeTypeId );
251     }
252 }