From: Roland Häder Date: Wed, 20 Apr 2016 14:45:09 +0000 (+0200) Subject: Continued a bit: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=8e326aa59f6193d7bda1669b7a9a9ca42652fd3d;p=jfinancials-war.git Continued a bit: - moved all admin controllers from session-scope to request-scope - renamed them, too Signed-off-by: Roland Häder --- diff --git a/nbproject/faces-config.NavData b/nbproject/faces-config.NavData index 0fa75d50..644e41ad 100644 --- a/nbproject/faces-config.NavData +++ b/nbproject/faces-config.NavData @@ -2,61 +2,61 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - + + + + + 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 index 5b5be64c..00000000 --- a/src/java/org/mxchange/addressbook/beans/country/AddressbookAdminCountryWebApplicationBean.java +++ /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 . - */ -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 - *

- * @author Roland Haeder - */ -@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 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 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. - *

- * @param country Country instance to look for - *

- * @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 countries = this.countryController.allCountries(); - - // Get iterator from it - Iterator 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 index 03980806..00000000 --- a/src/java/org/mxchange/addressbook/beans/country/AddressbookAdminCountryWebApplicationController.java +++ /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 . - */ -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 - *

- * @author Roland Haeder - */ -public interface AddressbookAdminCountryWebApplicationController extends Serializable { - - /** - * A list of all countries - *

- * @return All countries - */ - List allCountries (); - - /** - * Adds country to all relevant beans and sends it to the EJB. - */ - void addCountry (); - - /** - * Checks whether countries has been registered - *

- * @return Whether countries has been registered - */ - boolean hasCountries (); - - /** - * Getter for abroad dial prefix - *

- * @return Abroad dial prefix - */ - String getCountryAbroadDialPrefix (); - - /** - * Setter for abroad dial prefix - *

- * @param countryAbroadDialPrefix Abroad dial prefix - */ - void setCountryAbroadDialPrefix (final String countryAbroadDialPrefix); - - /** - * Getter for 2-characters country code - *

- * @return Country code - */ - String getCountryCode (); - - /** - * Setter for 2-characters country code - *

- * @param countryCode Country code - */ - void setCountryCode (final String countryCode); - - /** - * Getter for i18n key for country name - *

- * @return i18n key for country name - */ - String getCountryI18nKey (); - - /** - * Setter for i18n key for country name - *

- * @param countryI18nKey i18n key for country name - */ - void setCountryI18nKey (final String countryI18nKey); - - /** - * Getter for whether the local dial prefix is required for local calls - *

- * @return Whether the local dial prefix is required - */ - Boolean getCountryIsLocalPrefixRequired (); - - /** - * Setter for whether the local dial prefix is required for local calls - *

- * @param countryIsLocalPrefixRequired Whether the local dial prefix is - * required - */ - void setCountryIsLocalPrefixRequired (final Boolean countryIsLocalPrefixRequired); - - /** - * Getter for external dial prefix - *

- * @return External dial prefix - */ - String getCountryExternalDialPrefix (); - - /** - * Setter for external dial prefix - *

- * @param countryExternalDialPrefix External dial prefix - */ - void setCountryExternalDialPrefix (final String countryExternalDialPrefix); - - /** - * Getter for country code (example: 49 for Germany, 63 for Philippines) - *

- * @return Dial number without prefix - */ - Short getCountryPhoneCode (); - - /** - * Setter for country code (example: 49 for Germany, 63 for Philippines) - *

- * @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 index 00000000..baac32d4 --- /dev/null +++ b/src/java/org/mxchange/addressbook/beans/country/AddressbookAdminCountryWebRequestBean.java @@ -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 . + */ +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 + *

+ * @author Roland Haeder + */ +@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 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 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. + *

+ * @param country Country instance to look for + *

+ * @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 countries = this.countryController.allCountries(); + + // Get iterator from it + Iterator 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 index 00000000..061baa46 --- /dev/null +++ b/src/java/org/mxchange/addressbook/beans/country/AddressbookAdminCountryWebRequestController.java @@ -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 . + */ +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 + *

+ * @author Roland Haeder + */ +public interface AddressbookAdminCountryWebRequestController extends Serializable { + + /** + * A list of all countries + *

+ * @return All countries + */ + List allCountries (); + + /** + * Adds country to all relevant beans and sends it to the EJB. + */ + void addCountry (); + + /** + * Checks whether countries has been registered + *

+ * @return Whether countries has been registered + */ + boolean hasCountries (); + + /** + * Getter for abroad dial prefix + *

+ * @return Abroad dial prefix + */ + String getCountryAbroadDialPrefix (); + + /** + * Setter for abroad dial prefix + *

+ * @param countryAbroadDialPrefix Abroad dial prefix + */ + void setCountryAbroadDialPrefix (final String countryAbroadDialPrefix); + + /** + * Getter for 2-characters country code + *

+ * @return Country code + */ + String getCountryCode (); + + /** + * Setter for 2-characters country code + *

+ * @param countryCode Country code + */ + void setCountryCode (final String countryCode); + + /** + * Getter for i18n key for country name + *

+ * @return i18n key for country name + */ + String getCountryI18nKey (); + + /** + * Setter for i18n key for country name + *

+ * @param countryI18nKey i18n key for country name + */ + void setCountryI18nKey (final String countryI18nKey); + + /** + * Getter for whether the local dial prefix is required for local calls + *

+ * @return Whether the local dial prefix is required + */ + Boolean getCountryIsLocalPrefixRequired (); + + /** + * Setter for whether the local dial prefix is required for local calls + *

+ * @param countryIsLocalPrefixRequired Whether the local dial prefix is + * required + */ + void setCountryIsLocalPrefixRequired (final Boolean countryIsLocalPrefixRequired); + + /** + * Getter for external dial prefix + *

+ * @return External dial prefix + */ + String getCountryExternalDialPrefix (); + + /** + * Setter for external dial prefix + *

+ * @param countryExternalDialPrefix External dial prefix + */ + void setCountryExternalDialPrefix (final String countryExternalDialPrefix); + + /** + * Getter for country code (example: 49 for Germany, 63 for Philippines) + *

+ * @return Dial number without prefix + */ + Short getCountryPhoneCode (); + + /** + * Setter for country code (example: 49 for Germany, 63 for Philippines) + *

+ * @param countryPhoneCode Country code + */ + void setCountryPhoneCode (final Short countryPhoneCode); + +} diff --git a/src/java/org/mxchange/addressbook/beans/helper/AddressbookAdminWebRequestHelper.java b/src/java/org/mxchange/addressbook/beans/helper/AddressbookAdminWebRequestHelper.java index 0f45c175..9c599d16 100644 --- a/src/java/org/mxchange/addressbook/beans/helper/AddressbookAdminWebRequestHelper.java +++ b/src/java/org/mxchange/addressbook/beans/helper/AddressbookAdminWebRequestHelper.java @@ -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 index 00000000..7ba2f6c3 --- /dev/null +++ b/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebRequestBean.java @@ -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 . + */ +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 + *

+ * @author Roland Haeder + */ +@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> 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 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 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 index 00000000..04af7f01 --- /dev/null +++ b/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebRequestController.java @@ -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 . + */ +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. + *

+ * @author Roland Haeder + */ +public interface AddressbookAdminContactPhoneWebRequestController extends Serializable { + + /** + * Getter for all contacts having current cellphone instance linked + *

+ * @return List of all linked contacts + */ + List allCellphoneContacts (); + + /** + * Getter for dialable cellphone number instance + *

+ * @return Dialable cellphone number instance + */ + DialableCellphoneNumber getCellPhone (); + + /** + * Setter for dialable land-line number instance + *

+ * @param landLine Dialable land-line number instance + */ + void setLandLine (final DialableLandLineNumber landLine); + + /** + * Getter for dialable land-line number instance + *

+ * @return Dialable land-line number instance + */ + DialableLandLineNumber getLandLine (); + + /** + * Setter for dialable fax number instance + *

+ * @param fax Dialable fax number instance + */ + void setFax (final DialableFaxNumber fax); + + /** + * Getter for dialable fax number instance + *

+ * @return Dialable fax number instance + */ + DialableFaxNumber getFax (); + + /** + * Setter for dialable cellphone number instance + *

+ * @param cellPhone Dialable cellphone number instance + */ + void setCellPhone (final DialableCellphoneNumber cellPhone); + + /** + * Getter for linked contact account + *

+ * @return Linked contact account + */ + Contact getContact (); + + /** + * Setter for linked contact account + *

+ * @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 index 2d6718bf..00000000 --- a/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebSessionBean.java +++ /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 . - */ -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 - *

- * @author Roland Haeder - */ -@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> 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 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 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 index b9442338..00000000 --- a/src/java/org/mxchange/addressbook/beans/phone/AddressbookAdminContactPhoneWebSessionController.java +++ /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 . - */ -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. - *

- * @author Roland Haeder - */ -public interface AddressbookAdminContactPhoneWebSessionController extends Serializable { - - /** - * Getter for all contacts having current cellphone instance linked - *

- * @return List of all linked contacts - */ - List allCellphoneContacts (); - - /** - * Getter for dialable cellphone number instance - *

- * @return Dialable cellphone number instance - */ - DialableCellphoneNumber getCellPhone (); - - /** - * Setter for dialable land-line number instance - *

- * @param landLine Dialable land-line number instance - */ - void setLandLine (final DialableLandLineNumber landLine); - - /** - * Getter for dialable land-line number instance - *

- * @return Dialable land-line number instance - */ - DialableLandLineNumber getLandLine (); - - /** - * Setter for dialable fax number instance - *

- * @param fax Dialable fax number instance - */ - void setFax (final DialableFaxNumber fax); - - /** - * Getter for dialable fax number instance - *

- * @return Dialable fax number instance - */ - DialableFaxNumber getFax (); - - /** - * Setter for dialable cellphone number instance - *

- * @param cellPhone Dialable cellphone number instance - */ - void setCellPhone (final DialableCellphoneNumber cellPhone); - - /** - * Getter for linked contact account - *

- * @return Linked contact account - */ - Contact getContact (); - - /** - * Setter for linked contact account - *

- * @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 index 00000000..eae1bfe8 --- /dev/null +++ b/src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebRequestBean.java @@ -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 . + */ +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) + *

+ * @author Roland Haeder + */ +@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 addedUserEvent; + + /** + * Regular contact controller + */ + @Inject + private AddressbookContactWebSessionController contactController; + + /** + * Remote user bean + */ + private final UserSessionBeanRemote userBean; + + /** + * A list of all user profiles + */ + private List 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 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 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. + *

+ * @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 index 00000000..c2e24241 --- /dev/null +++ b/src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebRequestController.java @@ -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 . + */ +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 + *

+ * @author Roland Haeder + */ +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. + *

+ * @param userId User id + *

+ * @return User instance + *

+ * @throws UserNotFoundException If the user is not found + */ + User lookupUserById (final Long userId) throws UserNotFoundException; + + /** + * All users + *

+ * @return A list of all public user profiles + */ + List allUsers (); + + /** + * Checks whether users are registered + *

+ * @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 + *

+ * @return User name + */ + String getUserName (); + + /** + * Setter for user name + *

+ * @param userName User name + */ + void setUserName (final String userName); + + /** + * Getter for unencrypted user password + *

+ * @return Unencrypted user password + */ + String getUserPassword (); + + /** + * Setter for unencrypted user password + *

+ * @param userPassword Unencrypted user password + */ + void setUserPassword (final String userPassword); + + /** + * Getter for unencrypted user password repeated + *

+ * @return Unencrypted user password repeated + */ + String getUserPasswordRepeat (); + + /** + * Setter for unencrypted user password repeated + *

+ * @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 index 4173c524..00000000 --- a/src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebSessionBean.java +++ /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 . - */ -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) - *

- * @author Roland Haeder - */ -@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 addedUserEvent; - - /** - * Regular contact controller - */ - @Inject - private AddressbookContactWebSessionController contactController; - - /** - * Remote user bean - */ - private final UserSessionBeanRemote userBean; - - /** - * A list of all user profiles - */ - private List 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 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 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. - *

- * @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 index 979276d2..00000000 --- a/src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebSessionController.java +++ /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 . - */ -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 - *

- * @author Roland Haeder - */ -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. - *

- * @param userId User id - *

- * @return User instance - *

- * @throws UserNotFoundException If the user is not found - */ - User lookupUserById (final Long userId) throws UserNotFoundException; - - /** - * All users - *

- * @return A list of all public user profiles - */ - List allUsers (); - - /** - * Checks whether users are registered - *

- * @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 - *

- * @return User name - */ - String getUserName (); - - /** - * Setter for user name - *

- * @param userName User name - */ - void setUserName (final String userName); - - /** - * Getter for unencrypted user password - *

- * @return Unencrypted user password - */ - String getUserPassword (); - - /** - * Setter for unencrypted user password - *

- * @param userPassword Unencrypted user password - */ - void setUserPassword (final String userPassword); - - /** - * Getter for unencrypted user password repeated - *

- * @return Unencrypted user password repeated - */ - String getUserPasswordRepeat (); - - /** - * Setter for unencrypted user password repeated - *

- * @param userPasswordRepeat Unencrypted user password repeated - */ - void setUserPasswordRepeat (final String userPasswordRepeat); - -} diff --git a/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java b/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java index 6282bdd5..402c21e4 100644 --- a/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java +++ b/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java @@ -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)