]> git.mxchange.org Git - addressbook-war.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Fri, 21 Apr 2017 21:05:12 +0000 (23:05 +0200)
committerRoland Häder <roland@mxchange.org>
Sat, 22 Apr 2017 19:30:08 +0000 (21:30 +0200)
- added missing controllers
- renamed helper bean to more common name
- updated other beans as they seem to be not fully upgraded

Signed-off-by: Roland Häder <roland@mxchange.org>
21 files changed:
src/java/org/mxchange/addressbook/beans/confirmlink/AddressbookConfirmationLinkWebRequestBean.java
src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestBean.java
src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionBean.java
src/java/org/mxchange/addressbook/beans/contact/phone/AddressbookAdminContactPhoneWebRequestBean.java [new file with mode: 0644]
src/java/org/mxchange/addressbook/beans/contact/phone/AddressbookAdminContactPhoneWebRequestController.java [new file with mode: 0644]
src/java/org/mxchange/addressbook/beans/email_address/AddressbookEmailChangeWebSessionBean.java
src/java/org/mxchange/addressbook/beans/helper/AddressbookWebRequestController.java [deleted file]
src/java/org/mxchange/addressbook/beans/helper/AddressbookWebRequestHelper.java [deleted file]
src/java/org/mxchange/addressbook/beans/helper/AddressbookWebRequestHelperBean.java [new file with mode: 0644]
src/java/org/mxchange/addressbook/beans/helper/AddressbookWebRequestHelperController.java [new file with mode: 0644]
src/java/org/mxchange/addressbook/beans/login/AddressbookUserLoginWebSessionBean.java
src/java/org/mxchange/addressbook/beans/login/AddressbookUserLoginWebSessionController.java
src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminPhoneWebRequestBean.java
src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminPhoneWebRequestController.java
src/java/org/mxchange/addressbook/beans/phone/AddressbookPhoneWebApplicationBean.java [new file with mode: 0644]
src/java/org/mxchange/addressbook/beans/phone/AddressbookPhoneWebApplicationController.java [new file with mode: 0644]
src/java/org/mxchange/addressbook/beans/resendlink/AddressbookResendLinkWebSessionBean.java
src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebRequestBean.java
src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebRequestController.java
src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java
src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionController.java

index d64437b480de63d05c36aa8c7e6c3869a1e08125..ea05dcf6ca31482f07e02bc3a5a59c7c03e782ec 100644 (file)
@@ -31,7 +31,6 @@ import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import org.mxchange.addressbook.beans.BaseAddressbookController;
-import org.mxchange.addressbook.beans.helper.AddressbookWebRequestController;
 import org.mxchange.addressbook.beans.user.AddressbookUserWebSessionController;
 import org.mxchange.jcoreee.utils.FacesUtils;
 import org.mxchange.jusercore.events.confirmation.ObservableUserConfirmedAccountEvent;
@@ -41,6 +40,7 @@ import org.mxchange.jusercore.exceptions.UserStatusLockedException;
 import org.mxchange.jusercore.model.user.User;
 import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
 import org.mxchange.jusercore.model.user.status.UserAccountStatus;
+import org.mxchange.addressbook.beans.helper.AddressbookWebRequestHelperController;
 
 /**
  * A web request bean for confirmation link handling
@@ -60,7 +60,7 @@ public class AddressbookConfirmationLinkWebRequestBean extends BaseAddressbookCo
         * Bean helper instance
         */
        @Inject
-       private AddressbookWebRequestController beanHelper;
+       private AddressbookWebRequestHelperController beanHelper;
 
        /**
         * Confirmation key
index 0ca0188ae56ec14caa0b998826c7631bf189a2e4..9314278c06aeb693af8dff2c221875cb2d305a9d 100644 (file)
@@ -31,7 +31,7 @@ import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import org.mxchange.addressbook.beans.BaseAddressbookController;
-import org.mxchange.addressbook.beans.helper.AddressbookWebRequestController;
+import org.mxchange.addressbook.beans.helper.AddressbookWebRequestHelperController;
 import org.mxchange.jcontacts.contact.AdminContactSessionBeanRemote;
 import org.mxchange.jcontacts.contact.Contact;
 import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
@@ -83,7 +83,7 @@ public class AddressbookAdminContactWebRequestBean extends BaseAddressbookContro
         * Bean helper instance
         */
        @Inject
-       private AddressbookWebRequestController beanHelper;
+       private AddressbookWebRequestHelperController beanHelper;
 
        /**
         * Birth day
index 2e1fe76a0c9cd66a1621ebf6ca6dc57b151e87c0..2bc2ef61571dc1d4654ace10a701ddadc2325b08 100644 (file)
@@ -277,9 +277,6 @@ public class AddressbookContactWebSessionBean extends BaseAddressbookController
         * @param event Event being fired
         */
        public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent 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
@@ -357,9 +354,6 @@ public class AddressbookContactWebSessionBean extends BaseAddressbookController
 
                // Add email address to list
                this.emailAddressList.add(event.getUpdatedContact().getContactEmailAddress());
-
-               // Trace message
-               //* NOISY-DEBUG: */ System.out.println("contactController.afterAdminUpdatedContactDataEvent(): EXIT!"); //NOI18N
        }
 
        /**
@@ -452,18 +446,12 @@ public class AddressbookContactWebSessionBean extends BaseAddressbookController
        @Override
        @SuppressWarnings ("ReturnOfCollectionOrArrayField")
        public List<Contact> allContacts () {
-               // Debug message
-               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactController.allContacts: contactList.size()={0} - EXIT!", this.contactList.size()));
-
                // Return un-modified list
                return this.contactList;
        }
 
        @Override
        public Contact createContactInstance () {
-               // User message
-               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: CALLED!", this.getClass().getSimpleName()));
-
                // Is all required data set?
                if (!this.isRequiredPersonalDataSet()) {
                        // No, then abort here
@@ -490,9 +478,6 @@ public class AddressbookContactWebSessionBean extends BaseAddressbookController
                contact.setContactBirthday(this.getBirthday());
                contact.setContactComment(this.getComment());
 
-               // Debug message
-               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: this.emailAddress={1}", this.getClass().getSimpleName(), this.getEmailAddress()));
-
                // Don't set null or wrong references
                if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
                        // Now the number must be given
@@ -550,9 +535,6 @@ public class AddressbookContactWebSessionBean extends BaseAddressbookController
                        contact.setContactMobileNumber(mobile);
                }
 
-               // Trace message
-               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: contact={1} - EXIT!", this.getClass().getSimpleName(), contact));
-
                // Return it
                return contact;
        }
diff --git a/src/java/org/mxchange/addressbook/beans/contact/phone/AddressbookAdminContactPhoneWebRequestBean.java b/src/java/org/mxchange/addressbook/beans/contact/phone/AddressbookAdminContactPhoneWebRequestBean.java
new file mode 100644 (file)
index 0000000..1889708
--- /dev/null
@@ -0,0 +1,577 @@
+/*
+ * Copyright (C) 2016 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.contact.phone;
+
+import java.text.MessageFormat;
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.event.Event;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Any;
+import javax.faces.view.facelets.FaceletException;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import org.mxchange.addressbook.beans.BaseAddressbookController;
+import org.mxchange.addressbook.beans.helper.AddressbookWebRequestHelperController;
+import org.mxchange.addressbook.beans.phone.AddressbookAdminPhoneWebRequestController;
+import org.mxchange.jcontacts.contact.Contact;
+import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
+import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
+import org.mxchange.jcontacts.events.fax.linked.AdminLinkedFaxNumberEvent;
+import org.mxchange.jcontacts.events.fax.linked.ObservableAdminLinkedFaxNumberEvent;
+import org.mxchange.jcontacts.events.fax.unlinked.AdminUnlinkedFaxNumberEvent;
+import org.mxchange.jcontacts.events.fax.unlinked.ObservableAdminUnlinkedFaxNumberEvent;
+import org.mxchange.jcontacts.events.landline.linked.AdminLinkedLandLineNumberEvent;
+import org.mxchange.jcontacts.events.landline.linked.ObservableAdminLinkedLandLineNumberEvent;
+import org.mxchange.jcontacts.events.landline.unlinked.AdminUnlinkedLandLineNumberEvent;
+import org.mxchange.jcontacts.events.landline.unlinked.ObservableAdminUnlinkedLandLineNumberEvent;
+import org.mxchange.jcontacts.events.mobile.linked.AdminLinkedMobileNumberEvent;
+import org.mxchange.jcontacts.events.mobile.linked.ObservableAdminLinkedMobileNumberEvent;
+import org.mxchange.jcontacts.events.mobile.unlinked.AdminUnlinkedMobileNumberEvent;
+import org.mxchange.jcontacts.events.mobile.unlinked.ObservableAdminUnlinkedMobileNumberEvent;
+import org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote;
+import org.mxchange.jcountry.data.Country;
+import org.mxchange.jphone.exceptions.PhoneNumberAlreadyLinkedException;
+import org.mxchange.jphone.exceptions.PhoneNumberNotLinkedException;
+import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
+import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
+import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
+import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
+import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
+import org.mxchange.jphone.phonenumbers.mobile.MobileNumber;
+import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
+import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
+
+/**
+ * An administrative contact phone controller (bean)
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("adminContactPhoneController")
+@RequestScoped
+public class AddressbookAdminContactPhoneWebRequestBean extends BaseAddressbookController implements AddressbookAdminContactPhoneWebRequestController {
+
+       /**
+        * Call-stack instance (5 may show BeanELResolver.getValue as caller)
+        */
+       private static final short THREAD_STACK = 5;
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 542_145_347_916L;
+
+       /**
+        * Event being fired when a fax number has been linked
+        */
+       @Inject
+       @Any
+       private Event<ObservableAdminLinkedFaxNumberEvent> adminLinkedFaxNumberEvent;
+
+       /**
+        * Event being fired when a land-line number has been linked
+        */
+       @Inject
+       @Any
+       private Event<ObservableAdminLinkedLandLineNumberEvent> adminLinkedLandLineNumberEvent;
+
+       /**
+        * Event being fired when a mobile number has been linked
+        */
+       @Inject
+       @Any
+       private Event<ObservableAdminLinkedMobileNumberEvent> adminLinkedMobileNumberEvent;
+
+       /**
+        * Administrative EJB for phone number
+        */
+       private AdminContactsPhoneSessionBeanRemote adminPhoneBean;
+
+       /**
+        * Administrative phone controller
+        */
+       @Inject
+       private AddressbookAdminPhoneWebRequestController adminPhoneController;
+
+       /**
+        * Bean helper
+        */
+       @Inject
+       private AddressbookWebRequestHelperController beanHelper;
+
+       /**
+        * Event being fired when a fax number has been unlinked
+        */
+       @Inject
+       @Any
+       private Event<ObservableAdminUnlinkedFaxNumberEvent> faxNumberUnlinkedEvent;
+
+       /**
+        * Event being fired when a land-line number has been unlinked
+        */
+       @Inject
+       @Any
+       private Event<ObservableAdminUnlinkedLandLineNumberEvent> landLineNumberUnlinkedEvent;
+
+       /**
+        * Event being fired when admin unlinks mobile from contact
+        */
+       @Inject
+       @Any
+       private Event<ObservableAdminUnlinkedMobileNumberEvent> mobileNumberUnlinkedEvent;
+
+       /**
+        * Default constructor
+        */
+       public AddressbookAdminContactPhoneWebRequestBean () {
+               // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[3].getClassName(), Thread.currentThread().getStackTrace()[3].getMethodName());
+               // System.out.println(MessageFormat.format("{0}: Constructed, caller: {1}", this.getClass().getSimpleName(), caller));
+
+               // Try it
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // Try to lookup the beans
+                       this.adminPhoneBean = (AdminContactsPhoneSessionBeanRemote) context.lookup("java:global/addressbook-ejb/adminContactPhone!org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote"); //NOI18N
+               } catch (final NamingException e) {
+                       // Throw again
+                       throw new FaceletException(e);
+               }
+       }
+
+       /**
+        * Observes events being fired when an administrator has added a new
+        * contact.
+        * <p>
+        * @param event Event being fired
+        */
+       public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent 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.contactId is null"); //NOI18N
+               } else if (event.getAddedContact().getContactId() < 1) {
+                       // Not valid
+                       throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N
+               }
+
+               // Clear this bean
+               this.clear();
+       }
+
+       /**
+        * Event observer for newly added users by administrator
+        * <p>
+        * @param event Event being fired
+        */
+       public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //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 all data
+               this.clear();
+       }
+
+       /**
+        * Event observer for updated contact data by administrators
+        * <p>
+        * @param event Updated contact data event
+        */
+       public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getUpdatedContact() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.updatedContact is null"); //NOI18N
+               } else if (event.getUpdatedContact().getContactId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
+               } else if (event.getUpdatedContact().getContactId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
+               }
+
+               // Clear all data
+               this.clear();
+       }
+
+       @Override
+       public String doLinkAddFaxNumber (final Contact contact) {
+               // Is all data properly set?
+               if (null == contact) {
+                       // Throw NPE
+                       throw new NullPointerException("contact is null"); //NOI18N
+               } else if (contact.getContactId() == null) {
+                       // Throw it again
+                       throw new NullPointerException("contact.contactId is null"); //NOI18N
+               } else if (contact.getContactId() < 1) {
+                       // Is not valid
+                       throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
+               } else if ((this.adminPhoneController.getFaxNumber() == null) && (this.adminPhoneController.getPhoneCountry() == null) && ((this.adminPhoneController.getPhoneAreaCode() == null) || (this.adminPhoneController.getPhoneAreaCode() < 1)) && ((this.adminPhoneController.getPhoneNumber() == null) || (this.adminPhoneController.getPhoneNumber() < 1))) {
+                       // All fields are empty
+                       throw new NullPointerException("choosenFaxNumber, mobileProvider and phoneNumer are null"); //NOI18N
+               } else if ((this.adminPhoneController.getFaxNumber() instanceof DialableFaxNumber) && (this.adminPhoneController.getPhoneCountry() instanceof Country) && (this.adminPhoneController.getPhoneAreaCode() instanceof Integer) && (this.adminPhoneController.getPhoneNumber() instanceof Long)) {
+                       // All fields are set
+                       throw new IllegalStateException("choosenFaxNumber, mobileProvider and phoneNumer are all set"); //NOI18N
+               } else if ((this.adminPhoneController.getPhoneCountry() == null) && ((this.adminPhoneController.getPhoneAreaCode() instanceof Integer) || (this.adminPhoneController.getPhoneNumber() instanceof Long))) {
+                       // No country selected
+                       this.showFacesMessage("form_add_contact_fax:phoneCountry", "ERROR_ADMIN_NO_PHONE_COUNTRY_SELECTED"); //NOI18N
+                       return ""; //NOI18N
+               } else if (((this.adminPhoneController.getPhoneAreaCode() == null) || (this.adminPhoneController.getPhoneAreaCode() < 1)) && ((this.adminPhoneController.getPhoneCountry() instanceof Country) || (this.adminPhoneController.getPhoneNumber() instanceof Long))) {
+                       // No area code entered
+                       this.showFacesMessage("form_add_contact_fax:phoneAreaCode", "ERROR_ADMIN_NO_PHONE_AREA_CODE_ENTERED"); //NOI18N
+                       return ""; //NOI18N
+               } else if (((this.adminPhoneController.getPhoneNumber() == null) || (this.adminPhoneController.getPhoneNumber() < 1)) && ((this.adminPhoneController.getPhoneCountry() instanceof Country) || (this.adminPhoneController.getPhoneAreaCode() instanceof Integer))) {
+                       // No phone number entered
+                       this.showFacesMessage("form_add_contact_fax:phoneNumber", "ERROR_ADMIN_NO_PHONE_NUMBER_ENTERED"); //NOI18N
+                       return ""; //NOI18N
+               }
+
+               // Init instances
+               Contact updatedContact;
+               DialableFaxNumber faxNumber = this.adminPhoneController.getFaxNumber();
+
+               // Try it again
+               try {
+                       // All fine so far, then which was choosen?
+                       if (faxNumber instanceof DialableFaxNumber) {
+                               // User has choosen number
+                               updatedContact = this.adminPhoneBean.linkExistingFaxNumberWithContact(contact, faxNumber);
+                       } else {
+                               // Create new instance
+                               faxNumber = new FaxNumber(this.adminPhoneController.getPhoneCountry(), this.adminPhoneController.getPhoneAreaCode(), this.adminPhoneController.getPhoneNumber());
+
+                               // Link it, too
+                               updatedContact = this.adminPhoneBean.linkNewFaxNumberWithContact(contact, faxNumber);
+                       }
+               } catch (final PhoneNumberAlreadyLinkedException ex) {
+                       // Throw again as cause
+                       this.showFacesMessage("form_add_contact_fax:phoneNumber", ex); //NOI18N
+                       return ""; //NOI18N
+               }
+
+               // Fire event
+               this.adminLinkedFaxNumberEvent.fire(new AdminLinkedFaxNumberEvent(updatedContact, faxNumber));
+
+               // Return to contact profile
+               return "admin_show_contact"; //NOI18N
+       }
+
+       @Override
+       public String doLinkAddLandLineNumber (final Contact contact) {
+               // Is all data properly set?
+               if (null == contact) {
+                       // Throw NPE
+                       throw new NullPointerException("contact is null"); //NOI18N
+               } else if (contact.getContactId() == null) {
+                       // Throw it again
+                       throw new NullPointerException("contact.contactId is null"); //NOI18N
+               } else if (contact.getContactId() < 1) {
+                       // Is not valid
+                       throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
+               } else if ((this.adminPhoneController.getLandLineNumber() == null) && (this.adminPhoneController.getPhoneCountry() == null) && ((this.adminPhoneController.getPhoneAreaCode() == null) || (this.adminPhoneController.getPhoneAreaCode() < 1)) && ((this.adminPhoneController.getPhoneNumber() == null) || (this.adminPhoneController.getPhoneNumber() < 1))) {
+                       // All fields are empty
+                       throw new NullPointerException("choosenLandLineNumber, mobileProvider and phoneNumer are null"); //NOI18N
+               } else if ((this.adminPhoneController.getLandLineNumber() instanceof DialableLandLineNumber) && (this.adminPhoneController.getPhoneCountry() instanceof Country) && (this.adminPhoneController.getPhoneAreaCode() instanceof Integer) && (this.adminPhoneController.getPhoneNumber() instanceof Long)) {
+                       // All fields are set
+                       throw new IllegalStateException("choosenLandLineNumber, mobileProvider and phoneNumer are all set"); //NOI18N
+               } else if ((this.adminPhoneController.getPhoneCountry() == null) && ((this.adminPhoneController.getPhoneAreaCode() instanceof Integer) || (this.adminPhoneController.getPhoneNumber() instanceof Long))) {
+                       // No country selected
+                       this.showFacesMessage("form_add_contact_landLine:phoneCountry", "ERROR_ADMIN_NO_PHONE_COUNTRY_SELECTED"); //NOI18N
+                       return ""; //NOI18N
+               } else if (((this.adminPhoneController.getPhoneAreaCode() == null) || (this.adminPhoneController.getPhoneAreaCode() < 1)) && ((this.adminPhoneController.getPhoneCountry() instanceof Country) || (this.adminPhoneController.getPhoneNumber() instanceof Long))) {
+                       // No area code entered
+                       this.showFacesMessage("form_add_contact_landLine:phoneAreaCode", "ERROR_ADMIN_NO_PHONE_AREA_CODE_ENTERED"); //NOI18N
+                       return ""; //NOI18N
+               } else if (((this.adminPhoneController.getPhoneNumber() == null) || (this.adminPhoneController.getPhoneNumber() < 1)) && ((this.adminPhoneController.getPhoneCountry() instanceof Country) || (this.adminPhoneController.getPhoneAreaCode() instanceof Integer))) {
+                       // No phone number entered
+                       this.showFacesMessage("form_add_contact_landLine:phoneNumber", "ERROR_ADMIN_NO_PHONE_NUMBER_ENTERED"); //NOI18N
+                       return ""; //NOI18N
+               }
+
+               // Init instance
+               Contact updatedContact;
+               DialableLandLineNumber landLineNumber = this.adminPhoneController.getLandLineNumber();
+
+               // Try it again
+               try {
+                       // All fine so far, then which was choosen?
+                       if (landLineNumber instanceof DialableLandLineNumber) {
+                               // User has choosen number
+                               updatedContact = this.adminPhoneBean.linkExistingLandLineNumberWithContact(contact, landLineNumber);
+                       } else {
+                               // Create new instance
+                               landLineNumber = new LandLineNumber(this.adminPhoneController.getPhoneCountry(), this.adminPhoneController.getPhoneAreaCode(), this.adminPhoneController.getPhoneNumber());
+
+                               // Link it, too
+                               updatedContact = this.adminPhoneBean.linkNewLandLineNumberWithContact(contact, landLineNumber);
+                       }
+               } catch (final PhoneNumberAlreadyLinkedException ex) {
+                       // Throw again as cause
+                       this.showFacesMessage("form_add_contact_landLine:phoneNumber", ex); //NOI18N
+                       return ""; //NOI18N
+               }
+
+               // Fire event
+               this.adminLinkedLandLineNumberEvent.fire(new AdminLinkedLandLineNumberEvent(updatedContact, landLineNumber));
+
+               // Return to contact profile
+               return "admin_show_contact"; //NOI18N
+       }
+
+       @Override
+       public String doLinkAddMobileNumber (final Contact contact) {
+               // Is all data properly set?
+               if (null == contact) {
+                       // Throw NPE
+                       throw new NullPointerException("contact is null"); //NOI18N
+               } else if (contact.getContactId() == null) {
+                       // Throw it again
+                       throw new NullPointerException("contact.contactId is null"); //NOI18N
+               } else if (contact.getContactId() < 1) {
+                       // Is not valid
+                       throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
+               } else if ((this.adminPhoneController.getMobileNumber() == null) && (this.adminPhoneController.getMobileProvider() == null) && ((this.adminPhoneController.getPhoneNumber() == null) || (this.adminPhoneController.getPhoneNumber() < 1))) {
+                       // All fields are empty
+                       throw new NullPointerException("choosenMobileNumber, mobileProvider and phoneNumer are null"); //NOI18N
+               } else if ((this.adminPhoneController.getMobileNumber() instanceof DialableMobileNumber) && (this.adminPhoneController.getMobileProvider() instanceof MobileProvider) && (this.adminPhoneController.getPhoneNumber() instanceof Long)) {
+                       // All fields are set
+                       throw new IllegalStateException("choosenMobileNumber, mobileProvider and phoneNumer are all set"); //NOI18N
+               } else if ((this.adminPhoneController.getMobileProvider() == null) && (this.adminPhoneController.getPhoneNumber() instanceof Long)) {
+                       // No mobile provider selected
+                       this.showFacesMessage("form_add_contact_mobile:phoneCountry", "ERROR_ADMIN_NO_PHONE_MOBILE_PROVIDER_SELECTED"); //NOI18N
+                       return ""; //NOI18N
+               } else if (((this.adminPhoneController.getPhoneNumber() == null) || (this.adminPhoneController.getPhoneNumber() < 1)) && (this.adminPhoneController.getMobileProvider() instanceof MobileProvider)) {
+                       // No phone number entered
+                       this.showFacesMessage("form_add_contact_mobile:phoneNumber", "ERROR_ADMIN_NO_PHONE_NUMBER_ENTERED"); //NOI18N
+                       return ""; //NOI18N
+               }
+
+               // Init instance
+               Contact updatedContact;
+               DialableMobileNumber mobileNumber = this.adminPhoneController.getMobileNumber();
+
+               // Try it again
+               try {
+                       // All fine so far, then which was choosen?
+                       if (mobileNumber instanceof DialableMobileNumber) {
+                               // User has choosen number
+                               updatedContact = this.adminPhoneBean.linkExistingMobileNumberWithContact(contact, mobileNumber);
+                       } else {
+                               // Create new instance
+                               mobileNumber = new MobileNumber(this.adminPhoneController.getMobileProvider(), this.adminPhoneController.getPhoneNumber());
+
+                               // Link it, too
+                               updatedContact = this.adminPhoneBean.linkNewMobileNumberWithContact(contact, mobileNumber);
+                       }
+               } catch (final PhoneNumberAlreadyLinkedException ex) {
+                       // Throw again as cause
+                       this.showFacesMessage("form_add_contact_mobile:phoneNumber", ex); //NOI18N
+                       return ""; //NOI18N
+               }
+
+               // Fire event
+               this.adminLinkedMobileNumberEvent.fire(new AdminLinkedMobileNumberEvent(updatedContact, mobileNumber));
+
+               // Return to contact profile
+               return "admin_show_contact"; //NOI18N
+       }
+
+       @Override
+       public String unlinkFaxContactData () {
+               // Is all data set
+               if (this.beanHelper.getFaxNumber() == null) {
+                       // Not set, throw NPE
+                       throw new NullPointerException("this.beanHelper.faxNumber is null"); //NOI18N
+               } else if (this.beanHelper.getFaxNumber().getPhoneId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("this.beanHelper.faxNumber.phoneId is null"); //NOI18N
+               } else if (this.beanHelper.getFaxNumber().getPhoneId() < 1) {
+                       // Invalid number
+                       throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.faxNumber.phoneId={0} is not valid", this.beanHelper.getFaxNumber().getPhoneId())); //NOI18N
+               } else if (this.beanHelper.getFaxNumber().getPhoneNumber() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("this.beanHelper.faxNumber.phoneNumber is null"); //NOI18N
+               } else if (this.beanHelper.getFaxNumber().getPhoneNumber() < 1) {
+                       // Throw it again ...
+                       throw new NullPointerException(MessageFormat.format("this.beanHelper.faxNumber.phoneNumber={0} is not valid.", this.beanHelper.getFaxNumber().getPhoneNumber())); //NOI18N
+               } else if (this.beanHelper.getContact() == null) {
+                       // ... and throw again
+                       throw new NullPointerException("this.beanHelper.contact is null"); //NOI18N
+               } else if (this.beanHelper.getContact().getContactId() == null) {
+                       // ... and again ...
+                       throw new NullPointerException("this.beanHelper.contact.contactId is null"); //NOI18N
+               } else if (this.beanHelper.getContact().getContactId() < 1) {
+                       // Invalid id number
+                       throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.contact.contactId={0} is invalid.", this.beanHelper.getContact().getContactId())); //NOI18N
+               }
+
+               // Init contact instance
+               Contact updatedContact;
+
+               try {
+                       // Unlink it and return contact without fax instance
+                       updatedContact = this.adminPhoneBean.unlinkFaxDataFromContact(this.beanHelper.getContact(), this.beanHelper.getFaxNumber());
+               } catch (final PhoneNumberNotLinkedException ex) {
+                       // Did not work
+                       this.showFacesMessage("form_unlink_contact_fax:faxNumberId", ex); //NOI18N
+                       return ""; //NOI18N
+               }
+
+               // Fire event
+               this.faxNumberUnlinkedEvent.fire(new AdminUnlinkedFaxNumberEvent(updatedContact, this.beanHelper.getFaxNumber()));
+
+               // All fine here
+               return "admin_show_contact"; //NOI18N
+       }
+
+       @Override
+       public String unlinkLandLineContactData () {
+               // Is all data set
+               if (this.beanHelper.getLandLineNumber() == null) {
+                       // Not set, throw NPE
+                       throw new NullPointerException("this.beanHelper.landLineNumber is null"); //NOI18N
+               } else if (this.beanHelper.getLandLineNumber().getPhoneId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("this.beanHelper.landLineNumber.phoneId is null"); //NOI18N
+               } else if (this.beanHelper.getLandLineNumber().getPhoneId() < 1) {
+                       // Invalid number
+                       throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.landLineNumber.phoneId={0} is not valid", this.beanHelper.getLandLineNumber().getPhoneId())); //NOI18N
+               } else if (this.beanHelper.getLandLineNumber().getPhoneNumber() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("this.beanHelper.landLineNumber.phoneNumber is null"); //NOI18N
+               } else if (this.beanHelper.getLandLineNumber().getPhoneNumber() < 1) {
+                       // Throw it again ...
+                       throw new NullPointerException(MessageFormat.format("this.beanHelper.landLineNumber.phoneNumber={0} is not valid.", this.beanHelper.getLandLineNumber().getPhoneNumber())); //NOI18N
+               } else if (this.beanHelper.getContact() == null) {
+                       // ... and throw again
+                       throw new NullPointerException("this.beanHelper.contact is null"); //NOI18N
+               } else if (this.beanHelper.getContact().getContactId() == null) {
+                       // ... and again ...
+                       throw new NullPointerException("this.beanHelper.contact.contactId is null"); //NOI18N
+               } else if (this.beanHelper.getContact().getContactId() < 1) {
+                       // Invalid id number
+                       throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.contact.contactId={0} is invalid.", this.beanHelper.getContact().getContactId())); //NOI18N
+               }
+
+               // Init contact instance
+               Contact updatedContact;
+
+               try {
+                       // Unlink it and return contact without landLine instance
+                       updatedContact = this.adminPhoneBean.unlinkLandLineDataFromContact(this.beanHelper.getContact(), this.beanHelper.getLandLineNumber());
+               } catch (final PhoneNumberNotLinkedException ex) {
+                       // Did not work
+                       this.showFacesMessage("form_unlink_contact_landLine:landLineNumberId", ex); //NOI18N
+                       return ""; //NOI18N
+               }
+
+               // Fire event
+               this.landLineNumberUnlinkedEvent.fire(new AdminUnlinkedLandLineNumberEvent(updatedContact, this.beanHelper.getLandLineNumber()));
+
+               // All fine here
+               return "admin_show_contact"; //NOI18N
+       }
+
+       @Override
+       public String unlinkMobileContactData () {
+               // Is all data set
+               if (this.beanHelper.getMobileNumber() == null) {
+                       // Not set, throw NPE
+                       throw new NullPointerException("this.beanHelper.mobileNumber is null"); //NOI18N
+               } else if (this.beanHelper.getMobileNumber().getPhoneId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("this.beanHelper.mobileNumber.phoneId is null"); //NOI18N
+               } else if (this.beanHelper.getMobileNumber().getPhoneId() < 1) {
+                       // Invalid number
+                       throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.mobileNumber.phoneId={0} is not valid", this.beanHelper.getMobileNumber().getPhoneId())); //NOI18N
+               } else if (this.beanHelper.getMobileNumber().getMobileProvider() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("this.beanHelper.mobileNumber.mobileProvider is null"); //NOI18N
+               } else if (this.beanHelper.getMobileNumber().getMobileProvider().getProviderId() == null) {
+                       // ... throw again
+                       throw new NullPointerException("this.beanHelper.mobileNumber.mobileProvider.providerId is null"); //NOI18N
+               } else if (this.beanHelper.getMobileNumber().getMobileProvider().getProviderId() < 1) {
+                       // Id not valid
+                       throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.mobileNumber.mobileProvider.providerId={0} is not valid.", this.beanHelper.getMobileNumber().getMobileProvider().getProviderId())); //NOI18N
+               } else if (this.beanHelper.getMobileNumber().getPhoneNumber() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("this.beanHelper.mobileNumber.phoneNumber is null"); //NOI18N
+               } else if (this.beanHelper.getMobileNumber().getPhoneNumber() < 1) {
+                       // Throw it again ...
+                       throw new NullPointerException(MessageFormat.format("this.beanHelper.mobileNumber.phoneNumber={0} is not valid.", this.beanHelper.getMobileNumber().getPhoneNumber())); //NOI18N
+               } else if (this.beanHelper.getContact() == null) {
+                       // ... and throw again
+                       throw new NullPointerException("this.beanHelper.contact is null"); //NOI18N
+               } else if (this.beanHelper.getContact().getContactId() == null) {
+                       // ... and again ...
+                       throw new NullPointerException("this.beanHelper.contact.contactId is null"); //NOI18N
+               } else if (this.beanHelper.getContact().getContactId() < 1) {
+                       // Invalid id number
+                       throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.contact.contactId={0} is invalid.", this.beanHelper.getContact().getContactId())); //NOI18N
+               }
+
+               // Init contact instance
+               Contact updatedContact;
+
+               try {
+                       // Unlink it and return contact without mobile instance
+                       updatedContact = this.adminPhoneBean.unlinkMobileDataFromContact(this.beanHelper.getContact(), this.beanHelper.getMobileNumber());
+               } catch (final PhoneNumberNotLinkedException ex) {
+                       // Did not work
+                       this.showFacesMessage("form_unlink_contact_mobile:mobileNumberId", ex); //NOI18N
+                       return ""; //NOI18N
+               }
+
+               // Fire event
+               this.mobileNumberUnlinkedEvent.fire(new AdminUnlinkedMobileNumberEvent(updatedContact, this.beanHelper.getMobileNumber()));
+
+               // All fine here
+               return "admin_show_contact"; //NOI18N
+       }
+
+       /**
+        * Clears this bean
+        */
+       private void clear () {
+               // Clear all data
+       }
+
+}
diff --git a/src/java/org/mxchange/addressbook/beans/contact/phone/AddressbookAdminContactPhoneWebRequestController.java b/src/java/org/mxchange/addressbook/beans/contact/phone/AddressbookAdminContactPhoneWebRequestController.java
new file mode 100644 (file)
index 0000000..0dc1fd8
--- /dev/null
@@ -0,0 +1,84 @@
+
+/*
+ * Copyright (C) 2016 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.contact.phone;
+
+import java.io.Serializable;
+import javax.ejb.Local;
+import org.mxchange.jcontacts.contact.Contact;
+
+/**
+ * An interface for user beans
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Local
+public interface AddressbookAdminContactPhoneWebRequestController extends Serializable {
+
+       /**
+        * Unlinks fax data with current contact
+        * <p>
+        * @return Redirect outcome
+        */
+       String unlinkFaxContactData ();
+
+       /**
+        * Unlinks land-line data with current contact
+        * <p>
+        * @return Redirect outcome
+        */
+       String unlinkLandLineContactData ();
+
+       /**
+        * Unlinks mobile data with current contact
+        * <p>
+        * @return Redirect outcome
+        */
+       String unlinkMobileContactData ();
+
+       /**
+        * Links given contact instance with set fax number or entered data. If
+        * both is set, a proper exception is thrown as this is an invalid state.
+        * <p>
+        * @param contact Contact instance to link with existing/new data
+        * <p>
+        * @return Redirect outcome
+        */
+       String doLinkAddFaxNumber (final Contact contact);
+
+       /**
+        * Links given contact instance with set land-line number or entered
+        * data. If both is set, a proper exception is thrown as this is an invalid
+        * state.
+        * <p>
+        * @param contact Contact instance to link with existing/new data
+        * <p>
+        * @return Redirect outcome
+        */
+       String doLinkAddLandLineNumber (final Contact contact);
+
+       /**
+        * Links given contact instance with set mobile or entered data. If both
+        * is set, a proper exception is thrown as this is an invalid state.
+        * <p>
+        * @param contact Contact instance to link with existing/new data
+        * <p>
+        * @return Redirect outcome
+        */
+       String doLinkAddMobileNumber (final Contact contact);
+
+}
index cc88e1101f30cbcb38b3ed0ebe61e0589e86728d..2b99a5e751863c3e7266281193ceb8203e7bcc5e 100644 (file)
@@ -70,7 +70,7 @@ public class AddressbookEmailChangeWebSessionBean extends BaseAddressbookControl
        /**
         * Remote email change bean
         */
