]> git.mxchange.org Git - jfinancials-war.git/commitdiff
Continued a bit:
authorRoland Häder <roland@mxchange.org>
Wed, 20 Apr 2016 14:45:09 +0000 (16:45 +0200)
committerRoland Haeder <roland@mxchange.org>
Wed, 20 Apr 2016 18:33:24 +0000 (20:33 +0200)
- moved all admin controllers from session-scope to request-scope
- renamed them, too

Signed-off-by: Roland Häder <roland@mxchange.org>
15 files changed:
nbproject/faces-config.NavData
src/java/org/mxchange/addressbook/beans/country/AddressbookAdminCountryWebApplicationBean.java [deleted file]
src/java/org/mxchange/addressbook/beans/country/AddressbookAdminCountryWebApplicationController.java [deleted file]
src/java/org/mxchange/addressbook/beans/country/AddressbookAdminCountryWebRequestBean.java [new file with mode: 0644]
src/java/org/mxchange/addressbook/beans/country/AddressbookAdminCountryWebRequestController.java [new file with mode: 0644]
src/java/org/mxchange/addressbook/beans/helper/AddressbookAdminWebRequestHelper.java
src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebRequestBean.java [new file with mode: 0644]
src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebRequestController.java [new file with mode: 0644]
src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebSessionBean.java [deleted file]
src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebSessionController.java [deleted file]
src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebRequestBean.java [new file with mode: 0644]
src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebRequestController.java [new file with mode: 0644]
src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebSessionBean.java [deleted file]
src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebSessionController.java [deleted file]
src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java

index 0fa75d5023618925e65e9c08d8c25ef1e6fcfb48..644e41ad7701dc8cad5bc0df0b9e9d23792dff70 100644 (file)
@@ -2,61 +2,61 @@
 <Scene Scope="Project" version="2">
     <Scope Scope="Faces Configuration Only"/>
     <Scope Scope="Project">
-        <Node id="admin/cellphone/admin_contact_cellphone_list.xhtml" x="650" y="750" zoom="true"/>
-        <Node id="admin/contact/admin_contact_show.xhtml" x="650" y="900" zoom="true"/>
-        <Node id="privacy.xhtml" x="400" y="450" zoom="true"/>
-        <Node id="login/login_change_password.xhtml" x="900" y="300" zoom="true"/>
-        <Node id="admin/mobile_provider/admin_mobile_provider_show.xhtml" x="1400" y="600" zoom="true"/>
-        <Node id="admin/user/admin_user_show.xhtml" x="1400" y="300" zoom="true"/>
-        <Node id="admin/index.xhtml" x="400" y="1350" zoom="true"/>
-        <Node id="login/login_start_sharing_addressbook.xhtml" x="400" y="600" zoom="true"/>
-        <Node id="user/resend_link.xhtml" x="650" y="1050" zoom="true"/>
-        <Node id="admin/admin_logout.xhtml" x="900" y="750" zoom="true"/>
-        <Node id="admin/user/admin_user_unlock.xhtml" x="400" y="300" zoom="true"/>
-        <Node id="index.xhtml" x="900" y="1050" zoom="true"/>
-        <Node id="user/register_done.xhtml" x="1400" y="450" zoom="true"/>
-        <Node id="*" x="1400" y="150" zoom="true"/>
-        <Node id="admin/admin_category_delete.xhtml" x="1650" y="300" zoom="true"/>
-        <Node id="user/login_error.xhtml" x="150" y="1050" zoom="true"/>
-        <Node id="admin/cellphone/admin_contact_cellphone_edit.xhtml" x="1150" y="150" zoom="true"/>
-        <Node id="user/show_addressbook_entries.xhtml" x="150" y="150" zoom="true"/>
-        <Node id="user/lost_passwd.xhtml" x="2150" y="150" zoom="true"/>
-        <Node id="login/login_list_sharing_addressbooks.xhtml" x="650" y="300" zoom="true"/>
-        <Node id="user/login.xhtml" x="650" y="600" zoom="true"/>
-        <Node id="login/login_edit_user_data.xhtml" x="150" y="300" zoom="true"/>
-        <Node id="login/login_contact_data_saved.xhtml" x="400" y="750" zoom="true"/>
-        <Node id="admin/cellphone/admin_contact_cellphone_unlink.xhtml" x="900" y="900" zoom="true"/>
-        <Node id="admin/country/admin_country_list.xhtml" x="650" y="1200" zoom="true"/>
-        <Node id="login/login_shared_addressbooks.xhtml" x="650" y="450" zoom="true"/>
-        <Node id="admin/mobile_provider/admin_mobile_provider_delete.xhtml" x="400" y="1050" zoom="true"/>
-        <Node id="admin/mobile_provider/admin_mobile_provider_list.xhtml" x="150" y="1200" zoom="true"/>
-        <Node id="basket.xhtml" x="150" y="450" zoom="true"/>
-        <Node id="login/login_data_saved.xhtml" x="1900" y="150" zoom="true"/>
-        <Node id="admin/user/admin_user_delete.xhtml" x="1150" y="600" zoom="true"/>
-        <Node id="admin/cellphone/admin_contact_cellphone_delete.xhtml" x="1900" y="450" zoom="true"/>
-        <Node id="exception.xhtml" x="1150" y="900" zoom="true"/>
-        <Node id="user/register.xhtml" x="150" y="750" zoom="true"/>
+        <Node id="admin/cellphone/admin_contact_cellphone_list.xhtml" x="1400" y="450" zoom="true"/>
+        <Node id="admin/contact/admin_contact_show.xhtml" x="1400" y="300" zoom="true"/>
+        <Node id="login/login_change_password.xhtml" x="1400" y="150" zoom="true"/>
+        <Node id="privacy.xhtml" x="1650" y="450" zoom="true"/>
+        <Node id="admin/mobile_provider/admin_mobile_provider_show.xhtml" x="150" y="300" zoom="true"/>
+        <Node id="admin/user/admin_user_show.xhtml" x="900" y="1050" zoom="true"/>
+        <Node id="admin/index.xhtml" x="1650" y="150" zoom="true"/>
+        <Node id="login/login_start_sharing_addressbook.xhtml" x="900" y="150" zoom="true"/>
+        <Node id="user/resend_link.xhtml" x="900" y="450" zoom="true"/>
+        <Node id="admin/admin_logout.xhtml" x="150" y="450" zoom="true"/>
+        <Node id="admin/user/admin_user_unlock.xhtml" x="650" y="300" zoom="true"/>
+        <Node id="index.xhtml" x="1900" y="300" zoom="true"/>
+        <Node id="user/register_done.xhtml" x="150" y="150" zoom="true"/>
+        <Node id="*" x="900" y="300" zoom="true"/>
+        <Node id="admin/admin_category_delete.xhtml" x="900" y="900" zoom="true"/>
+        <Node id="user/login_error.xhtml" x="1150" y="600" zoom="true"/>
+        <Node id="admin/cellphone/admin_contact_cellphone_edit.xhtml" x="900" y="750" zoom="true"/>
+        <Node id="user/show_addressbook_entries.xhtml" x="1150" y="450" zoom="true"/>
+        <Node id="user/lost_passwd.xhtml" x="150" y="1050" zoom="true"/>
+        <Node id="login/login_list_sharing_addressbooks.xhtml" x="650" y="450" zoom="true"/>
+        <Node id="user/login.xhtml" x="900" y="600" zoom="true"/>
+        <Node id="admin/country/admin_country_list.xhtml" x="400" y="600" zoom="true"/>
+        <Node id="login/login_contact_data_saved.xhtml" x="1900" y="150" zoom="true"/>
+        <Node id="admin/cellphone/admin_contact_cellphone_unlink.xhtml" x="1400" y="750" zoom="true"/>
+        <Node id="login/login_edit_user_data.xhtml" x="650" y="1200" zoom="true"/>
+        <Node id="login/login_shared_addressbooks.xhtml" x="400" y="450" zoom="true"/>
+        <Node id="admin/mobile_provider/admin_mobile_provider_delete.xhtml" x="650" y="900" zoom="true"/>
+        <Node id="admin/mobile_provider/admin_mobile_provider_list.xhtml" x="2150" y="150" zoom="true"/>
+        <Node id="basket.xhtml" x="1650" y="600" zoom="true"/>
+        <Node id="admin/user/admin_user_delete.xhtml" x="650" y="150" zoom="true"/>
+        <Node id="exception.xhtml" x="400" y="1050" zoom="true"/>
+        <Node id="admin/cellphone/admin_contact_cellphone_delete.xhtml" x="1150" y="750" zoom="true"/>
+        <Node id="login/login_data_saved.xhtml" x="1150" y="900" zoom="true"/>
+        <Node id="user/register.xhtml" x="1400" y="600" zoom="true"/>
+        <Node id="login/login_index.xhtml" x="400" y="1200" zoom="true"/>
         <Node id="login/login_add_addressbook.xhtml" x="150" y="1350" zoom="true"/>
