]> git.mxchange.org Git - jcustomer-core.git/blobdiff - src/org/mxchange/jcustomercore/events/customer/added/AdminAddedCustomerEvent.java
Continued a bit:
[jcustomer-core.git] / src / org / mxchange / jcustomercore / events / customer / added / AdminAddedCustomerEvent.java
index 8b13aa513a1fdaf51ff819ab49e190f57e77b2c6..89ecf1a2b792ea96e16a56d6edc8cb24f32d15aa 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 Roland Häder
+ * Copyright (C) 2016, 2017 Roland Häder
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  */
 package org.mxchange.jcustomercore.events.customer.added;
 
-import java.io.Serializable;
+import java.text.MessageFormat;
 import org.mxchange.jcustomercore.model.customer.Customer;
 
 /**
- * An interface for events being fired when an administrator has added a
- * customer.
+ * An event being fired when an administrator has added a new customer
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
-public interface AdminAddedCustomerEvent extends Serializable {
+public class AdminAddedCustomerEvent implements ObservableAdminAddedCustomerEvent {
 
        /**
-        * Getter for added customer instance
+        * Serial number
+        */
+       private static final long serialVersionUID = 1_782_358_678_347_190L;
+
+       /**
+        * Added customer
+        */
+       private final Customer addedCustomer;
+
+       /**
+        * Constructor with valid customer instance being added (updated varriant)
         * <p>
-        * @return Added customer instance
+        * @param addedCustomer Added customer instance
         */
-       Customer getAddedCustomer ();
+       public AdminAddedCustomerEvent (final Customer addedCustomer) {
+               // The instance should be valid
+               if (null == addedCustomer) {
+                       // Throw NPE
+                       throw new NullPointerException("addedCustomer is null"); //NOI18N
+               } else if (addedCustomer.getCustomerId() == null) {
+                       // Throw NPE, again ...
+                       throw new NullPointerException("addedCustomer.customerId is null"); //NOI18N
+               } else if (addedCustomer.getCustomerId() < 1) {
+                       // Not valid
+                       throw new IllegalArgumentException(MessageFormat.format("addedCustomer.customerId={0} is not valid", addedCustomer.getCustomerId())); //NOI18N
+               } else if (addedCustomer.getCustomerNumber() == null) {
+                       // Throw NPE, again ...
+                       throw new NullPointerException("addedCustomer.customerNumber is null"); //NOI18N
+               } else if (addedCustomer.getCustomerNumber() == null) {
+                       // Empty customer number
+                       throw new IllegalArgumentException("addedCustomer.customerNumber is empty"); //NOI18N
+               } else if (addedCustomer.getCustomerContact() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("addedCustomer.customerContact is null"); //NOI18N
+               } else if (addedCustomer.getCustomerContact().getContactId() == null) {
+                       // ... and again ...
+                       throw new NullPointerException("addedCustomer.customerContact.contactId is null"); //NOI18N
+               } else if (addedCustomer.getCustomerContact().getContactId() < 1) {
+                       // Not valid
+                       throw new IllegalArgumentException(MessageFormat.format("addedCustomer.customerContact.contactId={0} is not valid", addedCustomer.getCustomerContact().getContactId())); //NOI18N
+               }
+
+               // Set it here
+               this.addedCustomer = addedCustomer;
+       }
+
+       @Override
+       public Customer getAddedCustomer () {
+               return this.addedCustomer;
+       }
 
 }