]> git.mxchange.org Git - jfinancials-war.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Fri, 21 Apr 2017 21:06:18 +0000 (23:06 +0200)
committerRoland Häder <roland@mxchange.org>
Sat, 22 Apr 2017 19:30:22 +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>
22 files changed:
src/java/org/mxchange/jfinancials/beans/confirmlink/FinancialsConfirmationLinkWebRequestBean.java
src/java/org/mxchange/jfinancials/beans/contact/FinancialsAdminContactWebRequestBean.java
src/java/org/mxchange/jfinancials/beans/contact/phone/FinancialsAdminContactPhoneWebRequestBean.java [new file with mode: 0644]
src/java/org/mxchange/jfinancials/beans/contact/phone/FinancialsAdminContactPhoneWebRequestController.java [new file with mode: 0644]
src/java/org/mxchange/jfinancials/beans/contact/phone/FinancialsContactPhoneWebSessionBean.java
src/java/org/mxchange/jfinancials/beans/contact/phone/FinancialsContactPhoneWebSessionController.java
src/java/org/mxchange/jfinancials/beans/email_address/FinancialsEmailChangeWebSessionBean.java
src/java/org/mxchange/jfinancials/beans/helper/FinancialsWebRequestController.java [deleted file]
src/java/org/mxchange/jfinancials/beans/helper/FinancialsWebRequestHelper.java [deleted file]
src/java/org/mxchange/jfinancials/beans/helper/FinancialsWebRequestHelperBean.java [new file with mode: 0644]
src/java/org/mxchange/jfinancials/beans/helper/FinancialsWebRequestHelperController.java [new file with mode: 0644]
src/java/org/mxchange/jfinancials/beans/login/FinancialsUserLoginWebSessionBean.java
src/java/org/mxchange/jfinancials/beans/login/FinancialsUserLoginWebSessionController.java
src/java/org/mxchange/jfinancials/beans/phone/FinancialsAdminPhoneWebRequestBean.java
src/java/org/mxchange/jfinancials/beans/phone/FinancialsAdminPhoneWebRequestController.java
src/java/org/mxchange/jfinancials/beans/phone/FinancialsPhoneWebApplicationBean.java [new file with mode: 0644]
src/java/org/mxchange/jfinancials/beans/phone/FinancialsPhoneWebApplicationController.java [new file with mode: 0644]
src/java/org/mxchange/jfinancials/beans/resendlink/FinancialsResendLinkWebSessionBean.java
src/java/org/mxchange/jfinancials/beans/user/FinancialsAdminUserWebRequestBean.java
src/java/org/mxchange/jfinancials/beans/user/FinancialsAdminUserWebRequestController.java
src/java/org/mxchange/jfinancials/beans/user/FinancialsUserWebSessionBean.java
src/java/org/mxchange/jfinancials/beans/user/FinancialsUserWebSessionController.java

index 296c28c6df4ae6de2109a0375b2dfda147cb4f83..af574493b1091b889f305e07f82e00852cfc5ec1 100644 (file)
@@ -32,7 +32,6 @@ import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import org.mxchange.jcoreee.utils.FacesUtils;
 import org.mxchange.jfinancials.beans.BaseFinancialsController;
-import org.mxchange.jfinancials.beans.helper.FinancialsWebRequestController;
 import org.mxchange.jfinancials.beans.user.FinancialsUserWebSessionController;
 import org.mxchange.jusercore.events.confirmation.ObservableUserConfirmedAccountEvent;
 import org.mxchange.jusercore.events.confirmation.UserConfirmedAccountEvent;
@@ -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.jfinancials.beans.helper.FinancialsWebRequestHelperController;
 
 /**
  * A web request bean for confirmation link handling
@@ -60,7 +60,7 @@ public class FinancialsConfirmationLinkWebRequestBean extends BaseFinancialsCont
         * Bean helper instance
         */
        @Inject
-       private FinancialsWebRequestController beanHelper;
+       private FinancialsWebRequestHelperController beanHelper;
 
        /**
         * Confirmation key
index b723b6d2b26c13c6308ca5c50cf1c83dc0763bab..0365390d10b5f14b4a9e73deddfa8ed06e8bfabd 100644 (file)
@@ -43,7 +43,6 @@ import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContac
 import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException;
 import org.mxchange.jcountry.data.Country;
 import org.mxchange.jfinancials.beans.BaseFinancialsController;
-import org.mxchange.jfinancials.beans.helper.FinancialsWebRequestController;
 import org.mxchange.jphone.phonenumbers.DialableNumber;
 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
@@ -52,6 +51,7 @@ 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.jfinancials.beans.helper.FinancialsWebRequestHelperController;
 
 /**
  * An administrative user bean (controller)
@@ -83,7 +83,7 @@ public class FinancialsAdminContactWebRequestBean extends BaseFinancialsControll
         * Bean helper instance
         */
        @Inject
