]> git.mxchange.org Git - juser-activity-core.git/blob - src/org/mxchange/jusercore/container/login/UserLoginContainer.java
Continued a bit:
[juser-activity-core.git] / src / org / mxchange / jusercore / container / login / UserLoginContainer.java
1 /*
2  * Copyright (C) 2016 Roland Haeder
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 package org.mxchange.jusercore.container.login;
18
19 import java.text.MessageFormat;
20 import org.mxchange.jusercore.model.user.User;
21
22 /**
23  * A user login container
24  * <p>
25  * @author Roland Haeder<roland@mxchange.org>
26  */
27 public class UserLoginContainer implements LoginContainer {
28
29         /**
30          * Serial number
31          */
32         private static final long serialVersionUID = 158_768_718_689_760_186L;
33
34         /**
35          * User instance
36          */
37         private User user;
38
39         /**
40          * Unencrypted password
41          */
42         private String userPassword;
43
44         /**
45          * Constructor with user instance and unencrypted password
46          * <p>
47          * @param user         User instance
48          * @param userPassword Unencrypted password
49          */
50         public UserLoginContainer (final User user, final String userPassword) {
51                 // Is both set?
52                 if (null == user) {
53                         // Throw NPE
54                         throw new NullPointerException("user is null"); //NOI18N
55                 } else if (user.getUserId() == null) {
56                         // Throw NPE again ..
57                         throw new NullPointerException("user.userId is null"); //NOI18N
58                 } else if (user.getUserId() < 1) {
59                         // Invalid id number
60                         throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N
61                 } else if (user.getUserContact() == null) {
62                         // Throw NPE again ...
63                         throw new NullPointerException("user.userContact is null"); //NOI18N
64                 } else if (user.getUserContact().getContactId() == null) {
65                         // Throw NPE again ...
66                         throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
67                 } else if (user.getUserContact().getContactId() < 1) {
68                         // Invalid id number
69                         throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is not valid", user.getUserContact().getContactId())); //NOI18N
70                 } else if (null == userPassword) {
71                         // Throw NPE again
72                         throw new NullPointerException("userPassword is null"); //NOI18N
73                 } else if (userPassword.isEmpty()) {
74                         // Empty password
75                         throw new IllegalArgumentException("user password is empty."); //NOI18N
76                 }
77
78                 // Set both
79                 this.user = user;
80                 this.userPassword = userPassword;
81         }
82
83         @Override
84         public User getUser () {
85                 return this.user;
86         }
87
88         @Override
89         public void setUser (final User user) {
90                 this.user = user;
91         }
92
93         @Override
94         public String getUserPassword () {
95                 return this.userPassword;
96         }
97
98         @Override
99         public void setUserPassword (final String userPassword) {
100                 this.userPassword = userPassword;
101         }
102
103 }