1
2
3
4 package org.company.thesandbox.domain;
5
6 import org.mod4j.runtime.validation.BusinessRuleValidationSupport;
7
8 import java.util.Collections;
9 import java.util.Set;
10 import java.util.HashSet;
11 import org.mod4j.runtime.validation.MinValueValidator;
12 import org.mod4j.runtime.validation.MaxValueValidator;
13 import org.mod4j.runtime.validation.MinLengthValidator;
14 import org.mod4j.runtime.validation.MaxLengthValidator;
15 import org.mod4j.runtime.validation.RegExpValidator;
16
17 import org.joda.time.DateTime;
18
19 import org.company.thesandbox.domain.businessrules.OrderDateBeforeDeliveryDate;
20
21
22
23
24
25
26
27 @SuppressWarnings("serial")
28 public abstract class OrderImplBase implements java.io.Serializable {
29
30
31
32
33
34 protected BusinessRuleValidationSupport validation = new BusinessRuleValidationSupport(this);
35
36
37
38
39 private long id;
40
41 @SuppressWarnings("unused")
42 private int version = -1;
43
44
45
46
47
48 public Long getId() {
49 return this.id;
50 }
51
52
53
54
55 private String orderNumber;
56
57
58
59
60 private DateTime orderDate = new DateTime("2009-01-01");
61
62 public static final String ORDERDATE_ACCURACY = "Day";
63
64
65
66
67 private DateTime deliveryDateTime;
68
69 public static final String DELIVERYDATETIME_ACCURACY = "Minute";
70
71
72
73
74 private Integer discountPercentage;
75
76 public static final Integer DISCOUNTPERCENTAGE_MINVALUE = 1;
77
78 public static final Integer DISCOUNTPERCENTAGE_MAXVALUE = 100;
79
80
81
82
83 private Set<OrderLine> orderLines = new HashSet<OrderLine>();
84
85
86
87
88 public Set<OrderLine> getOrderLines() {
89 return Collections.unmodifiableSet(this.orderLines);
90 }
91
92
93
94
95 public void addToOrderLines(OrderLine element) {
96 if (element == null) {
97 return;
98 }
99 if (this.orderLines.contains(element)) {
100 return;
101 }
102 this.orderLines.add(element);
103
104 }
105
106
107
108
109
110
111 public void removeFromOrderLines(OrderLine element) {
112 if (element == null) {
113 return;
114 }
115 this.orderLines.remove(element);
116
117 validation.validate();
118 }
119
120
121
122
123
124
125 public void z_internalAddToorderLines(OrderLine element) {
126 this.orderLines.add(element);
127 }
128
129
130
131
132
133
134 public void z_internalRemoveFromorderLines(OrderLine element) {
135 this.orderLines.remove(element);
136 }
137
138 private Customer customer;
139
140
141
142
143
144
145 public Customer getCustomer() {
146 return this.customer;
147 }
148
149
150
151
152
153
154 public void setCustomer(Customer element) {
155 if (this.customer != element) {
156 if (this.customer != null) {
157 this.customer.z_internalRemoveFromorders((Order) ((Order) this));
158 }
159 this.customer = element;
160 if (element != null) {
161 element.z_internalAddToorders((Order) ((Order) this));
162 }
163 }
164 validation.validate();
165 }
166
167
168
169
170
171
172
173 public void z_internalAddTocustomer(Customer element) {
174 this.customer = element;
175 }
176
177
178
179
180
181
182
183 public void z_internalRemoveFromcustomer(Customer element) {
184 this.customer = null;
185 }
186
187
188
189
190 protected OrderImplBase() {
191
192 }
193
194
195
196
197
198
199
200 public OrderImplBase(String orderNumber) {
201
202 this.orderNumber = orderNumber;
203
204 validation.addValidator(new MinValueValidator(Order.class, "discountPercentage", DISCOUNTPERCENTAGE_MINVALUE));
205
206 validation.addValidator(new MaxValueValidator(Order.class, "discountPercentage", DISCOUNTPERCENTAGE_MAXVALUE));
207
208 validation.addValidator(new OrderDateBeforeDeliveryDate());
209
210 validation.validate();
211 }
212
213
214
215
216
217 public String getOrderNumber() {
218 return this.orderNumber;
219 }
220
221
222
223
224
225 public DateTime getOrderDate() {
226 return this.orderDate;
227 }
228
229
230
231
232
233 public DateTime getDeliveryDateTime() {
234 return this.deliveryDateTime;
235 }
236
237
238
239
240
241 public Integer getDiscountPercentage() {
242 return this.discountPercentage;
243 }
244
245
246
247
248
249 public void setOrderNumber(final String orderNumber) {
250 this.orderNumber = orderNumber;
251 validation.validate();
252 }
253
254
255
256
257
258 public void setOrderDate(final DateTime orderDate) {
259 this.orderDate = orderDate;
260 validation.validate();
261 }
262
263
264
265
266
267 public void setDeliveryDateTime(final DateTime deliveryDateTime) {
268 this.deliveryDateTime = deliveryDateTime;
269 validation.validate();
270 }
271
272
273
274
275
276 public void setDiscountPercentage(final Integer discountPercentage) {
277 this.discountPercentage = discountPercentage;
278 validation.validate();
279 }
280
281
282
283
284
285
286
287
288 public void activateValidation(boolean value) {
289
290 this.validation.setActive(value);
291 if (value) {
292 validation.validate();
293 }
294 }
295
296 }