1 /*
2 * Copyright (c) 2002-2025, 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.pluralBusinessClass.notEmpty" )
57 @Pattern( regexp = "[A-Z][a-zA-Z]*", message = "pluginwizard.error.businessClass.pluralBusinessClass.pattern" )
58 private String _strPluralBusinessClass;
59 @NotEmpty( message = "pluginwizard.error.businessClass.tableName.notEmpty" )
60 @Pattern( regexp = "[a-z][a-z_]*", message = "pluginwizard.error.businessClass.tableName.pattern" )
61 private String _strBusinessTableName;
62 private List<Attribute> _listAttributes;
63 private String _strPrimaryAttributeName;
64
65 /**
66 *
67 */
68 public BusinessClass( )
69 {
70 _listAttributes = new ArrayList<>( );
71 }
72
73 /**
74 * Returns the nIdBusinessClass
75 *
76 * @return The nIdBusinessClass
77 */
78 public int getId( )
79 {
80 return _nIdBusinessClass;
81 }
82
83 /**
84 * Sets the nIdBusinessClass
85 *
86 * @param nIdBusinessClass
87 * The IdPlugin
88 */
89 public void setId( int nIdBusinessClass )
90 {
91 _nIdBusinessClass = nIdBusinessClass;
92 }
93
94 /**
95 * Returns the BusinessClass
96 *
97 * @return The BusinessClass
98 */
99 public String getBusinessClass( )
100 {
101 return _strBusinessClass;
102 }
103
104 /**
105 * Sets the BusinessClass
106 *
107 * @param strBusinessClass
108 * The BusinessClass
109 */
110 public void setBusinessClass( String strBusinessClass )
111 {
112 _strBusinessClass = strBusinessClass;
113 }
114
115 /**
116 * Returns the PluralBusinessClass
117 *
118 * @return The PluralBusinessClass
119 */
120 public String getPluralBusinessClass( )
121 {
122 return _strPluralBusinessClass;
123 }
124
125 /**
126 * Sets the PluralBusinessClass
127 *
128 * @param strPluralBusinessClass
129 * The PluralBusinessClass
130 */
131 public void setPluralBusinessClass( String strPluralBusinessClass )
132 {
133 _strPluralBusinessClass = strPluralBusinessClass;
134 }
135
136 /**
137 * Returns the BusinessTableName
138 *
139 * @return The BusinessTableName
140 */
141 public String getBusinessTableName( )
142 {
143 return _strBusinessTableName;
144 }
145
146 /**
147 * Sets the BusinessTableName
148 *
149 * @param strBusinessTableName
150 * The BusinessTableName
151 */
152 public void setBusinessTableName( String strBusinessTableName )
153 {
154 _strBusinessTableName = strBusinessTableName;
155 }
156
157 // ///////////////////////////////////////////////////////////
158 /**
159 * Sets the list of attributes associated to business class
160 *
161 * @param listAttributes
162 * The collection of attributes associated to the class
163 */
164 public void setAttributes( List<Attribute> listAttributes )
165 {
166 if ( listAttributes != null )
167 {
168 _listAttributes = new ArrayList<>( listAttributes );
169 }
170 else
171 {
172 _listAttributes = null;
173 }
174 }
175
176 /**
177 * Returns the collection of attributes
178 *
179 * @return the collection of child attributes
180 */
181 public List<Attribute> getAttributes( )
182 {
183 if ( _listAttributes != null )
184 {
185 return new ArrayList<>( _listAttributes );
186 }
187 else
188 {
189 return null;
190 }
191 }
192
193 /**
194 * Sets the primary key of the class
195 *
196 * @param strPrimaryAttributeName
197 * The key attribute name
198 */
199 public void setPrimaryKey( String strPrimaryAttributeName )
200 {
201 _strPrimaryAttributeName = strPrimaryAttributeName;
202 }
203
204 /**
205 * Fetches the attributes which represents the identifier of the business class
206 *
207 * @return The key
208 */
209 public String getPrimaryKey( )
210 {
211 return _strPrimaryAttributeName;
212 }
213
214 // ////////////////////////////////////////////////////////////
215 // The methods below are meant to be used when generating the artifacts of the plugin
216
217 /**
218 * Fetches the primary key
219 *
220 * @return The name of the key
221 */
222 @JsonIgnore
223 public String getPrimaryKeyName( )
224 {
225 return Utils.getProperName( _strPrimaryAttributeName );
226 }
227
228 /**
229 * Returns the BusinessClass
230 *
231 * @return The BusinessClass
232 */
233 @JsonIgnore
234 public String getBusinessClassCapsFirst( )
235 {
236 char [ ] characters = _strBusinessClass.toCharArray( );
237 characters [0] = Character.toTitleCase( characters [0] );
238
239 return String.valueOf( characters );
240 }
241
242
243 /**
244 * Returns the BusinessClass
245 *
246 * @return The BusinessClass
247 */
248 @JsonIgnore
249 public String getPluralBusinessClassCapsFirst( )
250 {
251 char [ ] characters = _strPluralBusinessClass.toCharArray( );
252 characters [0] = Character.toTitleCase( characters [0] );
253
254 return String.valueOf( characters );
255 }
256
257
258 /**
259 * Returns the InstanceName
260 *
261 * @return The InstanceName
262 */
263 @JsonIgnore
264 public String getInstanceName( )
265 {
266 return Utils.firstLowerCase( _strBusinessClass );
267 }
268
269 }