From: Roland Häder Date: Thu, 20 Oct 2022 17:17:46 +0000 (+0200) Subject: Please cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=daf5900d78542372a04edd38b8abd8b0c42a8b70;p=addressbook-war.git Please cherry-pick: - added missing parameter "country" for updated constructor - also validated if contact's Country instance is set and already persisted --- diff --git a/lib/jcontacts-core.jar b/lib/jcontacts-core.jar index 14ab378f..a30c9f08 100644 Binary files a/lib/jcontacts-core.jar and b/lib/jcontacts-core.jar differ diff --git a/src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestBean.java b/src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestBean.java index 57bb7db6..9f3ed0cf 100644 --- a/src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestBean.java +++ b/src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestBean.java @@ -37,9 +37,9 @@ import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException; import org.mxchange.jcontacts.model.contact.AdminContactSessionBeanRemote; import org.mxchange.jcontacts.model.contact.Contact; import org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote; -import org.mxchange.jcontacts.model.contact.ContactUtils; import org.mxchange.jcontacts.model.contact.UserContact; import org.mxchange.jcontacts.model.contact.title.PersonalTitle; +import org.mxchange.jcontacts.model.utils.ContactUtils; import org.mxchange.jcountry.model.data.Country; import org.mxchange.jphone.model.phonenumbers.DialableNumber; import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; @@ -175,7 +175,7 @@ public class AddressbookAdminContactWebRequestBean extends BaseAddressbookBean i private boolean isLandLineUnlinked; /** - * Whether a cmobile entry has been unlinked + * Whether a mobile entry has been unlinked */ private boolean isMobileNumberUnlinked; @@ -392,6 +392,15 @@ public class AddressbookAdminContactWebRequestBean extends BaseAddressbookBean i } else if (this.getFamilyName().isEmpty()) { // Empty string throw new IllegalStateException("familyName is empty"); //NOI18N + } else if (this.getContactCountry() == null) { + // Throw NPE + throw new NullPointerException("contactCountry is null"); //NOI18N + } else if (this.getContactCountry().getCountryId() == null) { + // Throw it again + throw new NullPointerException("contactCountry.countryId is null"); //NOI18N + } else if (this.getContactCountry().getCountryId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("contactCountry.countryId={0} is invalid", this.getContactCountry().getCountryId())); //NOI18N } // Generate phone number @@ -408,20 +417,24 @@ public class AddressbookAdminContactWebRequestBean extends BaseAddressbookBean i contact.setContactId(this.getContactId()); } - // Add all others - contact.setContactTitle(this.getAcademicTitle()); - contact.setContactBirthday(this.getBirthday()); - contact.setContactStreet(this.getStreet()); - contact.setContactHouseNumber(this.getHouseNumber()); - contact.setContactZipCode(this.getZipCode()); - contact.setContactCity(this.getCity()); - contact.setContactCountry(this.getContactCountry()); - contact.setContactEmailAddress(this.getEmailAddress()); - contact.setContactBirthday(this.getBirthday()); - contact.setContactComment(this.getComment()); + // Create new instance + final Contact localContact = new UserContact( + this.getPersonalTitle(), + this.getFirstName(), + this.getFamilyName(), + this.getContactCountry() + ); - // Set ownContact - contact.setContactOwnContact(Boolean.TRUE); + // Add all others + localContact.setContactBirthday(this.getBirthday()); + localContact.setContactCity(this.getCity()); + localContact.setContactComment(this.getComment()); + localContact.setContactEmailAddress(this.getEmailAddress()); + localContact.setContactHouseNumber(this.getHouseNumber()); + localContact.setContactId(this.getContactId()); + localContact.setContactStreet(this.getStreet()); + localContact.setContactTitle(this.getAcademicTitle()); + localContact.setContactZipCode(this.getZipCode()); // Don't set null or wrong references if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) { diff --git a/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebRequestBean.java b/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebRequestBean.java index c677fc8b..4bcf24cf 100644 --- a/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebRequestBean.java +++ b/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebRequestBean.java @@ -38,9 +38,9 @@ import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEven import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent; import org.mxchange.jcontacts.model.contact.Contact; import org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote; -import org.mxchange.jcontacts.model.contact.ContactUtils; import org.mxchange.jcontacts.model.contact.UserContact; import org.mxchange.jcontacts.model.contact.title.PersonalTitle; +import org.mxchange.jcontacts.model.utils.ContactUtils; import org.mxchange.jcountry.model.data.Country; import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber; @@ -493,37 +493,12 @@ public class AddressbookContactWebRequestBean extends BaseAddressbookBean implem DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber()); // Create new contact - Contact contact = new UserContact(this.getPersonalTitle(), this.getFirstName(), this.getFamilyName()); - contact.setContactStreet(this.getStreet()); - contact.setContactHouseNumber(this.getHouseNumber()); - contact.setContactHouseNumberExtension(this.getHouseNumberExtension()); - contact.setContactZipCode(this.getZipCode()); - contact.setContactCity(this.getCity()); - contact.setContactCountry(this.getCountry()); - contact.setContactEmailAddress(this.getEmailAddress()); - contact.setContactBirthday(this.getBirthday()); - contact.setContactComment(this.getComment()); - - // Don't set null or wrong references - if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) { - // Now the number must be given - if (phone.getPhoneAreaCode() == null) { - // Is null - throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N - } else if (phone.getPhoneAreaCode() < 1) { - // Abort here - throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N - } else if (phone.getPhoneNumber() == null) { - // Is null - throw new NullPointerException("phone.phoneNumber is null"); //NOI18N - } else if (phone.getPhoneNumber() < 1) { - // Abort here - throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N - } - - // Set phone number - contact.setContactLandLineNumber(phone); - } + final Contact contact = new UserContact( + this.getPersonalTitle(), + this.getFirstName(), + this.getFamilyName(), + this.getCountry() + ); // Don't set null or wrong references if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) { diff --git a/web/admin/contact/admin_contact_list.xhtml b/web/admin/contact/admin_contact_list.xhtml index 855fdc21..0d8e32ee 100644 --- a/web/admin/contact/admin_contact_list.xhtml +++ b/web/admin/contact/admin_contact_list.xhtml @@ -91,11 +91,31 @@ +<<<<<<< HEAD +======= + + + + + + + + +>>>>>>> 2b3f1b133 (Please cherry-pick:)