]> git.mxchange.org Git - jcustomer-core.git/blob - src/org/mxchange/jcustomercore/events/customer/added/AdminAddedCustomerEvent.java
66f82ac003ced30109d9d04903b50dc21755ffe7
[jcustomer-core.git] / src / org / mxchange / jcustomercore / events / customer / added / AdminAddedCustomerEvent.java
1 /*
2  * Copyright (C) 2016 - 2020 Free Software Foundation
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.jcustomercore.events.customer.added;
18
19 import java.text.MessageFormat;
20 import org.mxchange.jcustomercore.model.customer.Customer;
21
22 /**
23  * An event being fired when an administrator has added a new customer
24  * <p>
25  * @author Roland Häder<roland@mxchange.org>
26  */
27 public class AdminAddedCustomerEvent implements ObservableAdminAddedCustomerEvent {
28
29         /**
30          * Serial number
31          */
32         private static final long serialVersionUID = 1_782_358_678_347_190L;
33
34         /**
35          * Added customer
36          */
37         private final Customer addedCustomer;
38
39         /**
40          * Constructor with valid customer instance being added (updated varriant)
41          * <p>
42          * @param addedCustomer Added customer instance
43          */
44         public AdminAddedCustomerEvent (final Customer addedCustomer) {
45                 // The instance should be valid
46                 if (null == addedCustomer) {
47                         // Throw NPE
48                         throw new NullPointerException("addedCustomer is null"); //NOI18N
49                 } else if (addedCustomer.getCustomerId() == null) {
50                         // Throw NPE, again ...
51                         throw new NullPointerException("addedCustomer.customerId is null"); //NOI18N
52                 } else if (addedCustomer.getCustomerId() < 1) {
53                         // Not valid
54                         throw new IllegalArgumentException(MessageFormat.format("addedCustomer.customerId={0} is not valid", addedCustomer.getCustomerId())); //NOI18N
55                 } else if (addedCustomer.getCustomerNumber() == null) {
56                         // Throw NPE, again ...
57                         throw new NullPointerException("addedCustomer.customerNumber is null"); //NOI18N
58                 } else if (addedCustomer.getCustomerNumber() == null) {
59                         // Empty customer number
60                         throw new IllegalArgumentException("addedCustomer.customerNumber is empty"); //NOI18N
61                 } else if (addedCustomer.getCustomerContact() == null) {
62                         // Throw again ...
63                         throw new NullPointerException("addedCustomer.customerContact is null"); //NOI18N
64                 } else if (addedCustomer.getCustomerContact().getContactId() == null) {
65                         // ... and again ...
66                         throw new NullPointerException("addedCustomer.customerContact.contactId is null"); //NOI18N
67                 } else if (addedCustomer.getCustomerContact().getContactId() < 1) {
68                         // Not valid
69                         throw new IllegalArgumentException(MessageFormat.format("addedCustomer.customerContact.contactId={0} is not valid", addedCustomer.getCustomerContact().getContactId())); //NOI18N
70                 }
71
72                 // Set it here
73                 this.addedCustomer = addedCustomer;
74         }
75
76         @Override
77         public Customer getAddedCustomer () {
78                 return this.addedCustomer;
79         }
80
81 }