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.pizzaapplication.beans.helper;
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.jcustomercore.model.customer.Customer;
25 import org.mxchange.jusercore.model.user.User;
26 import org.mxchange.pizzaapplication.beans.contact.PizzaAdminContactWebRequestController;
27 import org.mxchange.pizzaapplication.beans.customer.PizzaAdminCustomerWebRequestController;
28 import org.mxchange.pizzaapplication.beans.customer.PizzaCustomerWebSessionController;
29 import org.mxchange.pizzaapplication.beans.user.PizzaAdminUserWebRequestController;
30 import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController;
33 * A general helper for administrative beans
35 * @author Roland Haeder<roland@mxchange.org>
37 @Named ("adminHelper")
39 public class PizzaAdminWebRequestHelper implements PizzaAdminWebRequestController {
44 private static final long serialVersionUID = 17_258_793_567_145_701L;
47 * Administrative contact controller
50 private PizzaAdminContactWebRequestController adminContactController;
53 * Administrative user controller
56 private PizzaAdminCustomerWebRequestController adminCustomerController;
59 * Administrative user controller
62 private PizzaAdminUserWebRequestController adminUserController;
67 private Contact contact;
72 private Customer customer;
75 * General user controller
78 private PizzaCustomerWebSessionController customerController;
86 * General user controller
89 private PizzaUserWebSessionController userController;
94 public PizzaAdminWebRequestHelper () {
98 public void copyContactToController () {
100 //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyContactToController - CALLED!"); //NOI18N
102 // Validate user instance
103 if (this.getContact() == null) {
105 throw new NullPointerException("this.contact is null"); //NOI18N
106 } else if (this.getContact().getContactId() == null) {
108 throw new NullPointerException("this.contact.contactId is null"); //NOI18N
109 } else if (this.getContact().getContactId() < 1) {
111 throw new IllegalStateException(MessageFormat.format("this.contact.contactId={0} is not valid.", this.getContact().getContactId())); //NOI18N
114 // Set all fields: user
115 this.adminContactController.copyContactToController(this.getContact());
118 //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyContactToController - EXIT!"); //NOI18N
122 public void copyCustomerToController () {
124 //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyCustomerToController - CALLED!"); //NOI18N
126 // Validate user instance
127 if (this.getCustomer() == null) {
129 throw new NullPointerException("this.customer is null"); //NOI18N
130 } else if (this.getCustomer().getCustomerId() == null) {
132 throw new NullPointerException("this.customer.customerId is null"); //NOI18N
133 } else if (this.getCustomer().getCustomerId() < 1) {
135 throw new IllegalStateException(MessageFormat.format("this.customer.customerId={0} is not valid.", this.getCustomer().getCustomerId())); //NOI18N
138 // Set all fields: user
139 this.adminCustomerController.copyCustomerToController(this.getCustomer());
142 //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyCustomerToController - EXIT!"); //NOI18N
146 public void copyUserToController () {
148 //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyUserToController - CALLED!"); //NOI18N
150 // Validate user instance
151 if (this.getUser() == null) {
153 throw new NullPointerException("this.user is null"); //NOI18N
154 } else if (this.getUser().getUserId() == null) {
156 throw new NullPointerException("this.user.userId is null"); //NOI18N
157 } else if (this.getUser().getUserId() < 1) {
159 throw new IllegalStateException(MessageFormat.format("this.user.userId={0} is not valid.", this.getUser().getUserId())); //NOI18N
162 // Set all fields: user
163 this.adminUserController.setUserName(this.getUser().getUserName());
166 //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyUserToController - EXIT!"); //NOI18N
170 public Contact getContact () {
175 public void setContact (final Contact contact) {
176 this.contact = contact;
180 public Customer getCustomer () {
181 return this.customer;
185 public void setCustomer (final Customer customer) {
186 this.customer = customer;
190 public User getUser () {
195 public void setUser (final User user) {
200 public String getUserCustomerUsageMessageKey (final Contact contact) {
201 // The contact must be valid
202 if (null == contact) {
204 throw new NullPointerException("contact is null"); //NOI18N
205 } else if (contact.getContactId() == null) {
207 throw new NullPointerException("contact.contactId is null"); //NOI18N
208 } else if (contact.getContactId() < 1) {
210 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
213 // Default key is "unused"
214 String messageKey = "CONTACT_IS_UNUSED"; //NOI18N
216 // Check user/customer
217 boolean isUserContact = this.userController.isContactFound(contact);
218 boolean isCustomerContact = this.customerController.isContactFound(contact);
221 if (isUserContact && isCustomerContact) {
223 messageKey = "CONTACT_IS_USER_CUSTOMER"; //NOI18N
224 } else if (isUserContact) {
226 messageKey = "CONTACT_IS_USER"; //NOI18N
227 } else if (isCustomerContact) {
229 messageKey = "CONTACT_IS_CUSTOMER"; //NOI18N
232 // Return message key