]> git.mxchange.org Git - pizzaservice-ejb.git/blobdiff - src/java/org/mxchange/jcontactsbusiness/model/basicdata/PizzaAdminBusinessDataSessionBean.java
Please cherry-pick:
[pizzaservice-ejb.git] / src / java / org / mxchange / jcontactsbusiness / model / basicdata / PizzaAdminBusinessDataSessionBean.java
index ca87ac01e2540b512c7d872e43912ba606db9c52..9139d7a9802e889ee9c3ebf3bf1a5e83833d2f64 100644 (file)
@@ -67,7 +67,19 @@ public class PizzaAdminBusinessDataSessionBean extends BasePizzaEnterpriseBean i
                } else if (basicData.getBasicDataId() != null) {
                        // Should be null
                        throw new IllegalArgumentException(MessageFormat.format("basicData.basicDataId={0} - is not null", basicData.getBasicDataId())); //NOI18N
-               } else if (this.isSameCompanyNameAdded(basicData)) {
+               } else if (basicData.getCompanyShortName() == null) {
+                       // Should not be null
+                       throw new NullPointerException("basicData.companyShortName is null"); //NOI18N
+               } else if (basicData.getCompanyShortName().isEmpty()) {
+                       // Should not be empty string
+                       throw new IllegalArgumentException("basicData.companyShortName is empty"); //NOI18N
+               } else if (this.isSameCompanyShortNameAdded(basicData)) {
+                       // Throw exception
+                       throw new BasicDataAlreadyAddedException(basicData);
+               } else if ((basicData.getCompanyName() != null) && (basicData.getCompanyName().isEmpty())) {
+                       // Should not be empty string when set
+                       throw new IllegalArgumentException("basicData.companyName is empty"); //NOI18N
+               } else if ((basicData.getCompanyName() != null) && (this.isSameCompanyNameAdded(basicData))) {
                        // Throw exception
                        throw new BasicDataAlreadyAddedException(basicData);
                }
@@ -103,7 +115,7 @@ public class PizzaAdminBusinessDataSessionBean extends BasePizzaEnterpriseBean i
                }
 
                // Is a headquarter set?
-               if (basicData.getCompanyHeadquarterData()instanceof Headquarter) {
+               if (basicData.getCompanyHeadquarterData() instanceof Headquarter) {
                        // Get managed instance
                        final Headquarter managedHeadquarter = this.createManaged(basicData.getCompanyHeadquarterData());
 
@@ -151,4 +163,31 @@ public class PizzaAdminBusinessDataSessionBean extends BasePizzaEnterpriseBean i
                return isFound;
        }
 
+       /**
+        * Checks if given basic data is already added by it's company short name
+        * <p>
+        * @param basicData Basic data to be checked
+        *
+        * @return Whether same company short name has been used
+        */
+       private boolean isSameCompanyShortNameAdded (final BasicData basicData) {
+               // Get all available entries
+               final List<BasicData> list = this.businessDataBean.allBusinessBasicData();
+
+               // Default is not found
+               boolean isFound = false;
+
+               // Then check each entry
+               for (final BasicData entry : list) {
+                       // Is the company name matching?
+                       if (Objects.equals(entry.getCompanyShortName(), basicData.getCompanyShortName())) {
+                               // Found match
+                               isFound = true;
+                       }
+               }
+
+               // Return flag
+               return isFound;
+       }
+
 }