2 * Copyright (C) 2016 Roland Haeder GmbH
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.addressbook.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.addressbook.beans.contact.AddressbookAdminContactWebRequestController;
24 import org.mxchange.addressbook.beans.user.AddressbookAdminUserWebRequestController;
25 import org.mxchange.jcontacts.contact.Contact;
26 import org.mxchange.jusercore.model.user.User;
29 * A general helper for beans
31 * @author Roland Haeder<roland@mxchange.org>
33 @Named ("adminHelper")
35 public class AddressbookAdminWebRequestHelper implements AddressbookAdminWebRequestController {
40 private static final long serialVersionUID = 17_258_793_567_145_701L;
43 * Administrative contact controller
46 private AddressbookAdminContactWebRequestController adminContactController;
49 * Administrative user controller
52 private AddressbookAdminUserWebRequestController adminUserController;
57 private Contact contact;
67 public AddressbookAdminWebRequestHelper () {
71 public void copyContactToController () {
73 //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyContactToController - CALLED!"); //NOI18N
75 // Validate user instance
76 if (this.getContact() == null) {
78 throw new NullPointerException("this.contact is null"); //NOI18N
79 } else if (this.getContact().getContactId() == null) {
81 throw new NullPointerException("this.contact.contactId is null"); //NOI18N
82 } else if (this.getContact().getContactId() < 1) {
84 throw new IllegalStateException(MessageFormat.format("this.contact.contactId={0} is not valid.", this.getContact().getContactId())); //NOI18N
87 // Set all fields: user
88 this.adminContactController.copyContactToController(this.getContact());
91 //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyContactToController - EXIT!"); //NOI18N
95 public void copyUserToController () {
97 //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyUserToController - CALLED!"); //NOI18N
99 // Validate user instance
100 if (this.getUser() == null) {
102 throw new NullPointerException("this.user is null"); //NOI18N
103 } else if (this.getUser().getUserId() == null) {
105 throw new NullPointerException("this.user.userId is null"); //NOI18N
106 } else if (this.getUser().getUserId() < 1) {
108 throw new IllegalStateException(MessageFormat.format("this.user.userId={0} is not valid.", this.getUser().getUserId())); //NOI18N
111 // Set all fields: user
112 this.adminUserController.setUserName(this.getUser().getUserName());
115 //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyUserToController - EXIT!"); //NOI18N
119 public Contact getContact () {
124 public void setContact (final Contact contact) {
125 this.contact = contact;
129 public String getContactUsageMessageKey (final Contact contact) {
130 // The contact must be valid
131 if (null == contact) {
133 throw new NullPointerException("contact is null"); //NOI18N
134 } else if (contact.getContactId() == null) {
136 throw new NullPointerException("contact.contactId is null"); //NOI18N
137 } else if (contact.getContactId() < 1) {
139 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
142 // Default key is "unused"
143 String messageKey = "CONTACT_IS_UNUSED"; //NOI18N
145 // Check user/customer
146 boolean isUserContact = this.adminUserController.isContactFound(contact);
151 messageKey = "CONTACT_IS_USER"; //NOI18N
154 // Return message key
159 public User getUser () {
164 public void setUser (final User user) {