2 * Copyright (C) 2016, 2017 Roland Häder
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.mobileprovider;
19 import java.text.MessageFormat;
20 import java.util.GregorianCalendar;
21 import javax.ejb.Stateless;
22 import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
23 import org.mxchange.jphone.exceptions.MobileProviderAlreadyAddedException;
24 import org.mxchange.jphone.model.phonenumbers.mobileprovider.AdminMobileProviderSessionBeanRemote;
25 import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider;
28 * An administrative singleton EJB for mobile provider informations
30 * @author Roland Häder<roland@mxchange.org>
32 @Stateless (name = "adminMobileProvider", description = "A singleton session-scoped bean for mobile provider informations, admin-edition")
33 public class AddressbookAdminMobileProviderSessionBean extends BaseAddressbookDatabaseBean implements AdminMobileProviderSessionBeanRemote {
38 private static final long serialVersionUID = 15_846_983_298_691_207L;
43 public AddressbookAdminMobileProviderSessionBean () {
44 // Call super constructor
49 public MobileProvider addMobileProvider (final MobileProvider mobileProvider) throws MobileProviderAlreadyAddedException {
51 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addMobileProvider: mobileProvider={1} - CALLED!", this.getClass().getSimpleName(), mobileProvider)); //NOI18N
53 // Is the instance valid?
54 if (null == mobileProvider) {
56 throw new NullPointerException("mobileProvider is null"); //NOI18N
57 } else if (mobileProvider.getProviderDialPrefix() == null) {
59 throw new NullPointerException("mobileProvider.providerDialPrefix is null"); //NOI18N
60 } else if (mobileProvider.getProviderDialPrefix() < 1) {
62 throw new IllegalArgumentException(MessageFormat.format("mobileProvider.providerDialPrefix={0} is not valid.", mobileProvider.getProviderDialPrefix())); //NOI18N
63 } else if (mobileProvider.getProviderCountry() == null) {
65 throw new NullPointerException("mobileProvider.providerCountry is null"); //NOI18N
66 } else if (mobileProvider.getProviderMailPattern() == null) {
68 throw new NullPointerException("mobileProvider.providerMailPattern is null"); //NOI18N
69 } else if (mobileProvider.getProviderMailPattern().isEmpty()) {
70 // Empty pattern set (not allowed)
71 throw new IllegalArgumentException("mobileProvider.providerMailPattern is empty."); //NOI18N
72 } else if (!mobileProvider.getProviderMailPattern().contains("%s")) { //NOI18N
73 // No place-holder found
74 throw new IllegalArgumentException(MessageFormat.format("mobileProvider.providerMailPattern={0} does not contain '%s' which is need to be replaced with the full mobile number.", mobileProvider.getProviderMailPattern())); //NOI18N
75 } else if (mobileProvider.getProviderName() == null) {
77 throw new NullPointerException("mobileProvider.providerName is null"); //NOI18N
78 } else if (mobileProvider.getProviderName().isEmpty()) {
79 // Empty name is not allowed
80 throw new IllegalArgumentException("mobileProvider.providerName is empty"); //NOI18N
83 // Set creation timestamp
84 mobileProvider.setProviderEntryCreated(new GregorianCalendar());
87 this.getEntityManager().persist(mobileProvider);
90 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addMobileProvider: mobileProvider.providerId={1} - EXIT!", this.getClass().getSimpleName(), mobileProvider.getProviderId())); //NOI18N
93 return mobileProvider;