-       private UserEmailChangeSessionBeanRemote emailBean;
+       private UserEmailChangeSessionBeanRemote emailChangeBean;
 
        /**
         * Features controller
@@ -79,7 +79,7 @@ public class AddressbookEmailChangeWebSessionBean extends BaseAddressbookControl
        private AddressbookFeaturesWebApplicationController featureController;
 
        /**
-        * Login bean (controller)
+        * Login controller (bean)
         */
        @Inject
        private AddressbookUserLoginWebSessionController userLoginController;
@@ -96,19 +96,20 @@ public class AddressbookEmailChangeWebSessionBean extends BaseAddressbookControl
                if (!this.userLoginController.isUserLoggedIn()) {
                        // Not logged-in
                        throw new IllegalStateException("User is not logged-in"); //NOI18N
+               } else if (!this.featureController.isFeatureEnabled("user_change_email_address")) { //NOI18N
+                       // Editing is not allowed
+                       throw new IllegalStateException("User tried to change email address"); //NOI18N
                } else if (!this.isRequiredChangeEmailAddressSet()) {
                        // Not all required fields are set
                        throw new FaceletException("Not all required fields are set."); //NOI18N
                } else if (!Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat())) {
                        // Email address 1+2 mismatch
-                       throw new FaceletException("Email address 1/2 are mismatching."); //NOI18N
+                       this.showFacesMessage("form_user_change_email_address:emailAddressRepeat", "ERROR_USER_EMAIL_ADDRESSES_MISMATCH"); //NOI18N
+                       return ""; //NOI18N
                } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
                        // Password not matching
                        this.showFacesMessage("form_login_user_change_email_address:currentPassword", new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); //NOI18N
                        return ""; //NOI18N
-               } else if (!this.featureController.isFeatureEnabled("edit_user_data")) { //NOI18N
-                       // Editing is not allowed
-                       throw new IllegalStateException("User tried to edit personal data"); //NOI18N
                }
 
                // Get user instance
@@ -124,8 +125,13 @@ public class AddressbookEmailChangeWebSessionBean extends BaseAddressbookControl
 
                // Check if the email address is already enqueued
                if (this.isEmailAddressQueued(this.getEmailAddress())) {
+                       // Clear both email addresses
+                       this.setEmailAddress(null);
+                       this.setEmailAddressRepeat(null);
+
                        // Yes, then abort here
-                       return "login_email_already_added"; //NOI18N
+                       this.showFacesMessage("form_user_change_email_address:emailAddress", "ERROR_USER_CHANGE_EMAIL_ADDRESS_ALREADY_QUEUED"); //NOI18N
+                       return ""; //NOI18N
                }
 
                // Create change object, to save EJB calls, the hash is not generated here
@@ -135,13 +141,13 @@ public class AddressbookEmailChangeWebSessionBean extends BaseAddressbookControl
                String baseUrl = FacesUtils.generateBaseUrl();
 
                // Call EJB
-               this.emailBean.enqueueEmailAddressForChange(emailChange, baseUrl);
+               this.emailChangeBean.enqueueEmailAddressForChange(emailChange, baseUrl);
 
                // Unset all so the user is forced to re-enter it
                this.clear();
 
                // All fine
-               return "login_email_change_queued"; //NOI18N
+               return "user_login_email_change_queued"; //NOI18N
        }
 
        @Override
@@ -165,7 +171,7 @@ public class AddressbookEmailChangeWebSessionBean extends BaseAddressbookControl
        }
 
        /**
-        * Post-construction method
+        * Post-construction
         */
        @PostConstruct
        public void init () {
@@ -175,14 +181,14 @@ public class AddressbookEmailChangeWebSessionBean extends BaseAddressbookControl
                        Context context = new InitialContext();
 
                        // Try to lookup
-                       this.emailBean = (UserEmailChangeSessionBeanRemote) context.lookup("java:global/addressbook-ejb/email-change!org.mxchange.jusercore.model.email_address.EmailChangeSessionBeanRemote"); //NOI18N
-
-                       // Init list
-                       this.emailAddresses = this.emailBean.allQueuedAddresses();
+                       this.emailChangeBean = (UserEmailChangeSessionBeanRemote) context.lookup("java:global/addressbook-ejb/userEmailChange!org.mxchange.jusercore.model.email_address.EmailChangeSessionBeanRemote"); //NOI18N
                } catch (final NamingException e) {
                        // Throw again
                        throw new FaceletException(e);
                }
+
+               // Init list
+               this.emailAddresses = this.emailChangeBean.allQueuedAddresses();
        }
 
        @Override
@@ -221,7 +227,7 @@ public class AddressbookEmailChangeWebSessionBean extends BaseAddressbookControl
                }
 
                // Check EJB
