]> git.mxchange.org Git - jproduct-core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Thu, 26 Apr 2018 21:29:33 +0000 (23:29 +0200)
committerRoland Häder <roland@mxchange.org>
Thu, 26 Apr 2018 21:40:27 +0000 (23:40 +0200)
- added event interface and class for updated product instances
- fixed documentation, was a leftover from older times
- implemented Products.copyAll()

Signed-off-by: Roland Häder <roland@mxchange.org>
src/org/mxchange/jproduct/events/product/updated/ProductUpdatedEvent.java [new file with mode: 0644]
src/org/mxchange/jproduct/events/product/updated/UpdatedProductEvent.java [new file with mode: 0644]
src/org/mxchange/jproduct/model/product/GenericProduct.java
src/org/mxchange/jproduct/model/product/Product.java
src/org/mxchange/jproduct/model/product/Products.java

diff --git a/src/org/mxchange/jproduct/events/product/updated/ProductUpdatedEvent.java b/src/org/mxchange/jproduct/events/product/updated/ProductUpdatedEvent.java
new file mode 100644 (file)
index 0000000..a6e8f5f
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2016 - 2018 Free Software Foundation
+ *
+ * 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.jproduct.events.product.updated;
+
+import java.text.MessageFormat;
+import org.mxchange.jproduct.model.product.Product;
+
+/**
+ * An event fired when a new shop category has been updated.
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public class ProductUpdatedEvent implements UpdatedProductEvent {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 18_567_817_669_108L;
+
+       /**
+        * Product instance that has been updated
+        */
+       private final Product updatedProduct;
+
+       /**
+        * Constructor with updated product instance
+        * <p>
+        * @param updatedProduct Updated product
+        */
+       public ProductUpdatedEvent (final Product updatedProduct) {
+               // The category should be valid
+               if (null == updatedProduct) {
+                       // Is NULL, throw NPE
+                       throw new NullPointerException("updatedProduct is null"); //NOI18N
+               } else if (updatedProduct.getProductI18nKey().isEmpty()) {
+                       // Empty title
+                       throw new IllegalArgumentException("updatedProduct.productI18nKey is empty"); //NOI18N
+               } else if (updatedProduct.getProductId() == null) {
+                       // Id is NULL
+                       throw new NullPointerException("updatedProduct.productId is null"); //NOI18N
+               } else if (updatedProduct.getProductId() <= 0) {
+                       // Not valid id
+                       throw new IllegalArgumentException(MessageFormat.format("updatedProduct.productId={0} is not valid.", updatedProduct.getProductId())); //NOI18N
+               } else if (updatedProduct.getProductCategory() == null) {
+                       // Id is NULL
+                       throw new NullPointerException("updatedProduct.productCategory is null"); //NOI18N
+               } else if (updatedProduct.getProductCategory().getCategoryId() == null) {
+                       // Id is NULL
+                       throw new NullPointerException("updatedProduct.productCategory.categoryId is null"); //NOI18N
+               } else if (updatedProduct.getProductCategory().getCategoryId() <= 0) {
+                       // Not valid id
+                       throw new IllegalArgumentException(MessageFormat.format("updatedProduct.productCategory.categoryId={0} is not valid.", updatedProduct.getProductId())); //NOI18N
+               }
+
+               // Set it here
+               this.updatedProduct = updatedProduct;
+       }
+
+       @Override
+       public Product getUpdatedProduct () {
+               return this.updatedProduct;
+       }
+
+}
diff --git a/src/org/mxchange/jproduct/events/product/updated/UpdatedProductEvent.java b/src/org/mxchange/jproduct/events/product/updated/UpdatedProductEvent.java
new file mode 100644 (file)
index 0000000..6048b4f
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2016 - 2018 Free Software Foundation
+ *
+ * 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.jproduct.events.product.updated;
+
+import java.io.Serializable;
+import org.mxchange.jproduct.model.product.Product;
+
+/**
+ * An interface for updated product events
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface UpdatedProductEvent extends Serializable {
+
+       /**
+        * Getter for updated product instance
+        * <p>
+        * @return Updated product instance
+        */
+       public Product getUpdatedProduct ();
+
+}
index bc357b637d0f9caf0f17ff4bee82967c5f9fdb60..1c04f3b20a5a17956016e673d48742fe1bf14774 100644 (file)
@@ -50,10 +50,9 @@ import org.mxchange.jproduct.model.category.ProductCategory;
 import org.mxchange.jproduct.model.product.agegroup.AgeGroup;
 
 /**
- * Generic product class
+ * Generic product POJO (entity)
  * <p>
  * @author Roland Häder<roland@mxchange.org>
- * TODO: Find a better name
  */
 @Entity (name = "generic_products")
 @Table (
index 7fc1a8151769f93dd8a52030c698a1702d992c6e..ed65cd9c069f7d87ef2498ac65408c6fe377251d 100644 (file)
@@ -24,7 +24,7 @@ import org.mxchange.jproduct.model.category.Category;
 import org.mxchange.jproduct.model.product.agegroup.AgeGroup;
 
 /**
- * An interface for in database storable products
+ * A POJI for product entities
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
index 028a10d0c0f6f7611b3357d19b96e4f4aa4d7b09..a05968ef2e6205414e4b77e74b4c70d206fc62d8 100644 (file)
@@ -57,6 +57,41 @@ public class Products implements Serializable {
                return product1.compareTo(product2);
        }
 
+       /**
+        * Copies all properties from source product to target product
+        * <p>
+        * @param sourceProduct Source product instance
+        * @param targetProduct Target product instance
+        * <p>
+        * @throws NullPointerException If one instance is null
+        */
+       public static void copyAll (final Product sourceProduct, final Product targetProduct) {
+               // Product should be valid
+               if (null == sourceProduct) {
+                       // Throw NPE
+                       throw new NullPointerException("sourceProduct is null"); //NOI18N
+               } else if (null == targetProduct) {
+                       // Throw NPE
+                       throw new NullPointerException("targetProduct is null"); //NOI18N
+               }
+
+               // Copy all:
+               targetProduct.setProductAgeGroup(sourceProduct.getProductAgeGroup());
+               targetProduct.setProductAvailability(sourceProduct.getProductAvailability());
+               targetProduct.setProductCategory(sourceProduct.getProductCategory());
+               targetProduct.setProductCreated(sourceProduct.getProductCreated());
+               targetProduct.setProductCurrencyCode(sourceProduct.getProductCurrencyCode());
+               targetProduct.setProductGrossPrice(sourceProduct.getProductGrossPrice());
+               targetProduct.setProductI18nKey(sourceProduct.getProductI18nKey());
+               targetProduct.setProductManufacturer(sourceProduct.getProductManufacturer());
+               targetProduct.setProductNetPrice(sourceProduct.getProductNetPrice());
+               targetProduct.setProductNumber(sourceProduct.getProductNumber());
+               targetProduct.setProductSize(sourceProduct.getProductSize());
+               targetProduct.setProductTaxRate(sourceProduct.getProductTaxRate());
+               targetProduct.setProductUnitAmount(sourceProduct.getProductUnitAmount());
+               targetProduct.setProductUnitI18nKey(sourceProduct.getProductUnitI18nKey());
+       }
+
        /**
         * Utility classes should have no instances
         */