]> git.mxchange.org Git - jcustomer-core.git/commitdiff
Continued with customer events:
authorRoland Häder <roland@mxchange.org>
Tue, 26 Apr 2016 08:01:55 +0000 (10:01 +0200)
committerRoland Häder <roland@mxchange.org>
Tue, 26 Apr 2016 08:01:55 +0000 (10:01 +0200)
- added event being fired when the administrator has added a new customer
- the customer instance must be persisted already as the id numbers are being validated.

src/org/mxchange/jcustomercore/events/AdminAddedCustomerEvent.java [new file with mode: 0644]
src/org/mxchange/jcustomercore/events/CustomerAdminAddedEvent.java [new file with mode: 0644]

diff --git a/src/org/mxchange/jcustomercore/events/AdminAddedCustomerEvent.java b/src/org/mxchange/jcustomercore/events/AdminAddedCustomerEvent.java
new file mode 100644 (file)
index 0000000..ea2c0dd
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2016 Roland Haeder
+ *
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcustomercore.events;
+
+import java.io.Serializable;
+import org.mxchange.jcustomercore.model.customer.Customer;
+
+/**
+ * An interface for events being fired when an administrator has added a
+ * customer.
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+public interface AdminAddedCustomerEvent extends Serializable {
+
+       /**
+        * Getter for added customer instance
+        * <p>
+        * @return Added customer instance
+        */
+       Customer getAddedCustomer ();
+
+}
diff --git a/src/org/mxchange/jcustomercore/events/CustomerAdminAddedEvent.java b/src/org/mxchange/jcustomercore/events/CustomerAdminAddedEvent.java
new file mode 100644 (file)
index 0000000..a932797
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2016 Roland Haeder
+ *
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcustomercore.events;
+
+import java.text.MessageFormat;
+import org.mxchange.jcustomercore.model.customer.Customer;
+
+/**
+ * An event being fired when an administrator has added a new customer
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+public class CustomerAdminAddedEvent implements AdminAddedCustomerEvent {
+
+       /**
+        * 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>
+        * @param addedCustomer Added customer instance
+        */
+       public CustomerAdminAddedEvent (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;
+       }
+
+}