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=42422ce2e2b62347eefc1617076047e07cbdcc61;p=jjobs-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/src/java/org/mxchange/jjobs/beans/country/JobsAdminCountryWebApplicationBean.java b/src/java/org/mxchange/jjobs/beans/country/JobsAdminCountryWebApplicationBean.java deleted file mode 100644 index c6f4f684..00000000 --- a/src/java/org/mxchange/jjobs/beans/country/JobsAdminCountryWebApplicationBean.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.jjobs.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 JobsAdminCountryWebApplicationBean implements JobsAdminCountryWebApplicationController { - - /** - * 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 JobsCountryWebApplicationController 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 JobsAdminCountryWebApplicationBean () { - // Try this - try { - // Get initial context - Context context = new InitialContext(); - - // Try to lookup the bean - this.countryBean = (CountrySingletonBeanRemote) context.lookup("java:global/jjobs-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/jjobs/beans/country/JobsAdminCountryWebApplicationController.java b/src/java/org/mxchange/jjobs/beans/country/JobsAdminCountryWebApplicationController.java deleted file mode 100644 index ad4dc467..00000000 --- a/src/java/org/mxchange/jjobs/beans/country/JobsAdminCountryWebApplicationController.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.jjobs.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 JobsAdminCountryWebApplicationController 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/jjobs/beans/country/JobsAdminCountryWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/country/JobsAdminCountryWebRequestBean.java new file mode 100644 index 00000000..eed8f3b2 --- /dev/null +++ b/src/java/org/mxchange/jjobs/beans/country/JobsAdminCountryWebRequestBean.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.jjobs.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 JobsAdminCountryWebRequestBean implements JobsAdminCountryWebRequestController { + + /** + * 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 JobsCountryWebApplicationController 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 JobsAdminCountryWebRequestBean () { + // Try this + try { + // Get initial context + Context context = new InitialContext(); + + // Try to lookup the bean + this.countryBean = (CountrySingletonBeanRemote) context.lookup("java:global/jjobs-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/jjobs/beans/country/JobsAdminCountryWebRequestController.java b/src/java/org/mxchange/jjobs/beans/country/JobsAdminCountryWebRequestController.java new file mode 100644 index 00000000..f0ab5012 --- /dev/null +++ b/src/java/org/mxchange/jjobs/beans/country/JobsAdminCountryWebRequestController.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.jjobs.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 JobsAdminCountryWebRequestController 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/jjobs/beans/helper/JobsAdminWebRequestHelper.java b/src/java/org/mxchange/jjobs/beans/helper/JobsAdminWebRequestHelper.java index 4b88e563..37f91756 100644 --- a/src/java/org/mxchange/jjobs/beans/helper/JobsAdminWebRequestHelper.java +++ b/src/java/org/mxchange/jjobs/beans/helper/JobsAdminWebRequestHelper.java @@ -22,8 +22,8 @@ import javax.inject.Inject; import javax.inject.Named; import org.mxchange.jcontacts.contact.Contact; import org.mxchange.jjobs.beans.contact.JobsAdminContactWebRequestController; -import org.mxchange.jusercore.model.user.User; import org.mxchange.jjobs.beans.user.JobsAdminUserWebRequestController; +import org.mxchange.jusercore.model.user.User; /** * A general helper for beans diff --git a/src/java/org/mxchange/jjobs/beans/phone/JobsAdminContactPhoneWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/phone/JobsAdminContactPhoneWebSessionBean.java index e54617fb..4f4bfe02 100644 --- a/src/java/org/mxchange/jjobs/beans/phone/JobsAdminContactPhoneWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/phone/JobsAdminContactPhoneWebSessionBean.java @@ -19,7 +19,7 @@ package org.mxchange.jjobs.beans.phone; import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.enterprise.context.SessionScoped; +import javax.enterprise.context.RequestScoped; import javax.faces.view.facelets.FaceletException; import javax.inject.Named; import javax.naming.Context; @@ -37,7 +37,7 @@ import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; * @author Roland Haeder */ @Named ("adminContactPhoneController") -@SessionScoped +@RequestScoped public class JobsAdminContactPhoneWebSessionBean implements JobsAdminContactPhoneWebSessionController { /** diff --git a/src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestBean.java index b58623e1..11363c2c 100644 --- a/src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestBean.java @@ -22,7 +22,7 @@ import java.util.Iterator; import java.util.List; import java.util.Objects; import javax.annotation.PostConstruct; -import javax.enterprise.context.SessionScoped; +import javax.enterprise.context.RequestScoped; import javax.enterprise.event.Event; import javax.enterprise.inject.Any; import javax.faces.view.facelets.FaceletException; @@ -52,7 +52,7 @@ import org.mxchange.jusercore.model.user.status.UserAccountStatus; * @author Roland Haeder */ @Named ("adminUserController") -@SessionScoped +@RequestScoped public class JobsAdminUserWebRequestBean implements JobsAdminUserWebRequestController { /**