From 0b2a64d2db140f757da61ab0325ea1fc33bc5fb9 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 28 Jul 2016 21:08:26 +0200 Subject: [PATCH] Imported new way into + ignored .gitcommits (please cherry-pick this) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .gitignore | 1 + .../contact/PizzaContactWebSessionBean.java | 155 +++++++++--------- .../PizzaContactWebSessionController.java | 16 +- 3 files changed, 90 insertions(+), 82 deletions(-) diff --git a/.gitignore b/.gitignore index 954416ad..d1971127 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ /*-ejb/build/ /*-ejb/dist/ .~lock* +.gitcommits diff --git a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionBean.java index eb3df7bd..e4a8e9f6 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionBean.java @@ -40,7 +40,6 @@ import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent; import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent; import org.mxchange.jcontacts.exceptions.ContactNotFoundException; import org.mxchange.jcountry.data.Country; -import org.mxchange.jcustomercore.events.customer.added.AdminAddedCustomerEvent; import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber; import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber; import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; @@ -52,9 +51,12 @@ import org.mxchange.jusercore.events.confirmation.UserConfirmedAccountEvent; import org.mxchange.jusercore.events.login.UserLoggedInEvent; import org.mxchange.jusercore.events.registration.UserRegisteredEvent; import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent; +import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent; import org.mxchange.jusercore.exceptions.UserPasswordMismatchException; +import org.mxchange.jusercore.model.user.User; import org.mxchange.pizzaapplication.beans.BasePizzaController; import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController; +import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController; /** * A general contact bean (controller) @@ -195,11 +197,22 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P */ private Long phoneNumber; + /** + * A list of all selectable contacts + */ + private List selectableContacts; + /** * Street */ private String street; + /** + * Regular user controller + */ + @Inject + private PizzaUserWebSessionController userController; + /** * Login bean (controller) */ @@ -230,9 +243,6 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P @Override public void afterAdminAddedContact (@Observes final AdminAddedContactEvent event) { - // Trace message - //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("contactController.afterAdminAddedContact(): event={0} - CALLED!", event)); //NOI18N - // The event must be valid if (null == event) { // Throw NPE @@ -242,10 +252,10 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P 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 + throw new NullPointerException("event.addedContact.contactId 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 + throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N } // Clear this bean @@ -253,81 +263,61 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P // Call other method this.contactList.add(event.getAddedContact()); - } - - @Override - public void afterAdminAddedCustomer (@Observes final AdminAddedCustomerEvent event) { - // The event must be valid // Call other method this.selectableContacts.add(event.getAddedContact()); - - // Trace message - //* NOISY-DEBUG: */ System.out.println("contactController.afterAdminAddedContact(): EXIT!"); //NOI18N } @Override public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) { - // Trace message - //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("contactController.afterAdminAddedUserEvent(): event={0} - CALLED!", event)); //NOI18N - // event should not be null if (null == event) { // Throw NPE throw new NullPointerException("event is null"); //NOI18N - } else if (event.getAddedCustomer() == null) { - // Throw again ... - throw new NullPointerException("event.addedCustomer is null"); //NOI18N - } else if (event.getAddedCustomer().getCustomerId() == null) { - // ... and again - throw new NullPointerException("event.addedCustomer.customerId is null"); //NOI18N - } else if (event.getAddedCustomer().getCustomerId() < 1) { - // Not valid - throw new IllegalArgumentException(MessageFormat.format("event.addedCustomer.customerId={0} is not valid", event.getAddedCustomer().getCustomerId())); //NOI18N //NOI18N + } else if (event.getAddedUser() == null) { + // Throw NPE again + throw new NullPointerException("event.addedUser is null"); //NOI18N + } else if (event.getAddedUser().getUserId() == null) { + // userId is null + throw new NullPointerException("event.addedUser.userId is null"); //NOI18N + } else if (event.getAddedUser().getUserId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N } - // Clear this bean + // Clear all data this.clear(); - - // Call other method - this.contactList.add(event.getAddedCustomer().getCustomerContact()); - - // Trace message - //* NOISY-DEBUG: */ System.out.println("contactController.afterAdminAddedUserEvent(): EXIT!"); //NOI18N } @Override - public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) { - // Trace message - //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterAdminAddedUserEvent: event={0} - CALLED!", event)); //NOI18N - + public void afterAdminLinkedUser (@Observes final AdminLinkedUserEvent event) { // event should not be null if (null == event) { // Throw NPE throw new NullPointerException("event is null"); //NOI18N - } else if (event.getAddedUser() == null) { + } else if (event.getLinkedUser() == null) { // Throw NPE again - throw new NullPointerException("event.addedUser is null"); //NOI18N - } else if (event.getAddedUser().getUserId() == null) { + throw new NullPointerException("event.linkedUser is null"); //NOI18N + } else if (event.getLinkedUser().getUserContact() == null) { + // Throw NPE again + throw new NullPointerException("event.linkedUser.userContact is null"); //NOI18N + } else if (event.getLinkedUser().getUserContact().getContactId() == null) { // userId is null - throw new NullPointerException("event.addedUser.userId is null"); //NOI18N - } else if (event.getAddedUser().getUserId() < 1) { + throw new NullPointerException("event.linkedUser.userContact.contactId is null"); //NOI18N + } else if (event.getLinkedUser().getUserContact().getContactId() < 1) { // Not avalid id - throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N + throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserContact().getContactId())); //NOI18N } + // Remove contact from list available contacts list + this.selectableContacts.remove(event.getLinkedUser().getUserContact()); + // Clear all data this.clear(); - - // Trace message - //* NOISY-DEBUG: */ System.out.println("contactController.afterAdminAddedUserEvent(): EXIT!"); //NOI18N } @Override public void afterAdminUpdatedContactDataEvent (@Observes final AdminUpdatedContactEvent event) { - // Trace message - //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("contactController.afterAdminUpdatedContactDataEvent(): event={0} - CALLED!", event)); //NOI18N - // event should not be null if (null == event) { // Throw NPE @@ -367,16 +357,10 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P // Add email address to list this.emailAddressList.add(event.getUpdatedContact().getContactEmailAddress()); - - // Trace message - //* NOISY-DEBUG: */ System.out.println("contactController.afterAdminUpdatedContactDataEvent(): EXIT!"); //NOI18N } @Override public void afterRegistrationEvent (@Observes final UserRegisteredEvent event) { - // Trace message - //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N - // event should not be null if (null == event) { // Throw NPE @@ -395,8 +379,6 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P // Get user instance Contact registeredContact = event.getRegisteredUser().getUserContact(); - // Debug message - //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: registeredContact={0}", registeredContact)); //NOI18N // Copy all data from registered->user this.copyContact(registeredContact); @@ -405,16 +387,10 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P // Clear all data this.clear(); - - // Trace message - //* NOISY-DEBUG: */ System.out.println("ContactWebBean:afterRegistration: EXIT!"); //NOI18N } @Override public void afterUserConfirmedAccount (@Observes final UserConfirmedAccountEvent event) { - // Trace message - //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterAdminUpdatedContactDataEvent: event={0} - CALLED!", event)); //NOI18N - // event should not be null if (null == event) { // Throw NPE @@ -444,23 +420,17 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P // Is id number the same? if (Objects.equals(contact.getContactId(), next.getContactId())) { // Found entry, so remove it and abort - this.contactList.remove(next); + this.removeContact(next); break; } } // Add contact to list this.contactList.add(contact); - - // Trace message - //* NOISY-DEBUG: */ System.out.println("ContactWebBean:afterAdminUpdatedContactDataEvent: EXIT!"); //NOI18N } @Override public void afterUserLogin (@Observes final UserLoggedInEvent event) { - // Trace message - //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N - // event should not be null if (null == event) { // Throw NPE @@ -478,9 +448,6 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P // Copy all data to this bean this.copyContact(event.getLoggedInUser().getUserContact()); - - // Trace message - //* NOISY-DEBUG: */ System.out.println("ContactWebBean:afterUserLogin - EXIT!"); //NOI18N } @Override @@ -873,6 +840,40 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P // Get full contact list this.contactList = this.contactBean.getAllContacts(); + + // Get all users + List allUsers = this.userController.allUsers(); + + // Get all contacts + List allContacts = this.contactBean.getAllContacts(); + + // Get iterator + Iterator iterator = allContacts.iterator(); + + // Loop through it + while (iterator.hasNext()) { + // Get next element + Contact next = iterator.next(); + + // Get iterator + Iterator userIterator = allUsers.iterator(); + + // Loop through all users + while (userIterator.hasNext()) { + // Get user instance + User nextUser = userIterator.next(); + + // Is contact same? + if (Objects.equals(next, nextUser.getUserContact())) { + // Found same + iterator.remove(); + break; + } + } + } + + // Set contact list + this.selectableContacts = allContacts; } @Override @@ -956,6 +957,11 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P return localContact; } + @Override + public List selectableContacts () { + return Collections.unmodifiableList(this.selectableContacts); + } + @Override public void updateContactDataFromController (final Contact contact) { // Is the instance valid? @@ -996,6 +1002,8 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P private void clear () { // Clear all data // - personal data + this.setGender(null); + // TODO: Unfinished this.setTitle(null); this.setFirstName(null); this.setFamilyName(null); this.setStreet(null); @@ -1008,7 +1016,6 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P // - contact data this.setEmailAddress(null); this.setEmailAddressRepeat(null); - this.setPhoneCountry(null); this.setPhoneAreaCode(null); this.setPhoneCountry(null); this.setPhoneNumber(null); diff --git a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionController.java index fd767813..984d2e97 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionController.java @@ -25,12 +25,12 @@ import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent; import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent; import org.mxchange.jcontacts.exceptions.ContactNotFoundException; import org.mxchange.jcountry.data.Country; -import org.mxchange.jcustomercore.events.customer.added.AdminAddedCustomerEvent; import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider; import org.mxchange.jusercore.events.confirmation.UserConfirmedAccountEvent; import org.mxchange.jusercore.events.login.UserLoggedInEvent; import org.mxchange.jusercore.events.registration.UserRegisteredEvent; import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent; +import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent; /** * An interface for user beans @@ -49,7 +49,7 @@ public interface PizzaContactWebSessionController extends Serializable { *

* @return A list of all contacts. */ - List allContacts(); + List allContacts (); /** * Checks whether there are contacts. @@ -100,22 +100,22 @@ public interface PizzaContactWebSessionController extends Serializable { /** * Observes events being fired when an administrator has added a new - * customer. + * contact. *

* @param event Event being fired */ - void afterAdminAddedCustomer (final AdminAddedCustomerEvent event); + void afterAdminAddedContact (final AdminAddedContactEvent event); /** - * Observes events being fired when an administrator has added a new - * contact. + * Observes events being fired when an administrator has linked a new user + * with existing contact data. *

* @param event Event being fired */ - void afterAdminAddedContact (final AdminAddedContactEvent event); + void afterAdminLinkedUser (final AdminLinkedUserEvent event); /** - * Event observer for updated contact data by admins + * Event observer for updated contact data by administrators *

* @param event Updated contact data event */ -- 2.39.5