-       private FinancialsWebRequestController beanHelper;
+       private FinancialsWebRequestHelperController beanHelper;
 
        /**
         * Birth day
diff --git a/src/java/org/mxchange/jfinancials/beans/contact/phone/FinancialsAdminContactPhoneWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/contact/phone/FinancialsAdminContactPhoneWebRequestBean.java
new file mode 100644 (file)
index 0000000..dc0be5c
--- /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.jfinancials.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.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.jfinancials.beans.BaseFinancialsController;
+import org.mxchange.jfinancials.beans.helper.FinancialsWebRequestHelperController;
+import org.mxchange.jfinancials.beans.phone.FinancialsAdminPhoneWebRequestController;
+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 FinancialsAdminContactPhoneWebRequestBean extends BaseFinancialsController implements FinancialsAdminContactPhoneWebRequestController {
+
+       /**
+        * 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 FinancialsAdminPhoneWebRequestController adminPhoneController;
+
+       /**
+        * Bean helper
+        */
+       @Inject
+       private FinancialsWebRequestHelperController 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 FinancialsAdminContactPhoneWebRequestBean () {
+               // 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/jfinancials-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/jfinancials/beans/contact/phone/FinancialsAdminContactPhoneWebRequestController.java b/src/java/org/mxchange/jfinancials/beans/contact/phone/FinancialsAdminContactPhoneWebRequestController.java
new file mode 100644 (file)
index 0000000..13dd2fd
--- /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.jfinancials.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 FinancialsAdminContactPhoneWebRequestController 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 068d03d0a1ec217d58db996834183512c800793a..ae35fd417305e993c454e2c42808735a92487922 100644 (file)
@@ -22,22 +22,23 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
-import javax.annotation.PostConstruct;
 import javax.enterprise.context.SessionScoped;
 import javax.enterprise.event.Observes;
-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.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.unlinked.ObservableAdminUnlinkedFaxNumberEvent;
+import org.mxchange.jcontacts.events.landline.unlinked.ObservableAdminUnlinkedLandLineNumberEvent;
+import org.mxchange.jcontacts.events.mobile.unlinked.ObservableAdminUnlinkedMobileNumberEvent;
 import org.mxchange.jfinancials.beans.BaseFinancialsController;
 import org.mxchange.jfinancials.beans.contact.FinancialsContactWebSessionController;
-import org.mxchange.jfinancials.beans.phone.FinancialsAdminPhoneWebRequestController;
-import org.mxchange.jphone.phonenumbers.phone.AdminPhoneSessionBeanRemote;
+import org.mxchange.jfinancials.beans.helper.FinancialsWebRequestHelperController;
+import org.mxchange.jphone.phonenumbers.DialableNumber;
+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;
 
 /**
@@ -55,15 +56,10 @@ public class FinancialsContactPhoneWebSessionBean extends BaseFinancialsControll
        private static final long serialVersionUID = 542_145_347_916L;
 
        /**
-        * Remote EJB for phone number (administrative)
-        */
-       private AdminPhoneSessionBeanRemote adminPhoneBean;
-
-       /**
-        * Administrative phone controller
+        * Bean helper
         */
        @Inject
-       private FinancialsAdminPhoneWebRequestController adminPhoneController;
+       private FinancialsWebRequestHelperController beanHelper;
 
        /**
         * General contact controller
@@ -72,10 +68,11 @@ public class FinancialsContactPhoneWebSessionBean extends BaseFinancialsControll
        private FinancialsContactWebSessionController contactController;
 
        /**
-        * "Cache" for contact lists, mostly only one is assigned. So this cache
-        * shouldn't grow beyond control.
+        * "Cache" for contact's mobile, land-line and fax numbers. Currently one
+        * per each type is supported. Maybe later this will change into a OneToMany
+        * relationship (one contact, many numbers).
         */
-       private final Map<Long, List<Contact>> contacts;
+       private final Map<DialableNumber, List<Contact>> contacts;
 
        /**
         * Default constructor
@@ -104,7 +101,7 @@ public class FinancialsContactPhoneWebSessionBean extends BaseFinancialsControll
                        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 //NOI18N
+                       throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N
                }
 
                // Clear this bean
@@ -112,7 +109,7 @@ public class FinancialsContactPhoneWebSessionBean extends BaseFinancialsControll
        }
 
        /**
-        * Event observer for newly added users by adminstrator
+        * Event observer for newly added users by administrator
         * <p>
         * @param event Event being fired
         */
@@ -136,6 +133,90 @@ public class FinancialsContactPhoneWebSessionBean extends BaseFinancialsControll
                this.clear();
        }
 
