From: Roland Häder Date: Sat, 16 Jun 2018 13:17:55 +0000 (+0200) Subject: Product-only: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=5b91a30a7f876b87300d08114ed49cf242ee9e9f;p=pizzaservice-ejb.git Product-only: - added mergeProductData() - implemented updateProductData() Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/jproduct/model/product/PizzaAdminGenericProductSessionBean.java b/src/java/org/mxchange/jproduct/model/product/PizzaAdminGenericProductSessionBean.java index fb5852c..fa89d62 100644 --- a/src/java/org/mxchange/jproduct/model/product/PizzaAdminGenericProductSessionBean.java +++ b/src/java/org/mxchange/jproduct/model/product/PizzaAdminGenericProductSessionBean.java @@ -24,6 +24,7 @@ import javax.ejb.EJB; import javax.ejb.Stateless; import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; import org.mxchange.jproduct.exceptions.product.ProductAlreadyAddedException; +import org.mxchange.jproduct.exceptions.product.ProductNotFoundException; import org.mxchange.jproduct.model.category.Category; import org.mxchange.pizzaapplication.database.product.BasePizzaProductEnterpriseBean; @@ -112,6 +113,36 @@ public class PizzaAdminGenericProductSessionBean extends BasePizzaProductEnterpr return product; } + @Override + public Product updateProductData (final Product product) throws ProductNotFoundException { + // Log trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateProductData: product={1} - CALLED!", this.getClass().getSimpleName(), product)); //NOI18N + + // The product instance must be valid + if (null == product) { + // Throw NPE again + throw new NullPointerException("product is null"); //NOI18N + } else if (product.getProductId() == null) { + // Throw NPE again + throw new NullPointerException("product.productId is null"); //NOI18N + } else if (product.getProductId() < 1) { + // Not valid + throw new IllegalStateException(MessageFormat.format("product.productId={0} is not valid.", product.getProductId())); //NOI18N + } else if (!this.isProductCreated(product)) { + // No not found + throw new ProductNotFoundException(product.getProductId()); + } + + // Merge data + final Product detachedProduct = this.mergeProductData(product); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateProductData: detachedProduct={1} - EXIT!", this.getClass().getSimpleName(), detachedProduct)); //NOI18N + + // Return it + return detachedProduct; + } + /** * Checks if given product is already added by it's title. *

@@ -120,21 +151,6 @@ public class PizzaAdminGenericProductSessionBean extends BasePizzaProductEnterpr * @return Whether it has been found */ private boolean isProductCreated (final Product product) { - // Validate parameter - if (null == product) { - // Throw NPE - throw new NullPointerException("product is null"); //NOI18N - } else if (product.getProductI18nKey() == null) { - // Throw it again - throw new NullPointerException("product.productI18nKey is null"); //NOI18N - } else if (product.getProductI18nKey().isEmpty()) { - // Throw it again - throw new IllegalArgumentException("product.productI18nKey is empty"); //NOI18N - } else if (product.getProductId() != null) { - // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("product.productId={0} is not expected.", product.getProductId())); //NOI18N - } - // Default is not found boolean isFound = false; @@ -143,9 +159,13 @@ public class PizzaAdminGenericProductSessionBean extends BasePizzaProductEnterpr // Check each entry for (final Product createdProduct : list) { - // Is same name? - if (Objects.equals(createdProduct.getProductI18nKey(), product.getProductI18nKey())) { - // Found it, then stop here + // Is same id or name? + if (Objects.equals(product.getProductId(), createdProduct.getProductId())) { + // Found by id + isFound = true; + break; + } else if (Objects.equals(createdProduct.getProductI18nKey(), product.getProductI18nKey())) { + // Found by i18n key, then stop here isFound = true; break; }