-               boolean isQueued = this.emailBean.isEmailAddressEnqueued(emailAddress);
+               boolean isQueued = this.emailChangeBean.isEmailAddressEnqueued(emailAddress);
 
                // Is it there?
                if (isQueued) {
diff --git a/src/java/org/mxchange/addressbook/beans/helper/AddressbookWebRequestController.java b/src/java/org/mxchange/addressbook/beans/helper/AddressbookWebRequestController.java
deleted file mode 100644 (file)
index 5f9cb56..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (C) 2016 Roland Häder GmbH
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.beans.helper;
-
-import java.io.Serializable;
-import org.mxchange.jcontacts.contact.Contact;
-import org.mxchange.jusercore.model.user.User;
-
-/**
- * An interface for general bean helper
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public interface AddressbookWebRequestController extends Serializable {
-
-       /**
-        * Getter for user instance
-        * <p>
-        * @return User instance
-        */
-       User getUser ();
-
-       /**
-        * Setter for user instance
-        * <p>
-        * @param user User instance
-        */
-       void setUser (final User user);
-
-       /**
-        * Copies currently set user instance's data to adminUserController
-        */
-       void copyUserToController ();
-
-       /**
-        * Returns a message key depending on if this contact is a user and/or a
-        * contact. If this contact is unused, a default key is returned.
-        * <p>
-        * @param contact Contact instance to check
-        * <p>
-        * @return Message key
-        */
-       String getContactUsageMessageKey (final Contact contact);
-
-       /**
-        * Getter for contact instance
-        * <p>
-        * @return Contact instance
-        */
-       Contact getContact ();
-
-       /**
-        * Setter for contact instance
-        * <p>
-        * @param contact Contact instance
-        */
-       void setContact (final Contact contact);
-
-       /**
-        * Copies currently set contact instance's data to adminContactController
-        */
-       void copyContactToController ();
-
-}
diff --git a/src/java/org/mxchange/addressbook/beans/helper/AddressbookWebRequestHelper.java b/src/java/org/mxchange/addressbook/beans/helper/AddressbookWebRequestHelper.java
deleted file mode 100644 (file)
index 347f530..0000000
+++ /dev/null
@@ -1,223 +0,0 @@
-/*
- * Copyright (C) 2016 Roland Häder GmbH
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.beans.helper;
-
-import java.text.MessageFormat;
-import javax.annotation.PostConstruct;
-import javax.enterprise.context.RequestScoped;
-import javax.inject.Inject;
-import javax.inject.Named;
-import org.mxchange.addressbook.beans.contact.AddressbookAdminContactWebRequestController;
-import org.mxchange.addressbook.beans.phone.AddressbookAdminPhoneWebRequestController;
-import org.mxchange.addressbook.beans.user.AddressbookUserWebSessionController;
-import org.mxchange.jcontacts.contact.Contact;
-import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
-import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
-import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
-import org.mxchange.jusercore.model.user.User;
-
-/**
- * A general helper for beans
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Named ("adminHelper")
-@RequestScoped
-public class AddressbookWebRequestHelper implements AddressbookWebRequestController {
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 17_258_793_567_145_701L;
-
-       /**
-        * Administrative contact controller
-        */
-       @Inject
-       private AddressbookAdminContactWebRequestController adminContactController;
-
-       /**
-        * Administrative phone controller
-        */
-       @Inject
-       private AddressbookAdminPhoneWebRequestController adminPhoneController;
-
-       /**
-        * Contact instance
-        */
-       private Contact contact;
-
-       /**
-        * User instance
-        */
-       private User user;
-
-       /**
-        * Regular user controller
-        */
-       @Inject
-       private AddressbookUserWebSessionController userController;
-
-       /**
-        * Default constructor
-        */
-       public AddressbookWebRequestHelper () {
-       }
-
-       @Override
-       public void copyContactToController () {
-               // Validate user instance
-               if (this.getContact() == null) {
-                       // Throw NPE
-                       throw new NullPointerException("this.contact is null"); //NOI18N
-               } else if (this.getContact().getContactId() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("this.contact.contactId is null"); //NOI18N
-               } else if (this.getContact().getContactId() < 1) {
-                       // Not valid
-                       throw new IllegalStateException(MessageFormat.format("this.contact.contactId={0} is not valid.", this.getContact().getContactId())); //NOI18N
-               }
-
-               // Set all phone instances
-               this.setPhoneInstances(this.getContact());
-
-               // Set all fields: user
-               this.adminContactController.copyContactToController(this.getContact());
-       }
-
-       @Override
-       public void copyUserToController () {
-               // Validate user instance
-               if (this.getUser() == null) {
-                       // Throw NPE
-                       throw new NullPointerException("this.user is null"); //NOI18N
-               } else if (this.getUser().getUserId() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("this.user.userId is null"); //NOI18N
-               } else if (this.getUser().getUserId() < 1) {
-                       // Not valid
-                       throw new IllegalStateException(MessageFormat.format("this.user.userId={0} is not valid.", this.getUser().getUserId())); //NOI18N
-               }
-
-               // Get contact
-               Contact userContact = this.getUser().getUserContact();
-
-               // Set contact here, too. This avoids parameters that cannot auto-complete in IDEs.
-               this.setContact(userContact);
-
-               // Set all phone instances
-               this.setPhoneInstances(userContact);
-
-               // Set all fields: user
-               this.userController.setUserName(this.getUser().getUserName());
-       }
-
-       @Override
-       public Contact getContact () {
-               return this.contact;
-       }
-
-       @Override
-       public void setContact (final Contact contact) {
-               this.contact = contact;
-       }
-
-       @Override
-       public String getContactUsageMessageKey (final Contact contact) {
-               // The contact must be valid
-               if (null == contact) {
-                       // Throw NPE
-                       throw new NullPointerException("contact is null"); //NOI18N
-               } else if (contact.getContactId() == null) {
-                       // Throw again ...
-                       throw new NullPointerException("contact.contactId is null"); //NOI18N
-               } else if (contact.getContactId() < 1) {
-                       // Not valid
-                       throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
-               }
-
-               // Default key is "unused"
-               String messageKey = "CONTACT_IS_UNUSED"; //NOI18N
-
-               // Check user
-               boolean isUserContact = this.userController.isContactFound(contact);
-
-               // Check user first
-               if (isUserContact) {
-                       // Only user
-                       messageKey = "CONTACT_IS_USER"; //NOI18N
-               }
-
-               // Return message key
-               return messageKey;
-       }
-
-       @Override
-       public User getUser () {
-               return this.user;
-       }
-
-       @Override
-       public void setUser (final User user) {
-               this.user = user;
-       }
-
-       /**
-        * Post-construction method
-        */
-       @PostConstruct
-       public void init () {
-       }
-
-       /**
-        * Set's all given contact's phone instances: land-line, mobile and fax
-        * <p>
-        * @param contact Contact to set phone instances for
-        */
-       private void setPhoneInstances (final Contact contact) {
-               // The contact must be valid
-               if (null == contact) {
-                       // Throw NPE
-                       throw new NullPointerException("contact is null"); //NOI18N
-               } else if (contact.getContactId() == null) {
-                       // Throw again ...
-                       throw new NullPointerException("contact.contactId is null"); //NOI18N
-               } else if (contact.getContactId() < 1) {
-                       // Not valid
-                       throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
-               }
-
-               // Is cellphone set?
-               if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
-                       // Yes, then set it in admin controller
-                       this.adminPhoneController.setMobileNumber(contact.getContactMobileNumber());
-               }
-
-               // Is land-line set?
-               if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
-                       // Yes, then set it in admin controller
-                       this.adminPhoneController.setLandLine(contact.getContactLandLineNumber());
-               }
-
-               // Is fax set?
-               if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
-                       // Yes, then set it in admin controller
-                       this.adminPhoneController.setFax(contact.getContactFaxNumber());
-               }
-       }
-
-}
diff --git a/src/java/org/mxchange/addressbook/beans/helper/AddressbookWebRequestHelperBean.java b/src/java/org/mxchange/addressbook/beans/helper/AddressbookWebRequestHelperBean.java
new file mode 100644 (file)
index 0000000..a7aa605
--- /dev/null
@@ -0,0 +1,402 @@
+/*
+ * Copyright (C) 2016 Roland Häder GmbH
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.helper;
+
+import java.text.MessageFormat;
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.inject.Named;
+import org.mxchange.addressbook.beans.contact.AddressbookAdminContactWebRequestController;
+import org.mxchange.addressbook.beans.phone.AddressbookAdminPhoneWebRequestController;
+import org.mxchange.addressbook.beans.user.AddressbookAdminUserWebRequestController;
+import org.mxchange.addressbook.beans.user.AddressbookUserWebSessionController;
+import org.mxchange.jcontacts.contact.Contact;
+import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
+import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
+import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
+import org.mxchange.jusercore.model.user.User;
+
+/**
+ * A general helper for beans
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("adminHelper")
+@RequestScoped
+public class AddressbookWebRequestHelperBean implements AddressbookWebRequestHelperController {
+
+       /**
+        * Call-stack instance (5 may show BeanELResolver.getValue as caller)
+        */
+       private static final short THREAD_STACK = 5;
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 17_258_793_567_145_701L;
+
+       /**
+        * Administrative contact controller
+        */
+       @Inject
+       private AddressbookAdminContactWebRequestController adminContactController;
+
+       /**
+        * Administrative phone controller
+        */
+       @Inject
+       private AddressbookAdminPhoneWebRequestController adminPhoneController;
+
+       /**
+        * Administrative user controller
+        */
+       @Inject
+       private AddressbookAdminUserWebRequestController adminUserController;
+
+       /**
+        * Contact instance
+        */
+       private Contact contact;
+
+       /**
+        * Fax number
+        */
+       private DialableFaxNumber faxNumber;
+
+       /**
+        * Land-line number
+        */
+       private DialableLandLineNumber landLineNumber;
+
+       /**
+        * Mobile number
+        */
+       private DialableMobileNumber mobileNumber;
+
+       /**
+        * User instance
+        */
+       private User user;
+
+       /**
+        * Regular user controller
+        */
+       @Inject
+       private AddressbookUserWebSessionController userController;
+
+       /**
+        * Default constructor
+        */
+       public AddressbookWebRequestHelperBean () {
+               // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[3].getClassName(), Thread.currentThread().getStackTrace()[3].getMethodName());
+               // System.out.println(MessageFormat.format("{0}: Constructed, caller: {1}", this.getClass().getSimpleName(), caller));
+       }
+
+       @Override
+       public void copyContactToController () {
+               // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[THREAD_STACK].getClassName(), Thread.currentThread().getStackTrace()[THREAD_STACK].getMethodName());
+               // System.out.println(MessageFormat.format("{0}.copyContactToController: CALLED, caller: {2}", this.getClass().getSimpleName(), this.contact, caller));
+
+               // Validate contact instance
+               if (this.getContact() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("this.contact is null"); //NOI18N
+               } else if (this.getContact().getContactId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("this.contact.contactId is null"); //NOI18N
+               } else if (this.getContact().getContactId() < 1) {
+                       // Not valid
+                       throw new IllegalStateException(MessageFormat.format("this.contact.contactId={0} is not valid.", this.getContact().getContactId())); //NOI18N
+               }
+
+               // Set all phone instances
+               this.setPhoneInstances(this.getContact());
+
+               // Set all fields: user
+               this.adminContactController.copyContactToController(this.getContact());
+       }
+
+       @Override
+       public void copyFaxNumberToController () {
+               // Validate fax instance
+               if (this.getFaxNumber() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("this.faxNumber is null");
+               } else if (this.getFaxNumber().getPhoneId() == null) {
+                       // Throw again
+                       throw new NullPointerException("this.faxNumber.phoneId is null");
+               } else if (this.getFaxNumber().getPhoneId() < 1) {
+                       // Invalid id number
+                       throw new IllegalArgumentException(MessageFormat.format("this.faxNumber.phoneId={0} is not valid", this.getFaxNumber().getPhoneId()));
+               } else if (this.getFaxNumber().getPhoneAreaCode() == null) {
+                       // Throw again
+                       throw new NullPointerException("this.faxNumber.phoneAreaCode is null");
+               } else if (this.getFaxNumber().getPhoneAreaCode() < 1) {
+                       // Invalid id number
+                       throw new IllegalArgumentException(MessageFormat.format("this.faxNumber.phoneAreaCode={0} is not valid", this.getFaxNumber().getPhoneAreaCode()));
+               } else if (this.getFaxNumber().getPhoneCountry() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("this.faxNumber.phoneCountry is null");
+               } else if (this.getFaxNumber().getPhoneCountry().getCountryId() == null) {
+                       // ... throw again
+                       throw new NullPointerException("this.faxNumber.phoneCountry.countryId is null");
+               } else if (this.getFaxNumber().getPhoneCountry().getCountryId() < 1) {
+                       // Invalid id
+                       throw new IllegalArgumentException(MessageFormat.format("this.faxNumber.phoneCountry.countryId={0} is invalid", this.getFaxNumber().getPhoneCountry().getCountryId()));
+               } else if (this.getFaxNumber().getPhoneNumber() == null) {
+                       // Throw NPE again ...
+                       throw new NullPointerException("this.faxNumber.phoneNumber is null");
+               } else if (this.getFaxNumber().getPhoneNumber() < 1) {
+                       // Invalid id number
+                       throw new IllegalArgumentException(MessageFormat.format("this.faxNumber.phoneNumber={0} is not valid", this.getFaxNumber().getPhoneNumber()));
+               }
+
+               // Copy all (changeable) data fields to admin controller
+               this.adminPhoneController.setPhoneAreaCode(this.getFaxNumber().getPhoneAreaCode());
+               this.adminPhoneController.setPhoneCountry(this.getFaxNumber().getPhoneCountry());
+               this.adminPhoneController.setPhoneNumber(this.getFaxNumber().getPhoneNumber());
+       }
+
+       @Override
+       public void copyLandLineNumberToController () {
+               // Validate land-line instance
+               if (this.getLandLineNumber() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("this.landLineNumber is null");
+               } else if (this.getLandLineNumber().getPhoneId() == null) {
+                       // Throw again
+                       throw new NullPointerException("this.landLineNumber.phoneId is null");
+               } else if (this.getLandLineNumber().getPhoneId() < 1) {
+                       // Invalid id number
+                       throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber.phoneId={0} is not valid", this.getLandLineNumber().getPhoneId()));
+               } else if (this.getLandLineNumber().getPhoneAreaCode() == null) {
+                       // Throw again
+                       throw new NullPointerException("this.landLineNumber.phoneAreaCode is null");
+               } else if (this.getLandLineNumber().getPhoneAreaCode() < 1) {
+                       // Invalid id number
+                       throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber.phoneAreaCode={0} is not valid", this.getFaxNumber().getPhoneAreaCode()));
+               } else if (this.getLandLineNumber().getPhoneCountry() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("this.landLineNumber.phoneCountry is null");
+               } else if (this.getLandLineNumber().getPhoneCountry().getCountryId() == null) {
+                       // ... throw again
+                       throw new NullPointerException("this.landLineNumber.phoneCountry.countryId is null");
+               } else if (this.getLandLineNumber().getPhoneCountry().getCountryId() < 1) {
+                       // Invalid id
+                       throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber.phoneCountry.countryId={0} is invalid", this.getLandLineNumber().getPhoneCountry().getCountryId()));
+               } else if (this.getLandLineNumber().getPhoneNumber() == null) {
+                       // Throw NPE again ...
+                       throw new NullPointerException("this.landLineNumber.phoneNumber is null");
+               } else if (this.getLandLineNumber().getPhoneNumber() < 1) {
+                       // Invalid id number
+                       throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber.phoneNumber={0} is not valid", this.getLandLineNumber().getPhoneNumber()));
+               }
+
+               // Copy all (changeable) data fields to admin controller
+               this.adminPhoneController.setPhoneAreaCode(this.getLandLineNumber().getPhoneAreaCode());
+               this.adminPhoneController.setPhoneCountry(this.getLandLineNumber().getPhoneCountry());
+               this.adminPhoneController.setPhoneNumber(this.getLandLineNumber().getPhoneNumber());
+       }
+
+       @Override
+       public void copyMobileNumberToController () {
+               // Validate mobile instance
+               if (this.getMobileNumber() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("this.mobileNumber is null");
+               } else if (this.getMobileNumber().getPhoneId() == null) {
+                       // Throw again
+                       throw new NullPointerException("this.mobileNumber.phoneId is null");
+               } else if (this.getMobileNumber().getPhoneId() < 1) {
+                       // Invalid id number
+                       throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber.phoneId={0} is not valid", this.getMobileNumber().getPhoneId()));
+               } else if (this.getMobileNumber().getMobileProvider() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("this.mobileNumber.mobileProvider is null");
+               } else if (this.getMobileNumber().getMobileProvider().getProviderId() == null) {
+                       // ... throw again
+                       throw new NullPointerException("this.mobileNumber.mobileProvider.providerId is null");
+               } else if (this.getMobileNumber().getMobileProvider().getProviderId() < 1) {
+                       // Invalid id
+                       throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber.mobileProvider.providerId={0} is invalid", this.getMobileNumber().getMobileProvider().getProviderId()));
+               } else if (this.getMobileNumber().getPhoneNumber() == null) {
+                       // Throw NPE again ...
+                       throw new NullPointerException("this.mobileNumber.phoneNumber is null");
+               } else if (this.getMobileNumber().getPhoneNumber() < 1) {
+                       // Invalid id number
+                       throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber.phoneNumber={0} is not valid", this.getMobileNumber().getPhoneNumber()));
+               }
+
+               // Copy all (changeable) data fields to admin controller
+               this.adminPhoneController.setMobileProvider(this.getMobileNumber().getMobileProvider());
+               this.adminPhoneController.setPhoneNumber(this.getMobileNumber().getPhoneNumber());
+       }
+
+       @Override
+       public void copyUserToController () {
+               // Log message
+               //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyUserToController - CALLED!"); //NOI18N
+
+               // Validate user instance
+               if (this.getUser() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("this.user is null"); //NOI18N
+               } else if (this.getUser().getUserId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("this.user.userId is null"); //NOI18N
+               } else if (this.getUser().getUserId() < 1) {
+                       // Not valid
+                       throw new IllegalStateException(MessageFormat.format("this.user.userId={0} is not valid.", this.getUser().getUserId())); //NOI18N
+               }
+
+               // Get contact
+               Contact userContact = this.getUser().getUserContact();
+
+               // Set contact here, too. This avoids parameters that cannot auto-complete in IDEs.
+               this.setContact(userContact);
+
+               // Set all phone instances
+               this.setPhoneInstances(userContact);
+
+               // Set all fields: user
+               this.userController.setUserName(this.getUser().getUserName());
+               this.adminUserController.setUserName(this.getUser().getUserName());
+       }
+
+       @Override
+       public Contact getContact () {
+               // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[THREAD_STACK].getClassName(), Thread.currentThread().getStackTrace()[THREAD_STACK].getMethodName());
+               // System.out.println(MessageFormat.format("{0}: Returning this.contact={1}, caller: {2}", this.getClass().getSimpleName(), this.contact, caller));
+               return this.contact;
+       }
+
+       @Override
+       public void setContact (final Contact contact) {
+               // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[THREAD_STACK].getClassName(), Thread.currentThread().getStackTrace()[THREAD_STACK].getMethodName());
+               // System.out.println(MessageFormat.format("{0}: Setting contact={1}, previous: {2}, caller: {3}", this.getClass().getSimpleName(), contact, this.contact, caller));
+               this.contact = contact;
+       }
+
+       @Override
+       public String getContactUsageMessageKey (final Contact contact) {
+               // The contact must be valid
+               if (null == contact) {
+                       // Throw NPE
+                       throw new NullPointerException("contact is null"); //NOI18N
+               } else if (contact.getContactId() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("contact.contactId is null"); //NOI18N
+               } else if (contact.getContactId() < 1) {
+                       // Not valid
+                       throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
+               }
+
+               // Default key is "unused"
+               String messageKey = "CONTACT_IS_UNUSED"; //NOI18N
+
+               // Check user/recruiter
+               boolean isUserContact = this.userController.isContactFound(contact);
+
+               // Check user first
+               if (isUserContact) {
+                       // Only user
+                       messageKey = "CONTACT_IS_USER"; //NOI18N
+               }
+
+               // Return message key
+               return messageKey;
+       }
+
+       @Override
+       public DialableFaxNumber getFaxNumber () {
+               return this.faxNumber;
+       }
+
+       @Override
+       public void setFaxNumber (final DialableFaxNumber faxNumber) {
+               this.faxNumber = faxNumber;
+       }
+
+       @Override
+       public DialableLandLineNumber getLandLineNumber () {
+               return this.landLineNumber;
+       }
+
+       @Override
+       public void setLandLineNumber (final DialableLandLineNumber landLineNumber) {
+               this.landLineNumber = landLineNumber;
+       }
+
+       @Override
+       public DialableMobileNumber getMobileNumber () {
+               return this.mobileNumber;
+       }
+
+       @Override
+       public void setMobileNumber (final DialableMobileNumber mobileNumber) {
+               this.mobileNumber = mobileNumber;
+       }
+
+       @Override
+       public User getUser () {
+               return this.user;
+       }
+
+       @Override
+       public void setUser (final User user) {
+               this.user = user;
+       }
+
+       /**
+        * Set's all given contact's phone instances: land-line, mobile and
+        * faxNumber
+        * <p>
+        * @param contact Contact to set phone instances for
+        */
+       private void setPhoneInstances (final Contact contact) {
+               // The contact must be valid
+               if (null == contact) {
+                       // Throw NPE
+                       throw new NullPointerException("contact is null"); //NOI18N
+               } else if (contact.getContactId() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("contact.contactId is null"); //NOI18N
+               } else if (contact.getContactId() < 1) {
+                       // Not valid
+                       throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
+               }
+
+               // Is mobile set?
+               if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
+                       // Yes, then set it in admin controller
+                       this.setMobileNumber(contact.getContactMobileNumber());
+               }
+
+               // Is land-line set?
+               if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
+                       // Yes, then set it in admin controller
+                       this.setLandLineNumber(contact.getContactLandLineNumber());
+               }
+
+               // Is faxNumber set?
+               if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
+                       // Yes, then set it in admin controller
+                       this.setFaxNumber(contact.getContactFaxNumber());
+               }
+       }
+
+}
diff --git a/src/java/org/mxchange/addressbook/beans/helper/AddressbookWebRequestHelperController.java b/src/java/org/mxchange/addressbook/beans/helper/AddressbookWebRequestHelperController.java
new file mode 100644 (file)
index 0000000..9c57506
--- /dev/null
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2016 Roland Häder GmbH
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.helper;
+
+import java.io.Serializable;
+import org.mxchange.jcontacts.contact.Contact;
+import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
+import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
+import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
+import org.mxchange.jusercore.model.user.User;
+
+/**
+ * An interface for general bean helper
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface AddressbookWebRequestHelperController extends Serializable {
+
+       /**
+        * Copies currently set fax number's data to admin phone controller
+        */
+       void copyFaxNumberToController ();
+
+       /**
+        * Copies currently set land-line number's data to admin phone controller
+        */
+       void copyLandLineNumberToController ();
+
+       /**
+        * Copies currently set mobile number's data to admin phone controller
+        */
+       void copyMobileNumberToController ();
+
+       /**
+        * Copies currently set contact instance's data to adminContactController
+        */
+       void copyContactToController ();
+
+       /**
+        * Copies currently set user instance's data to adminUserController
+        */
+       void copyUserToController ();
+
+       /**
+        * Returns a message key depending on if this contact is a user and/or a
+        * contact. If this contact is unused, a default key is returned.
+        * <p>
+        * @param contact Contact instance to check
+        * <p>
+        * @return Message key
+        */
+       String getContactUsageMessageKey (final Contact contact);
+
+       /**
+        * Getter for contact instance
+        * <p>
+        * @return Contact instance
+        */
+       Contact getContact ();
+
+       /**
+        * Setter for contact instance
+        * <p>
+        * @param contact Contact instance
+        */
+       void setContact (final Contact contact);
+
+       /**
+        * Getter for user instance
+        * <p>
+        * @return User instance
+        */
+       User getUser ();
+
+       /**
+        * Setter for user instance
+        * <p>
+        * @param user User instance
+        */
+       void setUser (final User user);
+
+       /**
+        * Getter for dialable mobile number
+        * <p>
+        * @return Dialable mobile number
+        */
+       DialableMobileNumber getMobileNumber ();
+
+       /**
+        * Setter for dialable mobile number
+        * <p>
+        * @param mobileNumber Dialable mobile number
+        */
+       void setMobileNumber (final DialableMobileNumber mobileNumber);
+
+       /**
+        * Getter for dialable land-line number
+        * <p>
+        * @return Dialable land-line number
+        */
+       DialableLandLineNumber getLandLineNumber ();
+
+       /**
+        * Setter for dialable land-line number
+        * <p>
+        * @param landLine Dialable land-line number
+        */
+       void setLandLineNumber (final DialableLandLineNumber landLine);
+
+       /**
+        * Getter for dialable fax number
+        * <p>
+        * @return Dialable fax number
+        */
+       DialableFaxNumber getFaxNumber ();
+
+       /**
+        * Setter for dialable fax number
+        * <p>
+        * @param faxNumber Dialable fax number
+        */
+       void setFaxNumber (final DialableFaxNumber faxNumber);
+
+}
index d2d405bb1d1cb5ccab1bfe894720b0c5da824915..0a1a8cbf77e91e6df71b3c77405b6eb60c7803dc 100644 (file)
@@ -65,12 +65,12 @@ public class AddressbookUserLoginWebSessionBean extends BaseAddressbookControlle
        /**
         * Path name for guest base template
         */
