From: Roland Häder Date: Fri, 29 Apr 2016 13:43:26 +0000 (+0200) Subject: Continued a bit: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=1eb1613f427eea06bb1d4bbef25583ad3eb473a2;p=jfinancials-war.git Continued a bit: - renamed method changeUserData() to editUserData() (members sorted) - surpressed some warnings that are not being fixed - clear() needs to be called Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestBean.java b/src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestBean.java index 415ba6cc..44a78a91 100644 --- a/src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestBean.java +++ b/src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestBean.java @@ -18,6 +18,7 @@ package org.mxchange.addressbook.beans.contact; import java.text.MessageFormat; import java.util.Date; +import java.util.List; import javax.annotation.PostConstruct; import javax.enterprise.context.RequestScoped; import javax.enterprise.event.Event; @@ -35,9 +36,8 @@ import org.mxchange.jcontacts.contact.gender.Gender; import org.mxchange.jcontacts.contact.utils.ContactUtils; import org.mxchange.jcontacts.events.contact.update.AdminContactUpdatedEvent; import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent; +import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException; import org.mxchange.jcountry.data.Country; -import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; -import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider; import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent; @@ -231,35 +231,43 @@ public class AddressbookAdminContactWebRequestBean implements AddressbookAdminCo } @Override - public String changeContactData () { - // Get contact instance - Contact contact = this.adminHelper.getContact(); + public String addContact () { + // Create new contact instance + Contact contact = this.createContactInstance(); - // Check if contact instance is in helper and valid - if (null == contact) { - // Throw NPE - throw new NullPointerException("adminHelper.contact is null"); //NOI18N - } else if (contact.getContactId() == null) { - // Throw NPE again - throw new NullPointerException("adminHelper.contact.contactId is null"); //NOI18N //NOI18N - } else if (contact.getContactId() < 1) { - // Invalid id - throw new IllegalStateException(MessageFormat.format("adminHelper.contact.contactId={0} is invalid", contact.getContactId())); //NOI18N + // Default is not same contact + if (this.isSameContactFound(contact)) { + // Already registered + throw new FaceletException(new ContactAlreadyAddedException(contact)); } - // Update all data in contact - this.updateContactData(contact); + // Init contact + Contact updatedContact; - // Call EJB for updating contact data - Contact updatedContact = this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked); + // Try to call EJB + try { + // Call EJB + updatedContact = this.contactBean.addContact(contact); + } catch (final ContactAlreadyAddedException ex) { + // Throw again + throw new FaceletException(ex); + } // Fire event - this.updatedContactEvent.fire(new AdminContactUpdatedEvent(updatedContact)); + this.addedContactEvent.fire(new AdminContactAddedEvent(updatedContact)); - // Return to contact list (for now) + // Clear this bean + this.clear(); + + // Return outcome return "admin_list_contact"; //NOI18N } + @Override + public List allContacts () { + return this.contactController.allContacts(); + } + @Override public void copyContactToController (final Contact contact) { // The contact instance must be valid @@ -307,11 +315,46 @@ public class AddressbookAdminContactWebRequestBean implements AddressbookAdminCo } @Override + public String editContactData () { + // Get contact instance + Contact contact = this.adminHelper.getContact(); + + // Check if contact instance is in helper and valid + if (null == contact) { + // Throw NPE + throw new NullPointerException("adminHelper.contact is null"); //NOI18N + } else if (contact.getContactId() == null) { + // Throw NPE again + throw new NullPointerException("adminHelper.contact.contactId is null"); //NOI18N //NOI18N + } else if (contact.getContactId() < 1) { + // Invalid id + throw new IllegalStateException(MessageFormat.format("adminHelper.contact.contactId={0} is invalid", contact.getContactId())); //NOI18N + } + + // Update all data in contact + this.updateContactData(contact); + + // Call EJB for updating contact data + Contact updatedContact = this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked); + + // Fire event + this.updatedContactEvent.fire(new AdminContactUpdatedEvent(updatedContact)); + + // Clear bean + this.clear(); + + // Return to contact list (for now) + return "admin_list_contact"; //NOI18N + } + + @Override + @SuppressWarnings ("ReturnOfDateField") public Date getBirthday () { return this.birthday; } @Override + @SuppressWarnings ("AssignmentToDateFieldFromParameter") public void setBirthday (final Date birthday) { this.birthday = birthday; } diff --git a/src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestController.java b/src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestController.java index b737bea2..25fcfc53 100644 --- a/src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestController.java +++ b/src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestController.java @@ -42,7 +42,7 @@ public interface AddressbookAdminContactWebRequestController extends Serializabl *

* @return Redirect outcome */ - String changeContactData (); + String editContactData (); /** * Getter for cellphone id diff --git a/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionBean.java b/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionBean.java index 3f584aa6..e06149a3 100644 --- a/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionBean.java +++ b/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionBean.java @@ -235,7 +235,7 @@ public class AddressbookContactWebSessionBean implements AddressbookContactWebSe if (null == event) { // Throw NPE throw new NullPointerException("event is null"); //NOI18N - } else if (event.getUpdatedContact()== null) { + } else if (event.getUpdatedContact() == null) { // Throw NPE again throw new NullPointerException("event.user is null"); //NOI18N } else if (event.getUpdatedContact().getContactId() == null) { @@ -338,6 +338,11 @@ public class AddressbookContactWebSessionBean implements AddressbookContactWebSe System.out.println("ContactWebBean:afterUserLogin - EXIT!"); //NOI18N } + @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public List allContacts () { + return this.contactList; + } + /** * Clears this bean */ @@ -456,7 +461,6 @@ public class AddressbookContactWebSessionBean implements AddressbookContactWebSe // Trace message //this.getLogger().logTrace(MessageFormat.format("createContactInstance: localContact={0} - EXIT!", localContact)); - // Return it return localContact; } @@ -510,11 +514,13 @@ public class AddressbookContactWebSessionBean implements AddressbookContactWebSe } @Override + @SuppressWarnings ("ReturnOfDateField") public Date getBirthday () { return this.birthday; } @Override + @SuppressWarnings ("AssignmentToDateFieldFromParameter") public void setBirthday (final Date birthday) { this.birthday = birthday; } diff --git a/web/admin/contact/admin_contact_edit.xhtml b/web/admin/contact/admin_contact_edit.xhtml index 9f608238..11928a3e 100644 --- a/web/admin/contact/admin_contact_edit.xhtml +++ b/web/admin/contact/admin_contact_edit.xhtml @@ -41,7 +41,7 @@