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.jphone.phonenumbers.phone;
19 import java.text.MessageFormat;
20 import java.util.GregorianCalendar;
21 import javax.ejb.Stateless;
22 import org.mxchange.jjobs.database.BaseJobsDatabaseBean;
23 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
24 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
25 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
28 * An EJB for administrative phone purposes
30 * @author Roland Haeder<roland@mxchange.org>
32 @Stateless (name = "adminPhone", description = "An administrative bean handling phone data")
33 public class JobsAdminPhoneSessionBean extends BaseJobsDatabaseBean implements AdminPhoneSessionBeanRemote {
38 private static final long serialVersionUID = 18_597_165_817_401_853L;
41 public void deleteFaxData (final DialableFaxNumber faxNumber) {
43 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteFaxData: faxNumber={1} - CALLED!", this.getClass().getSimpleName(), faxNumber));
46 if (faxNumber == null) {
48 throw new NullPointerException("faxNumber is null"); //NOI18N
49 } else if (faxNumber.getPhoneId() == null) {
51 throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N
52 } else if (faxNumber.getPhoneId() < 1) {
54 throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid", faxNumber.getPhoneId())); //NOI18N
55 } else if (faxNumber.getPhoneCountry() == null) {
57 throw new NullPointerException("faxNumber.phoneCountry is null"); //NOI18N
58 } else if (faxNumber.getPhoneCountry().getCountryId() == null) {
60 throw new NullPointerException("faxNumber.phoneCountry.countryId is null"); //NOI18N
61 } else if (faxNumber.getPhoneCountry().getCountryId() < 1) {
63 throw new NullPointerException(MessageFormat.format("faxNumber.phoneCountry.countryId={0} is not valid", faxNumber.getPhoneCountry().getCountryId())); //NOI18N
64 } else if (faxNumber.getPhoneAreaCode() == null) {
66 throw new NullPointerException("faxNumber.phoneAreaCode is null"); //NOI18N
67 } else if (faxNumber.getPhoneAreaCode() < 1) {
69 throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneAreaCode={0} is not valid.", faxNumber.getPhoneAreaCode())); //NOI18N
70 } else if (faxNumber.getPhoneNumber() == null) {
72 throw new NullPointerException("faxNumber.phoneNumber is null"); //NOI18N
73 } else if (faxNumber.getPhoneNumber() < 1) {
75 throw new NullPointerException(MessageFormat.format("faxNumber.phoneNumber={0} is not valid.", faxNumber.getPhoneNumber())); //NOI18N
78 // Get a managed instance
79 DialableFaxNumber managedNumber = this.getEntityManager().getReference(faxNumber.getClass(), faxNumber.getPhoneId());
81 // Remove it from database
82 this.getEntityManager().remove(managedNumber);
85 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteMobileData: EXIT!", this.getClass().getSimpleName()));
89 public void deleteLandLineData (final DialableLandLineNumber landLineNumber) {
91 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteLandLineData: landLineNumber={1} - CALLED!", this.getClass().getSimpleName(), landLineNumber));
94 if (landLineNumber == null) {
96 throw new NullPointerException("landLineNumber is null"); //NOI18N
97 } else if (landLineNumber.getPhoneId() == null) {
99 throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
100 } else if (landLineNumber.getPhoneId() < 1) {
102 throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", landLineNumber.getPhoneId())); //NOI18N
103 } else if (landLineNumber.getPhoneCountry() == null) {
105 throw new NullPointerException("landLineNumber.phoneCountry is null"); //NOI18N
106 } else if (landLineNumber.getPhoneCountry().getCountryId() == null) {
108 throw new NullPointerException("landLineNumber.phoneCountry.countryId is null"); //NOI18N
109 } else if (landLineNumber.getPhoneCountry().getCountryId() < 1) {
111 throw new NullPointerException(MessageFormat.format("landLineNumber.phoneCountry.countryId={0} is not valid", landLineNumber.getPhoneCountry().getCountryId())); //NOI18N
112 } else if (landLineNumber.getPhoneAreaCode() == null) {
114 throw new NullPointerException("landLineNumber.phoneAreaCode is null"); //NOI18N
115 } else if (landLineNumber.getPhoneAreaCode() < 1) {
117 throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneAreaCode={0} is not valid.", landLineNumber.getPhoneAreaCode())); //NOI18N
118 } else if (landLineNumber.getPhoneNumber() == null) {
120 throw new NullPointerException("landLineNumber.phoneNumber is null"); //NOI18N
121 } else if (landLineNumber.getPhoneNumber() < 1) {
123 throw new NullPointerException(MessageFormat.format("landLineNumber.phoneNumber={0} is not valid.", landLineNumber.getPhoneNumber())); //NOI18N
126 // Get a managed instance
127 DialableLandLineNumber managedNumber = this.getEntityManager().getReference(landLineNumber.getClass(), landLineNumber.getPhoneId());
129 // Remove it from database
130 this.getEntityManager().remove(managedNumber);
133 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteMobileData: EXIT!", this.getClass().getSimpleName()));
137 public void deleteMobileData (final DialableMobileNumber mobileNumber) {
139 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteMobileData: mobileNumber={1} - CALLED!", this.getClass().getSimpleName(), mobileNumber));
142 if (null == mobileNumber) {
143 // Not set, throw NPE
144 throw new NullPointerException("mobileNumber is null"); //NOI18N
145 } else if (mobileNumber.getPhoneId() == null) {
147 throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N
148 } else if (mobileNumber.getPhoneId() < 1) {
150 throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", mobileNumber.getPhoneId())); //NOI18N
151 } else if (mobileNumber.getMobileProvider() == null) {
153 throw new NullPointerException("mobileNumber.cellphoneProvider is null"); //NOI18N
154 } else if (mobileNumber.getMobileProvider().getProviderId() == null) {
156 throw new NullPointerException("mobileNumber.cellphoneProvider.providerId is null"); //NOI18N
157 } else if (mobileNumber.getMobileProvider().getProviderId() < 1) {
159 throw new IllegalArgumentException(MessageFormat.format("mobileNumber.cellphoneProvider.providerId={0} is not valid.", mobileNumber.getMobileProvider().getProviderId())); //NOI18N
160 } else if (mobileNumber.getPhoneNumber() == null) {
162 throw new NullPointerException("mobileNumber.phoneNumber is null"); //NOI18N
163 } else if (mobileNumber.getPhoneNumber() < 1) {
165 throw new NullPointerException(MessageFormat.format("mobileNumber.phoneNumber={0} is not valid.", mobileNumber.getPhoneNumber())); //NOI18N
168 // Get a managed instance
169 DialableMobileNumber managedNumber = this.getEntityManager().getReference(mobileNumber.getClass(), mobileNumber.getPhoneId());
171 // Remove it from database
172 this.getEntityManager().remove(managedNumber);
175 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteMobileData: EXIT!", this.getClass().getSimpleName()));
179 public DialableFaxNumber updateFaxData (final DialableFaxNumber faxNumber) {
181 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateFaxData: faxNumber={1} - CALLED!", this.getClass().getSimpleName(), faxNumber));
184 if (faxNumber == null) {
185 // Not set, throw NPE
186 throw new NullPointerException("faxNumber is null"); //NOI18N
187 } else if (faxNumber.getPhoneId() == null) {
189 throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N
190 } else if (faxNumber.getPhoneId() < 1) {
192 throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid", faxNumber.getPhoneId())); //NOI18N
193 } else if (faxNumber.getPhoneCountry() == null) {
195 throw new NullPointerException("faxNumber.phoneCountry is null"); //NOI18N
196 } else if (faxNumber.getPhoneCountry().getCountryId() == null) {
198 throw new NullPointerException("faxNumber.phoneCountry.countryId is null"); //NOI18N
199 } else if (faxNumber.getPhoneCountry().getCountryId() < 1) {
201 throw new NullPointerException(MessageFormat.format("faxNumber.phoneCountry.countryId={0} is not valid", faxNumber.getPhoneCountry().getCountryId())); //NOI18N
202 } else if (faxNumber.getPhoneAreaCode() == null) {
204 throw new NullPointerException("faxNumber.phoneAreaCode is null"); //NOI18N
205 } else if (faxNumber.getPhoneAreaCode() < 1) {
207 throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneAreaCode={0} is not valid.", faxNumber.getPhoneAreaCode())); //NOI18N
208 } else if (faxNumber.getPhoneNumber() == null) {
210 throw new NullPointerException("faxNumber.phoneNumber is null"); //NOI18N
211 } else if (faxNumber.getPhoneNumber() < 1) {
213 throw new NullPointerException(MessageFormat.format("faxNumber.phoneNumber={0} is not valid.", faxNumber.getPhoneNumber())); //NOI18N
216 // Get contact from it and find it
217 DialableFaxNumber managedNumber = this.getEntityManager().find(faxNumber.getClass(), faxNumber.getPhoneId());
220 assert (managedNumber instanceof DialableFaxNumber) : MessageFormat.format("Cell phone number with id {0} not found, but should be.", faxNumber.getPhoneId()); //NOI18N
223 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateFaxData: managedNumber.phoneId={1}", this.getClass().getSimpleName(), managedNumber.getPhoneId())); //NOI18N
225 // Set updated timestamp
226 managedNumber.setPhoneEntryUpdated(new GregorianCalendar());
229 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateFaxData: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
232 return managedNumber;
236 public DialableLandLineNumber updateLandLineData (final DialableLandLineNumber landLineNumber) {
238 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateLandLineData: landLineNumber={1} - CALLED!", this.getClass().getSimpleName(), landLineNumber));
241 if (landLineNumber == null) {
242 // Not set, throw NPE
243 throw new NullPointerException("landLineNumber is null"); //NOI18N
244 } else if (landLineNumber.getPhoneId() == null) {
246 throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
247 } else if (landLineNumber.getPhoneId() < 1) {
249 throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", landLineNumber.getPhoneId())); //NOI18N
250 } else if (landLineNumber.getPhoneCountry() == null) {
252 throw new NullPointerException("landLineNumber.phoneCountry is null"); //NOI18N
253 } else if (landLineNumber.getPhoneCountry().getCountryId() == null) {
255 throw new NullPointerException("landLineNumber.phoneCountry.countryId is null"); //NOI18N
256 } else if (landLineNumber.getPhoneCountry().getCountryId() < 1) {
258 throw new NullPointerException(MessageFormat.format("landLineNumber.phoneCountry.countryId={0} is not valid", landLineNumber.getPhoneCountry().getCountryId())); //NOI18N
259 } else if (landLineNumber.getPhoneAreaCode() == null) {
261 throw new NullPointerException("landLineNumber.phoneAreaCode is null"); //NOI18N
262 } else if (landLineNumber.getPhoneAreaCode() < 1) {
264 throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneAreaCode={0} is not valid.", landLineNumber.getPhoneAreaCode())); //NOI18N
265 } else if (landLineNumber.getPhoneNumber() == null) {
267 throw new NullPointerException("landLineNumber.phoneNumber is null"); //NOI18N
268 } else if (landLineNumber.getPhoneNumber() < 1) {
270 throw new NullPointerException(MessageFormat.format("landLineNumber.phoneNumber={0} is not valid.", landLineNumber.getPhoneNumber())); //NOI18N
273 // Get contact from it and find it
274 DialableLandLineNumber managedNumber = this.getEntityManager().find(landLineNumber.getClass(), landLineNumber.getPhoneId());
277 assert (managedNumber instanceof DialableLandLineNumber) : MessageFormat.format("Cell phone number with id {0} not found, but should be.", landLineNumber.getPhoneId()); //NOI18N
280 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateLandLineData: managedNumber.phoneId={1}", this.getClass().getSimpleName(), managedNumber.getPhoneId())); //NOI18N
282 // Set updated timestamp
283 landLineNumber.setPhoneEntryUpdated(new GregorianCalendar());
286 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateLandLineData: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
289 return managedNumber;
293 public DialableMobileNumber updateMobileData (final DialableMobileNumber mobileNumber) {
295 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateMobileData: mobileNumber={1} - CALLED!", this.getClass().getSimpleName(), mobileNumber));
298 if (null == mobileNumber) {
299 // Not set, throw NPE
300 throw new NullPointerException("mobileNumber is null"); //NOI18N
301 } else if (mobileNumber.getPhoneId() == null) {
303 throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N
304 } else if (mobileNumber.getPhoneId() < 1) {
306 throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", mobileNumber.getPhoneId())); //NOI18N
307 } else if (mobileNumber.getMobileProvider() == null) {
309 throw new NullPointerException("mobileNumber.cellphoneProvider is null"); //NOI18N
310 } else if (mobileNumber.getMobileProvider().getProviderId() == null) {
312 throw new NullPointerException("mobileNumber.cellphoneProvider.providerId is null"); //NOI18N
313 } else if (mobileNumber.getMobileProvider().getProviderId() < 1) {
315 throw new IllegalArgumentException(MessageFormat.format("mobileNumber.cellphoneProvider.providerId={0} is not valid.", mobileNumber.getMobileProvider().getProviderId())); //NOI18N
316 } else if (mobileNumber.getPhoneNumber() == null) {
318 throw new NullPointerException("mobileNumber.phoneNumber is null"); //NOI18N
319 } else if (mobileNumber.getPhoneNumber() < 1) {
321 throw new NullPointerException(MessageFormat.format("mobileNumber.phoneNumber={0} is not valid.", mobileNumber.getPhoneNumber())); //NOI18N
324 // Get contact from it and find it
325 DialableMobileNumber managedNumber = this.getEntityManager().find(mobileNumber.getClass(), mobileNumber.getPhoneId());
328 assert (managedNumber instanceof DialableMobileNumber) : MessageFormat.format("Cell phone number with id {0} not found, but should be.", mobileNumber.getPhoneId()); //NOI18N
331 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateMobileData: managedNumber.phoneId={1}", this.getClass().getSimpleName(), managedNumber.getPhoneId())); //NOI18N
333 // Set updated timestamp
334 mobileNumber.setPhoneEntryUpdated(new GregorianCalendar());
337 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateMobileData: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
340 return managedNumber;