-       private static final String GUEST_BASE_TEMPLATE_NAME = "guest/guest"; //NOI18N
+       private static final String GUEST_BASE_TEMPLATE_NAME = "guest/guest";
 
        /**
         * Path name for logged-in user base template
         */
-       private static final String USER_BASE_TEMPLATE_NAME = "login/user/user"; //NOI18N
+       private static final String USER_BASE_TEMPLATE_NAME = "login/user/user";
 
        /**
         * Serial number
@@ -84,14 +84,16 @@ public class AddressbookUserLoginWebSessionBean extends BaseAddressbookControlle
        private String baseTemplatePathName;
 
        /**
-        * Current password
+        * Logged-in user instance
         */
-       private String currentPassword;
+       private User loggedInUser;
 
        /**
-        * Logged-in user instance
+        * Event fired when user has logged in
         */
-       private User loggedInUser;
+       @Inject
+       @Any
+       private Event<ObservableUserLoggedInEvent> loginEvent;
 
        /**
         * User controller
@@ -99,13 +101,18 @@ public class AddressbookUserLoginWebSessionBean extends BaseAddressbookControlle
        @Inject
        private AddressbookUserWebSessionController userController;
 
+       /**
+        * Current password
+        */
+       private String userCurrentPassword;
+
        /**
         * Flag whether the user has logged-in, set only from inside
         */
        private boolean userLoggedIn;
 
        /**
-        * EJB for user-login
+        * Remote register session bean
         */
        private UserLoginSessionBeanRemote userLoginBean;
 
@@ -213,14 +220,20 @@ public class AddressbookUserLoginWebSessionBean extends BaseAddressbookControlle
                        this.clear();
 
                        // All fine
-                       return "login"; //NOI18N
-               } catch (final UserNotFoundException | UserStatusLockedException | UserStatusUnconfirmedException ex) {
+                       return "login_user"; //NOI18N
+               } catch (final UserNotFoundException ex) {
                        // Show JSF message
-                       this.showFacesMessage("form_user_login:userName", ex); //NOI18N
+                       this.showFacesMessage("form_user_login:userName", "ERROR_USER_NOT_FOUND"); //NOI18N
+                       return ""; //NOI18N
+               } catch (final UserStatusLockedException ex) {
+                       this.showFacesMessage("form_user_login:userName", "ERROR_USER_STATUS_LOCKED"); //NOI18N
+                       return ""; //NOI18N
+               } catch (final UserStatusUnconfirmedException ex) {
+                       this.showFacesMessage("form_user_login:userName", "ERROR_USER_STATUS_UNCONFIRMED"); //NOI18N
                        return ""; //NOI18N
                } catch (final UserPasswordMismatchException ex) {
                        // Show JSF message
-                       this.showFacesMessage("form_user_login:userPassword", ex); //NOI18N
+                       this.showFacesMessage("form_user_login:userPassword", "ERROR_USER_PASSWORD_MISMATCH"); //NOI18N
                        return ""; //NOI18N
                }
        }
@@ -264,23 +277,23 @@ public class AddressbookUserLoginWebSessionBean extends BaseAddressbookControlle
        }
 
        @Override
