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