import org.mxchange.pizzaapplication.beans.basket.PizzaBasketWebSessionController;
import org.mxchange.pizzaapplication.beans.contact.PizzaContactWebSessionController;
import org.mxchange.pizzaapplication.beans.customer.PizzaCustomerWebSessionController;
-import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestController;
+import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestHelperController;
import org.mxchange.pizzaapplication.beans.receipt.PizzaReceiptWebSessionController;
/**
* Bean helper instance
*/
@Inject
- private PizzaWebRequestController beanHelper;
+ private PizzaWebRequestHelperController beanHelper;
/**
* Event fired when a checkout was completed by the user
import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
import org.mxchange.jusercore.model.user.status.UserAccountStatus;
import org.mxchange.pizzaapplication.beans.BasePizzaController;
-import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestController;
import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController;
import org.mxchange.jusercore.events.confirmation.ObservableUserConfirmedAccountEvent;
+import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestHelperController;
/**
* A web request bean for confirmation link handling
* Bean helper instance
*/
@Inject
- private PizzaWebRequestController beanHelper;
+ private PizzaWebRequestHelperController beanHelper;
/**
* Confirmation key
import org.mxchange.jphone.phonenumbers.mobile.MobileNumber;
import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
import org.mxchange.pizzaapplication.beans.BasePizzaController;
-import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestController;
import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
+import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestHelperController;
/**
* Administrative user bean (controller)
* Bean helper instance
*/
@Inject
- private PizzaWebRequestController beanHelper;
+ private PizzaWebRequestHelperController beanHelper;
/**
* Birth day
import org.mxchange.jcontacts.contact.UserContact;
import org.mxchange.jcontacts.contact.gender.Gender;
import org.mxchange.jcontacts.contact.utils.ContactUtils;
+import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
+import org.mxchange.jcontacts.events.contact.deleted.ObservableAdminDeletedContactEvent;
+import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
+import org.mxchange.jcontacts.events.mobile.unlinked.ObservableAdminUnlinkedMobileNumberEvent;
import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
import org.mxchange.jcountry.data.Country;
+import org.mxchange.jphone.events.mobile.remove.AdminRemoveMobileNumberFromListEvent;
import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
import org.mxchange.jphone.phonenumbers.mobile.MobileNumber;
import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
-import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
-import org.mxchange.jusercore.model.user.User;
-import org.mxchange.pizzaapplication.beans.BasePizzaController;
-import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController;
-import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController;
import org.mxchange.jusercore.events.confirmation.ObservableUserConfirmedAccountEvent;
import org.mxchange.jusercore.events.login.ObservableUserLoggedInEvent;
import org.mxchange.jusercore.events.registration.ObservableUserRegisteredEvent;
import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent;
-import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
-import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
+import org.mxchange.jusercore.model.user.User;
+import org.mxchange.pizzaapplication.beans.BasePizzaController;
+import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController;
+import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController;
/**
* A general contact bean (controller)
*/
private Date birthday;
- /**
- * Mobile number's carrier
- */
- private MobileProvider cellphoneCarrier;
-
- /**
- * Mobile number
- */
- private Long cellphoneNumber;
-
/**
* City
*/
/**
* Contact list
*/
- private final List<Contact> contactList;
+ private final List<Contact> contacts;
/**
* Country instance
private String emailAddress;
/**
- * Email address list
+ * Email address repeated
*/
- private final List<String> emailAddressList;
+ private String emailAddressRepeat;
/**
- * Email address repeated
+ * Email address list
*/
- private String emailAddressRepeat;
+ private final List<String> emailAddresses;
/**
* Family name
*/
private String houseNumberExtension;
- /**
- * Whether a cellphone entry has been unlinked
- */
- private boolean isMobileUnlinked;
-
/**
* Whether a fax entry has been unlinked
*/
private boolean isLandLineUnlinked;
/**
- * Phone number area code
+ * Whether a mobile entry has been unlinked
*/
- private Integer phoneAreaCode;
+ private boolean isMobileUnlinked;
/**
- * Country instance for phone number
+ * Land-line number area code
*/
- private Country phoneCountry;
+ private Integer landLineAreaCode;
/**
- * Phone number
+ * Country instance for land-line number
*/
- private Long phoneNumber;
+ private Country landLineCountry;
+
+ /**
+ * Land-line number
+ */
+ private Long landLineNumber;
+
+ /**
+ * Mobile number
+ */
+ private Long mobileNumber;
+
+ /**
+ * Mobile provider
+ */
+ private MobileProvider mobileProvider;
/**
* A list of all selectable contacts
private PizzaUserWebSessionController userController;
/**
- * Login bean (controller)
+ * Login controller (bean)
*/
@Inject
private PizzaUserLoginWebSessionController userLoginController;
Context context = new InitialContext();
// Try to lookup
- this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
+ this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jjobs-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
} catch (final NamingException e) {
// Throw again
throw new FaceletException(e);
}
// Init lists/maps
- this.contactList = new LinkedList<>();
- this.emailAddressList = new LinkedList<>();
+ this.contacts = new LinkedList<>();
+ this.emailAddresses = new LinkedList<>();
}
- @Override
- public void afterAdminAddedContact (@Observes final ObservableAdminAddedContactEvent event) {
- // Trace message
- /* NOISY-DEBUG: */ System.out.println(MessageFormat.format("contactController.afterAdminAddedContact(): event={0} - CALLED!", event)); //NOI18N
-
+ /**
+ * Observes events being fired when an administrator has added a new
+ * contact.
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) {
// The event must be valid
if (null == event) {
// Throw NPE
throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N
} else if (event.getAddedContact().getContactId() < 1) {
// Not valid
- throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N
+ throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N
}
// Clear this bean
this.selectableContacts.add(event.getAddedContact());
}
- @Override
+ /**
+ * Event observer for newly added users by adminstrator
+ * <p>
+ * @param event Event being fired
+ */
public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
// event should not be null
if (null == event) {
this.clear();
}
- @Override
- public void afterAdminLinkedUser (@Observes final ObservableAdminLinkedUserEvent event) {
+ /**
+ * Event observer for deleted contact instance by administrator
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterAdminDeletedContactEvent (@Observes final ObservableAdminDeletedContactEvent event) {
+ // event should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getDeletedContact() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.deletedContact is null"); //NOI18N
+ } else if (event.getDeletedContact().getContactId() == null) {
+ // userId is null
+ throw new NullPointerException("event.deletedContact.contactId is null"); //NOI18N
+ } else if (event.getDeletedContact().getContactId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getDeletedContact(), event.getDeletedContact().getContactId())); //NOI18N
+ }
+
+ // Remove from both lists
+ this.contacts.remove(event.getDeletedContact());
+ this.selectableContacts.remove(event.getDeletedContact());
+
+ // Clear all data
+ this.clear();
+ }
+
+ /**
+ * Observes events being fired when an administrator has linked a new user
+ * with existing contact data.
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterAdminLinkedUserEvent (@Observes final ObservableAdminLinkedUserEvent event) {
// event should not be null
if (null == event) {
// Throw NPE
this.clear();
}
- @Override
+ /**
+ * Event observer for updated contact data by administrators
+ * <p>
+ * @param event Updated contact data event
+ */
public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) {
// event should not be null
if (null == event) {
this.uniqueAddContact(event.getUpdatedContact());
// Add email address to list
- this.emailAddressList.add(event.getUpdatedContact().getContactEmailAddress());
+ this.emailAddresses.add(event.getUpdatedContact().getContactEmailAddress());
}
- @Override
- public void afterRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) {
+ /**
+ * Event observer for new user registrations
+ * <p>
+ * @param event User registration event
+ */
+ public void afterUserRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) {
// event should not be null
if (null == event) {
// Throw NPE
// Copy all data from registered->user
this.copyContact(registeredContact);
- // Add contact instance only once
- this.uniqueAddContact(registeredContact);
-
// Add user name and email address
this.addUserNameEmailAddress(registeredContact);
this.clear();
}
- @Override
+ /**
+ * Event observer for unlinked mobile contact by administrators
+ * <p>
+ * @param event Unlinked mobile contact event
+ */
+ public void afterAdminUnlinkedMobileContactDataEvent (@Observes final ObservableAdminUnlinkedMobileNumberEvent event) {
+ // event should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getUnlinkedMobileNumber() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.unlinkedMobileNumber is null"); //NOI18N
+ } else if (event.getUnlinkedMobileNumber().getPhoneId() == null) {
+ // userId is null
+ throw new NullPointerException("event.unlinkedMobileNumber.contactId is null"); //NOI18N
+ } else if (event.getUnlinkedMobileNumber().getPhoneId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedMobileNumber(), event.getUnlinkedMobileNumber().getPhoneId())); //NOI18N
+ }
+
+ // Remove it from list
+ this.removeFromContacts(event.getUnlinkedMobileNumber());
+
+ // Clear all data
+ this.clear();
+ }
+
+ /**
+ * Event observer when user confirmed account.
+ * <p>
+ * @param event Event being fired
+ */
public void afterUserConfirmedAccount (@Observes final ObservableUserConfirmedAccountEvent event) {
// event should not be null
if (null == event) {
this.uniqueAddContact(event.getConfirmedUser().getUserContact());
}
- @Override
+ /**
+ * Event observer for logged-in user
+ * <p>
+ * @param event Event instance
+ */
public void afterUserLoginEvent (@Observes final ObservableUserLoggedInEvent event) {
// event should not be null
if (null == event) {
@Override
@SuppressWarnings ("ReturnOfCollectionOrArrayField")
public List<Contact> allContacts () {
- // Debug message
- //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactController.allContacts: contactList.size()={0} - EXIT!", this.contactList.size()));
-
// Return un-modified list
- return this.contactList;
+ return this.contacts;
}
@Override
public Contact createContactInstance () {
- // User message
- //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: CALLED!", this.getClass().getSimpleName()));
-
// Is all required data set?
if (!this.isRequiredPersonalDataSet()) {
// No, then abort here
}
// Generate phone number
- DialableLandLineNumber landLineNumber = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
- DialableMobileNumber mobileNumber = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
- DialableFaxNumber faxNumber = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
+ DialableLandLineNumber phone = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
+ DialableMobileNumber mobile = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
+ DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
// Create new contact
Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
contact.setContactBirthday(this.getBirthday());
contact.setContactComment(this.getComment());
- // Debug message
- //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: this.emailAddress={1}", this.getClass().getSimpleName(), this.getEmailAddress()));
-
// Don't set null or wrong references
- if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
+ if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
// Now the number must be given
- if (landLineNumber.getPhoneAreaCode() == null) {
+ if (phone.getPhoneAreaCode() == null) {
// Is null
throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
- } else if (landLineNumber.getPhoneAreaCode() < 1) {
+ } else if (phone.getPhoneAreaCode() < 1) {
// Abort here
throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
- } else if (landLineNumber.getPhoneNumber() == null) {
+ } else if (phone.getPhoneNumber() == null) {
// Is null
throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
- } else if (landLineNumber.getPhoneNumber() < 1) {
+ } else if (phone.getPhoneNumber() < 1) {
// Abort here
throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
}
// Set phone number
- contact.setContactLandLineNumber(landLineNumber);
+ contact.setContactLandLineNumber(phone);
}
// Don't set null or wrong references
- if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
+ if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
// Now the number must be given
- if (faxNumber.getPhoneAreaCode() == null) {
+ if (fax.getPhoneAreaCode() == null) {
// Is null
throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
- } else if (faxNumber.getPhoneAreaCode() < 1) {
+ } else if (fax.getPhoneAreaCode() < 1) {
// Abort here
throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
- } else if (faxNumber.getPhoneNumber() == null) {
+ } else if (fax.getPhoneNumber() == null) {
// Is null
throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
- } else if (faxNumber.getPhoneNumber() < 1) {
+ } else if (fax.getPhoneNumber() < 1) {
// Abort here
throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
}
// Set fax number
- contact.setContactFaxNumber(faxNumber);
+ contact.setContactFaxNumber(fax);
}
// Is the provider set?
- if ((mobileNumber instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
+ if ((mobile instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
// Is the number set?
- if (mobileNumber.getPhoneNumber() == null) {
+ if (mobile.getPhoneNumber() == null) {
// Is null
- throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N
- } else if (mobileNumber.getPhoneNumber() < 1) {
+ throw new NullPointerException("mobileNumber.phoneNumber is null"); //NOI18N
+ } else if (mobile.getPhoneNumber() < 1) {
// Abort here
- throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N
+ throw new IllegalArgumentException("mobileNumber.phoneNumber is zero or below."); //NOI18N
}
- // Set cellphone number
- contact.setContactMobileNumber(mobileNumber);
+ // Set mobile number
+ contact.setContactMobileNumber(mobile);
}
- // Trace message
- //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: contact={1} - EXIT!", this.getClass().getSimpleName(), contact));
-
// Return it
return contact;
}
throw new FaceletException("Not all required fields are set."); //NOI18N
} else if (!this.userLoginController.ifCurrentPasswordMatches()) {
// Password not matching
- this.showFacesMessage("form_login_change_personal:currentPassword", new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); //NOI18N
+ this.showFacesMessage("form_login_change_personal:currentPassword", "ERROR_USER_CURRENT_PASSWORD_MISMATCHING"); //NOI18N
return ""; //NOI18N
}
contact.setContactCity(this.getCity());
contact.setContactCountry(this.getCountry());
- // Update contact's cellphone number
+ // Update contact's mobile number
this.isMobileUnlinked = ContactUtils.updateMobileNumber(contact, this.getMobileProvider(), this.getMobileNumber());
// Update contact's land-line number
- this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
+ this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
// Update contact's fax number
this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
this.contactBean.updateContactData(contact, this.isMobileUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
// All fine
- return "contact_data_saved"; //NOI18N
+ return "user_contact_data_saved"; //NOI18N
}
@Override
this.birthday = birthday;
}
- @Override
- public MobileProvider getMobileProvider () {
- return this.cellphoneCarrier;
- }
-
- @Override
- public void setMobileProvider (final MobileProvider mobileProvider) {
- this.cellphoneCarrier = mobileProvider;
- }
-
- @Override
- public Long getMobileNumber () {
- return this.cellphoneNumber;
- }
-
- @Override
- public void setMobileNumber (Long cellphoneNumber) {
- this.cellphoneNumber = cellphoneNumber;
- }
-
@Override
public String getCity () {
return this.city;
}
@Override
- public Integer getPhoneAreaCode () {
- return this.phoneAreaCode;
+ public Integer getLandLineAreaCode () {
+ return this.landLineAreaCode;
}
@Override
- public void setPhoneAreaCode (final Integer phoneAreaCode) {
- this.phoneAreaCode = phoneAreaCode;
+ public void setLandLineAreaCode (final Integer landLineAreaCode) {
+ this.landLineAreaCode = landLineAreaCode;
}
@Override
- public Country getPhoneCountry () {
- return this.phoneCountry;
+ public Country getLandLineCountry () {
+ return this.landLineCountry;
}
@Override
- public void setPhoneCountry (final Country phoneCountry) {
- this.phoneCountry = phoneCountry;
+ public void setLandLineCountry (final Country landLineCountry) {
+ this.landLineCountry = landLineCountry;
}
@Override
- public Long getPhoneNumber () {
- return this.phoneNumber;
+ public Long getLandLineNumber () {
+ return this.landLineNumber;
}
@Override
- public void setPhoneNumber (final Long phoneNumber) {
- this.phoneNumber = phoneNumber;
+ public void setLandLineNumber (final Long landLineNumber) {
+ this.landLineNumber = landLineNumber;
+ }
+
+ @Override
+ public Long getMobileNumber () {
+ return this.mobileNumber;
+ }
+
+ @Override
+ public void setMobileNumber (Long mobileNumber) {
+ this.mobileNumber = mobileNumber;
+ }
+
+ @Override
+ public MobileProvider getMobileProvider () {
+ return this.mobileProvider;
+ }
+
+ @Override
+ public void setMobileProvider (final MobileProvider mobileProvider) {
+ this.mobileProvider = mobileProvider;
}
@Override
@PostConstruct
public void init () {
// Get full email address list for reducing EJB calls
- this.emailAddressList.addAll(this.contactBean.getEmailAddressList());
+ this.emailAddresses.addAll(this.contactBean.getEmailAddressList());
+
+ // Get all contacts
+ List<Contact> allContacts = this.contactBean.getAllContacts();
// Get full contact list
- this.contactList.addAll(this.contactBean.getAllContacts());
+ this.contacts.addAll(allContacts);
// Get all users
List<User> allUsers = this.userController.allUsers();
- // Get all contacts
- List<Contact> allContacts = this.contactBean.getAllContacts();
-
// Get iterator
Iterator<Contact> iterator = allContacts.iterator();
}
// Determine it
- return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(contact.getContactEmailAddress())));
+ return ((this.emailAddresses instanceof List) && (this.emailAddresses.contains(contact.getContactEmailAddress())));
}
@Override
this.clear();
// Try to lookup it in visible user list
- for (final Iterator<Contact> iterator = this.contactList.iterator(); iterator.hasNext();) {
+ for (final Iterator<Contact> iterator = this.contacts.iterator(); iterator.hasNext();) {
// Get next user
Contact next = iterator.next();
return localContact;
}
+ /**
+ * Event observer when a list with unused mobile numbers is being created
+ * <p>
+ * @param event Event being fired
+ */
+ public void removeMobileNumberFromListEvent (@Observes final AdminRemoveMobileNumberFromListEvent event) {
+ // event should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getMobileNumberList() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.mobileList is null"); //NOI18N
+ } else if (event.getMobileNumberList().isEmpty()) {
+ // List is empty, no need to check
+ return;
+ }
+
+ // Check all entries
+ for (final Contact contact : this.contacts) {
+ // Is the mobile instance set and in list?
+ if ((contact.getContactMobileNumber() instanceof DialableMobileNumber) && (event.getMobileNumberList().contains(contact.getContactMobileNumber()))) {
+ // Found it, so remvoe it from list
+ event.getMobileNumberList().remove(contact.getContactMobileNumber());
+ }
+ }
+ }
+
@Override
public List<Contact> selectableContacts () {
return Collections.unmodifiableList(this.selectableContacts);
*/
private void addUserNameEmailAddress (final Contact contact) {
// Make sure the entry is not added yet
- if (this.emailAddressList.contains(contact.getContactEmailAddress())) {
+ if (this.emailAddresses.contains(contact.getContactEmailAddress())) {
// Already added
throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N
}
// Add email addres
- this.emailAddressList.add(contact.getContactEmailAddress());
+ this.emailAddresses.add(contact.getContactEmailAddress());
}
/**
// - contact data
this.setEmailAddress(null);
this.setEmailAddressRepeat(null);
- this.setPhoneAreaCode(null);
- this.setPhoneCountry(null);
- this.setPhoneNumber(null);
+ this.setLandLineAreaCode(null);
+ this.setLandLineCountry(null);
+ this.setLandLineNumber(null);
this.setMobileProvider(null);
this.setMobileNumber(null);
this.setFaxAreaCode(null);
this.setBirthday(contact.getContactBirthday());
this.setComment(contact.getContactComment());
- // Get cellphone, phone and fax instance
- DialableMobileNumber cellphone = contact.getContactMobileNumber();
+ // Get mobile, phone and fax instance
+ DialableMobileNumber mobile = contact.getContactMobileNumber();
DialableFaxNumber fax = contact.getContactFaxNumber();
DialableLandLineNumber phone = contact.getContactLandLineNumber();
// - contact data
if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) {
- this.setPhoneCountry(phone.getPhoneCountry());
- this.setPhoneAreaCode(phone.getPhoneAreaCode());
- this.setPhoneNumber(phone.getPhoneNumber());
+ this.setLandLineCountry(phone.getPhoneCountry());
+ this.setLandLineAreaCode(phone.getPhoneAreaCode());
+ this.setLandLineNumber(phone.getPhoneNumber());
}
- if ((cellphone instanceof DialableMobileNumber) && (cellphone.getMobileProvider() instanceof MobileProvider)) {
- this.setMobileProvider(cellphone.getMobileProvider());
- this.setMobileNumber(cellphone.getPhoneNumber());
+ if ((mobile instanceof DialableMobileNumber) && (mobile.getMobileProvider() instanceof MobileProvider)) {
+ this.setMobileProvider(mobile.getMobileProvider());
+ this.setMobileNumber(mobile.getPhoneNumber());
}
if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
}
// Remove from general list
- if (!this.contactList.remove(contact)) {
+ if (!this.contacts.remove(contact)) {
// Did not remove contact
throw new IllegalStateException(MessageFormat.format("contact {0} was not removed.", contact.getContactId())); //NOI18N
}
// Remove from other lists
- this.emailAddressList.remove(contact.getContactEmailAddress());
+ this.emailAddresses.remove(contact.getContactEmailAddress());
+ }
+
+ /**
+ * Removes given fax number from all contacts
+ * <p>
+ * @param faxNumber Fax number to remove
+ */
+ private void removeFromContacts (final DialableFaxNumber faxNumber) {
+ // Is it valid?
+ if (null == faxNumber) {
+ // Throw NPE
+ throw new NullPointerException("faxNumber is null"); //NOI18N
+ } else if (faxNumber.getPhoneId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N
+ } else if (faxNumber.getPhoneId() < 1) {
+ // Throw NPE again
+ throw new NullPointerException(MessageFormat.format("faxNumber.phoneId={0} is not valid", faxNumber.getPhoneId())); //NOI18N
+ }
+
+ // Loop through all contacts
+ for (final Contact contact : this.contacts) {
+ // Is the number set?
+ if (Objects.equals(contact.getContactFaxNumber(), faxNumber)) {
+ // Found it
+ contact.setContactFaxNumber(null);
+ }
+ }
+ }
+
+ /**
+ * Removes given land-line number from all contacts
+ * <p>
+ * @param landLineNumber Land-line number to remove
+ */
+ private void removeFromContacts (final DialableLandLineNumber landLineNumber) {
+ // Is it valid?
+ if (null == landLineNumber) {
+ // Throw NPE
+ throw new NullPointerException("landLineNumber is null"); //NOI18N
+ } else if (landLineNumber.getPhoneId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
+ } else if (landLineNumber.getPhoneId() < 1) {
+ // Throw NPE again
+ throw new NullPointerException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", landLineNumber.getPhoneId())); //NOI18N
+ }
+
+ // Loop through all contacts
+ for (final Contact contact : this.contacts) {
+ // Is the number set?
+ if (Objects.equals(contact.getContactLandLineNumber(), landLineNumber)) {
+ // Found it
+ contact.setContactLandLineNumber(null);
+ }
+ }
+ }
+
+ /**
+ * Removes given mobile number from all contacts
+ * <p>
+ * @param mobileNumber Mobile number to remove
+ */
+ private void removeFromContacts (final DialableMobileNumber mobileNumber) {
+ // Is it valid?
+ if (null == mobileNumber) {
+ // Throw NPE
+ throw new NullPointerException("mobileNumber is null"); //NOI18N
+ } else if (mobileNumber.getPhoneId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N
+ } else if (mobileNumber.getPhoneId() < 1) {
+ // Throw NPE again
+ throw new NullPointerException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", mobileNumber.getPhoneId())); //NOI18N
+ }
+
+ // Loop through all contacts
+ for (final Contact contact : this.contacts) {
+ // Is the number set?
+ if (Objects.equals(contact.getContactMobileNumber(), mobileNumber)) {
+ // Unset it
+ contact.setContactMobileNumber(null);
+ }
+ }
}
/**
}
// Get iterator from list
- Iterator<Contact> iterator = this.contactList.iterator();
+ Iterator<Contact> iterator = this.contacts.iterator();
// "Walk" through all entries
while (iterator.hasNext()) {
}
// Add contact to list
- this.contactList.add(contact);
+ this.contacts.add(contact);
}
}
import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
import org.mxchange.jcountry.data.Country;
import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
-import org.mxchange.jusercore.events.confirmation.ObservableUserConfirmedAccountEvent;
-import org.mxchange.jusercore.events.login.ObservableUserLoggedInEvent;
-import org.mxchange.jusercore.events.registration.ObservableUserRegisteredEvent;
-import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
-import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent;
-import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
-import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
/**
* An interface for user beans
@Local
public interface PizzaContactWebSessionController extends Serializable {
- /**
- * Minimum password length
- */
- public static final Integer MINIMUM_PASSWORD_LENGTH = 5;
-
/**
* Returns a list of all found contacts
* <p>
*/
List<Contact> allContacts ();
- /**
- * Event observer for newly added users by adminstrator
- * <p>
- * @param event Event being fired
- */
- void afterAdminAddedUserEvent (final ObservableAdminAddedUserEvent event);
-
- /**
- * Event observer when user confirmed account.
- * <p>
- * @param event Event being fired
- */
- void afterUserConfirmedAccount (final ObservableUserConfirmedAccountEvent event);
-
/**
* Updates all data from bean in given contact instance
* <p>
*/
Contact lookupContactById (final Long contactId) throws ContactNotFoundException;
- /**
- * Event observer for new user registrations
- * <p>
- * @param event User registration event
- */
- void afterRegistrationEvent (final ObservableUserRegisteredEvent event);
-
- /**
- * Observes events being fired when an administrator has added a new
- * contact.
- * <p>
- * @param event Event being fired
- */
- void afterAdminAddedContact (final ObservableAdminAddedContactEvent event);
-
- /**
- * Observes events being fired when an administrator has linked a new user
- * with existing contact data.
- * <p>
- * @param event Event being fired
- */
- void afterAdminLinkedUser (final ObservableAdminLinkedUserEvent event);
-
- /**
- * Event observer for updated contact data by administrators
- * <p>
- * @param event Updated contact data event
- */
- void afterAdminUpdatedContactDataEvent (final ObservableAdminUpdatedContactEvent event);
-
- /**
- * Event observer for logged-in user
- * <p>
- * @param event Event instance
- */
- void afterUserLoginEvent (final ObservableUserLoggedInEvent event);
-
/**
* Creates an instance from all properties
* <p>
void setBirthday (final Date birthday);
/**
- * Getter for mobile number's provider
+ * Getter for mobile provider
* <p>
- * @return Mobile number's provider
+ * @return Mobile provider
*/
MobileProvider getMobileProvider ();
/**
- * Setter for mobile number's provider
+ * Setter for mobile provider
* <p>
- * @param mobileProvider Mobile number's provider
+ * @param mobileProvider Mobile provider
*/
void setMobileProvider (final MobileProvider mobileProvider);
* <p>
* @return Phone number's area code
*/
- Integer getPhoneAreaCode ();
+ Integer getLandLineAreaCode ();
/**
* Setter for phone number's area code
* <p>
* @param phoneAreaCode Phone number's area code
*/
- void setPhoneAreaCode (final Integer phoneAreaCode);
+ void setLandLineAreaCode (final Integer phoneAreaCode);
/**
* Getter for phone number's country instance
* <p>
* @return Phone number's country instance
*/
- Country getPhoneCountry ();
+ Country getLandLineCountry ();
/**
* Setter for phone number's country instance
* <p>
* @param phoneCountry Phone number's country instance
*/
- void setPhoneCountry (final Country phoneCountry);
+ void setLandLineCountry (final Country phoneCountry);
/**
* Getter for phone number
* <p>
* @return Phone number
*/
- Long getPhoneNumber ();
+ Long getLandLineNumber ();
/**
* Setter for phone number
* <p>
* @param phoneNumber Phone number
*/
- void setPhoneNumber (final Long phoneNumber);
+ void setLandLineNumber (final Long phoneNumber);
/**
* Street
--- /dev/null
+/*
+ * Copyright (C) 2016 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.pizzaapplication.beans.contact.phone;
+
+import java.text.MessageFormat;
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.event.Event;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Any;
+import javax.faces.view.facelets.FaceletException;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import org.mxchange.jcontacts.contact.Contact;
+import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
+import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
+import org.mxchange.jcontacts.events.fax.linked.AdminLinkedFaxNumberEvent;
+import org.mxchange.jcontacts.events.fax.linked.ObservableAdminLinkedFaxNumberEvent;
+import org.mxchange.jcontacts.events.fax.unlinked.AdminUnlinkedFaxNumberEvent;
+import org.mxchange.jcontacts.events.fax.unlinked.ObservableAdminUnlinkedFaxNumberEvent;
+import org.mxchange.jcontacts.events.landline.linked.AdminLinkedLandLineNumberEvent;
+import org.mxchange.jcontacts.events.landline.linked.ObservableAdminLinkedLandLineNumberEvent;
+import org.mxchange.jcontacts.events.landline.unlinked.AdminUnlinkedLandLineNumberEvent;
+import org.mxchange.jcontacts.events.landline.unlinked.ObservableAdminUnlinkedLandLineNumberEvent;
+import org.mxchange.jcontacts.events.mobile.linked.AdminLinkedMobileNumberEvent;
+import org.mxchange.jcontacts.events.mobile.linked.ObservableAdminLinkedMobileNumberEvent;
+import org.mxchange.jcontacts.events.mobile.unlinked.AdminUnlinkedMobileNumberEvent;
+import org.mxchange.jcontacts.events.mobile.unlinked.ObservableAdminUnlinkedMobileNumberEvent;
+import org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote;
+import org.mxchange.jcountry.data.Country;
+import org.mxchange.jphone.exceptions.PhoneNumberAlreadyLinkedException;
+import org.mxchange.jphone.exceptions.PhoneNumberNotLinkedException;
+import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
+import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
+import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
+import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
+import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
+import org.mxchange.jphone.phonenumbers.mobile.MobileNumber;
+import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
+import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
+import org.mxchange.pizzaapplication.beans.BasePizzaController;
+import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestHelperController;
+import org.mxchange.pizzaapplication.beans.phone.PizzaAdminPhoneWebRequestController;
+
+/**
+ * An administrative contact phone controller (bean)
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("adminContactPhoneController")
+@RequestScoped
+public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaController implements PizzaAdminContactPhoneWebRequestController {
+
+ /**
+ * Call-stack instance (5 may show BeanELResolver.getValue as caller)
+ */
+ private static final short THREAD_STACK = 5;
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 542_145_347_916L;
+
+ /**
+ * Event being fired when a fax number has been linked
+ */
+ @Inject
+ @Any
+ private Event<ObservableAdminLinkedFaxNumberEvent> adminLinkedFaxNumberEvent;
+
+ /**
+ * Event being fired when a land-line number has been linked
+ */
+ @Inject
+ @Any
+ private Event<ObservableAdminLinkedLandLineNumberEvent> adminLinkedLandLineNumberEvent;
+
+ /**
+ * Event being fired when a mobile number has been linked
+ */
+ @Inject
+ @Any
+ private Event<ObservableAdminLinkedMobileNumberEvent> adminLinkedMobileNumberEvent;
+
+ /**
+ * Administrative EJB for phone number
+ */
+ private AdminContactsPhoneSessionBeanRemote adminPhoneBean;
+
+ /**
+ * Administrative phone controller
+ */
+ @Inject
+ private PizzaAdminPhoneWebRequestController adminPhoneController;
+
+ /**
+ * Bean helper
+ */
+ @Inject
+ private PizzaWebRequestHelperController beanHelper;
+
+ /**
+ * Event being fired when a fax number has been unlinked
+ */
+ @Inject
+ @Any
+ private Event<ObservableAdminUnlinkedFaxNumberEvent> faxNumberUnlinkedEvent;
+
+ /**
+ * Event being fired when a land-line number has been unlinked
+ */
+ @Inject
+ @Any
+ private Event<ObservableAdminUnlinkedLandLineNumberEvent> landLineNumberUnlinkedEvent;
+
+ /**
+ * Event being fired when admin unlinks mobile from contact
+ */
+ @Inject
+ @Any
+ private Event<ObservableAdminUnlinkedMobileNumberEvent> mobileNumberUnlinkedEvent;
+
+ /**
+ * Default constructor
+ */
+ public PizzaAdminContactPhoneWebRequestBean () {
+ // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[3].getClassName(), Thread.currentThread().getStackTrace()[3].getMethodName());
+ // System.out.println(MessageFormat.format("{0}: Constructed, caller: {1}", this.getClass().getSimpleName(), caller));
+
+ // Try it
+ try {
+ // Get initial context
+ Context context = new InitialContext();
+
+ // Try to lookup the beans
+ this.adminPhoneBean = (AdminContactsPhoneSessionBeanRemote) context.lookup("java:global/jjobs-ejb/adminContactPhone!org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote"); //NOI18N
+ } catch (final NamingException e) {
+ // Throw again
+ throw new FaceletException(e);
+ }
+ }
+
+ /**
+ * Observes events being fired when an administrator has added a new
+ * contact.
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) {
+ // The event must be valid
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getAddedContact() == null) {
+ // Throw again ...
+ throw new NullPointerException("event.addedContact is null"); //NOI18N
+ } else if (event.getAddedContact().getContactId() == null) {
+ // ... and again
+ throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N
+ } else if (event.getAddedContact().getContactId() < 1) {
+ // Not valid
+ throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N
+ }
+
+ // Clear this bean
+ this.clear();
+ }
+
+ /**
+ * Event observer for newly added users by administrator
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
+ // event should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getAddedUser() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.addedUser is null"); //NOI18N
+ } else if (event.getAddedUser().getUserId() == null) {
+ // userId is null
+ throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
+ } else if (event.getAddedUser().getUserId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
+ }
+
+ // Clear all data
+ this.clear();
+ }
+
+ /**
+ * Event observer for updated contact data by administrators
+ * <p>
+ * @param event Updated contact data event
+ */
+ public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) {
+ // event should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getUpdatedContact() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.updatedContact is null"); //NOI18N
+ } else if (event.getUpdatedContact().getContactId() == null) {
+ // userId is null
+ throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
+ } else if (event.getUpdatedContact().getContactId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
+ }
+
+ // Clear all data
+ this.clear();
+ }
+
+ @Override
+ public String doLinkAddFaxNumber (final Contact contact) {
+ // Is all data properly set?
+ if (null == contact) {
+ // Throw NPE
+ throw new NullPointerException("contact is null"); //NOI18N
+ } else if (contact.getContactId() == null) {
+ // Throw it again
+ throw new NullPointerException("contact.contactId is null"); //NOI18N
+ } else if (contact.getContactId() < 1) {
+ // Is not valid
+ throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
+ } else if ((this.adminPhoneController.getChoosenFaxNumber() == null) && (this.adminPhoneController.getPhoneCountry() == null) && ((this.adminPhoneController.getPhoneAreaCode() == null) || (this.adminPhoneController.getPhoneAreaCode() < 1)) && ((this.adminPhoneController.getPhoneNumber() == null) || (this.adminPhoneController.getPhoneNumber() < 1))) {
+ // All fields are empty
+ throw new NullPointerException("choosenFaxNumber, mobileProvider and phoneNumer are null"); //NOI18N
+ } else if ((this.adminPhoneController.getChoosenFaxNumber() instanceof DialableFaxNumber) && (this.adminPhoneController.getPhoneCountry() instanceof Country) && (this.adminPhoneController.getPhoneAreaCode() instanceof Integer) && (this.adminPhoneController.getPhoneNumber() instanceof Long)) {
+ // All fields are set
+ throw new IllegalStateException("choosenFaxNumber, mobileProvider and phoneNumer are all set"); //NOI18N
+ } else if ((this.adminPhoneController.getPhoneCountry() == null) && ((this.adminPhoneController.getPhoneAreaCode() instanceof Integer) || (this.adminPhoneController.getPhoneNumber() instanceof Long))) {
+ // No country selected
+ this.showFacesMessage("form_add_contact_fax:phoneCountry", "ERROR_ADMIN_NO_PHONE_COUNTRY_SELECTED"); //NOI18N
+ return ""; //NOI18N
+ } else if (((this.adminPhoneController.getPhoneAreaCode() == null) || (this.adminPhoneController.getPhoneAreaCode() < 1)) && ((this.adminPhoneController.getPhoneCountry() instanceof Country) || (this.adminPhoneController.getPhoneNumber() instanceof Long))) {
+ // No area code entered
+ this.showFacesMessage("form_add_contact_fax:phoneAreaCode", "ERROR_ADMIN_NO_PHONE_AREA_CODE_ENTERED"); //NOI18N
+ return ""; //NOI18N
+ } else if (((this.adminPhoneController.getPhoneNumber() == null) || (this.adminPhoneController.getPhoneNumber() < 1)) && ((this.adminPhoneController.getPhoneCountry() instanceof Country) || (this.adminPhoneController.getPhoneAreaCode() instanceof Integer))) {
+ // No phone number entered
+ this.showFacesMessage("form_add_contact_fax:phoneNumber", "ERROR_ADMIN_NO_PHONE_NUMBER_ENTERED"); //NOI18N
+ return ""; //NOI18N
+ }
+
+ // Init instances
+ Contact updatedContact;
+ DialableFaxNumber faxNumber = this.adminPhoneController.getChoosenFaxNumber();
+
+ // Try it again
+ try {
+ // All fine so far, then which was choosen?
+ if (faxNumber instanceof DialableFaxNumber) {
+ // User has choosen number
+ updatedContact = this.adminPhoneBean.linkExistingFaxNumberWithContact(contact, faxNumber);
+ } else {
+ // Create new instance
+ faxNumber = new FaxNumber(this.adminPhoneController.getPhoneCountry(), this.adminPhoneController.getPhoneAreaCode(), this.adminPhoneController.getPhoneNumber());
+
+ // Link it, too
+ updatedContact = this.adminPhoneBean.linkNewFaxNumberWithContact(contact, faxNumber);
+ }
+ } catch (final PhoneNumberAlreadyLinkedException ex) {
+ // Throw again as cause
+ this.showFacesMessage("form_add_contact_fax:phoneNumber", ex); //NOI18N
+ return ""; //NOI18N
+ }
+
+ // Fire event
+ this.adminLinkedFaxNumberEvent.fire(new AdminLinkedFaxNumberEvent(updatedContact, faxNumber));
+
+ // Return to contact profile
+ return "admin_show_contact"; //NOI18N
+ }
+
+ @Override
+ public String doLinkAddLandLineNumber (final Contact contact) {
+ // Is all data properly set?
+ if (null == contact) {
+ // Throw NPE
+ throw new NullPointerException("contact is null"); //NOI18N
+ } else if (contact.getContactId() == null) {
+ // Throw it again
+ throw new NullPointerException("contact.contactId is null"); //NOI18N
+ } else if (contact.getContactId() < 1) {
+ // Is not valid
+ throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
+ } else if ((this.adminPhoneController.getChoosenLandLineNumber() == null) && (this.adminPhoneController.getPhoneCountry() == null) && ((this.adminPhoneController.getPhoneAreaCode() == null) || (this.adminPhoneController.getPhoneAreaCode() < 1)) && ((this.adminPhoneController.getPhoneNumber() == null) || (this.adminPhoneController.getPhoneNumber() < 1))) {
+ // All fields are empty
+ throw new NullPointerException("choosenLandLineNumber, mobileProvider and phoneNumer are null"); //NOI18N
+ } else if ((this.adminPhoneController.getChoosenLandLineNumber() instanceof DialableLandLineNumber) && (this.adminPhoneController.getPhoneCountry() instanceof Country) && (this.adminPhoneController.getPhoneAreaCode() instanceof Integer) && (this.adminPhoneController.getPhoneNumber() instanceof Long)) {
+ // All fields are set
+ throw new IllegalStateException("choosenLandLineNumber, mobileProvider and phoneNumer are all set"); //NOI18N
+ } else if ((this.adminPhoneController.getPhoneCountry() == null) && ((this.adminPhoneController.getPhoneAreaCode() instanceof Integer) || (this.adminPhoneController.getPhoneNumber() instanceof Long))) {
+ // No country selected
+ this.showFacesMessage("form_add_contact_landLine:phoneCountry", "ERROR_ADMIN_NO_PHONE_COUNTRY_SELECTED"); //NOI18N
+ return ""; //NOI18N
+ } else if (((this.adminPhoneController.getPhoneAreaCode() == null) || (this.adminPhoneController.getPhoneAreaCode() < 1)) && ((this.adminPhoneController.getPhoneCountry() instanceof Country) || (this.adminPhoneController.getPhoneNumber() instanceof Long))) {
+ // No area code entered
+ this.showFacesMessage("form_add_contact_landLine:phoneAreaCode", "ERROR_ADMIN_NO_PHONE_AREA_CODE_ENTERED"); //NOI18N
+ return ""; //NOI18N
+ } else if (((this.adminPhoneController.getPhoneNumber() == null) || (this.adminPhoneController.getPhoneNumber() < 1)) && ((this.adminPhoneController.getPhoneCountry() instanceof Country) || (this.adminPhoneController.getPhoneAreaCode() instanceof Integer))) {
+ // No phone number entered
+ this.showFacesMessage("form_add_contact_landLine:phoneNumber", "ERROR_ADMIN_NO_PHONE_NUMBER_ENTERED"); //NOI18N
+ return ""; //NOI18N
+ }
+
+ // Init instance
+ Contact updatedContact;
+ DialableLandLineNumber landLineNumber = this.adminPhoneController.getChoosenLandLineNumber();
+
+ // Try it again
+ try {
+ // All fine so far, then which was choosen?
+ if (landLineNumber instanceof DialableLandLineNumber) {
+ // User has choosen number
+ updatedContact = this.adminPhoneBean.linkExistingLandLineNumberWithContact(contact, landLineNumber);
+ } else {
+ // Create new instance
+ landLineNumber = new LandLineNumber(this.adminPhoneController.getPhoneCountry(), this.adminPhoneController.getPhoneAreaCode(), this.adminPhoneController.getPhoneNumber());
+
+ // Link it, too
+ updatedContact = this.adminPhoneBean.linkNewLandLineNumberWithContact(contact, landLineNumber);
+ }
+ } catch (final PhoneNumberAlreadyLinkedException ex) {
+ // Throw again as cause
+ this.showFacesMessage("form_add_contact_landLine:phoneNumber", ex); //NOI18N
+ return ""; //NOI18N
+ }
+
+ // Fire event
+ this.adminLinkedLandLineNumberEvent.fire(new AdminLinkedLandLineNumberEvent(updatedContact, landLineNumber));
+
+ // Return to contact profile
+ return "admin_show_contact"; //NOI18N
+ }
+
+ @Override
+ public String doLinkAddMobileNumber (final Contact contact) {
+ // Is all data properly set?
+ if (null == contact) {
+ // Throw NPE
+ throw new NullPointerException("contact is null"); //NOI18N
+ } else if (contact.getContactId() == null) {
+ // Throw it again
+ throw new NullPointerException("contact.contactId is null"); //NOI18N
+ } else if (contact.getContactId() < 1) {
+ // Is not valid
+ throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
+ } else if ((this.adminPhoneController.getChoosenMobileNumber() == null) && (this.adminPhoneController.getMobileProvider() == null) && ((this.adminPhoneController.getPhoneNumber() == null) || (this.adminPhoneController.getPhoneNumber() < 1))) {
+ // All fields are empty
+ throw new NullPointerException("choosenMobileNumber, mobileProvider and phoneNumer are null"); //NOI18N
+ } else if ((this.adminPhoneController.getChoosenMobileNumber() instanceof DialableMobileNumber) && (this.adminPhoneController.getMobileProvider() instanceof MobileProvider) && (this.adminPhoneController.getPhoneNumber() instanceof Long)) {
+ // All fields are set
+ throw new IllegalStateException("choosenMobileNumber, mobileProvider and phoneNumer are all set"); //NOI18N
+ } else if ((this.adminPhoneController.getMobileProvider() == null) && (this.adminPhoneController.getPhoneNumber() instanceof Long)) {
+ // No mobile provider selected
+ this.showFacesMessage("form_add_contact_mobile:phoneCountry", "ERROR_ADMIN_NO_PHONE_MOBILE_PROVIDER_SELECTED"); //NOI18N
+ return ""; //NOI18N
+ } else if (((this.adminPhoneController.getPhoneNumber() == null) || (this.adminPhoneController.getPhoneNumber() < 1)) && (this.adminPhoneController.getMobileProvider() instanceof MobileProvider)) {
+ // No phone number entered
+ this.showFacesMessage("form_add_contact_mobile:phoneNumber", "ERROR_ADMIN_NO_PHONE_NUMBER_ENTERED"); //NOI18N
+ return ""; //NOI18N
+ }
+
+ // Init instance
+ Contact updatedContact;
+ DialableMobileNumber mobileNumber = this.adminPhoneController.getChoosenMobileNumber();
+
+ // Try it again
+ try {
+ // All fine so far, then which was choosen?
+ if (mobileNumber instanceof DialableMobileNumber) {
+ // User has choosen number
+ updatedContact = this.adminPhoneBean.linkExistingMobileNumberWithContact(contact, mobileNumber);
+ } else {
+ // Create new instance
+ mobileNumber = new MobileNumber(this.adminPhoneController.getMobileProvider(), this.adminPhoneController.getPhoneNumber());
+
+ // Link it, too
+ updatedContact = this.adminPhoneBean.linkNewMobileNumberWithContact(contact, mobileNumber);
+ }
+ } catch (final PhoneNumberAlreadyLinkedException ex) {
+ // Throw again as cause
+ this.showFacesMessage("form_add_contact_mobile:phoneNumber", ex); //NOI18N
+ return ""; //NOI18N
+ }
+
+ // Fire event
+ this.adminLinkedMobileNumberEvent.fire(new AdminLinkedMobileNumberEvent(updatedContact, mobileNumber));
+
+ // Return to contact profile
+ return "admin_show_contact"; //NOI18N
+ }
+
+ @Override
+ public String unlinkFaxContactData () {
+ // Is all data set
+ if (this.beanHelper.getFaxNumber() == null) {
+ // Not set, throw NPE
+ throw new NullPointerException("this.beanHelper.faxNumber is null"); //NOI18N
+ } else if (this.beanHelper.getFaxNumber().getPhoneId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.beanHelper.faxNumber.phoneId is null"); //NOI18N
+ } else if (this.beanHelper.getFaxNumber().getPhoneId() < 1) {
+ // Invalid number
+ throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.faxNumber.phoneId={0} is not valid", this.beanHelper.getFaxNumber().getPhoneId())); //NOI18N
+ } else if (this.beanHelper.getFaxNumber().getPhoneNumber() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.beanHelper.faxNumber.phoneNumber is null"); //NOI18N
+ } else if (this.beanHelper.getFaxNumber().getPhoneNumber() < 1) {
+ // Throw it again ...
+ throw new NullPointerException(MessageFormat.format("this.beanHelper.faxNumber.phoneNumber={0} is not valid.", this.beanHelper.getFaxNumber().getPhoneNumber())); //NOI18N
+ } else if (this.beanHelper.getContact() == null) {
+ // ... and throw again
+ throw new NullPointerException("this.beanHelper.contact is null"); //NOI18N
+ } else if (this.beanHelper.getContact().getContactId() == null) {
+ // ... and again ...
+ throw new NullPointerException("this.beanHelper.contact.contactId is null"); //NOI18N
+ } else if (this.beanHelper.getContact().getContactId() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.contact.contactId={0} is invalid.", this.beanHelper.getContact().getContactId())); //NOI18N
+ }
+
+ // Init contact instance
+ Contact updatedContact;
+
+ try {
+ // Unlink it and return contact without fax instance
+ updatedContact = this.adminPhoneBean.unlinkFaxDataFromContact(this.beanHelper.getContact(), this.beanHelper.getFaxNumber());
+ } catch (final PhoneNumberNotLinkedException ex) {
+ // Did not work
+ this.showFacesMessage("form_unlink_contact_fax:faxNumberId", ex); //NOI18N
+ return ""; //NOI18N
+ }
+
+ // Fire event
+ this.faxNumberUnlinkedEvent.fire(new AdminUnlinkedFaxNumberEvent(updatedContact, this.beanHelper.getFaxNumber()));
+
+ // All fine here
+ return "admin_show_contact"; //NOI18N
+ }
+
+ @Override
+ public String unlinkLandLineContactData () {
+ // Is all data set
+ if (this.beanHelper.getLandLineNumber() == null) {
+ // Not set, throw NPE
+ throw new NullPointerException("this.beanHelper.landLineNumber is null"); //NOI18N
+ } else if (this.beanHelper.getLandLineNumber().getPhoneId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.beanHelper.landLineNumber.phoneId is null"); //NOI18N
+ } else if (this.beanHelper.getLandLineNumber().getPhoneId() < 1) {
+ // Invalid number
+ throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.landLineNumber.phoneId={0} is not valid", this.beanHelper.getLandLineNumber().getPhoneId())); //NOI18N
+ } else if (this.beanHelper.getLandLineNumber().getPhoneNumber() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.beanHelper.landLineNumber.phoneNumber is null"); //NOI18N
+ } else if (this.beanHelper.getLandLineNumber().getPhoneNumber() < 1) {
+ // Throw it again ...
+ throw new NullPointerException(MessageFormat.format("this.beanHelper.landLineNumber.phoneNumber={0} is not valid.", this.beanHelper.getLandLineNumber().getPhoneNumber())); //NOI18N
+ } else if (this.beanHelper.getContact() == null) {
+ // ... and throw again
+ throw new NullPointerException("this.beanHelper.contact is null"); //NOI18N
+ } else if (this.beanHelper.getContact().getContactId() == null) {
+ // ... and again ...
+ throw new NullPointerException("this.beanHelper.contact.contactId is null"); //NOI18N
+ } else if (this.beanHelper.getContact().getContactId() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.contact.contactId={0} is invalid.", this.beanHelper.getContact().getContactId())); //NOI18N
+ }
+
+ // Init contact instance
+ Contact updatedContact;
+
+ try {
+ // Unlink it and return contact without landLine instance
+ updatedContact = this.adminPhoneBean.unlinkLandLineDataFromContact(this.beanHelper.getContact(), this.beanHelper.getLandLineNumber());
+ } catch (final PhoneNumberNotLinkedException ex) {
+ // Did not work
+ this.showFacesMessage("form_unlink_contact_landLine:landLineNumberId", ex); //NOI18N
+ return ""; //NOI18N
+ }
+
+ // Fire event
+ this.landLineNumberUnlinkedEvent.fire(new AdminUnlinkedLandLineNumberEvent(updatedContact, this.beanHelper.getLandLineNumber()));
+
+ // All fine here
+ return "admin_show_contact"; //NOI18N
+ }
+
+ @Override
+ public String unlinkMobileContactData () {
+ // Is all data set
+ if (this.beanHelper.getMobileNumber() == null) {
+ // Not set, throw NPE
+ throw new NullPointerException("this.beanHelper.mobileNumber is null"); //NOI18N
+ } else if (this.beanHelper.getMobileNumber().getPhoneId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.beanHelper.mobileNumber.phoneId is null"); //NOI18N
+ } else if (this.beanHelper.getMobileNumber().getPhoneId() < 1) {
+ // Invalid number
+ throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.mobileNumber.phoneId={0} is not valid", this.beanHelper.getMobileNumber().getPhoneId())); //NOI18N
+ } else if (this.beanHelper.getMobileNumber().getMobileProvider() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.beanHelper.mobileNumber.mobileProvider is null"); //NOI18N
+ } else if (this.beanHelper.getMobileNumber().getMobileProvider().getProviderId() == null) {
+ // ... throw again
+ throw new NullPointerException("this.beanHelper.mobileNumber.mobileProvider.providerId is null"); //NOI18N
+ } else if (this.beanHelper.getMobileNumber().getMobileProvider().getProviderId() < 1) {
+ // Id not valid
+ throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.mobileNumber.mobileProvider.providerId={0} is not valid.", this.beanHelper.getMobileNumber().getMobileProvider().getProviderId())); //NOI18N
+ } else if (this.beanHelper.getMobileNumber().getPhoneNumber() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.beanHelper.mobileNumber.phoneNumber is null"); //NOI18N
+ } else if (this.beanHelper.getMobileNumber().getPhoneNumber() < 1) {
+ // Throw it again ...
+ throw new NullPointerException(MessageFormat.format("this.beanHelper.mobileNumber.phoneNumber={0} is not valid.", this.beanHelper.getMobileNumber().getPhoneNumber())); //NOI18N
+ } else if (this.beanHelper.getContact() == null) {
+ // ... and throw again
+ throw new NullPointerException("this.beanHelper.contact is null"); //NOI18N
+ } else if (this.beanHelper.getContact().getContactId() == null) {
+ // ... and again ...
+ throw new NullPointerException("this.beanHelper.contact.contactId is null"); //NOI18N
+ } else if (this.beanHelper.getContact().getContactId() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.contact.contactId={0} is invalid.", this.beanHelper.getContact().getContactId())); //NOI18N
+ }
+
+ // Init contact instance
+ Contact updatedContact;
+
+ try {
+ // Unlink it and return contact without mobile instance
+ updatedContact = this.adminPhoneBean.unlinkMobileDataFromContact(this.beanHelper.getContact(), this.beanHelper.getMobileNumber());
+ } catch (final PhoneNumberNotLinkedException ex) {
+ // Did not work
+ this.showFacesMessage("form_unlink_contact_mobile:mobileNumberId", ex); //NOI18N
+ return ""; //NOI18N
+ }
+
+ // Fire event
+ this.mobileNumberUnlinkedEvent.fire(new AdminUnlinkedMobileNumberEvent(updatedContact, this.beanHelper.getMobileNumber()));
+
+ // All fine here
+ return "admin_show_contact"; //NOI18N
+ }
+
+ /**
+ * Clears this bean
+ */
+ private void clear () {
+ // Clear all data
+ }
+
+}
--- /dev/null
+
+/*
+ * Copyright (C) 2016 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.pizzaapplication.beans.contact.phone;
+
+import java.io.Serializable;
+import javax.ejb.Local;
+import org.mxchange.jcontacts.contact.Contact;
+
+/**
+ * An interface for user beans
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Local
+public interface PizzaAdminContactPhoneWebRequestController extends Serializable {
+
+ /**
+ * Unlinks fax data with current contact
+ * <p>
+ * @return Redirect outcome
+ */
+ String unlinkFaxContactData ();
+
+ /**
+ * Unlinks land-line data with current contact
+ * <p>
+ * @return Redirect outcome
+ */
+ String unlinkLandLineContactData ();
+
+ /**
+ * Unlinks mobile data with current contact
+ * <p>
+ * @return Redirect outcome
+ */
+ String unlinkMobileContactData ();
+
+ /**
+ * Links given contact instance with set fax number or entered data. If
+ * both is set, a proper exception is thrown as this is an invalid state.
+ * <p>
+ * @param contact Contact instance to link with existing/new data
+ * <p>
+ * @return Redirect outcome
+ */
+ String doLinkAddFaxNumber (final Contact contact);
+
+ /**
+ * Links given contact instance with set land-line number or entered
+ * data. If both is set, a proper exception is thrown as this is an invalid
+ * state.
+ * <p>
+ * @param contact Contact instance to link with existing/new data
+ * <p>
+ * @return Redirect outcome
+ */
+ String doLinkAddLandLineNumber (final Contact contact);
+
+ /**
+ * Links given contact instance with set mobile or entered data. If both
+ * is set, a proper exception is thrown as this is an invalid state.
+ * <p>
+ * @param contact Contact instance to link with existing/new data
+ * <p>
+ * @return Redirect outcome
+ */
+ String doLinkAddMobileNumber (final Contact contact);
+
+}
import java.util.Objects;
import javax.enterprise.context.SessionScoped;
import javax.enterprise.event.Observes;
-import javax.faces.view.facelets.FaceletException;
import javax.inject.Inject;
import javax.inject.Named;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
import org.mxchange.jcontacts.contact.Contact;
-import org.mxchange.jphone.phonenumbers.phone.AdminPhoneSessionBeanRemote;
-import org.mxchange.pizzaapplication.beans.BasePizzaController;
-import org.mxchange.pizzaapplication.beans.contact.PizzaContactWebSessionController;
-import org.mxchange.pizzaapplication.beans.phone.PizzaAdminPhoneWebRequestController;
-import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
+import org.mxchange.jcontacts.events.fax.unlinked.ObservableAdminUnlinkedFaxNumberEvent;
+import org.mxchange.jcontacts.events.landline.unlinked.ObservableAdminUnlinkedLandLineNumberEvent;
+import org.mxchange.jcontacts.events.mobile.unlinked.ObservableAdminUnlinkedMobileNumberEvent;
+import org.mxchange.jphone.phonenumbers.DialableNumber;
+import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
+import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
+import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
+import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
+import org.mxchange.pizzaapplication.beans.BasePizzaController;
+import org.mxchange.pizzaapplication.beans.contact.PizzaContactWebSessionController;
+import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestHelperController;
/**
* A general contact bean (controller)
private static final long serialVersionUID = 542_145_347_916L;
/**
- * Remote EJB for phone number (administrative)
- */
- private AdminPhoneSessionBeanRemote adminPhoneBean;
-
- /**
- * Administrative phone controller
+ * Bean helper
*/
@Inject
- private PizzaAdminPhoneWebRequestController adminPhoneController;
+ private PizzaWebRequestHelperController beanHelper;
/**
* General contact controller
private PizzaContactWebSessionController contactController;
/**
- * "Cache" for contact lists, mostly only one is assigned. So this cache
- * shouldn't grow beyond control.
+ * "Cache" for contact's mobile, land-line and fax numbers. Currently one
+ * per each type is supported. Maybe later this will change into a OneToMany
+ * relationship (one contact, many numbers).
*/
- private final Map<Long, List<Contact>> contacts;
+ private final Map<DialableNumber, List<Contact>> contacts;
/**
* Default constructor
*/
public PizzaContactPhoneWebSessionBean () {
- // Try it
- try {
- // Get initial context
- Context context = new InitialContext();
-
- // Try to lookup the beans
- this.adminPhoneBean = (AdminPhoneSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/adminphone!org.mxchange.jphone.phonenumbers.phone.AdminPhoneSessionBeanRemote"); //NOI18N
- } catch (final NamingException e) {
- // Throw again
- throw new FaceletException(e);
- }
-
// Init lists/maps
this.contacts = new HashMap<>(10);
}
- @Override
- public void afterAdminAddedContact (@Observes final ObservableAdminAddedContactEvent event) {
+ /**
+ * Observes events being fired when an administrator has added a new
+ * contact.
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) {
// The event must be valid
if (null == event) {
// Throw NPE
throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N
} else if (event.getAddedContact().getContactId() < 1) {
// Not valid
- throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N
+ throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N
}
// Clear this bean
this.clear();
}
- @Override
+ /**
+ * Event observer for newly added users by administrator
+ * <p>
+ * @param event Event being fired
+ */
public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
// event should not be null
if (null == event) {
this.clear();
}
- @Override
+ /**
+ * Event observer for unlinked fax contact by administrators
+ * <p>
+ * @param event Unlinked fax contact event
+ */
+ public void afterAdminUnlinkedFaxContactDataEvent (@Observes final ObservableAdminUnlinkedFaxNumberEvent event) {
+ // event should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getUnlinkedFaxNumber() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.unlinkedFaxNumber is null"); //NOI18N
+ } else if (event.getUnlinkedFaxNumber().getPhoneId() == null) {
+ // userId is null
+ throw new NullPointerException("event.unlinkedFaxNumber.contactId is null"); //NOI18N
+ } else if (event.getUnlinkedFaxNumber().getPhoneId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedFaxNumber(), event.getUnlinkedFaxNumber().getPhoneId())); //NOI18N
+ }
+
+ // Remove it from list
+ this.contacts.remove(event.getUnlinkedFaxNumber());
+
+ // Clear all data
+ this.clear();
+ }
+
+ /**
+ * Event observer for unlinked land-line contact by administrators
+ * <p>
+ * @param event Unlinked land-line contact event
+ */
+ public void afterAdminUnlinkedLandLineContactDataEvent (@Observes final ObservableAdminUnlinkedLandLineNumberEvent event) {
+ // event should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getUnlinkedLandLineNumber() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.unlinkedLandLineNumber is null"); //NOI18N
+ } else if (event.getUnlinkedLandLineNumber().getPhoneId() == null) {
+ // userId is null
+ throw new NullPointerException("event.unlinkedLandLineNumber.contactId is null"); //NOI18N
+ } else if (event.getUnlinkedLandLineNumber().getPhoneId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedLandLineNumber(), event.getUnlinkedLandLineNumber().getPhoneId())); //NOI18N
+ }
+
+ // Remove it from list
+ this.contacts.remove(event.getUnlinkedLandLineNumber());
+
+ // Clear all data
+ this.clear();
+ }
+
+ /**
+ * Event observer for unlinked mobile contact by administrators
+ * <p>
+ * @param event Unlinked mobile contact event
+ */
+ public void afterAdminUnlinkedMobileContactDataEvent (@Observes final ObservableAdminUnlinkedMobileNumberEvent event) {
+ // event should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getUnlinkedMobileNumber() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.unlinkedMobileNumber is null"); //NOI18N
+ } else if (event.getUnlinkedMobileNumber().getPhoneId() == null) {
+ // userId is null
+ throw new NullPointerException("event.unlinkedMobileNumber.contactId is null"); //NOI18N
+ } else if (event.getUnlinkedMobileNumber().getPhoneId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedMobileNumber(), event.getUnlinkedMobileNumber().getPhoneId())); //NOI18N
+ }
+
+ // Remove it from list
+ this.contacts.remove(event.getUnlinkedMobileNumber());
+
+ // Clear all data
+ this.clear();
+ }
+
+ /**
+ * Event observer for updated contact data by administrators
+ * <p>
+ * @param event Updated contact data event
+ */
public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) {
// event should not be null
if (null == event) {
// Not avalid id
throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
}
+
+ // Clear all data
+ this.clear();
+ }
+
+ @Override
+ public List<Contact> allFaxNumberContacts () {
+ // Get id
+ DialableFaxNumber faxNumber = this.beanHelper.getFaxNumber();
+
+ // Is cache there?
+ if (this.contacts.containsKey(faxNumber)) {
+ // Return cached version
+ return this.contacts.get(faxNumber);
+ } else {
+ // Ask bean
+ List<Contact> list = new LinkedList<>();
+
+ // "Walk" through all contacts
+ for (final Contact contact : this.contactController.allContacts()) {
+ // Is mobile instance the same?
+ if (Objects.equals(contact.getContactFaxNumber(), this.beanHelper.getFaxNumber())) {
+ // Found one
+ list.add(contact);
+ }
+ }
+
+ // Store result in cache
+ this.contacts.put(faxNumber, list);
+
+ // Return now-cached list
+ return list;
+ }
+ }
+
+ @Override
+ public List<Contact> allLandLineNumberContacts () {
+ // Get id
+ DialableLandLineNumber landLineNumber = this.beanHelper.getLandLineNumber();
+
+ // Is cache there?
+ if (this.contacts.containsKey(landLineNumber)) {
+ // Return cached version
+ return this.contacts.get(landLineNumber);
+ } else {
+ // Ask bean
+ List<Contact> list = new LinkedList<>();
+
+ // "Walk" through all contacts
+ for (final Contact contact : this.contactController.allContacts()) {
+ // Is mobile instance the same?
+ if (Objects.equals(contact.getContactLandLineNumber(), this.beanHelper.getLandLineNumber())) {
+ // Found one
+ list.add(contact);
+ }
+ }
+
+ // Store result in cache
+ this.contacts.put(landLineNumber, list);
+
+ // Return now-cached list
+ return list;
+ }
}
@Override
- public List<Contact> allMobileContacts () {
+ public List<Contact> allMobileNumberContacts () {
// Get id
- Long phoneId = this.adminPhoneController.getMobileNumber().getPhoneId();
+ DialableMobileNumber mobileNumber = this.beanHelper.getMobileNumber();
// Is cache there?
- if (this.contacts.containsKey(phoneId)) {
+ if (this.contacts.containsKey(mobileNumber)) {
// Return cached version
- return this.contacts.get(phoneId);
+ return this.contacts.get(mobileNumber);
} else {
// Ask bean
List<Contact> list = new LinkedList<>();
// "Walk" through all contacts
for (final Contact contact : this.contactController.allContacts()) {
- // Is cellphone instance the same?
- if (Objects.equals(contact.getContactMobileNumber(), this.adminPhoneController.getMobileNumber())) {
+ // Is mobile instance the same?
+ if (Objects.equals(contact.getContactMobileNumber(), this.beanHelper.getMobileNumber())) {
// Found one
list.add(contact);
}
}
// Store result in cache
- this.contacts.put(phoneId, list);
+ this.contacts.put(mobileNumber, list);
// Return now-cached list
return list;
import java.util.List;
import javax.ejb.Local;
import org.mxchange.jcontacts.contact.Contact;
-import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
-import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
-import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
/**
* An interface for user beans
public interface PizzaContactPhoneWebSessionController extends Serializable {
/**
- * Minimum password length
- */
- public static final Integer MINIMUM_PASSWORD_LENGTH = 5;
-
- /**
- * Getter for all contacts having current cellphone instance linked
+ * Getter for all contacts having current fax number linked
* <p>
* @return List of all linked contacts
*/
- List<Contact> allMobileContacts ();
+ List<Contact> allFaxNumberContacts ();
/**
- * Event observer for newly added users by adminstrator
+ * Getter for all contacts having current land-line number linked
* <p>
- * @param event Event being fired
- */
- void afterAdminAddedUserEvent (final ObservableAdminAddedUserEvent event);
-
- /**
- * Observes events being fired when an administrator has added a new
- * contact.
- * <p>
- * @param event Event being fired
+ * @return List of all linked contacts
*/
- void afterAdminAddedContact (final ObservableAdminAddedContactEvent event);
+ List<Contact> allLandLineNumberContacts ();
/**
- * Event observer for updated contact data by administrators
+ * Getter for all contacts having current mobile number linked
* <p>
- * @param event Updated contact data event
+ * @return List of all linked contacts
*/
- void afterAdminUpdatedContactDataEvent (final ObservableAdminUpdatedContactEvent event);
+ List<Contact> allMobileNumberContacts ();
}
import javax.naming.NamingException;
import org.mxchange.jcountry.data.Country;
import org.mxchange.jcountry.data.CountrySingletonBeanRemote;
-import org.mxchange.pizzaapplication.beans.BasePizzaController;
import org.mxchange.jcountry.events.ObservableAdminAddedCountryEvent;
+import org.mxchange.pizzaapplication.beans.BasePizzaController;
/**
* A country bean
}
}
- @Override
- public void afterAdminAddedCountry (@Observes final ObservableAdminAddedCountryEvent event) {
+ /**
+ * Observing method when the event is fired that an administrator added a
+ * new country
+ * <p>
+ * @param event Event instance
+ */
+ public void afterAdminAddedCountryEvent (@Observes final ObservableAdminAddedCountryEvent event) {
// Is all valid?
if (null == event) {
// Throw NPE
import java.io.Serializable;
import java.util.List;
import org.mxchange.jcountry.data.Country;
-import org.mxchange.jcountry.events.ObservableAdminAddedCountryEvent;
/**
* An interface for country beans
*/
List<Country> allCountries ();
- /**
- * Observing method when the event is fired that an administrator added a
- * new country
- * <p>
- * @param event Event instance
- */
- void afterAdminAddedCountry (final ObservableAdminAddedCountryEvent event);
-
}
import org.mxchange.pizzaapplication.beans.contact.PizzaAdminContactWebRequestController;
import org.mxchange.pizzaapplication.model.customer.PizzaAdminCustomerSessionBeanRemote;
import org.mxchange.pizzaapplication.model.customer.PizzaCustomer;
-import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestController;
import org.mxchange.jcustomercore.events.customer.added.ObservableAdminAddedCustomerEvent;
+import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestHelperController;
/**
* Administrative customer bean (controller)
* Bean helper instance
*/
@Inject
- private PizzaWebRequestController adminHelper;
+ private PizzaWebRequestHelperController adminHelper;
/**
* An event being fired when an administrator has added a new customer
+++ /dev/null
-/*
- * Copyright (C) 2016 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.pizzaapplication.beans.helper;
-
-import java.io.Serializable;
-import org.mxchange.jcontacts.contact.Contact;
-import org.mxchange.jcustomercore.model.customer.Customer;
-import org.mxchange.jusercore.model.user.User;
-
-/**
- * An interface for general bean helper
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public interface PizzaWebRequestController extends Serializable {
-
- /**
- * Getter for user instance
- * <p>
- * @return User instance
- */
- User getUser ();
-
- /**
- * Setter for user instance
- * <p>
- * @param user User instance
- */
- void setUser (final User user);
-
- /**
- * Copies currently set user instance's data to adminUserController
- */
- void copyUserToController ();
-
- /**
- * Returns a message key depending on if this contact is a user and/or a
- * contact. If this contact is unused, a default key is returned.
- * <p>
- * @param contact Contact instance to check
- * <p>
- * @return Message key
- */
- String getContactUsageMessageKey (final Contact contact);
-
- /**
- * Getter for contact instance
- * <p>
- * @return Contact instance
- */
- Contact getContact ();
-
- /**
- * Setter for contact instance
- * <p>
- * @param contact Contact instance
- */
- void setContact (final Contact contact);
-
- /**
- * Getter for customer instance
- * <p>
- * @return Customer instance
- */
- Customer getCustomer ();
-
- /**
- * Setter for customer instance
- * <p>
- * @param customer Contact instance
- */
- void setCustomer (final Customer customer);
-
- /**
- * Copies currently set contact instance's data to adminContactController
- */
- void copyContactToController ();
-
- /**
- * Copies currently set customer instance's data to adminCustomerController
- */
- void copyCustomerToController ();
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2016 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.pizzaapplication.beans.helper;
-
-import java.text.MessageFormat;
-import javax.enterprise.context.RequestScoped;
-import javax.inject.Inject;
-import javax.inject.Named;
-import org.mxchange.jcontacts.contact.Contact;
-import org.mxchange.jcustomercore.model.customer.Customer;
-import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
-import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
-import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
-import org.mxchange.jusercore.model.user.User;
-import org.mxchange.pizzaapplication.beans.contact.PizzaAdminContactWebRequestController;
-import org.mxchange.pizzaapplication.beans.customer.PizzaAdminCustomerWebRequestController;
-import org.mxchange.pizzaapplication.beans.customer.PizzaCustomerWebSessionController;
-import org.mxchange.pizzaapplication.beans.phone.PizzaAdminPhoneWebRequestController;
-import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController;
-
-/**
- * A general helper for beans
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Named ("beanHelper")
-@RequestScoped
-public class PizzaWebRequestHelper implements PizzaWebRequestController {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 17_258_793_567_145_701L;
-
- /**
- * Administrative contact controller
- */
- @Inject
- private PizzaAdminContactWebRequestController adminContactController;
-
- /**
- * Administrative user controller
- */
- @Inject
- private PizzaAdminCustomerWebRequestController adminCustomerController;
-
- /**
- * Administrative phone controller
- */
- @Inject
- private PizzaAdminPhoneWebRequestController adminPhoneController;
-
- /**
- * Contact instance
- */
- private Contact contact;
-
- /**
- * Contact instance
- */
- private Customer customer;
-
- /**
- * General user controller
- */
- @Inject
- private PizzaCustomerWebSessionController customerController;
-
- /**
- * User instance
- */
- private User user;
-
- /**
- * Regular user controller
- */
- @Inject
- private PizzaUserWebSessionController userController;
-
- /**
- * Default constructor
- */
- public PizzaWebRequestHelper () {
- }
-
- @Override
- public void copyContactToController () {
- // Validate user instance
- if (this.getContact() == null) {
- // Throw NPE
- throw new NullPointerException("this.contact is null"); //NOI18N
- } else if (this.getContact().getContactId() == null) {
- // Throw NPE again
- throw new NullPointerException("this.contact.contactId is null"); //NOI18N
- } else if (this.getContact().getContactId() < 1) {
- // Not valid
- throw new IllegalStateException(MessageFormat.format("this.contact.contactId={0} is not valid.", this.getContact().getContactId())); //NOI18N
- }
-
- // Set all phone instances
- this.setPhoneInstances(this.getContact());
-
- // Set all fields: user
- this.adminContactController.copyContactToController(this.getContact());
- }
-
- @Override
- public void copyCustomerToController () {
- // Log message
- //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyCustomerToController - CALLED!"); //NOI18N
-
- // Validate user instance
- if (this.getCustomer() == null) {
- // Throw NPE
- throw new NullPointerException("this.customer is null"); //NOI18N
- } else if (this.getCustomer().getCustomerId() == null) {
- // Throw NPE again
- throw new NullPointerException("this.customer.customerId is null"); //NOI18N
- } else if (this.getCustomer().getCustomerId() < 1) {
- // Not valid
- throw new IllegalStateException(MessageFormat.format("this.customer.customerId={0} is not valid.", this.getCustomer().getCustomerId())); //NOI18N
- }
-
- // Set all fields: user
- this.adminCustomerController.copyCustomerToController(this.getCustomer());
-
- // Log message
- //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyCustomerToController - EXIT!"); //NOI18N
- }
-
- @Override
- public void copyUserToController () {
- // Validate user instance
- if (this.getUser() == null) {
- // Throw NPE
- throw new NullPointerException("this.user is null"); //NOI18N
- } else if (this.getUser().getUserId() == null) {
- // Throw NPE again
- throw new NullPointerException("this.user.userId is null"); //NOI18N
- } else if (this.getUser().getUserId() < 1) {
- // Not valid
- throw new IllegalStateException(MessageFormat.format("this.user.userId={0} is not valid.", this.getUser().getUserId())); //NOI18N
- }
-
- // Get contact
- Contact userContact = this.getUser().getUserContact();
-
- // Set contact here, too. This avoids parameters that cannot auto-complete in IDEs.
- this.setContact(userContact);
-
- // Set all phone instances
- this.setPhoneInstances(userContact);
-
- // Set all fields: user
- this.userController.setUserName(this.getUser().getUserName());
- }
-
- @Override
- public Contact getContact () {
- return this.contact;
- }
-
- @Override
- public void setContact (final Contact contact) {
- this.contact = contact;
- }
-
- @Override
- public String getContactUsageMessageKey (final Contact contact) {
- // The contact must be valid
- if (null == contact) {
- // Throw NPE
- throw new NullPointerException("contact is null"); //NOI18N
- } else if (contact.getContactId() == null) {
- // Throw again ...
- throw new NullPointerException("contact.contactId is null"); //NOI18N
- } else if (contact.getContactId() < 1) {
- // Not valid
- throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
- }
-
- // Default key is "unused"
- String messageKey = "CONTACT_IS_UNUSED"; //NOI18N
-
- // Check user/customer
- boolean isUserContact = this.userController.isContactFound(contact);
- boolean isCustomerContact = this.customerController.isContactFound(contact);
-
- // Check user first
- if (isUserContact && isCustomerContact) {
- // Is both
- messageKey = "CONTACT_IS_USER_USER"; //NOI18N
- } else if (isUserContact) {
- // Only user
- messageKey = "CONTACT_IS_USER"; //NOI18N
- } else if (isCustomerContact) {
- // Only customer
- messageKey = "CONTACT_IS_USER"; //NOI18N
- }
-
- // Return message key
- return messageKey;
- }
-
- @Override
- public Customer getCustomer () {
- return this.customer;
- }
-
- @Override
- public void setCustomer (final Customer customer) {
- this.customer = customer;
- }
-
- @Override
- public User getUser () {
- return this.user;
- }
-
- @Override
- public void setUser (final User user) {
- this.user = user;
- }
-
- /**
- * Set's all given contact's phone instances: land-line, cellphone and fax
- * <p>
- * @param contact Contact to set phone instances for
- */
- private void setPhoneInstances (final Contact contact) {
- // The contact must be valid
- if (null == contact) {
- // Throw NPE
- throw new NullPointerException("contact is null"); //NOI18N
- } else if (contact.getContactId() == null) {
- // Throw again ...
- throw new NullPointerException("contact.contactId is null"); //NOI18N
- } else if (contact.getContactId() < 1) {
- // Not valid
- throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
- }
-
- // Is cellphone set?
- if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
- // Yes, then set it in admin controller
- this.adminPhoneController.setMobileNumber(contact.getContactMobileNumber());
- }
-
- // Is land-line set?
- if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
- // Yes, then set it in admin controller
- this.adminPhoneController.setLandLineNumber(contact.getContactLandLineNumber());
- }
-
- // Is fax set?
- if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
- // Yes, then set it in admin controller
- this.adminPhoneController.setFaxNumber(contact.getContactFaxNumber());
- }
- }
-
-}
--- /dev/null
+/*
+ * Copyright (C) 2016 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.pizzaapplication.beans.helper;
+
+import java.text.MessageFormat;
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.inject.Named;
+import org.mxchange.jcontacts.contact.Contact;
+import org.mxchange.jcustomercore.model.customer.Customer;
+import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
+import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
+import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
+import org.mxchange.jusercore.model.user.User;
+import org.mxchange.pizzaapplication.beans.contact.PizzaAdminContactWebRequestController;
+import org.mxchange.pizzaapplication.beans.customer.PizzaAdminCustomerWebRequestController;
+import org.mxchange.pizzaapplication.beans.customer.PizzaCustomerWebSessionController;
+import org.mxchange.pizzaapplication.beans.phone.PizzaAdminPhoneWebRequestController;
+import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController;
+
+/**
+ * A general helper for beans
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("beanHelper")
+@RequestScoped
+public class PizzaWebRequestHelperBean implements PizzaWebRequestHelperController {
+
+ /**
+ * Call-stack instance (5 may show BeanELResolver.getValue as caller)
+ */
+ private static final short THREAD_STACK = 5;
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 17_258_793_567_145_701L;
+
+ /**
+ * Administrative contact controller
+ */
+ @Inject
+ private PizzaAdminContactWebRequestController adminContactController;
+
+ /**
+ * Administrative user controller
+ */
+ @Inject
+ private PizzaAdminCustomerWebRequestController adminCustomerController;
+
+ /**
+ * Administrative phone controller
+ */
+ @Inject
+ private PizzaAdminPhoneWebRequestController adminPhoneController;
+
+ /**
+ * Contact instance
+ */
+ private Contact contact;
+
+ /**
+ * Contact instance
+ */
+ private Customer customer;
+
+ /**
+ * General user controller
+ */
+ @Inject
+ private PizzaCustomerWebSessionController customerController;
+
+ /**
+ * Fax number
+ */
+ private DialableFaxNumber faxNumber;
+
+ /**
+ * Land-line number
+ */
+ private DialableLandLineNumber landLineNumber;
+
+ /**
+ * Mobile number
+ */
+ private DialableMobileNumber mobileNumber;
+
+ /**
+ * User instance
+ */
+ private User user;
+
+ /**
+ * Regular user controller
+ */
+ @Inject
+ private PizzaUserWebSessionController userController;
+
+ /**
+ * Default constructor
+ */
+ public PizzaWebRequestHelperBean () {
+ // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[3].getClassName(), Thread.currentThread().getStackTrace()[3].getMethodName());
+ // System.out.println(MessageFormat.format("{0}: Constructed, caller: {1}", this.getClass().getSimpleName(), caller));
+ }
+
+ @Override
+ public void copyContactToController () {
+ // Validate user instance
+ if (this.getContact() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.contact is null"); //NOI18N
+ } else if (this.getContact().getContactId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.contact.contactId is null"); //NOI18N
+ } else if (this.getContact().getContactId() < 1) {
+ // Not valid
+ throw new IllegalStateException(MessageFormat.format("this.contact.contactId={0} is not valid.", this.getContact().getContactId())); //NOI18N
+ }
+
+ // Set all phone instances
+ this.setPhoneInstances(this.getContact());
+
+ // Set all fields: user
+ this.adminContactController.copyContactToController(this.getContact());
+ }
+
+ @Override
+ public void copyCustomerToController () {
+ // Validate user instance
+ if (this.getCustomer() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.customer is null"); //NOI18N
+ } else if (this.getCustomer().getCustomerId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.customer.customerId is null"); //NOI18N
+ } else if (this.getCustomer().getCustomerId() < 1) {
+ // Not valid
+ throw new IllegalStateException(MessageFormat.format("this.customer.customerId={0} is not valid.", this.getCustomer().getCustomerId())); //NOI18N
+ }
+
+ // Set all fields: user
+ this.adminCustomerController.copyCustomerToController(this.getCustomer());
+ }
+
+ @Override
+ public void copyFaxNumberToController () {
+ // Validate fax instance
+ if (this.getFaxNumber() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.faxNumber is null");
+ } else if (this.getFaxNumber().getPhoneId() == null) {
+ // Throw again
+ throw new NullPointerException("this.faxNumber.phoneId is null");
+ } else if (this.getFaxNumber().getPhoneId() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("this.faxNumber.phoneId={0} is not valid", this.getFaxNumber().getPhoneId()));
+ } else if (this.getFaxNumber().getPhoneAreaCode() == null) {
+ // Throw again
+ throw new NullPointerException("this.faxNumber.phoneAreaCode is null");
+ } else if (this.getFaxNumber().getPhoneAreaCode() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("this.faxNumber.phoneAreaCode={0} is not valid", this.getFaxNumber().getPhoneAreaCode()));
+ } else if (this.getFaxNumber().getPhoneCountry() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.faxNumber.phoneCountry is null");
+ } else if (this.getFaxNumber().getPhoneCountry().getCountryId() == null) {
+ // ... throw again
+ throw new NullPointerException("this.faxNumber.phoneCountry.countryId is null");
+ } else if (this.getFaxNumber().getPhoneCountry().getCountryId() < 1) {
+ // Invalid id
+ throw new IllegalArgumentException(MessageFormat.format("this.faxNumber.phoneCountry.countryId={0} is invalid", this.getFaxNumber().getPhoneCountry().getCountryId()));
+ } else if (this.getFaxNumber().getPhoneNumber() == null) {
+ // Throw NPE again ...
+ throw new NullPointerException("this.faxNumber.phoneNumber is null");
+ } else if (this.getFaxNumber().getPhoneNumber() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("this.faxNumber.phoneNumber={0} is not valid", this.getFaxNumber().getPhoneNumber()));
+ }
+
+ // Copy all (changeable) data fields to admin controller
+ this.adminPhoneController.setPhoneAreaCode(this.getFaxNumber().getPhoneAreaCode());
+ this.adminPhoneController.setPhoneCountry(this.getFaxNumber().getPhoneCountry());
+ this.adminPhoneController.setPhoneNumber(this.getFaxNumber().getPhoneNumber());
+ }
+
+ @Override
+ public void copyLandLineNumberToController () {
+ // Validate land-line instance
+ if (this.getLandLineNumber() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.landLineNumber is null");
+ } else if (this.getLandLineNumber().getPhoneId() == null) {
+ // Throw again
+ throw new NullPointerException("this.landLineNumber.phoneId is null");
+ } else if (this.getLandLineNumber().getPhoneId() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber.phoneId={0} is not valid", this.getLandLineNumber().getPhoneId()));
+ } else if (this.getLandLineNumber().getPhoneAreaCode() == null) {
+ // Throw again
+ throw new NullPointerException("this.landLineNumber.phoneAreaCode is null");
+ } else if (this.getLandLineNumber().getPhoneAreaCode() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber.phoneAreaCode={0} is not valid", this.getFaxNumber().getPhoneAreaCode()));
+ } else if (this.getLandLineNumber().getPhoneCountry() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.landLineNumber.phoneCountry is null");
+ } else if (this.getLandLineNumber().getPhoneCountry().getCountryId() == null) {
+ // ... throw again
+ throw new NullPointerException("this.landLineNumber.phoneCountry.countryId is null");
+ } else if (this.getLandLineNumber().getPhoneCountry().getCountryId() < 1) {
+ // Invalid id
+ throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber.phoneCountry.countryId={0} is invalid", this.getLandLineNumber().getPhoneCountry().getCountryId()));
+ } else if (this.getLandLineNumber().getPhoneNumber() == null) {
+ // Throw NPE again ...
+ throw new NullPointerException("this.landLineNumber.phoneNumber is null");
+ } else if (this.getLandLineNumber().getPhoneNumber() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber.phoneNumber={0} is not valid", this.getLandLineNumber().getPhoneNumber()));
+ }
+
+ // Copy all (changeable) data fields to admin controller
+ this.adminPhoneController.setPhoneAreaCode(this.getLandLineNumber().getPhoneAreaCode());
+ this.adminPhoneController.setPhoneCountry(this.getLandLineNumber().getPhoneCountry());
+ this.adminPhoneController.setPhoneNumber(this.getLandLineNumber().getPhoneNumber());
+ }
+
+ @Override
+ public void copyMobileNumberToController () {
+ // Validate mobile instance
+ if (this.getMobileNumber() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.mobileNumber is null");
+ } else if (this.getMobileNumber().getPhoneId() == null) {
+ // Throw again
+ throw new NullPointerException("this.mobileNumber.phoneId is null");
+ } else if (this.getMobileNumber().getPhoneId() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber.phoneId={0} is not valid", this.getMobileNumber().getPhoneId()));
+ } else if (this.getMobileNumber().getMobileProvider() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.mobileNumber.mobileProvider is null");
+ } else if (this.getMobileNumber().getMobileProvider().getProviderId() == null) {
+ // ... throw again
+ throw new NullPointerException("this.mobileNumber.mobileProvider.providerId is null");
+ } else if (this.getMobileNumber().getMobileProvider().getProviderId() < 1) {
+ // Invalid id
+ throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber.mobileProvider.providerId={0} is invalid", this.getMobileNumber().getMobileProvider().getProviderId()));
+ } else if (this.getMobileNumber().getPhoneNumber() == null) {
+ // Throw NPE again ...
+ throw new NullPointerException("this.mobileNumber.phoneNumber is null");
+ } else if (this.getMobileNumber().getPhoneNumber() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber.phoneNumber={0} is not valid", this.getMobileNumber().getPhoneNumber()));
+ }
+
+ // Copy all (changeable) data fields to admin controller
+ this.adminPhoneController.setMobileProvider(this.getMobileNumber().getMobileProvider());
+ this.adminPhoneController.setPhoneNumber(this.getMobileNumber().getPhoneNumber());
+ }
+
+ @Override
+ public void copyUserToController () {
+ // Validate user instance
+ if (this.getUser() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.user is null"); //NOI18N
+ } else if (this.getUser().getUserId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.user.userId is null"); //NOI18N
+ } else if (this.getUser().getUserId() < 1) {
+ // Not valid
+ throw new IllegalStateException(MessageFormat.format("this.user.userId={0} is not valid.", this.getUser().getUserId())); //NOI18N
+ }
+
+ // Get contact
+ Contact userContact = this.getUser().getUserContact();
+
+ // Set contact here, too. This avoids parameters that cannot auto-complete in IDEs.
+ this.setContact(userContact);
+
+ // Set all phone instances
+ this.setPhoneInstances(userContact);
+
+ // Set all fields: user
+ this.userController.setUserName(this.getUser().getUserName());
+ }
+
+ @Override
+ public Contact getContact () {
+ // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[THREAD_STACK].getClassName(), Thread.currentThread().getStackTrace()[THREAD_STACK].getMethodName());
+ // System.out.println(MessageFormat.format("{0}: Returning this.contact={1}, caller: {2}", this.getClass().getSimpleName(), this.contact, caller));
+ return this.contact;
+ }
+
+ @Override
+ public void setContact (final Contact contact) {
+ // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[THREAD_STACK].getClassName(), Thread.currentThread().getStackTrace()[THREAD_STACK].getMethodName());
+ // System.out.println(MessageFormat.format("{0}: Setting contact={1}, previous: {2}, caller: {3}", this.getClass().getSimpleName(), contact, this.contact, caller));
+ this.contact = contact;
+ }
+
+ @Override
+ public String getContactUsageMessageKey (final Contact contact) {
+ // The contact must be valid
+ if (null == contact) {
+ // Throw NPE
+ throw new NullPointerException("contact is null"); //NOI18N
+ } else if (contact.getContactId() == null) {
+ // Throw again ...
+ throw new NullPointerException("contact.contactId is null"); //NOI18N
+ } else if (contact.getContactId() < 1) {
+ // Not valid
+ throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
+ }
+
+ // Default key is "unused"
+ String messageKey = "CONTACT_IS_UNUSED"; //NOI18N
+
+ // Check user/customer
+ boolean isUserContact = this.userController.isContactFound(contact);
+ boolean isCustomerContact = this.customerController.isContactFound(contact);
+
+ // Check user first
+ if (isUserContact && isCustomerContact) {
+ // Is both
+ messageKey = "CONTACT_IS_CUSTOMER_USER"; //NOI18N
+ } else if (isUserContact) {
+ // Only user
+ messageKey = "CONTACT_IS_USER"; //NOI18N
+ } else if (isCustomerContact) {
+ // Only customer
+ messageKey = "CONTACT_IS_CUSTOMER"; //NOI18N
+ }
+
+ // Return message key
+ return messageKey;
+ }
+
+ @Override
+ public Customer getCustomer () {
+ return this.customer;
+ }
+
+ @Override
+ public void setCustomer (final Customer customer) {
+ this.customer = customer;
+ }
+
+ @Override
+ public DialableFaxNumber getFaxNumber () {
+ return this.faxNumber;
+ }
+
+ @Override
+ public void setFaxNumber (final DialableFaxNumber faxNumber) {
+ this.faxNumber = faxNumber;
+ }
+
+ @Override
+ public DialableLandLineNumber getLandLineNumber () {
+ return this.landLineNumber;
+ }
+
+ @Override
+ public void setLandLineNumber (final DialableLandLineNumber landLineNumber) {
+ this.landLineNumber = landLineNumber;
+ }
+
+ @Override
+ public DialableMobileNumber getMobileNumber () {
+ return this.mobileNumber;
+ }
+
+ @Override
+ public void setMobileNumber (final DialableMobileNumber mobileNumber) {
+ this.mobileNumber = mobileNumber;
+ }
+
+ @Override
+ public User getUser () {
+ return this.user;
+ }
+
+ @Override
+ public void setUser (final User user) {
+ this.user = user;
+ }
+
+ /**
+ * Set's all given contact's phone instances: land-line, cellphone and fax
+ * <p>
+ * @param contact Contact to set phone instances for
+ */
+ private void setPhoneInstances (final Contact contact) {
+ // The contact must be valid
+ if (null == contact) {
+ // Throw NPE
+ throw new NullPointerException("contact is null"); //NOI18N
+ } else if (contact.getContactId() == null) {
+ // Throw again ...
+ throw new NullPointerException("contact.contactId is null"); //NOI18N
+ } else if (contact.getContactId() < 1) {
+ // Not valid
+ throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
+ }
+
+ // Is cellphone set?
+ if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
+ // Yes, then set it in admin controller
+ this.adminPhoneController.setMobileNumber(contact.getContactMobileNumber());
+ }
+
+ // Is land-line set?
+ if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
+ // Yes, then set it in admin controller
+ this.adminPhoneController.setLandLineNumber(contact.getContactLandLineNumber());
+ }
+
+ // Is fax set?
+ if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
+ // Yes, then set it in admin controller
+ this.adminPhoneController.setFaxNumber(contact.getContactFaxNumber());
+ }
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2016 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.pizzaapplication.beans.helper;
+
+import java.io.Serializable;
+import org.mxchange.jcontacts.contact.Contact;
+import org.mxchange.jcustomercore.model.customer.Customer;
+import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
+import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
+import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
+import org.mxchange.jusercore.model.user.User;
+
+/**
+ * An interface for general bean helper
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface PizzaWebRequestHelperController extends Serializable {
+
+ /**
+ * Getter for user instance
+ * <p>
+ * @return User instance
+ */
+ User getUser ();
+
+ /**
+ * Setter for user instance
+ * <p>
+ * @param user User instance
+ */
+ void setUser (final User user);
+
+ /**
+ * Copies currently set user instance's data to adminUserController
+ */
+ void copyUserToController ();
+
+ /**
+ * Returns a message key depending on if this contact is a user and/or a
+ * contact. If this contact is unused, a default key is returned.
+ * <p>
+ * @param contact Contact instance to check
+ * <p>
+ * @return Message key
+ */
+ String getContactUsageMessageKey (final Contact contact);
+
+ /**
+ * Getter for contact instance
+ * <p>
+ * @return Contact instance
+ */
+ Contact getContact ();
+
+ /**
+ * Setter for contact instance
+ * <p>
+ * @param contact Contact instance
+ */
+ void setContact (final Contact contact);
+
+ /**
+ * Getter for customer instance
+ * <p>
+ * @return Customer instance
+ */
+ Customer getCustomer ();
+
+ /**
+ * Setter for customer instance
+ * <p>
+ * @param customer Contact instance
+ */
+ void setCustomer (final Customer customer);
+
+ /**
+ * Copies currently set contact instance's data to adminContactController
+ */
+ void copyContactToController ();
+
+ /**
+ * Copies currently set customer instance's data to adminCustomerController
+ */
+ void copyCustomerToController ();
+
+ /**
+ * Copies currently set fax number's data to admin phone controller
+ */
+ void copyFaxNumberToController ();
+
+ /**
+ * Copies currently set land-line number's data to admin phone controller
+ */
+ void copyLandLineNumberToController ();
+
+ /**
+ * Copies currently set mobile number's data to admin phone controller
+ */
+ void copyMobileNumberToController ();
+
+ /**
+ * Getter for dialable mobile number
+ * <p>
+ * @return Dialable mobile number
+ */
+ DialableMobileNumber getMobileNumber ();
+
+ /**
+ * Setter for dialable mobile number
+ * <p>
+ * @param mobileNumber Dialable mobile number
+ */
+ void setMobileNumber (final DialableMobileNumber mobileNumber);
+
+ /**
+ * Getter for dialable land-line number
+ * <p>
+ * @return Dialable land-line number
+ */
+ DialableLandLineNumber getLandLineNumber ();
+
+ /**
+ * Setter for dialable land-line number
+ * <p>
+ * @param landLine Dialable land-line number
+ */
+ void setLandLineNumber (final DialableLandLineNumber landLine);
+
+ /**
+ * Getter for dialable fax number
+ * <p>
+ * @return Dialable fax number
+ */
+ DialableFaxNumber getFaxNumber ();
+
+ /**
+ * Setter for dialable fax number
+ * <p>
+ * @param faxNumber Dialable fax number
+ */
+ void setFaxNumber (final DialableFaxNumber faxNumber);
+
+}
*/
private Locale locale;
- @Override
+ /**
+ * Event observer for logged-in user
+ * <p>
+ * @param event Event instance
+ */
public void afterUserLoginEvent (@Observes final ObservableUserLoggedInEvent event) {
// event should not be null
if (null == event) {
}
}
- @Override
+ /**
+ * Event observer for logged-out user
+ * <p>
+ * @param event Event instance
+ */
public void afterUserLogoutEvent (@Observes final ObservableUserLogoutEvent event) {
// event should not be null
if (null == event) {
import java.io.Serializable;
import java.util.Locale;
-import org.mxchange.jusercore.events.login.ObservableUserLoggedInEvent;
-import org.mxchange.jusercore.events.logout.ObservableUserLogoutEvent;
/**
* An interface for localization change beans
*/
public interface PizzaLocalizationSessionController extends Serializable {
- /**
- * Event observer for logged-in user
- * <p>
- * @param event Event instance
- */
- void afterUserLoginEvent (final ObservableUserLoggedInEvent event);
-
- /**
- * Event observer for logged-out user
- * <p>
- * @param event Event instance
- */
- void afterUserLogoutEvent (final ObservableUserLogoutEvent event);
-
/**
* Getter for locale
* <p>
import javax.naming.NamingException;
import org.mxchange.jusercore.container.login.LoginContainer;
import org.mxchange.jusercore.container.login.UserLoginContainer;
+import org.mxchange.jusercore.events.login.ObservableUserLoggedInEvent;
import org.mxchange.jusercore.events.login.UserLoggedInEvent;
+import org.mxchange.jusercore.events.logout.ObservableUserLogoutEvent;
import org.mxchange.jusercore.events.logout.UserLogoutEvent;
+import org.mxchange.jusercore.events.user.password_change.ObservableUpdatedUserPasswordEvent;
import org.mxchange.jusercore.exceptions.UserNotFoundException;
import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
import org.mxchange.jusercore.exceptions.UserStatusLockedException;
import org.mxchange.jusercore.model.user.status.UserAccountStatus;
import org.mxchange.pizzaapplication.beans.BasePizzaController;
import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController;
-import org.mxchange.jusercore.events.login.ObservableUserLoggedInEvent;
-import org.mxchange.jusercore.events.logout.ObservableUserLogoutEvent;
-import org.mxchange.jusercore.events.user.password_change.ObservableUpdatedUserPasswordEvent;
/**
* A web bean for user registration
/**
* Path name for guest base template
*/
- private static final String GUEST_BASE_TEMPLATE_NAME = "guest/guest"; //NOI18N
+ private static final String GUEST_BASE_TEMPLATE_NAME = "guest/guest";
/**
* Path name for logged-in user base template
*/
- private static final String USER_BASE_TEMPLATE_NAME = "login/user/user"; //NOI18N
+ private static final String USER_BASE_TEMPLATE_NAME = "login/user/user";
/**
* Serial number
private String baseTemplatePathName;
/**
- * Current password
+ * Logged-in user instance
*/
- private String currentPassword;
+ private User loggedInUser;
/**
- * Logged-in user instance
+ * Remote register session bean
*/
- private User loggedInUser;
+ private UserLoginSessionBeanRemote loginBean;
+
+ /**
+ * Event fired when user has logged in
+ */
+ @Inject
+ @Any
+ private Event<ObservableUserLoggedInEvent> loginEvent;
/**
* User controller
private PizzaUserWebSessionController userController;
/**
- * Flag whether the user has logged-in, set only from inside
+ * Current password
*/
- private boolean userLoggedIn;
+ private String userCurrentPassword;
/**
- * EJB for user-login
+ * Flag whether the user has logged-in, set only from inside
*/
- private UserLoginSessionBeanRemote userLoginBean;
+ private boolean userLoggedIn;
/**
* Event fired when user has logged in
Context context = new InitialContext();
// Try to lookup
- this.userLoginBean = (UserLoginSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/login!org.mxchange.jusercore.model.login.UserLoginSessionBeanRemote"); //NOI18N
+ this.loginBean = (UserLoginSessionBeanRemote) context.lookup("java:global/jjobs-ejb/login!org.mxchange.jusercore.model.login.UserLoginSessionBeanRemote"); //NOI18N
// Also find this
- this.userPasswordHistoryBean = (UserPasswordHistorySessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/userPasswordHistory!org.mxchange.jusercore.model.user.password_history.UserPasswordHistorySessionBeanRemote"); //NOI18N
+ this.userPasswordHistoryBean = (UserPasswordHistorySessionBeanRemote) context.lookup("java:global/jjobs-ejb/userPasswordHistory!org.mxchange.jusercore.model.user.password_history.UserPasswordHistorySessionBeanRemote"); //NOI18N
// Defaul template is guest
this.baseTemplatePathName = GUEST_BASE_TEMPLATE_NAME;
}
}
- @Override
+ /**
+ * Method being call after user's password has been updated (and history
+ * entry has been created).
+ * <p>
+ * @param event Event being observed
+ */
public void afterUserUpdatedPasswordEvent (@Observes final ObservableUpdatedUserPasswordEvent event) {
// Check parameter
if (null == event) {
try {
// Call bean
- User confirmedUser = this.userLoginBean.validateUserAccountStatus(container);
+ User confirmedUser = this.loginBean.validateUserAccountStatus(container);
// All fine here so set it here
this.setLoggedInUser(confirmedUser);
this.clear();
// All fine
- return "login"; //NOI18N
- } catch (final UserNotFoundException | UserStatusLockedException | UserStatusUnconfirmedException ex) {
+ return "login_user"; //NOI18N
+ } catch (final UserNotFoundException ex) {
// Show JSF message
- this.showFacesMessage("form_user_login:userName", ex); //NOI18N
+ this.showFacesMessage("form_user_login:userName", "ERROR_USER_NOT_FOUND"); //NOI18N
+ return ""; //NOI18N
+ } catch (final UserStatusLockedException ex) {
+ this.showFacesMessage("form_user_login:userName", "ERROR_USER_STATUS_LOCKED"); //NOI18N
+ return ""; //NOI18N
+ } catch (final UserStatusUnconfirmedException ex) {
+ this.showFacesMessage("form_user_login:userName", "ERROR_USER_STATUS_UNCONFIRMED"); //NOI18N
return ""; //NOI18N
} catch (final UserPasswordMismatchException ex) {
// Show JSF message
- this.showFacesMessage("form_user_login:userPassword", ex); //NOI18N
+ this.showFacesMessage("form_user_login:userPassword", "ERROR_USER_PASSWORD_MISMATCH"); //NOI18N
return ""; //NOI18N
}
}
@Override
public String doUserLogout () {
+ // Is loggedInUser set?
+ if (this.getLoggedInUser() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.loggedInUser is null"); //NOI18N
+ } else if (this.getLoggedInUser().getUserId() == null) {
+ // Throw again
+ throw new NullPointerException("this.loggedInUser.userId is null"); //NOI18N
+ } else if (this.getLoggedInUser().getUserId() < 1) {
+ // Invalid user id
+ throw new IllegalStateException(MessageFormat.format("this.loggedInUser.userId={0} is not valid.", this.getLoggedInUser().getUserId())); //NOI18N
+ }
+
// Fire event
this.userLogoutEvent.fire(new UserLogoutEvent(this.getLoggedInUser()));
// Unset any user instances
this.setLoggedInUser(null);
+ this.setBaseTemplatePathName(GUEST_BASE_TEMPLATE_NAME); //NOI18N
// Redirect to index
- return "index?faces-redirect=true"; //NOI18N
+ return "index"; //NOI18N
}
@Override
}
@Override
- public String getCurrentPassword () {
- return this.currentPassword;
+ public User getLoggedInUser () {
+ return this.loggedInUser;
}
@Override
- public void setCurrentPassword (final String currentPassword) {
- this.currentPassword = currentPassword;
+ public void setLoggedInUser (final User loggedInUser) {
+ this.loggedInUser = loggedInUser;
}
@Override
- public User getLoggedInUser () {
- return this.loggedInUser;
+ public String getUserCurrentPassword () {
+ return this.userCurrentPassword;
}
@Override
- public void setLoggedInUser (final User loggedInUser) {
- this.loggedInUser = loggedInUser;
+ public void setUserCurrentPassword (final String userCurrentPassword) {
+ this.userCurrentPassword = userCurrentPassword;
}
@Override
@Override
public boolean ifCurrentPasswordMatches () {
// The current password must be set and not empty
- if (this.getCurrentPassword() == null) {
+ if (this.getUserCurrentPassword() == null) {
// Is not set
- throw new NullPointerException("this.currentPassword is null"); //NOI18N
- } else if (this.getCurrentPassword().isEmpty()) {
+ throw new NullPointerException("this.userCurrentPassword is null"); //NOI18N
+ } else if (this.getUserCurrentPassword().isEmpty()) {
// Is set empty
- throw new IllegalStateException("this.currentPassword is empty."); //NOI18N
+ throw new IllegalStateException("this.userCurrentPassword is empty."); //NOI18N
}
// Create "container"
- LoginContainer container = new UserLoginContainer(this.getLoggedInUser(), this.getCurrentPassword());
+ LoginContainer container = new UserLoginContainer(this.getLoggedInUser(), this.getUserCurrentPassword());
// Now check if it matches
return UserUtils.ifPasswordMatches(container, this.getLoggedInUser());
@Override
public boolean ifUserMustChangePassword () {
- return (this.isUserLoggedIn() && this.getLoggedInUser().getUserMustChangePassword());
+ return ((this.isUserLoggedIn()) && (Objects.equals(this.getLoggedInUser().getUserMustChangePassword(), Boolean.TRUE)));
}
@Override
}
// Check logged-in first, then invisibility
- return this.getLoggedInUser().getUserProfileMode().equals(ProfileMode.INVISIBLE);
+ return Objects.equals(this.getLoggedInUser().getUserProfileMode(), ProfileMode.INVISIBLE);
}
@Override
*/
private void clear () {
// Clear all fields
- this.setCurrentPassword(null);
+ this.setUserCurrentPassword(null);
}
/**
import javax.ejb.Local;
import org.mxchange.jusercore.model.user.User;
import org.mxchange.jusercore.model.user.password_history.PasswordHistory;
-import org.mxchange.jusercore.events.user.password_change.ObservableUpdatedUserPasswordEvent;
/**
* An interface for registration web controllers
@Local
public interface PizzaUserLoginWebSessionController extends Serializable {
- /**
- * Method being call after user's password has been updated (and history
- * entry has been created).
- * <p>
- * @param event Event being observed
- */
- void afterUserUpdatedPasswordEvent (final ObservableUpdatedUserPasswordEvent event);
-
/**
* Checks whether given clear-text password is in user's password history.
* <p>
boolean isPasswordInHistory (final String userPassword);
/**
- * Getter for template type
+ * Getter for base template type
* <p>
* @return Template type
*/
String getBaseTemplatePathName ();
/**
- * Setter for template type
+ * Setter for base template type
* <p>
* @param baseTemplatePathName Template type
*/
/**
* Setter for current password (clear text)
* <p>
- * @param currentPassword Current password
+ * @param userCurrentPassword Current password
*/
- void setCurrentPassword (final String currentPassword);
+ void setUserCurrentPassword (final String userCurrentPassword);
/**
* Getter for current password (clear text)
* <p>
* @return Current password
*/
- String getCurrentPassword ();
+ String getUserCurrentPassword ();
/**
* Checks whether the (previously entered) current password matches with
}
}
- @Override
- public void afterAdminAddedMobileProvider (@Observes final AdminAddedMobileProviderEvent event) {
+ /**
+ * Observes events being fired after the administrator has added a new
+ * mobile provider
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterAdminAddedMobileProviderEvent (@Observes final AdminAddedMobileProviderEvent event) {
// Is all valid?
if (null == event) {
// Throw NPE
import java.io.Serializable;
import java.util.List;
-import org.mxchange.jphone.events.mobileprovider.added.AdminAddedMobileProviderEvent;
import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
/**
*/
List<MobileProvider> allMobileProviders ();
- /**
- * Observes events being fired after the administrator has added a new
- * mobile provider
- * <p>
- * @param event Event being fired
- */
- void afterAdminAddedMobileProvider (final AdminAddedMobileProviderEvent event);
-
}
*/
package org.mxchange.pizzaapplication.beans.phone;
+import java.text.MessageFormat;
+import java.util.List;
+import java.util.Objects;
import javax.enterprise.context.RequestScoped;
+import javax.enterprise.event.Event;
+import javax.enterprise.inject.Any;
import javax.faces.view.facelets.FaceletException;
+import javax.inject.Inject;
import javax.inject.Named;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
-import org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote;
-import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
+import org.mxchange.jcountry.data.Country;
+import org.mxchange.jphone.events.fax.deleted.AdminDeletedFaxNumberEvent;
+import org.mxchange.jphone.events.fax.deleted.AdminFaxNumberDeletedEvent;
+import org.mxchange.jphone.events.fax.removed.AdminFaxNumberRemovedFromListEvent;
+import org.mxchange.jphone.events.fax.removed.AdminRemoveFaxNumberFromListEvent;
+import org.mxchange.jphone.events.fax.updated.AdminFaxNumberUpdatedEvent;
+import org.mxchange.jphone.events.fax.updated.AdminUpdatedFaxNumberEvent;
+import org.mxchange.jphone.events.landline.deleted.AdminDeletedLandLineNumberEvent;
+import org.mxchange.jphone.events.landline.deleted.AdminLandLineNumberDeletedEvent;
+import org.mxchange.jphone.events.landline.removed.AdminLandLineNumberRemovedFromListEvent;
+import org.mxchange.jphone.events.landline.removed.AdminRemoveLandLineNumberFromListEvent;
+import org.mxchange.jphone.events.landline.updated.AdminLandLineNumberUpdatedEvent;
+import org.mxchange.jphone.events.landline.updated.AdminUpdatedLandLineNumberEvent;
+import org.mxchange.jphone.events.mobile.deleted.AdminDeletedMobileNumberEvent;
+import org.mxchange.jphone.events.mobile.deleted.AdminMobileNumberDeletedEvent;
+import org.mxchange.jphone.events.mobile.remove.AdminMobileNumberRemovedFromListEvent;
+import org.mxchange.jphone.events.mobile.remove.AdminRemoveMobileNumberFromListEvent;
+import org.mxchange.jphone.events.mobile.updated.AdminMobileNumberUpdatedEvent;
+import org.mxchange.jphone.events.mobile.updated.AdminUpdatedMobileNumberEvent;
import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
+import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
+import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
+import org.mxchange.jphone.phonenumbers.phone.AdminPhoneSessionBeanRemote;
import org.mxchange.pizzaapplication.beans.BasePizzaController;
+import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestHelperController;
/**
* Administrative bean (controller) for phone numbers
@RequestScoped
public class PizzaAdminPhoneWebRequestBean extends BasePizzaController implements PizzaAdminPhoneWebRequestController {
+ /**
+ * Call-stack position
+ */
+ private static final short THREAD_STACK = 5;
+
/**
* Serial number
*/
/**
* Remote EJB for phone number (administrative)
*/
- private AdminContactsPhoneSessionBeanRemote adminPhoneBean;
+ private AdminPhoneSessionBeanRemote adminPhoneBean;
+
+ /**
+ * Bean helper
+ */
+ @Inject
+ private PizzaWebRequestHelperController beanHelper;
+
+ /**
+ * Choosen fax number
+ */
+ private DialableFaxNumber choosenFaxNumber;
+
+ /**
+ * Choosen land-line number
+ */
+ private DialableLandLineNumber choosenLandLineNumber;
+
+ /**
+ * Choosen mobile number
+ */
+ private DialableMobileNumber choosenMobileNumber;
+
+ /**
+ * Event being fired when an administrator has deleted fax number
+ */
+ @Inject
+ @Any
+ private Event<AdminDeletedFaxNumberEvent> faxNumberDeletedEvent;
+
+ /**
+ * Event being fired when an administrator has updated fax number
+ */
+ @Inject
+ @Any
+ private Event<AdminUpdatedFaxNumberEvent> faxNumberUpdatedEvent;
+
+ /**
+ * Event being fired when an administrator has deleted land-line number
+ */
+ @Inject
+ @Any
+ private Event<AdminDeletedLandLineNumberEvent> landLineNumberDeletedEvent;
+
+ /**
+ * Event being fired when an administrator has updated fax number
+ */
+ @Inject
+ @Any
+ private Event<AdminUpdatedLandLineNumberEvent> landLineNumberUpdatedEvent;
+
+ /**
+ * Event being fired when an administrator has deleted mobile number
+ */
+ @Inject
+ @Any
+ private Event<AdminDeletedMobileNumberEvent> mobileNumberDeletedEvent;
+
+ /**
+ * Event being fired when an administrator has updated land-line number
+ */
+ @Inject
+ @Any
+ private Event<AdminUpdatedMobileNumberEvent> mobileNumberUpdatedEvent;
+
+ /**
+ * Mobile provider
+ */
+ private MobileProvider mobileProvider;
+
+ /**
+ * Area code (city dial prefix)
+ */
+ private Integer phoneAreaCode;
+
+ /**
+ * Generic hone controller
+ */
+ @Inject
+ private PizzaPhoneWebApplicationController phoneController;
+
+ /**
+ * Country (for dial prefix)
+ */
+ private Country phoneCountry;
+
+ /**
+ * Phone number
+ */
+ private Long phoneNumber;
/**
- * Cell phone number
+ * Event being fired when a list of all unsed fax numbers is being created.
*/
- private DialableMobileNumber cellPhone;
+ @Inject
+ @Any
+ private Event<AdminRemoveFaxNumberFromListEvent> removeLinkedFaxNumbersEvent;
/**
- * Fax number
+ * Event being fired when a list of all unsed land-line numbers is being
+ * created.
*/
- private DialableFaxNumber fax;
+ @Inject
+ @Any
+ private Event<AdminRemoveLandLineNumberFromListEvent> removeLinkedLandLineNumbersEvent;
/**
- * Land-line number
+ * Event being fired when a list of all unsed mobile numbers is being
+ * created.
*/
- private DialableLandLineNumber landLine;
+ @Inject
+ @Any
+ private Event<AdminRemoveMobileNumberFromListEvent> removeLinkedMobileNumbersEvent;
/**
* Default constructor
*/
public PizzaAdminPhoneWebRequestBean () {
+ // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[3].getClassName(), Thread.currentThread().getStackTrace()[3].getMethodName());
+ // System.out.println(MessageFormat.format("{0}: Constructed, caller: {1}", this.getClass().getSimpleName(), caller));
+
// Try it
try {
// Get initial context
Context context = new InitialContext();
// Try to lookup the beans
- this.adminPhoneBean = (AdminContactsPhoneSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/admincontactphone!org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote"); //NOI18N
+ this.adminPhoneBean = (AdminPhoneSessionBeanRemote) context.lookup("java:global/jjobs-ejb/adminPhone!org.mxchange.jphone.phonenumbers.phone.AdminPhoneSessionBeanRemote"); //NOI18N
} catch (final NamingException e) {
// Throw it again
throw new FaceletException(e);
}
@Override
- public DialableMobileNumber getMobileNumber () {
- return this.cellPhone;
+ public List<DialableFaxNumber> allNonLinkedFaxNumbers () {
+ // Get list of all mobile numbers
+ List<DialableFaxNumber> list = this.phoneController.allFaxNumbers();
+
+ // Visit all controllers to reduce the list
+ this.removeLinkedFaxNumbersEvent.fire(new AdminFaxNumberRemovedFromListEvent(list));
+
+ // Return it
+ return list;
+ }
+
+ @Override
+ public List<DialableLandLineNumber> allNonLinkedLandLineNumbers () {
+ // Get list of all mobile numbers
+ List<DialableLandLineNumber> list = this.phoneController.allLandLineNumbers();
+
+ // Visit all controllers to reduce the list
+ this.removeLinkedLandLineNumbersEvent.fire(new AdminLandLineNumberRemovedFromListEvent(list));
+
+ // Return it
+ return list;
+ }
+
+ @Override
+ public List<DialableMobileNumber> allNonLinkedMobileNumbers () {
+ // Get list of all mobile numbers
+ List<DialableMobileNumber> list = this.phoneController.allMobileNumbers();
+
+ // Visit all controllers to reduce the list
+ this.removeLinkedMobileNumbersEvent.fire(new AdminMobileNumberRemovedFromListEvent(list));
+
+ // Return it
+ return list;
+ }
+
+ @Override
+ public String deleteFaxData (final DialableFaxNumber faxNumber) {
+ // Is all data set
+ if (faxNumber == null) {
+ // Not set, throw NPE
+ throw new NullPointerException("faxNumber is null"); //NOI18N
+ } else if (faxNumber.getPhoneId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N
+ } else if (faxNumber.getPhoneId() < 1) {
+ // Invalid number
+ throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid", faxNumber.getPhoneId())); //NOI18N
+ } else if (faxNumber.getPhoneCountry() == null) {
+ // Throw NPE
+ throw new NullPointerException("faxNumber.phoneCountry is null"); //NOI18N
+ } else if (faxNumber.getPhoneCountry().getCountryId() == null) {
+ // Throw NPE
+ throw new NullPointerException("faxNumber.phoneCountry.countryId is null"); //NOI18N
+ } else if (faxNumber.getPhoneCountry().getCountryId() < 1) {
+ // Throw NPE
+ throw new NullPointerException(MessageFormat.format("faxNumber.phoneCountry.countryId={0} is not valid", faxNumber.getPhoneCountry().getCountryId())); //NOI18N
+ } else if (faxNumber.getPhoneAreaCode() == null) {
+ // ... throw again
+ throw new NullPointerException("faxNumber.phoneAreaCode is null"); //NOI18N
+ } else if (faxNumber.getPhoneAreaCode() < 1) {
+ // Id not valid
+ throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneAreaCode={0} is not valid.", faxNumber.getPhoneAreaCode())); //NOI18N
+ } else if (faxNumber.getPhoneNumber() == null) {
+ // Throw NPE again
+ throw new NullPointerException("faxNumber.phoneNumber is null"); //NOI18N
+ } else if (faxNumber.getPhoneNumber() < 1) {
+ // Throw NPE again
+ throw new NullPointerException(MessageFormat.format("faxNumber.phoneNumber={0} is not valid.", faxNumber.getPhoneNumber())); //NOI18N
+ }
+
+ // Call EJB
+ this.adminPhoneBean.deleteFaxData(faxNumber);
+
+ // Fire event
+ this.faxNumberDeletedEvent.fire(new AdminFaxNumberDeletedEvent(faxNumber));
+
+ // All fine, redirect
+ return "admin_list_fax"; //NOI18N
+ }
+
+ @Override
+ public String deleteLandLineData (final DialableLandLineNumber landLineNumber) {
+ // Is all data set
+ if (landLineNumber == null) {
+ // Not set, throw NPE
+ throw new NullPointerException("landLineNumber is null"); //NOI18N
+ } else if (landLineNumber.getPhoneId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
+ } else if (landLineNumber.getPhoneId() < 1) {
+ // Invalid number
+ throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", landLineNumber.getPhoneId())); //NOI18N
+ } else if (landLineNumber.getPhoneCountry() == null) {
+ // Throw NPE
+ throw new NullPointerException("landLineNumber.phoneCountry is null"); //NOI18N
+ } else if (landLineNumber.getPhoneCountry().getCountryId() == null) {
+ // Throw NPE
+ throw new NullPointerException("landLineNumber.phoneCountry.countryId is null"); //NOI18N
+ } else if (landLineNumber.getPhoneCountry().getCountryId() < 1) {
+ // Throw NPE
+ throw new NullPointerException(MessageFormat.format("landLineNumber.phoneCountry.countryId={0} is not valid", landLineNumber.getPhoneCountry().getCountryId())); //NOI18N
+ } else if (landLineNumber.getPhoneAreaCode() == null) {
+ // ... throw again
+ throw new NullPointerException("landLineNumber.phoneAreaCode is null"); //NOI18N
+ } else if (landLineNumber.getPhoneAreaCode() < 1) {
+ // Id not valid
+ throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneAreaCode={0} is not valid.", landLineNumber.getPhoneAreaCode())); //NOI18N
+ } else if (landLineNumber.getPhoneNumber() == null) {
+ // Throw NPE again
+ throw new NullPointerException("landLineNumber.phoneNumber is null"); //NOI18N
+ } else if (landLineNumber.getPhoneNumber() < 1) {
+ // Throw NPE again
+ throw new NullPointerException(MessageFormat.format("landLineNumber.phoneNumber={0} is not valid.", landLineNumber.getPhoneNumber())); //NOI18N
+ }
+
+ // Call EJB
+ this.adminPhoneBean.deleteLandLineData(landLineNumber);
+
+ // Fire event
+ this.landLineNumberDeletedEvent.fire(new AdminLandLineNumberDeletedEvent(landLineNumber));
+
+ // All fine, redirect
+ return "admin_list_landline"; //NOI18N
+ }
+
+ @Override
+ public String deleteMobileData (final DialableMobileNumber mobileNumber) {
+ // Is all data set
+ if (mobileNumber == null) {
+ // Not set, throw NPE
+ throw new NullPointerException("mobileNumber is null"); //NOI18N
+ } else if (mobileNumber.getPhoneId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N
+ } else if (mobileNumber.getPhoneId() < 1) {
+ // Invalid number
+ throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", mobileNumber.getPhoneId())); //NOI18N
+ } else if (mobileNumber.getMobileProvider() == null) {
+ // Throw NPE
+ throw new NullPointerException("mobileNumber.mobileProvider is null"); //NOI18N
+ } else if (mobileNumber.getMobileProvider().getProviderId() == null) {
+ // ... throw again
+ throw new NullPointerException("mobileNumber.mobileProvider.providerId is null"); //NOI18N
+ } else if (mobileNumber.getMobileProvider().getProviderId() < 1) {
+ // Id not valid
+ throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileProvider.providerId={0} is not valid.", mobileNumber.getMobileProvider().getProviderId())); //NOI18N
+ } else if (mobileNumber.getPhoneNumber() == null) {
+ // Throw NPE again
+ throw new NullPointerException("mobileNumber.phoneNumber is null"); //NOI18N
+ } else if (mobileNumber.getPhoneNumber() < 1) {
+ // Throw NPE again
+ throw new NullPointerException(MessageFormat.format("mobileNumber.phoneNumber={0} is not valid.", mobileNumber.getPhoneNumber())); //NOI18N
+ }
+
+ // Call EJB
+ this.adminPhoneBean.deleteMobileData(mobileNumber);
+
+ // Fire event
+ this.mobileNumberDeletedEvent.fire(new AdminMobileNumberDeletedEvent(mobileNumber));
+
+ // All fine, redirect
+ return "admin_list_mobile"; //NOI18N
+ }
+
+ @Override
+ public String editFaxData (final DialableFaxNumber faxNumber) {
+ // Is all data set
+ if (faxNumber == null) {
+ // Not set, throw NPE
+ throw new NullPointerException("faxNumber is null"); //NOI18N
+ } else if (faxNumber.getPhoneId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N
+ } else if (faxNumber.getPhoneId() < 1) {
+ // Invalid number
+ throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid", faxNumber.getPhoneId())); //NOI18N
+ } else if (faxNumber.getPhoneCountry() == null) {
+ // Throw NPE
+ throw new NullPointerException("faxNumber.phoneCountry is null"); //NOI18N
+ } else if (faxNumber.getPhoneCountry().getCountryId() == null) {
+ // Throw NPE
+ throw new NullPointerException("faxNumber.phoneCountry.countryId is null"); //NOI18N
+ } else if (faxNumber.getPhoneCountry().getCountryId() < 1) {
+ // Throw NPE
+ throw new NullPointerException(MessageFormat.format("faxNumber.phoneCountry.countryId={0} is not valid", faxNumber.getPhoneCountry().getCountryId())); //NOI18N
+ } else if (faxNumber.getPhoneAreaCode() == null) {
+ // ... throw again
+ throw new NullPointerException("faxNumber.phoneAreaCode is null"); //NOI18N
+ } else if (faxNumber.getPhoneAreaCode() < 1) {
+ // Id not valid
+ throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneAreaCode={0} is not valid.", faxNumber.getPhoneAreaCode())); //NOI18N
+ } else if (faxNumber.getPhoneNumber() == null) {
+ // Throw NPE again
+ throw new NullPointerException("faxNumber.phoneNumber is null"); //NOI18N
+ } else if (faxNumber.getPhoneNumber() < 1) {
+ // Throw NPE again
+ throw new NullPointerException(MessageFormat.format("faxNumber.phoneNumber={0} is not valid.", faxNumber.getPhoneNumber())); //NOI18N
+ }
+
+ // Is the mobile provider and number the same?
+ if ((Objects.equals(this.getPhoneCountry(), faxNumber.getPhoneCountry())) && (Objects.equals(this.getPhoneAreaCode(), faxNumber.getPhoneAreaCode())) && (Objects.equals(this.getPhoneNumber(), faxNumber.getPhoneNumber()))) {
+ // Show message
+ this.showFacesMessage("form_edit_fax:faxNumber", "ERROR_ADMIN_NO_CHANGE_ENTERED"); //NOI18N
+
+ // No difference in both together, no need to edit
+ return ""; //NOI18N
+ }
+
+ // Set all data
+ faxNumber.setPhoneCountry(this.getPhoneCountry());
+ faxNumber.setPhoneAreaCode(this.getPhoneAreaCode());
+ faxNumber.setPhoneNumber(this.getPhoneNumber());
+
+ // Send to bean
+ DialableFaxNumber updatedNumber = this.adminPhoneBean.updateFaxData(faxNumber);
+
+ // Fire event
+ this.faxNumberUpdatedEvent.fire(new AdminFaxNumberUpdatedEvent(updatedNumber));
+
+ // All fine, redirect
+ return "admin_show_fax"; //NOI18N
+ }
+
+ @Override
+ public String editLandLineData (final DialableLandLineNumber landLineNumber) {
+ // Is all data set
+ if (landLineNumber == null) {
+ // Not set, throw NPE
+ throw new NullPointerException("landLineNumber is null"); //NOI18N
+ } else if (landLineNumber.getPhoneId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
+ } else if (landLineNumber.getPhoneId() < 1) {
+ // Invalid number
+ throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", landLineNumber.getPhoneId())); //NOI18N
+ } else if (landLineNumber.getPhoneCountry() == null) {
+ // Throw NPE
+ throw new NullPointerException("landLineNumber.phoneCountry is null"); //NOI18N
+ } else if (landLineNumber.getPhoneCountry().getCountryId() == null) {
+ // Throw NPE
+ throw new NullPointerException("landLineNumber.phoneCountry.countryId is null"); //NOI18N
+ } else if (landLineNumber.getPhoneCountry().getCountryId() < 1) {
+ // Throw NPE
+ throw new NullPointerException(MessageFormat.format("landLineNumber.phoneCountry.countryId={0} is not valid", landLineNumber.getPhoneCountry().getCountryId())); //NOI18N
+ } else if (landLineNumber.getPhoneAreaCode() == null) {
+ // ... throw again
+ throw new NullPointerException("landLineNumber.phoneAreaCode is null"); //NOI18N
+ } else if (landLineNumber.getPhoneAreaCode() < 1) {
+ // Id not valid
+ throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneAreaCode={0} is not valid.", landLineNumber.getPhoneAreaCode())); //NOI18N
+ } else if (landLineNumber.getPhoneNumber() == null) {
+ // Throw NPE again
+ throw new NullPointerException("landLineNumber.phoneNumber is null"); //NOI18N
+ } else if (landLineNumber.getPhoneNumber() < 1) {
+ // Throw NPE again
+ throw new NullPointerException(MessageFormat.format("landLineNumber.phoneNumber={0} is not valid.", landLineNumber.getPhoneNumber())); //NOI18N
+ }
+
+ // Is the mobile provider and number the same?
+ if ((Objects.equals(this.getPhoneCountry(), landLineNumber.getPhoneCountry())) && (Objects.equals(this.getPhoneAreaCode(), landLineNumber.getPhoneAreaCode())) && (Objects.equals(this.getPhoneNumber(), landLineNumber.getPhoneNumber()))) {
+ // Show message
+ this.showFacesMessage("form_edit_landline:landLineNumber", "ERROR_ADMIN_NO_CHANGE_ENTERED"); //NOI18N
+
+ // No difference in both together, no need to edit
+ return ""; //NOI18N
+ }
+
+ // Set all data
+ landLineNumber.setPhoneCountry(this.getPhoneCountry());
+ landLineNumber.setPhoneAreaCode(this.getPhoneAreaCode());
+ landLineNumber.setPhoneNumber(this.getPhoneNumber());
+
+ // Send to bean
+ DialableLandLineNumber updatedNumber = this.adminPhoneBean.updateLandLineData(landLineNumber);
+
+ // Fire event
+ this.landLineNumberUpdatedEvent.fire(new AdminLandLineNumberUpdatedEvent(updatedNumber));
+
+ // All fine, redirect
+ return "admin_show_landline"; //NOI18N
+ }
+
+ @Override
+ public String editMobileData (final DialableMobileNumber mobileNumber) {
+ // Is all data set
+ if (mobileNumber == null) {
+ // Not set, throw NPE
+ throw new NullPointerException("mobileNumber is null"); //NOI18N
+ } else if (mobileNumber.getPhoneId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N
+ } else if (mobileNumber.getPhoneId() < 1) {
+ // Invalid number
+ throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", mobileNumber.getPhoneId())); //NOI18N
+ } else if (mobileNumber.getMobileProvider() == null) {
+ // Throw NPE
+ throw new NullPointerException("mobileNumber.mobileProvider is null"); //NOI18N
+ } else if (mobileNumber.getMobileProvider().getProviderId() == null) {
+ // ... throw again
+ throw new NullPointerException("mobileNumber.mobileProvider.providerId is null"); //NOI18N
+ } else if (mobileNumber.getMobileProvider().getProviderId() < 1) {
+ // Id not valid
+ throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileProvider.providerId={0} is not valid.", mobileNumber.getMobileProvider().getProviderId())); //NOI18N
+ } else if (mobileNumber.getPhoneNumber() == null) {
+ // Throw NPE again
+ throw new NullPointerException("mobileNumber.phoneNumber is null"); //NOI18N
+ } else if (mobileNumber.getPhoneNumber() < 1) {
+ // Throw NPE again
+ throw new NullPointerException(MessageFormat.format("mobileNumber.phoneNumber={0} is not valid.", mobileNumber.getPhoneNumber())); //NOI18N
+ } else if (this.getMobileProvider() == null) {
+ // Not provided
+ this.showFacesMessage("form_edit_mobile:mobileProvider", "ERROR_ADMIN_NO_MOBILE_PROVIDER_SELECTED"); //NOI18N
+ return ""; //NOI18N
+ } else if (this.getMobileProvider().getProviderId() == null) {
+ // Throw NPE again ...
+ throw new NullPointerException("this.mobileProvider.providerId is null"); //NOI18N
+ } else if (this.getMobileProvider().getProviderId() < 0) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("this.mobileProvider.providerId={0} is not valid.", this.getMobileProvider().getProviderId())); //NOI18N
+ } else if (this.getPhoneNumber() == null) {
+ // Not provided
+ this.showFacesMessage("form_edit_mobile:mobileNumber", "ERROR_ADMIN_EMPTY_MOBILE_NUMBER"); //NOI18N
+ return ""; //NOI18N
+ }
+
+ // Is the mobile provider and number the same?
+ if ((Objects.equals(this.getMobileProvider(), mobileNumber.getMobileProvider())) && (Objects.equals(this.getPhoneNumber(), mobileNumber.getPhoneNumber()))) {
+ // Show message
+ this.showFacesMessage("form_edit_mobile:mobileNumber", "ERROR_ADMIN_NO_CHANGE_ENTERED"); //NOI18N
+
+ // No difference in both together, no need to edit
+ return ""; //NOI18N
+ }
+
+ // Set all data
+ mobileNumber.setMobileProvider(this.getMobileProvider());
+ mobileNumber.setPhoneNumber(this.getPhoneNumber());
+
+ // Send to bean
+ DialableMobileNumber updatedNumber = this.adminPhoneBean.updateMobileData(mobileNumber);
+
+ // Fire event
+ this.mobileNumberUpdatedEvent.fire(new AdminMobileNumberUpdatedEvent(updatedNumber));
+
+ // All fine, redirect
+ return "admin_show_mobile"; //NOI18N
+ }
+
+ @Override
+ public DialableFaxNumber getChoosenFaxNumber () {
+ // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[THREAD_STACK].getClassName(), Thread.currentThread().getStackTrace()[THREAD_STACK].getMethodName());
+ // System.out.println(MessageFormat.format("{0}: Returning this.choosenFaxNumber={1}, caller: {2}", this.getClass().getSimpleName(), this.choosenFaxNumber, caller));
+ return this.choosenFaxNumber;
+ }
+
+ @Override
+ public void setFaxNumber (final DialableFaxNumber choosenFaxNumber) {
+ // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[THREAD_STACK].getClassName(), Thread.currentThread().getStackTrace()[THREAD_STACK].getMethodName());
+ // System.out.println(MessageFormat.format("{0}: Settin choosenFaxNumber={1}, previous: this.choosenFaxNumber={2}, caller: {3}", this.getClass().getSimpleName(), choosenFaxNumber, this.choosenFaxNumber, caller));
+ this.choosenFaxNumber = choosenFaxNumber;
+ }
+
+ @Override
+ public DialableLandLineNumber getChoosenLandLineNumber () {
+ return this.choosenLandLineNumber;
+ }
+
+ @Override
+ public void setLandLineNumber (final DialableLandLineNumber choosenLandLineNumber) {
+ this.choosenLandLineNumber = choosenLandLineNumber;
+ }
+
+ @Override
+ public DialableMobileNumber getChoosenMobileNumber () {
+ return this.choosenMobileNumber;
+ }
+
+ @Override
+ public void setMobileNumber (final DialableMobileNumber choosenMobileNumber) {
+ this.choosenMobileNumber = choosenMobileNumber;
+ }
+
+ @Override
+ public MobileProvider getMobileProvider () {
+ return this.mobileProvider;
+ }
+
+ @Override
+ public void setMobileProvider (final MobileProvider mobileProvider) {
+ this.mobileProvider = mobileProvider;
+ }
+
+ @Override
+ public Integer getPhoneAreaCode () {
+ return this.phoneAreaCode;
}
@Override
- public void setMobileNumber (final DialableMobileNumber cellPhone) {
- this.cellPhone = cellPhone;
+ public void setPhoneAreaCode (final Integer phoneAreaCode) {
+ this.phoneAreaCode = phoneAreaCode;
}
@Override
- public DialableFaxNumber getFaxNumber () {
- return this.fax;
+ public Country getPhoneCountry () {
+ return this.phoneCountry;
}
@Override
- public void setFaxNumber (final DialableFaxNumber fax) {
- this.fax = fax;
+ public void setPhoneCountry (final Country phoneCountry) {
+ this.phoneCountry = phoneCountry;
}
@Override
- public DialableLandLineNumber getLandLineNumber () {
- return this.landLine;
+ public Long getPhoneNumber () {
+ return this.phoneNumber;
}
@Override
- public void setLandLineNumber (final DialableLandLineNumber landLine) {
- this.landLine = landLine;
+ public void setPhoneNumber (final Long phoneNumber) {
+ this.phoneNumber = phoneNumber;
}
}
package org.mxchange.pizzaapplication.beans.phone;
import java.io.Serializable;
+import java.util.List;
import javax.ejb.Local;
+import org.mxchange.jcountry.data.Country;
import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
+import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
/**
* An interface for a request web controller (bean) for administrative phone
public interface PizzaAdminPhoneWebRequestController extends Serializable {
/**
- * Getter for dialable mobile number instance
+ * Returns a list of all unused ("non-linked") mobile numbers
* <p>
- * @return Dialable mobile number instance
+ * @return List with all unused mobile numbers
*/
- DialableMobileNumber getMobileNumber ();
+ List<DialableMobileNumber> allNonLinkedMobileNumbers ();
/**
- * Setter for dialable land-line number instance
+ * Returns a list of all unused ("non-linked") land-line numbers
* <p>
- * @param landLine Dialable land-line number instance
+ * @return List with all unused land-line numbers
*/
- void setLandLineNumber (final DialableLandLineNumber landLine);
+ List<DialableFaxNumber> allNonLinkedFaxNumbers ();
/**
- * Getter for dialable land-line number instance
+ * Returns a list of all unused ("non-linked") land-line numbers
* <p>
- * @return Dialable land-line number instance
+ * @return List with all unused land-line numbers
*/
- DialableLandLineNumber getLandLineNumber ();
+ List<DialableLandLineNumber> allNonLinkedLandLineNumbers ();
/**
- * Setter for dialable fax number instance
+ * Deletes given fax entry data
* <p>
- * @param fax Dialable fax number instance
+ * @param faxNumber Fax number to delete
+ * <p>
+ * @return Redirect outcome
+ */
+ String deleteFaxData (final DialableFaxNumber faxNumber);
+
+ /**
+ * Changes fax entry data
+ * <p>
+ * @param faxNumber Fax number to change data
+ * <p>
+ * @return Redirect outcome
+ */
+ String editFaxData (final DialableFaxNumber faxNumber);
+
+ /**
+ * Deletes given land-line entry data
+ * <p>
+ * @param landLineNumber Land-line number to delete
+ * <p>
+ * @return Redirect outcome
+ */
+ String deleteLandLineData (final DialableLandLineNumber landLineNumber);
+
+ /**
+ * Changes land-line entry data
+ * <p>
+ * @param landLineNumber Land-line number to change data
+ * <p>
+ * @return Redirect outcome
+ */
+ String editLandLineData (final DialableLandLineNumber landLineNumber);
+
+ /**
+ * Deletes given mobile entry data
+ * <p>
+ * @param mobileNumber Mobile number to delete
+ * <p>
+ * @return Redirect outcome
+ */
+ String deleteMobileData (final DialableMobileNumber mobileNumber);
+
+ /**
+ * Changes mobile entry data
+ * <p>
+ * @param mobileNumber Mobile number to change data
+ * <p>
+ * @return Redirect outcome
+ */
+ String editMobileData (final DialableMobileNumber mobileNumber);
+
+ /**
+ * Getter for mobile provider
+ * <p>
+ * @return Mobile provider
+ */
+ MobileProvider getMobileProvider ();
+
+ /**
+ * Setter for mobile provider
+ * <p>
+ * @param mobileProvider Mobile provider
+ */
+ void setMobileProvider (final MobileProvider mobileProvider);
+
+ /**
+ * Getter for choosen fax number
+ * <p>
+ * @return Choosen fax number
+ */
+ DialableFaxNumber getChoosenFaxNumber ();
+
+ /**
+ * Setter for choosen fax number
+ * <p>
+ * @param choosenFaxNumber Choosen fax number
+ */
+ void setFaxNumber (final DialableFaxNumber choosenFaxNumber);
+
+ /**
+ * Getter for choosen land-line number
+ * <p>
+ * @return Choosen land-line number
+ */
+ DialableLandLineNumber getChoosenLandLineNumber ();
+
+ /**
+ * Setter for choosen land-line number
+ * <p>
+ * @param choosenLandLineNumber Choosen land-line number
+ */
+ void setLandLineNumber (final DialableLandLineNumber choosenLandLineNumber);
+
+ /**
+ * Getter for choosen mobile number
+ * <p>
+ * @return Choosen mobile number
+ */
+ DialableMobileNumber getChoosenMobileNumber ();
+
+ /**
+ * Setter for choosen mobile number
+ * <p>
+ * @param choosenMobileNumber Choosen mobile number
+ */
+ void setMobileNumber (final DialableMobileNumber choosenMobileNumber);
+
+ /**
+ * Getter for phone area code
+ * <p>
+ * @return Phone area code
+ */
+ Integer getPhoneAreaCode ();
+
+ /**
+ * Setter for phone area code
+ * <p>
+ * @param phoneAreaCode Phone area code
+ */
+ void setPhoneAreaCode (final Integer phoneAreaCode);
+
+ /**
+ * Getter for phone country (for dial prefix)
+ * <p>
+ * @return Phone country
+ */
+ Country getPhoneCountry ();
+
+ /**
+ * Setter for phone country (for dial prefix)
+ * <p>
+ * @param phoneCountry Phone country
*/
- void setFaxNumber (final DialableFaxNumber fax);
+ void setPhoneCountry (final Country phoneCountry);
/**
- * Getter for dialable fax number instance
+ * Getter for dial number without prefix
* <p>
- * @return Dialable fax number instance
+ * @return Dial number without prefix
*/
- DialableFaxNumber getFaxNumber ();
+ Long getPhoneNumber ();
/**
- * Setter for dialable mobile number instance
+ * Setter for dial number without prefix
* <p>
- * @param mobileNumber Dialable mobile number instance
+ * @param phoneNumber Dial number without prefix
*/
- void setMobileNumber (final DialableMobileNumber mobileNumber);
+ void setPhoneNumber (final Long phoneNumber);
}
--- /dev/null
+/*
+ * Copyright (C) 2016 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.pizzaapplication.beans.phone;
+
+import java.text.MessageFormat;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Objects;
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Observes;
+import javax.faces.view.facelets.FaceletException;
+import javax.inject.Named;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import org.mxchange.jcontacts.contact.Contact;
+import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
+import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
+import org.mxchange.jcontacts.events.fax.linked.ObservableAdminLinkedFaxNumberEvent;
+import org.mxchange.jcontacts.events.landline.linked.ObservableAdminLinkedLandLineNumberEvent;
+import org.mxchange.jcontacts.events.mobile.linked.ObservableAdminLinkedMobileNumberEvent;
+import org.mxchange.jphone.events.fax.deleted.AdminDeletedFaxNumberEvent;
+import org.mxchange.jphone.events.fax.updated.AdminUpdatedFaxNumberEvent;
+import org.mxchange.jphone.events.landline.deleted.AdminDeletedLandLineNumberEvent;
+import org.mxchange.jphone.events.landline.updated.AdminUpdatedLandLineNumberEvent;
+import org.mxchange.jphone.events.mobile.deleted.AdminDeletedMobileNumberEvent;
+import org.mxchange.jphone.events.mobile.updated.AdminUpdatedMobileNumberEvent;
+import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
+import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
+import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
+import org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote;
+import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
+import org.mxchange.pizzaapplication.beans.BasePizzaController;
+
+/**
+ * Regular controller (bean) for phone numbers
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("phoneController")
+@ApplicationScoped
+public class PizzaPhoneWebApplicationBean extends BasePizzaController implements PizzaPhoneWebApplicationController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 491_058_674_675_690_105L;
+
+ /**
+ * All fax numbers
+ */
+ private final List<DialableFaxNumber> faxNumbers;
+
+ /**
+ * All land-line numbers
+ */
+ private final List<DialableLandLineNumber> landLineNumbers;
+
+ /**
+ * All mobile numbers
+ */
+ private final List<DialableMobileNumber> mobileNumbers;
+
+ /**
+ * General EJB for phone numbers
+ */
+ private PhoneSessionBeanRemote phoneBean;
+
+ /**
+ * Default constructor
+ */
+ public PizzaPhoneWebApplicationBean () {
+ // Try it
+ try {
+ // Get initial context
+ Context context = new InitialContext();
+
+ // Try to lookup the beans
+ this.phoneBean = (PhoneSessionBeanRemote) context.lookup("java:global/jjobs-ejb/phone!org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote"); //NOI18N
+ } catch (final NamingException e) {
+ // Throw it again
+ throw new FaceletException(e);
+ }
+
+ // Init all lists
+ this.mobileNumbers = new LinkedList<>();
+ this.faxNumbers = new LinkedList<>();
+ this.landLineNumbers = new LinkedList<>();
+ }
+
+ @Override
+ public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) {
+ // The event must be valid
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getAddedContact() == null) {
+ // Throw again ...
+ throw new NullPointerException("event.addedContact is null"); //NOI18N
+ } else if (event.getAddedContact().getContactId() == null) {
+ // ... and again
+ throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N
+ } else if (event.getAddedContact().getContactId() < 1) {
+ // Not valid
+ throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N
+ }
+
+ // Update contact's mobile, land-line and fax number
+ this.updateContactPhoneNumbers(event.getAddedContact());
+
+ // Clear this bean
+ this.clear();
+ }
+
+ @Override
+ public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
+ // event should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getAddedUser() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.addedUser is null"); //NOI18N
+ } else if (event.getAddedUser().getUserId() == null) {
+ // userId is null
+ throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
+ } else if (event.getAddedUser().getUserId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
+ }
+
+ // Update contact's mobile, land-line and fax number
+ this.updateContactPhoneNumbers(event.getAddedUser().getUserContact());
+
+ // Clear all data
+ this.clear();
+ }
+
+ @Override
+ public void afterAdminDeletedFaxNumberEvent (@Observes final AdminDeletedFaxNumberEvent event) {
+ // event should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getDeletedFaxNumber()== null) {
+ // Throw NPE again
+ throw new NullPointerException("event.deletedFaxNumber is null"); //NOI18N
+ } else if (event.getDeletedFaxNumber().getPhoneId() == null) {
+ // userId is null
+ throw new NullPointerException("event.deletedFaxNumber.phoneId is null"); //NOI18N
+ } else if (event.getDeletedFaxNumber().getPhoneId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getDeletedFaxNumber(), event.getDeletedFaxNumber().getPhoneId())); //NOI18N
+ }
+
+ // Update contact's mobile, land-line and fax number
+ this.allFaxNumbers().remove(event.getDeletedFaxNumber());
+
+ // Clear all data
+ this.clear();
+ }
+
+ @Override
+ public void afterAdminDeletedLandLineNumberEvent (@Observes final AdminDeletedLandLineNumberEvent event) {
+ // event should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getDeletedLandLineNumber()== null) {
+ // Throw NPE again
+ throw new NullPointerException("event.deletedLandLineNumber is null"); //NOI18N
+ } else if (event.getDeletedLandLineNumber().getPhoneId() == null) {
+ // userId is null
+ throw new NullPointerException("event.deletedLandLineNumber.phoneId is null"); //NOI18N
+ } else if (event.getDeletedLandLineNumber().getPhoneId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getDeletedLandLineNumber(), event.getDeletedLandLineNumber().getPhoneId())); //NOI18N
+ }
+
+ // Update contact's mobile, land-line and fax number
+ this.allLandLineNumbers().remove(event.getDeletedLandLineNumber());
+
+ // Clear all data
+ this.clear();
+ }
+
+ @Override
+ public void afterAdminDeletedMobileNumberEvent (@Observes final AdminDeletedMobileNumberEvent event) {
+ // event should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getDeletedMobileNumber()== null) {
+ // Throw NPE again
+ throw new NullPointerException("event.deletedMobileNumber is null"); //NOI18N
+ } else if (event.getDeletedMobileNumber().getPhoneId() == null) {
+ // userId is null
+ throw new NullPointerException("event.deletedMobileNumber.phoneId is null"); //NOI18N
+ } else if (event.getDeletedMobileNumber().getPhoneId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getDeletedMobileNumber(), event.getDeletedMobileNumber().getPhoneId())); //NOI18N
+ }
+
+ // Update contact's mobile, land-line and fax number
+ this.allMobileNumbers().remove(event.getDeletedMobileNumber());
+
+ // Clear all data
+ this.clear();
+ }
+
+ @Override
+ public void afterAdminLinkedFaxNumberEvent (@Observes final ObservableAdminLinkedFaxNumberEvent event) {
+ // Is the event fine?
+ if (event == null) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getContact() == null) {
+ // Throw again ...
+ throw new NullPointerException("event.contact is null");
+ } else if (event.getContact().getContactId() == null) {
+ // Throw again ...
+ throw new NullPointerException("event.contact.contactId is null");
+ } else if (event.getContact().getContactId() < 1) {
+ // Throw again ...
+ throw new NullPointerException("event.contact.contactId="+ event.getContact().getContactId() + " is invalid");
+ } else if (event.getContact().getContactFaxNumber() == null) {
+ // Throw again ...
+ throw new NullPointerException("event.contact.contactFaxNumber is null");
+ } else if (event.getContact().getContactFaxNumber().getPhoneId() == null) {
+ // Throw again ...
+ throw new NullPointerException("event.contact.contactFaxNumber.phoneId is null");
+ } else if (event.getContact().getContactFaxNumber().getPhoneId() < 1) {
+ // Throw again ...
+ throw new NullPointerException("event.contact.contactFaxNumber.phoneId="+event.getContact().getContactFaxNumber().getPhoneId() + " is invalid");
+ } else if (event.getLinkedFaxNumber() == null) {
+ // Throw again ...
+ throw new NullPointerException("event.linkedFaxNumer is null");
+ }
+
+ // Is the id number in linked number not set?
+ if (event.getLinkedFaxNumber().getPhoneId() == null) {
+ // Then it is a new number, so add it from contact as there the id number has been set
+ this.uniqueAddFaxNumber(event.getContact().getContactFaxNumber());
+ }
+ }
+
+ @Override
+ public void afterAdminLinkedLandLineNumberEvent (@Observes final ObservableAdminLinkedLandLineNumberEvent event) {
+ // Is the event fine?
+ if (event == null) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getContact() == null) {
+ // Throw again ...
+ throw new NullPointerException("event.contact is null");
+ } else if (event.getContact().getContactId() == null) {
+ // Throw again ...
+ throw new NullPointerException("event.contact.contactId is null");
+ } else if (event.getContact().getContactId() < 1) {
+ // Throw again ...
+ throw new NullPointerException("event.contact.contactId="+ event.getContact().getContactId() + " is invalid");
+ } else if (event.getContact().getContactLandLineNumber() == null) {
+ // Throw again ...
+ throw new NullPointerException("event.contact.contactLandLineNumber is null");
+ } else if (event.getContact().getContactLandLineNumber().getPhoneId() == null) {
+ // Throw again ...
+ throw new NullPointerException("event.contact.contactLandLineNumber.phoneId is null");
+ } else if (event.getContact().getContactLandLineNumber().getPhoneId() < 1) {
+ // Throw again ...
+ throw new NullPointerException("event.contact.contactLandLineNumber.phoneId="+event.getContact().getContactLandLineNumber().getPhoneId() + " is invalid");
+ } else if (event.getLinkedLandLineNumber() == null) {
+ // Throw again ...
+ throw new NullPointerException("event.linkedLandLineNumer is null");
+ }
+
+ // Is the id number in linked number not set?
+ if (event.getLinkedLandLineNumber().getPhoneId() == null) {
+ // Then it is a new number, so add it from contact as there the id number has been set
+ this.uniqueAddLandLineNumber(event.getContact().getContactLandLineNumber());
+ }
+ }
+
+ @Override
+ public void afterAdminLinkedMobileNumberEvent (@Observes final ObservableAdminLinkedMobileNumberEvent event) {
+ // Is the event fine?
+ if (event == null) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getContact() == null) {
+ // Throw again ...
+ throw new NullPointerException("event.contact is null");
+ } else if (event.getContact().getContactId() == null) {
+ // Throw again ...
+ throw new NullPointerException("event.contact.contactId is null");
+ } else if (event.getContact().getContactId() < 1) {
+ // Throw again ...
+ throw new NullPointerException("event.contact.contactId="+ event.getContact().getContactId() + " is invalid");
+ } else if (event.getContact().getContactMobileNumber() == null) {
+ // Throw again ...
+ throw new NullPointerException("event.contact.contactMobileNumber is null");
+ } else if (event.getContact().getContactMobileNumber().getPhoneId() == null) {
+ // Throw again ...
+ throw new NullPointerException("event.contact.contactMobileNumber.phoneId is null");
+ } else if (event.getContact().getContactMobileNumber().getPhoneId() < 1) {
+ // Throw again ...
+ throw new NullPointerException("event.contact.contactMobileNumber.phoneId="+event.getContact().getContactMobileNumber().getPhoneId() + " is invalid");
+ } else if (event.getLinkedMobileNumber() == null) {
+ // Throw again ...
+ throw new NullPointerException("event.linkedMobileNumer is null");
+ }
+
+ // Is the id number in linked number not set?
+ if (event.getLinkedMobileNumber().getPhoneId() == null) {
+ // Then it is a new number, so add it from contact as there the id number has been set
+ this.uniqueAddMobileNumber(event.getContact().getContactMobileNumber());
+ }
+ }
+
+ @Override
+ public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) {
+ // event should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getUpdatedContact() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.updatedContact is null"); //NOI18N
+ } else if (event.getUpdatedContact().getContactId() == null) {
+ // userId is null
+ throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
+ } else if (event.getUpdatedContact().getContactId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
+ }
+
+ // Update contact's mobile, land-line and fax number
+ this.updateContactPhoneNumbers(event.getUpdatedContact());
+
+ // Clear all data
+ this.clear();
+ }
+
+ @Override
+ public void afterAdminUpdatedFaxNumberEvent (@Observes final AdminUpdatedFaxNumberEvent event) {
+ // event should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getUpdatedFaxNumber()== null) {
+ // Throw NPE again
+ throw new NullPointerException("event.updatedFaxNumber is null"); //NOI18N
+ } else if (event.getUpdatedFaxNumber().getPhoneId() == null) {
+ // userId is null
+ throw new NullPointerException("event.updatedFaxNumber.phoneId is null"); //NOI18N
+ } else if (event.getUpdatedFaxNumber().getPhoneId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getUpdatedFaxNumber(), event.getUpdatedFaxNumber().getPhoneId())); //NOI18N
+ }
+
+ // Uniquely add it
+ this.uniqueAddFaxNumber(event.getUpdatedFaxNumber());
+
+ // Clear it
+ this.clear();
+ }
+
+ @Override
+ public void afterAdminUpdatedLandLineNumberEvent (@Observes final AdminUpdatedLandLineNumberEvent event) {
+ // event should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getUpdatedLandLineNumber()== null) {
+ // Throw NPE again
+ throw new NullPointerException("event.updatedLandLineNumber is null"); //NOI18N
+ } else if (event.getUpdatedLandLineNumber().getPhoneId() == null) {
+ // userId is null
+ throw new NullPointerException("event.updatedLandLineNumber.phoneId is null"); //NOI18N
+ } else if (event.getUpdatedLandLineNumber().getPhoneId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getUpdatedLandLineNumber(), event.getUpdatedLandLineNumber().getPhoneId())); //NOI18N
+ }
+
+ // Uniquely add it
+ this.uniqueAddLandLineNumber(event.getUpdatedLandLineNumber());
+
+ // Clear it
+ this.clear();
+ }
+
+ @Override
+ public void afterAdminUpdatedMobileNumberEvent (@Observes final AdminUpdatedMobileNumberEvent event) {
+ // event should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getUpdatedMobileNumber()== null) {
+ // Throw NPE again
+ throw new NullPointerException("event.updatedMobileNumber is null"); //NOI18N
+ } else if (event.getUpdatedMobileNumber().getPhoneId() == null) {
+ // userId is null
+ throw new NullPointerException("event.updatedMobileNumber.phoneId is null"); //NOI18N
+ } else if (event.getUpdatedMobileNumber().getPhoneId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getUpdatedMobileNumber(), event.getUpdatedMobileNumber().getPhoneId())); //NOI18N
+ }
+
+ // Uniquely add it
+ this.uniqueAddMobileNumber(event.getUpdatedMobileNumber());
+
+ // Clear it
+ this.clear();
+ }
+
+ @Override
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<DialableFaxNumber> allFaxNumbers () {
+ return this.faxNumbers;
+ }
+
+ @Override
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<DialableLandLineNumber> allLandLineNumbers () {
+ return this.landLineNumbers;
+ }
+
+ @Override
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<DialableMobileNumber> allMobileNumbers () {
+ return this.mobileNumbers;
+ }
+
+ /**
+ * Post-construction method
+ */
+ @PostConstruct
+ public void init () {
+ // All phone numbers
+ this.allMobileNumbers().addAll(this.phoneBean.allMobileNumbers());
+ this.allFaxNumbers().addAll(this.phoneBean.allFaxNumbers());
+ this.allLandLineNumbers().addAll(this.phoneBean.allLandLineNumbers());
+ }
+
+ /**
+ * Clears this bean
+ */
+ private void clear () {
+ // Clear all data
+ }
+
+ /**
+ * Uniquely add given fax number to this bean's list. First remove the old
+ * instance (by id number), then re-add it again.
+ * <p>
+ * @param faxNumber number to add
+ */
+ private void uniqueAddFaxNumber (final DialableFaxNumber faxNumber) {
+ // Make sure the parameter is valid
+ if (null == faxNumber) {
+ // Throw NPE
+ throw new NullPointerException("faxNumber is null");
+ } else if (faxNumber.getPhoneId() == null) {
+ // Throw again ...
+ throw new NullPointerException("faxNumber.phoneId is null");
+ } else if (faxNumber.getPhoneId() < 1) {
+ // Not valid
+ throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid.", faxNumber.getPhoneId()));
+ }
+
+ // First remove it
+ if (!this.allFaxNumbers().remove(faxNumber)) {
+ // Did not work, try by id number
+ for (final DialableFaxNumber fax : this.allFaxNumbers()) {
+ // Is id number the same?
+ if (Objects.equals(fax.getPhoneId(), faxNumber.getPhoneId())) {
+ // Found it
+ this.allFaxNumbers().remove(fax);
+ break;
+ }
+ }
+ }
+
+ // ... then add it
+ this.allFaxNumbers().add(faxNumber);
+ }
+
+ /**
+ * Uniquely add given land-line number to this bean's list. First remove the
+ * old instance (by id number), then re-add it again.
+ * <p>
+ * @param landLineNumber Land-line number to add
+ */
+ private void uniqueAddLandLineNumber (final DialableLandLineNumber landLineNumber) {
+ // Make sure the parameter is valid
+ if (null == landLineNumber) {
+ // Throw NPE
+ throw new NullPointerException("landLineNumber is null");
+ } else if (landLineNumber.getPhoneId() == null) {
+ // Throw again ...
+ throw new NullPointerException("landLineNumber.phoneId is null");
+ } else if (landLineNumber.getPhoneId() < 1) {
+ // Not valid
+ throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid.", landLineNumber.getPhoneId()));
+ }
+
+ // First remove it
+ if (!this.allLandLineNumbers().remove(landLineNumber)) {
+ // Did not work, try by id number
+ for (final DialableLandLineNumber landLine : this.allLandLineNumbers()) {
+ // Is id number the same?
+ if (Objects.equals(landLine.getPhoneId(), landLineNumber.getPhoneId())) {
+ // Found it
+ this.allLandLineNumbers().remove(landLine);
+ break;
+ }
+ }
+ }
+
+ // ... then add it
+ this.allLandLineNumbers().add(landLineNumber);
+ }
+
+ /**
+ * Uniquely add given mobile number to this bean's list. First remove the
+ * old instance (by id number), then re-add it again.
+ * <p>
+ * @param mobileNumber Mobile number to add
+ */
+ private void uniqueAddMobileNumber (final DialableMobileNumber mobileNumber) {
+ // Make sure the parameter is valid
+ if (null == mobileNumber) {
+ // Throw NPE
+ throw new NullPointerException("mobileNumber is null");
+ } else if (mobileNumber.getPhoneId() == null) {
+ // Throw again ...
+ throw new NullPointerException("mobileNumber.phoneId is null");
+ } else if (mobileNumber.getPhoneId() < 1) {
+ // Not valid
+ throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid.", mobileNumber.getPhoneId()));
+ }
+
+ // First remove it by object
+ if (!this.allMobileNumbers().remove(mobileNumber)) {
+ // Did not work, try by id number
+ for (final DialableMobileNumber cell : this.allMobileNumbers()) {
+ // Is id number the same?
+ if (Objects.equals(cell.getPhoneId(), mobileNumber.getPhoneId())) {
+ // Found it
+ this.allMobileNumbers().remove(cell);
+ break;
+ }
+ }
+ }
+
+ // ... then add it
+ this.allMobileNumbers().add(mobileNumber);
+ }
+
+ /**
+ * Updates given contact's mobile, land-line and fax number
+ * <p>
+ * @param contact Contact instance
+ */
+ private void updateContactPhoneNumbers (final Contact contact) {
+ // Parameter must be valid
+ if (null == contact) {
+ // Throw NPE
+ throw new NullPointerException("contact is null");
+ } else if (contact.getContactId() == null) {
+ // Throw again
+ throw new NullPointerException("contact.contactId is null");
+ } else if (contact.getContactId() < 1) {
+ // Id number is not valid
+ }
+
+ // Is mobile set?
+ if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
+ // Unique-add it
+ this.uniqueAddMobileNumber(contact.getContactMobileNumber());
+ }
+
+ // Is land-line set?
+ if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
+ // Unique-add it
+ this.uniqueAddLandLineNumber(contact.getContactLandLineNumber());
+ }
+
+ // Is fax set?
+ if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
+ // Unique-add it
+ this.uniqueAddFaxNumber(contact.getContactFaxNumber());
+ }
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2016 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.pizzaapplication.beans.phone;
+
+import java.io.Serializable;
+import java.util.List;
+import javax.ejb.Local;
+import org.mxchange.jphone.events.fax.deleted.AdminDeletedFaxNumberEvent;
+import org.mxchange.jphone.events.fax.updated.AdminUpdatedFaxNumberEvent;
+import org.mxchange.jphone.events.landline.deleted.AdminDeletedLandLineNumberEvent;
+import org.mxchange.jphone.events.landline.updated.AdminUpdatedLandLineNumberEvent;
+import org.mxchange.jphone.events.mobile.deleted.AdminDeletedMobileNumberEvent;
+import org.mxchange.jphone.events.mobile.updated.AdminUpdatedMobileNumberEvent;
+import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
+import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
+import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
+import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
+import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
+import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
+import org.mxchange.jcontacts.events.fax.linked.ObservableAdminLinkedFaxNumberEvent;
+import org.mxchange.jcontacts.events.landline.linked.ObservableAdminLinkedLandLineNumberEvent;
+import org.mxchange.jcontacts.events.mobile.linked.ObservableAdminLinkedMobileNumberEvent;
+
+/**
+ * An interface for a request web controller (bean) for administrative phone
+ * number purposes.
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Local
+public interface PizzaPhoneWebApplicationController extends Serializable {
+
+ /**
+ * Event observer for newly added users by adminstrator
+ * <p>
+ * @param event Event being fired
+ */
+ void afterAdminAddedUserEvent (final ObservableAdminAddedUserEvent event);
+
+ /**
+ * Observes events being fired when an administrator has added a new
+ * contact.
+ * <p>
+ * @param event Event being fired
+ */
+ void afterAdminAddedContactEvent (final ObservableAdminAddedContactEvent event);
+
+ /**
+ * Observes events being fired when an administrator has deleted a fax
+ * number
+ * <p>
+ * @param event Event being fired
+ */
+ void afterAdminDeletedFaxNumberEvent (final AdminDeletedFaxNumberEvent event);
+
+ /**
+ * Observes events being fired when an administrator has deleted a land-line
+ * number
+ * <p>
+ * @param event Event being fired
+ */
+ void afterAdminDeletedLandLineNumberEvent (final AdminDeletedLandLineNumberEvent event);
+
+ /**
+ * Observes events being fired when an administrator has deleted a mobile
+ * number
+ * <p>
+ * @param event Event being fired
+ */
+ void afterAdminDeletedMobileNumberEvent (final AdminDeletedMobileNumberEvent event);
+
+ /**
+ * Observes events being fired when an administrator has a linked a fax
+ * number
+ * <p>
+ * @param event Event being fired
+ */
+ void afterAdminLinkedFaxNumberEvent (final ObservableAdminLinkedFaxNumberEvent event);
+
+ /**
+ * Observes events being fired when an administrator has a linked a
+ * land-line number
+ * <p>
+ * @param event Event being fired
+ */
+ void afterAdminLinkedLandLineNumberEvent (final ObservableAdminLinkedLandLineNumberEvent event);
+
+ /**
+ * Observes events being fired when an administrator has a linked a mobile
+ * number
+ * <p>
+ * @param event Event being fired
+ */
+ void afterAdminLinkedMobileNumberEvent (final ObservableAdminLinkedMobileNumberEvent event);
+
+ /**
+ * Observes events being fired when an administrator has updated a fax
+ * number.
+ * <p>
+ * @param event Event being fired
+ */
+ void afterAdminUpdatedFaxNumberEvent (final AdminUpdatedFaxNumberEvent event);
+
+ /**
+ * Observes events being fired when an administrator has updated a land-line
+ * number.
+ * <p>
+ * @param event Event being fired
+ */
+ void afterAdminUpdatedLandLineNumberEvent (final AdminUpdatedLandLineNumberEvent event);
+
+ /**
+ * Observes events being fired when an administrator has updated a mobile
+ * number.
+ * <p>
+ * @param event Event being fired
+ */
+ void afterAdminUpdatedMobileNumberEvent (final AdminUpdatedMobileNumberEvent event);
+
+ /**
+ * Event observer for updated contact data by administrators
+ * <p>
+ * @param event Updated contact data event
+ */
+ void afterAdminUpdatedContactDataEvent (final ObservableAdminUpdatedContactEvent event);
+
+ /**
+ * Returns a list of all mobile numbers. For performance reasons, the
+ * controller (bean) should be application-scoped as from user to user
+ * nothing changes. And the controller's post-construct method should load
+ * all numbers and cache it in the controller.
+ * <p>
+ * @return List of all mobile numbers
+ */
+ List<DialableMobileNumber> allMobileNumbers ();
+
+ /**
+ * Returns a list of all fax numbers. For performance reasons, the
+ * controller (bean) should be application-scoped as from user to user
+ * nothing changes. And the controller's post-construct method should load
+ * all numbers and cache it in the controller.
+ * <p>
+ * @return List of all fax numbers
+ */
+ List<DialableFaxNumber> allFaxNumbers ();
+
+ /**
+ * Returns a list of all land-line numbers. For performance reasons, the
+ * controller (bean) should be application-scoped as from user to user
+ * nothing changes. And the controller's post-construct method should load
+ * all numbers and cache it in the controller.
+ * <p>
+ * @return List of all land-line numbers
+ */
+ List<DialableLandLineNumber> allLandLineNumbers ();
+
+}
import javax.naming.NamingException;
import org.mxchange.jshopcore.model.receipt.ReceiptBeanRemote;
import org.mxchange.pizzaapplication.beans.BasePizzaController;
-import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestController;
+import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestHelperController;
/**
* Checkout controller
* Bean helper instance
*/
@Inject
- private PizzaWebRequestController beanHelper;
+ private PizzaWebRequestHelperController beanHelper;
/**
* Remote bean instance
private PizzaFeaturesWebApplicationController featureController;
/**
- * Reemote register session bean
+ * Remote register session bean
*/
private UserRegistrationSessionBeanRemote registerBean;
}
// Now only redirect to next page as the JSF does it
- return "register_page2"; //NOI18N
+ return "user_register_page2"; //NOI18N
}
}
import org.mxchange.jusercore.events.registration.ObservableUserRegisteredEvent;
import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
+import org.mxchange.jusercore.events.user.delete.AdminDeletedUserEvent;
+import org.mxchange.jusercore.events.user.delete.ObservableAdminDeletedUserEvent;
import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent;
import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent;
+import org.mxchange.jusercore.events.user.locked.AdminLockedUserEvent;
+import org.mxchange.jusercore.events.user.locked.ObservableAdminLockedUserEvent;
+import org.mxchange.jusercore.events.user.unlocked.AdminUnlockedUserEvent;
+import org.mxchange.jusercore.events.user.unlocked.ObservableAdminUnlockedUserEvent;
import org.mxchange.jusercore.events.user.update.AdminUpdatedUserDataEvent;
import org.mxchange.jusercore.events.user.update.ObservableAdminUpdatedUserDataEvent;
import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException;
import org.mxchange.pizzaapplication.beans.BasePizzaController;
import org.mxchange.pizzaapplication.beans.contact.PizzaAdminContactWebRequestController;
import org.mxchange.pizzaapplication.beans.contact.PizzaContactWebSessionController;
-import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestController;
+import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestHelperController;
+import org.mxchange.pizzaapplication.beans.localization.PizzaLocalizationSessionController;
/**
* Administrative user bean (controller)
private final AdminUserSessionBeanRemote adminUserBean;
/**
- * Bean helper instance
+ * Bean helper
*/
@Inject
- private PizzaWebRequestController beanHelper;
+ private PizzaWebRequestHelperController beanHelper;
/**
* Regular contact controller
@Inject
private PizzaContactWebSessionController contactController;
+ /**
+ * Event being fired when admin has deleted user
+ */
+ @Inject
+ @Any
+ private Event<ObservableAdminDeletedUserEvent> deleteUserEvent;
+
+ /**
+ * Localization controller
+ */
+ @Inject
+ private PizzaLocalizationSessionController localizationController;
+
/**
* An event fired when the administrator has updated a new user
*/
@Inject
private PizzaUserWebSessionController userController;
+ /**
+ * Delete reason
+ */
+ private String userDeleteReason;
+
/**
* An event fired when the administrator has linked a user with existing
* contact data.
*/
private String userLockReason;
+ /**
+ * Event being fired when an administrator has locked a user
+ */
+ @Inject
+ @Any
+ private Event<ObservableAdminLockedUserEvent> userLockedEvent;
+
/**
* Flag whether user must change password after login
*/
private String userName;
/**
- * User password (unencrypted from web form)
+ * User password (clear-text from web form)
*/
private String userPassword;
/**
- * User password repeated (unencrypted from web form)
+ * User password repeated (clear-text from web form)
*/
private String userPasswordRepeat;
+ /**
+ * Event being fired when admin unlocks an account
+ */
+ @Inject
+ @Any
+ private Event<ObservableAdminUnlockedUserEvent> userUnlockedEvent;
+
/**
* Default constructor
*/
Context context = new InitialContext();
// Try to lookup
- this.userBean = (UserSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N
- this.adminUserBean = (AdminUserSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/adminUser!org.mxchange.jusercore.model.user.AdminUserSessionBeanRemote"); //NOI18N
+ this.userBean = (UserSessionBeanRemote) context.lookup("java:global/jjobs-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N
+ this.adminUserBean = (AdminUserSessionBeanRemote) context.lookup("java:global/jjobs-ejb/adminUser!org.mxchange.jusercore.model.user.AdminUserSessionBeanRemote"); //NOI18N
} catch (final NamingException e) {
// Throw again
throw new FaceletException(e);
@Override
public String addUser () {
- // Create new user instance
- User user = new LoginUser();
-
// As the form cannot validate the data (required="true"), check it here
if (this.getUserName() == null) {
// Throw NPE
throw new NullPointerException("contactController.gender is null"); //NOI18N
} else if (this.contactController.getFirstName() == null) {
// ... and again
- throw new NullPointerException("contactController.firstName is null"); //NOI18N //NOI18N
- } else if (this.contactController.getFirstName().isEmpty()) {
+ throw new NullPointerException("contactController.firstName is null"); //NOI18N
+ } else if (this.adminContactController.getFirstName().isEmpty()) {
// ... and again
throw new IllegalArgumentException("contactController.firstName is empty"); //NOI18N
} else if (this.adminContactController.getFamilyName() == null) {
throw new NullPointerException("contactController.familyName is null"); //NOI18N
} else if (this.contactController.getFamilyName().isEmpty()) {
// ... and again
- throw new IllegalArgumentException("contactController.familyName is empty"); //NOI18N //NOI18N
- } else if (this.contactController.getEmailAddress() == null) {
+ throw new IllegalArgumentException("contactController.familyName is empty"); //NOI18N
+ } else if (this.adminContactController.getEmailAddress() == null) {
// ... and again
throw new NullPointerException("contactController.emailAddress is null"); //NOI18N
} else if (this.adminContactController.getEmailAddress().isEmpty()) {
// ... and again
- throw new IllegalArgumentException("contactController.emailAddress is empty"); //NOI18N //NOI18N
- } else if (this.contactController.getEmailAddressRepeat() == null) {
- // ... and again
- throw new NullPointerException("contactController.emailAddressRepeat is null");
- } else if (this.contactController.getEmailAddressRepeat().isEmpty()) {
- // ... and again
- throw new IllegalArgumentException("contactController.emailAddressRepeat is empty"); //NOI18N //NOI18N
- } else if (!Objects.equals(this.contactController.getEmailAddress(), this.contactController.getEmailAddressRepeat())) {
- // Is not same email address
- throw new IllegalArgumentException("Both entered email addresses don't match.");
+ throw new IllegalArgumentException("contactController.emailAddress is empty"); //NOI18N
}
}
+ // Create new user instance
+ User user = new LoginUser();
+
// Set user name, CONFIRMED and INVISIBLE
user.setUserName(this.getUserName());
+ user.setUserMustChangePassword(this.getUserMustChangePassword());
user.setUserAccountStatus(UserAccountStatus.CONFIRMED);
user.setUserProfileMode(ProfileMode.INVISIBLE);
throw new FaceletException(new UserNameAlreadyRegisteredException(user));
} else if ((this.beanHelper.getContact() == null) && (this.contactController.isEmailAddressRegistered(user.getUserContact()))) {
// Email address is already used
- throw new FaceletException(new EmailAddressAlreadyRegisteredException(user));
+ this.showFacesMessage("admin_add_user:emailAddress", "ERROR_EMAIL_ADDRESS_ALREADY_USED"); //NOI18N
+
+ // Always clear password
+ this.setUserPassword(null);
+ this.setUserPasswordRepeat(null);
+
+ // Skip it
+ return ""; //NOI18N
} else if ((this.getUserPassword() == null && (this.getUserPasswordRepeat() == null)) || ((this.getUserPassword().isEmpty()) && (this.getUserPasswordRepeat().isEmpty()))) {
// Empty password entered, then generate one
password = UserUtils.createRandomPassword(PizzaUserWebSessionController.MINIMUM_PASSWORD_LENGTH);
throw new FaceletException(ex);
}
+ // Clear helper
+ this.beanHelper.setContact(null);
+
// Clear this bean
this.clear();
return "admin_list_user"; //NOI18N
}
- @Override
- public void afterRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) {
+ /**
+ * Event observer for new user registrations
+ * <p>
+ * @param event User registration event
+ */
+ public void afterUserRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) {
// event should not be null
if (null == event) {
// Throw NPE
User registeredUser = event.getRegisteredUser();
// @TODO Nothing to do with the user here?
-
// Clear all data
this.clear();
}
+ @Override
+ public String deleteUserData (final User user) {
+ // Is the user instance valid and CONFIRMED?
+ if (null == user) {
+ // Throw NPE
+ throw new NullPointerException("user is null"); //NOI18N
+ } else if (user.getUserId() == null) {
+ // Throw again
+ throw new NullPointerException("user.userId is null"); //NOI18N
+ } else if (user.getUserId() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N
+ }
+
+ try {
+ // All fine, delete it
+ this.adminUserBean.deleteUser(user, this.getUserDeleteReason());
+ } catch (final UserNotFoundException ex) {
+ // Should not happen, so throw again
+ throw new FaceletException(ex);
+ }
+
+ // Fire event
+ this.deleteUserEvent.fire(new AdminDeletedUserEvent(user, this.getUserDeleteReason()));
+
+ // Redirect
+ return "admin_list_user"; //NOI18N
+ }
+
@Override
public String editUserData () {
// Get user instance
throw new NullPointerException("beanHelper.user is null"); //NOI18N
} else if (user.getUserId() == null) {
// Throw NPE again
- throw new NullPointerException("beanHelper.user.userId is null"); //NOI18N //NOI18N
+ throw new NullPointerException("beanHelper.user.userId is null"); //NOI18N
} else if (user.getUserId() < 1) {
// Invalid id
- throw new IllegalStateException(MessageFormat.format("beanHelper.user.userId={0} is invalid", user.getUserId())); //NOI18N //NOI18N
+ throw new IllegalStateException(MessageFormat.format("beanHelper.user.userId={0} is invalid", user.getUserId())); //NOI18N
} else if (this.getUserName() == null) {
// Not all required fields are set
throw new NullPointerException("this.userName is null"); //NOI18N
// Not all required fields are set
throw new IllegalArgumentException("this.userName is empty"); //NOI18N
} else if (((!this.getUserPassword().isEmpty()) || (!this.getUserPasswordRepeat().isEmpty())) && (!this.isSamePasswordEntered())) {
- // Not same password entered
+ // Clear password fields
this.setUserPassword(null);
this.setUserPasswordRepeat(null);
- // Throw exception
- throw new FaceletException("Not same password entered"); //NOI18N
- } else if (this.userBean.ifUserNameExists(this.getUserName())) {
+ // Not same password entered
+ this.showFacesMessage("form_edit_user:userPassword", "ADMIN_USER_PASSWORD_REPEAT_DIFFERENT"); //NOI18N
+ return ""; //NOI18N
+ } else if ((!Objects.equals(user.getUserName(), this.getUserName())) && (this.userBean.ifUserNameExists(this.getUserName()))) {
+ // Clear all fields
+ this.clear();
+
// User name already exists
- throw new FaceletException(new UserNameAlreadyRegisteredException(this.getUserName()));
+ this.showFacesMessage("form_edit_user:userName", "ADMIN_USER_NAME_ALREADY_EXISTS"); //NOI18N
+ return ""; //NOI18N
} else if (this.isSamePasswordEntered()) {
// Same password entered, create container
- if (UserUtils.ifPasswordMatches(new UserLoginContainer(user, this.getUserPassword()))) {
+ if ((Objects.equals(user.getUserMustChangePassword(), this.getUserMustChangePassword())) && (UserUtils.ifPasswordMatches(new UserLoginContainer(user, this.getUserPassword())))) {
+ // Clear password fields
+ this.setUserPassword(null);
+ this.setUserPasswordRepeat(null);
+
// Same password entered
- throw new FaceletException("Same password as stored entered."); //NOI18N
+ this.showFacesMessage("form_edit_user:userPassword", "ADMIN_USER_ENTERED_SAME_AS_OLD_PASSWORD"); //NOI18N
+ return ""; //NOI18N
}
// Encrypt password
return "admin_list_user"; //NOI18N
}
+ @Override
+ public String getUserDeleteReason () {
+ return this.userDeleteReason;
+ }
+
+ @Override
+ public void setUserDeleteReason (final String userDeleteReason) {
+ this.userDeleteReason = userDeleteReason;
+ }
+
@Override
public String getUserLockReason () {
return this.userLockReason;
throw new IllegalArgumentException("this.userLockReason is empty"); //NOI18N
}
+ // Init updated user instance
+ User updatedUser;
+
try {
// Get base URL
String baseUrl = FacesUtils.generateBaseUrl();
// Call EJB to lock account
- this.adminUserBean.lockUserAccount(user, this.getUserLockReason(), baseUrl);
+ updatedUser = this.adminUserBean.lockUserAccount(user, this.getUserLockReason(), baseUrl);
} catch (final UserStatusLockedException | UserStatusUnconfirmedException | UserNotFoundException ex) {
// Throw again
throw new FaceletException(ex);
}
+ // Fire event
+ this.userLockedEvent.fire(new AdminLockedUserEvent(updatedUser));
+
+ // Clear bean
+ this.clear();
+
// Should go fine at this point, redirect to user profile
- return "admin_show_user?faces-redirect=true&includeViewParams=true"; //NOI18N
+ return "admin_show_user"; //NOI18N
}
@Override
throw new FaceletException(new UserStatusUnconfirmedException(user));
}
+ // Init updated user instance
+ User updatedUser;
+
try {
// Get base URL
String baseUrl = FacesUtils.generateBaseUrl();
// Call EJB to unlock account
- this.adminUserBean.unlockUserAccount(user, baseUrl);
+ updatedUser = this.adminUserBean.unlockUserAccount(user, baseUrl);
} catch (final UserStatusConfirmedException | UserStatusUnconfirmedException | UserNotFoundException ex) {
// Throw again
throw new FaceletException(ex);
}
+ // Fire event
+ this.userUnlockedEvent.fire(new AdminUnlockedUserEvent(updatedUser));
+
+ // Clear bean
+ this.clear();
+
// Should go fine at this point, redirect to user profile
- return "admin_show_user?faces-redirect=true&includeViewParams=true"; //NOI18N
+ return "admin_show_user"; //NOI18N
}
/**
import java.io.Serializable;
import org.mxchange.jusercore.model.user.User;
-import org.mxchange.jusercore.events.registration.ObservableUserRegisteredEvent;
/**
* An interface for user beans
*/
public interface PizzaAdminUserWebRequestController extends Serializable {
- /**
- * Event observer for new user registrations
- * <p>
- * @param event User registration event
- */
- void afterRegistrationEvent (final ObservableUserRegisteredEvent event);
-
/**
* Adds user instance to database by preparing a complete user instance and
* sending it to the EJB. The data set in the controller is being verified,
*/
String addUser ();
+ /**
+ * Deletes given user account
+ * <p>
+ * @param user User instance to delete
+ * <p>
+ * @return Redirect outcome
+ */
+ String deleteUserData (final User user);
+
/**
* Edits currently loaded user's data in database.
* <p>
void setUserName (final String userName);
/**
- * Getter for unencrypted user password
+ * Getter for clear-text user password
* <p>
- * @return Unencrypted user password
+ * @return Clear-text user password
*/
String getUserPassword ();
/**
- * Setter for unencrypted user password
+ * Setter for clear-text user password
* <p>
- * @param userPassword Unencrypted user password
+ * @param userPassword Clear-text user password
*/
void setUserPassword (final String userPassword);
/**
- * Getter for unencrypted user password repeated
+ * Getter for clear-text user password repeated
* <p>
- * @return Unencrypted user password repeated
+ * @return Clear-text user password repeated
*/
String getUserPasswordRepeat ();
/**
- * Setter for unencrypted user password repeated
+ * Setter for clear-text user password repeated
* <p>
- * @param userPasswordRepeat Unencrypted user password repeated
+ * @param userPasswordRepeat Clear-text user password repeated
*/
void setUserPasswordRepeat (final String userPasswordRepeat);
*/
void setUserLockReason (final String userLockReason);
+ /**
+ * Getter for user delete reason
+ * <p>
+ * @return User delete reason
+ */
+ String getUserDeleteReason ();
+
+ /**
+ * Setter for user delete reason
+ * <p>
+ * @param userDeleteReason User delete reason
+ */
+ void setUserDeleteReason (final String userDeleteReason);
+
}
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.mxchange.jcontacts.contact.Contact;
-import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
+import org.mxchange.jusercore.events.confirmation.ObservableUserConfirmedAccountEvent;
+import org.mxchange.jusercore.events.login.ObservableUserLoggedInEvent;
+import org.mxchange.jusercore.events.registration.ObservableUserRegisteredEvent;
+import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
+import org.mxchange.jusercore.events.user.delete.ObservableAdminDeletedUserEvent;
+import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent;
+import org.mxchange.jusercore.events.user.locked.ObservableAdminLockedUserEvent;
+import org.mxchange.jusercore.events.user.password_change.ObservableUpdatedUserPasswordEvent;
+import org.mxchange.jusercore.events.user.unlocked.ObservableAdminUnlockedUserEvent;
+import org.mxchange.jusercore.events.user.update.ObservableAdminUpdatedUserDataEvent;
+import org.mxchange.jusercore.events.user.update.ObservableUpdatedUserPersonalDataEvent;
import org.mxchange.jusercore.events.user.update.UpdatedUserPersonalDataEvent;
import org.mxchange.jusercore.exceptions.UserEmailAddressNotFoundException;
import org.mxchange.jusercore.exceptions.UserNotFoundException;
import org.mxchange.pizzaapplication.beans.BasePizzaController;
import org.mxchange.pizzaapplication.beans.contact.PizzaContactWebSessionController;
import org.mxchange.pizzaapplication.beans.features.PizzaFeaturesWebApplicationController;
-import org.mxchange.pizzaapplication.beans.localization.PizzaLocalizationSessionController;
import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController;
-import org.mxchange.jusercore.events.confirmation.ObservableUserConfirmedAccountEvent;
-import org.mxchange.jusercore.events.login.ObservableUserLoggedInEvent;
-import org.mxchange.jusercore.events.registration.ObservableUserRegisteredEvent;
-import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
-import org.mxchange.jusercore.events.user.password_change.ObservableUpdatedUserPasswordEvent;
-import org.mxchange.jusercore.events.user.update.ObservableAdminUpdatedUserDataEvent;
-import org.mxchange.jusercore.events.user.update.ObservableUpdatedUserPersonalDataEvent;
/**
* A user bean (controller)
*/
private static final long serialVersionUID = 542_145_347_916L;
- /**
- * Contact EJB
- */
- private ContactSessionBeanRemote contactBean;
-
/**
* General contact controller
*/
@Inject
private PizzaFeaturesWebApplicationController featureController;
- /**
- * Localization controller
- */
- @Inject
- private PizzaLocalizationSessionController localizationController;
-
/**
* Event being fired when user updated personal data
*/
private List<User> userList;
/**
- * Login bean (controller)
+ * Login controller (bean)
*/
@Inject
private PizzaUserLoginWebSessionController userLoginController;
private List<String> userNameList;
/**
- * User password (unencrypted from web form)
+ * User password (clear-text from web form)
*/
private String userPassword;
/**
- * User password repeated (unencrypted from web form)
+ * User password repeated (clear-text from web form)
*/
private String userPasswordRepeat;
Context context = new InitialContext();
// Try to lookup
- this.userBean = (UserSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N
-
- // Try to lookup
- this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
+ this.userBean = (UserSessionBeanRemote) context.lookup("java:global/jrecruiter-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N
} catch (final NamingException e) {
// Throw again
throw new FaceletException(e);
}
}
- @Override
+ /**
+ * Event observer for newly added users by administrator
+ * <p>
+ * @param event Event being fired
+ */
public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
- // Trace message
- //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterAdminAddedUserEvent: event={0} - CALLED!", event)); //NOI18N
-
// event should not be null
if (null == event) {
// Throw NPE
throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
}
- // Add user uniquely
- this.uniqueAddUser(event.getAddedUser());
+ // Update user list
+ this.updateList(event.getAddedUser());
// Clear all data
this.clear();
// Set user id again
this.setUserId(event.getAddedUser().getUserId());
-
- // Trace message
- //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterAdminAddedUserEvent: EXIT!"); //NOI18N
}
- @Override
- public void afterAdminUpdatedUserDataEvent (@Observes final ObservableAdminUpdatedUserDataEvent event) {
- // Trace message
- //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterAdminUpdatedUserEvent: event={0} - CALLED!", event)); //NOI18N
-
+ /**
+ * Event observer for deleted user accounts (by administrator)
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterAdminDeletedUserEvent (final ObservableAdminDeletedUserEvent event) {
// event should not be null
if (null == event) {
// Throw NPE
throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getUpdatedUser() == null) {
+ } else if (event.getDeletedUser() == null) {
// Throw NPE again
- throw new NullPointerException("event.updatedUser is null"); //NOI18N
- } else if (event.getUpdatedUser().getUserId() == null) {
+ throw new NullPointerException("event.deletedUser is null"); //NOI18N
+ } else if (event.getDeletedUser().getUserId() == null) {
// userId is null
- throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
- } else if (event.getUpdatedUser().getUserId() < 1) {
+ throw new NullPointerException("event.deletedUser.userId is null"); //NOI18N
+ } else if (event.getDeletedUser().getUserId() < 1) {
// Not avalid id
- throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUpdatedUser(), event.getUpdatedUser().getUserId())); //NOI18N
+ throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getDeletedUser(), event.getDeletedUser().getUserId())); //NOI18N
}
- // Update list
- this.updateList(event.getUpdatedUser());
+ // Update user list
+ this.removeFromList(event.getDeletedUser());
// Clear all data
this.clear();
-
- // Trace message
- //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterAdminUpdatedUserEvent: EXIT!"); //NOI18N
}
- @Override
- public void afterRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) {
- // Trace message
- //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N
-
+ /**
+ * Event observer for linked users with existing contact data
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterAdminLinkedUserEvent (@Observes final ObservableAdminLinkedUserEvent event) {
// event should not be null
if (null == event) {
// Throw NPE
throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getRegisteredUser() == null) {
+ } else if (event.getLinkedUser() == null) {
// Throw NPE again
- throw new NullPointerException("event.registeredUser is null"); //NOI18N
- } else if (event.getRegisteredUser().getUserId() == null) {
+ throw new NullPointerException("event.linkedUser is null"); //NOI18N
+ } else if (event.getLinkedUser().getUserId() == null) {
// userId is null
- throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
- } else if (event.getRegisteredUser().getUserId() < 1) {
+ throw new NullPointerException("event.linkedUser.userId is null"); //NOI18N
+ } else if (event.getLinkedUser().getUserId() < 1) {
// Not avalid id
- throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
+ throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserId())); //NOI18N
}
- // Get user instance
- User registeredUser = event.getRegisteredUser();
-
- // Debug message
- //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterRegistration: registeredUser={0}", registeredUser)); //NOI18N
-
- // Copy all data from registered->user
- this.copyUser(registeredUser);
+ // Update user list
+ this.updateList(event.getLinkedUser());
// Clear all data
this.clear();
- // Add user uniquely
- this.uniqueAddUser(registeredUser);
-
- // Add user name
- this.addUserName(registeredUser);
+ // Set user id again
+ this.setUserId(event.getLinkedUser().getUserId());
+ }
- // Is the account public?
- if (Objects.equals(registeredUser.getUserProfileMode(), ProfileMode.PUBLIC)) {
- // Also add it to this list
- this.visibleUserList.add(registeredUser);
+ /**
+ * Event observer for locked users
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterAdminLockedUserEvent (@Observes final ObservableAdminLockedUserEvent event) {
+ // event should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getLockedUser() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.lockedUser is null"); //NOI18N
+ } else if (event.getLockedUser().getUserId() == null) {
+ // userId is null
+ throw new NullPointerException("event.lockedUser.userId is null"); //NOI18N
+ } else if (event.getLockedUser().getUserId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLockedUser(), event.getLockedUser().getUserId())); //NOI18N
}
- // Set user id again
- this.setUserId(registeredUser.getUserId());
+ // Update user list
+ this.updateList(event.getLockedUser());
+ }
- // Trace message
- //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterRegistration: EXIT!"); //NOI18N
+ /**
+ * Event observer for unlocked users
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterAdminUnlockedUserEvent (@Observes final ObservableAdminUnlockedUserEvent event) {
+ // event should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getUnlockedUser() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.unlockedUser is null"); //NOI18N
+ } else if (event.getUnlockedUser().getUserId() == null) {
+ // userId is null
+ throw new NullPointerException("event.unlockedUser.userId is null"); //NOI18N
+ } else if (event.getUnlockedUser().getUserId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUnlockedUser(), event.getUnlockedUser().getUserId())); //NOI18N
+ }
+
+ // Update user list
+ this.updateList(event.getUnlockedUser());
}
- @Override
- public void afterUserConfirmedAccount (@Observes final ObservableUserConfirmedAccountEvent event) {
- // Trace message
- //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterAdminUpdatedContactDataEvent: event={0} - CALLED!", event)); //NOI18N
+ /**
+ * Event observer for updated user data by administrator
+ * <p>
+ * @param event Event being updated
+ */
+ public void afterAdminUpdatedUserDataEvent (@Observes final ObservableAdminUpdatedUserDataEvent event) {
+ // event should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getUpdatedUser() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.updatedUser is null"); //NOI18N
+ } else if (event.getUpdatedUser().getUserId() == null) {
+ // userId is null
+ throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
+ } else if (event.getUpdatedUser().getUserId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUpdatedUser(), event.getUpdatedUser().getUserId())); //NOI18N
+ }
+
+ // Update user list
+ this.updateList(event.getUpdatedUser());
+
+ // Clear all data
+ this.clear();
+ }
+ /**
+ * Event observer when user confirmed account.
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterUserConfirmedAccountEvent (@Observes final ObservableUserConfirmedAccountEvent event) {
// event should not be null
if (null == event) {
// Throw NPE
throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
}
- // Add user uniquely
- this.uniqueAddUser(event.getConfirmedUser());
+ // Update user list
+ this.updateList(event.getConfirmedUser());
}
- @Override
+ /**
+ * Event observer for logged-in user
+ * <p>
+ * @param event Event instance
+ */
public void afterUserLoginEvent (@Observes final ObservableUserLoggedInEvent event) {
- // Trace message
- //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N
-
// event should not be null
if (null == event) {
// Throw NPE
}
}
- @Override
+ /**
+ * Event observer for new user registrations
+ * <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.registeredUser is null"); //NOI18N
+ } else if (event.getRegisteredUser().getUserId() == null) {
+ // userId is null
+ throw new NullPointerException("event.registeredUser.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();
+
+ // Copy all data from registered->user
+ this.copyUser(registeredUser);
+
+ // Clear all data
+ this.clear();
+
+ // Update user list
+ this.updateList(registeredUser);
+
+ // Add user name
+ this.addUserName(registeredUser);
+
+ // Is the account public?
+ if (Objects.equals(registeredUser.getUserProfileMode(), ProfileMode.PUBLIC)) {
+ // Also add it to this list
+ this.visibleUserList.add(registeredUser);
+ }
+
+ // Set user id again
+ this.setUserId(registeredUser.getUserId());
+ }
+
+ /**
+ * Method being call after user's password has been updated (and history
+ * entry has been created).
+ * <p>
+ * @param event Event being observed
+ */
public void afterUserUpdatedPasswordEvent (@Observes final ObservableUpdatedUserPasswordEvent event) {
// Check parameter
if (null == event) {
throw new IllegalArgumentException(MessageFormat.format("event.passwordHistory.userPasswordHistoryId={0} is in valid", event.getPasswordHistory().getUserPasswordHistoryId())); //NOI18N
}
- // All fine, so update list
+ // Update user list
this.updateList(event.getPasswordHistory().getUserPasswordHistoryUser());
}
- @Override
- public void afterUserUpdatedPersonalData (@Observes final ObservableUpdatedUserPersonalDataEvent event) {
+ /**
+ * Listens to fired event when user updated personal data
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterUserUpdatedPersonalDataEvent (@Observes final ObservableUpdatedUserPersonalDataEvent event) {
// Check parameter
if (null == event) {
// Throw NPE
throw new IllegalArgumentException(MessageFormat.format("event.updatedUser.userId={0} is in valid", event.getUpdatedUser().getUserId())); //NOI18N
}
- // All fine, so update list
+ // Update user list
this.updateList(event.getUpdatedUser());
}
this.setUserPasswordRepeat(randomPassword);
}
- // Set local, user name and mode
- user.setUserLocale(this.localizationController.getLocale());
+ // Set user name and mode
user.setUserName(this.getUserName());
user.setUserProfileMode(this.getUserProfileMode());
} else if (!this.userLoginController.ifCurrentPasswordMatches()) {
// Password not matching
throw new FaceletException(new UserPasswordMismatchException(this.userLoginController.getLoggedInUser()));
- } else if (!this.featureController.isFeatureEnabled("edit_user_data")) {
+ } else if (!this.featureController.isFeatureEnabled("change_user_personal_data")) {
// Editing is not allowed
throw new IllegalStateException("User tried to edit personal data."); //NOI18N
}
this.updatedPersonalDataEvent.fire(new UpdatedUserPersonalDataEvent(updatedUser));
// All fine
- return "contact_data_saved"; //NOI18N
+ return "user_contact_data_saved"; //NOI18N
}
@Override
@Override
public boolean isVisibleUserFound () {
- return ((this.visibleUserList instanceof List) && (!this.visibleUserList.isEmpty()));
+ return ((this.visibleUserList instanceof List) && (this.visibleUserList.size() > 0));
}
@Override
throw new NullPointerException(MessageFormat.format("next.userContact is null for user id {0}", next.getUserId())); //NOI18N
} else if (next.getUserContact().getContactEmailAddress() == null) {
// Email address should be set
- throw new NullPointerException(MessageFormat.format("next.userContact.contactEmailAddress is null for user id {0}", next.getUserId())); //NOI18N //NOI18N
+ throw new NullPointerException(MessageFormat.format("next.userContact.contactEmailAddress is null for user id {0}", next.getUserId())); //NOI18N
}
// Is the email address found?
}
/**
- * Uniquely adds given user instance to user list. First an existing
- * instance will be removed, then the given instance is being added.
+ * Removes user from all lists
* <p>
- * @param user User instance to add
+ * @param user User to remove
*/
- private void uniqueAddUser (final User user) {
- // Make sure the instance is valid
+ private void removeFromList (final User user) {
+ // The user should be valid
if (null == user) {
// Throw NPE
throw new NullPointerException("user is null"); //NOI18N
- } else if (user.getUserContact() == null) {
- // Throw again ...
- throw new NullPointerException("user.userContact is null"); //NOI18N
+ } else if (user.getUserId() == null) {
+ // ... again NPE
+ throw new NullPointerException("user.userId is null"); //NOI18N
+ } else if (user.getUserId() < 1) {
+ // Invalid id
+ throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
}
- // Get iterator from list
- Iterator<User> iterator = this.userList.iterator();
-
- // "Walk" through all entries
- while (iterator.hasNext()) {
- // Get next element
- User next = iterator.next();
+ // Remove it from lists
+ this.userList.remove(user);
+ this.visibleUserList.remove(user);
- // Is id number the same?
- if (Objects.equals(user.getUserId(), next.getUserId())) {
- // Found entry, so remove it and abort
- this.userList.remove(next);
- break;
- }
- }
-
- // Add contact to list
- this.userList.add(user);
+ // Remove name from list
+ this.userNameList.remove(user.getUserName());
}
/**
} else if (user.getUserId() < 1) {
// Invalid id
throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
+ } else if (user.getUserContact() == null) {
+ // Throw again ...
+ throw new NullPointerException("user.userContact is null"); //NOI18N
+ } else if (user.getUserContact().getContactId() == null) {
+ // Throw again ...
+ throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
+ } else if (user.getUserContact().getContactId() < 1) {
+ // Throw again ...
+ throw new NullPointerException(MessageFormat.format("user.userContact.contactId={0} is invalid.", user.getUserContact().getContactId())); //NOI18N
}
- // Get iterator
+ // Get iterator from list
Iterator<User> iterator = this.userList.iterator();
- // Look whole list
+ // "Walk" through all entries
while (iterator.hasNext()) {
// Get next element
User next = iterator.next();
- // Is the same user id?
+ // Is user id number the same?
if (Objects.equals(user.getUserId(), next.getUserId())) {
- // Found it, so remove it
+ // Found entry, so remove it and abort
this.userList.remove(next);
break;
}
}
- // Re-add item
+ // Re-add user
this.userList.add(user);
}
import org.mxchange.jusercore.exceptions.UserNotFoundException;
import org.mxchange.jusercore.model.user.User;
import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
-import org.mxchange.jusercore.events.confirmation.ObservableUserConfirmedAccountEvent;
-import org.mxchange.jusercore.events.login.ObservableUserLoggedInEvent;
-import org.mxchange.jusercore.events.registration.ObservableUserRegisteredEvent;
-import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
-import org.mxchange.jusercore.events.user.password_change.ObservableUpdatedUserPasswordEvent;
-import org.mxchange.jusercore.events.user.update.ObservableAdminUpdatedUserDataEvent;
-import org.mxchange.jusercore.events.user.update.ObservableUpdatedUserPersonalDataEvent;
/**
* An interface for user beans
*/
public static final Integer MINIMUM_PASSWORD_LENGTH = 5;
- /**
- * Event observer for newly added users by adminstrator
- * <p>
- * @param event Event being fired
- */
- void afterAdminAddedUserEvent (final ObservableAdminAddedUserEvent event);
-
- /**
- * Event observer for updated user data by administrator
- * <p>
- * @param event Event being updated
- */
- void afterAdminUpdatedUserDataEvent (final ObservableAdminUpdatedUserDataEvent event);
-
- /**
- * Event observer when user confirmed account.
- * <p>
- * @param event Event being fired
- */
- void afterUserConfirmedAccount (final ObservableUserConfirmedAccountEvent event);
-
- /**
- * Method being call after user's password has been updated (and history
- * entry has been created).
- * <p>
- * @param event Event being observed
- */
- void afterUserUpdatedPasswordEvent (final ObservableUpdatedUserPasswordEvent event);
-
- /**
- * Listens to fired event when user updated personal data
- * <p>
- * @param event Event being fired
- */
- void afterUserUpdatedPersonalData (final ObservableUpdatedUserPersonalDataEvent event);
-
- /**
- * Event observer for new user registrations
- * <p>
- * @param event User registration event
- */
- void afterRegistrationEvent (final ObservableUserRegisteredEvent event);
-
- /**
- * Event observer for logged-in user
- * <p>
- * @param event Event instance
- */
- void afterUserLoginEvent (final ObservableUserLoggedInEvent event);
-
/**
* All users
* <p>
* <p>
* @return User instance
* <p>
- * @throws UserEmailAddressNotFoundException If the user's email address is not found
+ * @throws UserEmailAddressNotFoundException If the user's email address is
+ * not found
*/
User lookupUserByEmailAddress (final String emailAddress) throws UserEmailAddressNotFoundException;
void setUserName (final String userName);
/**
- * Getter for unencrypted user password
+ * Getter for clear-text user password
* <p>
- * @return Unencrypted user password
+ * @return Clear-text user password
*/
String getUserPassword ();
/**
- * Setter for unencrypted user password
+ * Setter for clear-text user password
* <p>
- * @param userPassword Unencrypted user password
+ * @param userPassword Clear-text user password
*/
void setUserPassword (final String userPassword);
/**
- * Getter for unencrypted user password repeated
+ * Getter for clear-text user password repeated
* <p>
- * @return Unencrypted user password repeated
+ * @return Clear-text user password repeated
*/
String getUserPasswordRepeat ();
/**
- * Setter for unencrypted user password repeated
+ * Setter for clear-text user password repeated
* <p>
- * @param userPasswordRepeat Unencrypted user password repeated
+ * @param userPasswordRepeat Clear-text user password repeated
*/
void setUserPasswordRepeat (final String userPasswordRepeat);
private PizzaUserLoginWebSessionController userLoginController;
/**
- * User password (unencrypted from web form)
+ * User password (clear-text from web form)
*/
private String userPassword;
/**
- * User password repeated (unencrypted from web form)
+ * User password repeated (clear-text from web form)
*/
private String userPasswordRepeat;
public interface PizzaUserPasswordWebRequestController extends Serializable {
/**
- * Getter for unencrypted user password
+ * Getter for clear-text user password
* <p>
- * @return Unencrypted user password
+ * @return Clear-text user password
*/
String getUserPassword ();
/**
- * Setter for unencrypted user password
+ * Setter for clear-text user password
* <p>
- * @param userPassword Unencrypted user password
+ * @param userPassword Clear-text user password
*/
void setUserPassword (final String userPassword);
/**
- * Getter for current unencrypted user password
+ * Getter for current clear-text user password
* <p>
- * @return Current unencrypted user password
+ * @return Current clear-text user password
*/
String getUserCurrentPassword ();
/**
- * Setter for current unencrypted user password
+ * Setter for current clear-text user password
* <p>
- * @param userCurrentPassword Current unencrypted user password
+ * @param userCurrentPassword Current clear-text user password
*/
void setUserCurrentPassword (final String userCurrentPassword);
/**
- * Getter for unencrypted user password repeated
+ * Getter for clear-text user password repeated
* <p>
- * @return Unencrypted user password repeated
+ * @return Clear-text user password repeated
*/
String getUserPasswordRepeat ();
/**
- * Setter for unencrypted user password repeated
+ * Setter for clear-text user password repeated
* <p>
- * @param userPasswordRepeat Unencrypted user password repeated
+ * @param userPasswordRepeat Clear-text user password repeated
*/
void setUserPasswordRepeat (final String userPasswordRepeat);
@Override
public Object getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
- // Trace message
- // NOISY-DEBUG: this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: context={0},component={1},submittedValue={2} - CALLED!", context, component, submittedValue)); //NOI18N
-
// Is the value null or empty?
if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {
// Warning message
// Try to parse the value as long
Long contactId = Long.valueOf(submittedValue);
- // Debug message
- // NOISY-DEBUG: this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: contactId{0}", contactId)); //NOI18N
-
// Try to get user instance from it
contact = this.contactBean.findContactById(contactId);
-
- // Debug message
- // NOISY-DEBUG: this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: contact={0}", contact)); //NOI18N
} catch (final NumberFormatException ex) {
// Throw again
throw new ConverterException(ex);
// @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N
}
- // Trace message
- // NOISY-DEBUG: this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: contact={0} - EXIT!", contact)); //NOI18N
-
// Return it
return contact;
}
@Override
public Object getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
- // Trace message
- // NOISY-DEBUG: this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: context={0},component={1},submittedValue={2},this.countryBean={3} - CALLED!", context, component, submittedValue, this.countryBean)); //NOI18N
-
// Is the value null or empty?
if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {
// Warning message
// Category id should not be below 1
assert (countryId > 0) : "countryId is smaller than one: " + countryId; //NOI18N
- // Debug message
- // NOISY-DEBUG: this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: countryId={0}", countryId)); //NOI18N
-
// Try to find it
for (final Country cntry : countryList) {
// Is the id the same? (null-safe)
throw new ConverterException(ex);
}
- // Trace message
- // NOISY-DEBUG: this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: country={0} - EXIT!", country)); //NOI18N
-
// Return it
return country;
}
@Override
public Object getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
- // Trace message
- // NOISY-DEBUG: this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: context={0},component={1},submittedValue={2} - CALLED!", context, component, submittedValue)); //NOI18N
-
// Is the value null or empty?
if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {
// Warning message
// @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N
}
- // Trace message
- // NOISY-DEBUG: this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: mobile={0} - EXIT!", mobile)); //NOI18N
-
// Return it
return mobile;
}
@Override
public Object getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
- // Trace message
- // NOISY-DEBUG: this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: context={0},component={1},submittedValue={2} - CALLED!", context, component, submittedValue)); //NOI18N
-
// Is the value null or empty?
if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {
// Warning message
// Category id should not be below 1
assert (providerId > 0) : "providerId is smaller than one: " + providerId; //NOI18N
- // Debug message
- // NOISY-DEBUG: this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: providerId={0}", providerId)); //NOI18N
-
// Try to find it
for (final MobileProvider prov : providerList) {
// Is the id the same? (null-safe)
// @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logException(ex);
}
- // Trace message
- // NOISY-DEBUG: this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: provider={0} - EXIT!", provider)); //NOI18N
-
// Return it
return provider;
}
@Override
public Object getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
- // Trace message
- // NOISY-DEBUG: this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: context={0},component={1},submittedValue={2} - CALLED!", context, component, submittedValue)); //NOI18N
-
// Is the value null or empty?
if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {
// Warning message
// Try to parse the value as long
Long userId = Long.valueOf(submittedValue);
- // Debug message
- // NOISY-DEBUG: this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: userId{0}", userId)); //NOI18N
-
// Try to get user instance from it
user = this.userBean.findUserById(userId);
-
- // Debug message
- // NOISY-DEBUG: this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: user={0}", user)); //NOI18N
} catch (final NumberFormatException ex) {
// Throw again
throw new ConverterException(ex);
// @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: Exception: {0} - Returning null ...", ex)); //NOI18N
}
- // Trace message
- // NOISY-DEBUG: this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: user={0} - EXIT!", user)); //NOI18N
-
// Return it
return user;
}
@Override
public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {
- // Trace message
- // NOISY-DEBUG: this.loggerBeanLocal.logTrace(MessageFormat.format("validate: context={0},component={1},value={2} - CALLED!", context, component, value)); //NOI18N
-
// All accepted, required fields
String[] requiredFields = {"birthday", "contactBirthday"}; //NOI18N
Date birthday = (Date) value;
// @TODO Finish this, e.g. load maximum,minimum birthday from properties file
- // Trace message
- // NOISY-DEBUG: this.loggerBeanLocal.logTrace("validate: EXIT!"); //NOI18N
}
}
* <p>
* @param event User registration event
*/
- public void afterRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) {
- // Trace message
- // NOISY-DEBUG: this.loggerBeanLocal.logTrace(MessageFormat.format("UserIdValidator:afterRegistrationEvent: event={0} - CALLED!", event)); //NOI18N
-
+ public void afterUserRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) {
// event should not be null
if (null == event) {
// Throw NPE
// Get user instance
User registeredUser = event.getRegisteredUser();
- // Debug message
- // NOISY-DEBUG: this.loggerBeanLocal.logDebug(MessageFormat.format("UserIdValidator:afterRegistrationEvent: registeredUser={0}", registeredUser)); //NOI18N
-
// Update cache
PizzaUserIdValidator.cachedStatus.add(registeredUser.getUserId());
- // Trace message
- // NOISY-DEBUG: this.loggerBeanLocal.logTrace("UserIdValidator:afterRegistrationEvent: EXIT!"); //NOI18N
}
@Override
public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {
- // Trace message
- // NOISY-DEBUG: this.loggerBeanLocal.logTrace(MessageFormat.format("validate: context={0},component={1},value={2} - CALLED!", context, component, value)); //NOI18N
-
// All accepted, required fields
String[] requiredFields = {"userId"}; //NOI18N
// Add to cache if valid
PizzaUserIdValidator.cachedStatus.add(userId);
-
- // Trace message
- // NOISY-DEBUG: this.loggerBeanLocal.logTrace("validate: EXIT!"); //NOI18N
}
}