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 java.util.ArrayList;
37  import java.util.List;
38  
39  import javax.validation.constraints.NotEmpty;
40  import javax.validation.constraints.Pattern;
41  
42  import com.fasterxml.jackson.annotation.JsonIgnore;
43  
44  import fr.paris.lutece.plugins.pluginwizard.util.Utils;
45  
46  /**
47   * This is the business class for the object BusinessClass
48   */
49  public class BusinessClass
50  {
51      // Variables declarations
52      private int _nIdBusinessClass;
53      @NotEmpty( message = "pluginwizard.error.businessClass.class.notEmpty" )
54      @Pattern( regexp = "[A-Z][a-zA-Z]*", message = "pluginwizard.error.businessClass.class.pattern" )
55      private String _strBusinessClass;
56      @NotEmpty( message = "pluginwizard.error.businessClass.tableName.notEmpty" )
57      @Pattern( regexp = "[a-z][a-z_]*", message = "pluginwizard.error.businessClass.tableName.pattern" )
58      private String _strBusinessTableName;
59      private List<Attribute> _listAttributes;
60      private String _strPrimaryAttributeName;
61  
62      /**
63       *
64       */
65      public BusinessClass( )
66      {
67          _listAttributes = new ArrayList<>( );
68      }
69  
70      /**
71       * Returns the nIdBusinessClass
72       *
73       * @return The nIdBusinessClass
74       */
75      public int getId( )
76      {
77          return _nIdBusinessClass;
78      }
79  
80      /**
81       * Sets the nIdBusinessClass
82       *
83       * @param nIdBusinessClass
84       *            The IdPlugin
85       */
86      public void setId( int nIdBusinessClass )
87      {
88          _nIdBusinessClass = nIdBusinessClass;
89      }
90  
91      /**
92       * Returns the BusinessClass
93       *
94       * @return The BusinessClass
95       */
96      public String getBusinessClass( )
97      {
98          return _strBusinessClass;
99      }
100 
101     /**
102      * Sets the BusinessClass
103      *
104      * @param strBusinessClass
105      *            The BusinessClass
106      */
107     public void setBusinessClass( String strBusinessClass )
108     {
109         _strBusinessClass = strBusinessClass;
110     }
111 
112     /**
113      * Returns the BusinessTableName
114      *
115      * @return The BusinessTableName
116      */
117     public String getBusinessTableName( )
118     {
119         return _strBusinessTableName;
120     }
121 
122     /**
123      * Sets the BusinessTableName
124      *
125      * @param strBusinessTableName
126      *            The BusinessTableName
127      */
128     public void setBusinessTableName( String strBusinessTableName )
129     {
130         _strBusinessTableName = strBusinessTableName;
131     }
132 
133     // ///////////////////////////////////////////////////////////
134     /**
135      * Sets the list of attributes associated to business class
136      *
137      * @param listAttributes
138      *            The collection of attributes associated to the class
139      */
140     public void setAttributes( List<Attribute> listAttributes )
141     {
142         if ( listAttributes != null )
143         {
144             _listAttributes = new ArrayList<>( listAttributes );
145         }
146         else
147         {
148             _listAttributes = null;
149         }
150     }
151 
152     /**
153      * Returns the collection of attributes
154      *
155      * @return the collection of child attributes
156      */
157     public List<Attribute> getAttributes( )
158     {
159         if ( _listAttributes != null )
160         {
161             return new ArrayList<>( _listAttributes );
162         }
163         else
164         {
165             return null;
166         }
167     }
168 
169     /**
170      * Sets the primary key of the class
171      *
172      * @param strPrimaryAttributeName
173      *            The key attribute name
174      */
175     public void setPrimaryKey( String strPrimaryAttributeName )
176     {
177         _strPrimaryAttributeName = strPrimaryAttributeName;
178     }
179 
180     /**
181      * Fetches the attributes which represents the identifier of the business class
182      *
183      * @return The key
184      */
185     public String getPrimaryKey( )
186     {
187         return _strPrimaryAttributeName;
188     }
189 
190     // ////////////////////////////////////////////////////////////
191     // The methods below are meant to be used when generating the artifacts of the plugin
192 
193     /**
194      * Fetches the primary key
195      *
196      * @return The name of the key
197      */
198     @JsonIgnore
199     public String getPrimaryKeyName( )
200     {
201         return Utils.getProperName( _strPrimaryAttributeName );
202     }
203 
204     /**
205      * Returns the BusinessClass
206      *
207      * @return The BusinessClass
208      */
209     @JsonIgnore
210     public String getBusinessClassCapsFirst( )
211     {
212         char [ ] characters = _strBusinessClass.toCharArray( );
213         characters [0] = Character.toTitleCase( characters [0] );
214 
215         return String.valueOf( characters );
216     }
217 
218     /**
219      * Returns the InstanceName
220      *
221      * @return The InstanceName
222      */
223     @JsonIgnore
224     public String getInstanceName( )
225     {
226         return Utils.firstLowerCase( _strBusinessClass );
227     }
228 
229 }