-        <Node id="login/login_index.xhtml" x="150" y="1500" zoom="true"/>
-        <Node id="login/login_own_addressbooks.xhtml" x="1150" y="750" zoom="true"/>
-        <Node id="admin/user/admin_user_edit.xhtml" x="400" y="150" zoom="true"/>
-        <Node id="terms.xhtml" x="1400" y="750" zoom="true"/>
-        <Node id="admin/contact/admin_contact_edit.xhtml" x="900" y="150" zoom="true"/>
-        <Node id="admin/user/admin_user_list.xhtml" x="1150" y="450" zoom="true"/>
-        <Node id="admin/country/admin_country_delete.xhtml" x="900" y="450" zoom="true"/>
-        <Node id="user/user_list.xhtml" x="1150" y="300" zoom="true"/>
-        <Node id="login/login_user_data_saved.xhtml" x="1900" y="300" zoom="true"/>
-        <Node id="logout.xhtml" x="1650" y="150" zoom="true"/>
-        <Node id="admin/country/admin_country_edit.xhtml" x="900" y="600" zoom="true"/>
-        <Node id="user/user_profile.xhtml" x="150" y="600" zoom="true"/>
-        <Node id="login/login_change_personal_data.xhtml" x="2400" y="150" zoom="true"/>
-        <Node id="user/show_addressbook.xhtml" x="650" y="150" zoom="true"/>
+        <Node id="login/login_own_addressbooks.xhtml" x="400" y="300" zoom="true"/>
+        <Node id="admin/user/admin_user_edit.xhtml" x="650" y="600" zoom="true"/>
+        <Node id="terms.xhtml" x="1150" y="300" zoom="true"/>
+        <Node id="admin/contact/admin_contact_edit.xhtml" x="150" y="900" zoom="true"/>
+        <Node id="admin/user/admin_user_list.xhtml" x="400" y="750" zoom="true"/>
+        <Node id="admin/country/admin_country_delete.xhtml" x="400" y="900" zoom="true"/>
+        <Node id="login/login_user_data_saved.xhtml" x="150" y="750" zoom="true"/>
+        <Node id="user/user_list.xhtml" x="1900" y="450" zoom="true"/>
+        <Node id="logout.xhtml" x="650" y="1050" zoom="true"/>
+        <Node id="admin/country/admin_country_edit.xhtml" x="2400" y="150" zoom="true"/>
+        <Node id="user/user_profile.xhtml" x="150" y="1200" zoom="true"/>
+        <Node id="login/login_change_personal_data.xhtml" x="400" y="1350" zoom="true"/>
+        <Node id="user/show_addressbook.xhtml" x="650" y="750" zoom="true"/>
         <Node id="imprint.xhtml" x="2150" y="300" zoom="true"/>
-        <Node id="admin/mobile_provider/admin_mobile_provider_edit.xhtml" x="1650" y="450" zoom="true"/>
-        <Node id="login/login_other_addressbooks.xhtml" x="1650" y="600" zoom="true"/>
-        <Node id="admin/cellphone/admin_contact_cellphone_show.xhtml" x="150" y="900" zoom="true"/>
-        <Node id="admin/admin_product_delete.xhtml" x="400" y="1200" zoom="true"/>
-        <Node id="login/login_change_email_address.xhtml" x="400" y="900" zoom="true"/>
+        <Node id="admin/mobile_provider/admin_mobile_provider_edit.xhtml" x="1150" y="150" zoom="true"/>
+        <Node id="login/login_other_addressbooks.xhtml" x="400" y="150" zoom="true"/>
+        <Node id="admin/cellphone/admin_contact_cellphone_show.xhtml" x="150" y="1500" zoom="true"/>
+        <Node id="admin/admin_product_delete.xhtml" x="1650" y="300" zoom="true"/>
+        <Node id="login/login_change_email_address.xhtml" x="150" y="600" zoom="true"/>
     </Scope>
     <Scope Scope="All Faces Configurations"/>
 </Scene>
