From: Roland Häder Date: Thu, 26 Apr 2018 21:29:33 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2644e025d6aa482f05b6451ff528169318ab21a7;p=jproduct-core.git Continued: - 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 --- 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 index 0000000..a6e8f5f --- /dev/null +++ b/src/org/mxchange/jproduct/events/product/updated/ProductUpdatedEvent.java @@ -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 . + */ +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. + *

+ * @author Roland Häder + */ +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 + *

+ * @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 index 0000000..6048b4f --- /dev/null +++ b/src/org/mxchange/jproduct/events/product/updated/UpdatedProductEvent.java @@ -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 . + */ +package org.mxchange.jproduct.events.product.updated; + +import java.io.Serializable; +import org.mxchange.jproduct.model.product.Product; + +/** + * An interface for updated product events + *

+ * @author Roland Häder + */ +public interface UpdatedProductEvent extends Serializable { + + /** + * Getter for updated product instance + *

+ * @return Updated product instance + */ + public Product getUpdatedProduct (); + +} diff --git a/src/org/mxchange/jproduct/model/product/GenericProduct.java b/src/org/mxchange/jproduct/model/product/GenericProduct.java index bc357b6..1c04f3b 100644 --- a/src/org/mxchange/jproduct/model/product/GenericProduct.java +++ b/src/org/mxchange/jproduct/model/product/GenericProduct.java @@ -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) *

* @author Roland Häder - * TODO: Find a better name */ @Entity (name = "generic_products") @Table ( diff --git a/src/org/mxchange/jproduct/model/product/Product.java b/src/org/mxchange/jproduct/model/product/Product.java index 7fc1a81..ed65cd9 100644 --- a/src/org/mxchange/jproduct/model/product/Product.java +++ b/src/org/mxchange/jproduct/model/product/Product.java @@ -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 *

* @author Roland Häder */ diff --git a/src/org/mxchange/jproduct/model/product/Products.java b/src/org/mxchange/jproduct/model/product/Products.java index 028a10d..a05968e 100644 --- a/src/org/mxchange/jproduct/model/product/Products.java +++ b/src/org/mxchange/jproduct/model/product/Products.java @@ -57,6 +57,41 @@ public class Products implements Serializable { return product1.compareTo(product2); } + /** + * Copies all properties from source product to target product + *

+ * @param sourceProduct Source product instance + * @param targetProduct Target product instance + *

+ * @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 */