From 81ea43c6c468a8484b611c3ab38c76162b7363cf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 29 Apr 2016 15:43:26 +0200 Subject: [PATCH] Continued a bit: - renamed method changeUserData() to editUserData() (members sorted) - surpressed some warnings that are not being fixed - clear() needs to be called MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../JobsAdminContactWebRequestBean.java | 85 ++++++++++++++----- .../JobsAdminContactWebRequestController.java | 2 +- .../contact/JobsContactWebSessionBean.java | 10 ++- web/admin/contact/admin_contact_edit.xhtml | 2 +- 4 files changed, 74 insertions(+), 25 deletions(-) diff --git a/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestBean.java index 7b0a40ba..23623424 100644 --- a/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestBean.java @@ -18,6 +18,7 @@ package org.mxchange.jjobs.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; @@ -34,10 +35,9 @@ 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.jjobs.beans.helper.JobsAdminWebRequestController; -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 JobsAdminContactWebRequestBean implements JobsAdminContactWebReques } @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 JobsAdminContactWebRequestBean implements JobsAdminContactWebReques } @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/jjobs/beans/contact/JobsAdminContactWebRequestController.java b/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestController.java index 493aefbd..aa33a93e 100644 --- a/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestController.java +++ b/src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestController.java @@ -42,7 +42,7 @@ public interface JobsAdminContactWebRequestController extends Serializable { *

* @return Redirect outcome */ - String changeContactData (); + String editContactData (); /** * Getter for cellphone id diff --git a/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java index 86cbc631..324bd1a9 100644 --- a/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java @@ -235,7 +235,7 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle 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 JobsContactWebSessionBean implements JobsContactWebSessionControlle System.out.println("ContactWebBean:afterUserLogin - EXIT!"); //NOI18N } + @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public List allContacts () { + return this.contactList; + } + /** * Clears this bean */ @@ -456,7 +461,6 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle // Trace message //this.getLogger().logTrace(MessageFormat.format("createContactInstance: localContact={0} - EXIT!", localContact)); - // Return it return localContact; } @@ -510,11 +514,13 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle } @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 @@

-- 2.39.5