]> git.mxchange.org Git - jjobs-war.git/blob - src/java/org/mxchange/jjobs/beans/phone/JobsAdminContactPhoneWebSessionBean.java
Rewritten a lot:
[jjobs-war.git] / src / java / org / mxchange / jjobs / beans / phone / JobsAdminContactPhoneWebSessionBean.java
1 /*
2  * Copyright (C) 2016 Roland Haeder
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 package org.mxchange.jjobs.beans.phone;
18
19 import java.util.HashMap;
20 import java.util.List;
21 import java.util.Map;
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;
34
35 /**
36  * Administrative bean (controller) for contact's phone numbers
37  * <p>
38  * @author Roland Haeder<roland@mxchange.org>
39  */
40 @Named ("adminContactPhoneController")
41 @RequestScoped
42 public class JobsAdminContactPhoneWebSessionBean extends BaseJobsController implements JobsAdminContactPhoneWebSessionController {
43
44         /**
45          * Serial number
46          */
47         private static final long serialVersionUID = 184_598_175_371_269_016L;
48
49         /**
50          * Remote EJB for phone number (administrative)
51          */
52         private AdminContactsPhoneSessionBeanRemote adminRemoteBean;
53
54         /**
55          * Cell phone number
56          */
57         private DialableCellphoneNumber cellPhone;
58
59         /**
60          * Instance of linked contact account
61          */
62         private Contact contact;
63
64         /**
65          * "Cache" for contact lists, mostly only one is assigned. So this cache
66          * shouldn't grow beyond control.
67          */
68         private final Map<Long, List<Contact>> contacts;
69
70         /**
71          * Fax number
72          */
73         private DialableFaxNumber fax;
74
75         /**
76          * Land-line number
77          */
78         private DialableLandLineNumber landLine;
79
80         /**
81          * Default constructor
82          */
83         public JobsAdminContactPhoneWebSessionBean () {
84                 // Try it
85                 try {
86                         // Get initial context
87                         Context context = new InitialContext();
88
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) {
92                         // Throw it again
93                         throw new FaceletException(e);
94                 }
95
96                 // Init map
97                 this.contacts = new HashMap<>(10);
98         }
99
100         @Override
101         public List<Contact> allCellphoneContacts () {
102                 // Get id
103                 Long phoneId = this.getCellPhone().getPhoneId();
104
105                 // Is cache there?
106                 if (this.contacts.containsKey(phoneId)) {
107                         // Return cached version
108                         return this.contacts.get(phoneId);
109                 } else {
110                         // Ask bean
111                         List<Contact> list = this.adminRemoteBean.allContacts(this.getCellPhone());
112
113                         // Store result in cache
114                         this.contacts.put(phoneId, list);
115
116                         // Return now-cached list
117                         return list;
118                 }
119         }
120
121         @Override
122         public DialableCellphoneNumber getCellPhone () {
123                 return this.cellPhone;
124         }
125
126         @Override
127         public void setCellPhone (final DialableCellphoneNumber cellPhone) {
128                 this.cellPhone = cellPhone;
129         }
130
131         @Override
132         public Contact getContact () {
133                 return this.contact;
134         }
135
136         @Override
137         public void setContact (final Contact contact) {
138                 this.contact = contact;
139         }
140
141         @Override
142         public DialableFaxNumber getFax () {
143                 return this.fax;
144         }
145
146         @Override
147         public void setFax (final DialableFaxNumber fax) {
148                 this.fax = fax;
149         }
150
151         @Override
152         public DialableLandLineNumber getLandLine () {
153                 return this.landLine;
154         }
155
156         @Override
157         public void setLandLine (final DialableLandLineNumber landLine) {
158                 this.landLine = landLine;
159         }
160
161 }