2 * Copyright (C) 2016 - 2020 Free Software Foundation
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.model.phonenumbers.phone;
19 import java.text.MessageFormat;
20 import java.util.Date;
21 import javax.ejb.Stateless;
22 import org.mxchange.jjobs.enterprise.BaseJobsEnterpriseBean;
23 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
24 import org.mxchange.jphone.model.phonenumbers.fax.FaxNumbers;
25 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
26 import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumbers;
29 * An EJB for administrative phone purposes
31 * @author Roland Häder<roland@mxchange.org>
33 @Stateless (name = "adminPhone", description = "An administrative bean handling phone data")
34 public class JobsAdminPhoneSessionBean extends BaseJobsEnterpriseBean implements AdminPhoneSessionBeanRemote {
39 private static final long serialVersionUID = 18_597_165_817_401_853L;
44 public JobsAdminPhoneSessionBean () {
45 // Call super constructor
50 public void deleteFaxData (final DialableFaxNumber faxNumber) {
52 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteFaxData: faxNumber={1} - CALLED!", this.getClass().getSimpleName(), faxNumber));
55 if (faxNumber == null) {
57 throw new NullPointerException("faxNumber is null"); //NOI18N
58 } else if (faxNumber.getPhoneId() == null) {
60 throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N
61 } else if (faxNumber.getPhoneId() < 1) {
63 throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid", faxNumber.getPhoneId())); //NOI18N
64 } else if (faxNumber.getPhoneCountry() == null) {
66 throw new NullPointerException("faxNumber.phoneCountry is null"); //NOI18N
67 } else if (faxNumber.getPhoneCountry().getCountryId() == null) {
69 throw new NullPointerException("faxNumber.phoneCountry.countryId is null"); //NOI18N
70 } else if (faxNumber.getPhoneCountry().getCountryId() < 1) {
72 throw new NullPointerException(MessageFormat.format("faxNumber.phoneCountry.countryId={0} is not valid", faxNumber.getPhoneCountry().getCountryId())); //NOI18N
73 } else if (faxNumber.getPhoneAreaCode() == null) {
75 throw new NullPointerException("faxNumber.phoneAreaCode is null"); //NOI18N
76 } else if (faxNumber.getPhoneAreaCode() < 1) {
78 throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneAreaCode={0} is not valid.", faxNumber.getPhoneAreaCode())); //NOI18N
79 } else if (faxNumber.getPhoneNumber() == null) {
81 throw new NullPointerException("faxNumber.phoneNumber is null"); //NOI18N
82 } else if (faxNumber.getPhoneNumber() < 1) {
84 throw new NullPointerException(MessageFormat.format("faxNumber.phoneNumber={0} is not valid.", faxNumber.getPhoneNumber())); //NOI18N
87 // Get a managed instance
88 final DialableFaxNumber managedNumber = this.getEntityManager().getReference(faxNumber.getClass(), faxNumber.getPhoneId());
90 // Remove it from database
91 this.getEntityManager().remove(managedNumber);
94 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteMobileData: EXIT!", this.getClass().getSimpleName()));
98 public void deleteLandLineData (final DialableLandLineNumber landLineNumber) {
100 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteLandLineData: landLineNumber={1} - CALLED!", this.getClass().getSimpleName(), landLineNumber));
103 if (landLineNumber == null) {
104 // Not set, throw NPE
105 throw new NullPointerException("landLineNumber is null"); //NOI18N
106 } else if (landLineNumber.getPhoneId() == null) {
108 throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
109 } else if (landLineNumber.getPhoneId() < 1) {
111 throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", landLineNumber.getPhoneId())); //NOI18N
112 } else if (landLineNumber.getPhoneCountry() == null) {
114 throw new NullPointerException("landLineNumber.phoneCountry is null"); //NOI18N
115 } else if (landLineNumber.getPhoneCountry().getCountryId() == null) {
117 throw new NullPointerException("landLineNumber.phoneCountry.countryId is null"); //NOI18N
118 } else if (landLineNumber.getPhoneCountry().getCountryId() < 1) {
120 throw new NullPointerException(MessageFormat.format("landLineNumber.phoneCountry.countryId={0} is not valid", landLineNumber.getPhoneCountry().getCountryId())); //NOI18N
121 } else if (landLineNumber.getPhoneAreaCode() == null) {
123 throw new NullPointerException("landLineNumber.phoneAreaCode is null"); //NOI18N
124 } else if (landLineNumber.getPhoneAreaCode() < 1) {
126 throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneAreaCode={0} is not valid.", landLineNumber.getPhoneAreaCode())); //NOI18N
127 } else if (landLineNumber.getPhoneNumber() == null) {
129 throw new NullPointerException("landLineNumber.phoneNumber is null"); //NOI18N
130 } else if (landLineNumber.getPhoneNumber() < 1) {
132 throw new NullPointerException(MessageFormat.format("landLineNumber.phoneNumber={0} is not valid.", landLineNumber.getPhoneNumber())); //NOI18N
135 // Get a managed instance
136 final DialableLandLineNumber managedNumber = this.getEntityManager().getReference(landLineNumber.getClass(), landLineNumber.getPhoneId());
138 // Remove it from database
139 this.getEntityManager().remove(managedNumber);
142 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteMobileData: EXIT!", this.getClass().getSimpleName()));
146 public DialableFaxNumber updateFaxData (final DialableFaxNumber faxNumber) {
148 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateFaxData: faxNumber={1} - CALLED!", this.getClass().getSimpleName(), faxNumber));
151 if (faxNumber == null) {
152 // Not set, throw NPE
153 throw new NullPointerException("faxNumber is null"); //NOI18N
154 } else if (faxNumber.getPhoneId() == null) {
156 throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N
157 } else if (faxNumber.getPhoneId() < 1) {
159 throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid", faxNumber.getPhoneId())); //NOI18N
160 } else if (faxNumber.getPhoneCountry() == null) {
162 throw new NullPointerException("faxNumber.phoneCountry is null"); //NOI18N
163 } else if (faxNumber.getPhoneCountry().getCountryId() == null) {
165 throw new NullPointerException("faxNumber.phoneCountry.countryId is null"); //NOI18N
166 } else if (faxNumber.getPhoneCountry().getCountryId() < 1) {
168 throw new NullPointerException(MessageFormat.format("faxNumber.phoneCountry.countryId={0} is not valid", faxNumber.getPhoneCountry().getCountryId())); //NOI18N
169 } else if (faxNumber.getPhoneAreaCode() == null) {
171 throw new NullPointerException("faxNumber.phoneAreaCode is null"); //NOI18N
172 } else if (faxNumber.getPhoneAreaCode() < 1) {
174 throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneAreaCode={0} is not valid.", faxNumber.getPhoneAreaCode())); //NOI18N
175 } else if (faxNumber.getPhoneNumber() == null) {
177 throw new NullPointerException("faxNumber.phoneNumber is null"); //NOI18N
178 } else if (faxNumber.getPhoneNumber() < 1) {
180 throw new NullPointerException(MessageFormat.format("faxNumber.phoneNumber={0} is not valid.", faxNumber.getPhoneNumber())); //NOI18N
183 // Get contact from it and find it
184 final DialableFaxNumber managedNumber = this.getEntityManager().find(faxNumber.getClass(), faxNumber.getPhoneId());
187 assert (managedNumber instanceof DialableFaxNumber) : MessageFormat.format("Cell phone number with id {0} not found, but should be.", faxNumber.getPhoneId()); //NOI18N
190 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateFaxData: managedNumber.phoneId={1}", this.getClass().getSimpleName(), managedNumber.getPhoneId())); //NOI18N
192 // Set updated timestamp
193 FaxNumbers.copyFaxNumber(faxNumber, managedNumber);
194 managedNumber.setPhoneEntryUpdated(new Date());
197 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateFaxData: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
200 return managedNumber;
204 public DialableLandLineNumber updateLandLineData (final DialableLandLineNumber landLineNumber) {
206 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateLandLineData: landLineNumber={1} - CALLED!", this.getClass().getSimpleName(), landLineNumber));
209 if (landLineNumber == null) {
210 // Not set, throw NPE
211 throw new NullPointerException("landLineNumber is null"); //NOI18N
212 } else if (landLineNumber.getPhoneId() == null) {
214 throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
215 } else if (landLineNumber.getPhoneId() < 1) {
217 throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", landLineNumber.getPhoneId())); //NOI18N
218 } else if (landLineNumber.getPhoneCountry() == null) {
220 throw new NullPointerException("landLineNumber.phoneCountry is null"); //NOI18N
221 } else if (landLineNumber.getPhoneCountry().getCountryId() == null) {
223 throw new NullPointerException("landLineNumber.phoneCountry.countryId is null"); //NOI18N
224 } else if (landLineNumber.getPhoneCountry().getCountryId() < 1) {
226 throw new NullPointerException(MessageFormat.format("landLineNumber.phoneCountry.countryId={0} is not valid", landLineNumber.getPhoneCountry().getCountryId())); //NOI18N
227 } else if (landLineNumber.getPhoneAreaCode() == null) {
229 throw new NullPointerException("landLineNumber.phoneAreaCode is null"); //NOI18N
230 } else if (landLineNumber.getPhoneAreaCode() < 1) {
232 throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneAreaCode={0} is not valid.", landLineNumber.getPhoneAreaCode())); //NOI18N
233 } else if (landLineNumber.getPhoneNumber() == null) {
235 throw new NullPointerException("landLineNumber.phoneNumber is null"); //NOI18N
236 } else if (landLineNumber.getPhoneNumber() < 1) {
238 throw new NullPointerException(MessageFormat.format("landLineNumber.phoneNumber={0} is not valid.", landLineNumber.getPhoneNumber())); //NOI18N
241 // Get contact from it and find it
242 final DialableLandLineNumber managedNumber = this.getEntityManager().find(landLineNumber.getClass(), landLineNumber.getPhoneId());
245 assert (managedNumber instanceof DialableLandLineNumber) : MessageFormat.format("Cell phone number with id {0} not found, but should be.", landLineNumber.getPhoneId()); //NOI18N
248 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateLandLineData: managedNumber.phoneId={1}", this.getClass().getSimpleName(), managedNumber.getPhoneId())); //NOI18N
250 // Set updated timestamp
251 LandLineNumbers.copyLandLineNumber(landLineNumber, managedNumber);
252 managedNumber.setPhoneEntryUpdated(new Date());
255 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateLandLineData: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
258 return managedNumber;