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.jjobs.beans.BaseJobsController;
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 phone numbers
38 * @author Roland Haeder<roland@mxchange.org>
40 @Named ("adminPhoneController")
42 public class JobsAdminContactPhoneWebSessionBean extends BaseJobsController implements JobsAdminContactPhoneWebSessionController {
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 * @deprecated This is a generic phone controller, not just for contact data
65 private Contact contact;
68 * "Cache" for contact lists, mostly only one is assigned. So this cache
69 * shouldn't grow beyond control.
71 * @deprecated This is a generic phone controller, not just for contact data
74 private final Map<Long, List<Contact>> contacts;
79 private DialableFaxNumber fax;
84 private DialableLandLineNumber landLine;
89 public JobsAdminContactPhoneWebSessionBean () {
92 // Get initial context
93 Context context = new InitialContext();
95 // Try to lookup the beans
96 this.adminRemoteBean = (AdminContactsPhoneSessionBeanRemote) context.lookup("java:global/jjobs-ejb/admincontactphone!org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote"); //NOI18N
97 } catch (final NamingException e) {
99 throw new FaceletException(e);
103 this.contacts = new HashMap<>(10);
108 public List<Contact> allCellphoneContacts () {
110 Long phoneId = this.getCellPhone().getPhoneId();
113 if (this.contacts.containsKey(phoneId)) {
114 // Return cached version
115 return this.contacts.get(phoneId);
118 List<Contact> list = this.adminRemoteBean.allContacts(this.getCellPhone());
120 // Store result in cache
121 this.contacts.put(phoneId, list);
123 // Return now-cached list
129 public DialableCellphoneNumber getCellPhone () {
130 return this.cellPhone;
134 public void setCellPhone (final DialableCellphoneNumber cellPhone) {
135 this.cellPhone = cellPhone;
140 public Contact getContact () {
146 public void setContact (final Contact contact) {
147 this.contact = contact;
151 public DialableFaxNumber getFax () {
156 public void setFax (final DialableFaxNumber fax) {
161 public DialableLandLineNumber getLandLine () {
162 return this.landLine;
166 public void setLandLine (final DialableLandLineNumber landLine) {
167 this.landLine = landLine;