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 java.util.Date;
20 import javax.enterprise.context.SessionScoped;
21 import javax.faces.view.facelets.FaceletException;
22 import javax.inject.Named;
23 import javax.naming.Context;
24 import javax.naming.InitialContext;
25 import javax.naming.NamingException;
26 import org.mxchange.jcontacts.contact.Contact;
27 import org.mxchange.jcontacts.contact.UserContact;
28 import org.mxchange.jcontacts.contact.gender.Gender;
29 import org.mxchange.jusercore.model.user.LoginUser;
30 import org.mxchange.jusercore.model.user.User;
31 import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
34 * A user bean (controller)
36 * @author Roland Haeder<roland@mxchange.org>
38 @Named ("userController")
40 public class UserWebBean implements UserWebController {
45 private static final long serialVersionUID = 542_145_347_916L;
47 /////////////////////// Properties /////////////////////
52 private Date birthday;
57 private String cellphoneNumber;
67 private String comment;
72 private String countryCode;
77 private String emailAddress;
82 private String familyName;
87 private String faxNumber;
92 private String firstName;
97 private Gender gender;
102 private Short houseNumber;
112 private String phoneNumber;
117 private String street;
122 private final UserSessionBeanRemote userBean;
127 private String userName;
130 * User password (unencrypted from web form)
132 private String userPassword;
137 private Integer zipCode;
140 * Default constructor
142 public UserWebBean () {
143 // Set gender to UNKNOWN
144 this.gender = Gender.UNKNOWN;
148 // Get initial context
149 Context context = new InitialContext();
152 this.userBean = (UserSessionBeanRemote) context.lookup("ejb/stateless-user");
153 } catch (final NamingException e) {
155 throw new FaceletException(e);
160 public void copyUser (final User user) {
163 this.setUserId(user.getUserId());
164 this.setGender(user.getUserContact().getGender());
165 this.setFirstName(user.getUserContact().getFirstName());
166 this.setFamilyName(user.getUserContact().getFamilyName());
167 this.setStreet(user.getUserContact().getStreet());
168 this.setHouseNumber(user.getUserContact().getHouseNumber());
169 this.setZipCode(user.getUserContact().getZipCode());
170 this.setCity(user.getUserContact().getCity());
171 this.setCountryCode(user.getUserContact().getCountryCode());
174 this.setPhoneNumber(user.getUserContact().getPhoneNumber());
175 this.setCellphoneNumber(user.getUserContact().getCellphoneNumber());
176 this.setFaxNumber(user.getUserContact().getFaxNumber());
177 this.setEmailAddress(user.getUserContact().getEmailAddress());
180 this.setBirthday(user.getUserContact().getBirthday());
181 this.setComment(user.getUserContact().getComment());
185 public User createUserInstance () {
187 //this.getLogger().logTrace("createUserInstance: CALLED!");
189 // Required personal data must be set
190 assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
192 // Create new user instance
193 User user = new LoginUser();
194 user.setUserName(this.getUserName());
196 // Create new contact
197 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
198 contact.setStreet(this.getStreet());
199 contact.setHouseNumber(this.getHouseNumber());
200 contact.setZipCode(this.getZipCode());
201 contact.setCity(this.getCity());
202 contact.setPhoneNumber(this.getPhoneNumber());
203 contact.setFaxNumber(this.getFaxNumber());
204 contact.setCellphoneNumber(this.getCellphoneNumber());
205 contact.setBirthday(this.getBirthday());
206 contact.setComment(this.getComment());
208 // Set contact in user
209 user.setUserContact(contact);
212 //this.getLogger().logTrace(MessageFormat.format("createUserInstance: user={0} - EXIT!", user));
218 public Date getBirthday () {
223 public void setBirthday (final Date birthday) {
224 this.birthday = birthday;
228 public String getCellphoneNumber () {
229 return this.cellphoneNumber;
233 public void setCellphoneNumber (final String cellphoneNumber) {
234 this.cellphoneNumber = cellphoneNumber;
238 public String getCity () {
243 public void setCity (final String city) {
248 public String getComment () {
253 public void setComment (final String comment) {
254 this.comment = comment;
258 public String getCountryCode () {
259 return this.countryCode;
263 public void setCountryCode (final String countryCode) {
264 this.countryCode = countryCode;
268 public String getEmailAddress () {
269 return this.emailAddress;
273 public void setEmailAddress (final String emailAddress) {
274 this.emailAddress = emailAddress;
278 public String getFamilyName () {
279 return this.familyName;
283 public void setFamilyName (final String familyName) {
284 this.familyName = familyName;
288 public String getFaxNumber () {
289 return this.faxNumber;
293 public void setFaxNumber (final String faxNumber) {
294 this.faxNumber = faxNumber;
298 public String getFirstName () {
299 return this.firstName;
303 public void setFirstName (final String firstName) {
304 this.firstName = firstName;
308 public Gender getGender () {
313 public void setGender (final Gender gender) {
314 this.gender = gender;
318 public Short getHouseNumber () {
319 return this.houseNumber;
323 public void setHouseNumber (final Short houseNumber) {
324 this.houseNumber = houseNumber;
328 public String getPhoneNumber () {
329 return this.phoneNumber;
333 public void setPhoneNumber (final String phoneNumber) {
334 this.phoneNumber = phoneNumber;
338 public String getStreet () {
343 public void setStreet (final String street) {
344 this.street = street;
348 public Long getUserId () {
353 public void setUserId (final Long userId) {
354 this.userId = userId;
358 public String getUserName () {
359 return this.userName;
363 public void setUserName (final String userName) {
364 this.userName = userName;
368 public String getUserPassword () {
369 return this.userPassword;
373 public void setUserPassword (final String userPassword) {
374 this.userPassword = userPassword;
378 public Integer getZipCode () {
383 public void setZipCode (final Integer zipCode) {
384 this.zipCode = zipCode;
388 public boolean isRequiredPersonalDataSet () {
389 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));