]> git.mxchange.org Git - pizzaservice-war.git/blob - src/java/org/mxchange/pizzaapplication/beans/helper/PizzaAdminWebRequestHelper.java
b30ee67df83510029fab80e989e47bdcf947d4e6
[pizzaservice-war.git] / src / java / org / mxchange / pizzaapplication / beans / helper / PizzaAdminWebRequestHelper.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 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.
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 Affero General Public License for more details.
13  *
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/>.
16  */
17 package org.mxchange.pizzaapplication.beans.helper;
18
19 import java.text.MessageFormat;
20 import javax.enterprise.context.RequestScoped;
21 import javax.inject.Inject;
22 import javax.inject.Named;
23 import org.mxchange.jcontacts.contact.Contact;
24 import org.mxchange.jratecalc.beans.contact.PizzaAdminContactWebRequestController;
25 import org.mxchange.jusercore.model.user.User;
26 import org.mxchange.pizzaapplication.beans.user.PizzaAdminUserWebSessionController;
27
28 /**
29  * A general helper for beans
30  * <p>
31  * @author Roland Haeder<roland@mxchange.org>
32  */
33 @Named ("adminHelper")
34 @RequestScoped
35 public class PizzaAdminWebRequestHelper implements PizzaAdminWebRequestController {
36
37         /**
38          * Serial number
39          */
40         private static final long serialVersionUID = 17_258_793_567_145_701L;
41
42         /**
43          * Admin contact controller
44          */
45         @Inject
46         private PizzaAdminContactWebRequestController adminContactController;
47
48         /**
49          * Admin user controller
50          */
51         @Inject
52         private PizzaAdminUserWebSessionController adminUserController;
53
54         /**
55          * User instance
56          */
57         private User user;
58
59         /**
60          * Default constructor
61          */
62         public PizzaAdminWebRequestHelper () {
63         }
64
65         @Override
66         public void copyUserToController () {
67                 // Validate user instance
68                 if (this.getUser() == null) {
69                         // Throw NPE
70                         throw new NullPointerException("this.user is null");
71                 } else if (this.getUser().getUserId() == null) {
72                         // Throw NPE again
73                         throw new NullPointerException("this.user.userId is null");
74                 } else if (this.getUser().getUserId() < 1) {
75                         // Not valid
76                         throw new IllegalStateException(MessageFormat.format("this.user.userId={0} is not valid.", this.getUser().getUserId()));
77                 }
78
79                 // Set all fields: user
80                 this.adminUserController.setUserName(this.getUser().getUserName());
81
82                 // Get contact instance (shortens stuff)
83                 Contact contact = this.getUser().getUserContact();
84
85                 // Call contact controller
86                 this.adminContactController.copyContactToController(contact);
87         }
88
89         @Override
90         public User getUser () {
91                 return this.user;
92         }
93
94         @Override
95         public void setUser (final User user) {
96                 this.user = user;
97         }
98
99 }