import java.text.MessageFormat;
import java.util.Collections;
import java.util.Date;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
-import java.util.Map;
import java.util.Objects;
import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
-import org.mxchange.jphone.phonenumbers.phone.AdminPhoneSessionBeanRemote;
import org.mxchange.jusercore.events.confirmation.UserConfirmedAccountEvent;
import org.mxchange.jusercore.events.login.UserLoggedInEvent;
import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
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.phone.PizzaAdminPhoneWebRequestController;
import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController;
/**
*/
private static final long serialVersionUID = 542_145_347_916L;
- /**
- * Remote EJB for phone number (administrative)
- */
- private AdminPhoneSessionBeanRemote adminPhoneBean;
-
- /**
- * Administrative phone controller
- */
- @Inject
- private PizzaAdminPhoneWebRequestController adminPhoneController;
-
/**
* Birth day
*/
*/
private Long cellphoneNumber;
- /**
- * All cell phone numbers
- */
- private final List<DialableCellphoneNumber> cellphoneNumbers;
-
/**
* City
*/
*/
private final List<Contact> contactList;
- /**
- * "Cache" for contact lists, mostly only one is assigned. So this cache
- * shouldn't grow beyond control.
- */
- private final Map<Long, List<Contact>> contacts;
-
/**
* Country instance
*/
// Try to lookup
this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
-
- // 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.cellphoneNumbers = new LinkedList<>();
- this.contacts = new HashMap<>(10);
this.contactList = new LinkedList<>();
this.emailAddressList = new LinkedList<>();
}
}
@Override
- public List<Contact> allCellphoneContacts () {
- // Get id
- Long phoneId = this.adminPhoneController.getCellPhone().getPhoneId();
-
- // Is cache there?
- if (this.contacts.containsKey(phoneId)) {
- // Return cached version
- return this.contacts.get(phoneId);
- } else {
- // Ask bean
- List<Contact> list = new LinkedList<>();
-
- // "Walk" through all contacts
- for (final Contact contact : this.contactList) {
- // Is cellphone instance the same?
- if (Objects.equals(contact.getContactCellphoneNumber(), this.adminPhoneController.getCellPhone())) {
- // Found one
- list.add(contact);
- }
- }
-
- // Store result in cache
- this.contacts.put(phoneId, list);
-
- // Return now-cached list
- return list;
- }
- }
-
- @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 Collections.unmodifiableList(this.contactList);
+ return this.contactList;
}
@Override
this.zipCode = zipCode;
}
- @Override
- public boolean hasContacts () {
- return (!this.contactList.isEmpty());
- }
-
/**
* Post-initialization of this class
*/
// Set contact list
this.selectableContacts = allContacts;
-
- // All phone numbers
- this.cellphoneNumbers.addAll(this.adminPhoneBean.allCellphoneNumbers());
}
@Override
*/
List<Contact> allContacts ();
- /**
- * Getter for all contacts having current cellphone instance linked
- * <p>
- * @return List of all linked contacts
- */
- List<Contact> allCellphoneContacts ();
-
- /**
- * Checks whether there are contacts.
- * <p>
- * @return Whether contacts are there
- */
- boolean hasContacts ();
-
/**
* Event observer for newly added users by adminstrator
* <p>
--- /dev/null
+/*
+ * Copyright (C) 2016 Cho-Time GmbH
+ *
+ * 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 java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import javax.annotation.PostConstruct;
+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.jcontacts.events.contact.add.AdminAddedContactEvent;
+import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
+import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
+import org.mxchange.jphone.phonenumbers.phone.AdminPhoneSessionBeanRemote;
+import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
+import org.mxchange.pizzaapplication.beans.BasePizzaController;
+import org.mxchange.pizzaapplication.beans.contact.PizzaContactWebSessionController;
+import org.mxchange.pizzaapplication.beans.phone.PizzaAdminPhoneWebRequestController;
+
+/**
+ * A general contact bean (controller)
+ * <p>
+ * @author Roland Haeder<rhaeder@cho-time.de>
+ */
+@Named ("contactPhoneController")
+@SessionScoped
+public class PizzaContactPhoneWebSessionBean extends BasePizzaController implements PizzaContactPhoneWebSessionController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 542_145_347_916L;
+
+ /**
+ * Remote EJB for phone number (administrative)
+ */
+ private AdminPhoneSessionBeanRemote adminPhoneBean;
+
+ /**
+ * Administrative phone controller
+ */
+ @Inject
+ private PizzaAdminPhoneWebRequestController adminPhoneController;
+
+ /**
+ * All cell phone numbers
+ */
+ private final List<DialableCellphoneNumber> cellphoneNumbers;
+
+ /**
+ * General contact controller
+ */
+ @Inject
+ private PizzaContactWebSessionController contactController;
+
+ /**
+ * "Cache" for contact lists, mostly only one is assigned. So this cache
+ * shouldn't grow beyond control.
+ */
+ private final Map<Long, 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/jlandingpage-ejb/adminphone!org.mxchange.jphone.phonenumbers.phone.AdminPhoneSessionBeanRemote"); //NOI18N
+ } catch (final NamingException e) {
+ // Throw again
+ throw new FaceletException(e);
+ }
+
+ // Init lists/maps
+ this.cellphoneNumbers = new LinkedList<>();
+ this.contacts = new HashMap<>(10);
+ }
+
+ @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.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
+ }
+
+ // Clear this bean
+ this.clear();
+ }
+
+ @Override
+ public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent 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();
+ }
+
+ @Override
+ public void afterAdminUpdatedContactDataEvent (@Observes final AdminUpdatedContactEvent 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
+ }
+ }
+
+ @Override
+ public List<Contact> allCellphoneContacts () {
+ // Get id
+ Long phoneId = this.adminPhoneController.getCellPhone().getPhoneId();
+
+ // Is cache there?
+ if (this.contacts.containsKey(phoneId)) {
+ // Return cached version
+ return this.contacts.get(phoneId);
+ } 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.getContactCellphoneNumber(), this.adminPhoneController.getCellPhone())) {
+ // Found one
+ list.add(contact);
+ }
+ }
+
+ // Store result in cache
+ this.contacts.put(phoneId, list);
+
+ // Return now-cached list
+ return list;
+ }
+ }
+
+ /**
+ * Post-initialization of this class
+ */
+ @PostConstruct
+ public void init () {
+ // All phone numbers
+ this.cellphoneNumbers.addAll(this.adminPhoneBean.allCellphoneNumbers());
+ }
+
+ /**
+ * Clears this bean
+ */
+ private void clear () {
+ // Clear all data
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2016 Cho-Time GmbH
+ *
+ * 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 java.util.List;
+import javax.ejb.Local;
+import org.mxchange.jcontacts.contact.Contact;
+import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
+import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
+import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
+
+/**
+ * An interface for user beans
+ * <p>
+ * @author Roland Haeder<rhaeder@cho-time.de>
+ */
+@Local
+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
+ * <p>
+ * @return List of all linked contacts
+ */
+ List<Contact> allCellphoneContacts ();
+
+ /**
+ * Event observer for newly added users by adminstrator
+ * <p>
+ * @param event Event being fired
+ */
+ void afterAdminAddedUserEvent (final AdminAddedUserEvent event);
+
+ /**
+ * Observes events being fired when an administrator has added a new
+ * contact.
+ * <p>
+ * @param event Event being fired
+ */
+ void afterAdminAddedContact (final AdminAddedContactEvent event);
+
+ /**
+ * Event observer for updated contact data by administrators
+ * <p>
+ * @param event Updated contact data event
+ */
+ void afterAdminUpdatedContactDataEvent (final AdminUpdatedContactEvent event);
+
+}
package org.mxchange.pizzaapplication.beans.country;
import java.text.MessageFormat;
-import java.util.Collections;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
@Override
public List<Country> allCountries () {
// Return "cached" version
- return Collections.unmodifiableList(this.countryList);
- }
-
- @Override
- public boolean hasCountries () {
- return (!this.countryList.isEmpty());
+ return this.countryList;
}
/**
*/
List<Country> allCountries ();
- /**
- * Checks whether countries has been registered
- * <p>
- * @return Whether countries has been registered
- */
- boolean hasCountries ();
-
/**
* Observing method when the event is fired that an administrator added a
* new country
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;
}
@Override
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
public List<User> allUsers () {
// Return it
- return Collections.unmodifiableList(this.userList);
+ return this.userList;
}
@Override
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
public List<User> allVisibleUsers () {
// Return it
- return Collections.unmodifiableList(this.visibleUserList);
+ return this.visibleUserList;
}
@Override
this.userProfileMode = userProfileMode;
}
- @Override
- public boolean hasUsers () {
- return (!this.allUsers().isEmpty());
- }
-
/**
* Post-initialization of this class
*/
*/
List<User> allVisibleUsers ();
- /**
- * Checks whether users are registered
- * <p>
- * @return Whether users are registered
- */
- boolean hasUsers ();
-
/**
* Checks whether the given contact is a user
* <p>
<ui:param name="isShowPage" value="#{true}" />
</ui:include>
- <h:dataTable id="contact_cellphone_link" var="contact" value="#{adminPhoneController.allCellphoneContacts()}" summary="#{msg.TABLE_SUMMARY_ADMIN_SHOW_CELLPHONE_LINKS}" headerClass="table_header_column" styleClass="table_medium">
+ <h:dataTable id="contact_cellphone_link" var="contact" value="#{contactPhoneController.allCellphoneContacts()}" summary="#{msg.TABLE_SUMMARY_ADMIN_SHOW_CELLPHONE_LINKS}" headerClass="table_header_column" styleClass="table_medium">
<f:facet name="header">
<h:outputFormat value="#{msg.ADMIN_HEADER_SHOW_CELLPHONE_LINKS}">
<f:param value="#{adminPhoneController.cellPhone.phoneId}" />
<ui:define name="content">
<h:form id="form_export_contacts">
- <p:dataTable id="table_export_contacts" var="contact" value="#{contactController.allContacts()}" tableStyleClass="table_big" paginator="true" rows="10" summary="#{msg.TABLE_SUMMARY_ADMIN_EXPORT_CONTACT}" rendered="#{contactController.hasContacts()}">
+ <p:dataTable id="table_export_contacts" var="contact" value="#{contactController.allContacts()}" tableStyleClass="table_big" paginator="true" rows="10" summary="#{msg.TABLE_SUMMARY_ADMIN_EXPORT_CONTACT}" rendered="#{not contactController.allContacts().isEmpty()}">
<p:column exportable="false">
<f:facet name="header">
<h:outputText value="#{msg.ADMIN_EXPORT_CONTACT_ID}" />
</ui:define>
<ui:define name="content">
- <h:dataTable id="table_list_contacts" var="contact" value="#{contactController.allContacts()}" styleClass="table_big" headerClass="table_header_column" summary="#{msg.TABLE_SUMMARY_ADMIN_LIST_CONTACT}" rendered="#{contactController.hasContacts()}">
+ <h:dataTable id="table_list_contacts" var="contact" value="#{contactController.allContacts()}" styleClass="table_big" headerClass="table_header_column" summary="#{msg.TABLE_SUMMARY_ADMIN_LIST_CONTACT}" rendered="#{not contactController.allContacts().isEmpty()}">
<h:column>
<f:facet name="header">
<h:outputText value="#{msg.ADMIN_CONTACT_ID}" />
</ui:define>
<ui:define name="content">
- <h:dataTable id="table_list_countries" var="country" value="#{countryController.allCountries()}" styleClass="table_medium" headerClass="table_header_column" summary="#{msg.TABLE_SUMMARY_ADMIN_LIST_COUNTRIES}" rendered="#{countryController.hasCountries()}">
+ <h:dataTable id="table_list_countries" var="country" value="#{countryController.allCountries()}" styleClass="table_medium" headerClass="table_header_column" summary="#{msg.TABLE_SUMMARY_ADMIN_LIST_COUNTRIES}" rendered="#{not countryController.allCountries().isEmpty()}">
<h:column>
<f:facet name="header">
<h:outputText value="#{msg.ADMIN_LIST_COUNTRY_DATA_COUNTRY_ID}" />
<ui:define name="content">
<h:form id="form_export_users">
- <p:dataTable id="table_export_users" var="user" value="#{userController.allUsers()}" tableStyleClass="table_big" paginator="true" rows="10" summary="#{msg.TABLE_SUMMARY_ADMIN_EXPORT_USER}" rendered="#{userController.hasUsers()}">
+ <p:dataTable id="table_export_users" var="user" value="#{userController.allUsers()}" tableStyleClass="table_big" paginator="true" rows="10" summary="#{msg.TABLE_SUMMARY_ADMIN_EXPORT_USER}" rendered="#{not userController.allUsers().isEmpty()}">
<p:column exportable="false">
<f:facet name="header">
<h:outputText value="#{msg.ADMIN_EXPORT_USER_ID}" />
</ui:define>
<ui:define name="content">
- <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: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="#{not userController.allUsers().isEmpty()}">
<h:column>
<f:facet name="header">
<h:outputText value="#{msg.ADMIN_LIST_USER_ID}" />