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.jcontacts.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.cellphone.DialableCellphoneNumber;
26 * A session EJB for administrative contact's phone number purposes
28 * @author Roland Haeder<roland@mxchange.org>
30 @Stateless (name = "admincontactphone", description = "An administrative bean handling contact's phone data")
31 public class JobsAdminContactPhoneSessionBean extends BaseJobsDatabaseBean implements AdminContactsPhoneSessionBeanRemote {
36 private static final long serialVersionUID = 189_217_561_460_237_108L;
39 public DialableCellphoneNumber updateCellphoneData (final DialableCellphoneNumber cellPhoneNumber) {
41 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateCellphoneData: cellPhoneNumber={1} - CALLED!", this.getClass().getSimpleName(), cellPhoneNumber));
44 if (null == cellPhoneNumber) {
46 throw new NullPointerException("cellphoneNumber is null"); //NOI18N
47 } else if (cellPhoneNumber.getPhoneId() == null) {
49 throw new NullPointerException("cellphoneNumber.phoneId is null"); //NOI18N
50 } else if (cellPhoneNumber.getPhoneId() < 1) {
52 throw new IllegalArgumentException(MessageFormat.format("cellphoneNumber.phoneId={0} is not valid", cellPhoneNumber.getPhoneId())); //NOI18N
53 } else if (cellPhoneNumber.getCellphoneProvider() == null) {
55 throw new NullPointerException("cellphoneNumber.cellphoneProvider is null"); //NOI18N
56 } else if (cellPhoneNumber.getCellphoneProvider().getProviderId() == null) {
58 throw new NullPointerException("cellphoneNumber.cellphoneProvider.providerId is null"); //NOI18N
59 } else if (cellPhoneNumber.getCellphoneProvider().getProviderId() < 1) {
61 throw new IllegalArgumentException(MessageFormat.format("cellphoneNumber.cellphoneProvider.providerId={0} is not valid.", cellPhoneNumber.getCellphoneProvider().getProviderId())); //NOI18N
62 } else if (cellPhoneNumber.getPhoneNumber() == null) {
64 throw new NullPointerException("cellphoneNumber.phoneNumber is null"); //NOI18N
65 } else if (cellPhoneNumber.getPhoneNumber() < 1) {
67 throw new NullPointerException(MessageFormat.format("cellphoneNumber.phoneNumber={0} is not valid.", cellPhoneNumber.getPhoneNumber())); //NOI18N
70 // Set updated timestamp
71 cellPhoneNumber.setPhoneEntryUpdated(new GregorianCalendar());
73 // Get contact from it and find it
74 DialableCellphoneNumber foundNumber = this.getEntityManager().find(cellPhoneNumber.getClass(), cellPhoneNumber.getPhoneId());
77 assert (foundNumber instanceof DialableCellphoneNumber) : MessageFormat.format("Cell phone number with id {0} not found, but should be.", cellPhoneNumber.getPhoneId()); //NOI18N
80 this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateCellphoneData: foundNumber.phoneId={0}", foundNumber.getPhoneId())); //NOI18N
82 // Merge contact instance
83 DialableCellphoneNumber detachedNumber = this.getEntityManager().merge(foundNumber);
86 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateCellphoneData: detachedNumber={1} - EXIT!", this.getClass().getSimpleName(), detachedNumber)); //NOI18N
89 return detachedNumber;