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.addressbook.beans.phone;
19 import java.util.HashMap;
20 import java.util.List;
22 import javax.enterprise.context.RequestScoped;
23 import javax.faces.view.facelets.FaceletException;
24 import javax.inject.Named;
25 import javax.naming.Context;
26 import javax.naming.InitialContext;
27 import javax.naming.NamingException;
28 import org.mxchange.addressbook.beans.BaseAddressbookController;
29 import org.mxchange.jcontacts.contact.Contact;
30 import org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote;
31 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
32 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
33 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
36 * Administrative bean (controller) for contact's phone numbers
38 * @author Roland Haeder<roland@mxchange.org>
40 @Named ("adminContactPhoneController")
42 public class AddressbookAdminContactPhoneWebRequestBean extends BaseAddressbookController implements AddressbookAdminContactPhoneWebRequestController {
47 private static final long serialVersionUID = 184_598_175_371_269_016L;
50 * Remote EJB for phone number (administrative)
52 private AdminContactsPhoneSessionBeanRemote adminRemoteBean;
57 private DialableCellphoneNumber cellPhone;
60 * Instance of linked contact account
62 private Contact contact;
65 * "Cache" for contact lists, mostly only one is assigned. So this cache
66 * shouldn't grow beyond control.
68 private final Map<Long, List<Contact>> contacts;
73 private DialableFaxNumber fax;
78 private DialableLandLineNumber landLine;
83 public AddressbookAdminContactPhoneWebRequestBean () {
86 // Get initial context
87 Context context = new InitialContext();
89 // Try to lookup the beans
90 this.adminRemoteBean = (AdminContactsPhoneSessionBeanRemote) context.lookup("java:global/PizzaService-ejb/admincontactphone!org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote"); //NOI18N
91 } catch (final NamingException e) {
93 throw new FaceletException(e);
97 this.contacts = new HashMap<>(10);
101 public List<Contact> allCellphoneContacts () {
103 Long phoneId = this.getCellPhone().getPhoneId();
106 if (this.contacts.containsKey(phoneId)) {
107 // Return cached version
108 return this.contacts.get(phoneId);
111 List<Contact> list = this.adminRemoteBean.allContacts(this.getCellPhone());
113 // Store result in cache
114 this.contacts.put(phoneId, list);
116 // Return now-cached list
122 public DialableCellphoneNumber getCellPhone () {
123 return this.cellPhone;
127 public void setCellPhone (final DialableCellphoneNumber cellPhone) {
128 this.cellPhone = cellPhone;
132 public Contact getContact () {
137 public void setContact (final Contact contact) {
138 this.contact = contact;
142 public DialableFaxNumber getFax () {
147 public void setFax (final DialableFaxNumber fax) {
152 public DialableLandLineNumber getLandLine () {
153 return this.landLine;
157 public void setLandLine (final DialableLandLineNumber landLine) {
158 this.landLine = landLine;