+       /**
+        * Event observer for unlinked fax contact by administrators
+        * <p>
+        * @param event Unlinked fax contact event
+        */
+       public void afterAdminUnlinkedFaxContactDataEvent (@Observes final ObservableAdminUnlinkedFaxNumberEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getUnlinkedFaxNumber() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.unlinkedFaxNumber is null"); //NOI18N
+               } else if (event.getUnlinkedFaxNumber().getPhoneId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.unlinkedFaxNumber.contactId is null"); //NOI18N
+               } else if (event.getUnlinkedFaxNumber().getPhoneId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedFaxNumber(), event.getUnlinkedFaxNumber().getPhoneId())); //NOI18N
+               }
+
+               // Remove it from list
+               this.contacts.remove(event.getUnlinkedFaxNumber());
+
+               // Clear all data
+               this.clear();
+       }
+
+       /**
+        * Event observer for unlinked land-line contact by administrators
+        * <p>
+        * @param event Unlinked land-line contact event
+        */
+       public void afterAdminUnlinkedLandLineContactDataEvent (@Observes final ObservableAdminUnlinkedLandLineNumberEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getUnlinkedLandLineNumber() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.unlinkedLandLineNumber is null"); //NOI18N
+               } else if (event.getUnlinkedLandLineNumber().getPhoneId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.unlinkedLandLineNumber.contactId is null"); //NOI18N
+               } else if (event.getUnlinkedLandLineNumber().getPhoneId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedLandLineNumber(), event.getUnlinkedLandLineNumber().getPhoneId())); //NOI18N
+               }
+
+               // Remove it from list
+               this.contacts.remove(event.getUnlinkedLandLineNumber());
+
+               // Clear all data
+               this.clear();
+       }
+
+       /**
+        * Event observer for unlinked mobile contact by administrators
+        * <p>
+        * @param event Unlinked mobile contact event
+        */
+       public void afterAdminUnlinkedMobileContactDataEvent (@Observes final ObservableAdminUnlinkedMobileNumberEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getUnlinkedMobileNumber() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.unlinkedMobileNumber is null"); //NOI18N
+               } else if (event.getUnlinkedMobileNumber().getPhoneId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.unlinkedMobileNumber.contactId is null"); //NOI18N
+               } else if (event.getUnlinkedMobileNumber().getPhoneId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedMobileNumber(), event.getUnlinkedMobileNumber().getPhoneId())); //NOI18N
+               }
+
+               // Remove it from list
+               this.contacts.remove(event.getUnlinkedMobileNumber());
+
+               // Clear all data
+               this.clear();
+       }
+
        /**
         * Event observer for updated contact data by administrators
         * <p>
@@ -156,17 +237,20 @@ public class FinancialsContactPhoneWebSessionBean extends BaseFinancialsControll
                        // 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 List<Contact> allMobileContacts () {
+       public List<Contact> allFaxNumberContacts () {
                // Get id
-               Long phoneId = this.adminPhoneController.getMobileNumber().getPhoneId();
+               DialableFaxNumber faxNumber = this.beanHelper.getFaxNumber();
 
                // Is cache there?
-               if (this.contacts.containsKey(phoneId)) {
+               if (this.contacts.containsKey(faxNumber)) {
                        // Return cached version
-                       return this.contacts.get(phoneId);
+                       return this.contacts.get(faxNumber);
                } else {
                        // Ask bean
                        List<Contact> list = new LinkedList<>();
@@ -174,34 +258,78 @@ public class FinancialsContactPhoneWebSessionBean extends BaseFinancialsControll
                        // "Walk" through all contacts
                        for (final Contact contact : this.contactController.allContacts()) {
                                // Is mobile instance the same?
-                               if (Objects.equals(contact.getContactMobileNumber(), this.adminPhoneController.getMobileNumber())) {
+                               if (Objects.equals(contact.getContactFaxNumber(), this.beanHelper.getFaxNumber())) {
                                        // Found one
                                        list.add(contact);
                                }
                        }
 
                        // Store result in cache
-                       this.contacts.put(phoneId, list);
+                       this.contacts.put(faxNumber, list);
 
                        // Return now-cached list
                        return list;
                }
        }
 
-       @PostConstruct
-       public void init () {
-               // Try it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Try to lookup the beans
-                       this.adminPhoneBean = (AdminPhoneSessionBeanRemote) context.lookup("java:global/jfinancials-ejb/adminphone!org.mxchange.jphone.phonenumbers.phone.AdminPhoneSessionBeanRemote"); //NOI18N
-               } catch (final NamingException e) {
-                       // Throw again
-                       throw new FaceletException(e);
+       @Override
+       public List<Contact> allLandLineNumberContacts () {
+               // Get id
+               DialableLandLineNumber landLineNumber = this.beanHelper.getLandLineNumber();
+
+               // Is cache there?
+               if (this.contacts.containsKey(landLineNumber)) {
+                       // Return cached version
+                       return this.contacts.get(landLineNumber);
+               } else {
+                       // Ask bean
+                       List<Contact> list = new LinkedList<>();
+
+                       // "Walk" through all contacts
+                       for (final Contact contact : this.contactController.allContacts()) {
+                               // Is mobile instance the same?
+                               if (Objects.equals(contact.getContactLandLineNumber(), this.beanHelper.getLandLineNumber())) {
+                                       // Found one
+                                       list.add(contact);
+                               }
+                       }
+
+                       // Store result in cache
+                       this.contacts.put(landLineNumber, list);
+
+                       // Return now-cached list
+                       return list;
                }
+       }
 
+       @Override
+       public List<Contact> allMobileNumberContacts () {
+               // Get id
+               DialableMobileNumber mobileNumber = this.beanHelper.getMobileNumber();
+
+               // Is cache there?
+               if (this.contacts.containsKey(mobileNumber)) {
+                       // Return cached version
+                       return this.contacts.get(mobileNumber);
+               } else {
+                       // Ask bean
+                       List<Contact> list = new LinkedList<>();
+
+                       // "Walk" through all contacts
+                       for (final Contact contact : this.contactController.allContacts()) {
+                               // Is mobile instance the same?
+                               if (Objects.equals(contact.getContactMobileNumber(), this.beanHelper.getMobileNumber())) {
+                                       // Found one
+                                       list.add(contact);
+                               }
+                       }
+
+                       // Store result in cache
+                       this.contacts.put(mobileNumber, list);
+
+                       // Return now-cached list
+                       return list;
+               }
        }
 
        /**
index a32509892c4865d04fa85caa0b6abade5cd37451..3cdb8c75264b8d20e6d388c8c2c111df3c979635 100644 (file)
@@ -30,15 +30,24 @@ import org.mxchange.jcontacts.contact.Contact;
 public interface FinancialsContactPhoneWebSessionController extends Serializable {
 
        /**
-        * Minimum password length
+        * Getter for all contacts having current fax number linked
+        * <p>
+        * @return List of all linked contacts
+        */
+       List<Contact> allFaxNumberContacts ();
+
+       /**
+        * Getter for all contacts having current land-line number linked
+        * <p>
+        * @return List of all linked contacts
         */
