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.jjobs.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.jcontacts.contact.Contact;
29 import org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote;
30 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
31 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
32 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
35 * Administrative bean (controller) for contact's phone numbers
37 * @author Roland Haeder<roland@mxchange.org>
39 @Named ("adminContactPhoneController")
41 public class JobsAdminContactPhoneWebSessionBean implements JobsAdminContactPhoneWebSessionController {
46 private static final long serialVersionUID = 184_598_175_371_269_016L;
49 * Remote EJB for phone number (administrative)
51 private AdminContactsPhoneSessionBeanRemote adminRemoteBean;
56 private DialableCellphoneNumber cellPhone;
59 * Instance of linked contact account
61 private Contact contact;
64 * "Cache" for contact lists, mostly only one is assigned. So this cache
65 * shouldn't grow beyond control.
67 private final Map<Long, List<Contact>> contacts;
72 private DialableFaxNumber fax;
77 private DialableLandLineNumber landLine;
82 public JobsAdminContactPhoneWebSessionBean () {
85 // Get initial context
86 Context context = new InitialContext();
88 // Try to lookup the beans
89 this.adminRemoteBean = (AdminContactsPhoneSessionBeanRemote) context.lookup("java:global/PizzaService-ejb/admincontactphone!org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote"); //NOI18N
90 } catch (final NamingException e) {
92 throw new FaceletException(e);
96 this.contacts = new HashMap<>(10);
100 public List<Contact> allCellphoneContacts () {
102 Long phoneId = this.getCellPhone().getPhoneId();
105 if (this.contacts.containsKey(phoneId)) {
106 // Return cached version
107 return this.contacts.get(phoneId);
110 List<Contact> list = this.adminRemoteBean.allContacts(this.getCellPhone());
112 // Store result in cache
113 this.contacts.put(phoneId, list);
115 // Return now-cached list
121 public DialableCellphoneNumber getCellPhone () {
122 return this.cellPhone;
126 public void setCellPhone (final DialableCellphoneNumber cellPhone) {
127 this.cellPhone = cellPhone;
131 public Contact getContact () {
136 public void setContact (final Contact contact) {
137 this.contact = contact;
141 public DialableFaxNumber getFax () {
146 public void setFax (final DialableFaxNumber fax) {
151 public DialableLandLineNumber getLandLine () {
152 return this.landLine;
156 public void setLandLine (final DialableLandLineNumber landLine) {
157 this.landLine = landLine;