2 * Copyright (C) 2016 Roland Haeder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation, either version 3 of the
7 * License, or (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 Affero General Public License for more details.
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jjobs.beans.user;
19 import java.util.Collections;
20 import java.util.Date;
21 import java.util.Iterator;
22 import java.util.List;
23 import java.util.Objects;
24 import javax.annotation.PostConstruct;
25 import javax.enterprise.context.SessionScoped;
26 import javax.faces.view.facelets.FaceletException;
27 import javax.inject.Named;
28 import javax.naming.Context;
29 import javax.naming.InitialContext;
30 import javax.naming.NamingException;
31 import org.mxchange.jcontacts.contact.gender.Gender;
32 import org.mxchange.jcountry.data.Country;
33 import org.mxchange.jphone.phonenumbers.smsprovider.SmsProvider;
34 import org.mxchange.jusercore.exceptions.UserNotFoundException;
35 import org.mxchange.jusercore.model.user.User;
36 import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
37 import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
40 * A user bean (controller)
42 * @author Roland Haeder<roland@mxchange.org>
44 @Named ("adminUserController")
46 public class JobsAdminUserWebSessionBean implements JobsAdminUserWebSessionController {
51 private static final long serialVersionUID = 542_145_347_916L;
53 /////////////////////// Properties /////////////////////
57 private Date birthday;
60 * Cellphone number's carrier
62 private SmsProvider cellphoneCarrier;
67 private Long cellphoneNumber;
77 private String comment;
82 private Country country;
87 private String emailAddress;
92 private String familyName;
95 * Fax number's area code
97 private Integer faxAreaCode;
100 * Country instance for fax number
102 private Country faxCountry;
107 private Long faxNumber;
112 private String firstName;
117 private Gender gender;
122 private Short houseNumber;
125 * Phone number area code
127 private Integer phoneAreaCode;
130 * Country instance for phone number
132 private Country phoneCountry;
137 private Long phoneNumber;
142 private String street;
147 private final UserSessionBeanRemote userBean;
155 * A list of all user profiles
157 private List<User> userList;
162 private String userName;
165 * User password (unencrypted from web form)
167 private String userPassword;
170 * User password repeated (unencrypted from web form)
172 private String userPasswordRepeat;
175 * Whether the user wants a public profile
177 private ProfileMode userProfileMode;
182 private Integer zipCode;
185 * Default constructor
187 public JobsAdminUserWebSessionBean () {
188 // Set gender to UNKNOWN
189 this.gender = Gender.UNKNOWN;
193 // Get initial context
194 Context context = new InitialContext();
197 this.userBean = (UserSessionBeanRemote) context.lookup("java:global/PizzaService-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N
198 } catch (final NamingException e) {
200 throw new FaceletException(e);
205 public List<User> allUsers () {
207 return Collections.unmodifiableList(this.userList);
211 public Date getBirthday () {
212 return this.birthday;
216 public void setBirthday (final Date birthday) {
217 this.birthday = birthday;
221 public SmsProvider getCellphoneCarrier () {
222 return this.cellphoneCarrier;
226 public void setCellphoneCarrier (final SmsProvider cellphoneCarrier) {
227 this.cellphoneCarrier = cellphoneCarrier;
231 public Long getCellphoneNumber () {
232 return this.cellphoneNumber;
236 public void setCellphoneNumber (Long cellphoneNumber) {
237 this.cellphoneNumber = cellphoneNumber;
241 public String getCity () {
246 public void setCity (final String city) {
251 public String getComment () {
256 public void setComment (final String comment) {
257 this.comment = comment;
261 public Country getCountry () {
266 public void setCountry (final Country country) {
267 this.country = country;
271 public String getEmailAddress () {
272 return this.emailAddress;
276 public void setEmailAddress (final String emailAddress) {
277 this.emailAddress = emailAddress;
281 public String getFamilyName () {
282 return this.familyName;
286 public void setFamilyName (final String familyName) {
287 this.familyName = familyName;
291 public Integer getFaxAreaCode () {
292 return this.faxAreaCode;
296 public void setFaxAreaCode (final Integer faxAreaCode) {
297 this.faxAreaCode = faxAreaCode;
301 public Country getFaxCountry () {
302 return this.faxCountry;
306 public void setFaxCountry (final Country faxCountry) {
307 this.faxCountry = faxCountry;
311 public Long getFaxNumber () {
312 return this.faxNumber;
316 public void setFaxNumber (final Long faxNumber) {
317 this.faxNumber = faxNumber;
321 public String getFirstName () {
322 return this.firstName;
326 public void setFirstName (final String firstName) {
327 this.firstName = firstName;
331 public Gender getGender () {
336 public void setGender (final Gender gender) {
337 this.gender = gender;
341 public Short getHouseNumber () {
342 return this.houseNumber;
346 public void setHouseNumber (final Short houseNumber) {
347 this.houseNumber = houseNumber;
351 public Integer getPhoneAreaCode () {
352 return this.phoneAreaCode;
356 public void setPhoneAreaCode (final Integer phoneAreaCode) {
357 this.phoneAreaCode = phoneAreaCode;
361 public Country getPhoneCountry () {
362 return this.phoneCountry;
366 public void setPhoneCountry (final Country phoneCountry) {
367 this.phoneCountry = phoneCountry;
371 public Long getPhoneNumber () {
372 return this.phoneNumber;
376 public void setPhoneNumber (final Long phoneNumber) {
377 this.phoneNumber = phoneNumber;
381 public String getStreet () {
386 public void setStreet (final String street) {
387 this.street = street;
391 public Long getUserId () {
396 public void setUserId (final Long userId) {
397 this.userId = userId;
401 public String getUserName () {
402 return this.userName;
406 public void setUserName (final String userName) {
407 this.userName = userName;
411 public String getUserPassword () {
412 return this.userPassword;
416 public void setUserPassword (final String userPassword) {
417 this.userPassword = userPassword;
421 public String getUserPasswordRepeat () {
422 return this.userPasswordRepeat;
426 public void setUserPasswordRepeat (final String userPasswordRepeat) {
427 this.userPasswordRepeat = userPasswordRepeat;
431 public ProfileMode getUserProfileMode () {
432 return this.userProfileMode;
436 public void setUserProfileMode (final ProfileMode userProfileMode) {
437 this.userProfileMode = userProfileMode;
441 public Integer getZipCode () {
446 public void setZipCode (final Integer zipCode) {
447 this.zipCode = zipCode;
451 public boolean hasUsers () {
452 return (!this.allUsers().isEmpty());
456 * Post-initialization of this class
459 public void init () {
460 // Initialize user list
461 this.userList = this.userBean.allUsers();
465 public User lookupUserById (final Long userId) throws UserNotFoundException {
469 // Try to lookup it in visible user list
470 for (final Iterator<User> iterator = this.userList.iterator(); iterator.hasNext();) {
472 User next = iterator.next();
474 // Is the user id found?
475 if (Objects.equals(next.getUserId(), userId)) {
476 // Copy to other variable
484 // Not visible for the current user
485 throw new UserNotFoundException(userId);