-       public static final Integer MINIMUM_PASSWORD_LENGTH = 5;
+       List<Contact> allLandLineNumberContacts ();
 
        /**
-        * Getter for all contacts having current mobile instance linked
+        * Getter for all contacts having current mobile number linked
         * <p>
         * @return List of all linked contacts
         */
-       List<Contact> allMobileContacts ();
+       List<Contact> allMobileNumberContacts ();
 
 }
index 99a501b2eef230f38fd76f5ff8ce92ca7a4a8495..f1799d51a6c28c0cb569e369f6b41a938c94bc56 100644 (file)
@@ -70,7 +70,7 @@ public class FinancialsEmailChangeWebSessionBean extends BaseFinancialsControlle
        /**
         * Remote email change bean
         */
-       private UserEmailChangeSessionBeanRemote emailBean;
+       private UserEmailChangeSessionBeanRemote emailChangeBean;
 
        /**
         * Features controller
@@ -79,7 +79,7 @@ public class FinancialsEmailChangeWebSessionBean extends BaseFinancialsControlle
        private FinancialsFeaturesWebApplicationController featureController;
 
        /**
-        * Login bean (controller)
+        * Login controller (bean)
         */
        @Inject
        private FinancialsUserLoginWebSessionController userLoginController;
@@ -96,19 +96,20 @@ public class FinancialsEmailChangeWebSessionBean extends BaseFinancialsControlle
                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 FinancialsEmailChangeWebSessionBean extends BaseFinancialsControlle
 
                // 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 FinancialsEmailChangeWebSessionBean extends BaseFinancialsControlle
                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 FinancialsEmailChangeWebSessionBean extends BaseFinancialsControlle
        }
 
        /**
-        * Post-construction method
+        * Post-construction
         */
        @PostConstruct
        public void init () {
@@ -175,14 +181,14 @@ public class FinancialsEmailChangeWebSessionBean extends BaseFinancialsControlle
                        Context context = new InitialContext();
 
                        // Try to lookup
-                       this.emailBean = (UserEmailChangeSessionBeanRemote) context.lookup("java:global/jfinancials-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/jfinancials-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 FinancialsEmailChangeWebSessionBean extends BaseFinancialsControlle
                }
 
                // 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/jfinancials/beans/helper/FinancialsWebRequestController.java b/src/java/org/mxchange/jfinancials/beans/helper/FinancialsWebRequestController.java
deleted file mode 100644 (file)
index 532b030..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.jfinancials.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 FinancialsWebRequestController 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/jfinancials/beans/helper/FinancialsWebRequestHelper.java b/src/java/org/mxchange/jfinancials/beans/helper/FinancialsWebRequestHelper.java
deleted file mode 100644 (file)
index d496d36..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.jfinancials.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.jcontacts.contact.Contact;
-import org.mxchange.jfinancials.beans.contact.FinancialsAdminContactWebRequestController;
-import org.mxchange.jfinancials.beans.phone.FinancialsAdminPhoneWebRequestController;
-import org.mxchange.jfinancials.beans.user.FinancialsUserWebSessionController;
-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 FinancialsWebRequestHelper implements FinancialsWebRequestController {
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 17_258_793_567_145_701L;
-
-       /**
-        * Administrative contact controller
-        */
-       @Inject
-       private FinancialsAdminContactWebRequestController adminContactController;
-
-       /**
-        * Administrative phone controller
-        */
-       @Inject
-       private FinancialsAdminPhoneWebRequestController adminPhoneController;
-
-       /**
-        * Contact instance
-        */
-       private Contact contact;
-
-       /**
-        * User instance
-        */
-       private User user;
-
-       /**
-        * Regular user controller
-        */
-       @Inject
-       private FinancialsUserWebSessionController userController;
-
-       /**
-        * Default constructor
-        */
-       public FinancialsWebRequestHelper () {
-       }
-
-       @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 mobile 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/jfinancials/beans/helper/FinancialsWebRequestHelperBean.java b/src/java/org/mxchange/jfinancials/beans/helper/FinancialsWebRequestHelperBean.java
new file mode 100644 (file)
index 0000000..eb2e482
--- /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.jfinancials.beans.helper;
+
+import java.text.MessageFormat;
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.inject.Named;
+import org.mxchange.jcontacts.contact.Contact;
+import org.mxchange.jfinancials.beans.contact.FinancialsAdminContactWebRequestController;
+import org.mxchange.jfinancials.beans.phone.FinancialsAdminPhoneWebRequestController;
+import org.mxchange.jfinancials.beans.user.FinancialsAdminUserWebRequestController;
+import org.mxchange.jfinancials.beans.user.FinancialsUserWebSessionController;
+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 FinancialsWebRequestHelperBean implements FinancialsWebRequestHelperController {
+
+       /**
+        * 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 FinancialsAdminContactWebRequestController adminContactController;
+
+       /**
+        * Administrative phone controller
+        */
+       @Inject
+       private FinancialsAdminPhoneWebRequestController adminPhoneController;
+
+       /**
+        * Administrative user controller
+        */
+       @Inject
+       private FinancialsAdminUserWebRequestController 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 FinancialsUserWebSessionController userController;
+
+       /**
+        * Default constructor
+        */
+       public FinancialsWebRequestHelperBean () {
+               // 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/jfinancials/beans/helper/FinancialsWebRequestHelperController.java b/src/java/org/mxchange/jfinancials/beans/helper/FinancialsWebRequestHelperController.java
new file mode 100644 (file)
index 0000000..5f188f9
--- /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.jfinancials.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 FinancialsWebRequestHelperController 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 8d6917e3b62a6daf03857add2ab17e4044b74a54..8499c99c391c43d97a447fe36202d174a935979f 100644 (file)
@@ -65,12 +65,12 @@ public class FinancialsUserLoginWebSessionBean extends BaseFinancialsController
        /**
         * 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 FinancialsUserLoginWebSessionBean extends BaseFinancialsController
        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 FinancialsUserLoginWebSessionBean extends BaseFinancialsController
        @Inject
        private FinancialsUserWebSessionController 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 FinancialsUserLoginWebSessionBean extends BaseFinancialsController
                        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 FinancialsUserLoginWebSessionBean extends BaseFinancialsController
        }
 
        @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 FinancialsUserLoginWebSessionBean extends BaseFinancialsController
        @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 FinancialsUserLoginWebSessionBean extends BaseFinancialsController
 
        @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 FinancialsUserLoginWebSessionBean extends BaseFinancialsController
 
                        // Also find this
                        this.userPasswordHistoryBean = (UserPasswordHistorySessionBeanRemote) context.lookup("java:global/jfinancials-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 FinancialsUserLoginWebSessionBean extends BaseFinancialsController
                }
 
                // 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 FinancialsUserLoginWebSessionBean extends BaseFinancialsController
 
        @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 FinancialsUserLoginWebSessionBean extends BaseFinancialsController
         */
        private void clear () {
                // Clear all fields
-               this.setCurrentPassword(null);
+               this.setUserCurrentPassword(null);
        }
 
        /**
index 1e56985495bee0310fa00bb707ec9d65fd71feb5..8f108f492e95e01b9e1cfbe8ff372a4c4a7f3c6e 100644 (file)
@@ -40,14 +40,14 @@ public interface FinancialsUserLoginWebSessionController 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 FinancialsUserLoginWebSessionController 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 87420a225d6ff23acb7d6f0d41d9f7c691d1ec23..7d20d89fc58e3da5e94bcda80317bb4037f0bd64 100644 (file)
  */
 package org.mxchange.jfinancials.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.jcontacts.phone.AdminContactsPhoneSessionBeanRemote;
+import org.mxchange.jcountry.data.Country;
 import org.mxchange.jfinancials.beans.BaseFinancialsController;
+import org.mxchange.jfinancials.beans.helper.FinancialsWebRequestHelperController;
+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 FinancialsAdminPhoneWebRequestBean extends BaseFinancialsController implements FinancialsAdminPhoneWebRequestController {
 
+       /**
+        * Call-stack position
+        */
+       private static final short THREAD_STACK = 5;
+
        /**
         * Serial number
         */
@@ -46,57 +78,549 @@ public class FinancialsAdminPhoneWebRequestBean extends BaseFinancialsController
        /**
         * Remote EJB for phone number (administrative)
         */
-       private AdminContactsPhoneSessionBeanRemote adminPhoneBean;
+       private AdminPhoneSessionBeanRemote adminPhoneBean;
+
+       /**
+        * Bean helper
+        */
+       @Inject
+       private FinancialsWebRequestHelperController 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 FinancialsPhoneWebApplicationController 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 FinancialsAdminPhoneWebRequestBean () {
+               // 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 FinancialsAdminPhoneWebRequestBean extends BaseFinancialsController
                        Context context = new InitialContext();
 
                        // Try to lookup the beans
-                       this.adminPhoneBean = (AdminContactsPhoneSessionBeanRemote) context.lookup("java:global/jfinancials-ejb/admincontactphone!org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote"); //NOI18N
+                       this.adminPhoneBean = (AdminPhoneSessionBeanRemote) context.lookup("java:global/jfinancials-ejb/adminPhone!org.mxchange.jphone.phonenumbers.phone.AdminPhoneSessionBeanRemote"); //NOI18N
                } catch (final NamingException e) {
                        // Throw it again
                        throw new FaceletException(e);
index 821d521fc085d53163f278ebd41f25a7381685e3..ba4703c06764cf154a9559761f6f681b391f2c44 100644 (file)
 package org.mxchange.jfinancials.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 FinancialsAdminPhoneWebRequestController extends Serializable {
 
        /**
-        * Setter for dialable mobile number instance
+        * Returns a list of all unused ("non-linked") mobile numbers
         * <p>
-        * @param cellPhone Dialable mobile number instance
+        * @return List with all unused mobile numbers
         */
-       void setMobileNumber (final DialableMobileNumber cellPhone);
+       List<DialableMobileNumber> allNonLinkedMobileNumbers ();
 
        /**
-        * Getter for dialable mobile number instance
+        * Returns a list of all unused ("non-linked") land-line numbers
         * <p>
-        * @return Dialable mobile 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/jfinancials/beans/phone/FinancialsPhoneWebApplicationBean.java b/src/java/org/mxchange/jfinancials/beans/phone/FinancialsPhoneWebApplicationBean.java
new file mode 100644 (file)
index 0000000..2cfcf1b
--- /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.jfinancials.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.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.jfinancials.beans.BaseFinancialsController;
+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 FinancialsPhoneWebApplicationBean extends BaseFinancialsController implements FinancialsPhoneWebApplicationController {
+
+       /**
+        * 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 FinancialsPhoneWebApplicationBean () {
+               // Try it
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // Try to lookup the beans
+                       this.phoneBean = (PhoneSessionBeanRemote) context.lookup("java:global/jfinancials-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/jfinancials/beans/phone/FinancialsPhoneWebApplicationController.java b/src/java/org/mxchange/jfinancials/beans/phone/FinancialsPhoneWebApplicationController.java
new file mode 100644 (file)
index 0000000..e7e0c45
--- /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.jfinancials.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 FinancialsPhoneWebApplicationController 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 2414d935e753b32b0ce4a3eb3a646199689cf082..e07efeff8de98f1555da0f7ded2cf9ca4a85ccb1 100644 (file)
@@ -57,7 +57,7 @@ public class FinancialsResendLinkWebSessionBean extends BaseFinancialsController
        /**
         * EJB for resending confirmation link
         */
-       private ResendLinkSessionBeanRemote emailBean;
+       private ResendLinkSessionBeanRemote resendLinkBean;
 
        /**
         * Localization controller
@@ -123,7 +123,7 @@ public class FinancialsResendLinkWebSessionBean extends BaseFinancialsController
                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 FinancialsResendLinkWebSessionBean extends BaseFinancialsController
                        Context context = new InitialContext();
 
                        // Try to lookup
-                       this.emailBean = (ResendLinkSessionBeanRemote) context.lookup("java:global/jfinancials-ejb/resendLink!org.mxchange.jfinancials.beans.resendlink.ResendLinkSessionBeanRemote"); //NOI18N
+                       this.resendLinkBean = (ResendLinkSessionBeanRemote) context.lookup("java:global/jfinancials-ejb/resendLink!org.mxchange.jfinancials.beans.resendlink.ResendLinkSessionBeanRemote"); //NOI18N
                } catch (final NamingException e) {
                        // Throw again
                        throw new FaceletException(e);
index 86542dae5d30e6c8d107120c0d8ec58a9569515d..087730c8ede2b645e9a4427e48236e6aeb95e206 100644 (file)
@@ -35,13 +35,20 @@ import org.mxchange.jcoreee.utils.FacesUtils;
 import org.mxchange.jfinancials.beans.BaseFinancialsController;
 import org.mxchange.jfinancials.beans.contact.FinancialsAdminContactWebRequestController;
 import org.mxchange.jfinancials.beans.contact.FinancialsContactWebSessionController;
-import org.mxchange.jfinancials.beans.helper.FinancialsWebRequestController;
+import org.mxchange.jfinancials.beans.helper.FinancialsWebRequestHelperController;
+import org.mxchange.jfinancials.beans.localization.FinancialsLocalizationSessionController;
 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 FinancialsAdminUserWebRequestBean extends BaseFinancialsController
        private AdminUserSessionBeanRemote adminUserBean;
 
        /**
-        * Bean helper instance
+        * Bean helper
         */
        @Inject
-       private FinancialsWebRequestController beanHelper;
+       private FinancialsWebRequestHelperController beanHelper;
 
        /**
         * Regular contact controller
@@ -103,6 +110,19 @@ public class FinancialsAdminUserWebRequestBean extends BaseFinancialsController
        @Inject
        private FinancialsContactWebSessionController contactController;
 
+       /**
+        * Event being fired when admin has deleted user
+        */
+       @Inject
+       @Any
+       private Event<ObservableAdminDeletedUserEvent> deleteUserEvent;
+
+       /**
+        * Localization controller
+        */
+       @Inject
+       private FinancialsLocalizationSessionController localizationController;
+
        /**
         * An event fired when the administrator has updated a new user
         */
@@ -121,6 +141,11 @@ public class FinancialsAdminUserWebRequestBean extends BaseFinancialsController
        @Inject
        private FinancialsUserWebSessionController 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 FinancialsAdminUserWebRequestBean extends BaseFinancialsController
         */
        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 FinancialsAdminUserWebRequestBean extends BaseFinancialsController
         */
        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 FinancialsAdminUserWebRequestBean extends BaseFinancialsController
 
        @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 FinancialsAdminUserWebRequestBean extends BaseFinancialsController
                                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 FinancialsAdminUserWebRequestBean extends BaseFinancialsController
                                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 FinancialsAdminUserWebRequestBean extends BaseFinancialsController
                        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(FinancialsUserWebSessionController.MINIMUM_PASSWORD_LENGTH);
@@ -279,6 +317,9 @@ public class FinancialsAdminUserWebRequestBean extends BaseFinancialsController
                        throw new FaceletException(ex);
                }
 
+               // Clear helper
+               this.beanHelper.setContact(null);
+
                // Clear this bean
                this.clear();
 
@@ -315,6 +356,35 @@ public class FinancialsAdminUserWebRequestBean extends BaseFinancialsController
                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 FinancialsAdminUserWebRequestBean extends BaseFinancialsController
                        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 FinancialsAdminUserWebRequestBean extends BaseFinancialsController
                        // 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 FinancialsAdminUserWebRequestBean extends BaseFinancialsController
                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 FinancialsAdminUserWebRequestBean extends BaseFinancialsController
                        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 FinancialsAdminUserWebRequestBean extends BaseFinancialsController
                        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 f73f2edb79e0a31fca879eb0b21569a417d39975..19fc1e313b2394a150eae3e6050f7da2fe0a1de9 100644 (file)
@@ -35,6 +35,15 @@ public interface FinancialsAdminUserWebRequestController 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 FinancialsAdminUserWebRequestController 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 151c641ea17507357b41c8868781f14aa9a624c3..19fd811015b17c3419865c93ed9561457963c802 100644 (file)
@@ -36,13 +36,16 @@ import org.mxchange.jcontacts.contact.Contact;
 import org.mxchange.jfinancials.beans.BaseFinancialsController;
 import org.mxchange.jfinancials.beans.contact.FinancialsContactWebSessionController;
 import org.mxchange.jfinancials.beans.features.FinancialsFeaturesWebApplicationController;
-import org.mxchange.jfinancials.beans.localization.FinancialsLocalizationSessionController;
 import org.mxchange.jfinancials.beans.login.FinancialsUserLoginWebSessionController;
 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 FinancialsUserWebSessionBean extends BaseFinancialsController imple
        @Inject
        private FinancialsFeaturesWebApplicationController featureController;
 
-       /**
-        * Localization controller
-        */
-       @Inject
-       private FinancialsLocalizationSessionController localizationController;
-
        /**
         * Event being fired when user updated personal data
         */
@@ -110,7 +107,7 @@ public class FinancialsUserWebSessionBean extends BaseFinancialsController imple
        private List<User> userList;
 
        /**
-        * Login bean (controller)
+        * Login controller (bean)
         */
        @Inject
        private FinancialsUserLoginWebSessionController userLoginController;
@@ -175,8 +172,8 @@ public class FinancialsUserWebSessionBean extends BaseFinancialsController imple
                        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();
@@ -186,77 +183,140 @@ public class FinancialsUserWebSessionBean extends BaseFinancialsController imple
        }
 
        /**
-        * 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) {
+       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();
        }
 
        /**
-        * 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();
-
-               // 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());
+       }
+
+       /**
+        * 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();
        }
 
        /**
@@ -280,8 +340,8 @@ public class FinancialsUserWebSessionBean extends BaseFinancialsController imple
                        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());
        }
 
        /**
@@ -318,6 +378,52 @@ public class FinancialsUserWebSessionBean extends BaseFinancialsController imple
                }
        }
 
+       /**
+        * 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).
@@ -340,7 +446,7 @@ public class FinancialsUserWebSessionBean extends BaseFinancialsController imple
                        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());
        }
 
@@ -365,7 +471,7 @@ public class FinancialsUserWebSessionBean extends BaseFinancialsController imple
                        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());
        }
 
@@ -385,6 +491,9 @@ public class FinancialsUserWebSessionBean extends BaseFinancialsController imple
 
        @Override
        public User createUserInstance (final boolean createContactData) {
+               // Trace message
+               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createUserInstance: CALLED!", this.getClass().getSimpleName()));
+
                // Required personal data must be set
                assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
 
@@ -392,7 +501,7 @@ public class FinancialsUserWebSessionBean extends BaseFinancialsController imple
                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();
 
@@ -408,8 +517,7 @@ public class FinancialsUserWebSessionBean extends BaseFinancialsController imple
                        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());
 
@@ -418,16 +526,25 @@ public class FinancialsUserWebSessionBean extends BaseFinancialsController imple
                        // Create contact instance
                        Contact contact = this.contactController.createContactInstance();
 
+                       // Debug message
+                       //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createUserInstance: contact={1}", this.getClass().getSimpleName(), contact));
+
                        // Set contact in user
                        user.setUserContact(contact);
                }
 
+               // Trace message
+               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createUserInstance: user={1} - EXIT!", this.getClass().getSimpleName(), user));
+
                // Return it
                return user;
        }
 
        @Override
        public User createUserLogin () {
+               // Trace message
+               //* NOISY-DEBUG */ System.out.println(MessageFormat.format("{0}.createUserLogin: CALLED!", this.getClass().getSimpleName()));
+
                // Is all data set?
                if (this.getUserName() == null) {
                        // Throw NPE
@@ -443,6 +560,9 @@ public class FinancialsUserWebSessionBean extends BaseFinancialsController imple
                // Update all data ...
                recruiter.setUserName(this.getUserName());
 
+               // Trace message
+               //* NOISY-DEBUG */ System.out.println(MessageFormat.format("{0}.createUserLogin: recruiter={1} - EXIT!", this.getClass().getSimpleName(), recruiter));
+
                // Return the new instance
                return recruiter;
        }
@@ -459,7 +579,7 @@ public class FinancialsUserWebSessionBean extends BaseFinancialsController imple
                } 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
                }
@@ -488,7 +608,7 @@ public class FinancialsUserWebSessionBean extends BaseFinancialsController imple
                this.updatedPersonalDataEvent.fire(new UpdatedUserPersonalDataEvent(updatedUser));
 
                // All fine
-               return "contact_data_saved"; //NOI18N
+               return "user_contact_data_saved"; //NOI18N
        }
 
        @Override
@@ -620,7 +740,7 @@ public class FinancialsUserWebSessionBean extends BaseFinancialsController imple
                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
                }
@@ -643,7 +763,7 @@ public class FinancialsUserWebSessionBean extends BaseFinancialsController imple
                        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) &&
@@ -666,9 +786,21 @@ public class FinancialsUserWebSessionBean extends BaseFinancialsController imple
                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
@@ -696,7 +828,7 @@ public class FinancialsUserWebSessionBean extends BaseFinancialsController imple
                                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?
@@ -811,39 +943,29 @@ public class FinancialsUserWebSessionBean extends BaseFinancialsController imple
        }
 
        /**
-        * 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());
        }
 
        /**
@@ -862,25 +984,34 @@ public class FinancialsUserWebSessionBean extends BaseFinancialsController imple
                } 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 48a3e29d57bf1248291121e2310f740fb17f839e..38aa8d8fd4e565a80a0b24e94241cdae3004bd34 100644 (file)
@@ -222,6 +222,14 @@ public interface FinancialsUserWebSessionController 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.