-       public String getCurrentPassword () {
-               return this.currentPassword;
+       public User getLoggedInUser () {
+               return this.loggedInUser;
        }
 
        @Override
-       public void setCurrentPassword (final String currentPassword) {
-               this.currentPassword = currentPassword;
+       public void setLoggedInUser (final User loggedInUser) {
+               this.loggedInUser = loggedInUser;
        }
 
        @Override
-       public User getLoggedInUser () {
-               return this.loggedInUser;
+       public String getUserCurrentPassword () {
+               return this.userCurrentPassword;
        }
 
        @Override
-       public void setLoggedInUser (final User loggedInUser) {
-               this.loggedInUser = loggedInUser;
+       public void setUserCurrentPassword (final String userCurrentPassword) {
+               this.userCurrentPassword = userCurrentPassword;
        }
 
        @Override
@@ -291,16 +304,16 @@ public class AddressbookUserLoginWebSessionBean extends BaseAddressbookControlle
        @Override
        public boolean ifCurrentPasswordMatches () {
                // The current password must be set and not empty
-               if (this.getCurrentPassword() == null) {
+               if (this.getUserCurrentPassword() == null) {
                        // Is not set
-                       throw new NullPointerException("this.currentPassword is null"); //NOI18N
-               } else if (this.getCurrentPassword().isEmpty()) {
+                       throw new NullPointerException("this.userCurrentPassword is null"); //NOI18N
+               } else if (this.getUserCurrentPassword().isEmpty()) {
                        // Is set empty
-                       throw new IllegalStateException("this.currentPassword is empty."); //NOI18N
+                       throw new IllegalStateException("this.userCurrentPassword is empty."); //NOI18N
                }
 
                // Create "container"
-               LoginContainer container = new UserLoginContainer(this.getLoggedInUser(), this.getCurrentPassword());
+               LoginContainer container = new UserLoginContainer(this.getLoggedInUser(), this.getUserCurrentPassword());
 
                // Now check if it matches
                return UserUtils.ifPasswordMatches(container, this.getLoggedInUser());
@@ -308,7 +321,7 @@ public class AddressbookUserLoginWebSessionBean extends BaseAddressbookControlle
 
        @Override
        public boolean ifUserMustChangePassword () {
-               return (this.isUserLoggedIn() && this.getLoggedInUser().getUserMustChangePassword());
+               return ((this.isUserLoggedIn()) && (Objects.equals(this.getLoggedInUser().getUserMustChangePassword(), Boolean.TRUE)));
        }
 
        /**
@@ -325,6 +338,9 @@ public class AddressbookUserLoginWebSessionBean extends BaseAddressbookControlle
 
                        // Also find this
                        this.userPasswordHistoryBean = (UserPasswordHistorySessionBeanRemote) context.lookup("java:global/addressbook-ejb/userPasswordHistory!org.mxchange.jusercore.model.user.password_history.UserPasswordHistorySessionBeanRemote"); //NOI18N
+
+                       // Defaul template is guest
+                       this.baseTemplatePathName = GUEST_BASE_TEMPLATE_NAME;
                } catch (final NamingException ex) {
                        // Continue to throw
                        throw new FaceletException(ex);
@@ -340,7 +356,7 @@ public class AddressbookUserLoginWebSessionBean extends BaseAddressbookControlle
                }
 
                // Check logged-in first, then invisibility
-               return this.getLoggedInUser().getUserProfileMode().equals(ProfileMode.INVISIBLE);
+               return Objects.equals(this.getLoggedInUser().getUserProfileMode(), ProfileMode.INVISIBLE);
        }
 
        @Override
@@ -374,6 +390,7 @@ public class AddressbookUserLoginWebSessionBean extends BaseAddressbookControlle
 
        @Override
        public boolean isUserLoggedIn () {
+               // Compare instance
                this.userLoggedIn = ((this.getLoggedInUser() instanceof User) && (Objects.equals(this.getLoggedInUser().getUserAccountStatus(), UserAccountStatus.CONFIRMED)));
 
                // Return it
@@ -385,7 +402,7 @@ public class AddressbookUserLoginWebSessionBean extends BaseAddressbookControlle
         */
        private void clear () {
                // Clear all fields
-               this.setCurrentPassword(null);
+               this.setUserCurrentPassword(null);
        }
 
        /**
index fdffbe9cdcb92a87a2e5a1efe545bb5293ec51a6..04276dac3921b3eb385b3cad0740ee704f473967 100644 (file)
@@ -40,14 +40,14 @@ public interface AddressbookUserLoginWebSessionController extends Serializable {
        boolean isPasswordInHistory (final String userPassword);
 
        /**
-        * Getter for template type
+        * Getter for base template type
         * <p>
         * @return Template type
         */
        String getBaseTemplatePathName ();
 
        /**
-        * Setter for template type
+        * Setter for base template type
         * <p>
         * @param baseTemplatePathName Template type
         */
@@ -113,16 +113,16 @@ public interface AddressbookUserLoginWebSessionController extends Serializable {
        /**
         * Setter for current password (clear text)
         * <p>
-        * @param currentPassword Current password
+        * @param userCurrentPassword Current password
         */
-       void setCurrentPassword (final String currentPassword);
+       void setUserCurrentPassword (final String userCurrentPassword);
 
        /**
         * Getter for current password (clear text)
         * <p>
         * @return Current password
         */
-       String getCurrentPassword ();
+       String getUserCurrentPassword ();
 
        /**
         * Checks whether the (previously entered) current password matches with
index 2d3811ac42748aad415d25c547ad7e03189c264a..ee93f4880a648a02505eb8bc970522d0a9713a86 100644 (file)
  */
 package org.mxchange.addressbook.beans.phone;
 
+import java.text.MessageFormat;
+import java.util.List;
+import java.util.Objects;
 import javax.annotation.PostConstruct;
 import javax.enterprise.context.RequestScoped;
+import javax.enterprise.event.Event;
+import javax.enterprise.inject.Any;
 import javax.faces.view.facelets.FaceletException;
+import javax.inject.Inject;
 import javax.inject.Named;
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import org.mxchange.addressbook.beans.BaseAddressbookController;
-import org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote;
+import org.mxchange.addressbook.beans.helper.AddressbookWebRequestHelperController;
+import org.mxchange.jcountry.data.Country;
+import org.mxchange.jphone.events.fax.deleted.AdminDeletedFaxNumberEvent;
+import org.mxchange.jphone.events.fax.deleted.AdminFaxNumberDeletedEvent;
+import org.mxchange.jphone.events.fax.removed.AdminFaxNumberRemovedFromListEvent;
+import org.mxchange.jphone.events.fax.removed.AdminRemoveFaxNumberFromListEvent;
+import org.mxchange.jphone.events.fax.updated.AdminFaxNumberUpdatedEvent;
+import org.mxchange.jphone.events.fax.updated.AdminUpdatedFaxNumberEvent;
+import org.mxchange.jphone.events.landline.deleted.AdminDeletedLandLineNumberEvent;
+import org.mxchange.jphone.events.landline.deleted.AdminLandLineNumberDeletedEvent;
+import org.mxchange.jphone.events.landline.removed.AdminLandLineNumberRemovedFromListEvent;
+import org.mxchange.jphone.events.landline.removed.AdminRemoveLandLineNumberFromListEvent;
+import org.mxchange.jphone.events.landline.updated.AdminLandLineNumberUpdatedEvent;
+import org.mxchange.jphone.events.landline.updated.AdminUpdatedLandLineNumberEvent;
+import org.mxchange.jphone.events.mobile.deleted.AdminDeletedMobileNumberEvent;
+import org.mxchange.jphone.events.mobile.deleted.AdminMobileNumberDeletedEvent;
+import org.mxchange.jphone.events.mobile.remove.AdminMobileNumberRemovedFromListEvent;
+import org.mxchange.jphone.events.mobile.remove.AdminRemoveMobileNumberFromListEvent;
+import org.mxchange.jphone.events.mobile.updated.AdminMobileNumberUpdatedEvent;
+import org.mxchange.jphone.events.mobile.updated.AdminUpdatedMobileNumberEvent;
 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
+import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
+import org.mxchange.jphone.phonenumbers.phone.AdminPhoneSessionBeanRemote;
 
 /**
  * Administrative bean (controller) for phone numbers
@@ -38,6 +65,11 @@ import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
 @RequestScoped
 public class AddressbookAdminPhoneWebRequestBean extends BaseAddressbookController implements AddressbookAdminPhoneWebRequestController {
 
+       /**
+        * Call-stack position
+        */
+       private static final short THREAD_STACK = 5;
+
        /**
         * Serial number
         */
@@ -46,57 +78,549 @@ public class AddressbookAdminPhoneWebRequestBean extends BaseAddressbookControll
        /**
         * Remote EJB for phone number (administrative)
         */
-       private AdminContactsPhoneSessionBeanRemote adminPhoneBean;
+       private AdminPhoneSessionBeanRemote adminPhoneBean;
+
+       /**
+        * Bean helper
+        */
+       @Inject
+       private AddressbookWebRequestHelperController beanHelper;
+
+       /**
+        *  fax number
+        */
+       private DialableFaxNumber choosenFaxNumber;
+
+       /**
+        *  land-line number
+        */
+       private DialableLandLineNumber choosenLandLineNumber;
+
+       /**
+        *  mobile number
+        */
+       private DialableMobileNumber choosenMobileNumber;
+
+       /**
+        * Event being fired when an administrator has deleted fax number
+        */
+       @Inject
+       @Any
+       private Event<AdminDeletedFaxNumberEvent> faxNumberDeletedEvent;
+
+       /**
+        * Event being fired when an administrator has updated fax number
+        */
+       @Inject
+       @Any
+       private Event<AdminUpdatedFaxNumberEvent> faxNumberUpdatedEvent;
+
+       /**
+        * Event being fired when an administrator has deleted land-line number
+        */
+       @Inject
+       @Any
+       private Event<AdminDeletedLandLineNumberEvent> landLineNumberDeletedEvent;
+
+       /**
+        * Event being fired when an administrator has updated fax number
+        */
+       @Inject
+       @Any
+       private Event<AdminUpdatedLandLineNumberEvent> landLineNumberUpdatedEvent;
+
+       /**
+        * Event being fired when an administrator has deleted mobile number
+        */
+       @Inject
+       @Any
+       private Event<AdminDeletedMobileNumberEvent> mobileNumberDeletedEvent;
+
+       /**
+        * Event being fired when an administrator has updated land-line number
+        */
+       @Inject
+       @Any
+       private Event<AdminUpdatedMobileNumberEvent> mobileNumberUpdatedEvent;
+
+       /**
+        * Mobile provider
+        */
+       private MobileProvider mobileProvider;
 
        /**
-        * Fax number
+        * Area code (city dial prefix)
         */
-       private DialableFaxNumber fax;
+       private Integer phoneAreaCode;
 
        /**
-        * Land-line number
+        * Generic hone controller
         */
-       private DialableLandLineNumber landLine;
+       @Inject
+       private AddressbookPhoneWebApplicationController phoneController;
 
        /**
-        * Cell phone number
+        * Country (for dial prefix)
         */
-       private DialableMobileNumber mobileNumber;
+       private Country phoneCountry;
+
+       /**
+        * Phone number
+        */
+       private Long phoneNumber;
+
+       /**
+        * Event being fired when a list of all unsed fax numbers is being created.
+        */
+       @Inject
+       @Any
+       private Event<AdminRemoveFaxNumberFromListEvent> removeLinkedFaxNumbersEvent;
+
+       /**
+        * Event being fired when a list of all unsed land-line numbers is being
+        * created.
+        */
+       @Inject
+       @Any
+       private Event<AdminRemoveLandLineNumberFromListEvent> removeLinkedLandLineNumbersEvent;
+
+       /**
+        * Event being fired when a list of all unsed mobile numbers is being
+        * created.
+        */
+       @Inject
+       @Any
+       private Event<AdminRemoveMobileNumberFromListEvent> removeLinkedMobileNumbersEvent;
 
        /**
         * Default constructor
         */
        public AddressbookAdminPhoneWebRequestBean () {
+               // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[3].getClassName(), Thread.currentThread().getStackTrace()[3].getMethodName());
+               // System.out.println(MessageFormat.format("{0}: Constructed, caller: {1}", this.getClass().getSimpleName(), caller));
        }
 
        @Override
-       public DialableFaxNumber getFax () {
-               return this.fax;
+       public List<DialableFaxNumber> allNonLinkedFaxNumbers () {
+               // Get list of all mobile numbers
+               List<DialableFaxNumber> list = this.phoneController.allFaxNumbers();
+
+               // Visit all controllers to reduce the list
+               this.removeLinkedFaxNumbersEvent.fire(new AdminFaxNumberRemovedFromListEvent(list));
+
+               // Return it
+               return list;
        }
 
        @Override
-       public void setFax (final DialableFaxNumber fax) {
-               this.fax = fax;
+       public List<DialableLandLineNumber> allNonLinkedLandLineNumbers () {
+               // Get list of all mobile numbers
+               List<DialableLandLineNumber> list = this.phoneController.allLandLineNumbers();
+
+               // Visit all controllers to reduce the list
+               this.removeLinkedLandLineNumbersEvent.fire(new AdminLandLineNumberRemovedFromListEvent(list));
+
+               // Return it
+               return list;
        }
 
        @Override
-       public DialableLandLineNumber getLandLine () {
-               return this.landLine;
+       public List<DialableMobileNumber> allNonLinkedMobileNumbers () {
+               // Get list of all mobile numbers
+               List<DialableMobileNumber> list = this.phoneController.allMobileNumbers();
+
+               // Visit all controllers to reduce the list
+               this.removeLinkedMobileNumbersEvent.fire(new AdminMobileNumberRemovedFromListEvent(list));
+
+               // Return it
+               return list;
        }
 
        @Override
-       public void setLandLine (final DialableLandLineNumber landLine) {
-               this.landLine = landLine;
+       public String deleteFaxData (final DialableFaxNumber faxNumber) {
+               // Is all data set
+               if (faxNumber == null) {
+                       // Not set, throw NPE
+                       throw new NullPointerException("faxNumber is null"); //NOI18N
+               } else if (faxNumber.getPhoneId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N
+               } else if (faxNumber.getPhoneId() < 1) {
+                       // Invalid number
+                       throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid", faxNumber.getPhoneId())); //NOI18N
+               } else if (faxNumber.getPhoneCountry() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("faxNumber.phoneCountry is null"); //NOI18N
+               } else if (faxNumber.getPhoneCountry().getCountryId() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("faxNumber.phoneCountry.countryId is null"); //NOI18N
+               } else if (faxNumber.getPhoneCountry().getCountryId() < 1) {
+                       // Throw NPE
+                       throw new NullPointerException(MessageFormat.format("faxNumber.phoneCountry.countryId={0} is not valid", faxNumber.getPhoneCountry().getCountryId())); //NOI18N
+               } else if (faxNumber.getPhoneAreaCode() == null) {
+                       // ... throw again
+                       throw new NullPointerException("faxNumber.phoneAreaCode is null"); //NOI18N
+               } else if (faxNumber.getPhoneAreaCode() < 1) {
+                       // Id not valid
+                       throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneAreaCode={0} is not valid.", faxNumber.getPhoneAreaCode())); //NOI18N
+               } else if (faxNumber.getPhoneNumber() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("faxNumber.phoneNumber is null"); //NOI18N
+               } else if (faxNumber.getPhoneNumber() < 1) {
+                       // Throw NPE again
+                       throw new NullPointerException(MessageFormat.format("faxNumber.phoneNumber={0} is not valid.", faxNumber.getPhoneNumber())); //NOI18N
+               }
+
+               // Call EJB
+               this.adminPhoneBean.deleteFaxData(faxNumber);
+
+               // Fire event
+               this.faxNumberDeletedEvent.fire(new AdminFaxNumberDeletedEvent(faxNumber));
+
+               // All fine, redirect
+               return "admin_list_fax"; //NOI18N
+       }
+
+       @Override
+       public String deleteLandLineData (final DialableLandLineNumber landLineNumber) {
+               // Is all data set
+               if (landLineNumber == null) {
+                       // Not set, throw NPE
+                       throw new NullPointerException("landLineNumber is null"); //NOI18N
+               } else if (landLineNumber.getPhoneId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
+               } else if (landLineNumber.getPhoneId() < 1) {
+                       // Invalid number
+                       throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", landLineNumber.getPhoneId())); //NOI18N
+               } else if (landLineNumber.getPhoneCountry() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("landLineNumber.phoneCountry is null"); //NOI18N
+               } else if (landLineNumber.getPhoneCountry().getCountryId() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("landLineNumber.phoneCountry.countryId is null"); //NOI18N
+               } else if (landLineNumber.getPhoneCountry().getCountryId() < 1) {
+                       // Throw NPE
+                       throw new NullPointerException(MessageFormat.format("landLineNumber.phoneCountry.countryId={0} is not valid", landLineNumber.getPhoneCountry().getCountryId())); //NOI18N
+               } else if (landLineNumber.getPhoneAreaCode() == null) {
+                       // ... throw again
+                       throw new NullPointerException("landLineNumber.phoneAreaCode is null"); //NOI18N
+               } else if (landLineNumber.getPhoneAreaCode() < 1) {
+                       // Id not valid
+                       throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneAreaCode={0} is not valid.", landLineNumber.getPhoneAreaCode())); //NOI18N
+               } else if (landLineNumber.getPhoneNumber() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("landLineNumber.phoneNumber is null"); //NOI18N
+               } else if (landLineNumber.getPhoneNumber() < 1) {
+                       // Throw NPE again
+                       throw new NullPointerException(MessageFormat.format("landLineNumber.phoneNumber={0} is not valid.", landLineNumber.getPhoneNumber())); //NOI18N
+               }
+
+               // Call EJB
+               this.adminPhoneBean.deleteLandLineData(landLineNumber);
+
+               // Fire event
+               this.landLineNumberDeletedEvent.fire(new AdminLandLineNumberDeletedEvent(landLineNumber));
+
+               // All fine, redirect
+               return "admin_list_landline"; //NOI18N
+       }
+
+       @Override
+       public String deleteMobileData (final DialableMobileNumber mobileNumber) {
+               // Is all data set
+               if (mobileNumber == null) {
+                       // Not set, throw NPE
+                       throw new NullPointerException("mobileNumber is null"); //NOI18N
+               } else if (mobileNumber.getPhoneId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N
+               } else if (mobileNumber.getPhoneId() < 1) {
+                       // Invalid number
+                       throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", mobileNumber.getPhoneId())); //NOI18N
+               } else if (mobileNumber.getMobileProvider() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("mobileNumber.mobileProvider is null"); //NOI18N
+               } else if (mobileNumber.getMobileProvider().getProviderId() == null) {
+                       // ... throw again
+                       throw new NullPointerException("mobileNumber.mobileProvider.providerId is null"); //NOI18N
+               } else if (mobileNumber.getMobileProvider().getProviderId() < 1) {
+                       // Id not valid
+                       throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileProvider.providerId={0} is not valid.", mobileNumber.getMobileProvider().getProviderId())); //NOI18N
+               } else if (mobileNumber.getPhoneNumber() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("mobileNumber.phoneNumber is null"); //NOI18N
+               } else if (mobileNumber.getPhoneNumber() < 1) {
+                       // Throw NPE again
+                       throw new NullPointerException(MessageFormat.format("mobileNumber.phoneNumber={0} is not valid.", mobileNumber.getPhoneNumber())); //NOI18N
+               }
+
+               // Call EJB
+               this.adminPhoneBean.deleteMobileData(mobileNumber);
+
+               // Fire event
+               this.mobileNumberDeletedEvent.fire(new AdminMobileNumberDeletedEvent(mobileNumber));
+
+               // All fine, redirect
+               return "admin_list_mobile"; //NOI18N
+       }
+
+       @Override
+       public String editFaxData (final DialableFaxNumber faxNumber) {
+               // Is all data set
+               if (faxNumber == null) {
+                       // Not set, throw NPE
+                       throw new NullPointerException("faxNumber is null"); //NOI18N
+               } else if (faxNumber.getPhoneId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N
+               } else if (faxNumber.getPhoneId() < 1) {
+                       // Invalid number
+                       throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid", faxNumber.getPhoneId())); //NOI18N
+               } else if (faxNumber.getPhoneCountry() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("faxNumber.phoneCountry is null"); //NOI18N
+               } else if (faxNumber.getPhoneCountry().getCountryId() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("faxNumber.phoneCountry.countryId is null"); //NOI18N
+               } else if (faxNumber.getPhoneCountry().getCountryId() < 1) {
+                       // Throw NPE
+                       throw new NullPointerException(MessageFormat.format("faxNumber.phoneCountry.countryId={0} is not valid", faxNumber.getPhoneCountry().getCountryId())); //NOI18N
+               } else if (faxNumber.getPhoneAreaCode() == null) {
+                       // ... throw again
+                       throw new NullPointerException("faxNumber.phoneAreaCode is null"); //NOI18N
+               } else if (faxNumber.getPhoneAreaCode() < 1) {
+                       // Id not valid
+                       throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneAreaCode={0} is not valid.", faxNumber.getPhoneAreaCode())); //NOI18N
+               } else if (faxNumber.getPhoneNumber() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("faxNumber.phoneNumber is null"); //NOI18N
+               } else if (faxNumber.getPhoneNumber() < 1) {
+                       // Throw NPE again
+                       throw new NullPointerException(MessageFormat.format("faxNumber.phoneNumber={0} is not valid.", faxNumber.getPhoneNumber())); //NOI18N
+               }
+
+               // Is the mobile provider and number the same?
+               if ((Objects.equals(this.getPhoneCountry(), faxNumber.getPhoneCountry())) && (Objects.equals(this.getPhoneAreaCode(), faxNumber.getPhoneAreaCode())) && (Objects.equals(this.getPhoneNumber(), faxNumber.getPhoneNumber()))) {
+                       // Show message
+                       this.showFacesMessage("form_edit_fax:faxNumber", "ERROR_ADMIN_NO_CHANGE_ENTERED"); //NOI18N
+
+                       // No difference in both together, no need to edit
+                       return ""; //NOI18N
+               }
+
+               // Set all data
+               faxNumber.setPhoneCountry(this.getPhoneCountry());
+               faxNumber.setPhoneAreaCode(this.getPhoneAreaCode());
+               faxNumber.setPhoneNumber(this.getPhoneNumber());
+
+               // Send to bean
+               DialableFaxNumber updatedNumber = this.adminPhoneBean.updateFaxData(faxNumber);
+
+               // Fire event
+               this.faxNumberUpdatedEvent.fire(new AdminFaxNumberUpdatedEvent(updatedNumber));
+
+               // All fine, redirect
+               return "admin_show_fax"; //NOI18N
+       }
+
+       @Override
+       public String editLandLineData (final DialableLandLineNumber landLineNumber) {
+               // Is all data set
+               if (landLineNumber == null) {
+                       // Not set, throw NPE
+                       throw new NullPointerException("landLineNumber is null"); //NOI18N
+               } else if (landLineNumber.getPhoneId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
+               } else if (landLineNumber.getPhoneId() < 1) {
+                       // Invalid number
+                       throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", landLineNumber.getPhoneId())); //NOI18N
+               } else if (landLineNumber.getPhoneCountry() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("landLineNumber.phoneCountry is null"); //NOI18N
+               } else if (landLineNumber.getPhoneCountry().getCountryId() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("landLineNumber.phoneCountry.countryId is null"); //NOI18N
+               } else if (landLineNumber.getPhoneCountry().getCountryId() < 1) {
+                       // Throw NPE
+                       throw new NullPointerException(MessageFormat.format("landLineNumber.phoneCountry.countryId={0} is not valid", landLineNumber.getPhoneCountry().getCountryId())); //NOI18N
+               } else if (landLineNumber.getPhoneAreaCode() == null) {
+                       // ... throw again
+                       throw new NullPointerException("landLineNumber.phoneAreaCode is null"); //NOI18N
+               } else if (landLineNumber.getPhoneAreaCode() < 1) {
+                       // Id not valid
+                       throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneAreaCode={0} is not valid.", landLineNumber.getPhoneAreaCode())); //NOI18N
+               } else if (landLineNumber.getPhoneNumber() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("landLineNumber.phoneNumber is null"); //NOI18N
+               } else if (landLineNumber.getPhoneNumber() < 1) {
+                       // Throw NPE again
+                       throw new NullPointerException(MessageFormat.format("landLineNumber.phoneNumber={0} is not valid.", landLineNumber.getPhoneNumber())); //NOI18N
+               }
+
+               // Is the mobile provider and number the same?
+               if ((Objects.equals(this.getPhoneCountry(), landLineNumber.getPhoneCountry())) && (Objects.equals(this.getPhoneAreaCode(), landLineNumber.getPhoneAreaCode())) && (Objects.equals(this.getPhoneNumber(), landLineNumber.getPhoneNumber()))) {
+                       // Show message
+                       this.showFacesMessage("form_edit_landline:landLineNumber", "ERROR_ADMIN_NO_CHANGE_ENTERED"); //NOI18N
+
+                       // No difference in both together, no need to edit
+                       return ""; //NOI18N
+               }
+
+               // Set all data
+               landLineNumber.setPhoneCountry(this.getPhoneCountry());
+               landLineNumber.setPhoneAreaCode(this.getPhoneAreaCode());
+               landLineNumber.setPhoneNumber(this.getPhoneNumber());
+
+               // Send to bean
+               DialableLandLineNumber updatedNumber = this.adminPhoneBean.updateLandLineData(landLineNumber);
+
+               // Fire event
+               this.landLineNumberUpdatedEvent.fire(new AdminLandLineNumberUpdatedEvent(updatedNumber));
+
+               // All fine, redirect
+               return "admin_show_landline"; //NOI18N
+       }
+
+       @Override
+       public String editMobileData (final DialableMobileNumber mobileNumber) {
+               // Is all data set
+               if (mobileNumber == null) {
+                       // Not set, throw NPE
+                       throw new NullPointerException("mobileNumber is null"); //NOI18N
+               } else if (mobileNumber.getPhoneId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N
+               } else if (mobileNumber.getPhoneId() < 1) {
+                       // Invalid number
+                       throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", mobileNumber.getPhoneId())); //NOI18N
+               } else if (mobileNumber.getMobileProvider() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("mobileNumber.mobileProvider is null"); //NOI18N
+               } else if (mobileNumber.getMobileProvider().getProviderId() == null) {
+                       // ... throw again
+                       throw new NullPointerException("mobileNumber.mobileProvider.providerId is null"); //NOI18N
+               } else if (mobileNumber.getMobileProvider().getProviderId() < 1) {
+                       // Id not valid
+                       throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileProvider.providerId={0} is not valid.", mobileNumber.getMobileProvider().getProviderId())); //NOI18N
+               } else if (mobileNumber.getPhoneNumber() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("mobileNumber.phoneNumber is null"); //NOI18N
+               } else if (mobileNumber.getPhoneNumber() < 1) {
+                       // Throw NPE again
+                       throw new NullPointerException(MessageFormat.format("mobileNumber.phoneNumber={0} is not valid.", mobileNumber.getPhoneNumber())); //NOI18N
+               } else if (this.getMobileProvider() == null) {
+                       // Not provided
+                       this.showFacesMessage("form_edit_mobile:mobileProvider", "ERROR_ADMIN_NO_MOBILE_PROVIDER_SELECTED"); //NOI18N
+                       return ""; //NOI18N
+               } else if (this.getMobileProvider().getProviderId() == null) {
+                       // Throw NPE again ...
+                       throw new NullPointerException("this.mobileProvider.providerId is null"); //NOI18N
+               } else if (this.getMobileProvider().getProviderId() < 0) {
+                       // Invalid id number
+                       throw new IllegalArgumentException(MessageFormat.format("this.mobileProvider.providerId={0} is not valid.", this.getMobileProvider().getProviderId())); //NOI18N
+               } else if (this.getPhoneNumber() == null) {
+                       // Not provided
+                       this.showFacesMessage("form_edit_mobile:mobileNumber", "ERROR_ADMIN_EMPTY_MOBILE_NUMBER"); //NOI18N
+                       return ""; //NOI18N
+               }
+
+               // Is the mobile provider and number the same?
+               if ((Objects.equals(this.getMobileProvider(), mobileNumber.getMobileProvider())) && (Objects.equals(this.getPhoneNumber(), mobileNumber.getPhoneNumber()))) {
+                       // Show message
+                       this.showFacesMessage("form_edit_mobile:mobileNumber", "ERROR_ADMIN_NO_CHANGE_ENTERED"); //NOI18N
+
+                       // No difference in both together, no need to edit
+                       return ""; //NOI18N
+               }
+
+               // Set all data
+               mobileNumber.setMobileProvider(this.getMobileProvider());
+               mobileNumber.setPhoneNumber(this.getPhoneNumber());
+
+               // Send to bean
+               DialableMobileNumber updatedNumber = this.adminPhoneBean.updateMobileData(mobileNumber);
+
+               // Fire event
+               this.mobileNumberUpdatedEvent.fire(new AdminMobileNumberUpdatedEvent(updatedNumber));
+
+               // All fine, redirect
+               return "admin_show_mobile"; //NOI18N
+       }
+
+       @Override
+       public DialableFaxNumber getFaxNumber () {
+               // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[THREAD_STACK].getClassName(), Thread.currentThread().getStackTrace()[THREAD_STACK].getMethodName());
+               // System.out.println(MessageFormat.format("{0}: Returning this.choosenFaxNumber={1}, caller: {2}", this.getClass().getSimpleName(), this.choosenFaxNumber, caller));
+               return this.choosenFaxNumber;
+       }
+
+       @Override
+       public void setFaxNumber (final DialableFaxNumber choosenFaxNumber) {
+               // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[THREAD_STACK].getClassName(), Thread.currentThread().getStackTrace()[THREAD_STACK].getMethodName());
+               // System.out.println(MessageFormat.format("{0}: Settin choosenFaxNumber={1}, previous: this.choosenFaxNumber={2}, caller: {3}", this.getClass().getSimpleName(), choosenFaxNumber, this.choosenFaxNumber, caller));
+               this.choosenFaxNumber = choosenFaxNumber;
+       }
+
+       @Override
+       public DialableLandLineNumber getLandLineNumber () {
+               return this.choosenLandLineNumber;
+       }
+
+       @Override
+       public void setLandLineNumber (final DialableLandLineNumber choosenLandLineNumber) {
+               this.choosenLandLineNumber = choosenLandLineNumber;
        }
 
        @Override
        public DialableMobileNumber getMobileNumber () {
-               return this.mobileNumber;
+               return this.choosenMobileNumber;
+       }
+
+       @Override
+       public void setMobileNumber (final DialableMobileNumber choosenMobileNumber) {
+               this.choosenMobileNumber = choosenMobileNumber;
+       }
+
+       @Override
+       public MobileProvider getMobileProvider () {
+               return this.mobileProvider;
+       }
+
+       @Override
+       public void setMobileProvider (final MobileProvider mobileProvider) {
+               this.mobileProvider = mobileProvider;
+       }
+
+       @Override
+       public Integer getPhoneAreaCode () {
+               return this.phoneAreaCode;
+       }
+
+       @Override
+       public void setPhoneAreaCode (final Integer phoneAreaCode) {
+               this.phoneAreaCode = phoneAreaCode;
+       }
+
+       @Override
+       public Country getPhoneCountry () {
+               return this.phoneCountry;
+       }
+
+       @Override
+       public void setPhoneCountry (final Country phoneCountry) {
+               this.phoneCountry = phoneCountry;
+       }
+
+       @Override
+       public Long getPhoneNumber () {
+               return this.phoneNumber;
        }
 
        @Override
-       public void setMobileNumber (final DialableMobileNumber mobileNumber) {
-               this.mobileNumber = mobileNumber;
+       public void setPhoneNumber (final Long phoneNumber) {
+               this.phoneNumber = phoneNumber;
        }
 
        /**
@@ -110,7 +634,7 @@ public class AddressbookAdminPhoneWebRequestBean extends BaseAddressbookControll
                        Context context = new InitialContext();
 
                        // Try to lookup the beans
-                       this.adminPhoneBean = (AdminContactsPhoneSessionBeanRemote) context.lookup("java:global/addressbook-ejb/admincontactphone!org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote"); //NOI18N
+                       this.adminPhoneBean = (AdminPhoneSessionBeanRemote) context.lookup("java:global/addressbook-ejb/adminPhone!org.mxchange.jphone.phonenumbers.phone.AdminPhoneSessionBeanRemote"); //NOI18N
                } catch (final NamingException e) {
                        // Throw it again
                        throw new FaceletException(e);
index 79730853a5f66e46669fa53e9c841f21f55043b4..e198365ac0d9c35b51b934dde478a4b25cffcc15 100644 (file)
 package org.mxchange.addressbook.beans.phone;
 
 import java.io.Serializable;
+import java.util.List;
 import javax.ejb.Local;
+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.mobile.DialableMobileNumber;
+import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
 
 /**
  * An interface for a request web controller (bean) for administrative phone
@@ -32,45 +35,176 @@ import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
 public interface AddressbookAdminPhoneWebRequestController extends Serializable {
 
        /**
-        * Setter for dialable cellphone number instance
+        * Returns a list of all unused ("non-linked") mobile numbers
         * <p>
-        * @param cellPhone Dialable cellphone number instance
+        * @return List with all unused mobile numbers
         */
-       void setMobileNumber (final DialableMobileNumber cellPhone);
+       List<DialableMobileNumber> allNonLinkedMobileNumbers ();
 
        /**
-        * Getter for dialable cellphone number instance
+        * Returns a list of all unused ("non-linked") land-line numbers
         * <p>
-        * @return Dialable cellphone number instance
+        * @return List with all unused land-line numbers
+        */
+       List<DialableFaxNumber> allNonLinkedFaxNumbers ();
+
+       /**
+        * Returns a list of all unused ("non-linked") land-line numbers
+        * <p>
+        * @return List with all unused land-line numbers
+        */
+       List<DialableLandLineNumber> allNonLinkedLandLineNumbers ();
+
+       /**
+        * Deletes given fax entry data
+        * <p>
+        * @param faxNumber Fax number to delete
+        * <p>
+        * @return Redirect outcome
+        */
+       String deleteFaxData (final DialableFaxNumber faxNumber);
+
+       /**
+        * Changes fax entry data
+        * <p>
+        * @param faxNumber Fax number to change data
+        * <p>
+        * @return Redirect outcome
+        */
+       String editFaxData (final DialableFaxNumber faxNumber);
+
+       /**
+        * Deletes given land-line entry data
+        * <p>
+        * @param landLineNumber Land-line number to delete
+        * <p>
+        * @return Redirect outcome
+        */
+       String deleteLandLineData (final DialableLandLineNumber landLineNumber);
+
+       /**
+        * Changes land-line entry data
+        * <p>
+        * @param landLineNumber Land-line number to change data
+        * <p>
+        * @return Redirect outcome
+        */
+       String editLandLineData (final DialableLandLineNumber landLineNumber);
+
+       /**
+        * Deletes given mobile entry data
+        * <p>
+        * @param mobileNumber Mobile number to delete
+        * <p>
+        * @return Redirect outcome
+        */
+       String deleteMobileData (final DialableMobileNumber mobileNumber);
+
+       /**
+        * Changes mobile entry data
+        * <p>
+        * @param mobileNumber Mobile number to change data
+        * <p>
+        * @return Redirect outcome
+        */
+       String editMobileData (final DialableMobileNumber mobileNumber);
+
+       /**
+        * Getter for mobile provider
+        * <p>
+        * @return Mobile provider
+        */
+       MobileProvider getMobileProvider ();
+
+       /**
+        * Setter for mobile provider
+        * <p>
+        * @param mobileProvider Mobile provider
+        */
+       void setMobileProvider (final MobileProvider mobileProvider);
+
+       /**
+        * Getter for choosen fax number
+        * <p>
+        * @return  fax number
+        */
+       DialableFaxNumber getFaxNumber ();
+
+       /**
+        * Setter for choosen fax number
+        * <p>
+        * @param choosenFaxNumber  fax number
+        */
+       void setFaxNumber (final DialableFaxNumber choosenFaxNumber);
+
+       /**
+        * Getter for choosen land-line number
+        * <p>
+        * @return  land-line number
+        */
+       DialableLandLineNumber getLandLineNumber ();
+
+       /**
+        * Setter for choosen land-line number
+        * <p>
+        * @param choosenLandLineNumber  land-line number
+        */
+       void setLandLineNumber (final DialableLandLineNumber choosenLandLineNumber);
+
+       /**
+        * Getter for choosen mobile number
+        * <p>
+        * @return  mobile number
         */
        DialableMobileNumber getMobileNumber ();
 
        /**
-        * Setter for dialable land-line number instance
+        * Setter for choosen mobile number
+        * <p>
+        * @param choosenMobileNumber  mobile number
+        */
+       void setMobileNumber (final DialableMobileNumber choosenMobileNumber);
+
+       /**
+        * Getter for phone area code
+        * <p>
+        * @return Phone area code
+        */
+       Integer getPhoneAreaCode ();
+
+       /**
+        * Setter for phone area code
+        * <p>
+        * @param phoneAreaCode Phone area code
+        */
+       void setPhoneAreaCode (final Integer phoneAreaCode);
+
+       /**
+        * Getter for phone country (for dial prefix)
         * <p>
-        * @param landLine Dialable land-line number instance
+        * @return Phone country
         */
-       void setLandLine (final DialableLandLineNumber landLine);
+       Country getPhoneCountry ();
 
        /**
-        * Getter for dialable land-line number instance
+        * Setter for phone country (for dial prefix)
         * <p>
-        * @return Dialable land-line number instance
+        * @param phoneCountry Phone country
         */
-       DialableLandLineNumber getLandLine ();
+       void setPhoneCountry (final Country phoneCountry);
 
        /**
-        * Setter for dialable fax number instance
+        * Getter for dial number without prefix
         * <p>
-        * @param fax Dialable fax number instance
+        * @return Dial number without prefix
         */
-       void setFax (final DialableFaxNumber fax);
+       Long getPhoneNumber ();
 
        /**
-        * Getter for dialable fax number instance
+        * Setter for dial number without prefix
         * <p>
-        * @return Dialable fax number instance
+        * @param phoneNumber Dial number without prefix
         */
-       DialableFaxNumber getFax ();
+       void setPhoneNumber (final Long phoneNumber);
 
 }
diff --git a/src/java/org/mxchange/addressbook/beans/phone/AddressbookPhoneWebApplicationBean.java b/src/java/org/mxchange/addressbook/beans/phone/AddressbookPhoneWebApplicationBean.java
new file mode 100644 (file)
index 0000000..080d5be
--- /dev/null
@@ -0,0 +1,610 @@
+/*
+ * Copyright (C) 2016 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.phone;
+
+import java.text.MessageFormat;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Objects;
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Observes;
+import javax.faces.view.facelets.FaceletException;
+import javax.inject.Named;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import org.mxchange.addressbook.beans.BaseAddressbookController;
+import org.mxchange.jcontacts.contact.Contact;
+import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
+import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
+import org.mxchange.jcontacts.events.fax.linked.ObservableAdminLinkedFaxNumberEvent;
+import org.mxchange.jcontacts.events.landline.linked.ObservableAdminLinkedLandLineNumberEvent;
+import org.mxchange.jcontacts.events.mobile.linked.ObservableAdminLinkedMobileNumberEvent;
+import org.mxchange.jphone.events.fax.deleted.AdminDeletedFaxNumberEvent;
+import org.mxchange.jphone.events.fax.updated.AdminUpdatedFaxNumberEvent;
+import org.mxchange.jphone.events.landline.deleted.AdminDeletedLandLineNumberEvent;
+import org.mxchange.jphone.events.landline.updated.AdminUpdatedLandLineNumberEvent;
+import org.mxchange.jphone.events.mobile.deleted.AdminDeletedMobileNumberEvent;
+import org.mxchange.jphone.events.mobile.updated.AdminUpdatedMobileNumberEvent;
+import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
+import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
+import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
+import org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote;
+import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
+
+/**
+ * Regular controller (bean) for phone numbers
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("phoneController")
+@ApplicationScoped
+public class AddressbookPhoneWebApplicationBean extends BaseAddressbookController implements AddressbookPhoneWebApplicationController {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 491_058_674_675_690_105L;
+
+       /**
+        * All fax numbers
+        */
+       private final List<DialableFaxNumber> faxNumbers;
+
+       /**
+        * All land-line numbers
+        */
+       private final List<DialableLandLineNumber> landLineNumbers;
+
+       /**
+        * All mobile numbers
+        */
+       private final List<DialableMobileNumber> mobileNumbers;
+
+       /**
+        * General EJB for phone numbers
+        */
+       private PhoneSessionBeanRemote phoneBean;
+
+       /**
+        * Default constructor
+        */
+       public AddressbookPhoneWebApplicationBean () {
+               // Try it
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // Try to lookup the beans
+                       this.phoneBean = (PhoneSessionBeanRemote) context.lookup("java:global/addressbook-ejb/phone!org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote"); //NOI18N
+               } catch (final NamingException e) {
+                       // Throw it again
+                       throw new FaceletException(e);
+               }
+
+               // Init all lists
+               this.mobileNumbers = new LinkedList<>();
+               this.faxNumbers = new LinkedList<>();
+               this.landLineNumbers = new LinkedList<>();
+       }
+
+       @Override
+       public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent 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.contactId is null"); //NOI18N
+               } else if (event.getAddedContact().getContactId() < 1) {
+                       // Not valid
+                       throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N
+               }
+
+               // Update contact's mobile, land-line and fax number
+               this.updateContactPhoneNumbers(event.getAddedContact());
+
+               // Clear this bean
+               this.clear();
+       }
+
+       @Override
+       public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //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
+               }
+
+               // Update contact's mobile, land-line and fax number
+               this.updateContactPhoneNumbers(event.getAddedUser().getUserContact());
+
+               // Clear all data
+               this.clear();
+       }
+
+       @Override
+       public void afterAdminDeletedFaxNumberEvent (@Observes final AdminDeletedFaxNumberEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getDeletedFaxNumber()== null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.deletedFaxNumber is null"); //NOI18N
+               } else if (event.getDeletedFaxNumber().getPhoneId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.deletedFaxNumber.phoneId is null"); //NOI18N
+               } else if (event.getDeletedFaxNumber().getPhoneId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getDeletedFaxNumber(), event.getDeletedFaxNumber().getPhoneId())); //NOI18N
+               }
+
+               // Update contact's mobile, land-line and fax number
+               this.allFaxNumbers().remove(event.getDeletedFaxNumber());
+
+               // Clear all data
+               this.clear();
+       }
+
+       @Override
+       public void afterAdminDeletedLandLineNumberEvent (@Observes final AdminDeletedLandLineNumberEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getDeletedLandLineNumber()== null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.deletedLandLineNumber is null"); //NOI18N
+               } else if (event.getDeletedLandLineNumber().getPhoneId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.deletedLandLineNumber.phoneId is null"); //NOI18N
+               } else if (event.getDeletedLandLineNumber().getPhoneId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getDeletedLandLineNumber(), event.getDeletedLandLineNumber().getPhoneId())); //NOI18N
+               }
+
+               // Update contact's mobile, land-line and fax number
+               this.allLandLineNumbers().remove(event.getDeletedLandLineNumber());
+
+               // Clear all data
+               this.clear();
+       }
+
+       @Override
+       public void afterAdminDeletedMobileNumberEvent (@Observes final AdminDeletedMobileNumberEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getDeletedMobileNumber()== null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.deletedMobileNumber is null"); //NOI18N
+               } else if (event.getDeletedMobileNumber().getPhoneId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.deletedMobileNumber.phoneId is null"); //NOI18N
+               } else if (event.getDeletedMobileNumber().getPhoneId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getDeletedMobileNumber(), event.getDeletedMobileNumber().getPhoneId())); //NOI18N
+               }
+
+               // Update contact's mobile, land-line and fax number
+               this.allMobileNumbers().remove(event.getDeletedMobileNumber());
+
+               // Clear all data
+               this.clear();
+       }
+
+       @Override
+       public void afterAdminLinkedFaxNumberEvent (@Observes final ObservableAdminLinkedFaxNumberEvent event) {
+               // Is the event fine?
+               if (event == null) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getContact() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("event.contact is null");
+               } else if (event.getContact().getContactId() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("event.contact.contactId is null");
+               } else if (event.getContact().getContactId() < 1) {
+                       // Throw again ...
+                       throw new NullPointerException("event.contact.contactId="+ event.getContact().getContactId() + " is invalid");
+               } else if (event.getContact().getContactFaxNumber() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("event.contact.contactFaxNumber is null");
+               } else if (event.getContact().getContactFaxNumber().getPhoneId() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("event.contact.contactFaxNumber.phoneId is null");
+               } else if (event.getContact().getContactFaxNumber().getPhoneId() < 1) {
+                       // Throw again ...
+                       throw new NullPointerException("event.contact.contactFaxNumber.phoneId="+event.getContact().getContactFaxNumber().getPhoneId() + " is invalid");
+               } else if (event.getLinkedFaxNumber() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("event.linkedFaxNumer is null");
+               }
+
+               // Is the id number in linked number not set?
+               if (event.getLinkedFaxNumber().getPhoneId() == null) {
+                       // Then it is a new number, so add it from contact as there the id number has been set
+                       this.uniqueAddFaxNumber(event.getContact().getContactFaxNumber());
+               }
+       }
+
+       @Override
+       public void afterAdminLinkedLandLineNumberEvent (@Observes final ObservableAdminLinkedLandLineNumberEvent event) {
+               // Is the event fine?
+               if (event == null) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getContact() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("event.contact is null");
+               } else if (event.getContact().getContactId() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("event.contact.contactId is null");
+               } else if (event.getContact().getContactId() < 1) {
+                       // Throw again ...
+                       throw new NullPointerException("event.contact.contactId="+ event.getContact().getContactId() + " is invalid");
+               } else if (event.getContact().getContactLandLineNumber() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("event.contact.contactLandLineNumber is null");
+               } else if (event.getContact().getContactLandLineNumber().getPhoneId() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("event.contact.contactLandLineNumber.phoneId is null");
+               } else if (event.getContact().getContactLandLineNumber().getPhoneId() < 1) {
+                       // Throw again ...
+                       throw new NullPointerException("event.contact.contactLandLineNumber.phoneId="+event.getContact().getContactLandLineNumber().getPhoneId() + " is invalid");
+               } else if (event.getLinkedLandLineNumber() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("event.linkedLandLineNumer is null");
+               }
+
+               // Is the id number in linked number not set?
+               if (event.getLinkedLandLineNumber().getPhoneId() == null) {
+                       // Then it is a new number, so add it from contact as there the id number has been set
+                       this.uniqueAddLandLineNumber(event.getContact().getContactLandLineNumber());
+               }
+       }
+
+       @Override
+       public void afterAdminLinkedMobileNumberEvent (@Observes final ObservableAdminLinkedMobileNumberEvent event) {
+               // Is the event fine?
+               if (event == null) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getContact() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("event.contact is null");
+               } else if (event.getContact().getContactId() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("event.contact.contactId is null");
+               } else if (event.getContact().getContactId() < 1) {
+                       // Throw again ...
+                       throw new NullPointerException("event.contact.contactId="+ event.getContact().getContactId() + " is invalid");
+               } else if (event.getContact().getContactMobileNumber() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("event.contact.contactMobileNumber is null");
+               } else if (event.getContact().getContactMobileNumber().getPhoneId() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("event.contact.contactMobileNumber.phoneId is null");
+               } else if (event.getContact().getContactMobileNumber().getPhoneId() < 1) {
+                       // Throw again ...
+                       throw new NullPointerException("event.contact.contactMobileNumber.phoneId="+event.getContact().getContactMobileNumber().getPhoneId() + " is invalid");
+               } else if (event.getLinkedMobileNumber() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("event.linkedMobileNumer is null");
+               }
+
+               // Is the id number in linked number not set?
+               if (event.getLinkedMobileNumber().getPhoneId() == null) {
+                       // Then it is a new number, so add it from contact as there the id number has been set
+                       this.uniqueAddMobileNumber(event.getContact().getContactMobileNumber());
+               }
+       }
+
+       @Override
+       public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getUpdatedContact() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.updatedContact is null"); //NOI18N
+               } else if (event.getUpdatedContact().getContactId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
+               } else if (event.getUpdatedContact().getContactId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
+               }
+
+               // Update contact's mobile, land-line and fax number
+               this.updateContactPhoneNumbers(event.getUpdatedContact());
+
+               // Clear all data
+               this.clear();
+       }
+
+       @Override
+       public void afterAdminUpdatedFaxNumberEvent (@Observes final AdminUpdatedFaxNumberEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getUpdatedFaxNumber()== null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.updatedFaxNumber is null"); //NOI18N
+               } else if (event.getUpdatedFaxNumber().getPhoneId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.updatedFaxNumber.phoneId is null"); //NOI18N
+               } else if (event.getUpdatedFaxNumber().getPhoneId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getUpdatedFaxNumber(), event.getUpdatedFaxNumber().getPhoneId())); //NOI18N
+               }
+
+               // Uniquely add it
+               this.uniqueAddFaxNumber(event.getUpdatedFaxNumber());
+
+               // Clear it
+               this.clear();
+       }
+
+       @Override
+       public void afterAdminUpdatedLandLineNumberEvent (@Observes final AdminUpdatedLandLineNumberEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getUpdatedLandLineNumber()== null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.updatedLandLineNumber is null"); //NOI18N
+               } else if (event.getUpdatedLandLineNumber().getPhoneId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.updatedLandLineNumber.phoneId is null"); //NOI18N
+               } else if (event.getUpdatedLandLineNumber().getPhoneId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getUpdatedLandLineNumber(), event.getUpdatedLandLineNumber().getPhoneId())); //NOI18N
+               }
+
+               // Uniquely add it
+               this.uniqueAddLandLineNumber(event.getUpdatedLandLineNumber());
+
+               // Clear it
+               this.clear();
+       }
+
+       @Override
+       public void afterAdminUpdatedMobileNumberEvent (@Observes final AdminUpdatedMobileNumberEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getUpdatedMobileNumber()== null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.updatedMobileNumber is null"); //NOI18N
+               } else if (event.getUpdatedMobileNumber().getPhoneId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.updatedMobileNumber.phoneId is null"); //NOI18N
+               } else if (event.getUpdatedMobileNumber().getPhoneId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getUpdatedMobileNumber(), event.getUpdatedMobileNumber().getPhoneId())); //NOI18N
+               }
+
+               // Uniquely add it
+               this.uniqueAddMobileNumber(event.getUpdatedMobileNumber());
+
+               // Clear it
+               this.clear();
+       }
+
+       @Override
+       @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+       public List<DialableFaxNumber> allFaxNumbers () {
+               return this.faxNumbers;
+       }
+
+       @Override
+       @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+       public List<DialableLandLineNumber> allLandLineNumbers () {
+               return this.landLineNumbers;
+       }
+
+       @Override
+       @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+       public List<DialableMobileNumber> allMobileNumbers () {
+               return this.mobileNumbers;
+       }
+
+       /**
+        * Post-construction method
+        */
+       @PostConstruct
+       public void init () {
+               // All phone numbers
+               this.allMobileNumbers().addAll(this.phoneBean.allMobileNumbers());
+               this.allFaxNumbers().addAll(this.phoneBean.allFaxNumbers());
+               this.allLandLineNumbers().addAll(this.phoneBean.allLandLineNumbers());
+       }
+
+       /**
+        * Clears this bean
+        */
+       private void clear () {
+               // Clear all data
+       }
+
+       /**
+        * Uniquely add given fax number to this bean's list. First remove the old
+        * instance (by id number), then re-add it again.
+        * <p>
+        * @param faxNumber number to add
+        */
+       private void uniqueAddFaxNumber (final DialableFaxNumber faxNumber) {
+               // Make sure the parameter is valid
+               if (null == faxNumber) {
+                       // Throw NPE
+                       throw new NullPointerException("faxNumber is null");
+               } else if (faxNumber.getPhoneId() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("faxNumber.phoneId is null");
+               } else if (faxNumber.getPhoneId() < 1) {
+                       // Not valid
+                       throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid.", faxNumber.getPhoneId()));
+               }
+
+               // First remove it
+               if (!this.allFaxNumbers().remove(faxNumber)) {
+                       // Did not work, try by id number
+                       for (final DialableFaxNumber fax : this.allFaxNumbers()) {
+                               // Is id number the same?
+                               if (Objects.equals(fax.getPhoneId(), faxNumber.getPhoneId())) {
+                                       // Found it
+                                       this.allFaxNumbers().remove(fax);
+                                       break;
+                               }
+                       }
+               }
+
+               // ... then add it
+               this.allFaxNumbers().add(faxNumber);
+       }
+
+       /**
+        * Uniquely add given land-line number to this bean's list. First remove the
+        * old instance (by id number), then re-add it again.
+        * <p>
+        * @param landLineNumber Land-line number to add
+        */
+       private void uniqueAddLandLineNumber (final DialableLandLineNumber landLineNumber) {
+               // Make sure the parameter is valid
+               if (null == landLineNumber) {
+                       // Throw NPE
+                       throw new NullPointerException("landLineNumber is null");
+               } else if (landLineNumber.getPhoneId() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("landLineNumber.phoneId is null");
+               } else if (landLineNumber.getPhoneId() < 1) {
+                       // Not valid
+                       throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid.", landLineNumber.getPhoneId()));
+               }
+
+               // First remove it
+               if (!this.allLandLineNumbers().remove(landLineNumber)) {
+                       // Did not work, try by id number
+                       for (final DialableLandLineNumber landLine : this.allLandLineNumbers()) {
+                               // Is id number the same?
+                               if (Objects.equals(landLine.getPhoneId(), landLineNumber.getPhoneId())) {
+                                       // Found it
+                                       this.allLandLineNumbers().remove(landLine);
+                                       break;
+                               }
+                       }
+               }
+
+               // ... then add it
+               this.allLandLineNumbers().add(landLineNumber);
+       }
+
+       /**
+        * Uniquely add given mobile number to this bean's list. First remove the
+        * old instance (by id number), then re-add it again.
+        * <p>
+        * @param mobileNumber Mobile number to add
+        */
+       private void uniqueAddMobileNumber (final DialableMobileNumber mobileNumber) {
+               // Make sure the parameter is valid
+               if (null == mobileNumber) {
+                       // Throw NPE
+                       throw new NullPointerException("mobileNumber is null");
+               } else if (mobileNumber.getPhoneId() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("mobileNumber.phoneId is null");
+               } else if (mobileNumber.getPhoneId() < 1) {
+                       // Not valid
+                       throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid.", mobileNumber.getPhoneId()));
+               }
+
+               // First remove it by object
+               if (!this.allMobileNumbers().remove(mobileNumber)) {
+                       // Did not work, try by id number
+                       for (final DialableMobileNumber cell : this.allMobileNumbers()) {
+                               // Is id number the same?
+                               if (Objects.equals(cell.getPhoneId(), mobileNumber.getPhoneId())) {
+                                       // Found it
+                                       this.allMobileNumbers().remove(cell);
+                                       break;
+                               }
+                       }
+               }
+
+               // ... then add it
+               this.allMobileNumbers().add(mobileNumber);
+       }
+
+       /**
+        * Updates given contact's mobile, land-line and fax number
+        * <p>
+        * @param contact Contact instance
+        */
+       private void updateContactPhoneNumbers (final Contact contact) {
+               // Parameter must be valid
+               if (null == contact) {
+                       // Throw NPE
+                       throw new NullPointerException("contact is null");
+               } else if (contact.getContactId() == null) {
+                       // Throw again
+                       throw new NullPointerException("contact.contactId is null");
+               } else if (contact.getContactId() < 1) {
+                       // Id number is not valid
+               }
+
+               // Is mobile set?
+               if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
+                       // Unique-add it
+                       this.uniqueAddMobileNumber(contact.getContactMobileNumber());
+               }
+
+               // Is land-line set?
+               if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
+                       // Unique-add it
+                       this.uniqueAddLandLineNumber(contact.getContactLandLineNumber());
+               }
+
+               // Is fax set?
+               if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
+                       // Unique-add it
+                       this.uniqueAddFaxNumber(contact.getContactFaxNumber());
+               }
+       }
+
+}
diff --git a/src/java/org/mxchange/addressbook/beans/phone/AddressbookPhoneWebApplicationController.java b/src/java/org/mxchange/addressbook/beans/phone/AddressbookPhoneWebApplicationController.java
new file mode 100644 (file)
index 0000000..35e4dd9
--- /dev/null
@@ -0,0 +1,171 @@
+/*
+ * Copyright (C) 2016 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.phone;
+
+import java.io.Serializable;
+import java.util.List;
+import javax.ejb.Local;
+import org.mxchange.jphone.events.fax.deleted.AdminDeletedFaxNumberEvent;
+import org.mxchange.jphone.events.fax.updated.AdminUpdatedFaxNumberEvent;
+import org.mxchange.jphone.events.landline.deleted.AdminDeletedLandLineNumberEvent;
+import org.mxchange.jphone.events.landline.updated.AdminUpdatedLandLineNumberEvent;
+import org.mxchange.jphone.events.mobile.deleted.AdminDeletedMobileNumberEvent;
+import org.mxchange.jphone.events.mobile.updated.AdminUpdatedMobileNumberEvent;
+import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
+import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
+import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
+import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
+import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
+import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
+import org.mxchange.jcontacts.events.fax.linked.ObservableAdminLinkedFaxNumberEvent;
+import org.mxchange.jcontacts.events.landline.linked.ObservableAdminLinkedLandLineNumberEvent;
+import org.mxchange.jcontacts.events.mobile.linked.ObservableAdminLinkedMobileNumberEvent;
+
+/**
+ * An interface for a request web controller (bean) for administrative phone
+ * number purposes.
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Local
+public interface AddressbookPhoneWebApplicationController extends Serializable {
+
+       /**
+        * Event observer for newly added users by adminstrator
+        * <p>
+        * @param event Event being fired
+        */
+       void afterAdminAddedUserEvent (final ObservableAdminAddedUserEvent event);
+
+       /**
+        * Observes events being fired when an administrator has added a new
+        * contact.
+        * <p>
+        * @param event Event being fired
+        */
+       void afterAdminAddedContactEvent (final ObservableAdminAddedContactEvent event);
+
+       /**
+        * Observes events being fired when an administrator has deleted a fax
+        * number
+        * <p>
+        * @param event Event being fired
+        */
+       void afterAdminDeletedFaxNumberEvent (final AdminDeletedFaxNumberEvent event);
+
+       /**
+        * Observes events being fired when an administrator has deleted a land-line
+        * number
+        * <p>
+        * @param event Event being fired
+        */
+       void afterAdminDeletedLandLineNumberEvent (final AdminDeletedLandLineNumberEvent event);
+
+       /**
+        * Observes events being fired when an administrator has deleted a mobile
+        * number
+        * <p>
+        * @param event Event being fired
+        */
+       void afterAdminDeletedMobileNumberEvent (final AdminDeletedMobileNumberEvent event);
+
+       /**
+        * Observes events being fired when an administrator has a linked a fax
+        * number
+        * <p>
+        * @param event Event being fired
+        */
+       void afterAdminLinkedFaxNumberEvent (final ObservableAdminLinkedFaxNumberEvent event);
+
+       /**
+        * Observes events being fired when an administrator has a linked a
+        * land-line number
+        * <p>
+        * @param event Event being fired
+        */
+       void afterAdminLinkedLandLineNumberEvent (final ObservableAdminLinkedLandLineNumberEvent event);
+
+       /**
+        * Observes events being fired when an administrator has a linked a mobile
+        * number
+        * <p>
+        * @param event Event being fired
+        */
+       void afterAdminLinkedMobileNumberEvent (final ObservableAdminLinkedMobileNumberEvent event);
+
+       /**
+        * Observes events being fired when an administrator has updated a fax
+        * number.
+        * <p>
+        * @param event Event being fired
+        */
+       void afterAdminUpdatedFaxNumberEvent (final AdminUpdatedFaxNumberEvent event);
+
+       /**
+        * Observes events being fired when an administrator has updated a land-line
+        * number.
+        * <p>
+        * @param event Event being fired
+        */
+       void afterAdminUpdatedLandLineNumberEvent (final AdminUpdatedLandLineNumberEvent event);
+
+       /**
+        * Observes events being fired when an administrator has updated a mobile
+        * number.
+        * <p>
+        * @param event Event being fired
+        */
+       void afterAdminUpdatedMobileNumberEvent (final AdminUpdatedMobileNumberEvent event);
+
+       /**
+        * Event observer for updated contact data by administrators
+        * <p>
+        * @param event Updated contact data event
+        */
+       void afterAdminUpdatedContactDataEvent (final ObservableAdminUpdatedContactEvent event);
+
+       /**
+        * Returns a list of all mobile numbers. For performance reasons, the
+        * controller (bean) should be application-scoped as from user to user
+        * nothing changes. And the controller's post-construct method should load
+        * all numbers and cache it in the controller.
+        * <p>
+        * @return List of all mobile numbers
+        */
+       List<DialableMobileNumber> allMobileNumbers ();
+
+       /**
+        * Returns a list of all fax numbers. For performance reasons, the
+        * controller (bean) should be application-scoped as from user to user
+        * nothing changes. And the controller's post-construct method should load
+        * all numbers and cache it in the controller.
+        * <p>
+        * @return List of all fax numbers
+        */
+       List<DialableFaxNumber> allFaxNumbers ();
+
+       /**
+        * Returns a list of all land-line numbers. For performance reasons, the
+        * controller (bean) should be application-scoped as from user to user
+        * nothing changes. And the controller's post-construct method should load
+        * all numbers and cache it in the controller.
+        * <p>
+        * @return List of all land-line numbers
+        */
+       List<DialableLandLineNumber> allLandLineNumbers ();
+
+}
index 2da5a7b7ac7b88488916b5cace7bd9195a9ce5e8..c2aacc54c58d2a9740365e8cc61d645d08121a40 100644 (file)
@@ -57,7 +57,7 @@ public class AddressbookResendLinkWebSessionBean extends BaseAddressbookControll
        /**
         * EJB for resending confirmation link
         */
