import org.mxchange.jcontacts.contact.AdminContactSessionBeanRemote;
import org.mxchange.jcontacts.contact.Contact;
import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
+import org.mxchange.jcontacts.contact.ContactUtils;
import org.mxchange.jcontacts.contact.UserContact;
import org.mxchange.jcontacts.contact.title.PersonalTitle;
-import org.mxchange.jcontacts.contact.ContactUtils;
import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
*/
private static final long serialVersionUID = 542_145_347_916L;
+ /**
+ * Academic academicTitle
+ */
+ private String academicTitle;
+
/**
* An event fired when the administrator has added a new contact
*/
*/
private String street;
- /**
- * Academic academicTitle
- */
- private String academicTitle;
-
/**
* An event fired when the administrator has updated contact data
*/
return number;
}
+ @Override
+ public String getAcademicTitle () {
+ return this.academicTitle;
+ }
+
+ @Override
+ public void setAcademicTitle (final String academicTitle) {
+ this.academicTitle = academicTitle;
+ }
+
@Override
@SuppressWarnings ("ReturnOfDateField")
public Date getBirthday () {
this.street = street;
}
- @Override
- public String getAcademicTitle () {
- return this.academicTitle;
- }
-
- @Override
- public void setAcademicTitle (final String academicTitle) {
- this.academicTitle = academicTitle;
- }
-
@Override
public Integer getZipCode () {
return this.zipCode;
* Initialization of this converter
*/
public PizzaContactConverter () {
- // Try to get it
- try {
- // Get initial context
- Context context = new InitialContext();
-
- // ... and user controller
- this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
- } catch (final NamingException ex) {
- // Continue to throw it
- throw new ConverterException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
- }
}
@Override
return null;
}
+ synchronized (this) {
+ // Is the EJB instanciated?
+ if (null == this.contactBean) {
+ // Try to get it
+ try {
+ // Get initial context
+ Context initialContext = new InitialContext();
+
+ // ... and user controller
+ this.contactBean = (ContactSessionBeanRemote) initialContext.lookup("java:global/pizzaservice-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
+ } catch (final NamingException ex) {
+ // Continue to throw it
+ throw new ConverterException(MessageFormat.format("initialContext.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
+ }
+ }
+ }
+
// Init instance
Contact contact = null;
/**
* Country bean
*/
- private CountrySingletonBeanRemote countryBean;
+ private CountrySingletonBeanRemote countryBean = null;
/**
* Initialization of this converter
*/
public PizzaCountryConverter () {
- // Try to get it
- try {
- // Get initial context
- Context context = new InitialContext();
-
- // ... and country bean
- this.countryBean = (CountrySingletonBeanRemote) context.lookup("java:global/pizzaservice-ejb/country!org.mxchange.jcountry.data.CountrySingletonBeanRemote"); //NOI18N
- } catch (final NamingException ex) {
- // Continue to throw it
- throw new ConverterException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
- }
}
@Override
return null;
}
+ synchronized (this) {
+ // Is the EJB instanciated?
+ if (null == this.countryBean) {
+ // Try to get it
+ try {
+ // Get initial context
+ Context initialContext = new InitialContext();
+
+ // ... and country bean
+ this.countryBean = (CountrySingletonBeanRemote) initialContext.lookup("java:global/pizzaservice-ejb/country!org.mxchange.jcountry.data.CountrySingletonBeanRemote"); //NOI18N
+ } catch (final NamingException ex) {
+ // Continue to throw it
+ throw new ConverterException(MessageFormat.format("initialContext.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
+ }
+ }
+ }
+
// Get full list
List<Country> countryList = this.countryBean.allCountries();
* Initialization of this converter
*/
public PizzaMobileConverter () {
- // Try to get it
- try {
- // Get initial context
- Context context = new InitialContext();
-
- // ... and user controller
- this.phoneBean = (PhoneSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/phone!org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote"); //NOI18N
- } catch (final NamingException ex) {
- // Continue to throw it
- throw new ConverterException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
- }
}
@Override
return null;
}
+ synchronized (this) {
+ // Is the EJB instanciated?
+ if (null == this.phoneBean) {
+ // Try to get it
+ try {
+ // Get initial context
+ Context initialContext = new InitialContext();
+
+ // ... and user controller
+ this.phoneBean = (PhoneSessionBeanRemote) initialContext.lookup("java:global/pizzaservice-ejb/phone!org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote"); //NOI18N
+ } catch (final NamingException ex) {
+ // Continue to throw it
+ throw new ConverterException(MessageFormat.format("initialContext.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
+ }
+ }
+ }
+
// Init instance
DialableMobileNumber mobile = null;
* Initialization of this converter
*/
public PizzaMobileProviderConverter () {
- // Try to get it
- try {
- // Get initial context
- Context context = new InitialContext();
-
- /// and SMS provider controller
- this.mobileRemoteBean = (MobileProviderSingletonBeanRemote) context.lookup("java:global/pizzaservice-ejb/mobileprovider!org.mxchange.jphone.phonenumbers.mobileprovider.MobileProviderSingletonBeanRemote"); //NOI18N
- } catch (final NamingException ex) {
- // Continue to throw it
- throw new ConverterException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
- }
}
@Override
return null;
}
+ synchronized (this) {
+ // Is the EJB instanciated?
+ if (null == this.mobileRemoteBean) {
+ // Try to get it
+ try {
+ // Get initial context
+ Context initialContext = new InitialContext();
+
+ /// and mobile provider controller
+ this.mobileRemoteBean = (MobileProviderSingletonBeanRemote) initialContext.lookup("java:global/pizzaservice-ejb/mobileprovider!org.mxchange.jphone.phonenumbers.mobileprovider.MobileProviderSingletonBeanRemote"); //NOI18N
+ } catch (final NamingException ex) {
+ // Continue to throw it
+ throw new ConverterException(MessageFormat.format("initialContext.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
+ }
+ }
+ }
+
// Get full list
List<MobileProvider> providerList = this.mobileRemoteBean.allMobileProvider();
* Initialization of this converter
*/
public PizzaUserConverter () {
- // Try to get it
- try {
- // Get initial context
- Context context = new InitialContext();
-
- // ... and user controller
- this.userBean = (UserSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N
- } catch (final NamingException ex) {
- // Continue to throw it
- throw new RuntimeException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
- }
}
@Override
return null;
}
+ synchronized (this) {
+ // Is the EJB instanciated?
+ if (null == this.userBean) {
+ // Try to get it
+ try {
+ // Get initial context
+ Context initialContext = new InitialContext();
+
+ // ... and user controller
+ this.userBean = (UserSessionBeanRemote) initialContext.lookup("java:global/pizzaservice-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N
+ } catch (final NamingException ex) {
+ // Continue to throw it
+ throw new RuntimeException(MessageFormat.format("initialContext.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
+ }
+ }
+ }
+
// Init instance
User user = null;
// Try to get it
try {
// Get initial context
- Context context = new InitialContext();
+ Context initialContext = new InitialContext();
} catch (final NamingException ex) {
// Continue to throw it
- throw new ConverterException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
+ throw new ConverterException(MessageFormat.format("initialContext.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
}
}
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
+import javax.faces.convert.ConverterException;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
-import javax.faces.view.facelets.FaceletException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* Contact session-scoped bean
*/
- private final ContactSessionBeanRemote contactBean;
+ private ContactSessionBeanRemote contactBean;
/**
* Default constructor
*/
public PizzaEmailAddressValidator () {
- // Try it
- try {
- // Get initial context
- Context context = new InitialContext();
-
- // Try to lookup
- this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
- } catch (final NamingException e) {
- // Throw again
- throw new FaceletException(e);
- }
}
@Override
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, message, message));
}
+ synchronized (this) {
+ // Is the EJB instanciated?
+ if (null == this.contactBean) {
+ // Try it
+ try {
+ // Get initial context
+ Context initialContext = new InitialContext();
+
+ // Try to lookup
+ this.contactBean = (ContactSessionBeanRemote) initialContext.lookup("java:global/pizzaservice-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
+ } catch (final NamingException ex) {
+ // Continue to throw it
+ throw new ConverterException(MessageFormat.format("initialContext.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
+ }
+ }
+ }
+
// Get client id (aka form id)
String clientId = component.getClientId();
// Pre-validation (example: not null, not a string, empty string ...)
super.preValidate(context, component, value, requiredFields, false);
}
+
}
package org.mxchange.pizzaapplication.validator.user;
import java.text.MessageFormat;
-import java.util.Set;
-import java.util.TreeSet;
-import javax.enterprise.event.Observes;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.mxchange.jcoreee.validator.number.BaseLongValidator;
-import org.mxchange.jusercore.events.registration.ObservableUserRegisteredEvent;
-import org.mxchange.jusercore.model.user.User;
import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
/**
@FacesValidator ("UserIdValidator")
public class PizzaUserIdValidator extends BaseLongValidator implements Validator {
- /**
- * Cached user status
- */
- private static final Set<Long> cachedStatus = new TreeSet<>();
-
/**
* Serial number
*/
* Initialization of this converter
*/
public PizzaUserIdValidator () {
- // Try to get it
- try {
- // Get initial context
- Context context = new InitialContext();
-
- // ... and user controller
- this.userBean = (UserSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N
- } catch (final NamingException ex) {
- // Continue to throw it
- throw new ConverterException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
- }
- }
-
- /**
- * Event fired when the user registration is complete
- * <p>
- * @param event User registration event
- */
- public void afterUserRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) {
- // event should not be null
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getRegisteredUser() == null) {
- // Throw NPE again
- throw new NullPointerException("event.user is null"); //NOI18N
- } else if (event.getRegisteredUser().getUserId() == null) {
- // userId is null
- throw new NullPointerException("event.user.userId is null"); //NOI18N
- } else if (event.getRegisteredUser().getUserId() < 1) {
- // Not avalid id
- throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
- }
-
- // Get user instance
- User registeredUser = event.getRegisteredUser();
-
- // Update cache
- PizzaUserIdValidator.cachedStatus.add(registeredUser.getUserId());
-
}
@Override
// Cast value
Long userId = (Long) value;
- // Define variable
- Boolean ifUserExists;
-
- // Is a map entry there?
- if (PizzaUserIdValidator.cachedStatus.contains(userId)) {
- // Get from cache
- ifUserExists = Boolean.TRUE;
- } else {
- // Get status
- ifUserExists = this.userBean.ifUserIdExists(userId);
+ synchronized (this) {
+ // Is the EJB instanciated?
+ if (null == this.userBean) {
+ // Try to get it
+ try {
+ // Get initial context
+ Context initialContext = new InitialContext();
+
+ // ... and user controller
+ this.userBean = (UserSessionBeanRemote) initialContext.lookup("java:global/pizzaservice-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N
+ } catch (final NamingException ex) {
+ // Continue to throw it
+ throw new ConverterException(MessageFormat.format("initialContext.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
+ }
+ }
}
+ // Define variable
+ Boolean ifUserExists = this.userBean.ifUserIdExists(userId);
+
// Is the user id valid?
if (!ifUserExists) {
// Is not valid
throw new ValidatorException(new FacesMessage(MessageFormat.format("No user found with id {0}. Please check your link.", userId))); //NOI18N
}
-
- // Add to cache if valid
- PizzaUserIdValidator.cachedStatus.add(userId);
}
}