]> git.mxchange.org Git - jshop-core.git/commitdiff
added same event class for product
authorRoland Haeder <roland@mxchange.org>
Sun, 10 Apr 2016 14:20:00 +0000 (16:20 +0200)
committerRoland Haeder <roland@mxchange.org>
Sun, 10 Apr 2016 14:20:00 +0000 (16:20 +0200)
src/org/mxchange/jshopcore/events/product/AddedProductEvent.java [new file with mode: 0644]
src/org/mxchange/jshopcore/events/product/ShopProductAddedEvent.java [new file with mode: 0644]

diff --git a/src/org/mxchange/jshopcore/events/product/AddedProductEvent.java b/src/org/mxchange/jshopcore/events/product/AddedProductEvent.java
new file mode 100644 (file)
index 0000000..6f4ae69
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2016 Roland Haeder<roland@mxchange.org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jshopcore.events.product;
+
+import java.io.Serializable;
+import org.mxchange.jshopcore.model.product.Product;
+
+/**
+ * An interface for added product events
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+public interface AddedProductEvent extends Serializable {
+
+       /**
+        * Getter for added product instance
+        * <p>
+        * @return Added product instance
+        */
+       public Product getAddedProduct ();
+
+}
diff --git a/src/org/mxchange/jshopcore/events/product/ShopProductAddedEvent.java b/src/org/mxchange/jshopcore/events/product/ShopProductAddedEvent.java
new file mode 100644 (file)
index 0000000..87fca6e
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2016 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jshopcore.events.product;
+
+import java.text.MessageFormat;
+import org.mxchange.jshopcore.model.product.Product;
+
+/**
+ * An event fired when a new shop category has been added.
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+public class ShopProductAddedEvent implements AddedProductEvent {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 18_567_817_669_107L;
+
+       /**
+        * Product instance that has been added
+        */
+       private final Product addedProduct;
+
+       /**
+        * Constructor with added product instance
+        * <p>
+        * @param addedProduct Added product
+        */
+       public ShopProductAddedEvent (final Product addedProduct) {
+               // The category should be valid
+               if (null == addedProduct) {
+                       // Is NULL, throw NPE
+                       throw new NullPointerException("addedProduct is null"); //NOI18N
+               } else if (addedProduct.getProductTitle().isEmpty()) {
+                       // Empty title
+                       throw new IllegalArgumentException("addedProduct.categoryTitle is empty"); //NOI18N
+               } else if (addedProduct.getProductId() == null) {
+                       // Id is NULL
+                       throw new NullPointerException("addedProduct.productId is null"); //NOI18N
+               } else if (addedProduct.getProductId() <= 0) {
+                       // Not valid id
+                       throw new IllegalArgumentException(MessageFormat.format("addedProduct.productId={0} is not valid.", addedProduct.getProductId())); //NOI18N
+               } else if (addedProduct.getProductCategory() == null) {
+                       // Id is NULL
+                       throw new NullPointerException("addedProduct.productCategory is null"); //NOI18N
+               } else if (addedProduct.getProductCategory().getCategoryId() == null) {
+                       // Id is NULL
+                       throw new NullPointerException("addedProduct.productCategory.categoryId is null"); //NOI18N
+               } else if (addedProduct.getProductCategory().getCategoryId() <= 0) {
+                       // Not valid id
+                       throw new IllegalArgumentException(MessageFormat.format("addedProduct.productCategory.categoryId={0} is not valid.", addedProduct.getProductId())); //NOI18N
+               }
+
+               // Set it here
+               this.addedProduct = addedProduct;
+       }
+
+       @Override
+       public Product getAddedProduct () {
+               return this.addedProduct;
+       }
+
+}