-       private ResendLinkSessionBeanRemote emailBean;
+       private ResendLinkSessionBeanRemote resendLinkBean;
 
        /**
         * Localization controller
@@ -123,7 +123,7 @@ public class AddressbookResendLinkWebSessionBean extends BaseAddressbookControll
                String baseUrl = FacesUtils.generateBaseUrl();
 
                // Call EJB and return redirect target
-               this.emailBean.resendConfirmationLink(user, this.localizationController.getLocale(), baseUrl);
+               this.resendLinkBean.resendConfirmationLink(user, this.localizationController.getLocale(), baseUrl);
 
                // Clear this bean
                this.clear();
@@ -153,7 +153,7 @@ public class AddressbookResendLinkWebSessionBean extends BaseAddressbookControll
                        Context context = new InitialContext();
 
                        // Try to lookup
-                       this.emailBean = (ResendLinkSessionBeanRemote) context.lookup("java:global/addressbook-ejb/resendLink!org.mxchange.addressbook.beans.resendlink.ResendLinkSessionBeanRemote"); //NOI18N
+                       this.resendLinkBean = (ResendLinkSessionBeanRemote) context.lookup("java:global/addressbook-ejb/resendLink!org.mxchange.addressbook.beans.resendlink.ResendLinkSessionBeanRemote"); //NOI18N
                } catch (final NamingException e) {
                        // Throw again
                        throw new FaceletException(e);
index 78f07c3c682fe461645930bf72203a7bce1dfce4..9b4fe504971ccd1e5295ff0b90fbc43a432c3756 100644 (file)
@@ -33,15 +33,22 @@ import javax.naming.NamingException;
 import org.mxchange.addressbook.beans.BaseAddressbookController;
 import org.mxchange.addressbook.beans.contact.AddressbookAdminContactWebRequestController;
 import org.mxchange.addressbook.beans.contact.AddressbookContactWebSessionController;
-import org.mxchange.addressbook.beans.helper.AddressbookWebRequestController;
+import org.mxchange.addressbook.beans.helper.AddressbookWebRequestHelperController;
+import org.mxchange.addressbook.beans.localization.AddressbookLocalizationSessionController;
 import org.mxchange.jcontacts.contact.Contact;
 import org.mxchange.jcoreee.utils.FacesUtils;
 import org.mxchange.jusercore.container.login.UserLoginContainer;
 import org.mxchange.jusercore.events.registration.ObservableUserRegisteredEvent;
 import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
 import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
+import org.mxchange.jusercore.events.user.delete.AdminDeletedUserEvent;
+import org.mxchange.jusercore.events.user.delete.ObservableAdminDeletedUserEvent;
 import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent;
 import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent;
+import org.mxchange.jusercore.events.user.locked.AdminLockedUserEvent;
+import org.mxchange.jusercore.events.user.locked.ObservableAdminLockedUserEvent;
+import org.mxchange.jusercore.events.user.unlocked.AdminUnlockedUserEvent;
+import org.mxchange.jusercore.events.user.unlocked.ObservableAdminUnlockedUserEvent;
 import org.mxchange.jusercore.events.user.update.AdminUpdatedUserDataEvent;
 import org.mxchange.jusercore.events.user.update.ObservableAdminUpdatedUserDataEvent;
 import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException;
@@ -92,10 +99,10 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookControlle
        private AdminUserSessionBeanRemote adminUserBean;
 
        /**
-        * Bean helper instance
+        * Bean helper
         */
        @Inject
