]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
Better check the parameter on missing (but important) stuff
authorRoland Haeder <roland@mxchange.org>
Wed, 13 Apr 2016 20:38:39 +0000 (22:38 +0200)
committerRoland Haeder <roland@mxchange.org>
Wed, 13 Apr 2016 20:38:39 +0000 (22:38 +0200)
src/java/org/mxchange/pizzaapplication/beans/category/PizzaCategoryWebApplicationBean.java
src/java/org/mxchange/pizzaapplication/beans/product/PizzaProductWebApplicationBean.java

index f71ac756db52672fa72486b5b9f99d6152053970..9af316c12ffe66598f152295cb63bf0f899bfc04 100644 (file)
@@ -16,6 +16,7 @@
  */
 package org.mxchange.pizzaapplication.beans.category;
 
+import java.text.MessageFormat;
 import java.util.LinkedList;
 import java.util.List;
 import javax.annotation.PostConstruct;
@@ -58,6 +59,21 @@ public class PizzaCategoryWebApplicationBean implements PizzaCategoryWebApplicat
 
        @Override
        public void afterShopCategoryAdded (@Observes final AddedCategoryEvent event) {
+               // Is all valid?
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getAddedCategory() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("event.addedCategory is null"); //NOI18N
+               } else if (event.getAddedCategory().getCategoryId() == null) {
+                       // And again ...
+                       throw new NullPointerException("event.addedCategory.categoryId is null"); //NOI18N
+               } else if (event.getAddedCategory().getCategoryId() < 1) {
+                       // Id is invalid
+                       throw new IllegalArgumentException(MessageFormat.format("event.addedCategory.categoryId={0} is not valid.", event.getAddedCategory().getCategoryId())); //NOI18N
+               }
+
                // Add it here, too.
                this.addCategory(event.getAddedCategory());
        }
index 4e600f95021d6076b4300f31c7004450dfd40b4b..f90a5bc9a7dec9bdcf11f6b1dfdfaacfe101393c 100644 (file)
@@ -16,6 +16,7 @@
  */
 package org.mxchange.pizzaapplication.beans.product;
 
+import java.text.MessageFormat;
 import java.util.Collections;
 import java.util.List;
 import javax.annotation.PostConstruct;
@@ -60,6 +61,21 @@ public class PizzaProductWebApplicationBean implements PizzaProductWebApplicatio
 
        @Override
        public void afterShopProductAdded (@Observes final AddedProductEvent event) {
+               // Is all valid?
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getAddedProduct()== null) {
+                       // Throw again ...
+                       throw new NullPointerException("event.addedProduct is null"); //NOI18N
+               } else if (event.getAddedProduct().getProductId() == null) {
+                       // And again ...
+                       throw new NullPointerException("event.addedProduct.productId is null"); //NOI18N
+               } else if (event.getAddedProduct().getProductId() < 1) {
+                       // Id is invalid
+                       throw new IllegalArgumentException(MessageFormat.format("event.addedProduct.productId={0} is not valid.", event.getAddedProduct().getProductId())); //NOI18N
+               }
+
                // Add it here, too.
                this.addProduct(event.getAddedProduct());
        }