View Javadoc

1   /**
2    * Generated by Mod4j BusinessDomain DSL by BeanClassImplBase in JavaBean.xpt at: Mon Oct 20 22:16:43 CEST 2008
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   * An Order represents the agreement between a Customer and the RecordShop about one or more purchased Records.
23   * 
24   * @author Generated by Mod4j BusinessDomain DSL
25   */
26  
27  @SuppressWarnings("serial")
28  public abstract class OrderImplBase implements java.io.Serializable {
29  
30      /**
31       * validation : Responsible for validating attribute constraints and businessrules for this business class.
32       * 
33       */
34      protected BusinessRuleValidationSupport validation = new BusinessRuleValidationSupport(this);
35  
36      /**
37       * id: The identifier of this object.
38       */
39      private long id;
40  
41      @SuppressWarnings("unused")
42      private int version = -1;
43  
44      /**
45       * 
46       * @return id (Long) The identifier of this object.
47       */
48      public Long getId() {
49          return this.id;
50      }
51  
52      /**
53       * orderNumber: An ordernumber should be unique
54       */
55      private String orderNumber;
56  
57      /**
58       * orderDate: The date on which the order has been placed
59       */
60      private DateTime orderDate = new DateTime("2009-01-01");
61  
62      public static final String ORDERDATE_ACCURACY = "Day";
63  
64      /**
65       * deliveryDateTime:
66       */
67      private DateTime deliveryDateTime;
68  
69      public static final String DELIVERYDATETIME_ACCURACY = "Minute";
70  
71      /**
72       * discountPercentage:
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       * orderLines: One 2 Many unidirectional: An order consists of orderlines
82       */
83      private Set<OrderLine> orderLines = new HashSet<OrderLine>();
84  
85      /**
86       * @return orderLines (Set<OrderLine>)
87       */
88      public Set<OrderLine> getOrderLines() {
89          return Collections.unmodifiableSet(this.orderLines);
90      }
91  
92      /**
93       * Implements adding single element to a collection
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      * Implements removal of a single element from feature
108      * 
109      * @param element
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      * This operation should NOT be used by clients. It implements the correct addition of an element in an association.
122      * 
123      * @param element
124      */
125     public void z_internalAddToorderLines(OrderLine element) {
126         this.orderLines.add(element);
127     }
128 
129     /**
130      * This operation should NOT be used by clients. It implements the correct removal of an element in an association.
131      * 
132      * @param element
133      */
134     public void z_internalRemoveFromorderLines(OrderLine element) {
135         this.orderLines.remove(element);
136     }
137 
138     private Customer customer;
139 
140     /**
141      * Implements the setter of association end
142      * 
143      * @param element
144      */
145     public Customer getCustomer() {
146         return this.customer;
147     }
148 
149     /**
150      * Implements the setter of association end
151      * 
152      * @param element
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      * Should NOT be used by clients! Implements the correct setting of the link for + owner : Customer when a single
169      * element is added to it.
170      * 
171      * @param element
172      */
173     public void z_internalAddTocustomer(Customer element) {
174         this.customer = element;
175     }
176 
177     /**
178      * Should NOT be used by clients! Implements the correct setting of the link for + owner : Customer when a single
179      * element is removed to it.
180      * 
181      * @param element
182      */
183     public void z_internalRemoveFromcustomer(Customer element) {
184         this.customer = null;
185     }
186 
187     /**
188      * Default no-argument constructor for OrderImplBase
189      */
190     protected OrderImplBase() {
191 
192     }
193 
194     /**
195      * Minimal constructor for OrderImplBase
196      * 
197      * @param orderNumber
198      *            (string) An ordernumber should be unique
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      * @return orderNumber (String) An ordernumber should be unique
216      */
217     public String getOrderNumber() {
218         return this.orderNumber;
219     }
220 
221     /**
222      * 
223      * @return orderDate (DateTime) The date on which the order has been placed
224      */
225     public DateTime getOrderDate() {
226         return this.orderDate;
227     }
228 
229     /**
230      * 
231      * @return deliveryDateTime (DateTime)
232      */
233     public DateTime getDeliveryDateTime() {
234         return this.deliveryDateTime;
235     }
236 
237     /**
238      * 
239      * @return discountPercentage (Integer)
240      */
241     public Integer getDiscountPercentage() {
242         return this.discountPercentage;
243     }
244 
245     /**
246      * @param orderNumber
247      *            (String) An ordernumber should be unique
248      */
249     public void setOrderNumber(final String orderNumber) {
250         this.orderNumber = orderNumber;
251         validation.validate();
252     }
253 
254     /**
255      * @param orderDate
256      *            (DateTime) The date on which the order has been placed
257      */
258     public void setOrderDate(final DateTime orderDate) {
259         this.orderDate = orderDate;
260         validation.validate();
261     }
262 
263     /**
264      * @param deliveryDateTime
265      *            (DateTime)
266      */
267     public void setDeliveryDateTime(final DateTime deliveryDateTime) {
268         this.deliveryDateTime = deliveryDateTime;
269         validation.validate();
270     }
271 
272     /**
273      * @param discountPercentage
274      *            (Integer)
275      */
276     public void setDiscountPercentage(final Integer discountPercentage) {
277         this.discountPercentage = discountPercentage;
278         validation.validate();
279     }
280 
281     /**
282      * Activate/deactivate validation for this business class. When set to active the validation will immediately be
283      * executed.
284      * 
285      * @param value
286      *            (boolean)
287      */
288     public void activateValidation(boolean value) {
289 
290         this.validation.setActive(value);
291         if (value) {
292             validation.validate();
293         }
294     }
295 
296 }