From 51b92002cda7d30d081bb5ad6bf9671ec2f18fb5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 10 May 2016 12:44:35 +0200 Subject: [PATCH] Continued a bit: - merged some generic stuff from jrecruiter-war project - no customer in addressbook, but surely in pizzaservice - sorted members MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../contact/JobsContactWebSessionBean.java | 84 +++++++++++++++---- 1 file changed, 69 insertions(+), 15 deletions(-) diff --git a/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java index 8233eb18..65af5406 100644 --- a/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java @@ -219,9 +219,27 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle } @Override - public void addEmailAddress (final String contactEmailAddress) { - // Add it - this.emailAddressList.add(contactEmailAddress); + public void afterAdminAddedContact (@Observes final AdminAddedContactEvent event) { + // The event must be valid + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getAddedContact() == null) { + // Throw again ... + throw new NullPointerException("event.addedContact is null"); //NOI18N + } else if (event.getAddedContact().getContactId() == null) { + // ... and again + throw new NullPointerException("event.addedContact.customerId is null"); //NOI18N + } else if (event.getAddedContact().getContactId() < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("event.addedContact.customerId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N + } + + // Clear this bean + this.clear(); + + // Call other method + this.contactList.add(event.getAddedContact()); } @Override @@ -462,11 +480,7 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle // Trace message //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: contact={1} - EXIT!", this.getClass().getSimpleName(), contact)); - // Created timestamp and ownContact - contact.setContactOwnContact(Boolean.TRUE); - // Trace message - //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("createContactInstance: localContact={0} - EXIT!", localContact)); // Return it return localContact; } @@ -807,21 +821,21 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle } @Override - public void updateContactDataFromController (final Contact userContact) { + public void updateContactDataFromController (final Contact contact) { // Is the instance valid? - if (null == userContact) { + if (null == contact) { // Throw NPE - throw new NullPointerException("userContact is null"); //NOI18N - } else if (userContact.getContactId() == null) { + throw new NullPointerException("contact is null"); //NOI18N + } else if (contact.getContactId() == null) { // Throw NPE - throw new NullPointerException("userContact.contactId is null"); //NOI18N - } else if (userContact.getContactId() < 1) { + throw new NullPointerException("contact.contactId is null"); //NOI18N + } else if (contact.getContactId() < 1) { // Not valid id number - throw new IllegalArgumentException(MessageFormat.format("userContact.contactId={0} is not valid.", userContact.getContactId())); //NOI18N + throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N } // Set all - this.copyContact(userContact); + this.copyContact(contact); } /** @@ -873,6 +887,18 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle * @param contact Contact instance */ private void copyContact (final Contact contact) { + // Is the instance valid? + if (null == contact) { + // Throw NPE + throw new NullPointerException("contact is null"); //NOI18N + } else if (contact.getContactId() == null) { + // Throw NPE + throw new NullPointerException("contact.contactId is null"); //NOI18N + } else if (contact.getContactId() < 1) { + // Not valid id number + throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N + } + // Copy all fields: // - base data this.setGender(contact.getContactGender()); @@ -911,4 +937,32 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle this.setComment(contact.getContactComment()); } + /** + * Removes given contact from all lists + *

+ * @param contact Contact instance to remove + */ + private void removeContact (final Contact contact) { + // Is the instance valid? + if (null == contact) { + // Throw NPE + throw new NullPointerException("contact is null"); //NOI18N + } else if (contact.getContactId() == null) { + // Throw NPE + throw new NullPointerException("contact.contactId is null"); //NOI18N + } else if (contact.getContactId() < 1) { + // Not valid id number + throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N + } + + // Remove from general list + if (!this.contactList.remove(contact)) { + // Did not remove contact + throw new IllegalStateException(MessageFormat.format("contact {0} was not removed.", contact.getContactId())); //NOI18N + } + + // Remove from other lists + this.emailAddressList.remove(contact.getContactEmailAddress()); + } + } -- 2.39.5