]> git.mxchange.org Git - jjobs-war.git/blob - src/java/org/mxchange/jjobs/beans/phone/JobsAdminContactPhoneWebSessionBean.java
updated copyright + author
[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 phone numbers
37  * <p>
38  * @author Roland Haeder<roland@mxchange.org>
39  */
40 @Named ("adminPhoneController")
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          * <p>
62          * @deprecated This is a generic phone controller, not just for contact data
63          */
64         @Deprecated
65         private Contact contact;
66
67         /**
68          * "Cache" for contact lists, mostly only one is assigned. So this cache
69          * shouldn't grow beyond control.
70          * <p>
71          * @deprecated This is a generic phone controller, not just for contact data
72          */
73         @Deprecated
74         private final Map<Long, List<Contact>> contacts;
75
76         /**
77          * Fax number
78          */
79         private DialableFaxNumber fax;
80
81         /**
82          * Land-line number
83          */
84         private DialableLandLineNumber landLine;
85
86         /**
87          * Default constructor
88          */
89         public JobsAdminContactPhoneWebSessionBean () {
90                 // Try it
91                 try {
92                         // Get initial context
93                         Context context = new InitialContext();
94
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) {
98                         // Throw it again
99                         throw new FaceletException(e);
100                 }
101
102                 // Init map
103                 this.contacts = new HashMap<>(10);
104         }
105
106         @Override
107         @Deprecated
108         public List<Contact> allCellphoneContacts () {
109                 // Get id
110                 Long phoneId = this.getCellPhone().getPhoneId();
111
112                 // Is cache there?
113                 if (this.contacts.containsKey(phoneId)) {
114                         // Return cached version
115                         return this.contacts.get(phoneId);
116                 } else {
117                         // Ask bean
118                         List<Contact> list = this.adminRemoteBean.allContacts(this.getCellPhone());
119
120                         // Store result in cache
121                         this.contacts.put(phoneId, list);
122
123                         // Return now-cached list
124                         return list;
125                 }
126         }
127
128         @Override
129         public DialableCellphoneNumber getCellPhone () {
130                 return this.cellPhone;
131         }
132
133         @Override
134         public void setCellPhone (final DialableCellphoneNumber cellPhone) {
135                 this.cellPhone = cellPhone;
136         }
137
138         @Override
139         @Deprecated
140         public Contact getContact () {
141                 return this.contact;
142         }
143
144         @Override
145         @Deprecated
146         public void setContact (final Contact contact) {
147                 this.contact = contact;
148         }
149
150         @Override
151         public DialableFaxNumber getFax () {
152                 return this.fax;
153         }
154
155         @Override
156         public void setFax (final DialableFaxNumber fax) {
157                 this.fax = fax;
158         }
159
160         @Override
161         public DialableLandLineNumber getLandLine () {
162                 return this.landLine;
163         }
164
165         @Override
166         public void setLandLine (final DialableLandLineNumber landLine) {
167                 this.landLine = landLine;
168         }
169
170 }