-       private AddressbookWebRequestController beanHelper;
+       private AddressbookWebRequestHelperController beanHelper;
 
        /**
         * Regular contact controller
@@ -103,6 +110,19 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookControlle
        @Inject
        private AddressbookContactWebSessionController contactController;
 
+       /**
+        * Event being fired when admin has deleted user
+        */
+       @Inject
+       @Any
+       private Event<ObservableAdminDeletedUserEvent> deleteUserEvent;
+
+       /**
+        * Localization controller
+        */
+       @Inject
+       private AddressbookLocalizationSessionController localizationController;
+
        /**
         * An event fired when the administrator has updated a new user
         */
@@ -121,6 +141,11 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookControlle
        @Inject
        private AddressbookUserWebSessionController userController;
 
+       /**
+        * Delete reason
+        */
+       private String userDeleteReason;
+
        /**
         * An event fired when the administrator has linked a user with existing
         * contact data.
@@ -134,6 +159,13 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookControlle
         */
        private String userLockReason;
 
+       /**
+        * Event being fired when an administrator has locked a user
+        */
+       @Inject
+       @Any
+       private Event<ObservableAdminLockedUserEvent> userLockedEvent;
+
        /**
         * Flag whether user must change password after login
         */
@@ -154,6 +186,13 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookControlle
         */
        private String userPasswordRepeat;
 
+       /**
+        * Event being fired when admin unlocks an account
+        */
+       @Inject
+       @Any
+       private Event<ObservableAdminUnlockedUserEvent> userUnlockedEvent;
+
        /**
         * Default constructor
         */
@@ -162,9 +201,6 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookControlle
 
        @Override
        public String addUser () {
-               // Create new user instance
-               User user = new LoginUser();
-
                // As the form cannot validate the data (required="true"), check it here
                if (this.getUserName() == null) {
                        // Throw NPE
@@ -179,8 +215,8 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookControlle
                                throw new NullPointerException("contactController.gender is null"); //NOI18N
                        } else if (this.contactController.getFirstName() == null) {
                                // ... and again
-                               throw new NullPointerException("contactController.firstName is null"); //NOI18N //NOI18N
-                       } else if (this.contactController.getFirstName().isEmpty()) {
+                               throw new NullPointerException("contactController.firstName is null"); //NOI18N
+                       } else if (this.adminContactController.getFirstName().isEmpty()) {
                                // ... and again
                                throw new IllegalArgumentException("contactController.firstName is empty"); //NOI18N
                        } else if (this.adminContactController.getFamilyName() == null) {
@@ -188,27 +224,22 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookControlle
                                throw new NullPointerException("contactController.familyName is null"); //NOI18N
                        } else if (this.contactController.getFamilyName().isEmpty()) {
                                // ... and again
-                               throw new IllegalArgumentException("contactController.familyName is empty"); //NOI18N //NOI18N
-                       } else if (this.contactController.getEmailAddress() == null) {
+                               throw new IllegalArgumentException("contactController.familyName is empty"); //NOI18N
+                       } else if (this.adminContactController.getEmailAddress() == null) {
                                // ... and again
                                throw new NullPointerException("contactController.emailAddress is null"); //NOI18N
                        } else if (this.adminContactController.getEmailAddress().isEmpty()) {
                                // ... and again
-                               throw new IllegalArgumentException("contactController.emailAddress is empty"); //NOI18N //NOI18N
-                       } else if (this.contactController.getEmailAddressRepeat() == null) {
-                               // ... and again
-                               throw new NullPointerException("contactController.emailAddressRepeat is null");
-                       } else if (this.contactController.getEmailAddressRepeat().isEmpty()) {
-                               // ... and again
-                               throw new IllegalArgumentException("contactController.emailAddressRepeat is empty"); //NOI18N //NOI18N
-                       } else if (!Objects.equals(this.contactController.getEmailAddress(), this.contactController.getEmailAddressRepeat())) {
-                               // Is not same email address
-                               throw new IllegalArgumentException("Both entered email addresses don't match.");
+                               throw new IllegalArgumentException("contactController.emailAddress is empty"); //NOI18N
                        }
                }
 
+               // Create new user instance
+               User user = new LoginUser();
+
                // Set user name, CONFIRMED and INVISIBLE
                user.setUserName(this.getUserName());
+               user.setUserMustChangePassword(this.getUserMustChangePassword());
                user.setUserAccountStatus(UserAccountStatus.CONFIRMED);
                user.setUserProfileMode(ProfileMode.INVISIBLE);
 
@@ -237,7 +268,14 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookControlle
                        throw new FaceletException(new UserNameAlreadyRegisteredException(user));
                } else if ((this.beanHelper.getContact() == null) && (this.contactController.isEmailAddressRegistered(user.getUserContact()))) {
                        // Email address is already used
-                       throw new FaceletException(new EmailAddressAlreadyRegisteredException(user));
+                       this.showFacesMessage("admin_add_user:emailAddress", "ERROR_EMAIL_ADDRESS_ALREADY_USED"); //NOI18N
+
+                       // Always clear password
+                       this.setUserPassword(null);
+                       this.setUserPasswordRepeat(null);
+
+                       // Skip it
+                       return ""; //NOI18N
                } else if ((this.getUserPassword() == null && (this.getUserPasswordRepeat() == null)) || ((this.getUserPassword().isEmpty()) && (this.getUserPasswordRepeat().isEmpty()))) {
                        // Empty password entered, then generate one
                        password = UserUtils.createRandomPassword(AddressbookUserWebSessionController.MINIMUM_PASSWORD_LENGTH);
@@ -279,6 +317,9 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookControlle
                        throw new FaceletException(ex);
                }
 
+               // Clear helper
+               this.beanHelper.setContact(null);
+
                // Clear this bean
                this.clear();
 
@@ -315,6 +356,35 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookControlle
                this.clear();
        }
 
+       @Override
+       public String deleteUserData (final User user) {
+               // Is the user instance valid and CONFIRMED?
+               if (null == user) {
+                       // Throw NPE
+                       throw new NullPointerException("user is null"); //NOI18N
+               } else if (user.getUserId() == null) {
+                       // Throw again
+                       throw new NullPointerException("user.userId is null"); //NOI18N
+               } else if (user.getUserId() < 1) {
+                       // Invalid id number
+                       throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N
+               }
+
+               try {
+                       // All fine, delete it
+                       this.adminUserBean.deleteUser(user, this.getUserDeleteReason());
+               } catch (final UserNotFoundException ex) {
+                       // Should not happen, so throw again
+                       throw new FaceletException(ex);
+               }
+
+               // Fire event
+               this.deleteUserEvent.fire(new AdminDeletedUserEvent(user, this.getUserDeleteReason()));
+
+               // Redirect
+               return "admin_list_user"; //NOI18N
+       }
+
        @Override
        public String editUserData () {
                // Get user instance
@@ -329,10 +399,10 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookControlle
                        throw new NullPointerException("beanHelper.user is null"); //NOI18N
                } else if (user.getUserId() == null) {
                        // Throw NPE again
-                       throw new NullPointerException("beanHelper.user.userId is null"); //NOI18N //NOI18N
+                       throw new NullPointerException("beanHelper.user.userId is null"); //NOI18N
                } else if (user.getUserId() < 1) {
                        // Invalid id
-                       throw new IllegalStateException(MessageFormat.format("beanHelper.user.userId={0} is invalid", user.getUserId())); //NOI18N //NOI18N
+                       throw new IllegalStateException(MessageFormat.format("beanHelper.user.userId={0} is invalid", user.getUserId())); //NOI18N
                } else if (this.getUserName() == null) {
                        // Not all required fields are set
                        throw new NullPointerException("this.userName is null"); //NOI18N
@@ -340,20 +410,30 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookControlle
                        // Not all required fields are set
                        throw new IllegalArgumentException("this.userName is empty"); //NOI18N
                } else if (((!this.getUserPassword().isEmpty()) || (!this.getUserPasswordRepeat().isEmpty())) && (!this.isSamePasswordEntered())) {
-                       // Not same password entered
+                       // Clear password fields
                        this.setUserPassword(null);
                        this.setUserPasswordRepeat(null);
 
-                       // Throw exception
-                       throw new FaceletException("Not same password entered"); //NOI18N
-               } else if (this.userBean.ifUserNameExists(this.getUserName())) {
+                       // Not same password entered
+                       this.showFacesMessage("form_edit_user:userPassword", "ADMIN_USER_PASSWORD_REPEAT_DIFFERENT"); //NOI18N
+                       return ""; //NOI18N
+               } else if ((!Objects.equals(user.getUserName(), this.getUserName())) && (this.userBean.ifUserNameExists(this.getUserName()))) {
+                       // Clear all fields
+                       this.clear();
+
                        // User name already exists
-                       throw new FaceletException(new UserNameAlreadyRegisteredException(this.getUserName()));
+                       this.showFacesMessage("form_edit_user:userName", "ADMIN_USER_NAME_ALREADY_EXISTS"); //NOI18N
+                       return ""; //NOI18N
                } else if (this.isSamePasswordEntered()) {
                        // Same password entered, create container
-                       if (UserUtils.ifPasswordMatches(new UserLoginContainer(user, this.getUserPassword()))) {
+                       if ((Objects.equals(user.getUserMustChangePassword(), this.getUserMustChangePassword())) && (UserUtils.ifPasswordMatches(new UserLoginContainer(user, this.getUserPassword())))) {
+                               // Clear password fields
+                               this.setUserPassword(null);
+                               this.setUserPasswordRepeat(null);
+
                                // Same password entered
-                               throw new FaceletException("Same password as stored entered."); //NOI18N
+                               this.showFacesMessage("form_edit_user:userPassword", "ADMIN_USER_ENTERED_SAME_AS_OLD_PASSWORD"); //NOI18N
+                               return ""; //NOI18N
                        }
 
                        // Encrypt password
@@ -380,6 +460,16 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookControlle
                return "admin_list_user"; //NOI18N
        }
 
+       @Override
+       public String getUserDeleteReason () {
+               return this.userDeleteReason;
+       }
+
+       @Override
+       public void setUserDeleteReason (final String userDeleteReason) {
+               this.userDeleteReason = userDeleteReason;
+       }
+
        @Override
        public String getUserLockReason () {
                return this.userLockReason;
@@ -475,19 +565,28 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookControlle
                        throw new IllegalArgumentException("this.userLockReason is empty"); //NOI18N
                }
 
+               // Init updated user instance
+               User updatedUser;
+
                try {
                        // Get base URL
                        String baseUrl = FacesUtils.generateBaseUrl();
 
                        // Call EJB to lock account
-                       this.adminUserBean.lockUserAccount(user, this.getUserLockReason(), baseUrl);
+                       updatedUser = this.adminUserBean.lockUserAccount(user, this.getUserLockReason(), baseUrl);
                } catch (final UserStatusLockedException | UserStatusUnconfirmedException | UserNotFoundException ex) {
                        // Throw again
                        throw new FaceletException(ex);
                }
 
+               // Fire event
+               this.userLockedEvent.fire(new AdminLockedUserEvent(updatedUser));
+
+               // Clear bean
+               this.clear();
+
                // Should go fine at this point, redirect to user profile
-               return "admin_show_user?faces-redirect=true&includeViewParams=true"; //NOI18N
+               return "admin_show_user"; //NOI18N
        }
 
        @Override
