2 * Copyright (C) 2015 Roland Haeder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.addressbook.beans.user;
19 import javax.enterprise.context.SessionScoped;
20 import javax.faces.view.facelets.FaceletException;
21 import javax.inject.Named;
22 import javax.naming.Context;
23 import javax.naming.InitialContext;
24 import javax.naming.NamingException;
25 import org.mxchange.jcontacts.contact.Contact;
26 import org.mxchange.jcontacts.contact.UserContact;
27 import org.mxchange.jcontacts.contact.gender.Gender;
28 import org.mxchange.jusercore.model.user.LoginUser;
29 import org.mxchange.jusercore.model.user.User;
30 import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
33 * A user bean (controller)
35 * @author Roland Haeder<roland@mxchange.org>
37 @Named ("userController")
39 public class UserWebBean implements UserWebController {
44 private static final long serialVersionUID = 542_145_347_916L;
46 /////////////////////// Properties /////////////////////
50 private String cellphoneNumber;
60 private String comment;
65 private String companyName;
70 private String countryCode;
75 private String emailAddress;
80 private String familyName;
85 private String faxNumber;
90 private String firstName;
95 private Gender gender;
100 private Short houseNumber;
105 private String phoneNumber;
110 private String street;
115 private final UserSessionBeanRemote userBean;
120 private String userName;
123 * User password (unencrypted from web form)
125 private String userPassword;
130 private Integer zipCode;
133 * Default constructor
135 public UserWebBean () {
136 // Set gender to UNKNOWN
137 this.gender = Gender.UNKNOWN;
141 // Get initial context
142 Context context = new InitialContext();
145 this.userBean = (UserSessionBeanRemote) context.lookup("ejb/stateless-user");
146 } catch (final NamingException e) {
148 throw new FaceletException(e);
153 public User createUserInstance () {
155 //this.getLogger().logTrace("createUserInstance: CALLED!");
157 // Required personal data must be set
158 assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
160 // Create new user instance
161 User user = new LoginUser();
162 user.setUserName(this.getUserName());
164 // Create new contact
165 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName(), this.getCompanyName());
166 contact.setStreet(this.getStreet());
167 contact.setHouseNumber(this.getHouseNumber());
168 contact.setZipCode(this.getZipCode());
169 contact.setCity(this.getCity());
170 contact.setPhoneNumber(this.getPhoneNumber());
171 contact.setFaxNumber(this.getFaxNumber());
172 contact.setCellphoneNumber(this.getCellphoneNumber());
173 contact.setComment(this.getComment());
175 // Set contact in user
176 user.setUserContact(contact);
179 //this.getLogger().logTrace(MessageFormat.format("createUserInstance: user={0} - EXIT!", user));
185 public String getCellphoneNumber () {
186 return this.cellphoneNumber;
190 public void setCellphoneNumber (final String cellphoneNumber) {
191 this.cellphoneNumber = cellphoneNumber;
195 public String getCity () {
200 public void setCity (final String city) {
205 public String getComment () {
210 public void setComment (final String comment) {
211 this.comment = comment;
215 public String getCompanyName () {
216 return this.companyName;
220 public void setCompanyName (final String companyName) {
221 this.companyName = companyName;
225 public String getCountryCode () {
226 return this.countryCode;
230 public void setCountryCode (final String countryCode) {
231 this.countryCode = countryCode;
235 public String getEmailAddress () {
236 return this.emailAddress;
240 public void setEmailAddress (final String emailAddress) {
241 this.emailAddress = emailAddress;
245 public String getFamilyName () {
246 return this.familyName;
250 public void setFamilyName (final String familyName) {
251 this.familyName = familyName;
255 public String getFaxNumber () {
256 return this.faxNumber;
260 public void setFaxNumber (final String faxNumber) {
261 this.faxNumber = faxNumber;
265 public String getFirstName () {
266 return this.firstName;
270 public void setFirstName (final String firstName) {
271 this.firstName = firstName;
275 public Gender getGender () {
280 public void setGender (final Gender gender) {
281 this.gender = gender;
285 public Short getHouseNumber () {
286 return this.houseNumber;
290 public void setHouseNumber (final Short houseNumber) {
291 this.houseNumber = houseNumber;
295 public String getPhoneNumber () {
296 return this.phoneNumber;
300 public void setPhoneNumber (final String phoneNumber) {
301 this.phoneNumber = phoneNumber;
305 public String getStreet () {
310 public void setStreet (final String street) {
311 this.street = street;
315 public String getUserName () {
316 return this.userName;
320 public void setUserName (final String userName) {
321 this.userName = userName;
325 public String getUserPassword () {
326 return this.userPassword;
330 public void setUserPassword (final String userPassword) {
331 this.userPassword = userPassword;
335 public Integer getZipCode () {
340 public void setZipCode (final Integer zipCode) {
341 this.zipCode = zipCode;
345 public boolean isRequiredPersonalDataSet () {
346 return ((this.getUserName() != null) && (this.getGender() != null) && (this.getFirstName() != null) && (this.getFamilyName() != null) && (this.getStreet() != null) && (this.getHouseNumber() != null) && (this.getZipCode() != null) && (this.getCity() != null));