From: Roland Haeder Date: Mon, 11 Apr 2016 16:36:38 +0000 (+0200) Subject: Moved to proper package and fixed interface name from pizzaservice-war cherry-pick X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=21de16b07d7036668c1ab0083f605d0ac1c347a2;p=addressbook-war.git Moved to proper package and fixed interface name from pizzaservice-war cherry-pick --- diff --git a/src/java/org/mxchange/addressbook/beans/country/AddressbookAdminCountryWebApplicationBean.java b/src/java/org/mxchange/addressbook/beans/country/AddressbookAdminCountryWebApplicationBean.java new file mode 100644 index 00000000..d342b319 --- /dev/null +++ b/src/java/org/mxchange/addressbook/beans/country/AddressbookAdminCountryWebApplicationBean.java @@ -0,0 +1,256 @@ +/* + * 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.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.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; + + /** + * 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/PizzaService-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)); + } + + try { + // Send country to bean + this.countryBean.addCountry(country); + + // Clear bean + this.clear(); + } catch (final CountryAlreadyAddedException ex) { + // Throw again + throw new FaceletException(ex); + } + } + + @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 new file mode 100644 index 00000000..03980806 --- /dev/null +++ b/src/java/org/mxchange/addressbook/beans/country/AddressbookAdminCountryWebApplicationController.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 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/pizzaapplication/beans/country/PizzaAdminCountryWebApplicationBean.java b/src/java/org/mxchange/pizzaapplication/beans/country/PizzaAdminCountryWebApplicationBean.java deleted file mode 100644 index e3663743..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/country/PizzaAdminCountryWebApplicationBean.java +++ /dev/null @@ -1,256 +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.pizzaapplication.beans.country; - -import java.util.Iterator; -import java.util.List; -import java.util.Objects; -import javax.enterprise.context.ApplicationScoped; -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.exceptions.CountryAlreadyAddedException; - -/** - * An administrative country bean - *

- * @author Roland Haeder - */ -@Named ("adminCountryController") -@ApplicationScoped -public class PizzaAdminCountryWebApplicationBean implements PizzaAdminCountryWebApplicationController { - - /** - * Serial number - */ - private static final long serialVersionUID = 18_598_175_719_603L; - - /** - * Abroad dial prefix - */ - private String countryAbroadDialPrefix; - - /** - * Remote country EJB - */ - private CountrySingletonBeanRemote countryBean; - - /** - * 2-letter country code - */ - private String countryCode; - - /** - * Regular country controller - */ - @Inject - private PizzaCountryWebApplicationController 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 PizzaAdminCountryWebApplicationBean () { - // Try this - try { - // Get initial context - Context context = new InitialContext(); - - // Try to lookup the bean - this.countryBean = (CountrySingletonBeanRemote) context.lookup("java:global/PizzaService-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)); - } - - try { - // Send country to bean - this.countryBean.addCountry(country); - - // Clear bean - this.clear(); - } catch (final CountryAlreadyAddedException ex) { - // Throw again - throw new FaceletException(ex); - } - } - - @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/pizzaapplication/beans/country/PizzaAdminCountryWebApplicationController.java b/src/java/org/mxchange/pizzaapplication/beans/country/PizzaAdminCountryWebApplicationController.java deleted file mode 100644 index 40b581ea..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/country/PizzaAdminCountryWebApplicationController.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.pizzaapplication.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 PizzaAdminCountryWebApplicationController 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); - -}