]> git.mxchange.org Git - addressbook-ejb.git/blob - src/java/org/mxchange/jusercore/model/email_address/EmailChangeSessionBean.java
it must be @EJB to inject another EJB into an EJB
[addressbook-ejb.git] / src / java / org / mxchange / jusercore / model / email_address / EmailChangeSessionBean.java
1 /*
2  * Copyright (C) 2016 quix0r
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.model.email_address;
18
19 import java.text.MessageFormat;
20 import javax.ejb.EJB;
21 import javax.ejb.Stateless;
22 import javax.persistence.PersistenceException;
23 import org.mxchange.jcoreee.database.BaseDatabaseBean;
24 import org.mxchange.jusercore.model.user.User;
25 import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
26
27 /**
28  * A session bean for changing email addresses
29  * <p>
30  * @author Roland Haeder<roland@mxchange.org>
31  */
32 @Stateless (name = "email-change", mappedName = "ejb/stateless-addressbook-email-change", description = "A bean handling email changes")
33 public class EmailChangeSessionBean extends BaseDatabaseBean implements EmailChangeSessionBeanRemote {
34
35         /**
36          * Serial number
37          */
38         private static final long serialVersionUID = 182_698_165_971_548L;
39
40         /**
41          * User bean
42          */
43         @EJB
44         private UserSessionBeanRemote userBean;
45
46         /**
47          * Default constructor
48          */
49         public EmailChangeSessionBean () {
50         }
51
52         @Override
53         public void enqueueEmailAddressForChange (final User user) {
54                 // Trace message
55                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("enqueueEmailAddressForChange: user={0} - CALLED!", user));
56
57                 // user should not be null
58                 if (null == user) {
59                         // Abort here
60                         throw new NullPointerException("user is null"); //NOI18N
61                 } else if (user.getUserId() == null) {
62                         // Throw NPE again
63                         throw new NullPointerException("user.userId is null"); //NOI18N
64                 } else if (user.getUserId() < 1) {
65                         // Not valid
66                         throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); //NOI18N
67                 } else if (user.getUserAccountStatus() == null) {
68                         // Throw NPE again
69                         throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
70                 } else if (!this.userBean.ifUserIdExists(user.getUserId())) {
71                         // User does not exist
72                         throw new PersistenceException(MessageFormat.format("User with id {0} does not exist.", user.getUserId())); //NOI18N
73                 }
74
75                 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
76         }
77
78         @Override
79         public void updateEmailAddress (final User user) {
80                 // Trace message
81                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("updateEmailAddress: user={0} - CALLED!", user));
82
83                 // user should not be null
84                 if (null == user) {
85                         // Abort here
86                         throw new NullPointerException("user is null"); //NOI18N
87                 } else if (user.getUserId() == null) {
88                         // Throw NPE again
89                         throw new NullPointerException("user.userId is null"); //NOI18N
90                 } else if (user.getUserId() < 1) {
91                         // Not valid
92                         throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); //NOI18N
93                 } else if (user.getUserAccountStatus() == null) {
94                         // Throw NPE again
95                         throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
96                 } else if (!this.userBean.ifUserIdExists(user.getUserId())) {
97                         // User does not exist
98                         throw new PersistenceException(MessageFormat.format("User with id {0} does not exist.", user.getUserId())); //NOI18N
99                 }
100
101                 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
102         }
103
104 }