@@ -510,19 +609,28 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookControlle
                        throw new FaceletException(new UserStatusUnconfirmedException(user));
                }
 
+               // Init updated user instance
+               User updatedUser;
+
                try {
                        // Get base URL
                        String baseUrl = FacesUtils.generateBaseUrl();
 
                        // Call EJB to unlock account
-                       this.adminUserBean.unlockUserAccount(user, baseUrl);
+                       updatedUser = this.adminUserBean.unlockUserAccount(user, baseUrl);
                } catch (final UserStatusConfirmedException | UserStatusUnconfirmedException | UserNotFoundException ex) {
                        // Throw again
                        throw new FaceletException(ex);
                }
 
+               // Fire event
+               this.userUnlockedEvent.fire(new AdminUnlockedUserEvent(updatedUser));
+
+               // Clear bean
+               this.clear();
+
                // Should go fine at this point, redirect to user profile
-               return "admin_show_user?faces-redirect=true&includeViewParams=true"; //NOI18N
+               return "admin_show_user"; //NOI18N
        }
 
        /**
index 12a12d4c8dcb539be0e8443affb741931299b73c..b9deb5ef4a161fc78b6efe2c683548201a56a3dc 100644 (file)
@@ -35,6 +35,15 @@ public interface AddressbookAdminUserWebRequestController extends Serializable {
         */
        String addUser ();
 
+       /**
+        * Deletes given user account
+        * <p>
+        * @param user User instance to delete
+        * <p>
+        * @return Redirect outcome
+        */
+       String deleteUserData (final User user);
+
        /**
         * Edits currently loaded user's data in database.
         * <p>
@@ -132,4 +141,18 @@ public interface AddressbookAdminUserWebRequestController extends Serializable {
         */
        void setUserLockReason (final String userLockReason);
 
+       /**
+        * Getter for user delete reason
+        * <p>
+        * @return User delete reason
+        */
+       String getUserDeleteReason ();
+
+       /**
+        * Setter for user delete reason
+        * <p>
+        * @param userDeleteReason User delete reason
+        */
+       void setUserDeleteReason (final String userDeleteReason);
+
 }
index 26f9dd104d75a216057d66f26ab83653f373113a..9768f597c06f3f8881dcddc36fac9b3d0a66eddb 100644 (file)
@@ -35,14 +35,17 @@ import javax.naming.NamingException;
 import org.mxchange.addressbook.beans.BaseAddressbookController;
 import org.mxchange.addressbook.beans.contact.AddressbookContactWebSessionController;
 import org.mxchange.addressbook.beans.features.AddressbookFeaturesWebApplicationController;
-import org.mxchange.addressbook.beans.localization.AddressbookLocalizationSessionController;
 import org.mxchange.addressbook.beans.login.AddressbookUserLoginWebSessionController;
 import org.mxchange.jcontacts.contact.Contact;
 import org.mxchange.jusercore.events.confirmation.ObservableUserConfirmedAccountEvent;
 import org.mxchange.jusercore.events.login.ObservableUserLoggedInEvent;
 import org.mxchange.jusercore.events.registration.ObservableUserRegisteredEvent;
 import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
+import org.mxchange.jusercore.events.user.delete.ObservableAdminDeletedUserEvent;
+import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent;
+import org.mxchange.jusercore.events.user.locked.ObservableAdminLockedUserEvent;
 import org.mxchange.jusercore.events.user.password_change.ObservableUpdatedUserPasswordEvent;
+import org.mxchange.jusercore.events.user.unlocked.ObservableAdminUnlockedUserEvent;
 import org.mxchange.jusercore.events.user.update.ObservableAdminUpdatedUserDataEvent;
 import org.mxchange.jusercore.events.user.update.ObservableUpdatedUserPersonalDataEvent;
 import org.mxchange.jusercore.events.user.update.UpdatedUserPersonalDataEvent;
@@ -81,12 +84,6 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp
        @Inject
        private AddressbookFeaturesWebApplicationController featureController;
 
-       /**
-        * Localization controller
-        */
-       @Inject
-       private AddressbookLocalizationSessionController localizationController;
-
        /**
         * Event being fired when user updated personal data
         */
@@ -110,7 +107,7 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp
        private List<User> userList;
 
        /**
-        * Login bean (controller)
+        * Login controller (bean)
         */
        @Inject
        private AddressbookUserLoginWebSessionController userLoginController;
@@ -160,9 +157,6 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp
         * @param event Event being fired
         */
        public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
-               // Trace message
-               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterAdminAddedUserEvent: event={0} - CALLED!", event)); //NOI18N
-
                // event should not be null
                if (null == event) {
                        // Throw NPE
@@ -178,103 +172,151 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp
                        throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
                }
 
-               // Add user uniquely
-               this.uniqueAddUser(event.getAddedUser());
+               // Update user list
+               this.updateList(event.getAddedUser());
 
                // Clear all data
                this.clear();
 
                // Set user id again
                this.setUserId(event.getAddedUser().getUserId());
-
-               // Trace message
-               //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterAdminAddedUserEvent: EXIT!"); //NOI18N
        }
 
        /**
-        * Event observer for updated user data by administrator
+        * Event observer for deleted user accounts (by administrator)
         * <p>
-        * @param event Event being updated
+        * @param event Event being fired
         */
-       public void afterAdminUpdatedUserDataEvent (@Observes final ObservableAdminUpdatedUserDataEvent event) {
-               // Trace message
-               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterAdminUpdatedUserEvent: event={0} - CALLED!", event)); //NOI18N
-
+       public void afterAdminDeletedUserEvent (final ObservableAdminDeletedUserEvent event) {
                // event should not be null
                if (null == event) {
                        // Throw NPE
                        throw new NullPointerException("event is null"); //NOI18N
-               } else if (event.getUpdatedUser() == null) {
+               } else if (event.getDeletedUser() == null) {
                        // Throw NPE again
-                       throw new NullPointerException("event.updatedUser is null"); //NOI18N
-               } else if (event.getUpdatedUser().getUserId() == null) {
+                       throw new NullPointerException("event.deletedUser is null"); //NOI18N
+               } else if (event.getDeletedUser().getUserId() == null) {
                        // userId is null
-                       throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
-               } else if (event.getUpdatedUser().getUserId() < 1) {
+                       throw new NullPointerException("event.deletedUser.userId is null"); //NOI18N
+               } else if (event.getDeletedUser().getUserId() < 1) {
                        // Not avalid id
-                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUpdatedUser(), event.getUpdatedUser().getUserId())); //NOI18N
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getDeletedUser(), event.getDeletedUser().getUserId())); //NOI18N
                }
 
-               // Update list
-               this.updateList(event.getUpdatedUser());
+               // Update user list
+               this.removeFromList(event.getDeletedUser());
 
                // Clear all data
                this.clear();
-
-               // Trace message
-               //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterAdminUpdatedUserEvent: EXIT!"); //NOI18N
        }
 
        /**
-        * Event observer for new user registrations
+        * Event observer for linked users with existing contact data
         * <p>
-        * @param event User registration event
+        * @param event Event being fired
         */
-       public void afterUserRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) {
+       public void afterAdminLinkedUserEvent (@Observes final ObservableAdminLinkedUserEvent event) {
                // event should not be null
                if (null == event) {
                        // Throw NPE
                        throw new NullPointerException("event is null"); //NOI18N
-               } else if (event.getRegisteredUser() == null) {
+               } else if (event.getLinkedUser() == null) {
                        // Throw NPE again
-                       throw new NullPointerException("event.registeredUser is null"); //NOI18N
-               } else if (event.getRegisteredUser().getUserId() == null) {
+                       throw new NullPointerException("event.linkedUser is null"); //NOI18N
+               } else if (event.getLinkedUser().getUserId() == null) {
                        // userId is null
-                       throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
-               } else if (event.getRegisteredUser().getUserId() < 1) {
+                       throw new NullPointerException("event.linkedUser.userId is null"); //NOI18N
+               } else if (event.getLinkedUser().getUserId() < 1) {
                        // Not avalid id
-                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserId())); //NOI18N
                }
 
-               // Get user instance
-               User registeredUser = event.getRegisteredUser();
-
-               // Debug message
-               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterRegistration: registeredUser={0}", registeredUser)); //NOI18N
-
-               // Copy all data from registered->user
-               this.copyUser(registeredUser);
+               // Update user list
+               this.updateList(event.getLinkedUser());
 
                // Clear all data
                this.clear();
 
-               // Add user uniquely
-               this.uniqueAddUser(registeredUser);
+               // Set user id again
+               this.setUserId(event.getLinkedUser().getUserId());
+       }
 
-               // Add user name
-               this.addUserName(registeredUser);
+       /**
+        * Event observer for locked users
+        * <p>
+        * @param event Event being fired
+        */
+       public void afterAdminLockedUserEvent (@Observes final ObservableAdminLockedUserEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getLockedUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.lockedUser is null"); //NOI18N
+               } else if (event.getLockedUser().getUserId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.lockedUser.userId is null"); //NOI18N
+               } else if (event.getLockedUser().getUserId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLockedUser(), event.getLockedUser().getUserId())); //NOI18N
+               }
 
-               // Is the account public?
-               if (Objects.equals(registeredUser.getUserProfileMode(), ProfileMode.PUBLIC)) {
-                       // Also add it to this list
-                       this.visibleUserList.add(registeredUser);
+               // Update user list
+               this.updateList(event.getLockedUser());
+       }
+
+       /**
+        * Event observer for unlocked users
+        * <p>
+        * @param event Event being fired
+        */
+       public void afterAdminUnlockedUserEvent (@Observes final ObservableAdminUnlockedUserEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getUnlockedUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.unlockedUser is null"); //NOI18N
+               } else if (event.getUnlockedUser().getUserId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.unlockedUser.userId is null"); //NOI18N
+               } else if (event.getUnlockedUser().getUserId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUnlockedUser(), event.getUnlockedUser().getUserId())); //NOI18N
                }
 
-               // Set user id again
-               this.setUserId(registeredUser.getUserId());
+               // Update user list
+               this.updateList(event.getUnlockedUser());
+       }
 
-               // Trace message
-               //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterRegistration: EXIT!"); //NOI18N
+       /**
+        * Event observer for updated user data by administrator
+        * <p>
+        * @param event Event being updated
+        */
+       public void afterAdminUpdatedUserDataEvent (@Observes final ObservableAdminUpdatedUserDataEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getUpdatedUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.updatedUser is null"); //NOI18N
+               } else if (event.getUpdatedUser().getUserId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
+               } else if (event.getUpdatedUser().getUserId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUpdatedUser(), event.getUpdatedUser().getUserId())); //NOI18N
+               }
+
+               // Update user list
+               this.updateList(event.getUpdatedUser());
+
+               // Clear all data
+               this.clear();
        }
 
        /**
@@ -298,8 +340,8 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp
                        throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
                }
 
-               // Add user uniquely
-               this.uniqueAddUser(event.getConfirmedUser());
+               // Update user list
+               this.updateList(event.getConfirmedUser());
        }
 
        /**
@@ -308,9 +350,6 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp
         * @param event Event instance
         */
        public void afterUserLoginEvent (@Observes final ObservableUserLoggedInEvent event) {
-               // Trace message
-               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N
-
                // event should not be null
                if (null == event) {
                        // Throw NPE
@@ -339,6 +378,52 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp
                }
        }
 
+       /**
+        * Event observer for new user registrations
+        * <p>
+        * @param event User registration event
+        */
+       public void afterUserRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getRegisteredUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.registeredUser is null"); //NOI18N
+               } else if (event.getRegisteredUser().getUserId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
+               } else if (event.getRegisteredUser().getUserId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
+               }
+
+               // Get user instance
+               User registeredUser = event.getRegisteredUser();
+
+               // Copy all data from registered->user
+               this.copyUser(registeredUser);
+
+               // Clear all data
+               this.clear();
+
+               // Update user list
+               this.updateList(registeredUser);
+
+               // Add user name
+               this.addUserName(registeredUser);
+
+               // Is the account public?
+               if (Objects.equals(registeredUser.getUserProfileMode(), ProfileMode.PUBLIC)) {
+                       // Also add it to this list
+                       this.visibleUserList.add(registeredUser);
+               }
+
+               // Set user id again
+               this.setUserId(registeredUser.getUserId());
+       }
+
        /**
         * Method being call after user's password has been updated (and history
         * entry has been created).
@@ -361,7 +446,7 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp
                        throw new IllegalArgumentException(MessageFormat.format("event.passwordHistory.userPasswordHistoryId={0} is in valid", event.getPasswordHistory().getUserPasswordHistoryId())); //NOI18N
                }
 
-               // All fine, so update list
+               // Update user list
                this.updateList(event.getPasswordHistory().getUserPasswordHistoryUser());
        }
 
@@ -386,7 +471,7 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp
                        throw new IllegalArgumentException(MessageFormat.format("event.updatedUser.userId={0} is in valid", event.getUpdatedUser().getUserId())); //NOI18N
                }
 
-               // All fine, so update list
+               // Update user list
                this.updateList(event.getUpdatedUser());
        }
 
@@ -416,7 +501,7 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp
                User user = new LoginUser();
 
                // Is user name required?
-               if ((!this.featureController.isFeatureEnabled("user_name_required")) && (this.getUserName() == null)) { //NOI18N
+               if (!this.isUserNameRequired()) {
                        // Generate pseudo-random user name
                        String randomName = this.userBean.generateRandomUserName();
 
@@ -432,8 +517,7 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp
                        this.setUserPasswordRepeat(randomPassword);
                }
 
-               // Set local, user name and mode
-               user.setUserLocale(this.localizationController.getLocale());
+               // Set user name and mode
                user.setUserName(this.getUserName());
                user.setUserProfileMode(this.getUserProfileMode());
 
@@ -495,7 +579,7 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp
                } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
                        // Password not matching
                        throw new FaceletException(new UserPasswordMismatchException(this.userLoginController.getLoggedInUser()));
-               } else if (!this.featureController.isFeatureEnabled("edit_user_data")) { //NOI18N
+               } else if (!this.featureController.isFeatureEnabled("change_user_personal_data")) {
                        // Editing is not allowed
                        throw new IllegalStateException("User tried to edit personal data."); //NOI18N
                }
@@ -524,7 +608,7 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp
                this.updatedPersonalDataEvent.fire(new UpdatedUserPersonalDataEvent(updatedUser));
 
                // All fine
-               return "contact_data_saved"; //NOI18N
+               return "user_contact_data_saved"; //NOI18N
        }
 
        @Override
@@ -656,7 +740,7 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp
                boolean isEnabled = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N
 
                // This requires user names being enabled, too.
-               if ((isEnabled) && (!this.featureController.isFeatureEnabled("user_name_required"))) { //NOI18N
+               if ((isEnabled) && (!this.isUserNameRequired())) {
                        // Not valid state, users must be able to modify their profile, especially when it is public
                        throw new IllegalStateException("Public user profiles are enabled but user name requirement is disabled, this is not possible."); //NOI18N
                }
@@ -679,7 +763,7 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp
                        return this.contactController.isRequiredPersonalDataSet();
                } else {
                        // Single registration page
-                       return (((this.getUserName() != null) || (!this.featureController.isFeatureEnabled("user_name_required"))) && //NOI18N
+                       return (((this.getUserName() != null) || (!this.isUserNameRequired())) &&
                                        (this.getUserProfileMode() != null) &&
                                        (this.contactController.isRequiredPersonalDataSet()) &&
                                        (this.getUserPassword() != null) &&
@@ -702,9 +786,21 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp
                return ((this.userNameList instanceof List) && (this.userNameList.contains(user.getUserName())));
        }
 
+       @Override
+       public boolean isUserNameRequired () {
+               // Get context parameter
+               String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_user_name_required"); //NOI18N
+
+               // Is it set?
+               boolean isRequired = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N
+
+               // Return value
+               return isRequired;
+       }
+
        @Override
        public boolean isVisibleUserFound () {
-               return ((this.visibleUserList instanceof List) && (!this.visibleUserList.isEmpty()));
+               return ((this.visibleUserList instanceof List) && (this.visibleUserList.size() > 0));
        }
 
        @Override
@@ -732,7 +828,7 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp
                                throw new NullPointerException(MessageFormat.format("next.userContact is null for user id {0}", next.getUserId())); //NOI18N
                        } else if (next.getUserContact().getContactEmailAddress() == null) {
                                // Email address should be set
-                               throw new NullPointerException(MessageFormat.format("next.userContact.contactEmailAddress is null for user id {0}", next.getUserId())); //NOI18N //NOI18N
+                               throw new NullPointerException(MessageFormat.format("next.userContact.contactEmailAddress is null for user id {0}", next.getUserId())); //NOI18N
                        }
 
                        // Is the email address found?
@@ -847,39 +943,29 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp
        }
 
        /**
-        * Uniquely adds given user instance to user list. First an existing
-        * instance will be removed, then the given instance is being added.
+        * Removes user from all lists
         * <p>
-        * @param user User instance to add
+        * @param user User to remove
         */
-       private void uniqueAddUser (final User user) {
-               // Make sure the instance is valid
+       private void removeFromList (final User user) {
+               // The user should be valid
                if (null == user) {
                        // Throw NPE
                        throw new NullPointerException("user is null"); //NOI18N
-               } else if (user.getUserContact() == null) {
-                       // Throw again ...
-                       throw new NullPointerException("user.userContact is null"); //NOI18N
+               } else if (user.getUserId() == null) {
+                       // ... again NPE
+                       throw new NullPointerException("user.userId is null"); //NOI18N
+               } else if (user.getUserId() < 1) {
+                       // Invalid id
+                       throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
                }
 
-               // Get iterator from list
-               Iterator<User> iterator = this.userList.iterator();
-
-               // "Walk" through all entries
-               while (iterator.hasNext()) {
-                       // Get next element
-                       User next = iterator.next();
+               // Remove it from lists
+               this.userList.remove(user);
+               this.visibleUserList.remove(user);
 
-                       // Is id number the same?
-                       if (Objects.equals(user.getUserId(), next.getUserId())) {
-                               // Found entry, so remove it and abort
-                               this.userList.remove(next);
-                               break;
-                       }
-               }
-
-               // Add contact to list
-               this.userList.add(user);
+               // Remove name from list
+               this.userNameList.remove(user.getUserName());
        }
 
        /**
@@ -898,25 +984,34 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp
                } else if (user.getUserId() < 1) {
                        // Invalid id
                        throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
+               } else if (user.getUserContact() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("user.userContact is null"); //NOI18N
+               } else if (user.getUserContact().getContactId() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
+               } else if (user.getUserContact().getContactId() < 1) {
+                       // Throw again ...
+                       throw new NullPointerException(MessageFormat.format("user.userContact.contactId={0} is invalid.", user.getUserContact().getContactId())); //NOI18N
                }
 
-               // Get iterator
+               // Get iterator from list
                Iterator<User> iterator = this.userList.iterator();
 
-               // Look whole list
+               // "Walk" through all entries
                while (iterator.hasNext()) {
                        // Get next element
                        User next = iterator.next();
 
-                       // Is the same user id?
+                       // Is user id number the same?
                        if (Objects.equals(user.getUserId(), next.getUserId())) {
-                               // Found it, so remove it
+                               // Found entry, so remove it and abort
                                this.userList.remove(next);
                                break;
                        }
                }
 
-               // Re-add item
+               // Re-add user
                this.userList.add(user);
        }
 
index 3ba716278e2e8fccbc770994c889f2d3afb99b94..36dbb4cedcb2d5e08f88549df7ba3116788783e8 100644 (file)
@@ -222,6 +222,14 @@ public interface AddressbookUserWebSessionController extends Serializable {
         */
        String doChangePersonalData ();
 
+       /**
+        * Checks whether this application requires a user name to be entered.
+        * Otherwise a random name like "userXXXXX" is generated
+        * <p>
+        * @return Whether this application requires a user name
+        */
+       boolean isUserNameRequired ();
+
        /**
         * Checks wether public user profiles are enabled. This requires that user
         * names are also enabled.