--- /dev/null
+/*
+ * Copyright (C) 2016 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.pizzaapplication.beans.user;
+
+import java.util.Collections;
+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.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.gender.Gender;
+import org.mxchange.jcountry.data.Country;
+import org.mxchange.jphone.phonenumbers.smsprovider.SmsProvider;
+import org.mxchange.jusercore.exceptions.UserNotFoundException;
+import org.mxchange.jusercore.model.user.User;
+import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
+import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
+
+/**
+ * A user bean (controller)
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+@Named ("adminUserController")
+@SessionScoped
+public class PizzaAdminUserWebSessionBean implements PizzaAdminUserWebSessionController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 542_145_347_916L;
+
+ /////////////////////// Properties /////////////////////
+ /**
+ * Birth day
+ */
+ private Date birthday;
+
+ /**
+ * Cellphone number's carrier
+ */
+ private SmsProvider cellphoneCarrier;
+
+ /**
+ * Cellphone number
+ */
+ private Long cellphoneNumber;
+
+ /**
+ * City
+ */
+ private String city;
+
+ /**
+ * Optional comments
+ */
+ private String comment;
+
+ /**
+ * 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 number
+ */
+ private Long faxNumber;
+
+ /**
+ * First name
+ */
+ private String firstName;
+
+ /**
+ * Gender instance
+ */
+ private Gender gender;
+
+ /**
+ * House number
+ */
+ private Short houseNumber;
+
+ /**
+ * Phone number area code
+ */
+ private Integer phoneAreaCode;
+
+ /**
+ * Country instance for phone number
+ */
+ private Country phoneCountry;
+
+ /**
+ * Phone number
+ */
+ private Long phoneNumber;
+
+ /**
+ * Street
+ */
+ private String street;
+
+ /**
+ * Remote user bean
+ */
+ private final UserSessionBeanRemote userBean;
+
+ /**
+ * User id
+ */
+ private Long userId;
+
+ /**
+ * A list of all user profiles
+ */
+ private List<User> userList;
+
+ /**
+ * User name
+ */
+ private String userName;
+
+ /**
+ * User password (unencrypted from web form)
+ */
+ private String userPassword;
+
+ /**
+ * User password repeated (unencrypted from web form)
+ */
+ private String userPasswordRepeat;
+
+ /**
+ * Whether the user wants a public profile
+ */
+ private ProfileMode userProfileMode;
+
+ /**
+ * ZIP code
+ */
+ private Integer zipCode;
+
+ /**
+ * Default constructor
+ */
+ public PizzaAdminUserWebSessionBean () {
+ // Set gender to UNKNOWN
+ this.gender = Gender.UNKNOWN;
+
+ // 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 List<User> allUsers () {
+ // Return it
+ return Collections.unmodifiableList(this.userList);
+ }
+
+ @Override
+ public Date getBirthday () {
+ return this.birthday;
+ }
+
+ @Override
+ public void setBirthday (final Date birthday) {
+ this.birthday = birthday;
+ }
+
+ @Override
+ public SmsProvider getCellphoneCarrier () {
+ return this.cellphoneCarrier;
+ }
+
+ @Override
+ public void setCellphoneCarrier (final SmsProvider 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 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 Long getUserId () {
+ return this.userId;
+ }
+
+ @Override
+ public void setUserId (final Long userId) {
+ this.userId = userId;
+ }
+
+ @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 ProfileMode getUserProfileMode () {
+ return this.userProfileMode;
+ }
+
+ @Override
+ public void setUserProfileMode (final ProfileMode userProfileMode) {
+ this.userProfileMode = userProfileMode;
+ }
+
+ @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 () {
+ // Initialize user list
+ this.userList = this.userBean.allUsers();
+ }
+
+ @Override
+ public User lookupUserById (final Long userId) throws UserNotFoundException {
+ // Init variable
+ User user = null;
+
+ // Try to lookup it in visible user list
+ for (final Iterator<User> iterator = this.userList.iterator(); iterator.hasNext();) {
+ // Get next user
+ User next = iterator.next();
+
+ // Is the user id found?
+ if (Objects.equals(next.getUserId(), userId)) {
+ // Copy to other variable
+ user = next;
+ break;
+ }
+ }
+
+ // Is it still null?
+ if (null == user) {
+ // Not visible for the current user
+ throw new UserNotFoundException(userId);
+ }
+
+ // Return it
+ return user;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2016 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.pizzaapplication.beans.user;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.util.List;
+import org.mxchange.jcontacts.contact.gender.Gender;
+import org.mxchange.jcountry.data.Country;
+import org.mxchange.jphone.phonenumbers.smsprovider.SmsProvider;
+import org.mxchange.jusercore.exceptions.UserNotFoundException;
+import org.mxchange.jusercore.model.user.User;
+import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
+
+/**
+ * An interface for user beans
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+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.
+ * <p>
+ * @param userId User id
+ * <p>
+ * @return User instance
+ * <p>
+ * @throws UserNotFoundException If the user is not found
+ */
+ User lookupUserById (final Long userId) throws UserNotFoundException;
+
+ /**
+ * All users
+ * <p>
+ * @return A list of all public user profiles
+ */
+ List<User> allUsers ();
+
+ /**
+ * Getter for birth day
+ * <p>
+ * @return Birth day
+ */
+ Date getBirthday ();
+
+ /**
+ * Setter for birth day
+ * <p>
+ * @param birthday Birth day
+ */
+ void setBirthday (final Date birthday);
+
+ /**
+ * Getter for ellphone number's carrier
+ * <p>
+ * @return Cellphone number's carrier
+ */
+ SmsProvider getCellphoneCarrier ();
+
+ /**
+ * Setter for cellphone number's carrier prefix
+ * <p>
+ * @param cellphoneCarrier Cellphone number's carrier prefix
+ */
+ void setCellphoneCarrier (final SmsProvider cellphoneCarrier);
+
+ /**
+ * Getter for ellphone number
+ * <p>
+ * @return Cellphone number
+ */
+ Long getCellphoneNumber ();
+
+ /**
+ * Setter for ellphone number
+ * <p>
+ * @param cellphoneNumber Cellphone number
+ */
+ void setCellphoneNumber (final Long cellphoneNumber);
+
+ /**
+ * City
+ * <p>
+ * @return the city
+ */
+ String getCity ();
+
+ /**
+ * City
+ * <p>
+ * @param city the city to set
+ */
+ void setCity (final String city);
+
+ /**
+ * Getter for comments
+ * <p>
+ * @return Comments
+ */
+ String getComment ();
+
+ /**
+ * Setter for comment
+ * <p>
+ * @param comment Comments
+ */
+ void setComment (final String comment);
+
+ /**
+ * Getter for country instance
+ * <p>
+ * @return Country instance
+ */
+ Country getCountry ();
+
+ /**
+ * Setter for country instance
+ * <p>
+ * @param country Country instance
+ */
+ void setCountry (final Country country);
+
+ /**
+ * Getter for email address
+ * <p>
+ * @return Email address
+ */
+ String getEmailAddress ();
+
+ /**
+ * Setter for email address
+ * <p>
+ * @param emailAddress Email address
+ */
+ void setEmailAddress (final String emailAddress);
+
+ /**
+ * Family name
+ * <p>
+ * @return the familyName
+ */
+ String getFamilyName ();
+
+ /**
+ * Family name
+ * <p>
+ * @param familyName the familyName to set
+ */
+ void setFamilyName (final String familyName);
+
+ /**
+ * Getter for fax number's area code
+ * <p>
+ * @return Fax number's area code
+ */
+ Integer getFaxAreaCode ();
+
+ /**
+ * Setter for fax number's area code
+ * <p>
+ * @param faxAreaCode Fax number's area code
+ */
+ void setFaxAreaCode (final Integer faxAreaCode);
+
+ /**
+ * Getter for fax's country instance
+ * <p>
+ * @return Fax' country instance
+ */
+ Country getFaxCountry ();
+
+ /**
+ * Setter for fax's country instance
+ * <p>
+ * @param faxCountry Fax' country instance
+ */
+ void setFaxCountry (final Country faxCountry);
+
+ /**
+ * Getter for fax number
+ * <p>
+ * @return Fax number
+ */
+ Long getFaxNumber ();
+
+ /**
+ * Setter for fax number
+ * <p>
+ * @param faxNumber Fax number
+ */
+ void setFaxNumber (final Long faxNumber);
+
+ /**
+ * First name
+ * <p>
+ * @return the first name
+ */
+ String getFirstName ();
+
+ /**
+ * First name
+ * <p>
+ * @param firstName the first name to set
+ */
+ void setFirstName (final String firstName);
+
+ /**
+ * Gender of the contact
+ * <p>
+ * @return the gender
+ */
+ Gender getGender ();
+
+ /**
+ * Gender of the contact
+ * <p>
+ * @param gender the gender to set
+ */
+ void setGender (final Gender gender);
+
+ /**
+ * House number
+ * <p>
+ * @return the houseNumber
+ */
+ Short getHouseNumber ();
+
+ /**
+ * House number
+ * <p>
+ * @param houseNumber the houseNumber to set
+ */
+ void setHouseNumber (final Short houseNumber);
+
+ /**
+ * Getter for phone number's area code
+ * <p>
+ * @return Phone number's area code
+ */
+ Integer getPhoneAreaCode ();
+
+ /**
+ * Setter for phone number's area code
+ * <p>
+ * @param phoneAreaCode Phone number's area code
+ */
+ void setPhoneAreaCode (final Integer phoneAreaCode);
+
+ /**
+ * Getter for phone number's country instance
+ * <p>
+ * @return Phone number's country instance
+ */
+ Country getPhoneCountry ();
+
+ /**
+ * Setter for phone number's country instance
+ * <p>
+ * @param phoneCountry Phone number's country instance
+ */
+ void setPhoneCountry (final Country phoneCountry);
+
+ /**
+ * Getter for phone number
+ * <p>
+ * @return Phone number
+ */
+ Long getPhoneNumber ();
+
+ /**
+ * Setter for phone number
+ * <p>
+ * @param phoneNumber Phone number
+ */
+ void setPhoneNumber (final Long phoneNumber);
+
+ /**
+ * Street
+ * <p>
+ * @return the street
+ */
+ String getStreet ();
+
+ /**
+ * Street
+ * <p>
+ * @param street the street to set
+ */
+ void setStreet (final String street);
+
+ /**
+ * Getter for user id
+ * <p>
+ * @return User id
+ */
+ Long getUserId ();
+
+ /**
+ * Setter for user id
+ * <p>
+ * @param userId User id
+ */
+ void setUserId (final Long userId);
+
+ /**
+ * Getter for user name
+ * <p>
+ * @return User name
+ */
+ String getUserName ();
+
+ /**
+ * Setter for user name
+ * <p>
+ * @param userName User name
+ */
+ void setUserName (final String userName);
+
+ /**
+ * Getter for unencrypted user password
+ * <p>
+ * @return Unencrypted user password
+ */
+ String getUserPassword ();
+
+ /**
+ * Setter for unencrypted user password
+ * <p>
+ * @param userPassword Unencrypted user password
+ */
+ void setUserPassword (final String userPassword);
+
+ /**
+ * Getter for unencrypted user password repeated
+ * <p>
+ * @return Unencrypted user password repeated
+ */
+ String getUserPasswordRepeat ();
+
+ /**
+ * Setter for unencrypted user password repeated
+ * <p>
+ * @param userPasswordRepeat Unencrypted user password repeated
+ */
+ void setUserPasswordRepeat (final String userPasswordRepeat);
+
+ /**
+ * Getter for user profile mode
+ * <p>
+ * @return User profile mode
+ */
+ ProfileMode getUserProfileMode ();
+
+ /**
+ * Setter for user profile mode
+ * <p>
+ * @param userProfileMode User profile mode
+ */
+ void setUserProfileMode (final ProfileMode userProfileMode);
+
+ /**
+ * ZIP code
+ * <p>
+ * @return the zipCode
+ */
+ Integer getZipCode ();
+
+ /**
+ * ZIP code
+ * <p>
+ * @param zipCode the zipCode to set
+ */
+ void setZipCode (final Integer zipCode);
+
+}