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=7cce5b421ddba1faf3c88d6d5ddf2571ade9331e;p=pizzaservice-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 ab2141a7..baa26860 100644 --- a/nbproject/faces-config.NavData +++ b/nbproject/faces-config.NavData @@ -2,51 +2,51 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/java/org/mxchange/jratecalc/beans/contact/PizzaAdminContactWebRequestBean.java b/src/java/org/mxchange/jratecalc/beans/contact/PizzaAdminContactWebRequestBean.java deleted file mode 100644 index 786c84e0..00000000 --- a/src/java/org/mxchange/jratecalc/beans/contact/PizzaAdminContactWebRequestBean.java +++ /dev/null @@ -1,506 +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.jratecalc.beans.contact; - -import java.text.MessageFormat; -import java.util.Date; -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.jcontacts.contact.ContactSessionBeanRemote; -import org.mxchange.jcontacts.contact.gender.Gender; -import org.mxchange.jcountry.data.Country; -import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider; -import org.mxchange.jusercore.events.user.AdminAddedUserEvent; - -/** - * A user bean (controller) - *

- * @author Roland Haeder - */ -@Named ("adminContactController") -@RequestScoped -public class PizzaAdminContactWebRequestBean implements PizzaAdminContactWebRequestController { - - /** - * 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; - - /** - * Birth day - */ - private Date birthday; - - /** - * Cellphone number's carrier - */ - private MobileProvider cellphoneCarrier; - - /** - * Cellphone id number - */ - private Long cellphoneId; - - /** - * Cellphone number - */ - private Long cellphoneNumber; - - /** - * City - */ - private String city; - - /** - * Optional comments - */ - private String comment; - - /** - * Remote contact bean - */ - private final ContactSessionBeanRemote contactBean; - - /** - * Contact id - */ - private Long contactId; - - /** - * Country instance - */ - private Country country; - - /** - * Email address - */ - private String emailAddress; - - /** - * Family name - */ - private String familyName; - - /** - * Fax number's area code - */ - private Integer faxAreaCode; - - /** - * Country instance for fax number - */ - private Country faxCountry; - - /** - * Fax id number - */ - private Long faxId; - - /** - * Fax number - */ - private Long faxNumber; - - /** - * First name - */ - private String firstName; - - /** - * Gender instance - */ - private Gender gender; - - /** - * House number - */ - private Short houseNumber; - - /** - * Land-line id number - */ - private Long landLineId; - - /** - * Phone number area code - */ - private Integer phoneAreaCode; - - /** - * Country instance for phone number - */ - private Country phoneCountry; - - /** - * Phone number - */ - private Long phoneNumber; - - /** - * Street - */ - private String street; - - /** - * ZIP code - */ - private Integer zipCode; - - /** - * Default constructor - */ - public PizzaAdminContactWebRequestBean () { - // Set gender to UNKNOWN - this.gender = Gender.UNKNOWN; - - // Try it - try { - // Get initial context - Context context = new InitialContext(); - - // Try to lookup - this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jratecalc-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N - } catch (final NamingException e) { - // Throw again - throw new FaceletException(e); - } - } - - @Override - public void copyContactToController (final Contact contact) { - // The contact instance must be valid - if (null == contact) { - // Throw NPE again - throw new NullPointerException("this.user.userContact is null"); - } else if (contact.getContactId() < 1) { - // Not valid - throw new IllegalStateException(MessageFormat.format("this.user.userContact.contactId={0} is not valid.", contact.getContactId())); - } - - // Set all fields: contact - this.setContactId(contact.getContactId()); - this.setBirthday(contact.getContactBirthday()); - this.setCity(contact.getContactCity()); - this.setComment(contact.getContactComment()); - this.setCountry(contact.getContactCountry()); - this.setEmailAddress(contact.getContactEmailAddress()); - this.setFamilyName(contact.getContactFamilyName()); - this.setFirstName(contact.getContactFirstName()); - this.setGender(contact.getContactGender()); - this.setHouseNumber(contact.getContactHouseNumber()); - this.setStreet(contact.getContactStreet()); - this.setZipCode(contact.getContactZipCode()); - - // ... cellphone data - this.setCellphoneId(contact.getContactCellphoneNumber().getPhoneId()); - this.setCellphoneCarrier(contact.getContactCellphoneNumber().getCellphoneProvider()); - this.setCellphoneNumber(contact.getContactCellphoneNumber().getPhoneNumber()); - - // ... fax data - this.setFaxId(contact.getContactFaxNumber().getPhoneId()); - this.setFaxAreaCode(contact.getContactFaxNumber().getPhoneAreaCode()); - this.setFaxCountry(contact.getContactFaxNumber().getPhoneCountry()); - this.setFaxNumber(contact.getContactFaxNumber().getPhoneNumber()); - - // .. land-line data - this.setLandLineId(contact.getContactLandLineNumber().getPhoneId()); - this.setPhoneAreaCode(contact.getContactLandLineNumber().getPhoneAreaCode()); - this.setPhoneCountry(contact.getContactLandLineNumber().getPhoneCountry()); - this.setPhoneNumber(contact.getContactLandLineNumber().getPhoneNumber()); - } - - @Override - public Date getBirthday () { - return this.birthday; - } - - @Override - public void setBirthday (final Date birthday) { - this.birthday = birthday; - } - - @Override - public MobileProvider getCellphoneCarrier () { - return this.cellphoneCarrier; - } - - @Override - public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) { - this.cellphoneCarrier = cellphoneCarrier; - } - - @Override - public Long getCellphoneId () { - return this.cellphoneId; - } - - @Override - public void setCellphoneId (final Long cellphoneId) { - this.cellphoneId = cellphoneId; - } - - @Override - public Long getCellphoneNumber () { - return this.cellphoneNumber; - } - - @Override - public void setCellphoneNumber (Long cellphoneNumber) { - this.cellphoneNumber = cellphoneNumber; - } - - @Override - public String getCity () { - return this.city; - } - - @Override - public void setCity (final String city) { - this.city = city; - } - - @Override - public String getComment () { - return this.comment; - } - - @Override - public void setComment (final String comment) { - this.comment = comment; - } - - @Override - public Long getContactId () { - return this.contactId; - } - - @Override - public void setContactId (final Long contactId) { - this.contactId = contactId; - } - - @Override - public Country getCountry () { - return this.country; - } - - @Override - public void setCountry (final Country country) { - this.country = country; - } - - @Override - public String getEmailAddress () { - return this.emailAddress; - } - - @Override - public void setEmailAddress (final String emailAddress) { - this.emailAddress = emailAddress; - } - - @Override - public String getFamilyName () { - return this.familyName; - } - - @Override - public void setFamilyName (final String familyName) { - this.familyName = familyName; - } - - @Override - public Integer getFaxAreaCode () { - return this.faxAreaCode; - } - - @Override - public void setFaxAreaCode (final Integer faxAreaCode) { - this.faxAreaCode = faxAreaCode; - } - - @Override - public Country getFaxCountry () { - return this.faxCountry; - } - - @Override - public void setFaxCountry (final Country faxCountry) { - this.faxCountry = faxCountry; - } - - @Override - public Long getFaxId () { - return this.faxId; - } - - @Override - public void setFaxId (final Long faxId) { - this.faxId = faxId; - } - - @Override - public Long getFaxNumber () { - return this.faxNumber; - } - - @Override - public void setFaxNumber (final Long faxNumber) { - this.faxNumber = faxNumber; - } - - @Override - public String getFirstName () { - return this.firstName; - } - - @Override - public void setFirstName (final String firstName) { - this.firstName = firstName; - } - - @Override - public Gender getGender () { - return this.gender; - } - - @Override - public void setGender (final Gender gender) { - this.gender = gender; - } - - @Override - public Short getHouseNumber () { - return this.houseNumber; - } - - @Override - public void setHouseNumber (final Short houseNumber) { - this.houseNumber = houseNumber; - } - - @Override - public Long getLandLineId () { - return this.landLineId; - } - - @Override - public void setLandLineId (final Long landLineId) { - this.landLineId = landLineId; - } - - @Override - public Integer getPhoneAreaCode () { - return this.phoneAreaCode; - } - - @Override - public void setPhoneAreaCode (final Integer phoneAreaCode) { - this.phoneAreaCode = phoneAreaCode; - } - - @Override - public Country getPhoneCountry () { - return this.phoneCountry; - } - - @Override - public void setPhoneCountry (final Country phoneCountry) { - this.phoneCountry = phoneCountry; - } - - @Override - public Long getPhoneNumber () { - return this.phoneNumber; - } - - @Override - public void setPhoneNumber (final Long phoneNumber) { - this.phoneNumber = phoneNumber; - } - - @Override - public String getStreet () { - return this.street; - } - - @Override - public void setStreet (final String street) { - this.street = street; - } - - @Override - public Integer getZipCode () { - return this.zipCode; - } - - @Override - public void setZipCode (final Integer zipCode) { - this.zipCode = zipCode; - } - - /** - * Post-initialization of this class - */ - @PostConstruct - public void init () { - } - - /** - * Clears this bean - */ - private void clear () { - // Clear all - this.setContactId(null); - this.setBirthday(null); - this.setCellphoneCarrier(null); - this.setCellphoneNumber(null); - this.setCity(null); - this.setComment(null); - this.setCountry(null); - this.setEmailAddress(null); - this.setFamilyName(null); - this.setFaxAreaCode(null); - this.setFaxCountry(null); - this.setFaxNumber(null); - this.setFirstName(null); - this.setGender(null); - this.setHouseNumber(null); - this.setPhoneAreaCode(null); - this.setPhoneCountry(null); - this.setPhoneNumber(null); - this.setStreet(null); - this.setZipCode(null); - } - -} diff --git a/src/java/org/mxchange/jratecalc/beans/contact/PizzaAdminContactWebRequestController.java b/src/java/org/mxchange/jratecalc/beans/contact/PizzaAdminContactWebRequestController.java deleted file mode 100644 index d6d6fbd2..00000000 --- a/src/java/org/mxchange/jratecalc/beans/contact/PizzaAdminContactWebRequestController.java +++ /dev/null @@ -1,362 +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.jratecalc.beans.contact; - -import java.io.Serializable; -import java.util.Date; -import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jcontacts.contact.gender.Gender; -import org.mxchange.jcountry.data.Country; -import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider; - -/** - * An administrative interface for user beans - *

- * @author Roland Haeder - */ -public interface PizzaAdminContactWebRequestController extends Serializable { - - /** - * Copies given contact's data to this controller - *

- * @param contact Contact instance - */ - void copyContactToController (final Contact contact); - - /** - * Getter for cellphone id - *

- * @return Cellphone id - */ - Long getCellphoneId (); - - /** - * Setter for cellphone id - *

- * @param cellphoneId Cellphone id - */ - void setCellphoneId (final Long cellphoneId); - - /** - * Getter for fax id - *

- * @return Fax id - */ - Long getFaxId (); - - /** - * Setter for fax id - *

- * @param faxId Fax id - */ - void setFaxId (final Long faxId); - - /** - * Getter for land-line id - *

- * @return Land-line id - */ - Long getLandLineId (); - - /** - * Setter for land-line id - *

- * @param landLineId Land-line id - */ - void setLandLineId (final Long landLineId); - - /** - * Getter for birth day - *

- * @return Birth day - */ - Date getBirthday (); - - /** - * Setter for birth day - *

- * @param birthday Birth day - */ - void setBirthday (final Date birthday); - - /** - * Getter for ellphone number's carrier - *

- * @return Cellphone number's carrier - */ - MobileProvider getCellphoneCarrier (); - - /** - * Setter for cellphone number's carrier prefix - *

- * @param cellphoneCarrier Cellphone number's carrier prefix - */ - void setCellphoneCarrier (final MobileProvider cellphoneCarrier); - - /** - * Getter for ellphone number - *

- * @return Cellphone number - */ - Long getCellphoneNumber (); - - /** - * Setter for ellphone number - *

- * @param cellphoneNumber Cellphone number - */ - void setCellphoneNumber (final Long cellphoneNumber); - - /** - * City - *

- * @return the city - */ - String getCity (); - - /** - * City - *

- * @param city the city to set - */ - void setCity (final String city); - - /** - * Getter for comments - *

- * @return Comments - */ - String getComment (); - - /** - * Setter for comment - *

- * @param comment Comments - */ - void setComment (final String comment); - - /** - * Getter for contact id - *

- * @return Contact id - */ - Long getContactId (); - - /** - * Setter for contact id - *

- * @param contactId Contact id - */ - void setContactId (final Long contactId); - - /** - * Getter for country instance - *

- * @return Country instance - */ - Country getCountry (); - - /** - * Setter for country instance - *

- * @param country Country instance - */ - void setCountry (final Country country); - - /** - * Getter for email address - *

- * @return Email address - */ - String getEmailAddress (); - - /** - * Setter for email address - *

- * @param emailAddress Email address - */ - void setEmailAddress (final String emailAddress); - - /** - * Family name - *

- * @return the familyName - */ - String getFamilyName (); - - /** - * Family name - *

- * @param familyName the familyName to set - */ - void setFamilyName (final String familyName); - - /** - * Getter for fax number's area code - *

- * @return Fax number's area code - */ - Integer getFaxAreaCode (); - - /** - * Setter for fax number's area code - *

- * @param faxAreaCode Fax number's area code - */ - void setFaxAreaCode (final Integer faxAreaCode); - - /** - * Getter for fax's country instance - *

- * @return Fax' country instance - */ - Country getFaxCountry (); - - /** - * Setter for fax's country instance - *

- * @param faxCountry Fax' country instance - */ - void setFaxCountry (final Country faxCountry); - - /** - * Getter for fax number - *

- * @return Fax number - */ - Long getFaxNumber (); - - /** - * Setter for fax number - *

- * @param faxNumber Fax number - */ - void setFaxNumber (final Long faxNumber); - - /** - * First name - *

- * @return the first name - */ - String getFirstName (); - - /** - * First name - *

- * @param firstName the first name to set - */ - void setFirstName (final String firstName); - - /** - * Gender of the contact - *

- * @return the gender - */ - Gender getGender (); - - /** - * Gender of the contact - *

- * @param gender the gender to set - */ - void setGender (final Gender gender); - - /** - * House number - *

- * @return the houseNumber - */ - Short getHouseNumber (); - - /** - * House number - *

- * @param houseNumber the houseNumber to set - */ - void setHouseNumber (final Short houseNumber); - - /** - * Getter for phone number's area code - *

- * @return Phone number's area code - */ - Integer getPhoneAreaCode (); - - /** - * Setter for phone number's area code - *

- * @param phoneAreaCode Phone number's area code - */ - void setPhoneAreaCode (final Integer phoneAreaCode); - - /** - * Getter for phone number's country instance - *

- * @return Phone number's country instance - */ - Country getPhoneCountry (); - - /** - * Setter for phone number's country instance - *

- * @param phoneCountry Phone number's country instance - */ - void setPhoneCountry (final Country phoneCountry); - - /** - * Getter for phone number - *

- * @return Phone number - */ - Long getPhoneNumber (); - - /** - * Setter for phone number - *

- * @param phoneNumber Phone number - */ - void setPhoneNumber (final Long phoneNumber); - - /** - * Street - *

- * @return the street - */ - String getStreet (); - - /** - * Street - *

- * @param street the street to set - */ - void setStreet (final String street); - - /** - * ZIP code - *

- * @return the zipCode - */ - Integer getZipCode (); - - /** - * ZIP code - *

- * @param zipCode the zipCode to set - */ - void setZipCode (final Integer zipCode); - -} diff --git a/src/java/org/mxchange/jratecalc/beans/contact/PizzaContactWebSessionBean.java b/src/java/org/mxchange/jratecalc/beans/contact/PizzaContactWebSessionBean.java deleted file mode 100644 index ed14a2c2..00000000 --- a/src/java/org/mxchange/jratecalc/beans/contact/PizzaContactWebSessionBean.java +++ /dev/null @@ -1,827 +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.jratecalc.beans.contact; - -import java.text.MessageFormat; -import java.util.Date; -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.Observes; -import javax.faces.view.facelets.FaceletException; -import javax.inject.Inject; -import javax.inject.Named; -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NamingException; -import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jcontacts.contact.ContactSessionBeanRemote; -import org.mxchange.jcontacts.contact.UserContact; -import org.mxchange.jcontacts.contact.gender.Gender; -import org.mxchange.jcontacts.exceptions.ContactNotFoundException; -import org.mxchange.jcountry.data.Country; -import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber; -import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber; -import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; -import org.mxchange.jphone.phonenumbers.fax.FaxNumber; -import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; -import org.mxchange.jphone.phonenumbers.landline.LandLineNumber; -import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider; -import org.mxchange.jusercore.events.login.UserLoggedInEvent; -import org.mxchange.jusercore.events.registration.UserRegisteredEvent; -import org.mxchange.jusercore.exceptions.UserPasswordMismatchException; -import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController; - -/** - * A general contact bean (controller) - *

- * @author Roland Haeder - */ -@Named ("contactController") -@SessionScoped -public class PizzaContactWebSessionBean implements PizzaContactWebSessionController { - - /** - * Serial number - */ - private static final long serialVersionUID = 542_145_347_916L; - - /** - * Birth day - */ - private Date birthday; - - /** - * Cellphone number's carrier - */ - private MobileProvider cellphoneCarrier; - - /** - * Cellphone number - */ - private Long cellphoneNumber; - - /** - * City - */ - private String city; - - /** - * Optional comments - */ - private String comment; - - /** - * Remote contact bean - */ - private final ContactSessionBeanRemote contactBean; - - /** - * Contact list - */ - private List contactList; - - /** - * Country instance - */ - private Country country; - - /** - * Email address - */ - private String emailAddress; - - /** - * Email address list - */ - private List emailAddressList; - - /** - * Email address repeated - */ - private String emailAddressRepeat; - - /** - * Family name - */ - private String familyName; - - /** - * Fax number's area code - */ - private Integer faxAreaCode; - - /** - * Country instance for fax number - */ - private Country faxCountry; - - /** - * Fax number - */ - private Long faxNumber; - - /** - * First name - */ - private String firstName; - - /** - * Gender instance - */ - private Gender gender; - - /** - * House number - */ - private Short houseNumber; - - /** - * Login bean (controller) - */ - @Inject - private PizzaUserLoginWebSessionController loginController; - - /** - * Phone number area code - */ - private Integer phoneAreaCode; - - /** - * Country instance for phone number - */ - private Country phoneCountry; - - /** - * Phone number - */ - private Long phoneNumber; - - /** - * Street - */ - private String street; - - /** - * ZIP code - */ - private Integer zipCode; - - /** - * Default constructor - */ - public PizzaContactWebSessionBean () { - // Set gender to UNKNOWN - this.gender = Gender.UNKNOWN; - - // Try it - try { - // Get initial context - Context context = new InitialContext(); - - // Try to lookup - this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jratecalc-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N - } catch (final NamingException e) { - // Throw again - throw new FaceletException(e); - } - } - - @Override - public void addEmailAddress (final String contactEmailAddress) { - // Add it - this.emailAddressList.add(contactEmailAddress); - } - - @Override - public void afterRegistrationEvent (final @Observes UserRegisteredEvent event) { - // Trace message - System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N - - // event should not be null - if (null == event) { - // Throw NPE - throw new NullPointerException("event is null"); //NOI18N - } else if (event.getRegisteredUser() == null) { - // Throw NPE again - throw new NullPointerException("event.user is null"); //NOI18N - } else if (event.getRegisteredUser().getUserId() == null) { - // userId is null - throw new NullPointerException("event.user.userId is null"); //NOI18N - } else if (event.getRegisteredUser().getUserId() < 1) { - // Not avalid id - throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N - } - - // Get user instance - Contact registeredContact = event.getRegisteredUser().getUserContact(); - - // Debug message - System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: registeredContact={0}", registeredContact)); //NOI18N - - // Copy all data from registered->user - this.copyContact(registeredContact); - - // Add user name and email address - this.addUserNameEmailAddress(registeredContact); - - // Clear all data - this.clear(); - - // Trace message - System.out.println("ContactWebBean:afterRegistration: EXIT!"); //NOI18N - } - - @Override - public void afterUserLogin (final @Observes UserLoggedInEvent event) { - // Trace message - System.out.println(MessageFormat.format("ContactWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N - - // event should not be null - if (null == event) { - // Throw NPE - throw new NullPointerException("event is null"); //NOI18N - } else if (event.getLoggedInUser() == null) { - // Throw NPE again - throw new NullPointerException("event.user is null"); //NOI18N - } else if (event.getLoggedInUser().getUserId() == null) { - // userId is null - throw new NullPointerException("event.user.userId is null"); //NOI18N - } else if (event.getLoggedInUser().getUserId() < 1) { - // Not avalid id - throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N - } - - // Copy all data to this bean - this.copyContact(event.getLoggedInUser().getUserContact()); - - // Trace message - System.out.println("ContactWebBean:afterUserLogin - EXIT!"); //NOI18N - } - - /** - * Clears this bean - */ - @Override - public void clear () { - // Clear all data - // - personal data - this.setGender(Gender.UNKNOWN); - this.setFirstName(null); - this.setFamilyName(null); - this.setStreet(null); - this.setHouseNumber(null); - this.setZipCode(null); - this.setCity(null); - this.setCountry(null); - - // - contact data - this.setEmailAddress(null); - this.setEmailAddressRepeat(null); - this.setPhoneAreaCode(null); - this.setCellphoneCarrier(null); - this.setFaxAreaCode(null); - - // - other data - this.setBirthday(null); - this.setComment(null); - } - - @Override - public Contact createContactInstance () { - // User message - //this.getLogger().logTrace("createContactInstance: CALLED!"); - - // Required personal data must be set - assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N - - // Create new contact instance - Contact localContact = new UserContact(); - - // Generate phone number - DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber()); - DialableCellphoneNumber cellphone = new CellphoneNumber(this.getCellphoneCarrier(), this.getCellphoneNumber()); - DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber()); - - // Create new contact - Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName()); - contact.setContactStreet(this.getStreet()); - contact.setContactHouseNumber(this.getHouseNumber()); - contact.setContactZipCode(this.getZipCode()); - contact.setContactCity(this.getCity()); - contact.setContactCountry(this.getCountry()); - contact.setContactEmailAddress(this.getEmailAddress()); - - // Don't set null or wrong references - if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) { - // Now the number must be given - if (phone.getPhoneAreaCode() == null) { - // Is null - throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N - } else if (phone.getPhoneAreaCode() < 1) { - // Abort here - throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N - } else if (phone.getPhoneNumber() == null) { - // Is null - throw new NullPointerException("phone.phoneNumber is null"); //NOI18N - } else if (phone.getPhoneNumber() < 1) { - // Abort here - throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N - } - - // Set phone number - contact.setContactLandLineNumber(phone); - } - - // Don't set null or wrong references - if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) { - // Now the number must be given - if (fax.getPhoneAreaCode() == null) { - // Is null - throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N - } else if (fax.getPhoneAreaCode() < 1) { - // Abort here - throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N - } else if (fax.getPhoneNumber() == null) { - // Is null - throw new NullPointerException("fax.phoneNumber is null"); //NOI18N - } else if (fax.getPhoneNumber() < 1) { - // Abort here - throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N - } - - // Set fax number - contact.setContactFaxNumber(fax); - } - - // Is the provider set? - if ((cellphone instanceof DialableCellphoneNumber) && (this.getCellphoneCarrier() instanceof MobileProvider) && (this.getCellphoneNumber() != null) && (this.getCellphoneNumber() > 0)) { - // Is the number set? - if (cellphone.getPhoneNumber() == null) { - // Is null - throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N - } else if (cellphone.getPhoneNumber() < 1) { - // Abort here - throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N - } - - // Set cellphone number - contact.setContactCellphoneNumber(cellphone); - } - - contact.setContactBirthday(this.getBirthday()); - contact.setContactComment(this.getComment()); - - // Created timestamp and ownContact - contact.setContactOwnContact(Boolean.TRUE); - - // Trace message - //this.getLogger().logTrace(MessageFormat.format("createContactInstance: localContact={0} - EXIT!", localContact)); - // Return it - return localContact; - } - - @Override - public String doChangePersonalContactData () { - // This method shall only be called if the user is logged-in - if (!this.loginController.isUserLoggedIn()) { - // Not logged-in - throw new IllegalStateException("User is not logged-in"); //NOI18N - } else if (!this.isRequiredChangePersonalDataSet()) { - // Not all required fields are set - throw new FaceletException("Not all required fields are set."); //NOI18N - } else if (!this.loginController.ifCurrentPasswordMatches()) { - // Password not matching - throw new FaceletException(new UserPasswordMismatchException(this.loginController.getLoggedInUser())); - } - - // Get contact instance - Contact contact = this.loginController.getLoggedInUser().getUserContact(); - - // It should be there, so run some tests on it - assert (contact instanceof Contact) : "Instance loginController.loggedInUser.userContact is null"; //NOI18N - assert (contact.getContactId() instanceof Long) : "Instance loginController.userContact.contactId is null"; //NOI18N - assert (contact.getContactId() > 0) : MessageFormat.format("Instance loginController.userContact.contactId={0} is invalid", contact.getContactId()); //NOI18N - - // Update all fields - contact.setContactGender(this.getGender()); - contact.setContactFirstName(this.getFirstName()); - contact.setContactFamilyName(this.getFamilyName()); - contact.setContactStreet(this.getStreet()); - contact.setContactHouseNumber(this.getHouseNumber()); - contact.setContactZipCode(this.getZipCode()); - contact.setContactCity(this.getCity()); - contact.setContactCountry(this.getCountry()); - - // Is there a phone number? - if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) { - // Debug message - System.out.println(MessageFormat.format("ContactWebBean:doChangePersonalData: phoneId={0}", contact.getContactLandLineNumber().getPhoneId())); //NOI18N - - // Yes, then update as well - contact.getContactLandLineNumber().setPhoneAreaCode(this.getPhoneAreaCode()); - contact.getContactLandLineNumber().setPhoneNumber(this.getPhoneNumber()); - } - - // Is there a fax number? - if (contact.getContactFaxNumber() instanceof DialableFaxNumber) { - // Debug message - System.out.println(MessageFormat.format("ContactWebBean:doChangePersonalData: faxId={0}", contact.getContactFaxNumber().getPhoneId())); //NOI18N - - // Yes, then update as well - contact.getContactFaxNumber().setPhoneAreaCode(this.getFaxAreaCode()); - contact.getContactFaxNumber().setPhoneNumber(this.getFaxNumber()); - } - - // Is there a cellphone number? - if (contact.getContactCellphoneNumber() instanceof DialableCellphoneNumber) { - // Debug message - System.out.println(MessageFormat.format("ContactWebBean:doChangePersonalData: cellPhoneId={0}", contact.getContactCellphoneNumber().getPhoneId())); //NOI18N - - // Yes, then update as well - contact.getContactCellphoneNumber().setCellphoneProvider(this.getCellphoneCarrier()); - contact.getContactCellphoneNumber().setPhoneNumber(this.getCellphoneNumber()); - } - - // Send it to the EJB - this.contactBean.updateContactPersonalData(contact); - - // All fine - return "contact_data_saved"; //NOI18N - } - - @Override - public Date getBirthday () { - return this.birthday; - } - - @Override - public void setBirthday (final Date birthday) { - this.birthday = birthday; - } - - @Override - public MobileProvider getCellphoneCarrier () { - return this.cellphoneCarrier; - } - - @Override - public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) { - this.cellphoneCarrier = cellphoneCarrier; - } - - @Override - public Long getCellphoneNumber () { - return this.cellphoneNumber; - } - - @Override - public void setCellphoneNumber (Long cellphoneNumber) { - this.cellphoneNumber = cellphoneNumber; - } - - @Override - public String getCity () { - return this.city; - } - - @Override - public void setCity (final String city) { - this.city = city; - } - - @Override - public String getComment () { - return this.comment; - } - - @Override - public void setComment (final String comment) { - this.comment = comment; - } - - @Override - public Country getCountry () { - return this.country; - } - - @Override - public void setCountry (final Country country) { - this.country = country; - } - - @Override - public String getEmailAddress () { - return this.emailAddress; - } - - @Override - public void setEmailAddress (final String emailAddress) { - this.emailAddress = emailAddress; - } - - @Override - public String getEmailAddressRepeat () { - return this.emailAddressRepeat; - } - - @Override - public void setEmailAddressRepeat (final String emailAddressRepeat) { - this.emailAddressRepeat = emailAddressRepeat; - } - - @Override - public String getFamilyName () { - return this.familyName; - } - - @Override - public void setFamilyName (final String familyName) { - this.familyName = familyName; - } - - @Override - public Integer getFaxAreaCode () { - return this.faxAreaCode; - } - - @Override - public void setFaxAreaCode (final Integer faxAreaCode) { - this.faxAreaCode = faxAreaCode; - } - - @Override - public Country getFaxCountry () { - return this.faxCountry; - } - - @Override - public void setFaxCountry (final Country faxCountry) { - this.faxCountry = faxCountry; - } - - @Override - public Long getFaxNumber () { - return this.faxNumber; - } - - @Override - public void setFaxNumber (final Long faxNumber) { - this.faxNumber = faxNumber; - } - - @Override - public String getFirstName () { - return this.firstName; - } - - @Override - public void setFirstName (final String firstName) { - this.firstName = firstName; - } - - @Override - public Gender getGender () { - return this.gender; - } - - @Override - public void setGender (final Gender gender) { - this.gender = gender; - } - - @Override - public Short getHouseNumber () { - return this.houseNumber; - } - - @Override - public void setHouseNumber (final Short houseNumber) { - this.houseNumber = houseNumber; - } - - @Override - public Integer getPhoneAreaCode () { - return this.phoneAreaCode; - } - - @Override - public void setPhoneAreaCode (final Integer phoneAreaCode) { - this.phoneAreaCode = phoneAreaCode; - } - - @Override - public Country getPhoneCountry () { - return this.phoneCountry; - } - - @Override - public void setPhoneCountry (final Country phoneCountry) { - this.phoneCountry = phoneCountry; - } - - @Override - public Long getPhoneNumber () { - return this.phoneNumber; - } - - @Override - public void setPhoneNumber (final Long phoneNumber) { - this.phoneNumber = phoneNumber; - } - - @Override - public String getStreet () { - return this.street; - } - - @Override - public void setStreet (final String street) { - this.street = street; - } - - @Override - public Integer getZipCode () { - return this.zipCode; - } - - @Override - public void setZipCode (final Integer zipCode) { - this.zipCode = zipCode; - } - - /** - * Post-initialization of this class - */ - @PostConstruct - public void init () { - // Get full email address list for reducing EJB calls - this.emailAddressList = this.contactBean.getEmailAddressList(); - - // Get full contact list - this.contactList = this.contactBean.getAllContacts(); - } - - @Override - public boolean isEmailAddressRegistered (final Contact contact) { - return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(contact.getContactEmailAddress()))); - } - - @Override - public boolean isRequiredChangePersonalDataSet () { - return ((this.getGender() != null) && - (this.getFirstName() != null) && - (this.getFamilyName() != null) && - (this.getStreet() != null) && - (this.getHouseNumber() != null) && - (this.getZipCode() != null) && - (this.getCity() != null)); - } - - @Override - public boolean isRequiredPersonalDataSet () { - return ((this.getGender() != null) && - (this.getFirstName() != null) && - (this.getFamilyName() != null) && - (this.getStreet() != null) && - (this.getHouseNumber() != null) && - (this.getZipCode() != null) && - (this.getCity() != null) && - (this.getEmailAddress() != null) && - (this.getEmailAddressRepeat() != null)); - } - - @Override - public boolean isSameEmailAddressEntered () { - return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat())); - } - - @Override - public Contact lookupContactById (final Long contactId) throws ContactNotFoundException { - // Init variable - Contact localContact = null; - - // Clear this bean - this.clear(); - - // Try to lookup it in visible user list - for (final Iterator iterator = this.contactList.iterator(); iterator.hasNext();) { - // Get next user - Contact next = iterator.next(); - - // Is the user id found? - if (Objects.equals(next.getContactId(), contactId)) { - // Copy to other variable - localContact = next; - break; - } - } - - // Is it still null? - if (null == localContact) { - // Not visible for the current user - throw new ContactNotFoundException(contactId); - } - - // Copy all data to this bean - this.copyContact(localContact); - - // Return it - return localContact; - } - - @Override - public void updateContactDataFromController (final Contact userContact) { - // Is the instance valid? - if (null == userContact) { - // Throw NPE - throw new NullPointerException("userContact is null"); //NOI18N - } else if (userContact.getContactId() == null) { - // Throw NPE - throw new NullPointerException("userContact.contactId is null"); //NOI18N - } else if (userContact.getContactId() < 1) { - // Not valid id number - throw new IllegalArgumentException(MessageFormat.format("userContact.contactId={0} is not valid.", userContact.getContactId())); //NOI18N - } - - // Set all - this.copyContact(userContact); - } - - /** - * Adds email address to bean's internal list. - *

- * @param contact Contact instance - */ - private void addUserNameEmailAddress (final Contact contact) { - // Make sure the entry is not added yet - if (this.emailAddressList.contains(contact.getContactEmailAddress())) { - // Already added - throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N - } - - // Add email addres - this.emailAddressList.add(contact.getContactEmailAddress()); - } - - /** - * Copies given contact into the controller - *

- * @param contact Contact instance - */ - private void copyContact (final Contact contact) { - // Copy all fields: - // - base data - this.setGender(contact.getContactGender()); - this.setFirstName(contact.getContactFirstName()); - this.setFamilyName(contact.getContactFamilyName()); - this.setStreet(contact.getContactStreet()); - this.setHouseNumber(contact.getContactHouseNumber()); - this.setZipCode(contact.getContactZipCode()); - this.setCity(contact.getContactCity()); - this.setCountry(contact.getContactCountry()); - - // Get cellphone, phone and fax instance - DialableCellphoneNumber cellphone = contact.getContactCellphoneNumber(); - DialableFaxNumber fax = contact.getContactFaxNumber(); - DialableLandLineNumber phone = contact.getContactLandLineNumber(); - - // - contact data - if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) { - this.setPhoneCountry(phone.getPhoneCountry()); - this.setPhoneAreaCode(phone.getPhoneAreaCode()); - this.setPhoneNumber(phone.getPhoneNumber()); - } - if ((cellphone instanceof DialableCellphoneNumber) && (cellphone.getCellphoneProvider() instanceof MobileProvider)) { - this.setCellphoneCarrier(cellphone.getCellphoneProvider()); - this.setCellphoneNumber(cellphone.getPhoneNumber()); - } - if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) { - this.setFaxCountry(fax.getPhoneCountry()); - this.setFaxAreaCode(fax.getPhoneAreaCode()); - this.setFaxNumber(fax.getPhoneNumber()); - } - this.setEmailAddress(contact.getContactEmailAddress()); - - // -- other data - this.setBirthday(contact.getContactBirthday()); - this.setComment(contact.getContactComment()); - } - -} diff --git a/src/java/org/mxchange/jratecalc/beans/contact/PizzaContactWebSessionController.java b/src/java/org/mxchange/jratecalc/beans/contact/PizzaContactWebSessionController.java deleted file mode 100644 index 2de56865..00000000 --- a/src/java/org/mxchange/jratecalc/beans/contact/PizzaContactWebSessionController.java +++ /dev/null @@ -1,411 +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.jratecalc.beans.contact; - -import java.io.Serializable; -import java.util.Date; -import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jcontacts.contact.gender.Gender; -import org.mxchange.jcontacts.exceptions.ContactNotFoundException; -import org.mxchange.jcountry.data.Country; -import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider; -import org.mxchange.jusercore.events.login.UserLoggedInEvent; -import org.mxchange.jusercore.events.registration.UserRegisteredEvent; - -/** - * An interface for user beans - *

- * @author Roland Haeder - */ -public interface PizzaContactWebSessionController extends Serializable { - - /** - * Minimum password length - */ - public static final Integer MINIMUM_PASSWORD_LENGTH = 5; - - /** - * Updates all data from bean in given contact instance - *

- * @param userContact Contact instance to update - */ - void updateContactDataFromController (final Contact userContact); - - /** - * Adds given email address to list - *

- * @param contactEmailAddress Email address to add - */ - void addEmailAddress (final String contactEmailAddress); - - /** - * Tries to lookup contact by given id number. If the user is not found a - * proper exceptions are thrown. - *

- * @param contactId Contact id - *

- * @return Contact instance - *

- * @throws ContactNotFoundException If the user is not found - */ - Contact lookupContactById (final Long contactId) throws ContactNotFoundException; - - /** - * Clears this controller - */ - void clear (); - - /** - * Event observer for new user registrations - *

- * @param event User registration event - */ - void afterRegistrationEvent (final UserRegisteredEvent event); - - /** - * Event observer for logged-in user - *

- * @param event Event instance - */ - void afterUserLogin (final UserLoggedInEvent event); - - /** - * Creates an instance from all properties - *

- * @return A contact instance - */ - Contact createContactInstance (); - - /** - * Getter for birth day - *

- * @return Birth day - */ - Date getBirthday (); - - /** - * Setter for birth day - *

- * @param birthday Birth day - */ - void setBirthday (final Date birthday); - - /** - * Getter for ellphone number's carrier - *

- * @return Cellphone number's carrier - */ - MobileProvider getCellphoneCarrier (); - - /** - * Setter for cellphone number's carrier prefix - *

- * @param cellphoneCarrier Cellphone number's carrier prefix - */ - void setCellphoneCarrier (final MobileProvider cellphoneCarrier); - - /** - * Getter for ellphone number - *

- * @return Cellphone number - */ - Long getCellphoneNumber (); - - /** - * Setter for ellphone number - *

- * @param cellphoneNumber Cellphone number - */ - void setCellphoneNumber (final Long cellphoneNumber); - - /** - * City - *

- * @return the city - */ - String getCity (); - - /** - * City - *

- * @param city the city to set - */ - void setCity (final String city); - - /** - * Getter for comments - *

- * @return Comments - */ - String getComment (); - - /** - * Setter for comment - *

- * @param comment Comments - */ - void setComment (final String comment); - - /** - * Getter for country instance - *

- * @return Country instance - */ - Country getCountry (); - - /** - * Setter for country instance - *

- * @param country Country instance - */ - void setCountry (final Country country); - - /** - * Getter for email address - *

- * @return Email address - */ - String getEmailAddress (); - - /** - * Setter for email address - *

- * @param emailAddress Email address - */ - void setEmailAddress (final String emailAddress); - - /** - * Getter for email address, repeated - *

- * @return the emailAddress, repeated - */ - String getEmailAddressRepeat (); - - /** - * Setter for email address repeated - *

- * @param emailAddressRepeat the emailAddress to set - */ - void setEmailAddressRepeat (final String emailAddressRepeat); - - /** - * Family name - *

- * @return the familyName - */ - String getFamilyName (); - - /** - * Family name - *

- * @param familyName the familyName to set - */ - void setFamilyName (final String familyName); - - /** - * Getter for fax number's area code - *

- * @return Fax number's area code - */ - Integer getFaxAreaCode (); - - /** - * Setter for fax number's area code - *

- * @param faxAreaCode Fax number's area code - */ - void setFaxAreaCode (final Integer faxAreaCode); - - /** - * Getter for fax's country instance - *

- * @return Fax' country instance - */ - Country getFaxCountry (); - - /** - * Setter for fax's country instance - *

- * @param faxCountry Fax' country instance - */ - void setFaxCountry (final Country faxCountry); - - /** - * Getter for fax number - *

- * @return Fax number - */ - Long getFaxNumber (); - - /** - * Setter for fax number - *

- * @param faxNumber Fax number - */ - void setFaxNumber (final Long faxNumber); - - /** - * First name - *

- * @return the first name - */ - String getFirstName (); - - /** - * First name - *

- * @param firstName the first name to set - */ - void setFirstName (final String firstName); - - /** - * Gender of the contact - *

- * @return the gender - */ - Gender getGender (); - - /** - * Gender of the contact - *

- * @param gender the gender to set - */ - void setGender (final Gender gender); - - /** - * House number - *

- * @return the houseNumber - */ - Short getHouseNumber (); - - /** - * House number - *

- * @param houseNumber the houseNumber to set - */ - void setHouseNumber (final Short houseNumber); - - /** - * Getter for phone number's area code - *

- * @return Phone number's area code - */ - Integer getPhoneAreaCode (); - - /** - * Setter for phone number's area code - *

- * @param phoneAreaCode Phone number's area code - */ - void setPhoneAreaCode (final Integer phoneAreaCode); - - /** - * Getter for phone number's country instance - *

- * @return Phone number's country instance - */ - Country getPhoneCountry (); - - /** - * Setter for phone number's country instance - *

- * @param phoneCountry Phone number's country instance - */ - void setPhoneCountry (final Country phoneCountry); - - /** - * Getter for phone number - *

- * @return Phone number - */ - Long getPhoneNumber (); - - /** - * Setter for phone number - *

- * @param phoneNumber Phone number - */ - void setPhoneNumber (final Long phoneNumber); - - /** - * Street - *

- * @return the street - */ - String getStreet (); - - /** - * Street - *

- * @param street the street to set - */ - void setStreet (final String street); - - /** - * ZIP code - *

- * @return the zipCode - */ - Integer getZipCode (); - - /** - * ZIP code - *

- * @param zipCode the zipCode to set - */ - void setZipCode (final Integer zipCode); - - /** - * Checks whether contact instance's email address is used - *

- * @param contact Contact instance's email address to check - *

- * @return Whether it is already used - */ - boolean isEmailAddressRegistered (final Contact contact); - - /** - * Checks whether all required personal data is set - *

- * @return Whether the required personal data is set - */ - boolean isRequiredPersonalDataSet (); - - /** - * Checks whether all required personal data is set for changing them - *

- * @return Whether the required personal data is set - */ - boolean isRequiredChangePersonalDataSet (); - - /** - * Checks whether same email addresses have been entered - *

- * @return Whether same email addresses have been entered - */ - boolean isSameEmailAddressEntered (); - - /** - * Changes logged-in user's personal data if the current password matches - * and TAC + privacy statement has been accepted. - *

- * @return New target page - */ - String doChangePersonalContactData (); - -} diff --git a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java new file mode 100644 index 00000000..798afbef --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java @@ -0,0 +1,506 @@ +/* + * 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.contact; + +import java.text.MessageFormat; +import java.util.Date; +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.jcontacts.contact.ContactSessionBeanRemote; +import org.mxchange.jcontacts.contact.gender.Gender; +import org.mxchange.jcountry.data.Country; +import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider; +import org.mxchange.jusercore.events.user.AdminAddedUserEvent; + +/** + * A user bean (controller) + *

+ * @author Roland Haeder + */ +@Named ("adminContactController") +@RequestScoped +public class PizzaAdminContactWebRequestBean implements PizzaAdminContactWebRequestController { + + /** + * 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; + + /** + * Birth day + */ + private Date birthday; + + /** + * Cellphone number's carrier + */ + private MobileProvider cellphoneCarrier; + + /** + * Cellphone id number + */ + private Long cellphoneId; + + /** + * Cellphone number + */ + private Long cellphoneNumber; + + /** + * City + */ + private String city; + + /** + * Optional comments + */ + private String comment; + + /** + * Remote contact bean + */ + private final ContactSessionBeanRemote contactBean; + + /** + * Contact id + */ + private Long contactId; + + /** + * Country instance + */ + private Country country; + + /** + * Email address + */ + private String emailAddress; + + /** + * Family name + */ + private String familyName; + + /** + * Fax number's area code + */ + private Integer faxAreaCode; + + /** + * Country instance for fax number + */ + private Country faxCountry; + + /** + * Fax id number + */ + private Long faxId; + + /** + * Fax number + */ + private Long faxNumber; + + /** + * First name + */ + private String firstName; + + /** + * Gender instance + */ + private Gender gender; + + /** + * House number + */ + private Short houseNumber; + + /** + * Land-line id number + */ + private Long landLineId; + + /** + * Phone number area code + */ + private Integer phoneAreaCode; + + /** + * Country instance for phone number + */ + private Country phoneCountry; + + /** + * Phone number + */ + private Long phoneNumber; + + /** + * Street + */ + private String street; + + /** + * ZIP code + */ + private Integer zipCode; + + /** + * Default constructor + */ + public PizzaAdminContactWebRequestBean () { + // Set gender to UNKNOWN + this.gender = Gender.UNKNOWN; + + // Try it + try { + // Get initial context + Context context = new InitialContext(); + + // Try to lookup + this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jratecalc-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N + } catch (final NamingException e) { + // Throw again + throw new FaceletException(e); + } + } + + @Override + public void copyContactToController (final Contact contact) { + // The contact instance must be valid + if (null == contact) { + // Throw NPE again + throw new NullPointerException("this.user.userContact is null"); + } else if (contact.getContactId() < 1) { + // Not valid + throw new IllegalStateException(MessageFormat.format("this.user.userContact.contactId={0} is not valid.", contact.getContactId())); + } + + // Set all fields: contact + this.setContactId(contact.getContactId()); + this.setBirthday(contact.getContactBirthday()); + this.setCity(contact.getContactCity()); + this.setComment(contact.getContactComment()); + this.setCountry(contact.getContactCountry()); + this.setEmailAddress(contact.getContactEmailAddress()); + this.setFamilyName(contact.getContactFamilyName()); + this.setFirstName(contact.getContactFirstName()); + this.setGender(contact.getContactGender()); + this.setHouseNumber(contact.getContactHouseNumber()); + this.setStreet(contact.getContactStreet()); + this.setZipCode(contact.getContactZipCode()); + + // ... cellphone data + this.setCellphoneId(contact.getContactCellphoneNumber().getPhoneId()); + this.setCellphoneCarrier(contact.getContactCellphoneNumber().getCellphoneProvider()); + this.setCellphoneNumber(contact.getContactCellphoneNumber().getPhoneNumber()); + + // ... fax data + this.setFaxId(contact.getContactFaxNumber().getPhoneId()); + this.setFaxAreaCode(contact.getContactFaxNumber().getPhoneAreaCode()); + this.setFaxCountry(contact.getContactFaxNumber().getPhoneCountry()); + this.setFaxNumber(contact.getContactFaxNumber().getPhoneNumber()); + + // .. land-line data + this.setLandLineId(contact.getContactLandLineNumber().getPhoneId()); + this.setPhoneAreaCode(contact.getContactLandLineNumber().getPhoneAreaCode()); + this.setPhoneCountry(contact.getContactLandLineNumber().getPhoneCountry()); + this.setPhoneNumber(contact.getContactLandLineNumber().getPhoneNumber()); + } + + @Override + public Date getBirthday () { + return this.birthday; + } + + @Override + public void setBirthday (final Date birthday) { + this.birthday = birthday; + } + + @Override + public MobileProvider getCellphoneCarrier () { + return this.cellphoneCarrier; + } + + @Override + public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) { + this.cellphoneCarrier = cellphoneCarrier; + } + + @Override + public Long getCellphoneId () { + return this.cellphoneId; + } + + @Override + public void setCellphoneId (final Long cellphoneId) { + this.cellphoneId = cellphoneId; + } + + @Override + public Long getCellphoneNumber () { + return this.cellphoneNumber; + } + + @Override + public void setCellphoneNumber (Long cellphoneNumber) { + this.cellphoneNumber = cellphoneNumber; + } + + @Override + public String getCity () { + return this.city; + } + + @Override + public void setCity (final String city) { + this.city = city; + } + + @Override + public String getComment () { + return this.comment; + } + + @Override + public void setComment (final String comment) { + this.comment = comment; + } + + @Override + public Long getContactId () { + return this.contactId; + } + + @Override + public void setContactId (final Long contactId) { + this.contactId = contactId; + } + + @Override + public Country getCountry () { + return this.country; + } + + @Override + public void setCountry (final Country country) { + this.country = country; + } + + @Override + public String getEmailAddress () { + return this.emailAddress; + } + + @Override + public void setEmailAddress (final String emailAddress) { + this.emailAddress = emailAddress; + } + + @Override + public String getFamilyName () { + return this.familyName; + } + + @Override + public void setFamilyName (final String familyName) { + this.familyName = familyName; + } + + @Override + public Integer getFaxAreaCode () { + return this.faxAreaCode; + } + + @Override + public void setFaxAreaCode (final Integer faxAreaCode) { + this.faxAreaCode = faxAreaCode; + } + + @Override + public Country getFaxCountry () { + return this.faxCountry; + } + + @Override + public void setFaxCountry (final Country faxCountry) { + this.faxCountry = faxCountry; + } + + @Override + public Long getFaxId () { + return this.faxId; + } + + @Override + public void setFaxId (final Long faxId) { + this.faxId = faxId; + } + + @Override + public Long getFaxNumber () { + return this.faxNumber; + } + + @Override + public void setFaxNumber (final Long faxNumber) { + this.faxNumber = faxNumber; + } + + @Override + public String getFirstName () { + return this.firstName; + } + + @Override + public void setFirstName (final String firstName) { + this.firstName = firstName; + } + + @Override + public Gender getGender () { + return this.gender; + } + + @Override + public void setGender (final Gender gender) { + this.gender = gender; + } + + @Override + public Short getHouseNumber () { + return this.houseNumber; + } + + @Override + public void setHouseNumber (final Short houseNumber) { + this.houseNumber = houseNumber; + } + + @Override + public Long getLandLineId () { + return this.landLineId; + } + + @Override + public void setLandLineId (final Long landLineId) { + this.landLineId = landLineId; + } + + @Override + public Integer getPhoneAreaCode () { + return this.phoneAreaCode; + } + + @Override + public void setPhoneAreaCode (final Integer phoneAreaCode) { + this.phoneAreaCode = phoneAreaCode; + } + + @Override + public Country getPhoneCountry () { + return this.phoneCountry; + } + + @Override + public void setPhoneCountry (final Country phoneCountry) { + this.phoneCountry = phoneCountry; + } + + @Override + public Long getPhoneNumber () { + return this.phoneNumber; + } + + @Override + public void setPhoneNumber (final Long phoneNumber) { + this.phoneNumber = phoneNumber; + } + + @Override + public String getStreet () { + return this.street; + } + + @Override + public void setStreet (final String street) { + this.street = street; + } + + @Override + public Integer getZipCode () { + return this.zipCode; + } + + @Override + public void setZipCode (final Integer zipCode) { + this.zipCode = zipCode; + } + + /** + * Post-initialization of this class + */ + @PostConstruct + public void init () { + } + + /** + * Clears this bean + */ + private void clear () { + // Clear all + this.setContactId(null); + this.setBirthday(null); + this.setCellphoneCarrier(null); + this.setCellphoneNumber(null); + this.setCity(null); + this.setComment(null); + this.setCountry(null); + this.setEmailAddress(null); + this.setFamilyName(null); + this.setFaxAreaCode(null); + this.setFaxCountry(null); + this.setFaxNumber(null); + this.setFirstName(null); + this.setGender(null); + this.setHouseNumber(null); + this.setPhoneAreaCode(null); + this.setPhoneCountry(null); + this.setPhoneNumber(null); + this.setStreet(null); + this.setZipCode(null); + } + +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestController.java b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestController.java new file mode 100644 index 00000000..0e8e7668 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestController.java @@ -0,0 +1,362 @@ +/* + * 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.contact; + +import java.io.Serializable; +import java.util.Date; +import org.mxchange.jcontacts.contact.Contact; +import org.mxchange.jcontacts.contact.gender.Gender; +import org.mxchange.jcountry.data.Country; +import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider; + +/** + * An administrative interface for user beans + *

+ * @author Roland Haeder + */ +public interface PizzaAdminContactWebRequestController extends Serializable { + + /** + * Copies given contact's data to this controller + *

+ * @param contact Contact instance + */ + void copyContactToController (final Contact contact); + + /** + * Getter for cellphone id + *

+ * @return Cellphone id + */ + Long getCellphoneId (); + + /** + * Setter for cellphone id + *

+ * @param cellphoneId Cellphone id + */ + void setCellphoneId (final Long cellphoneId); + + /** + * Getter for fax id + *

+ * @return Fax id + */ + Long getFaxId (); + + /** + * Setter for fax id + *

+ * @param faxId Fax id + */ + void setFaxId (final Long faxId); + + /** + * Getter for land-line id + *

+ * @return Land-line id + */ + Long getLandLineId (); + + /** + * Setter for land-line id + *

+ * @param landLineId Land-line id + */ + void setLandLineId (final Long landLineId); + + /** + * Getter for birth day + *

+ * @return Birth day + */ + Date getBirthday (); + + /** + * Setter for birth day + *

+ * @param birthday Birth day + */ + void setBirthday (final Date birthday); + + /** + * Getter for ellphone number's carrier + *

+ * @return Cellphone number's carrier + */ + MobileProvider getCellphoneCarrier (); + + /** + * Setter for cellphone number's carrier prefix + *

+ * @param cellphoneCarrier Cellphone number's carrier prefix + */ + void setCellphoneCarrier (final MobileProvider cellphoneCarrier); + + /** + * Getter for ellphone number + *

+ * @return Cellphone number + */ + Long getCellphoneNumber (); + + /** + * Setter for ellphone number + *

+ * @param cellphoneNumber Cellphone number + */ + void setCellphoneNumber (final Long cellphoneNumber); + + /** + * City + *

+ * @return the city + */ + String getCity (); + + /** + * City + *

+ * @param city the city to set + */ + void setCity (final String city); + + /** + * Getter for comments + *

+ * @return Comments + */ + String getComment (); + + /** + * Setter for comment + *

+ * @param comment Comments + */ + void setComment (final String comment); + + /** + * Getter for contact id + *

+ * @return Contact id + */ + Long getContactId (); + + /** + * Setter for contact id + *

+ * @param contactId Contact id + */ + void setContactId (final Long contactId); + + /** + * Getter for country instance + *

+ * @return Country instance + */ + Country getCountry (); + + /** + * Setter for country instance + *

+ * @param country Country instance + */ + void setCountry (final Country country); + + /** + * Getter for email address + *

+ * @return Email address + */ + String getEmailAddress (); + + /** + * Setter for email address + *

+ * @param emailAddress Email address + */ + void setEmailAddress (final String emailAddress); + + /** + * Family name + *

+ * @return the familyName + */ + String getFamilyName (); + + /** + * Family name + *

+ * @param familyName the familyName to set + */ + void setFamilyName (final String familyName); + + /** + * Getter for fax number's area code + *

+ * @return Fax number's area code + */ + Integer getFaxAreaCode (); + + /** + * Setter for fax number's area code + *

+ * @param faxAreaCode Fax number's area code + */ + void setFaxAreaCode (final Integer faxAreaCode); + + /** + * Getter for fax's country instance + *

+ * @return Fax' country instance + */ + Country getFaxCountry (); + + /** + * Setter for fax's country instance + *

+ * @param faxCountry Fax' country instance + */ + void setFaxCountry (final Country faxCountry); + + /** + * Getter for fax number + *

+ * @return Fax number + */ + Long getFaxNumber (); + + /** + * Setter for fax number + *

+ * @param faxNumber Fax number + */ + void setFaxNumber (final Long faxNumber); + + /** + * First name + *

+ * @return the first name + */ + String getFirstName (); + + /** + * First name + *

+ * @param firstName the first name to set + */ + void setFirstName (final String firstName); + + /** + * Gender of the contact + *

+ * @return the gender + */ + Gender getGender (); + + /** + * Gender of the contact + *

+ * @param gender the gender to set + */ + void setGender (final Gender gender); + + /** + * House number + *

+ * @return the houseNumber + */ + Short getHouseNumber (); + + /** + * House number + *

+ * @param houseNumber the houseNumber to set + */ + void setHouseNumber (final Short houseNumber); + + /** + * Getter for phone number's area code + *

+ * @return Phone number's area code + */ + Integer getPhoneAreaCode (); + + /** + * Setter for phone number's area code + *

+ * @param phoneAreaCode Phone number's area code + */ + void setPhoneAreaCode (final Integer phoneAreaCode); + + /** + * Getter for phone number's country instance + *

+ * @return Phone number's country instance + */ + Country getPhoneCountry (); + + /** + * Setter for phone number's country instance + *

+ * @param phoneCountry Phone number's country instance + */ + void setPhoneCountry (final Country phoneCountry); + + /** + * Getter for phone number + *

+ * @return Phone number + */ + Long getPhoneNumber (); + + /** + * Setter for phone number + *

+ * @param phoneNumber Phone number + */ + void setPhoneNumber (final Long phoneNumber); + + /** + * Street + *

+ * @return the street + */ + String getStreet (); + + /** + * Street + *

+ * @param street the street to set + */ + void setStreet (final String street); + + /** + * ZIP code + *

+ * @return the zipCode + */ + Integer getZipCode (); + + /** + * ZIP code + *

+ * @param zipCode the zipCode to set + */ + void setZipCode (final Integer zipCode); + +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionBean.java new file mode 100644 index 00000000..94d397f1 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionBean.java @@ -0,0 +1,827 @@ +/* + * 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.contact; + +import java.text.MessageFormat; +import java.util.Date; +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.Observes; +import javax.faces.view.facelets.FaceletException; +import javax.inject.Inject; +import javax.inject.Named; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import org.mxchange.jcontacts.contact.Contact; +import org.mxchange.jcontacts.contact.ContactSessionBeanRemote; +import org.mxchange.jcontacts.contact.UserContact; +import org.mxchange.jcontacts.contact.gender.Gender; +import org.mxchange.jcontacts.exceptions.ContactNotFoundException; +import org.mxchange.jcountry.data.Country; +import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber; +import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber; +import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; +import org.mxchange.jphone.phonenumbers.fax.FaxNumber; +import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; +import org.mxchange.jphone.phonenumbers.landline.LandLineNumber; +import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider; +import org.mxchange.jusercore.events.login.UserLoggedInEvent; +import org.mxchange.jusercore.events.registration.UserRegisteredEvent; +import org.mxchange.jusercore.exceptions.UserPasswordMismatchException; +import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController; + +/** + * A general contact bean (controller) + *

+ * @author Roland Haeder + */ +@Named ("contactController") +@SessionScoped +public class PizzaContactWebSessionBean implements PizzaContactWebSessionController { + + /** + * Serial number + */ + private static final long serialVersionUID = 542_145_347_916L; + + /** + * Birth day + */ + private Date birthday; + + /** + * Cellphone number's carrier + */ + private MobileProvider cellphoneCarrier; + + /** + * Cellphone number + */ + private Long cellphoneNumber; + + /** + * City + */ + private String city; + + /** + * Optional comments + */ + private String comment; + + /** + * Remote contact bean + */ + private final ContactSessionBeanRemote contactBean; + + /** + * Contact list + */ + private List contactList; + + /** + * Country instance + */ + private Country country; + + /** + * Email address + */ + private String emailAddress; + + /** + * Email address list + */ + private List emailAddressList; + + /** + * Email address repeated + */ + private String emailAddressRepeat; + + /** + * Family name + */ + private String familyName; + + /** + * Fax number's area code + */ + private Integer faxAreaCode; + + /** + * Country instance for fax number + */ + private Country faxCountry; + + /** + * Fax number + */ + private Long faxNumber; + + /** + * First name + */ + private String firstName; + + /** + * Gender instance + */ + private Gender gender; + + /** + * House number + */ + private Short houseNumber; + + /** + * Login bean (controller) + */ + @Inject + private PizzaUserLoginWebSessionController loginController; + + /** + * Phone number area code + */ + private Integer phoneAreaCode; + + /** + * Country instance for phone number + */ + private Country phoneCountry; + + /** + * Phone number + */ + private Long phoneNumber; + + /** + * Street + */ + private String street; + + /** + * ZIP code + */ + private Integer zipCode; + + /** + * Default constructor + */ + public PizzaContactWebSessionBean () { + // Set gender to UNKNOWN + this.gender = Gender.UNKNOWN; + + // Try it + try { + // Get initial context + Context context = new InitialContext(); + + // Try to lookup + this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jratecalc-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N + } catch (final NamingException e) { + // Throw again + throw new FaceletException(e); + } + } + + @Override + public void addEmailAddress (final String contactEmailAddress) { + // Add it + this.emailAddressList.add(contactEmailAddress); + } + + @Override + public void afterRegistrationEvent (final @Observes UserRegisteredEvent event) { + // Trace message + System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N + + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getRegisteredUser() == null) { + // Throw NPE again + throw new NullPointerException("event.user is null"); //NOI18N + } else if (event.getRegisteredUser().getUserId() == null) { + // userId is null + throw new NullPointerException("event.user.userId is null"); //NOI18N + } else if (event.getRegisteredUser().getUserId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N + } + + // Get user instance + Contact registeredContact = event.getRegisteredUser().getUserContact(); + + // Debug message + System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: registeredContact={0}", registeredContact)); //NOI18N + + // Copy all data from registered->user + this.copyContact(registeredContact); + + // Add user name and email address + this.addUserNameEmailAddress(registeredContact); + + // Clear all data + this.clear(); + + // Trace message + System.out.println("ContactWebBean:afterRegistration: EXIT!"); //NOI18N + } + + @Override + public void afterUserLogin (final @Observes UserLoggedInEvent event) { + // Trace message + System.out.println(MessageFormat.format("ContactWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N + + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getLoggedInUser() == null) { + // Throw NPE again + throw new NullPointerException("event.user is null"); //NOI18N + } else if (event.getLoggedInUser().getUserId() == null) { + // userId is null + throw new NullPointerException("event.user.userId is null"); //NOI18N + } else if (event.getLoggedInUser().getUserId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N + } + + // Copy all data to this bean + this.copyContact(event.getLoggedInUser().getUserContact()); + + // Trace message + System.out.println("ContactWebBean:afterUserLogin - EXIT!"); //NOI18N + } + + /** + * Clears this bean + */ + @Override + public void clear () { + // Clear all data + // - personal data + this.setGender(Gender.UNKNOWN); + this.setFirstName(null); + this.setFamilyName(null); + this.setStreet(null); + this.setHouseNumber(null); + this.setZipCode(null); + this.setCity(null); + this.setCountry(null); + + // - contact data + this.setEmailAddress(null); + this.setEmailAddressRepeat(null); + this.setPhoneAreaCode(null); + this.setCellphoneCarrier(null); + this.setFaxAreaCode(null); + + // - other data + this.setBirthday(null); + this.setComment(null); + } + + @Override + public Contact createContactInstance () { + // User message + //this.getLogger().logTrace("createContactInstance: CALLED!"); + + // Required personal data must be set + assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N + + // Create new contact instance + Contact localContact = new UserContact(); + + // Generate phone number + DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber()); + DialableCellphoneNumber cellphone = new CellphoneNumber(this.getCellphoneCarrier(), this.getCellphoneNumber()); + DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber()); + + // Create new contact + Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName()); + contact.setContactStreet(this.getStreet()); + contact.setContactHouseNumber(this.getHouseNumber()); + contact.setContactZipCode(this.getZipCode()); + contact.setContactCity(this.getCity()); + contact.setContactCountry(this.getCountry()); + contact.setContactEmailAddress(this.getEmailAddress()); + + // Don't set null or wrong references + if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) { + // Now the number must be given + if (phone.getPhoneAreaCode() == null) { + // Is null + throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N + } else if (phone.getPhoneAreaCode() < 1) { + // Abort here + throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N + } else if (phone.getPhoneNumber() == null) { + // Is null + throw new NullPointerException("phone.phoneNumber is null"); //NOI18N + } else if (phone.getPhoneNumber() < 1) { + // Abort here + throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N + } + + // Set phone number + contact.setContactLandLineNumber(phone); + } + + // Don't set null or wrong references + if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) { + // Now the number must be given + if (fax.getPhoneAreaCode() == null) { + // Is null + throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N + } else if (fax.getPhoneAreaCode() < 1) { + // Abort here + throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N + } else if (fax.getPhoneNumber() == null) { + // Is null + throw new NullPointerException("fax.phoneNumber is null"); //NOI18N + } else if (fax.getPhoneNumber() < 1) { + // Abort here + throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N + } + + // Set fax number + contact.setContactFaxNumber(fax); + } + + // Is the provider set? + if ((cellphone instanceof DialableCellphoneNumber) && (this.getCellphoneCarrier() instanceof MobileProvider) && (this.getCellphoneNumber() != null) && (this.getCellphoneNumber() > 0)) { + // Is the number set? + if (cellphone.getPhoneNumber() == null) { + // Is null + throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N + } else if (cellphone.getPhoneNumber() < 1) { + // Abort here + throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N + } + + // Set cellphone number + contact.setContactCellphoneNumber(cellphone); + } + + contact.setContactBirthday(this.getBirthday()); + contact.setContactComment(this.getComment()); + + // Created timestamp and ownContact + contact.setContactOwnContact(Boolean.TRUE); + + // Trace message + //this.getLogger().logTrace(MessageFormat.format("createContactInstance: localContact={0} - EXIT!", localContact)); + // Return it + return localContact; + } + + @Override + public String doChangePersonalContactData () { + // This method shall only be called if the user is logged-in + if (!this.loginController.isUserLoggedIn()) { + // Not logged-in + throw new IllegalStateException("User is not logged-in"); //NOI18N + } else if (!this.isRequiredChangePersonalDataSet()) { + // Not all required fields are set + throw new FaceletException("Not all required fields are set."); //NOI18N + } else if (!this.loginController.ifCurrentPasswordMatches()) { + // Password not matching + throw new FaceletException(new UserPasswordMismatchException(this.loginController.getLoggedInUser())); + } + + // Get contact instance + Contact contact = this.loginController.getLoggedInUser().getUserContact(); + + // It should be there, so run some tests on it + assert (contact instanceof Contact) : "Instance loginController.loggedInUser.userContact is null"; //NOI18N + assert (contact.getContactId() instanceof Long) : "Instance loginController.userContact.contactId is null"; //NOI18N + assert (contact.getContactId() > 0) : MessageFormat.format("Instance loginController.userContact.contactId={0} is invalid", contact.getContactId()); //NOI18N + + // Update all fields + contact.setContactGender(this.getGender()); + contact.setContactFirstName(this.getFirstName()); + contact.setContactFamilyName(this.getFamilyName()); + contact.setContactStreet(this.getStreet()); + contact.setContactHouseNumber(this.getHouseNumber()); + contact.setContactZipCode(this.getZipCode()); + contact.setContactCity(this.getCity()); + contact.setContactCountry(this.getCountry()); + + // Is there a phone number? + if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) { + // Debug message + System.out.println(MessageFormat.format("ContactWebBean:doChangePersonalData: phoneId={0}", contact.getContactLandLineNumber().getPhoneId())); //NOI18N + + // Yes, then update as well + contact.getContactLandLineNumber().setPhoneAreaCode(this.getPhoneAreaCode()); + contact.getContactLandLineNumber().setPhoneNumber(this.getPhoneNumber()); + } + + // Is there a fax number? + if (contact.getContactFaxNumber() instanceof DialableFaxNumber) { + // Debug message + System.out.println(MessageFormat.format("ContactWebBean:doChangePersonalData: faxId={0}", contact.getContactFaxNumber().getPhoneId())); //NOI18N + + // Yes, then update as well + contact.getContactFaxNumber().setPhoneAreaCode(this.getFaxAreaCode()); + contact.getContactFaxNumber().setPhoneNumber(this.getFaxNumber()); + } + + // Is there a cellphone number? + if (contact.getContactCellphoneNumber() instanceof DialableCellphoneNumber) { + // Debug message + System.out.println(MessageFormat.format("ContactWebBean:doChangePersonalData: cellPhoneId={0}", contact.getContactCellphoneNumber().getPhoneId())); //NOI18N + + // Yes, then update as well + contact.getContactCellphoneNumber().setCellphoneProvider(this.getCellphoneCarrier()); + contact.getContactCellphoneNumber().setPhoneNumber(this.getCellphoneNumber()); + } + + // Send it to the EJB + this.contactBean.updateContactPersonalData(contact); + + // All fine + return "contact_data_saved"; //NOI18N + } + + @Override + public Date getBirthday () { + return this.birthday; + } + + @Override + public void setBirthday (final Date birthday) { + this.birthday = birthday; + } + + @Override + public MobileProvider getCellphoneCarrier () { + return this.cellphoneCarrier; + } + + @Override + public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) { + this.cellphoneCarrier = cellphoneCarrier; + } + + @Override + public Long getCellphoneNumber () { + return this.cellphoneNumber; + } + + @Override + public void setCellphoneNumber (Long cellphoneNumber) { + this.cellphoneNumber = cellphoneNumber; + } + + @Override + public String getCity () { + return this.city; + } + + @Override + public void setCity (final String city) { + this.city = city; + } + + @Override + public String getComment () { + return this.comment; + } + + @Override + public void setComment (final String comment) { + this.comment = comment; + } + + @Override + public Country getCountry () { + return this.country; + } + + @Override + public void setCountry (final Country country) { + this.country = country; + } + + @Override + public String getEmailAddress () { + return this.emailAddress; + } + + @Override + public void setEmailAddress (final String emailAddress) { + this.emailAddress = emailAddress; + } + + @Override + public String getEmailAddressRepeat () { + return this.emailAddressRepeat; + } + + @Override + public void setEmailAddressRepeat (final String emailAddressRepeat) { + this.emailAddressRepeat = emailAddressRepeat; + } + + @Override + public String getFamilyName () { + return this.familyName; + } + + @Override + public void setFamilyName (final String familyName) { + this.familyName = familyName; + } + + @Override + public Integer getFaxAreaCode () { + return this.faxAreaCode; + } + + @Override + public void setFaxAreaCode (final Integer faxAreaCode) { + this.faxAreaCode = faxAreaCode; + } + + @Override + public Country getFaxCountry () { + return this.faxCountry; + } + + @Override + public void setFaxCountry (final Country faxCountry) { + this.faxCountry = faxCountry; + } + + @Override + public Long getFaxNumber () { + return this.faxNumber; + } + + @Override + public void setFaxNumber (final Long faxNumber) { + this.faxNumber = faxNumber; + } + + @Override + public String getFirstName () { + return this.firstName; + } + + @Override + public void setFirstName (final String firstName) { + this.firstName = firstName; + } + + @Override + public Gender getGender () { + return this.gender; + } + + @Override + public void setGender (final Gender gender) { + this.gender = gender; + } + + @Override + public Short getHouseNumber () { + return this.houseNumber; + } + + @Override + public void setHouseNumber (final Short houseNumber) { + this.houseNumber = houseNumber; + } + + @Override + public Integer getPhoneAreaCode () { + return this.phoneAreaCode; + } + + @Override + public void setPhoneAreaCode (final Integer phoneAreaCode) { + this.phoneAreaCode = phoneAreaCode; + } + + @Override + public Country getPhoneCountry () { + return this.phoneCountry; + } + + @Override + public void setPhoneCountry (final Country phoneCountry) { + this.phoneCountry = phoneCountry; + } + + @Override + public Long getPhoneNumber () { + return this.phoneNumber; + } + + @Override + public void setPhoneNumber (final Long phoneNumber) { + this.phoneNumber = phoneNumber; + } + + @Override + public String getStreet () { + return this.street; + } + + @Override + public void setStreet (final String street) { + this.street = street; + } + + @Override + public Integer getZipCode () { + return this.zipCode; + } + + @Override + public void setZipCode (final Integer zipCode) { + this.zipCode = zipCode; + } + + /** + * Post-initialization of this class + */ + @PostConstruct + public void init () { + // Get full email address list for reducing EJB calls + this.emailAddressList = this.contactBean.getEmailAddressList(); + + // Get full contact list + this.contactList = this.contactBean.getAllContacts(); + } + + @Override + public boolean isEmailAddressRegistered (final Contact contact) { + return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(contact.getContactEmailAddress()))); + } + + @Override + public boolean isRequiredChangePersonalDataSet () { + return ((this.getGender() != null) && + (this.getFirstName() != null) && + (this.getFamilyName() != null) && + (this.getStreet() != null) && + (this.getHouseNumber() != null) && + (this.getZipCode() != null) && + (this.getCity() != null)); + } + + @Override + public boolean isRequiredPersonalDataSet () { + return ((this.getGender() != null) && + (this.getFirstName() != null) && + (this.getFamilyName() != null) && + (this.getStreet() != null) && + (this.getHouseNumber() != null) && + (this.getZipCode() != null) && + (this.getCity() != null) && + (this.getEmailAddress() != null) && + (this.getEmailAddressRepeat() != null)); + } + + @Override + public boolean isSameEmailAddressEntered () { + return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat())); + } + + @Override + public Contact lookupContactById (final Long contactId) throws ContactNotFoundException { + // Init variable + Contact localContact = null; + + // Clear this bean + this.clear(); + + // Try to lookup it in visible user list + for (final Iterator iterator = this.contactList.iterator(); iterator.hasNext();) { + // Get next user + Contact next = iterator.next(); + + // Is the user id found? + if (Objects.equals(next.getContactId(), contactId)) { + // Copy to other variable + localContact = next; + break; + } + } + + // Is it still null? + if (null == localContact) { + // Not visible for the current user + throw new ContactNotFoundException(contactId); + } + + // Copy all data to this bean + this.copyContact(localContact); + + // Return it + return localContact; + } + + @Override + public void updateContactDataFromController (final Contact userContact) { + // Is the instance valid? + if (null == userContact) { + // Throw NPE + throw new NullPointerException("userContact is null"); //NOI18N + } else if (userContact.getContactId() == null) { + // Throw NPE + throw new NullPointerException("userContact.contactId is null"); //NOI18N + } else if (userContact.getContactId() < 1) { + // Not valid id number + throw new IllegalArgumentException(MessageFormat.format("userContact.contactId={0} is not valid.", userContact.getContactId())); //NOI18N + } + + // Set all + this.copyContact(userContact); + } + + /** + * Adds email address to bean's internal list. + *

+ * @param contact Contact instance + */ + private void addUserNameEmailAddress (final Contact contact) { + // Make sure the entry is not added yet + if (this.emailAddressList.contains(contact.getContactEmailAddress())) { + // Already added + throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N + } + + // Add email addres + this.emailAddressList.add(contact.getContactEmailAddress()); + } + + /** + * Copies given contact into the controller + *

+ * @param contact Contact instance + */ + private void copyContact (final Contact contact) { + // Copy all fields: + // - base data + this.setGender(contact.getContactGender()); + this.setFirstName(contact.getContactFirstName()); + this.setFamilyName(contact.getContactFamilyName()); + this.setStreet(contact.getContactStreet()); + this.setHouseNumber(contact.getContactHouseNumber()); + this.setZipCode(contact.getContactZipCode()); + this.setCity(contact.getContactCity()); + this.setCountry(contact.getContactCountry()); + + // Get cellphone, phone and fax instance + DialableCellphoneNumber cellphone = contact.getContactCellphoneNumber(); + DialableFaxNumber fax = contact.getContactFaxNumber(); + DialableLandLineNumber phone = contact.getContactLandLineNumber(); + + // - contact data + if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) { + this.setPhoneCountry(phone.getPhoneCountry()); + this.setPhoneAreaCode(phone.getPhoneAreaCode()); + this.setPhoneNumber(phone.getPhoneNumber()); + } + if ((cellphone instanceof DialableCellphoneNumber) && (cellphone.getCellphoneProvider() instanceof MobileProvider)) { + this.setCellphoneCarrier(cellphone.getCellphoneProvider()); + this.setCellphoneNumber(cellphone.getPhoneNumber()); + } + if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) { + this.setFaxCountry(fax.getPhoneCountry()); + this.setFaxAreaCode(fax.getPhoneAreaCode()); + this.setFaxNumber(fax.getPhoneNumber()); + } + this.setEmailAddress(contact.getContactEmailAddress()); + + // -- other data + this.setBirthday(contact.getContactBirthday()); + this.setComment(contact.getContactComment()); + } + +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionController.java new file mode 100644 index 00000000..44aa596f --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionController.java @@ -0,0 +1,411 @@ +/* + * 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.contact; + +import java.io.Serializable; +import java.util.Date; +import org.mxchange.jcontacts.contact.Contact; +import org.mxchange.jcontacts.contact.gender.Gender; +import org.mxchange.jcontacts.exceptions.ContactNotFoundException; +import org.mxchange.jcountry.data.Country; +import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider; +import org.mxchange.jusercore.events.login.UserLoggedInEvent; +import org.mxchange.jusercore.events.registration.UserRegisteredEvent; + +/** + * An interface for user beans + *

+ * @author Roland Haeder + */ +public interface PizzaContactWebSessionController extends Serializable { + + /** + * Minimum password length + */ + public static final Integer MINIMUM_PASSWORD_LENGTH = 5; + + /** + * Updates all data from bean in given contact instance + *

+ * @param userContact Contact instance to update + */ + void updateContactDataFromController (final Contact userContact); + + /** + * Adds given email address to list + *

+ * @param contactEmailAddress Email address to add + */ + void addEmailAddress (final String contactEmailAddress); + + /** + * Tries to lookup contact by given id number. If the user is not found a + * proper exceptions are thrown. + *

+ * @param contactId Contact id + *

+ * @return Contact instance + *

+ * @throws ContactNotFoundException If the user is not found + */ + Contact lookupContactById (final Long contactId) throws ContactNotFoundException; + + /** + * Clears this controller + */ + void clear (); + + /** + * Event observer for new user registrations + *

+ * @param event User registration event + */ + void afterRegistrationEvent (final UserRegisteredEvent event); + + /** + * Event observer for logged-in user + *

+ * @param event Event instance + */ + void afterUserLogin (final UserLoggedInEvent event); + + /** + * Creates an instance from all properties + *

+ * @return A contact instance + */ + Contact createContactInstance (); + + /** + * Getter for birth day + *

+ * @return Birth day + */ + Date getBirthday (); + + /** + * Setter for birth day + *

+ * @param birthday Birth day + */ + void setBirthday (final Date birthday); + + /** + * Getter for ellphone number's carrier + *

+ * @return Cellphone number's carrier + */ + MobileProvider getCellphoneCarrier (); + + /** + * Setter for cellphone number's carrier prefix + *

+ * @param cellphoneCarrier Cellphone number's carrier prefix + */ + void setCellphoneCarrier (final MobileProvider cellphoneCarrier); + + /** + * Getter for ellphone number + *

+ * @return Cellphone number + */ + Long getCellphoneNumber (); + + /** + * Setter for ellphone number + *

+ * @param cellphoneNumber Cellphone number + */ + void setCellphoneNumber (final Long cellphoneNumber); + + /** + * City + *

+ * @return the city + */ + String getCity (); + + /** + * City + *

+ * @param city the city to set + */ + void setCity (final String city); + + /** + * Getter for comments + *

+ * @return Comments + */ + String getComment (); + + /** + * Setter for comment + *

+ * @param comment Comments + */ + void setComment (final String comment); + + /** + * Getter for country instance + *

+ * @return Country instance + */ + Country getCountry (); + + /** + * Setter for country instance + *

+ * @param country Country instance + */ + void setCountry (final Country country); + + /** + * Getter for email address + *

+ * @return Email address + */ + String getEmailAddress (); + + /** + * Setter for email address + *

+ * @param emailAddress Email address + */ + void setEmailAddress (final String emailAddress); + + /** + * Getter for email address, repeated + *

+ * @return the emailAddress, repeated + */ + String getEmailAddressRepeat (); + + /** + * Setter for email address repeated + *

+ * @param emailAddressRepeat the emailAddress to set + */ + void setEmailAddressRepeat (final String emailAddressRepeat); + + /** + * Family name + *

+ * @return the familyName + */ + String getFamilyName (); + + /** + * Family name + *

+ * @param familyName the familyName to set + */ + void setFamilyName (final String familyName); + + /** + * Getter for fax number's area code + *

+ * @return Fax number's area code + */ + Integer getFaxAreaCode (); + + /** + * Setter for fax number's area code + *

+ * @param faxAreaCode Fax number's area code + */ + void setFaxAreaCode (final Integer faxAreaCode); + + /** + * Getter for fax's country instance + *

+ * @return Fax' country instance + */ + Country getFaxCountry (); + + /** + * Setter for fax's country instance + *

+ * @param faxCountry Fax' country instance + */ + void setFaxCountry (final Country faxCountry); + + /** + * Getter for fax number + *

+ * @return Fax number + */ + Long getFaxNumber (); + + /** + * Setter for fax number + *

+ * @param faxNumber Fax number + */ + void setFaxNumber (final Long faxNumber); + + /** + * First name + *

+ * @return the first name + */ + String getFirstName (); + + /** + * First name + *

+ * @param firstName the first name to set + */ + void setFirstName (final String firstName); + + /** + * Gender of the contact + *

+ * @return the gender + */ + Gender getGender (); + + /** + * Gender of the contact + *

+ * @param gender the gender to set + */ + void setGender (final Gender gender); + + /** + * House number + *

+ * @return the houseNumber + */ + Short getHouseNumber (); + + /** + * House number + *

+ * @param houseNumber the houseNumber to set + */ + void setHouseNumber (final Short houseNumber); + + /** + * Getter for phone number's area code + *

+ * @return Phone number's area code + */ + Integer getPhoneAreaCode (); + + /** + * Setter for phone number's area code + *

+ * @param phoneAreaCode Phone number's area code + */ + void setPhoneAreaCode (final Integer phoneAreaCode); + + /** + * Getter for phone number's country instance + *

+ * @return Phone number's country instance + */ + Country getPhoneCountry (); + + /** + * Setter for phone number's country instance + *

+ * @param phoneCountry Phone number's country instance + */ + void setPhoneCountry (final Country phoneCountry); + + /** + * Getter for phone number + *

+ * @return Phone number + */ + Long getPhoneNumber (); + + /** + * Setter for phone number + *

+ * @param phoneNumber Phone number + */ + void setPhoneNumber (final Long phoneNumber); + + /** + * Street + *

+ * @return the street + */ + String getStreet (); + + /** + * Street + *

+ * @param street the street to set + */ + void setStreet (final String street); + + /** + * ZIP code + *

+ * @return the zipCode + */ + Integer getZipCode (); + + /** + * ZIP code + *

+ * @param zipCode the zipCode to set + */ + void setZipCode (final Integer zipCode); + + /** + * Checks whether contact instance's email address is used + *

+ * @param contact Contact instance's email address to check + *

+ * @return Whether it is already used + */ + boolean isEmailAddressRegistered (final Contact contact); + + /** + * Checks whether all required personal data is set + *

+ * @return Whether the required personal data is set + */ + boolean isRequiredPersonalDataSet (); + + /** + * Checks whether all required personal data is set for changing them + *

+ * @return Whether the required personal data is set + */ + boolean isRequiredChangePersonalDataSet (); + + /** + * Checks whether same email addresses have been entered + *

+ * @return Whether same email addresses have been entered + */ + boolean isSameEmailAddressEntered (); + + /** + * Changes logged-in user's personal data if the current password matches + * and TAC + privacy statement has been accepted. + *

+ * @return New target page + */ + String doChangePersonalContactData (); + +} 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 c14d4a5c..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/country/PizzaAdminCountryWebApplicationBean.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.pizzaapplication.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 PizzaAdminCountryWebApplicationBean implements PizzaAdminCountryWebApplicationController { - - /** - * 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 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)); - } - - // 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/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); - -} diff --git a/src/java/org/mxchange/pizzaapplication/beans/country/PizzaAdminCountryWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/country/PizzaAdminCountryWebRequestBean.java new file mode 100644 index 00000000..1fef7df6 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/country/PizzaAdminCountryWebRequestBean.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.pizzaapplication.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 PizzaAdminCountryWebRequestBean implements PizzaAdminCountryWebRequestController { + + /** + * 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 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 PizzaAdminCountryWebRequestBean () { + // 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)); + } + + // 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/pizzaapplication/beans/country/PizzaAdminCountryWebRequestController.java b/src/java/org/mxchange/pizzaapplication/beans/country/PizzaAdminCountryWebRequestController.java new file mode 100644 index 00000000..64222449 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/country/PizzaAdminCountryWebRequestController.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.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 PizzaAdminCountryWebRequestController 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/helper/PizzaAdminWebRequestHelper.java b/src/java/org/mxchange/pizzaapplication/beans/helper/PizzaAdminWebRequestHelper.java index b30ee67d..fe347eea 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/helper/PizzaAdminWebRequestHelper.java +++ b/src/java/org/mxchange/pizzaapplication/beans/helper/PizzaAdminWebRequestHelper.java @@ -21,9 +21,9 @@ import javax.enterprise.context.RequestScoped; import javax.inject.Inject; import javax.inject.Named; import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jratecalc.beans.contact.PizzaAdminContactWebRequestController; +import org.mxchange.pizzaapplication.beans.contact.PizzaAdminContactWebRequestController; import org.mxchange.jusercore.model.user.User; -import org.mxchange.pizzaapplication.beans.user.PizzaAdminUserWebSessionController; +import org.mxchange.pizzaapplication.beans.user.PizzaAdminUserWebRequestController; /** * A general helper for beans @@ -49,7 +49,7 @@ public class PizzaAdminWebRequestHelper implements PizzaAdminWebRequestControlle * Admin user controller */ @Inject - private PizzaAdminUserWebSessionController adminUserController; + private PizzaAdminUserWebRequestController adminUserController; /** * User instance diff --git a/src/java/org/mxchange/pizzaapplication/beans/phone/PizzaAdminContactPhoneWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/phone/PizzaAdminContactPhoneWebRequestBean.java new file mode 100644 index 00000000..f289ca94 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/phone/PizzaAdminContactPhoneWebRequestBean.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.pizzaapplication.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 PizzaAdminContactPhoneWebRequestBean implements PizzaAdminContactPhoneWebRequestController { + + /** + * 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 PizzaAdminContactPhoneWebRequestBean () { + // 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/pizzaapplication/beans/phone/PizzaAdminContactPhoneWebRequestController.java b/src/java/org/mxchange/pizzaapplication/beans/phone/PizzaAdminContactPhoneWebRequestController.java new file mode 100644 index 00000000..400e97d3 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/phone/PizzaAdminContactPhoneWebRequestController.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.pizzaapplication.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 PizzaAdminContactPhoneWebRequestController 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/pizzaapplication/beans/phone/PizzaAdminContactPhoneWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/phone/PizzaAdminContactPhoneWebSessionBean.java deleted file mode 100644 index 5928351b..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/phone/PizzaAdminContactPhoneWebSessionBean.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.pizzaapplication.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 PizzaAdminContactPhoneWebSessionBean implements PizzaAdminContactPhoneWebSessionController { - - /** - * 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 PizzaAdminContactPhoneWebSessionBean () { - // 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/pizzaapplication/beans/phone/PizzaAdminContactPhoneWebSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/phone/PizzaAdminContactPhoneWebSessionController.java deleted file mode 100644 index 97321ad7..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/phone/PizzaAdminContactPhoneWebSessionController.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.pizzaapplication.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 PizzaAdminContactPhoneWebSessionController 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/pizzaapplication/beans/register/PizzaUserRegisterWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/register/PizzaUserRegisterWebSessionBean.java index 1eb3e905..2b339ea8 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/register/PizzaUserRegisterWebSessionBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/register/PizzaUserRegisterWebSessionBean.java @@ -26,7 +26,7 @@ import javax.inject.Named; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; -import org.mxchange.jratecalc.beans.contact.PizzaContactWebSessionController; +import org.mxchange.pizzaapplication.beans.contact.PizzaContactWebSessionController; import org.mxchange.jusercore.events.registration.RegisteredUserEvent; import org.mxchange.jusercore.events.registration.UserRegisteredEvent; import org.mxchange.jusercore.exceptions.DataRepeatMismatchException; diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java new file mode 100644 index 00000000..7f11e8b8 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java @@ -0,0 +1,299 @@ +/* + * 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.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.pizzaapplication.beans.contact.PizzaContactWebSessionController; +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; + +/** + * A user bean (controller) + *

+ * @author Roland Haeder + */ +@Named ("adminUserController") +@RequestScoped +public class PizzaAdminUserWebRequestBean implements PizzaAdminUserWebRequestController { + + /** + * 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 PizzaContactWebSessionController contactController; + + /** + * Remote user bean + */ + private final UserSessionBeanRemote userBean; + + /** + * Regular user controller + */ + @Inject + private PizzaUserWebSessionController userController; + + /** + * 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; + + /** + * Default constructor + */ + public PizzaAdminUserWebRequestBean () { + // Try it + try { + // Get initial context + Context context = new InitialContext(); + + // Try to lookup + this.userBean = (UserSessionBeanRemote) context.lookup("java:global/PizzaService-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(PizzaUserWebSessionController.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() >= PizzaUserWebSessionController.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/pizzaapplication/beans/user/PizzaAdminUserWebRequestController.java b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestController.java new file mode 100644 index 00000000..7a64e7b4 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestController.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.pizzaapplication.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 PizzaAdminUserWebRequestController 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/pizzaapplication/beans/user/PizzaAdminUserWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebSessionBean.java deleted file mode 100644 index 61f5f5d0..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebSessionBean.java +++ /dev/null @@ -1,299 +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.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.jratecalc.beans.contact.PizzaContactWebSessionController; -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; - -/** - * A user bean (controller) - *

- * @author Roland Haeder - */ -@Named ("adminUserController") -@SessionScoped -public class PizzaAdminUserWebSessionBean implements PizzaAdminUserWebSessionController { - - /** - * 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 PizzaContactWebSessionController contactController; - - /** - * Remote user bean - */ - private final UserSessionBeanRemote userBean; - - /** - * Regular user controller - */ - @Inject - private PizzaUserWebSessionController userController; - - /** - * 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; - - /** - * Default constructor - */ - public PizzaAdminUserWebSessionBean () { - // Try it - try { - // Get initial context - Context context = new InitialContext(); - - // Try to lookup - this.userBean = (UserSessionBeanRemote) context.lookup("java:global/PizzaService-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(PizzaUserWebSessionController.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() >= PizzaUserWebSessionController.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/pizzaapplication/beans/user/PizzaAdminUserWebSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebSessionController.java deleted file mode 100644 index 15edff03..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebSessionController.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.pizzaapplication.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 PizzaAdminUserWebSessionController 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/pizzaapplication/beans/user/PizzaUserWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionBean.java index f1818294..e8f06a21 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionBean.java @@ -42,7 +42,7 @@ 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.pizzaapplication.beans.login.PizzaUserLoginWebSessionController; -import org.mxchange.jratecalc.beans.contact.PizzaContactWebSessionController; +import org.mxchange.pizzaapplication.beans.contact.PizzaContactWebSessionController; import org.mxchange.jusercore.exceptions.UserPasswordMismatchException; /**