--- /dev/null
+/*
+ * 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;
+ }
+
+}
--- /dev/null
+/*
+ * 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 ();
+
+}
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 (
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>
*/
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
*/