]> git.mxchange.org Git - jcustomer-core.git/blob - src/org/mxchange/jcustomercore/events/customer/created/CreatedCustomerEvent.java
Updated copyright year
[jcustomer-core.git] / src / org / mxchange / jcustomercore / events / customer / created / CreatedCustomerEvent.java
1 /*
2  * Copyright (C) 2017 - 2024 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.created;
18
19 import java.text.MessageFormat;
20 import org.mxchange.jcustomercore.model.customer.Customer;
21
22 /**
23  * An interface for observable events being fired when a customer instance has
24  * been successfully created. This may happen when a customer profile was
25  * called.
26  * <p>
27  * @author Roland Häder<roland@mxchange.org>
28  */
29 public class CreatedCustomerEvent implements ObservableCreatedCustomerEvent {
30
31         /**
32          * Serial number
33          */
34         private static final long serialVersionUID = 24_138_056_876_716_451L;
35
36         /**
37          * Customer instance being created
38          */
39         private final Customer createdCustomer;
40
41         /**
42          * Constructor with customer instance
43          * <p>
44          * @param createdCustomer Customer instance being created by helper
45          */
46         public CreatedCustomerEvent (final Customer createdCustomer) {
47                 // The instance should be valid
48                 if (null == createdCustomer) {
49                         // Throw NPE
50                         throw new NullPointerException("createdCustomer is null"); //NOI18N
51                 } else if (createdCustomer.getCustomerId() == null) {
52                         // Throw NPE, again ...
53                         throw new NullPointerException("createdCustomer.customerId is null"); //NOI18N
54                 } else if (createdCustomer.getCustomerId() < 1) {
55                         // Not valid
56                         throw new IllegalArgumentException(MessageFormat.format("createdCustomer.customerId={0} is not valid", createdCustomer.getCustomerId())); //NOI18N
57                 } else if (createdCustomer.getCustomerNumber() == null) {
58                         // Throw NPE, again ...
59                         throw new NullPointerException("createdCustomer.customerNumber is null"); //NOI18N
60                 } else if (createdCustomer.getCustomerNumber() == null) {
61                         // Empty customer number
62                         throw new IllegalArgumentException("createdCustomer.customerNumber is empty"); //NOI18N
63                 } else if (createdCustomer.getCustomerContact() == null) {
64                         // Throw again ...
65                         throw new NullPointerException("createdCustomer.customerContact is null"); //NOI18N
66                 } else if (createdCustomer.getCustomerContact().getContactId() == null) {
67                         // ... and again ...
68                         throw new NullPointerException("createdCustomer.customerContact.contactId is null"); //NOI18N
69                 } else if (createdCustomer.getCustomerContact().getContactId() < 1) {
70                         // Not valid
71                         throw new IllegalArgumentException(MessageFormat.format("createdCustomer.customerContact.contactId={0} is not valid", createdCustomer.getCustomerContact().getContactId())); //NOI18N
72                 }
73
74                 // Set customer instance
75                 this.createdCustomer = createdCustomer;
76         }
77
78         @Override
79         public Customer getCreatedCustomer () {
80                 return this.createdCustomer;
81         }
82
83 }