]> git.mxchange.org Git - jproduct-core.git/blob - src/org/mxchange/jproduct/events/product/updated/ProductUpdatedEvent.java
Continued:
[jproduct-core.git] / src / org / mxchange / jproduct / events / product / updated / ProductUpdatedEvent.java
1 /*
2  * Copyright (C) 2016 - 2018 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 Affero General Public License as
6  * published by the Free Software Foundation, either version 3 of the
7  * License, or (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 Affero General Public License for more details.
13  *
14  * You should have received a copy of the GNU Affero General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.jproduct.events.product.updated;
18
19 import java.text.MessageFormat;
20 import org.mxchange.jproduct.model.product.Product;
21
22 /**
23  * An event fired when a new shop category has been updated.
24  * <p>
25  * @author Roland Häder<roland@mxchange.org>
26  */
27 public class ProductUpdatedEvent implements UpdatedProductEvent {
28
29         /**
30          * Serial number
31          */
32         private static final long serialVersionUID = 18_567_817_669_108L;
33
34         /**
35          * Product instance that has been updated
36          */
37         private final Product updatedProduct;
38
39         /**
40          * Constructor with updated product instance
41          * <p>
42          * @param updatedProduct Updated product
43          */
44         public ProductUpdatedEvent (final Product updatedProduct) {
45                 // The category should be valid
46                 if (null == updatedProduct) {
47                         // Is NULL, throw NPE
48                         throw new NullPointerException("updatedProduct is null"); //NOI18N
49                 } else if (updatedProduct.getProductI18nKey().isEmpty()) {
50                         // Empty title
51                         throw new IllegalArgumentException("updatedProduct.productI18nKey is empty"); //NOI18N
52                 } else if (updatedProduct.getProductId() == null) {
53                         // Id is NULL
54                         throw new NullPointerException("updatedProduct.productId is null"); //NOI18N
55                 } else if (updatedProduct.getProductId() <= 0) {
56                         // Not valid id
57                         throw new IllegalArgumentException(MessageFormat.format("updatedProduct.productId={0} is not valid.", updatedProduct.getProductId())); //NOI18N
58                 } else if (updatedProduct.getProductCategory() == null) {
59                         // Id is NULL
60                         throw new NullPointerException("updatedProduct.productCategory is null"); //NOI18N
61                 } else if (updatedProduct.getProductCategory().getCategoryId() == null) {
62                         // Id is NULL
63                         throw new NullPointerException("updatedProduct.productCategory.categoryId is null"); //NOI18N
64                 } else if (updatedProduct.getProductCategory().getCategoryId() <= 0) {
65                         // Not valid id
66                         throw new IllegalArgumentException(MessageFormat.format("updatedProduct.productCategory.categoryId={0} is not valid.", updatedProduct.getProductId())); //NOI18N
67                 }
68
69                 // Set it here
70                 this.updatedProduct = updatedProduct;
71         }
72
73         @Override
74         public Product getUpdatedProduct () {
75                 return this.updatedProduct;
76         }
77
78 }