diff --git a/src/java/org/mxchange/addressbook/beans/country/AddressbookAdminCountryWebApplicationBean.java b/src/java/org/mxchange/addressbook/beans/country/AddressbookAdminCountryWebApplicationBean.java
deleted file mode 100644 (file)
index 5b5be64..0000000
+++ /dev/null
@@ -1,273 +0,0 @@
-/*
- * Copyright (C) 2016 Roland Haeder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.beans.country;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.Objects;
-import javax.enterprise.context.ApplicationScoped;
-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.jcountry.data.Country;
-import org.mxchange.jcountry.data.CountryData;
-import org.mxchange.jcountry.data.CountrySingletonBeanRemote;
-import org.mxchange.jcountry.events.AdminAddedCountryEvent;
-import org.mxchange.jcountry.events.AdminEventCountryAdded;
-import org.mxchange.jcountry.exceptions.CountryAlreadyAddedException;
-
-/**
- * An administrative country bean
- * <p>
- * @author Roland Haeder<roland@mxchange.org>
- */
-@Named ("adminCountryController")
-@ApplicationScoped
-public class AddressbookAdminCountryWebApplicationBean implements AddressbookAdminCountryWebApplicationController {
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 18_598_175_719_603L;
-
-       /**
-        * An event triggered when the administrator has added a country
-        */
-       @Inject
-       @Any
-       private Event<AdminAddedCountryEvent> addedCountryEvent;
-
-       /**
-        * Abroad dial prefix
-        */
-       private String countryAbroadDialPrefix;
-
-       /**
-        * Remote country EJB
-        */
-       private CountrySingletonBeanRemote countryBean;
-
-       /**
-        * 2-letter country code
-        */
-       private String countryCode;
-
-       /**
-        * Regular country controller
-        */
-       @Inject
-       private AddressbookCountryWebApplicationController countryController;
-
-       /**
-        * Local dial prefix
-        */
-       private String countryExternalDialPrefix;
-
-       /**
-        * i18n bundle key
-        */
-       private String countryI18nKey;
-
-       /**
-        * Whether the local dial prefix is required to use
-        */
-       private Boolean countryIsLocalPrefixRequired;
-
-       /**
-        * Phone code
-        */
-       private Short countryPhoneCode;
-
-       /**
-        * Default constructor
-        */
-       public AddressbookAdminCountryWebApplicationBean () {
-               // Try this
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Try to lookup the bean
-                       this.countryBean = (CountrySingletonBeanRemote) context.lookup("java:global/addressbook-ejb/country!org.mxchange.jcountry.data.CountrySingletonBeanRemote"); //NOI18N
-               } catch (final NamingException ex) {
-                       // Continue to throw
-                       throw new FaceletException(ex);
-               }
-       }
-
-       @Override
-       public void addCountry () {
-               // Create new country object
-               Country country = new CountryData();
-
-               // Add all data
-               country.setCountryAbroadDialPrefix(this.getCountryAbroadDialPrefix());
-               country.setCountryCode(this.getCountryCode());
-               country.setCountryExternalDialPrefix(this.getCountryExternalDialPrefix());
-               country.setCountryI18nkey(this.getCountryI18nKey());
-               country.setCountryIsLocalPrefixRequired(this.getCountryIsLocalPrefixRequired());
-               country.setCountryPhoneCode(this.getCountryPhoneCode());
-
-               // Does it already exist?
-               if (this.isCountryAdded(country)) {
-                       // Yes, then abort here
-                       throw new FaceletException(new CountryAlreadyAddedException(country));
-               }
-
-               // Init variable
-               Country updatedCountry = null;
-
-               try {
-                       // Send country to bean
-                       updatedCountry = this.countryBean.addCountry(country);
-               } catch (final CountryAlreadyAddedException ex) {
-                       // Throw again
-                       throw new FaceletException(ex);
-               }
-
-               // Fire event
-               this.addedCountryEvent.fire(new AdminEventCountryAdded(updatedCountry));
-
-               // Clear bean
-               this.clear();
-       }
-
-       @Override
-       public List<Country> allCountries () {
-               // Return "cached" version
-               return this.countryController.allCountries();
-       }
-
-       @Override
-       public String getCountryAbroadDialPrefix () {
-               return this.countryAbroadDialPrefix;
-       }
-
-       @Override
-       public void setCountryAbroadDialPrefix (final String countryAbroadDialPrefix) {
-               this.countryAbroadDialPrefix = countryAbroadDialPrefix;
-       }
-
-       @Override
-       public String getCountryCode () {
-               return this.countryCode;
-       }
-
-       @Override
-       public void setCountryCode (final String countryCode) {
-               this.countryCode = countryCode;
-       }
-
-       @Override
-       public String getCountryExternalDialPrefix () {
-               return this.countryExternalDialPrefix;
-       }
-
-       @Override
-       public void setCountryExternalDialPrefix (final String countryExternalDialPrefix) {
-               this.countryExternalDialPrefix = countryExternalDialPrefix;
-       }
-
-       @Override
-       public String getCountryI18nKey () {
-               return this.countryI18nKey;
-       }
-
-       @Override
-       public void setCountryI18nKey (final String countryI18nKey) {
-               this.countryI18nKey = countryI18nKey;
-       }
-
-       @Override
-       public Boolean getCountryIsLocalPrefixRequired () {
-               return this.countryIsLocalPrefixRequired;
-       }
-
-       @Override
-       public void setCountryIsLocalPrefixRequired (final Boolean countryIsLocalPrefixRequired) {
-               this.countryIsLocalPrefixRequired = countryIsLocalPrefixRequired;
-       }
-
-       @Override
-       public Short getCountryPhoneCode () {
-               return this.countryPhoneCode;
-       }
-
-       @Override
-       public void setCountryPhoneCode (final Short countryPhoneCode) {
-               this.countryPhoneCode = countryPhoneCode;
-       }
-
-       @Override
-       public boolean hasCountries () {
-               return (!this.allCountries().isEmpty());
-       }
-
-       /**
-        * Clears this bean
-        */
-       private void clear () {
-               // Clear all
-               this.setCountryAbroadDialPrefix(null);
-               this.setCountryCode(null);
-               this.setCountryExternalDialPrefix(null);
-               this.setCountryI18nKey(null);
-               this.setCountryIsLocalPrefixRequired(null);
-               this.setCountryPhoneCode(null);
-       }
-
-       /**
-        * Checks if given country is already added by iterating over the whole list
-        * and try to find it.
-        * <p>
-        * @param country Country instance to look for
-        * <p>
-        * @return Whether the country was already found
-        */
-       private boolean isCountryAdded (final Country country) {
-               // Default is not found
-               boolean isAdded = false;
-
-               // Now get whole ist
-               List<Country> countries = this.countryController.allCountries();
-
-               // Get iterator from it
-               Iterator<Country> iterator = countries.iterator();
-
-               // Check whole list
-               while (iterator.hasNext()) {
-                       // Get next country
-                       Country next = iterator.next();
-
-                       // Is country code or i18n the same?
-                       if ((Objects.equals(country.getCountryCode(), next.getCountryCode())) || (Objects.equals(country.getCountryI18nkey(), next.getCountryI18nkey()))) {
-                               // Yes, then abort search
-                               isAdded = true;
-                               break;
-                       }
-               }
-
-               // Return result
-               return isAdded;
-       }
-
-}
diff --git a/src/java/org/mxchange/addressbook/beans/country/AddressbookAdminCountryWebApplicationController.java b/src/java/org/mxchange/addressbook/beans/country/AddressbookAdminCountryWebApplicationController.java
deleted file mode 100644 (file)
index 0398080..0000000
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Copyright (C) 2016 Roland Haeder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.beans.country;
-
-import java.io.Serializable;
-import java.util.List;
-import org.mxchange.jcountry.data.Country;
-
-/**
- * An interface for administrative country beans
- * <p>
- * @author Roland Haeder<roland@mxchange.org>
- */
-public interface AddressbookAdminCountryWebApplicationController extends Serializable {
-
-       /**
-        * A list of all countries
-        * <p>
-        * @return All countries
-        */
-       List<Country> allCountries ();
-
-       /**
-        * Adds country to all relevant beans and sends it to the EJB.
-        */
-       void addCountry ();
-
-       /**
-        * Checks whether countries has been registered
-        * <p>
-        * @return Whether countries has been registered
-        */
-       boolean hasCountries ();
-
-       /**
-        * Getter for abroad dial prefix
-        * <p>
-        * @return Abroad dial prefix
-        */
-       String getCountryAbroadDialPrefix ();
-
-       /**
-        * Setter for abroad dial prefix
-        * <p>
-        * @param countryAbroadDialPrefix Abroad dial prefix
-        */
-       void setCountryAbroadDialPrefix (final String countryAbroadDialPrefix);
-
-       /**
-        * Getter for 2-characters country code
-        * <p>
-        * @return Country code
-        */
-       String getCountryCode ();
-
-       /**
-        * Setter for 2-characters country code
-        * <p>
-        * @param countryCode Country code
-        */
-       void setCountryCode (final String countryCode);
-
-       /**
-        * Getter for i18n key for country name
-        * <p>
-        * @return i18n key for country name
-        */
-       String getCountryI18nKey ();
-
-       /**
-        * Setter for i18n key for country name
-        * <p>
-        * @param countryI18nKey i18n key for country name
-        */
-       void setCountryI18nKey (final String countryI18nKey);
-
-       /**
-        * Getter for whether the local dial prefix is required for local calls
-        * <p>
-        * @return Whether the local dial prefix is required
-        */
-       Boolean getCountryIsLocalPrefixRequired ();
-
-       /**
-        * Setter for whether the local dial prefix is required for local calls
-        * <p>
-        * @param countryIsLocalPrefixRequired Whether the local dial prefix is
-        *                                     required
-        */
-       void setCountryIsLocalPrefixRequired (final Boolean countryIsLocalPrefixRequired);
-
-       /**
-        * Getter for external dial prefix
-        * <p>
-        * @return External dial prefix
-        */
-       String getCountryExternalDialPrefix ();
-
-       /**
-        * Setter for external dial prefix
-        * <p>
-        * @param countryExternalDialPrefix External dial prefix
-        */
-       void setCountryExternalDialPrefix (final String countryExternalDialPrefix);
-
-       /**
-        * Getter for country code (example: 49 for Germany, 63 for Philippines)
-        * <p>
-        * @return Dial number without prefix
-        */
-       Short getCountryPhoneCode ();
-
-       /**
-        * Setter for country code (example: 49 for Germany, 63 for Philippines)
-        * <p>
-        * @param countryPhoneCode Country code
-        */
-       void setCountryPhoneCode (final Short countryPhoneCode);
-
-}
diff --git a/src/java/org/mxchange/addressbook/beans/country/AddressbookAdminCountryWebRequestBean.java b/src/java/org/mxchange/addressbook/beans/country/AddressbookAdminCountryWebRequestBean.java
new file mode 100644 (file)
index 0000000..baac32d
--- /dev/null
@@ -0,0 +1,273 @@
+/*
+ * Copyright (C) 2016 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.country;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Objects;
+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.jcountry.data.Country;
+import org.mxchange.jcountry.data.CountryData;
+import org.mxchange.jcountry.data.CountrySingletonBeanRemote;
+import org.mxchange.jcountry.events.AdminAddedCountryEvent;
+import org.mxchange.jcountry.events.AdminEventCountryAdded;
+import org.mxchange.jcountry.exceptions.CountryAlreadyAddedException;
+
+/**
+ * An administrative country bean
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+@Named ("adminCountryController")
+@RequestScoped
+public class AddressbookAdminCountryWebRequestBean implements AddressbookAdminCountryWebRequestController {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 18_598_175_719_603L;
+
+       /**
+        * An event triggered when the administrator has added a country
+        */
+       @Inject
+       @Any
+       private Event<AdminAddedCountryEvent> addedCountryEvent;
+
+       /**
+        * Abroad dial prefix
+        */
+       private String countryAbroadDialPrefix;
+
+       /**
+        * Remote country EJB
+        */
+       private CountrySingletonBeanRemote countryBean;
+
+       /**
+        * 2-letter country code
+        */
+       private String countryCode;
+
+       /**
+        * Regular country controller
+        */
+       @Inject
+       private AddressbookCountryWebApplicationController countryController;
+
+       /**
+        * Local dial prefix
+        */
+       private String countryExternalDialPrefix;
+
+       /**
+        * i18n bundle key
+        */
+       private String countryI18nKey;
+
+       /**
+        * Whether the local dial prefix is required to use
+        */
+       private Boolean countryIsLocalPrefixRequired;
+
+       /**
+        * Phone code
+        */
+       private Short countryPhoneCode;
+
+       /**
+        * Default constructor
+        */
+       public AddressbookAdminCountryWebRequestBean () {
+               // Try this
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // Try to lookup the bean
+                       this.countryBean = (CountrySingletonBeanRemote) context.lookup("java:global/addressbook-ejb/country!org.mxchange.jcountry.data.CountrySingletonBeanRemote"); //NOI18N
+               } catch (final NamingException ex) {
+                       // Continue to throw
+                       throw new FaceletException(ex);
+               }
+       }
+
+       @Override
+       public void addCountry () {
+               // Create new country object
+               Country country = new CountryData();
+
+               // Add all data
+               country.setCountryAbroadDialPrefix(this.getCountryAbroadDialPrefix());
+               country.setCountryCode(this.getCountryCode());
+               country.setCountryExternalDialPrefix(this.getCountryExternalDialPrefix());
+               country.setCountryI18nkey(this.getCountryI18nKey());
+               country.setCountryIsLocalPrefixRequired(this.getCountryIsLocalPrefixRequired());
+               country.setCountryPhoneCode(this.getCountryPhoneCode());
+
+               // Does it already exist?
+               if (this.isCountryAdded(country)) {
+                       // Yes, then abort here
+                       throw new FaceletException(new CountryAlreadyAddedException(country));
+               }
+
+               // Init variable
+               Country updatedCountry = null;
+
+               try {
+                       // Send country to bean
+                       updatedCountry = this.countryBean.addCountry(country);
+               } catch (final CountryAlreadyAddedException ex) {
+                       // Throw again
+                       throw new FaceletException(ex);
+               }
+
+               // Fire event
+               this.addedCountryEvent.fire(new AdminEventCountryAdded(updatedCountry));
+
+               // Clear bean
+               this.clear();
+       }
+
+       @Override
+       public List<Country> allCountries () {
+               // Return "cached" version
+               return this.countryController.allCountries();
+       }
+
+       @Override
+       public String getCountryAbroadDialPrefix () {
+               return this.countryAbroadDialPrefix;
+       }
+
+       @Override
+       public void setCountryAbroadDialPrefix (final String countryAbroadDialPrefix) {
+               this.countryAbroadDialPrefix = countryAbroadDialPrefix;
+       }
+
+       @Override
+       public String getCountryCode () {
+               return this.countryCode;
+       }
+
+       @Override
+       public void setCountryCode (final String countryCode) {
+               this.countryCode = countryCode;
+       }
+
+       @Override
+       public String getCountryExternalDialPrefix () {
+               return this.countryExternalDialPrefix;
+       }
+
+       @Override
+       public void setCountryExternalDialPrefix (final String countryExternalDialPrefix) {
+               this.countryExternalDialPrefix = countryExternalDialPrefix;
+       }
+
+       @Override
+       public String getCountryI18nKey () {
+               return this.countryI18nKey;
+       }
+
+       @Override
+       public void setCountryI18nKey (final String countryI18nKey) {
+               this.countryI18nKey = countryI18nKey;
+       }
+
+       @Override
+       public Boolean getCountryIsLocalPrefixRequired () {
+               return this.countryIsLocalPrefixRequired;
+       }
+
+       @Override
+       public void setCountryIsLocalPrefixRequired (final Boolean countryIsLocalPrefixRequired) {
+               this.countryIsLocalPrefixRequired = countryIsLocalPrefixRequired;
+       }
+
+       @Override
+       public Short getCountryPhoneCode () {
+               return this.countryPhoneCode;
+       }
+
+       @Override
+       public void setCountryPhoneCode (final Short countryPhoneCode) {
+               this.countryPhoneCode = countryPhoneCode;
+       }
+
+       @Override
+       public boolean hasCountries () {
+               return (!this.allCountries().isEmpty());
+       }
+
+       /**
+        * Clears this bean
+        */
+       private void clear () {
+               // Clear all
+               this.setCountryAbroadDialPrefix(null);
+               this.setCountryCode(null);
+               this.setCountryExternalDialPrefix(null);
+               this.setCountryI18nKey(null);
+               this.setCountryIsLocalPrefixRequired(null);
+               this.setCountryPhoneCode(null);
+       }
+
+       /**
+        * Checks if given country is already added by iterating over the whole list
+        * and try to find it.
+        * <p>
+        * @param country Country instance to look for
+        * <p>
+        * @return Whether the country was already found
+        */
+       private boolean isCountryAdded (final Country country) {
+               // Default is not found
+               boolean isAdded = false;
+
+               // Now get whole ist
+               List<Country> countries = this.countryController.allCountries();
+
+               // Get iterator from it
+               Iterator<Country> iterator = countries.iterator();
+
+               // Check whole list
+               while (iterator.hasNext()) {
+                       // Get next country
+                       Country next = iterator.next();
+
+                       // Is country code or i18n the same?
+                       if ((Objects.equals(country.getCountryCode(), next.getCountryCode())) || (Objects.equals(country.getCountryI18nkey(), next.getCountryI18nkey()))) {
+                               // Yes, then abort search
+                               isAdded = true;
+                               break;
+                       }
+               }
+
+               // Return result
+               return isAdded;
+       }
+
+}
diff --git a/src/java/org/mxchange/addressbook/beans/country/AddressbookAdminCountryWebRequestController.java b/src/java/org/mxchange/addressbook/beans/country/AddressbookAdminCountryWebRequestController.java
new file mode 100644 (file)
index 0000000..061baa4
--- /dev/null
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2016 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.country;
+
+import java.io.Serializable;
+import java.util.List;
+import org.mxchange.jcountry.data.Country;
+
+/**
+ * An interface for administrative country beans
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+public interface AddressbookAdminCountryWebRequestController extends Serializable {
+
+       /**
+        * A list of all countries
+        * <p>
+        * @return All countries
+        */
+       List<Country> allCountries ();
+
+       /**
+        * Adds country to all relevant beans and sends it to the EJB.
+        */
+       void addCountry ();
+
+       /**
+        * Checks whether countries has been registered
+        * <p>
+        * @return Whether countries has been registered
+        */
+       boolean hasCountries ();
+
+       /**
+        * Getter for abroad dial prefix
+        * <p>
+        * @return Abroad dial prefix
+        */
+       String getCountryAbroadDialPrefix ();
+
+       /**
+        * Setter for abroad dial prefix
+        * <p>
+        * @param countryAbroadDialPrefix Abroad dial prefix
+        */
+       void setCountryAbroadDialPrefix (final String countryAbroadDialPrefix);
+
+       /**
+        * Getter for 2-characters country code
+        * <p>
+        * @return Country code
+        */
+       String getCountryCode ();
+
+       /**
+        * Setter for 2-characters country code
+        * <p>
+        * @param countryCode Country code
+        */
+       void setCountryCode (final String countryCode);
+
+       /**
+        * Getter for i18n key for country name
+        * <p>
+        * @return i18n key for country name
+        */
+       String getCountryI18nKey ();
+
+       /**
+        * Setter for i18n key for country name
+        * <p>
+        * @param countryI18nKey i18n key for country name
+        */
+       void setCountryI18nKey (final String countryI18nKey);
+
+       /**
+        * Getter for whether the local dial prefix is required for local calls
+        * <p>
+        * @return Whether the local dial prefix is required
+        */
+       Boolean getCountryIsLocalPrefixRequired ();
+
+       /**
+        * Setter for whether the local dial prefix is required for local calls
+        * <p>
+        * @param countryIsLocalPrefixRequired Whether the local dial prefix is
+        *                                     required
+        */
+       void setCountryIsLocalPrefixRequired (final Boolean countryIsLocalPrefixRequired);
+
+       /**
+        * Getter for external dial prefix
+        * <p>
+        * @return External dial prefix
+        */
+       String getCountryExternalDialPrefix ();
+
+       /**
+        * Setter for external dial prefix
+        * <p>
+        * @param countryExternalDialPrefix External dial prefix
+        */
+       void setCountryExternalDialPrefix (final String countryExternalDialPrefix);
+
+       /**
+        * Getter for country code (example: 49 for Germany, 63 for Philippines)
+        * <p>
+        * @return Dial number without prefix
+        */
+       Short getCountryPhoneCode ();
+
+       /**
+        * Setter for country code (example: 49 for Germany, 63 for Philippines)
+        * <p>
+        * @param countryPhoneCode Country code
+        */
+       void setCountryPhoneCode (final Short countryPhoneCode);
+
+}
index 0f45c1751766282d8818e6b6264b5401c4f0baa6..9c599d1634cb6558615f8f1880b13cde858cb8d8 100644 (file)
@@ -21,9 +21,9 @@ import javax.enterprise.context.RequestScoped;
 import javax.inject.Inject;
 import javax.inject.Named;
 import org.mxchange.addressbook.beans.contact.AddressbookAdminContactWebRequestController;
