From f84e62b732a60589b0dcb9a02e48e703f22efd64 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 21 Dec 2018 15:10:12 +0100 Subject: [PATCH] Please cherry-pick: - companyShortName is now mandatory, while companyName (full name) is optional - but if companyName is set, check it as well, if it doesn't exist MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- ...dressbookAdminBusinessDataSessionBean.java | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/src/java/org/mxchange/jcontactsbusiness/model/basicdata/AddressbookAdminBusinessDataSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/basicdata/AddressbookAdminBusinessDataSessionBean.java index 6f25bcf..b682509 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/basicdata/AddressbookAdminBusinessDataSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/basicdata/AddressbookAdminBusinessDataSessionBean.java @@ -67,7 +67,19 @@ public class AddressbookAdminBusinessDataSessionBean extends BaseAddressbookData } 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 AddressbookAdminBusinessDataSessionBean extends BaseAddressbookData } // 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 AddressbookAdminBusinessDataSessionBean extends BaseAddressbookData return isFound; } + /** + * Checks if given basic data is already added by it's company short name + *

+ * @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 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; + } + } -- 2.39.5