import javax.enterprise.context.RequestScoped;
import javax.enterprise.event.Event;
import javax.enterprise.inject.Any;
+import javax.faces.context.FacesContext;
import javax.faces.view.facelets.FaceletException;
import javax.inject.Inject;
import javax.inject.Named;
public void init () {
}
+ @Override
+ public boolean isGenderRequired () {
+ // Get context parameter
+ String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_admin_gender_enabled"); //NOI18N
+
+ // Is it set?
+ boolean isRequired = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N
+
+ // Return value
+ return isRequired;
+ }
+
/**
* Clears this bean
*/
*/
String generateCellphoneNumber (final DialableCellphoneNumber cellphoneNumber);
+ /**
+ * Checks/returns whether the gender/salutation is required for this
+ * controller.
+ * <p>
+ * @return Whether gender is required
+ */
+ boolean isGenderRequired ();
+
}
@Override
public void afterAdminAddedContact (@Observes final AdminAddedContactEvent event) {
+ // Trace message
+ /* NOISY-DEBUG: */ System.out.println(MessageFormat.format("contactController.afterAdminAddedContact(): event={0} - CALLED!", event)); //NOI18N
+
// The event must be valid
if (null == event) {
// Throw NPE
// 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 ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
// Now the number must be given
// Trace message
//* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: contact={1} - EXIT!", this.getClass().getSimpleName(), contact));
+
// Return it
return contact;
}
import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
import org.mxchange.jusercore.events.user.add.AdminUserAddedEvent;
+import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent;
+import org.mxchange.jusercore.events.user.linked.AdminUserLinkedEvent;
import org.mxchange.jusercore.events.user.update.AdminUpdatedUserDataEvent;
import org.mxchange.jusercore.events.user.update.AdminUserDataUpdatedEvent;
import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException;
@Inject
private PizzaUserWebSessionController userController;
+ /**
+ * An event fired when the administrator has linked a user with existing
+ * contact data.
+ */
+ @Inject
+ @Any
+ private Event<AdminLinkedUserEvent> userLinkedEvent;
+
/**
* User name
*/
// Encrypt password and set it
user.setUserEncryptedPassword(UserUtils.encryptPassword(password));
- // Init updated user instance
- User updatedUser = null;
-
try {
// Now, that all is set, call EJB
if (this.beanHelper.getContact() instanceof Contact) {
// Link contact with this user
- updatedUser = this.userBean.linkUser(user);
+ User updatedUser = this.userBean.linkUser(user);
+
+ // Fire event
+ this.userLinkedEvent.fire(new AdminUserLinkedEvent(updatedUser));
// Remove contact instance
this.beanHelper.setContact(null);
} else {
// Add new contact
- updatedUser = this.userBean.addUser(user);
+ User updatedUser = this.userBean.addUser(user);
+
+ // Fire event
+ this.addedUserEvent.fire(new AdminUserAddedEvent(updatedUser));
}
} catch (final UserNameAlreadyRegisteredException | EmailAddressAlreadyRegisteredException ex) {
// Throw again
throw new FaceletException(ex);
}
- // Clear helper
- this.beanHelper.setContact(null);
-
- // Fire event
- this.addedUserEvent.fire(new AdminUserAddedEvent(updatedUser));
-
// Clear this bean
this.clear();
import javax.naming.NamingException;
import org.mxchange.jcontacts.contact.Contact;
import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
-import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
import org.mxchange.jusercore.events.confirmation.UserConfirmedAccountEvent;
import org.mxchange.jusercore.events.login.UserLoggedInEvent;
import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
}
}
- @Override
- public void afterAdminAddedContact (@Observes final AdminAddedContactEvent 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.customerId is null"); //NOI18N
- } else if (event.getAddedContact().getContactId() < 1) {
- // Not valid
- throw new IllegalArgumentException(MessageFormat.format("event.addedContact.customerId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N
- }
-
- // Call other method
- this.selectableContacts.add(event.getAddedContact());
- }
-
@Override
public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) {
// Trace message
@Override
public String doChangePersonalData () {
// This method shall only be called if the user is logged-in
- if (!this.loginController.isUserLoggedIn()) {
+ if (!this.userLoginController.isUserLoggedIn()) {
// Not logged-in
throw new IllegalStateException("User is not logged-in"); //NOI18N
} else if (!this.isRequiredChangePersonalDataSet()) {
// Not all required fields are set
throw new FaceletException("Not all required fields are set."); //NOI18N
- } else if (!this.loginController.ifCurrentPasswordMatches()) {
+ } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
// Password not matching
throw new FaceletException(new UserPasswordMismatchException(this.userLoginController.getLoggedInUser()));
} else if (!this.featureController.isFeatureEnabled("edit_user_data")) {
}
// Get user instance
- User user = this.loginController.getLoggedInUser();
+ User user = this.userLoginController.getLoggedInUser();
// Copy contact data to contact instance
this.contactController.updateContactDataFromController(user.getUserContact());
// Initialize user list
this.visibleUserList = this.userBean.allPublicUsers();
}
-
- // Get all users
- List<User> allUsers = this.allUsers();
-
- // Get all contacts
- List<Contact> allContacts = this.contactBean.getAllContacts();
-
- // Get iterator
- Iterator<Contact> iterator = allContacts.iterator();
-
- // Loop through it
- while (iterator.hasNext()) {
- // Get next element
- Contact next = iterator.next();
-
- // Get iterator
- Iterator<User> userIterator = allUsers.iterator();
-
- // Loop through all users
- while (userIterator.hasNext()) {
- // Get user instance
- User nextUser = userIterator.next();
-
- // Is contact same?
- if (Objects.equals(next, nextUser.getUserContact())) {
- // Found same
- iterator.remove();
- break;
- }
- }
- }
-
- // Set contact list
- this.selectableContacts = allContacts;
}
@Override
return user;
}
- @Override
- public List<Contact> selectableContacts () {
- return Collections.unmodifiableList(this.selectableContacts);
- }
-
/**
* Adds user's name to bean's internal list. It also updates the public user
* list if the user has decided to have a public account,
*/
User lookupUserByEmailAddress (final String emailAddress) throws UserEmailAddressNotFoundException;
- /**
- * Returns a list of all selectable contacts for user creation. Contacts
- * from already existing users are excluded in this list.
- * <p>
- * @return A list of all selectable contacts
- */
- List<Contact> selectableContacts ();
-
/**
* Creates an instance from all properties
* <p>
<h:selectOneMenu styleClass="select" id="userContact" value="#{beanHelper.contact}">
<f:converter converterId="ContactConverter" />
<f:selectItem itemValue="" itemLabel="#{msg.NONE_SELECTED}" />
- <f:selectItems value="#{userController.selectableContacts()}" var="contact" itemValue="#{contact}" itemLabel="#{contact.contactId}: #{msg[contact.contactGender.messageKey]} #{contact.contactFirstName} #{contact.contactFamilyName}" />
+ <f:selectItems value="#{contactController.selectableContacts()}" var="contact" itemValue="#{contact}" itemLabel="#{contact.contactId}: #{msg[contact.contactGender.messageKey]} #{contact.contactFirstName} #{contact.contactFamilyName}" />
</h:selectOneMenu>
</div>