-import org.mxchange.addressbook.beans.user.AddressbookAdminUserWebSessionController;
 import org.mxchange.jcontacts.contact.Contact;
 import org.mxchange.jusercore.model.user.User;
+import org.mxchange.addressbook.beans.user.AddressbookAdminUserWebRequestController;
 
 /**
  * A general helper for beans
@@ -49,7 +49,7 @@ public class AddressbookAdminWebRequestHelper implements AddressbookAdminWebRequ
         * Admin user controller
         */
        @Inject
-       private AddressbookAdminUserWebSessionController adminUserController;
+       private AddressbookAdminUserWebRequestController adminUserController;
 
        /**
         * User instance
diff --git a/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebRequestBean.java b/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebRequestBean.java
new file mode 100644 (file)
index 0000000..7ba2f6c
--- /dev/null
@@ -0,0 +1,171 @@
+/*
+ * Copyright (C) 2016 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.phone;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.enterprise.context.RequestScoped;
+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.phone.AdminContactsPhoneSessionBeanRemote;
+import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
+import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
+import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
+
+/**
+ * Administrative bean (controller) for contact's phone numbers
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+@Named ("adminContactPhoneController")
+@RequestScoped
+public class AddressbookAdminContactPhoneWebRequestBean implements AddressbookAdminContactPhoneWebRequestController {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 184_598_175_371_269_016L;
+
+       /**
+        * Remote EJB for phone number (administrative)
+        */
+       private AdminContactsPhoneSessionBeanRemote adminRemoteBean;
+
+       /**
+        * Cell phone number
+        */
+       private DialableCellphoneNumber cellPhone;
+
+       /**
+        * Instance of linked contact account
+        */
+       private Contact contact;
+
+       /**
+        * "Cache" for contact lists, mostly only one is assigned. So this cache
+        * shouldn't grow beyond control.
+        */
+       private final Map<Long, List<Contact>> contacts;
+
+       /**
+        * Fax number
+        */
+       private DialableFaxNumber fax;
+
+       /**
+        * Land-line number
+        */
+       private DialableLandLineNumber landLine;
+
+       /**
+        * Default constructor
+        */
+       public AddressbookAdminContactPhoneWebRequestBean () {
+               // Try it
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // Try to lookup the beans
+                       this.adminRemoteBean = (AdminContactsPhoneSessionBeanRemote) context.lookup("java:global/PizzaService-ejb/admincontactphone!org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote"); //NOI18N
+               } catch (final NamingException e) {
+                       // Throw it again
+                       throw new FaceletException(e);
+               }
+
+               // Init map
+               this.contacts = new HashMap<>(10);
+       }
+
+       @Override
+       public List<Contact> allCellphoneContacts () {
+               // Get id
+               Long phoneId = this.getCellPhone().getPhoneId();
+
+               // Is cache there?
+               if (this.contacts.containsKey(phoneId)) {
+                       // Return cached version
+                       return this.contacts.get(phoneId);
+               } else {
+                       // Ask bean
+                       List<Contact> list = this.adminRemoteBean.allContacts(this.getCellPhone());
+
+                       // Store result in cache
+                       this.contacts.put(phoneId, list);
+
+                       // Return now-cached list
+                       return list;
+               }
+       }
+
+       @Override
+       public DialableCellphoneNumber getCellPhone () {
+               return this.cellPhone;
+       }
+
+       @Override
+       public void setCellPhone (final DialableCellphoneNumber cellPhone) {
+               this.cellPhone = cellPhone;
+       }
+
+       @Override
+       public Contact getContact () {
+               return this.contact;
+       }
+
+       @Override
+       public void setContact (final Contact contact) {
+               this.contact = contact;
+       }
+
+       @Override
+       public DialableFaxNumber getFax () {
+               return this.fax;
+       }
+
+       @Override
+       public void setFax (final DialableFaxNumber fax) {
+               this.fax = fax;
+       }
+
+       @Override
+       public DialableLandLineNumber getLandLine () {
+               return this.landLine;
+       }
+
+       @Override
+       public void setLandLine (final DialableLandLineNumber landLine) {
+               this.landLine = landLine;
+       }
+
+       /**
+        * Clears this bean
+        */
+       private void clear () {
+               // Clear all instances
+               this.setCellPhone(null);
+               this.setFax(null);
+               this.setLandLine(null);
+               this.setContact(null);
+       }
+
+}
diff --git a/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebRequestController.java b/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebRequestController.java
new file mode 100644 (file)
index 0000000..04af7f0
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2016 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.phone;
+
+import java.io.Serializable;
+import java.util.List;
+import org.mxchange.jcontacts.contact.Contact;
+import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
+import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
+import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
+
+/**
+ * An interface for a request web controller (bean) for administrative phone
+ * number purposes.
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+public interface AddressbookAdminContactPhoneWebRequestController extends Serializable {
+
+       /**
+        * Getter for all contacts having current cellphone instance linked
+        * <p>
+        * @return List of all linked contacts
+        */
+       List<Contact> allCellphoneContacts ();
+
+       /**
+        * Getter for dialable cellphone number instance
+        * <p>
+        * @return Dialable cellphone number instance
+        */
+       DialableCellphoneNumber getCellPhone ();
+
+       /**
+        * Setter for dialable land-line number instance
+        * <p>
+        * @param landLine Dialable land-line number instance
+        */
+       void setLandLine (final DialableLandLineNumber landLine);
+
+       /**
+        * Getter for dialable land-line number instance
+        * <p>
+        * @return Dialable land-line number instance
+        */
+       DialableLandLineNumber getLandLine ();
+
+       /**
+        * Setter for dialable fax number instance
+        * <p>
+        * @param fax Dialable fax number instance
+        */
+       void setFax (final DialableFaxNumber fax);
+
+       /**
+        * Getter for dialable fax number instance
+        * <p>
+        * @return Dialable fax number instance
+        */
+       DialableFaxNumber getFax ();
+
+       /**
+        * Setter for dialable cellphone number instance
+        * <p>
+        * @param cellPhone Dialable cellphone number instance
+        */
+       void setCellPhone (final DialableCellphoneNumber cellPhone);
+
+       /**
+        * Getter for linked contact account
+        * <p>
+        * @return Linked contact account
+        */
+       Contact getContact ();
+
+       /**
+        * Setter for linked contact account
+        * <p>
+        * @param contact Linked contact account
+        */
+       void setContact (final Contact contact);
+
+}
diff --git a/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebSessionBean.java b/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebSessionBean.java
deleted file mode 100644 (file)
index 2d6718b..0000000
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * Copyright (C) 2016 Roland Haeder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.beans.phone;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import javax.enterprise.context.SessionScoped;
-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.phone.AdminContactsPhoneSessionBeanRemote;
-import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
-import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
-import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
-
-/**
- * Administrative bean (controller) for contact's phone numbers
- * <p>
- * @author Roland Haeder<roland@mxchange.org>
- */
-@Named ("adminContactPhoneController")
-@SessionScoped
-public class AddressbookAdminContactPhoneWebSessionBean implements AddressbookAdminContactPhoneWebSessionController {
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 184_598_175_371_269_016L;
-
-       /**
-        * Remote EJB for phone number (administrative)
-        */
-       private AdminContactsPhoneSessionBeanRemote adminRemoteBean;
-
-       /**
-        * Cell phone number
-        */
-       private DialableCellphoneNumber cellPhone;
-
-       /**
-        * Instance of linked contact account
-        */
-       private Contact contact;
-
-       /**
-        * "Cache" for contact lists, mostly only one is assigned. So this cache
-        * shouldn't grow beyond control.
-        */
-       private final Map<Long, List<Contact>> contacts;
-
-       /**
-        * Fax number
-        */
-       private DialableFaxNumber fax;
-
-       /**
-        * Land-line number
-        */
-       private DialableLandLineNumber landLine;
-
-       /**
-        * Default constructor
-        */
-       public AddressbookAdminContactPhoneWebSessionBean () {
-               // Try it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Try to lookup the beans
-                       this.adminRemoteBean = (AdminContactsPhoneSessionBeanRemote) context.lookup("java:global/PizzaService-ejb/admincontactphone!org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote"); //NOI18N
-               } catch (final NamingException e) {
-                       // Throw it again
-                       throw new FaceletException(e);
-               }
-
-               // Init map
-               this.contacts = new HashMap<>(10);
-       }
-
-       @Override
-       public List<Contact> allCellphoneContacts () {
-               // Get id
-               Long phoneId = this.getCellPhone().getPhoneId();
-
-               // Is cache there?
-               if (this.contacts.containsKey(phoneId)) {
-                       // Return cached version
-                       return this.contacts.get(phoneId);
-               } else {
-                       // Ask bean
-                       List<Contact> list = this.adminRemoteBean.allContacts(this.getCellPhone());
-
-                       // Store result in cache
-                       this.contacts.put(phoneId, list);
-
-                       // Return now-cached list
-                       return list;
-               }
-       }
-
-       @Override
-       public DialableCellphoneNumber getCellPhone () {
-               return this.cellPhone;
-       }
-
-       @Override
-       public void setCellPhone (final DialableCellphoneNumber cellPhone) {
-               this.cellPhone = cellPhone;
-       }
-
-       @Override
-       public Contact getContact () {
-               return this.contact;
-       }
-
-       @Override
-       public void setContact (final Contact contact) {
-               this.contact = contact;
-       }
-
-       @Override
-       public DialableFaxNumber getFax () {
-               return this.fax;
-       }
-
-       @Override
-       public void setFax (final DialableFaxNumber fax) {
-               this.fax = fax;
-       }
-
-       @Override
-       public DialableLandLineNumber getLandLine () {
-               return this.landLine;
-       }
-
-       @Override
-       public void setLandLine (final DialableLandLineNumber landLine) {
-               this.landLine = landLine;
-       }
-
-       /**
-        * Clears this bean
-        */
-       private void clear () {
-               // Clear all instances
-               this.setCellPhone(null);
-               this.setFax(null);
-               this.setLandLine(null);
-               this.setContact(null);
-       }
-
-}
diff --git a/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebSessionController.java b/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebSessionController.java
deleted file mode 100644 (file)
index b944233..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright (C) 2016 Roland Haeder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.beans.phone;
-
-import java.io.Serializable;
-import java.util.List;
-import org.mxchange.jcontacts.contact.Contact;
-import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
-import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
-import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
-
-/**
- * An interface for a request web controller (bean) for administrative phone
- * number purposes.
- * <p>
- * @author Roland Haeder<roland@mxchange.org>
- */
-public interface AddressbookAdminContactPhoneWebSessionController extends Serializable {
-
-       /**
-        * Getter for all contacts having current cellphone instance linked
-        * <p>
-        * @return List of all linked contacts
-        */
-       List<Contact> allCellphoneContacts ();
-
-       /**
-        * Getter for dialable cellphone number instance
-        * <p>
-        * @return Dialable cellphone number instance
-        */
-       DialableCellphoneNumber getCellPhone ();
-
-       /**
-        * Setter for dialable land-line number instance
-        * <p>
-        * @param landLine Dialable land-line number instance
-        */
-       void setLandLine (final DialableLandLineNumber landLine);
-
-       /**
-        * Getter for dialable land-line number instance
-        * <p>
-        * @return Dialable land-line number instance
-        */
-       DialableLandLineNumber getLandLine ();
-
-       /**
-        * Setter for dialable fax number instance
-        * <p>
-        * @param fax Dialable fax number instance
-        */
-       void setFax (final DialableFaxNumber fax);
-
-       /**
-        * Getter for dialable fax number instance
-        * <p>
-        * @return Dialable fax number instance
-        */
-       DialableFaxNumber getFax ();
-
-       /**
-        * Setter for dialable cellphone number instance
-        * <p>
-        * @param cellPhone Dialable cellphone number instance
-        */
-       void setCellPhone (final DialableCellphoneNumber cellPhone);
-
-       /**
-        * Getter for linked contact account
-        * <p>
-        * @return Linked contact account
-        */
-       Contact getContact ();
-
-       /**
-        * Setter for linked contact account
-        * <p>
-        * @param contact Linked contact account
-        */
-       void setContact (final Contact contact);
-
-}
diff --git a/src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebRequestBean.java b/src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebRequestBean.java
new file mode 100644 (file)
index 0000000..eae1bfe
--- /dev/null
@@ -0,0 +1,305 @@
+/*
+ * Copyright (C) 2016 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.user;
+
+import java.text.MessageFormat;
+import java.util.Collections;
+import java.util.Iterator;
+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.contact.Contact;
+import org.mxchange.jusercore.events.user.AdminAddedUserEvent;
+import org.mxchange.jusercore.events.user.AdminUserAddedEvent;
+import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException;
+import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException;
+import org.mxchange.jusercore.exceptions.UserNotFoundException;
+import org.mxchange.jusercore.exceptions.UserPasswordRepeatMismatchException;
+import org.mxchange.jusercore.model.user.LoginUser;
+import org.mxchange.jusercore.model.user.User;
+import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
+import org.mxchange.jusercore.model.user.UserUtils;
+import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
+import org.mxchange.jusercore.model.user.status.UserAccountStatus;
+import org.mxchange.addressbook.beans.contact.AddressbookContactWebSessionController;
+
+/**
+ * A user bean (controller)
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+@Named ("adminUserController")
+@RequestScoped
+public class AddressbookAdminUserWebRequestBean implements AddressbookAdminUserWebRequestController {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 542_145_347_916L;
+
+       /**
+        * An event fired when the administrator has added a new user
+        */
+       @Inject
+       @Any
+       private Event<AdminAddedUserEvent> addedUserEvent;
+
+       /**
+        * Regular contact controller
+        */
+       @Inject
+       private AddressbookContactWebSessionController contactController;
+
+       /**
+        * Remote user bean
+        */
+       private final UserSessionBeanRemote userBean;
+
+       /**
+        * A list of all user profiles
+        */
+       private List<User> userList;
+
+       /**
+        * User name
+        */
+       private String userName;
+
+       /**
+        * User password (unencrypted from web form)
+        */
+       private String userPassword;
+
+       /**
+        * User password repeated (unencrypted from web form)
+        */
+       private String userPasswordRepeat;
+
+       /**
+<<<<<<< HEAD:src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebRequestBean.java
+ ZIP code
+        */
+       private Integer zipCode;
+
+       /**
+        * Regular user controller
+        */
+       @Inject
+       private AddressbookUserWebSessionController userController;
+
+       /**
+        * Default constructor
+        */
+       public AddressbookAdminUserWebRequestBean () {
+               // Try it
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // Try to lookup
+                       this.userBean = (UserSessionBeanRemote) context.lookup("java:global/addressbook-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N
+               } catch (final NamingException e) {
+                       // Throw again
+                       throw new FaceletException(e);
+               }
+       }
+
+       @Override
+       public void addUser () {
+               // Create new user instance
+               User localUser = new LoginUser();
+
+               // Set user name, CONFIRMED and INVISIBLE
+               localUser.setUserName(this.getUserName());
+               localUser.setUserAccountStatus(UserAccountStatus.CONFIRMED);
+               localUser.setUserProfileMode(ProfileMode.INVISIBLE);
+
+               // Create contact instance
+               Contact contact = this.contactController.createContactInstance();
+
+               // Set contact in user
+               localUser.setUserContact(contact);
+
+               // Init variable for password
+               String password = null;
+
+               // Is the user name or email address used already?
+               // @TODO Add password length check
+               if (this.userController.isUserNameRegistered(localUser)) {
+                       // User name is already used
+                       throw new FaceletException(new UserNameAlreadyRegisteredException(localUser));
+               } else if (this.contactController.isEmailAddressRegistered(localUser.getUserContact())) {
+                       // Email address is already used
+                       throw new FaceletException(new EmailAddressAlreadyRegisteredException(localUser));
+               } else if ((this.getUserPassword() == null && (this.getUserPasswordRepeat() == null)) || ((this.getUserPassword().isEmpty()) && (this.getUserPasswordRepeat().isEmpty()))) {
+                       // Empty password entered, then generate one
+                       password = UserUtils.createRandomPassword(AddressbookUserWebSessionController.MINIMUM_PASSWORD_LENGTH);
+               } else if (!this.isSamePasswordEntered()) {
+                       // Both passwords don't match
+                       throw new FaceletException(new UserPasswordRepeatMismatchException(localUser));
+               } else {
+                       // Both match, so get it from this bean
+                       password = this.getUserPassword();
+               }
+
+               // The password should not be null and at least 5 characters long
+               assert (password != null) : "password is null"; //NOI18N
+               assert (password.length() >= AddressbookUserWebSessionController.MINIMUM_PASSWORD_LENGTH) : "Password is not long enough."; //NOI18N
+
+               // Encrypt password and set it
+               localUser.setUserEncryptedPassword(UserUtils.encryptPassword(password));
+
+               // Init updated user instance
+               User updatedUser = null;
+
+               try {
+                       // Now, that all is set, call EJB
+                       updatedUser = this.userBean.addUser(localUser);
+               } catch (final UserNameAlreadyRegisteredException | EmailAddressAlreadyRegisteredException ex) {
+                       // Throw again
+                       throw new FaceletException(ex);
+               }
+
+               // Fire event
+               this.addedUserEvent.fire(new AdminUserAddedEvent(updatedUser));
+
+               // Add user to local list
+               this.userList.add(updatedUser);
+
+               // Clear all
+               this.clear();
+
+               // Clear contact instance
+               this.contactController.clear();
+       }
+
+       @Override
+       public List<User> allUsers () {
+               // Return it
+               return Collections.unmodifiableList(this.userList);
+       }
+
+       @Override
+       public String getUserName () {
+               return this.userName;
+       }
+
+       @Override
+       public void setUserName (final String userName) {
+               this.userName = userName;
+       }
+
+       @Override
+       public String getUserPassword () {
+               return this.userPassword;
+       }
+
+       @Override
+       public void setUserPassword (final String userPassword) {
+               this.userPassword = userPassword;
+       }
+
+       @Override
+       public String getUserPasswordRepeat () {
+               return this.userPasswordRepeat;
+       }
+
+       @Override
+       public void setUserPasswordRepeat (final String userPasswordRepeat) {
+               this.userPasswordRepeat = userPasswordRepeat;
+       }
+
+       @Override
+       public boolean hasUsers () {
+               return (!this.allUsers().isEmpty());
+       }
+
+       /**
+        * Post-initialization of this class
+        */
+       @PostConstruct
+       public void init () {
+               // Initialize user list
+               this.userList = this.userBean.allUsers();
+       }
+
+       @Override
+       public User lookupUserById (final Long userId) throws UserNotFoundException {
+               // Parameter must be valid
+               if (null == userId) {
+                       // Throw NPE
+                       throw new NullPointerException("userId is null"); //NOI18N
+               } else if (userId < 1) {
+                       // Not valid
+                       throw new IllegalArgumentException(MessageFormat.format("userId={0} is not valid.", userId)); //NOI18N
+               }
+
+               // Init variable
+               User user = null;
+
+               // Try to lookup it in visible user list
+               for (final Iterator<User> iterator = this.userList.iterator(); iterator.hasNext();) {
+                       // Get next user
+                       User next = iterator.next();
+
+                       // Is the user id found?
+                       if (Objects.equals(next.getUserId(), userId)) {
+                               // Copy to other variable
+                               user = next;
+                               break;
+                       }
+               }
+
+               // Is it still null?
+               if (null == user) {
+                       // Not visible for the current user
+                       throw new UserNotFoundException(userId);
+               }
+
+               // Return it
+               return user;
+       }
+
+       /**
+        * Clears this bean
+        */
+       private void clear () {
+               // Clear all
+               this.setUserName(null);
+               this.setUserPassword(null);
+               this.setUserPasswordRepeat(null);
+       }
+
+       /**
+        * Checks if same password is entered and that they are not empty.
+        * <p>
+        * @return Whether the same password was entered
+        */
+       private boolean isSamePasswordEntered () {
+               return ((!this.getUserPassword().isEmpty()) && (Objects.equals(this.getUserPassword(), this.getUserPasswordRepeat())));
+       }
+
+}
diff --git a/src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebRequestController.java b/src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebRequestController.java
new file mode 100644 (file)
index 0000000..c2e2424
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2016 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.user;
+
+import java.io.Serializable;
+import java.util.List;
+import org.mxchange.jusercore.exceptions.UserNotFoundException;
+import org.mxchange.jusercore.model.user.User;
+
+/**
+ * An interface for user beans
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+public interface AddressbookAdminUserWebRequestController extends Serializable {
+
+       /**
+        * Tries to lookup user by given id number. If the user is not found or the
+        * account status is not CONFIRMED proper exceptions are thrown.
+        * <p>
+        * @param userId User id
+        * <p>
+        * @return User instance
+        * <p>
+        * @throws UserNotFoundException If the user is not found
+        */
+       User lookupUserById (final Long userId) throws UserNotFoundException;
+
+       /**
+        * All users
+        * <p>
+        * @return A list of all public user profiles
+        */
+       List<User> allUsers ();
+
+       /**
+        * Checks whether users are registered
+        * <p>
+        * @return Whether users are registered
+        */
+       boolean hasUsers ();
+
+       /**
+        * Adds user instance to database by preparing a complete user instance and
+        * sending it to the EJB. The data set in the controller is being verified,
+        * e.g. if the user name or email address is not used yet.
+        */
+       void addUser ();
+
+       /**
+        * Getter for user name
+        * <p>
+        * @return User name
+        */
+       String getUserName ();
+
+       /**
+        * Setter for user name
+        * <p>
+        * @param userName User name
+        */
+       void setUserName (final String userName);
+
+       /**
+        * Getter for unencrypted user password
+        * <p>
+        * @return Unencrypted user password
+        */
+       String getUserPassword ();
+
+       /**
+        * Setter for unencrypted user password
+        * <p>
+        * @param userPassword Unencrypted user password
+        */
+       void setUserPassword (final String userPassword);
+
+       /**
+        * Getter for unencrypted user password repeated
+        * <p>
+        * @return Unencrypted user password repeated
+        */
+       String getUserPasswordRepeat ();
+
+       /**
+        * Setter for unencrypted user password repeated
+        * <p>
+        * @param userPasswordRepeat Unencrypted user password repeated
+        */
+       void setUserPasswordRepeat (final String userPasswordRepeat);
+
+}
diff --git a/src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebSessionBean.java b/src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebSessionBean.java
deleted file mode 100644 (file)
index 4173c52..0000000
+++ /dev/null
@@ -1,305 +0,0 @@
-/*
- * Copyright (C) 2016 Roland Haeder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.beans.user;
-
-import java.text.MessageFormat;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Objects;
-import javax.annotation.PostConstruct;
-import javax.enterprise.context.SessionScoped;
-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.contact.Contact;
-import org.mxchange.jusercore.events.user.AdminAddedUserEvent;
-import org.mxchange.jusercore.events.user.AdminUserAddedEvent;
-import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException;
-import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException;
-import org.mxchange.jusercore.exceptions.UserNotFoundException;
-import org.mxchange.jusercore.exceptions.UserPasswordRepeatMismatchException;
-import org.mxchange.jusercore.model.user.LoginUser;
-import org.mxchange.jusercore.model.user.User;
-import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
-import org.mxchange.jusercore.model.user.UserUtils;
-import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
-import org.mxchange.jusercore.model.user.status.UserAccountStatus;
-import org.mxchange.addressbook.beans.contact.AddressbookContactWebSessionController;
-
-/**
- * A user bean (controller)
- * <p>
- * @author Roland Haeder<roland@mxchange.org>
- */
-@Named ("adminUserController")
-@SessionScoped
-public class AddressbookAdminUserWebSessionBean implements AddressbookAdminUserWebSessionController {
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 542_145_347_916L;
-
-       /**
-        * An event fired when the administrator has added a new user
-        */
-       @Inject
-       @Any
-       private Event<AdminAddedUserEvent> addedUserEvent;
-
-       /**
-        * Regular contact controller
-        */
-       @Inject
-       private AddressbookContactWebSessionController contactController;
-
-       /**
-        * Remote user bean
-        */
-       private final UserSessionBeanRemote userBean;
-
-       /**
-        * A list of all user profiles
-        */
-       private List<User> userList;
-
-       /**
-        * User name
-        */
-       private String userName;
-
-       /**
-        * User password (unencrypted from web form)
-        */
-       private String userPassword;
-
-       /**
-        * User password repeated (unencrypted from web form)
-        */
-       private String userPasswordRepeat;
-
-       /**
-<<<<<<< HEAD:src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebSessionBean.java
-        * ZIP code
-        */
-       private Integer zipCode;
-
-       /**
-        * Regular user controller
-        */
-       @Inject
-       private AddressbookUserWebSessionController userController;
-
-       /**
-        * Default constructor
-        */
-       public AddressbookAdminUserWebSessionBean () {
-               // Try it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Try to lookup
-                       this.userBean = (UserSessionBeanRemote) context.lookup("java:global/addressbook-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N
-               } catch (final NamingException e) {
-                       // Throw again
-                       throw new FaceletException(e);
-               }
-       }
-
-       @Override
-       public void addUser () {
-               // Create new user instance
-               User localUser = new LoginUser();
-
-               // Set user name, CONFIRMED and INVISIBLE
-               localUser.setUserName(this.getUserName());
-               localUser.setUserAccountStatus(UserAccountStatus.CONFIRMED);
-               localUser.setUserProfileMode(ProfileMode.INVISIBLE);
-
-               // Create contact instance
-               Contact contact = this.contactController.createContactInstance();
-
-               // Set contact in user
-               localUser.setUserContact(contact);
-
-               // Init variable for password
-               String password = null;
-
-               // Is the user name or email address used already?
-               // @TODO Add password length check
-               if (this.userController.isUserNameRegistered(localUser)) {
-                       // User name is already used
-                       throw new FaceletException(new UserNameAlreadyRegisteredException(localUser));
-               } else if (this.contactController.isEmailAddressRegistered(localUser.getUserContact())) {
-                       // Email address is already used
-                       throw new FaceletException(new EmailAddressAlreadyRegisteredException(localUser));
-               } else if ((this.getUserPassword() == null && (this.getUserPasswordRepeat() == null)) || ((this.getUserPassword().isEmpty()) && (this.getUserPasswordRepeat().isEmpty()))) {
-                       // Empty password entered, then generate one
-                       password = UserUtils.createRandomPassword(AddressbookUserWebSessionController.MINIMUM_PASSWORD_LENGTH);
-               } else if (!this.isSamePasswordEntered()) {
-                       // Both passwords don't match
-                       throw new FaceletException(new UserPasswordRepeatMismatchException(localUser));
-               } else {
-                       // Both match, so get it from this bean
-                       password = this.getUserPassword();
-               }
-
-               // The password should not be null and at least 5 characters long
-               assert (password != null) : "password is null"; //NOI18N
-               assert (password.length() >= AddressbookUserWebSessionController.MINIMUM_PASSWORD_LENGTH) : "Password is not long enough."; //NOI18N
-
-               // Encrypt password and set it
-               localUser.setUserEncryptedPassword(UserUtils.encryptPassword(password));
-
-               // Init updated user instance
-               User updatedUser = null;
-
-               try {
-                       // Now, that all is set, call EJB
-                       updatedUser = this.userBean.addUser(localUser);
-               } catch (final UserNameAlreadyRegisteredException | EmailAddressAlreadyRegisteredException ex) {
-                       // Throw again
-                       throw new FaceletException(ex);
-               }
-
-               // Fire event
-               this.addedUserEvent.fire(new AdminUserAddedEvent(updatedUser));
-
-               // Add user to local list
-               this.userList.add(updatedUser);
-
-               // Clear all
-               this.clear();
-
-               // Clear contact instance
-               this.contactController.clear();
-       }
-
-       @Override
-       public List<User> allUsers () {
-               // Return it
-               return Collections.unmodifiableList(this.userList);
-       }
-
-       @Override
-       public String getUserName () {
-               return this.userName;
-       }
-
-       @Override
-       public void setUserName (final String userName) {
-               this.userName = userName;
-       }
-
-       @Override
-       public String getUserPassword () {
-               return this.userPassword;
-       }
-
-       @Override
-       public void setUserPassword (final String userPassword) {
-               this.userPassword = userPassword;
-       }
-
-       @Override
-       public String getUserPasswordRepeat () {
-               return this.userPasswordRepeat;
-       }
-
-       @Override
-       public void setUserPasswordRepeat (final String userPasswordRepeat) {
-               this.userPasswordRepeat = userPasswordRepeat;
-       }
-
-       @Override
-       public boolean hasUsers () {
-               return (!this.allUsers().isEmpty());
-       }
-
-       /**
-        * Post-initialization of this class
-        */
-       @PostConstruct
-       public void init () {
-               // Initialize user list
-               this.userList = this.userBean.allUsers();
-       }
-
-       @Override
-       public User lookupUserById (final Long userId) throws UserNotFoundException {
-               // Parameter must be valid
-               if (null == userId) {
-                       // Throw NPE
-                       throw new NullPointerException("userId is null"); //NOI18N
-               } else if (userId < 1) {
-                       // Not valid
-                       throw new IllegalArgumentException(MessageFormat.format("userId={0} is not valid.", userId)); //NOI18N
-               }
-
-               // Init variable
-               User user = null;
-
-               // Try to lookup it in visible user list
-               for (final Iterator<User> iterator = this.userList.iterator(); iterator.hasNext();) {
-                       // Get next user
-                       User next = iterator.next();
-
-                       // Is the user id found?
-                       if (Objects.equals(next.getUserId(), userId)) {
-                               // Copy to other variable
-                               user = next;
-                               break;
-                       }
-               }
-
-               // Is it still null?
-               if (null == user) {
-                       // Not visible for the current user
-                       throw new UserNotFoundException(userId);
-               }
-
-               // Return it
-               return user;
-       }
-
-       /**
-        * Clears this bean
-        */
-       private void clear () {
-               // Clear all
-               this.setUserName(null);
-               this.setUserPassword(null);
-               this.setUserPasswordRepeat(null);
-       }
-
-       /**
-        * Checks if same password is entered and that they are not empty.
-        * <p>
-        * @return Whether the same password was entered
-        */
-       private boolean isSamePasswordEntered () {
-               return ((!this.getUserPassword().isEmpty()) && (Objects.equals(this.getUserPassword(), this.getUserPasswordRepeat())));
-       }
-
-}
diff --git a/src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebSessionController.java b/src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebSessionController.java
deleted file mode 100644 (file)
index 979276d..0000000
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright (C) 2016 Roland Haeder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.beans.user;
-
-import java.io.Serializable;
-import java.util.List;
-import org.mxchange.jusercore.exceptions.UserNotFoundException;
-import org.mxchange.jusercore.model.user.User;
-
-/**
- * An interface for user beans
- * <p>
- * @author Roland Haeder<roland@mxchange.org>
- */
-public interface AddressbookAdminUserWebSessionController extends Serializable {
-
-       /**
-        * Tries to lookup user by given id number. If the user is not found or the
-        * account status is not CONFIRMED proper exceptions are thrown.
-        * <p>
-        * @param userId User id
-        * <p>
-        * @return User instance
-        * <p>
-        * @throws UserNotFoundException If the user is not found
-        */
-       User lookupUserById (final Long userId) throws UserNotFoundException;
-
-       /**
-        * All users
-        * <p>
-        * @return A list of all public user profiles
-        */
-       List<User> allUsers ();
-
-       /**
-        * Checks whether users are registered
-        * <p>
-        * @return Whether users are registered
-        */
-       boolean hasUsers ();
-
-       /**
-        * Adds user instance to database by preparing a complete user instance and
-        * sending it to the EJB. The data set in the controller is being verified,
-        * e.g. if the user name or email address is not used yet.
-        */
-       void addUser ();
-
-       /**
-        * Getter for user name
-        * <p>
-        * @return User name
-        */
-       String getUserName ();
-
-       /**
-        * Setter for user name
-        * <p>
-        * @param userName User name
-        */
-       void setUserName (final String userName);
-
-       /**
-        * Getter for unencrypted user password
-        * <p>
-        * @return Unencrypted user password
-        */
-       String getUserPassword ();
-
-       /**
-        * Setter for unencrypted user password
-        * <p>
-        * @param userPassword Unencrypted user password
-        */
-       void setUserPassword (final String userPassword);
-
-       /**
-        * Getter for unencrypted user password repeated
-        * <p>
-        * @return Unencrypted user password repeated
-        */
-       String getUserPasswordRepeat ();
-
-       /**
-        * Setter for unencrypted user password repeated
-        * <p>
-        * @param userPasswordRepeat Unencrypted user password repeated
-        */
-       void setUserPasswordRepeat (final String userPasswordRepeat);
-
-}
index 6282bdd5abf02d548e5855daae908e2f5a2f8e51..402c21e4ec89c223f4a191c2a5fd9265ff70a769 100644 (file)
@@ -30,6 +30,8 @@ import javax.inject.Named;
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
+import org.mxchange.addressbook.beans.contact.AddressbookContactWebSessionController;
+import org.mxchange.addressbook.beans.login.AddressbookUserLoginWebSessionController;
 import org.mxchange.jcontacts.contact.Contact;
 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
@@ -37,13 +39,11 @@ import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
 import org.mxchange.jusercore.events.login.UserLoggedInEvent;
 import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
 import org.mxchange.jusercore.exceptions.UserNotFoundException;
+import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
 import org.mxchange.jusercore.model.user.LoginUser;
 import org.mxchange.jusercore.model.user.User;
 import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
 import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
-import org.mxchange.addressbook.beans.login.AddressbookUserLoginWebSessionController;
-import org.mxchange.addressbook.beans.contact.AddressbookContactWebSessionController;
-import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
 
 /**
  * A user bean (controller)