]> git.mxchange.org Git - addressbook-ejb.git/blob - src/java/org/mxchange/jphone/model/phonenumbers/phone/AddressbookAdminPhoneSessionBean.java
Updated copyright year
[addressbook-ejb.git] / src / java / org / mxchange / jphone / model / phonenumbers / phone / AddressbookAdminPhoneSessionBean.java
1 /*
2  * Copyright (C) 2016 - 2024 Free Software Foundation
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.jphone.model.phonenumbers.phone;
18
19 import java.text.MessageFormat;
20 import java.util.Date;
21 import javax.ejb.Stateless;
22 import org.mxchange.addressbook.enterprise.BaseAddressbookEnterpriseBean;
23 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
24 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
25 import org.mxchange.jphone.model.utils.FaxNumberUtils;
26 import org.mxchange.jphone.model.utils.LandLineNumberUtils;
27
28 /**
29  * An EJB for administrative phone purposes
30  * <p>
31  * @author Roland Häder<roland@mxchange.org>
32  */
33 @Stateless (name = "adminPhone", description = "An administrative bean handling phone data")
34 public class AddressbookAdminPhoneSessionBean extends BaseAddressbookEnterpriseBean implements AdminPhoneSessionBeanRemote {
35
36         /**
37          * Serial number
38          */
39         private static final long serialVersionUID = 18_597_165_817_401_853L;
40
41         /**
42          * Default constructor
43          */
44         public AddressbookAdminPhoneSessionBean () {
45                 // Call super constructor
46                 super();
47         }
48
49         @Override
50         public void deleteFaxData (final DialableFaxNumber faxNumber) {
51                 // Trace message
52                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteFaxData: faxNumber={1} - CALLED!", this.getClass().getSimpleName(), faxNumber));
53
54                 // Is all data set
55                 if (faxNumber == null) {
56                         // Not set, throw NPE
57                         throw new NullPointerException("faxNumber is null"); //NOI18N
58                 } else if (faxNumber.getPhoneId() == null) {
59                         // Throw NPE again
60                         throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N
61                 } else if (faxNumber.getPhoneId() < 1) {
62                         // Invalid number
63                         throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid", faxNumber.getPhoneId())); //NOI18N
64                 } else if (faxNumber.getPhoneCountry() == null) {
65                         // Throw NPE
66                         throw new NullPointerException("faxNumber.phoneCountry is null"); //NOI18N
67                 } else if (faxNumber.getPhoneCountry().getCountryId() == null) {
68                         // Throw NPE
69                         throw new NullPointerException("faxNumber.phoneCountry.countryId is null"); //NOI18N
70                 } else if (faxNumber.getPhoneCountry().getCountryId() < 1) {
71                         // Throw NPE
72                         throw new NullPointerException(MessageFormat.format("faxNumber.phoneCountry.countryId={0} is not valid", faxNumber.getPhoneCountry().getCountryId())); //NOI18N
73                 } else if (faxNumber.getPhoneAreaCode() == null) {
74                         // ... throw again
75                         throw new NullPointerException("faxNumber.phoneAreaCode is null"); //NOI18N
76                 } else if (faxNumber.getPhoneAreaCode() < 1) {
77                         // Id not valid
78                         throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneAreaCode={0} is not valid.", faxNumber.getPhoneAreaCode())); //NOI18N
79                 } else if (faxNumber.getPhoneNumber() == null) {
80                         // Throw NPE again
81                         throw new NullPointerException("faxNumber.phoneNumber is null"); //NOI18N
82                 } else if (faxNumber.getPhoneNumber() < 1) {
83                         // Throw NPE again
84                         throw new NullPointerException(MessageFormat.format("faxNumber.phoneNumber={0} is not valid.", faxNumber.getPhoneNumber())); //NOI18N
85                 }
86
87                 // Get a managed instance
88                 final DialableFaxNumber managedNumber = this.getEntityManager().getReference(faxNumber.getClass(), faxNumber.getPhoneId());
89
90                 // Remove it from database
91                 this.getEntityManager().remove(managedNumber);
92
93                 // Trace message
94                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteMobileData: EXIT!", this.getClass().getSimpleName()));
95         }
96
97         @Override
98         public void deleteLandLineData (final DialableLandLineNumber landLineNumber) {
99                 // Trace message
100                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteLandLineData: landLineNumber={1} - CALLED!", this.getClass().getSimpleName(), landLineNumber));
101
102                 // Is all data set
103                 if (landLineNumber == null) {
104                         // Not set, throw NPE
105                         throw new NullPointerException("landLineNumber is null"); //NOI18N
106                 } else if (landLineNumber.getPhoneId() == null) {
107                         // Throw NPE again
108                         throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
109                 } else if (landLineNumber.getPhoneId() < 1) {
110                         // Invalid number
111                         throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", landLineNumber.getPhoneId())); //NOI18N
112                 } else if (landLineNumber.getPhoneCountry() == null) {
113                         // Throw NPE
114                         throw new NullPointerException("landLineNumber.phoneCountry is null"); //NOI18N
115                 } else if (landLineNumber.getPhoneCountry().getCountryId() == null) {
116                         // Throw NPE
117                         throw new NullPointerException("landLineNumber.phoneCountry.countryId is null"); //NOI18N
118                 } else if (landLineNumber.getPhoneCountry().getCountryId() < 1) {
119                         // Throw NPE
120                         throw new NullPointerException(MessageFormat.format("landLineNumber.phoneCountry.countryId={0} is not valid", landLineNumber.getPhoneCountry().getCountryId())); //NOI18N
121                 } else if (landLineNumber.getPhoneAreaCode() == null) {
122                         // ... throw again
123                         throw new NullPointerException("landLineNumber.phoneAreaCode is null"); //NOI18N
124                 } else if (landLineNumber.getPhoneAreaCode() < 1) {
125                         // Id not valid
126                         throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneAreaCode={0} is not valid.", landLineNumber.getPhoneAreaCode())); //NOI18N
127                 } else if (landLineNumber.getPhoneNumber() == null) {
128                         // Throw NPE again
129                         throw new NullPointerException("landLineNumber.phoneNumber is null"); //NOI18N
130                 } else if (landLineNumber.getPhoneNumber() < 1) {
131                         // Throw NPE again
132                         throw new NullPointerException(MessageFormat.format("landLineNumber.phoneNumber={0} is not valid.", landLineNumber.getPhoneNumber())); //NOI18N
133                 }
134
135                 // Get a managed instance
136                 final DialableLandLineNumber managedNumber = this.getEntityManager().getReference(landLineNumber.getClass(), landLineNumber.getPhoneId());
137
138                 // Remove it from database
139                 this.getEntityManager().remove(managedNumber);
140
141                 // Trace message
142                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteMobileData: EXIT!", this.getClass().getSimpleName()));
143         }
144
145         @Override
146         public DialableFaxNumber updateFaxData (final DialableFaxNumber faxNumber) {
147                 // Trace message
148                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateFaxData: faxNumber={1} - CALLED!", this.getClass().getSimpleName(), faxNumber));
149
150                 // Is all data set
151                 if (faxNumber == null) {
152                         // Not set, throw NPE
153                         throw new NullPointerException("faxNumber is null"); //NOI18N
154                 } else if (faxNumber.getPhoneId() == null) {
155                         // Throw NPE again
156                         throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N
157                 } else if (faxNumber.getPhoneId() < 1) {
158                         // Invalid number
159                         throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid", faxNumber.getPhoneId())); //NOI18N
160                 } else if (faxNumber.getPhoneCountry() == null) {
161                         // Throw NPE
162                         throw new NullPointerException("faxNumber.phoneCountry is null"); //NOI18N
163                 } else if (faxNumber.getPhoneCountry().getCountryId() == null) {
164                         // Throw NPE
165                         throw new NullPointerException("faxNumber.phoneCountry.countryId is null"); //NOI18N
166                 } else if (faxNumber.getPhoneCountry().getCountryId() < 1) {
167                         // Throw NPE
168                         throw new NullPointerException(MessageFormat.format("faxNumber.phoneCountry.countryId={0} is not valid", faxNumber.getPhoneCountry().getCountryId())); //NOI18N
169                 } else if (faxNumber.getPhoneAreaCode() == null) {
170                         // ... throw again
171                         throw new NullPointerException("faxNumber.phoneAreaCode is null"); //NOI18N
172                 } else if (faxNumber.getPhoneAreaCode() < 1) {
173                         // Id not valid
174                         throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneAreaCode={0} is not valid.", faxNumber.getPhoneAreaCode())); //NOI18N
175                 } else if (faxNumber.getPhoneNumber() == null) {
176                         // Throw NPE again
177                         throw new NullPointerException("faxNumber.phoneNumber is null"); //NOI18N
178                 } else if (faxNumber.getPhoneNumber() < 1) {
179                         // Throw NPE again
180                         throw new NullPointerException(MessageFormat.format("faxNumber.phoneNumber={0} is not valid.", faxNumber.getPhoneNumber())); //NOI18N
181                 }
182
183                 // Get contact from it and find it
184                 final DialableFaxNumber managedNumber = this.getEntityManager().find(faxNumber.getClass(), faxNumber.getPhoneId());
185
186                 // Should be found
187                 assert (managedNumber instanceof DialableFaxNumber) : MessageFormat.format("Cell phone number with id {0} not found, but should be.", faxNumber.getPhoneId()); //NOI18N
188
189                 // Debug message
190                 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateFaxData: managedNumber.phoneId={1}", this.getClass().getSimpleName(), managedNumber.getPhoneId())); //NOI18N
191
192                 // Set updated timestamp
193                 FaxNumberUtils.copyFaxNumberData(faxNumber, managedNumber);
194                 managedNumber.setPhoneEntryUpdated(new Date());
195
196                 // Trace message
197                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateFaxData: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
198
199                 // Return it
200                 return managedNumber;
201         }
202
203         @Override
204         public DialableLandLineNumber updateLandLineData (final DialableLandLineNumber landLineNumber) {
205                 // Trace message
206                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateLandLineData: landLineNumber={1} - CALLED!", this.getClass().getSimpleName(), landLineNumber));
207
208                 // Is all data set
209                 if (landLineNumber == null) {
210                         // Not set, throw NPE
211                         throw new NullPointerException("landLineNumber is null"); //NOI18N
212                 } else if (landLineNumber.getPhoneId() == null) {
213                         // Throw NPE again
214                         throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
215                 } else if (landLineNumber.getPhoneId() < 1) {
216                         // Invalid number
217                         throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", landLineNumber.getPhoneId())); //NOI18N
218                 } else if (landLineNumber.getPhoneCountry() == null) {
219                         // Throw NPE
220                         throw new NullPointerException("landLineNumber.phoneCountry is null"); //NOI18N
221                 } else if (landLineNumber.getPhoneCountry().getCountryId() == null) {
222                         // Throw NPE
223                         throw new NullPointerException("landLineNumber.phoneCountry.countryId is null"); //NOI18N
224                 } else if (landLineNumber.getPhoneCountry().getCountryId() < 1) {
225                         // Throw NPE
226                         throw new NullPointerException(MessageFormat.format("landLineNumber.phoneCountry.countryId={0} is not valid", landLineNumber.getPhoneCountry().getCountryId())); //NOI18N
227                 } else if (landLineNumber.getPhoneAreaCode() == null) {
228                         // ... throw again
229                         throw new NullPointerException("landLineNumber.phoneAreaCode is null"); //NOI18N
230                 } else if (landLineNumber.getPhoneAreaCode() < 1) {
231                         // Id not valid
232                         throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneAreaCode={0} is not valid.", landLineNumber.getPhoneAreaCode())); //NOI18N
233                 } else if (landLineNumber.getPhoneNumber() == null) {
234                         // Throw NPE again
235                         throw new NullPointerException("landLineNumber.phoneNumber is null"); //NOI18N
236                 } else if (landLineNumber.getPhoneNumber() < 1) {
237                         // Throw NPE again
238                         throw new NullPointerException(MessageFormat.format("landLineNumber.phoneNumber={0} is not valid.", landLineNumber.getPhoneNumber())); //NOI18N
239                 }
240
241                 // Get contact from it and find it
242                 final DialableLandLineNumber managedNumber = this.getEntityManager().find(landLineNumber.getClass(), landLineNumber.getPhoneId());
243
244                 // Should be found
245                 assert (managedNumber instanceof DialableLandLineNumber) : MessageFormat.format("Cell phone number with id {0} not found, but should be.", landLineNumber.getPhoneId()); //NOI18N
246
247                 // Debug message
248                 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateLandLineData: managedNumber.phoneId={1}", this.getClass().getSimpleName(), managedNumber.getPhoneId())); //NOI18N
249
250                 // Set updated timestamp
251                 LandLineNumberUtils.copyLandLineNumberData(landLineNumber, managedNumber);
252                 managedNumber.setPhoneEntryUpdated(new Date());
253
254                 // Trace message
255                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateLandLineData: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
256
257                 // Return it
258                 return managedNumber;
259         }
260
261 }