- administrative controller are request-scoped, therefor their "cached" lists are never cached for a longer time. So all lists has to be moved to general controllers
- added new general customer bean for above refacturing
Signed-off-by: Roland Häder <roland@mxchange.org>
ADMIN_CONTACT_CREATED=Erstellt:
ADMIN_ADD_CONTACT_TITLE=Neue Kontaktdaten hinzuf\u00fcgen
BUTTON_ADMIN_ADD_CONTACT=Kontaktdaten hinzuf\u00fcgen
+CONTACT_IS_UNUSED=Nicht verlinkt
+CONTACT_IS_USER_CUSTOMER=Benutzer und Kunde
+CONTACT_IS_USER=Ist Benutzer
+CONTACT_IS_CUSTOMER=Ist Kunde
ADMIN_CONTACT_CREATED=Created:
ADMIN_ADD_CONTACT_TITLE=Add new contact data
BUTTON_ADMIN_ADD_CONTACT=Add contact data
+CONTACT_IS_UNUSED=Not linked
+CONTACT_IS_USER_CUSTOMER=User and customer
+CONTACT_IS_USER=Is a user
+CONTACT_IS_CUSTOMER=Is a customer
* General contact controller
*/
@Inject
- private RateCalcContactWebSessionController contactController;
+ private PizzaContactWebSessionController contactController;
/**
* Contact id
*/
package org.mxchange.pizzaapplication.beans.customer;
-import java.util.Collections;
-import java.util.List;
import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.event.Event;
private Event<AdminAddedCustomerEvent> customerAddedEvent;
/**
- * A list of all customers
+ * General customer controller
*/
- private List<Customer> customerList;
+ @Inject
+ private PizzaCustomerWebSessionController customerController;
/**
* Default constructor
}
// Add customer to list
- this.customerList.add(updatedCustomer);
+ this.customerController.addCustomer(updatedCustomer);
// Fire event
this.customerAddedEvent.fire(new CustomerAdminAddedEvent(updatedCustomer));
return "admin_list_customer"; //NOI18N
}
- @Override
- public List<Customer> allCustomers () {
- // Return it
- return Collections.unmodifiableList(this.customerList);
- }
-
- @Override
- public boolean hasCustomers () {
- return (!this.allCustomers().isEmpty());
- }
-
/**
* Post-initialization of this class
*/
@PostConstruct
public void init () {
- // Initialize customer list
- this.customerList = this.adminCustomerBean.allCustomers();
}
/**
package org.mxchange.pizzaapplication.beans.customer;
import java.io.Serializable;
-import java.util.List;
-import org.mxchange.jcustomercore.model.customer.Customer;
/**
* An interface for user beans
*/
public interface PizzaAdminCustomerWebRequestController extends Serializable {
- /**
- * All customer
- * <p>
- * @return A list of all customer profiles
- */
- List<Customer> allCustomers ();
-
- /**
- * Checks whether customers are registered
- * <p>
- * @return Whether customers are registered
- */
- boolean hasCustomers ();
-
/**
* Adds customer to database if not already added. This method should return
* a redirect outcome on success.
*/
package org.mxchange.pizzaapplication.beans.customer;
+import java.text.MessageFormat;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Objects;
+import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
+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.contact.Contact;
-import org.mxchange.jcontacts.contact.UserContact;
-import org.mxchange.jcontacts.contact.gender.Gender;
-import org.mxchange.jcountry.data.Country;
+import org.mxchange.jcustomercore.events.AdminAddedCustomerEvent;
import org.mxchange.jcustomercore.model.customer.Customer;
-import org.mxchange.jcustomercore.model.customer.CustomerSessionBeanRemote;
-import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
-import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
-import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
-import org.mxchange.jshopcore.model.customer.ShopCustomer;
+import org.mxchange.pizzaapplication.beans.contact.PizzaAdminContactWebRequestController;
+import org.mxchange.pizzaapplication.model.customer.PizzaAdminCustomerSessionBeanRemote;
/**
* A customer bean which hides the customer instance
/**
* Serial number
*/
- private static final long serialVersionUID = 542_145_347_916L;
+ private static final long serialVersionUID = 12_487_062_487_527_913L;
- /////////////////////// Properties /////////////////////
/**
- * Cellphone number
+ * Administrative contact controller (for personal data)
*/
- private DialableCellphoneNumber cellphoneNumber;
+ @Inject
+ private PizzaAdminContactWebRequestController adminContactController;
/**
- * City
+ * Administrative customer EJB
*/
- private String city;
+ private PizzaAdminCustomerSessionBeanRemote adminCustomerBean;
/**
- * Optional comments
+ * An event being fired when an administrator has added a new customer
*/
- private String comment;
+ @Inject
+ @Any
+ private Event<AdminAddedCustomerEvent> customerAddedEvent;
/**
- * Country code
+ * A list of all customers
*/
- private Country country;
-
- /**
- * Remote customer bean
- */
- private CustomerSessionBeanRemote customerBean;
-
- /**
- * Email address
- */
- private String emailAddress;
-
- /**
- * Family name
- */
- private String familyName;
-
- /**
- * Fax number
- */
- private DialableFaxNumber faxNumber;
-
- /**
- * First name
- */
- private String firstName;
-
- /**
- * Gender instance
- */
- private Gender gender;
-
- /**
- * House number
- */
- private Short houseNumber;
-
- /**
- * Phone number
- */
- private DialableLandLineNumber phoneNumber;
-
- /**
- * Street
- */
- private String street;
-
- /**
- * ZIP code
- */
- private Integer zipCode;
+ private List<Customer> customerList;
/**
* Default constructor
*/
public PizzaCustomerWebSessionBean () {
- // Set gender to UNKNOWN
- this.gender = Gender.UNKNOWN;
-
// Try it
try {
// Get initial context
Context context = new InitialContext();
// Try to lookup
- this.customerBean = (CustomerSessionBeanRemote) context.lookup("java:global/jshop-ejb/shop_customer!org.mxchange.jcustomercore.model.customer.CustomerSessionBeanRemote"); //NOI18N
+ this.adminCustomerBean = (PizzaAdminCustomerSessionBeanRemote) context.lookup("java:global/jratecalc-ejb/admincustomer!de.chotime.jratecalc.model.customer.PizzaAdminCustomerSessionBeanRemote"); //NOI18N
} catch (final NamingException e) {
// Throw again
throw new FaceletException(e);
}
@Override
- public Customer createCustomerInstance () {
- // Trace message
- //this.getLogger().logTrace("createInstance: CALLED!");
-
- // Required personal data must be set
- assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
-
- // Create new customer instance
- Customer customer = new ShopCustomer();
-
- // Create new contact
- Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
- contact.setContactStreet(this.getStreet());
- contact.setContactHouseNumber(this.getHouseNumber());
- contact.setContactZipCode(this.getZipCode());
- contact.setContactCity(this.getCity());
- contact.setContactCountry(this.getCountry());
- contact.setContactLandLineNumber(this.getPhoneNumber());
- contact.setContactFaxNumber(this.getFaxNumber());
- contact.setContactCellphoneNumber(this.getCellphoneNumber());
-
- // Set contact in customer
- customer.setCustomerContact(contact);
-
- // Trace message
- //this.getLogger().logTrace(MessageFormat.format("createInstance: customer={0} - EXIT!", customer));
- // Return it
- return customer;
- }
-
- @Override
- public DialableCellphoneNumber getCellphoneNumber () {
- return this.cellphoneNumber;
- }
-
- @Override
- public void setCellphoneNumber (final DialableCellphoneNumber cellphoneNumber) {
- this.cellphoneNumber = cellphoneNumber;
- }
-
- @Override
- public String getCity () {
- return this.city;
- }
-
- @Override
- public void setCity (final String city) {
- this.city = city;
- }
-
- @Override
- public Country getCountry () {
- return this.country;
- }
-
- @Override
- public void setCountry (final Country country) {
- this.country = country;
- }
-
- @Override
- public String getEmailAddress () {
- return this.emailAddress;
- }
-
- @Override
- public void setEmailAddress (final String emailAddress) {
- this.emailAddress = emailAddress;
- }
-
- @Override
- public String getFamilyName () {
- return this.familyName;
- }
-
- @Override
- public void setFamilyName (final String familyName) {
- this.familyName = familyName;
- }
-
- @Override
- public DialableFaxNumber getFaxNumber () {
- return this.faxNumber;
- }
-
- @Override
- public void setFaxNumber (final DialableFaxNumber faxNumber) {
- this.faxNumber = faxNumber;
- }
-
- @Override
- public String getFirstName () {
- return this.firstName;
- }
-
- @Override
- public void setFirstName (final String firstName) {
- this.firstName = firstName;
- }
-
- @Override
- public Gender getGender () {
- return this.gender;
- }
+ public void addCustomer (final Customer customer) {
+ // The contact must be valid
+ if (null == customer) {
+ // Throw NPE
+ throw new NullPointerException("customer is null"); //NOI18N
+ } else if (customer.getCustomerId() == null) {
+ // Throw again ...
+ throw new NullPointerException("customer.customerId is null"); //NOI18N
+ } else if (customer.getCustomerId() < 1) {
+ // Not valid
+ throw new IllegalArgumentException(MessageFormat.format("customer.customerId={0} is not valid", customer.getCustomerId())); //NOI18N
+ } else if (customer.getCustomerContact() == null) {
+ // Throw NPE
+ throw new NullPointerException("customer.customerContact is null"); //NOI18N
+ } else if (customer.getCustomerContact().getContactId() == null) {
+ // Throw again ...
+ throw new NullPointerException("customer.customerContact.contactId is null"); //NOI18N
+ } else if (customer.getCustomerContact().getContactId() < 1) {
+ // Not valid
+ throw new IllegalArgumentException(MessageFormat.format("customer.customerContact.contactId={0} is not valid", customer.getCustomerContact().getContactId())); //NOI18N
+ }
- @Override
- public void setGender (final Gender gender) {
- this.gender = gender;
+ // Add to list
+ this.customerList.add(customer);
}
@Override
- public Short getHouseNumber () {
- return this.houseNumber;
+ public List<Customer> allCustomers () {
+ // Return it
+ return Collections.unmodifiableList(this.customerList);
}
@Override
- public void setHouseNumber (final Short houseNumber) {
- this.houseNumber = houseNumber;
+ public boolean hasCustomers () {
+ return (!this.allCustomers().isEmpty());
}
- @Override
- public DialableLandLineNumber getPhoneNumber () {
- return this.phoneNumber;
+ /**
+ * Post-initialization of this class
+ */
+ @PostConstruct
+ public void init () {
+ // Initialize customer list
+ this.customerList = this.adminCustomerBean.allCustomers();
}
@Override
- public void setPhoneNumber (final DialableLandLineNumber phoneNumber) {
- this.phoneNumber = phoneNumber;
- }
+ public boolean isContactFound (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
+ }
- @Override
- public String getStreet () {
- return this.street;
- }
+ // Default is not found
+ boolean isFound = false;
- @Override
- public void setStreet (final String street) {
- this.street = street;
- }
+ // Get iterator
+ Iterator<Customer> iterator = this.allCustomers().iterator();
- @Override
- public Integer getZipCode () {
- return this.zipCode;
- }
+ // Loop through all entries
+ while (iterator.hasNext()) {
+ // Get customer
+ Customer next = iterator.next();
- @Override
- public void setZipCode (final Integer zipCode) {
- this.zipCode = zipCode;
- }
+ // Compare both objects
+ if (Objects.equals(contact, next.getCustomerContact())) {
+ // Found it
+ isFound = true;
+ break;
+ }
+ }
- @Override
- public boolean isRequiredPersonalDataSet () {
- return ((this.getGender() != null) && (this.getFirstName() != null) && (this.getFamilyName() != null) && (this.getStreet() != null) && (this.getHouseNumber() != null) && (this.getZipCode() != null) && (this.getCity() != null));
+ // Return status
+ return isFound;
}
}
package org.mxchange.pizzaapplication.beans.customer;
import java.io.Serializable;
-import org.mxchange.jcontacts.contact.gender.Gender;
-import org.mxchange.jcountry.data.Country;
+import java.util.List;
+import org.mxchange.jcontacts.contact.Contact;
import org.mxchange.jcustomercore.model.customer.Customer;
-import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
-import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
-import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
/**
* An interface for customer beans
public interface PizzaCustomerWebSessionController extends Serializable {
/**
- * Creates an instance from all properties
+ * Adds customer instance to list. The customer should be an updated
+ * instance (with id number).
* <p>
- * @return A Customer instance
+ * @param customer Customer instance
*/
- Customer createCustomerInstance ();
+ void addCustomer (final Customer customer);
/**
- * Cellphone number
+ * Checks whether the given contact is a customer
* <p>
- * @return the cellphoneNumber
+ * @param contact Contact to check
+ *
+ * @return Whether the contact is a customer
*/
- DialableCellphoneNumber getCellphoneNumber ();
+ boolean isContactFound (final Contact contact);
/**
- * Cellphone number
+ * All customer
* <p>
- * @param cellphoneNumber the cellphoneNumber to set
+ * @return A list of all customer profiles
*/
- void setCellphoneNumber (final DialableCellphoneNumber cellphoneNumber);
+ List<Customer> allCustomers ();
/**
- * City
+ * Checks whether customers are registered
* <p>
- * @return the city
+ * @return Whether customers are registered
*/
- String getCity ();
-
- /**
- * City
- * <p>
- * @param city the city to set
- */
- void setCity (final String city);
-
- /**
- * Getter for country instance
- * <p>
- * @return Country instance
- */
- Country getCountry ();
-
- /**
- * Setter for country instance
- * <p>
- * @param country Country instance
- */
- void setCountry (final Country country);
-
- /**
- * Email address
- * <p>
- * @return the emailAddress
- */
- String getEmailAddress ();
-
- /**
- * Email address
- * <p>
- * @param emailAddress the emailAddress to set
- */
- void setEmailAddress (final String emailAddress);
-
- /**
- * Family name
- * <p>
- * @return the familyName
- */
- String getFamilyName ();
-
- /**
- * Family name
- * <p>
- * @param familyName the familyName to set
- */
- void setFamilyName (final String familyName);
-
- /**
- * Fax number
- * <p>
- * @return the faxNumber
- */
- DialableFaxNumber getFaxNumber ();
-
- /**
- * Fax number
- * <p>
- * @param faxNumber the faxNumber to set
- */
- void setFaxNumber (final DialableFaxNumber faxNumber);
-
- /**
- * First name
- * <p>
- * @return the first name
- */
- String getFirstName ();
-
- /**
- * First name
- * <p>
- * @param firstName the first name to set
- */
- void setFirstName (final String firstName);
-
- /**
- * Gender of the contact
- * <p>
- * @return the gender
- */
- Gender getGender ();
-
- /**
- * Gender of the contact
- * <p>
- * @param gender the gender to set
- */
- void setGender (final Gender gender);
-
- /**
- * House number
- * <p>
- * @return the houseNumber
- */
- Short getHouseNumber ();
-
- /**
- * House number
- * <p>
- * @param houseNumber the houseNumber to set
- */
- void setHouseNumber (final Short houseNumber);
-
- /**
- * Phone number
- * <p>
- * @return the phoneNumber
- */
- DialableLandLineNumber getPhoneNumber ();
-
- /**
- * Phone number
- * <p>
- * @param phoneNumber the phoneNumber to set
- */
- void setPhoneNumber (final DialableLandLineNumber phoneNumber);
-
- /**
- * Street
- * <p>
- * @return the street
- */
- String getStreet ();
-
- /**
- * Street
- * <p>
- * @param street the street to set
- */
- void setStreet (final String street);
-
- /**
- * ZIP code
- * <p>
- * @return the zipCode
- */
- Integer getZipCode ();
-
- /**
- * ZIP code
- * <p>
- * @param zipCode the zipCode to set
- */
- void setZipCode (final Integer zipCode);
-
- /**
- * Checks whether all required personal data is set
- * <p>
- * @return Whether the required personal data is set
- */
- boolean isRequiredPersonalDataSet ();
+ boolean hasCustomers ();
}
*/
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 getUserCustomerUsageMessageKey (final Contact contact);
+
/**
* Getter for contact instance
* <p>
import org.mxchange.jcontacts.contact.Contact;
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.user.PizzaAdminUserWebRequestController;
+import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController;
/**
* A general helper for administrative beans
private static final long serialVersionUID = 17_258_793_567_145_701L;
/**
- * Admin contact controller
+ * Administrative contact controller
*/
@Inject
private PizzaAdminContactWebRequestController adminContactController;
/**
- * Admin user controller
+ * Administrative user controller
+ */
+ @Inject
+ private PizzaAdminCustomerWebRequestController adminCustomerController;
+
+ /**
+ * Administrative user controller
*/
@Inject
private PizzaAdminUserWebRequestController adminUserController;
*/
private Contact contact;
+ /**
+ * General user controller
+ */
+ @Inject
+ private PizzaCustomerWebSessionController customerController;
+
/**
* User instance
*/
private User user;
+ /**
+ * General user controller
+ */
+ @Inject
+ private PizzaUserWebSessionController userController;
+
/**
* Default constructor
*/
@Override
public void copyContactToController () {
// Log message
- System.out.println("AdminHelper::copyContactToController - CALLED!"); //NOI18N
+ //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyContactToController - CALLED!"); //NOI18N
// Validate user instance
if (this.getContact() == null) {
this.adminContactController.copyContactToController(this.getContact());
// Log message
- System.out.println("AdminHelper::copyContactToController - EXIT!"); //NOI18N
+ //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyContactToController - EXIT!"); //NOI18N
}
@Override
public void copyUserToController () {
// Log message
- System.out.println("AdminHelper::copyUserToController - CALLED!"); //NOI18N
+ //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyUserToController - CALLED!"); //NOI18N
// Validate user instance
if (this.getUser() == null) {
this.adminUserController.setUserName(this.getUser().getUserName());
// Log message
- System.out.println("AdminHelper::copyUserToController - EXIT!"); //NOI18N
+ //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyUserToController - EXIT!"); //NOI18N
}
@Override
this.user = user;
}
+ @Override
+ public String getUserCustomerUsageMessageKey (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_CUSTOMER"; //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;
+ }
+
}
package org.mxchange.pizzaapplication.beans.user;
import java.text.MessageFormat;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
import java.util.Objects;
import javax.annotation.PostConstruct;
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 org.mxchange.jusercore.events.user.AdminUserAddedEvent;
import org.mxchange.jusercore.events.user.update.AdminUpdatedUserDataEvent;
import org.mxchange.jusercore.events.user.update.AdminUserDataUpdatedEvent;
-import org.mxchange.jusercore.events.user.update.UpdatedUserPersonalDataEvent;
import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException;
import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException;
-import org.mxchange.jusercore.exceptions.UserNotFoundException;
import org.mxchange.jusercore.exceptions.UserPasswordRepeatMismatchException;
import org.mxchange.jusercore.model.user.LoginUser;
import org.mxchange.jusercore.model.user.User;
@Inject
private PizzaUserWebSessionController userController;
- /**
- * A list of all user profiles
- */
- private List<User> userList;
-
/**
* User name
*/
} else if (this.contactController.getFamilyName().isEmpty()) {
// ... and again
throw new IllegalArgumentException("contactController.familyName is empty"); //NOI18N //NOI18N
- } else if (this.contactController.getEmailAddress()== null) {
+ } else if (this.contactController.getEmailAddress() == null) {
// ... and again
throw new NullPointerException("contactController.emailAddress is null");
} else if (this.contactController.getEmailAddress().isEmpty()) {
// ... and again
throw new IllegalArgumentException("contactController.emailAddress is empty"); //NOI18N //NOI18N
- } else if (this.contactController.getEmailAddressRepeat()== null) {
+ } else if (this.contactController.getEmailAddressRepeat() == null) {
// ... and again
throw new NullPointerException("contactController.emailAddressRepeat is null");
} else if (this.contactController.getEmailAddressRepeat().isEmpty()) {
// Add new contact
updatedUser = this.userBean.addUser(user);
}
- } catch (final UserNameAlreadyRegisteredException | EmailAddressAlreadyRegisteredException ex) {
+ } catch (final UserNameAlreadyRegisteredException | EmailAddressAlreadyRegisteredException ex) {
// Throw again
throw new FaceletException(ex);
}
// Fire event
this.addedUserEvent.fire(new AdminUserAddedEvent(updatedUser));
- // Add user to local list
- this.userList.add(updatedUser);
-
// Clear contact instance
this.contactController.clear();
return "admin_list_user"; //NOI18N
}
- @Override
- public void afterUserUpdatedPersonalData (@Observes final UpdatedUserPersonalDataEvent event) {
- // Check parameter
- 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) {
- // ... and again
- throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
- } else if (event.getUpdatedUser().getUserId() < 1) {
- // Invalid value
- throw new IllegalArgumentException(MessageFormat.format("event.updatedUser.userId={0} is in valid", event.getUpdatedUser().getUserId())); //NOI18N
- }
-
- // All fine, so update list
- this.updateList(event.getUpdatedUser());
- }
-
- @Override
- public List<User> allUsers () {
- // Return it
- return Collections.unmodifiableList(this.userList);
- }
-
@Override
public String changeUserData () {
// Get user instance
User updatedUser = this.userBean.updateUserData(user);
// Update list
- this.updateList(updatedUser);
+ this.userController.updateList(updatedUser);
// Fire event
this.updatedUserDataEvent.fire(new AdminUserDataUpdatedEvent(updatedUser));
this.userPasswordRepeat = userPasswordRepeat;
}
- @Override
- public boolean hasUsers () {
- return (!this.allUsers().isEmpty());
- }
-
/**
* Post-initialization of this class
*/
@PostConstruct
public void init () {
- // Initialize user list
- this.userList = this.userBean.allUsers();
- }
-
- @Override
- public User lookupUserById (final Long userId) throws UserNotFoundException {
- // Parameter must be valid
- if (null == userId) {
- // Throw NPE
- throw new NullPointerException("userId is null"); //NOI18N
- } else if (userId < 1) {
- // Not valid
- throw new IllegalArgumentException(MessageFormat.format("userId={0} is not valid.", userId)); //NOI18N
- }
-
- // Init variable
- User user = null;
-
- // Try to lookup it in visible user list
- for (final Iterator<User> iterator = this.userList.iterator(); iterator.hasNext();) {
- // Get next user
- User next = iterator.next();
-
- // Is the user id found?
- if (Objects.equals(next.getUserId(), userId)) {
- // Copy to other variable
- user = next;
- break;
- }
- }
-
- // Is it still null?
- if (null == user) {
- // Not visible for the current user
- throw new UserNotFoundException(userId);
- }
-
- // Return it
- return user;
}
/**
return ((!this.getUserPassword().isEmpty()) && (Objects.equals(this.getUserPassword(), this.getUserPasswordRepeat())));
}
- /**
- * Updates list with given user instance
- * <p>
- * @param user User instance
- */
- private void updateList (final User user) {
- // The user should be valid
- if (null == user) {
- // Throw NPE
- throw new NullPointerException("user 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
- Iterator<User> iterator = this.userList.iterator();
-
- // Look whole list
- while (iterator.hasNext()) {
- // Get next element
- User next = iterator.next();
-
- // Is the same user id?
- if (Objects.equals(user.getUserId(), next.getUserId())) {
- // Found it, so remove it
- this.userList.remove(next);
- break;
- }
- }
-
- // Re-add item
- this.userList.add(user);
- }
-
}
package org.mxchange.pizzaapplication.beans.user;
import java.io.Serializable;
-import java.util.List;
-import org.mxchange.jusercore.events.user.update.UpdatedUserPersonalDataEvent;
-import org.mxchange.jusercore.exceptions.UserNotFoundException;
-import org.mxchange.jusercore.model.user.User;
/**
* An interface for user beans
*/
public interface PizzaAdminUserWebRequestController extends Serializable {
- /**
- * Listens to fired event when user updated personal data
- * <p>
- * @param event Event being fired
- */
- void afterUserUpdatedPersonalData (final UpdatedUserPersonalDataEvent event);
-
- /**
- * Tries to lookup user by given id number. If the user is not found or the
- * account status is not CONFIRMED proper exceptions are thrown.
- * <p>
- * @param userId User id
- * <p>
- * @return User instance
- * <p>
- * @throws UserNotFoundException If the user is not found
- */
- User lookupUserById (final Long userId) throws UserNotFoundException;
-
- /**
- * All users
- * <p>
- * @return A list of all public user profiles
- */
- List<User> allUsers ();
-
- /**
- * Checks whether users are registered
- * <p>
- * @return Whether users are registered
- */
- boolean hasUsers ();
-
/**
* 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,
*/
package org.mxchange.pizzaapplication.beans.user;
-import de.chotime.jratecalc.beans.contact.RateCalcContactWebSessionController;
-import de.chotime.jratecalc.beans.login.RateCalcUserLoginWebSessionController;
import java.text.MessageFormat;
import java.util.Collections;
import java.util.Iterator;
import org.mxchange.jusercore.events.user.update.UpdatedUserPersonalDataEvent;
import org.mxchange.jusercore.events.user.update.UserUpdatedPersonalDataEvent;
import org.mxchange.jusercore.exceptions.UserNotFoundException;
+import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
import org.mxchange.jusercore.model.user.LoginUser;
import org.mxchange.jusercore.model.user.User;
import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
-import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController;
import org.mxchange.pizzaapplication.beans.contact.PizzaContactWebSessionController;
-import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
+import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController;
/**
* A user bean (controller)
* Administrative user controller
*/
@Inject
- private RateCalcAdminUserWebRequestController adminController;
+ private PizzaAdminUserWebRequestController adminController;
/**
* Remote user bean
*/
private Long userId;
+ /**
+ * A list of all user profiles
+ */
+ private List<User> userList;
+
/**
* User name
*/
// Set user id again
this.setUserId(registeredUser.getUserId());
+ // Add user to local list
+ this.userList.add(registeredUser);
+
// Is the account public?
if (Objects.equals(registeredUser.getUserProfileMode(), ProfileMode.PUBLIC)) {
// Also add it to this list
// Remove this contact from selectable list
assert(this.selectableContacts.remove(event.getAddedUser().getUserContact())) : "contact was not removed"; //NOI18N
+
+ // Add user to local list
+ this.userList.add(event.getAddedUser());
}
@Override
System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: this.visibleUserList.size()={0} - EXIT!", this.visibleUserList.size())); //NOI18N
}
+ @Override
+ public List<User> allUsers () {
+ // Return it
+ return Collections.unmodifiableList(this.userList);
+ }
+
@Override
public List<User> allVisibleUsers () {
// Return it
this.userProfileMode = userProfileMode;
}
+ @Override
+ public boolean hasUsers () {
+ return (!this.allUsers().isEmpty());
+ }
+
/**
* Post-initialization of this class
*/
// Initialize user list
this.visibleUserList = this.userBean.allPublicUsers();
}
-
- // Get all users
- List<User> allUsers = this.adminController.allUsers();
+ // Initialize user list
+ this.userList = this.userBean.allUsers();
// Get all contacts
List<Contact> allContacts = this.contactBean.getAllContacts();
Contact next = iterator.next();
// Get iterator
- Iterator<User> userIterator = allUsers.iterator();
+ Iterator<User> userIterator = this.userList.iterator();
// Loop through all users
while (userIterator.hasNext()) {
this.selectableContacts = allContacts;
}
+ @Override
+ public boolean isContactFound (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 is not found
+ boolean isFound = false;
+
+ // Get iterator
+ Iterator<User> iterator = this.allUsers().iterator();
+
+ // Loop through all entries
+ while (iterator.hasNext()) {
+ // Get user
+ User next = iterator.next();
+
+ // Compare both objects
+ if (Objects.equals(contact, next.getUserContact())) {
+ // Found it
+ isFound = true;
+ break;
+ }
+ }
+
+ // Return status
+ return isFound;
+ }
+
+ @Override
+ public void afterUserUpdatedPersonalData (@Observes final UpdatedUserPersonalDataEvent event) {
+ // Check parameter
+ 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) {
+ // ... and again
+ throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
+ } else if (event.getUpdatedUser().getUserId() < 1) {
+ // Invalid value
+ throw new IllegalArgumentException(MessageFormat.format("event.updatedUser.userId={0} is in valid", event.getUpdatedUser().getUserId())); //NOI18N
+ }
+
+ // All fine, so update list
+ this.updateList(event.getUpdatedUser());
+ }
+
@Override
public boolean isRequiredChangePersonalDataSet () {
return ((this.getUserProfileMode() != null) &&
this.contactController.addEmailAddress(user.getUserContact().getContactEmailAddress());
}
+ /**
+ * Updates list with given user instance
+ * <p>
+ * @param user User instance
+ */
+ @Override
+ public void updateList (final User user) {
+ // The user should be valid
+ if (null == user) {
+ // Throw NPE
+ throw new NullPointerException("user 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
+ Iterator<User> iterator = this.userList.iterator();
+
+ // Look whole list
+ while (iterator.hasNext()) {
+ // Get next element
+ User next = iterator.next();
+
+ // Is the same user id?
+ if (Objects.equals(user.getUserId(), next.getUserId())) {
+ // Found it, so remove it
+ this.userList.remove(next);
+ break;
+ }
+ }
+
+ // Re-add item
+ this.userList.add(user);
+ }
+
/**
* Clears this bean
*/
import org.mxchange.jusercore.events.login.UserLoggedInEvent;
import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
+import org.mxchange.jusercore.events.user.update.UpdatedUserPersonalDataEvent;
import org.mxchange.jusercore.exceptions.UserNotFoundException;
import org.mxchange.jusercore.model.user.User;
import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
*/
public static final Integer MINIMUM_PASSWORD_LENGTH = 5;
+ /**
+ * All users
+ * <p>
+ * @return A list of all public user profiles
+ */
+ List<User> allUsers ();
+
+ /**
+ * Checks whether users are registered
+ * <p>
+ * @return Whether users are registered
+ */
+ boolean hasUsers ();
+
+ /**
+ * Checks whether the given contact is a user
+ * <p>
+ * @param contact Contact to check
+ * <p>
+ * @return Whether the contact is a user
+ */
+ boolean isContactFound (final Contact contact);
+
+ /**
+ * Listens to fired event when user updated personal data
+ * <p>
+ * @param event Event being fired
+ */
+ void afterUserUpdatedPersonalData (final UpdatedUserPersonalDataEvent event);
+
+ void updateList (final User user);
+
/**
* Returns a list of all selectable contacts for user creation. Contacts
* from already existing users are excluded in this list.
* <p>
* @param event Event being fired
*/
- void afterAdminAddedUserEvent(final AdminAddedUserEvent event);
+ void afterAdminAddedUserEvent (final AdminAddedUserEvent event);
/**
* Event observer for new user registrations
<h:outputText value="#{contact.contactFamilyName}" />
</h:column>
+ <h:column>
+ <f:facet name="header">#{msg.ADMIN_CONTACT_USER_CUSTOMER_USAGE}</f:facet>
+
+ <h:outputText value="#{msg[adminHelper.getUserCustomerUsageMessageKey(contact)]}" />
+ </h:column>
+
<h:column>
<f:facet name="header">#{msg.ADMIN_CONTACT_CREATED}</f:facet>
</ui:define>
<ui:define name="content">
- <h:dataTable id="table_list_customers" var="customer" value="#{adminCustomerController.allCustomers()}" styleClass="table_big" headerClass="table_header_column" summary="#{msg.TABLE_SUMMARY_ADMIN_LIST_CUSTOMER}" rendered="#{adminCustomerController.hasCustomers()}">
+ <h:dataTable id="table_list_customers" var="customer" value="#{customerController.allCustomers()}" styleClass="table_big" headerClass="table_header_column" summary="#{msg.TABLE_SUMMARY_ADMIN_LIST_CUSTOMER}" rendered="#{customerController.hasCustomers()}">
<h:column>
<f:facet name="header">#{msg.ADMIN_LIST_CUSTOMER_ID}</f:facet>
</h:column>
<h:column>
- <f:facet name="header">#{msg.ADMIN_LIST_CUSTOMER_GENDER}</f:facet>
+ <f:facet name="header">#{msg.ADMIN_CONTACT_GENDER}</f:facet>
<h:outputText value="#{msg[customer.customerContact.contactGender.messageKey]}" />
</h:column>
<h:column>
- <f:facet name="header">#{msg.ADMIN_LIST_CUSTOMER_FIRST_NAME}</f:facet>
+ <f:facet name="header">#{msg.ADMIN_CONTACT_FIRST_NAME}</f:facet>
<h:outputText value="#{customer.customerContact.contactFirstName}" />
</h:column>
<h:column>
- <f:facet name="header">#{msg.ADMIN_LIST_CUSTOMER_FAMILY_NAME}</f:facet>
+ <f:facet name="header">#{msg.ADMIN_CONTACT_FAMILY_NAME}</f:facet>
<h:outputText value="#{customer.customerContact.contactFamilyName}" />
</h:column>
</ui:define>
<ui:define name="content">
- <h:dataTable id="table_list_users" var="user" value="#{adminUserController.allUsers()}" styleClass="table_big" headerClass="table_header_column" summary="#{msg.TABLE_SUMMARY_ADMIN_LIST_USERS}" rendered="#{adminUserController.hasUsers()}">
+ <h:dataTable id="table_list_users" var="user" value="#{userController.allUsers()}" styleClass="table_big" headerClass="table_header_column" summary="#{msg.TABLE_SUMMARY_ADMIN_LIST_USERS}" rendered="#{userController.hasUsers()}">
<h:column>
- <f:facet name="header">#{msg.ADMIN_LIST_USER_ID}</f:facet>
+ <f:facet name="header">#{msg.ADMIN_USER_ID}</f:facet>
<h:link outcome="admin_show_user" title="#{msg.ADMIN_LINK_SHOW_USER_TITLE}" value="#{user.userId}">
<f:param name="userId" value="#{user.userId}" />
</h:column>
<h:column>
- <f:facet name="header">#{msg.ADMIN_LIST_USER_NAME}</f:facet>
+ <f:facet name="header">#{msg.ADMIN_USER_NAME}</f:facet>
<h:outputText value="#{user.userName}" />
</h:column>
<h:column>
- <f:facet name="header">#{msg.ADMIN_LIST_USER_GENDER}</f:facet>
+ <f:facet name="header">#{msg.ADMIN_CONTACT_GENDER}</f:facet>
<h:outputText value="#{msg[user.userContact.contactGender.messageKey]}" />
</h:column>
<h:column>
- <f:facet name="header">#{msg.ADMIN_LIST_USER_FIRST_NAME}</f:facet>
+ <f:facet name="header">#{msg.ADMIN_CONTACT_FIRST_NAME}</f:facet>
<h:outputText value="#{user.userContact.contactFirstName}" />
</h:column>
<h:column>
- <f:facet name="header">#{msg.ADMIN_LIST_USER_FAMILY_NAME}</f:facet>
+ <f:facet name="header">#{msg.ADMIN_CONTACT_FAMILY_NAME}</f:facet>
<h:outputText value="#{user.userContact.contactFamilyName}" />
</h:column>
<h:column>
- <f:facet name="header">#{msg.ADMIN_LIST_USER_ACCOUNT_STATUS}</f:facet>
+ <f:facet name="header">#{msg.ADMIN_USER_ACCOUNT_STATUS}</f:facet>
<h:outputText styleClass="#{user.userAccountStatus.styleClass}" value="#{msg[user.userAccountStatus.messageKey]}" />
</h:column>
<h:column>
- <f:facet name="header">#{msg.ADMIN_LIST_USER_PROFILE_MODE}</f:facet>
+ <f:facet name="header">#{msg.ADMIN_USER_PROFILE_MODE}</f:facet>
<h:outputText value="#{msg[user.userProfileMode.messageKey]}" />
</h:column>
<h:column>
- <f:facet name="header">#{msg.ADMIN_LIST_USER_CREATED}</f:facet>
+ <f:facet name="header">#{msg.ADMIN_USER_CREATED}</f:facet>
<h:outputText id="userCreated" value="#{user.userCreated.time}">
<f:convertDateTime for="userCreated" type="both" timeStyle="short" dateStyle="short" />