import java.text.MessageFormat;
import java.util.Date;
-import java.util.Iterator;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.event.Event;
*/
private Long contactId;
+ /**
+ * An instance of a contact list controller
+ */
+ @Inject
+ private JobsContactListWebViewController contactListController;
+
/**
* Email address
*/
final Contact contact = this.createContactInstance();
// Default is not same contact
- if (this.isSameContactFound(contact)) {
+ if (this.contactListController.isSameContactFound(contact)) {
// Already registered
throw new FaceletException(new ContactAlreadyAddedException(contact));
}
this.setComment(null);
}
- /**
- * Checks whether the given contact is found
- * <p>
- * @param contact Contact instance
- *
- * @return Whether contact has been found
- */
- private boolean isSameContactFound (final Contact contact) {
- // Default is not found
- boolean IsFound = false;
-
- // Get iterator
- final Iterator<Contact> iterator = this.contactController.allContacts().iterator();
-
- // Loop through all
- while (iterator.hasNext()) {
- // Get next contact
- final Contact next = iterator.next();
-
- // Is the same?
- if (Contacts.isSameContact(contact, next)) {
- // Yes, then abort loop
- IsFound = false;
- break;
- }
- }
-
- // Return status
- return IsFound;
- }
-
/**
* Updates all data in contact instance.
* <p>
*/
package org.mxchange.jjobs.beans.contact;
-import fish.payara.cdi.jsr107.impl.NamedCache;
import java.text.MessageFormat;
import java.util.Date;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
import java.util.Objects;
-import javax.annotation.PostConstruct;
-import javax.cache.Cache;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.event.Observes;
import javax.faces.view.facelets.FaceletException;
import javax.inject.Inject;
import javax.inject.Named;
-import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
-import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
-import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
import org.mxchange.jcontacts.model.contact.Contact;
import org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote;
import org.mxchange.jcontacts.model.contact.Contacts;
import org.mxchange.jcontacts.model.contact.title.PersonalTitle;
import org.mxchange.jcountry.model.data.Country;
import org.mxchange.jjobs.beans.BaseJobsBean;
-import org.mxchange.jjobs.beans.user.JobsUserWebRequestController;
+import org.mxchange.jjobs.beans.contact.list.JobsContactListWebViewController;
import org.mxchange.jjobs.beans.user.login.JobsUserLoginWebSessionController;
import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber;
import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider;
import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent;
-import org.mxchange.jusercore.model.user.User;
-import org.mxchange.juserlogincore.events.confirmation.ObservableUserConfirmedAccountEvent;
import org.mxchange.juserlogincore.events.login.ObservableUserLoggedInEvent;
-import org.mxchange.juserlogincore.events.registration.ObservableUserRegisteredEvent;
import org.mxchange.juserlogincore.exceptions.UserPasswordMismatchException;
/**
private ContactSessionBeanRemote contactBean;
/**
- * Contact list
+ * An instance of a contact-list backing bean
*/
- @Inject
- @NamedCache (cacheName = "contactCache")
- private Cache<Long, Contact> contactCache;
+ private JobsContactListWebViewController contactListController;
/**
* Country instance
*/
private String emailAddress;
- /**
- * Email address list
- */
- @Inject
- @NamedCache (cacheName = "emailAddressCache")
- private Cache<Long, String> emailAddressCache;
-
/**
* Email address repeated
*/
*/
private PersonalTitle personalTitle;
- /**
- * A list of all selectable contacts
- */
- @Inject
- @NamedCache (cacheName = "selectableContactsCache")
- private Cache<Long, Contact> selectableContactsCache;
-
/**
* Street
*/
private String street;
- /**
- * Regular user controller
- */
- @Inject
- private JobsUserWebRequestController userController;
-
/**
* Login bean (controller)
*/
super();
}
- /**
- * 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 //NOI18N
- }
-
- // Clear this bean
- this.clear();
-
- // Call other method
- this.uniqueAddContact(event.getAddedContact());
-
- // Add to selectable contacts
- this.selectableContactsCache.put(event.getAddedContact().getContactId(), event.getAddedContact());
- }
-
/**
* Event observer for newly added users by administrator
* <p>
throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserContact().getContactId())); //NOI18N
}
- // Remove contact from list available contacts list
- this.selectableContactsCache.remove(event.getLinkedUser().getUserContact().getContactId());
-
// 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("userId of user={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
- }
-
- // Add contact instance only once
- this.uniqueAddContact(event.getUpdatedContact());
-
- // Add email address to list
- this.emailAddressCache.put(event.getUpdatedContact().getContactId(), event.getUpdatedContact().getContactEmailAddress());
- }
-
- /**
- * 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) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getConfirmedUser() == null) {
- // Throw NPE again
- throw new NullPointerException("event.confirmedUser is null"); //NOI18N
- } else if (event.getConfirmedUser().getUserId() == null) {
- // userId is null
- throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
- } else if (event.getConfirmedUser().getUserId() < 1) {
- // Not avalid id
- throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
- }
-
- // Add contact instance only once
- this.uniqueAddContact(event.getConfirmedUser().getUserContact());
- }
-
/**
* Event observer for logged-in user
* <p>
this.copyContact(event.getLoggedInUser().getUserContact());
}
- /**
- * 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
- final Contact registeredContact = event.getRegisteredUser().getUserContact();
-
- // 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);
-
- // Clear all data
- this.clear();
- }
-
- @Override
- @SuppressWarnings ("ReturnOfCollectionOrArrayField")
- public List<Contact> allContacts () {
- // Init list
- final List<Contact> list = new LinkedList<>();
-
- // Get iterator
- final Iterator<Cache.Entry<Long, Contact>> iterator = this.contactCache.iterator();
-
- // Loop over all
- while (iterator.hasNext()) {
- // Get next entry
- final Cache.Entry<Long, Contact> next = iterator.next();
-
- // Add value to list
- list.add(next.getValue());
- }
-
- // Return it
- return list;
- }
-
@Override
public void clearEmailAddresses () {
// Clear both
return "contact_data_saved"; //NOI18N
}
- @Override
- public Contact findContactById (final Long contactId) throws ContactNotFoundException {
- // Validate parameter
- if (null == contactId) {
- // Throw NPE
- throw new NullPointerException("contactId is null"); //NOI18N
- } else if (contactId < 1) {
- // Throw IAE
- throw new IllegalArgumentException("contactId=" + contactId + " is invalid"); //NOI18N
- } else if (!this.contactCache.containsKey(contactId)) {
- // Not found
- throw new ContactNotFoundException(contactId);
- }
-
- // Get it from cache
- final Contact contact = this.contactCache.get(contactId);
-
- // Return it
- return contact;
- }
-
/**
* Getter for academic title
* <p>
this.zipCode = zipCode;
}
- /**
- * Post-construction method
- */
- @PostConstruct
- public void init () {
- // Is cache there?
- if (!this.contactCache.iterator().hasNext()) {
- // Get whole list from EJB
- final List<Contact> contacts = this.contactBean.allContacts();
-
- // Add all
- for (final Contact contact : contacts) {
- // Add it to cache
- this.contactCache.put(contact.getContactId(), contact);
-
- // Is email address given?
- if (contact.getContactEmailAddress() != null) {
- // Set it, too
- this.emailAddressCache.put(contact.getContactId(), contact.getContactEmailAddress());
- }
- }
- } else if (this.selectableContactsCache.iterator().hasNext()) {
- // Has already entries, avoid executing below code
- return;
- }
-
- // Get all users
- final List<User> allUsers = this.userController.allUsers();
-
- // Get iterator from contacts cache
- final Iterator<Cache.Entry<Long, Contact>> iterator = this.contactCache.iterator();
-
- // Loop through all contacts
- while (iterator.hasNext()) {
- // Get next element
- final Cache.Entry<Long, Contact> next = iterator.next();
-
- // Default is not found
- boolean isFound = false;
-
- // User list is not empty, check each entry, if contact is found
- for (final User user : allUsers) {
- // Is the contact the same?
- if (Objects.equals(user.getUserContact(), next.getValue())) {
- // Found one
- isFound = true;
- break;
- }
- }
-
- // Is contact not found?
- if (!isFound) {
- // Add it as selectable
- this.selectableContactsCache.put(next.getKey(), next.getValue());
- }
- }
- }
-
@Override
public boolean isEmailAddressRegistered (final Contact contact) {
// Cherck parameter
throw new IllegalArgumentException("contact.contactEmailAddress is empty."); //NOI18N
}
+ // Default is not registered
+ boolean isRegistered = false;
+
// Determine it
- return ((this.emailAddressCache instanceof List) && (this.emailAddressCache.containsKey(contact.getContactId())));
+ for (final Contact currentContact : this.contactListController.getAllContacts()) {
+ // Is same contact found?
+ if (currentContact.getContactEmailAddress().equals(contact.getContactEmailAddress())) {
+ // Found same email address
+ isRegistered = true;
+
+ // Skipp further iterations
+ break;
+ }
+ }
+
+ // Return status
+ return isRegistered;
}
@Override
return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
}
- /**
- * 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
- */
- public List<Contact> selectableContacts () {
- // Init list
- final List<Contact> selectableContacts = new LinkedList<>();
-
- // Get iterator from cache
- final Iterator<Cache.Entry<Long, Contact>> iterator = this.contactCache.iterator();
-
- // Loop through all contacts
- while (iterator.hasNext()) {
- // Get next element
- final Cache.Entry<Long, Contact> next = iterator.next();
-
- // Add entry's value to list
- selectableContacts.add(next.getValue());
- }
-
- // Return list
- return selectableContacts;
- }
-
@Override
public void updateContactDataFromController (final Contact contact) {
// Is the instance valid?
this.copyContact(contact);
}
- /**
- * Adds email address to bean's internal list.
- * <p>
- * @param contact Contact instance
- */
- private void addUserNameEmailAddress (final Contact contact) {
- // Make sure the entry is not added yet
- if (this.emailAddressCache.containsKey(contact.getContactId())) {
- // Already added
- throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N
- }
-
- // Add email addres
- this.emailAddressCache.put(contact.getContactId(), contact.getContactEmailAddress());
- }
-
/**
* Clears this bean
*/
}
}
- /**
- * Removes given contact from all lists
- * <p>
- * @param contact Contact instance to remove
- */
- private void removeContact (final Contact contact) {
- // Remove from general list
- if (!this.contactCache.remove(contact.getContactId())) {
- // Did not remove contact
- throw new IllegalStateException(MessageFormat.format("contact {0} was not removed.", contact.getContactId())); //NOI18N
- }
-
- // Remove from other lists
- this.emailAddressCache.remove(contact.getContactId());
- }
-
- /**
- * Adds unique instance to contact list. First any existing instance is
- * being removed, then the new instance is added.
- * <p>
- * @param contact Contact instance to add uniquely
- */
- private void uniqueAddContact (final Contact contact) {
- // Get iterator from list
- final Iterator<Cache.Entry<Long, Contact>> iterator = this.contactCache.iterator();
-
- // "Walk" through all entries
- while (iterator.hasNext()) {
- // Get next element
- final Cache.Entry<Long, Contact> next = iterator.next();
-
- // Is id number the same?
- if (Objects.equals(contact.getContactId(), next.getKey())) {
- // Found entry, so remove it and abort
- this.removeContact(next.getValue());
- break;
- }
- }
-
- // Add contact to list
- this.contactCache.put(contact.getContactId(), contact);
- }
-
}
package org.mxchange.jjobs.beans.contact;
import java.io.Serializable;
-import java.util.List;
-import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
import org.mxchange.jcontacts.model.contact.Contact;
/**
*/
void clearEmailAddresses ();
- /**
- * Returns a list of all found contacts
- * <p>
- * @return A list of all contacts.
- */
- List<Contact> allContacts ();
-
/**
* Updates all data from bean in given contact instance
* <p>
*/
String doChangePersonalContactData ();
- /**
- * Returns a contact instance which has the given id number.
- * <p>
- * @param contactId Contact id
- * <p>
- * @return Contact instance
- * <p>
- * @throws ContactNotFoundException If the contact was not found
- */
- Contact findContactById (final Long contactId) throws ContactNotFoundException;
-
/**
* Checks whether the given email address is already registered. The email
* address should be validated by EmailAddressValidator before calling this
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2020 Free Software Foundation
+ *
+ * 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.jjobs.beans.contact.list;
+
+import fish.payara.cdi.jsr107.impl.NamedCache;
+import java.text.MessageFormat;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Objects;
+import javax.annotation.PostConstruct;
+import javax.cache.Cache;
+import javax.ejb.EJB;
+import javax.enterprise.event.Observes;
+import javax.faces.view.ViewScoped;
+import javax.inject.Inject;
+import javax.inject.Named;
+import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
+import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
+import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
+import org.mxchange.jcontacts.model.contact.Contact;
+import org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote;
+import org.mxchange.jcontacts.model.contact.Contacts;
+import org.mxchange.jjobs.beans.BaseJobsBean;
+import org.mxchange.jphone.model.phonenumbers.DialableNumber;
+import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
+import org.mxchange.juserlogincore.events.confirmation.ObservableUserConfirmedAccountEvent;
+import org.mxchange.juserlogincore.events.registration.ObservableUserRegisteredEvent;
+
+/**
+ * A regular contact list bean (controller)
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("contactListController")
+@ViewScoped
+public class JobsContactListWebViewBean extends BaseJobsBean implements JobsContactListWebViewController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 542_145_347_917L;
+
+ /**
+ * All contacts
+ */
+ private final List<Contact> allContacts;
+
+ /**
+ * Administrative contact EJB
+ */
+ @EJB (lookup = "java:global/jjobs-ejb/contact!org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote")
+ private ContactSessionBeanRemote contactBean;
+
+ /**
+ * Contact list
+ */
+ @Inject
+ @NamedCache (cacheName = "contactCache")
+ private transient Cache<Long, Contact> contactCache;
+
+ /**
+ * A list of filtered contacts
+ */
+ private List<Contact> filteredContacts;
+
+ /**
+ * Current selected contact
+ */
+ private Contact selectedContact;
+
+ /**
+ * Default constructor
+ */
+ public JobsContactListWebViewBean () {
+ // Call super constructor
+ super();
+
+ // Init list
+ this.allContacts = new LinkedList<>();
+ }
+
+ /**
+ * 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 //NOI18N
+ }
+
+ // Call other method
+ this.uniqueAddContact(event.getAddedContact());
+ }
+
+ /**
+ * 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("userId of user={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
+ }
+
+ // Add contact instance only once
+ this.uniqueAddContact(event.getUpdatedContact());
+ }
+
+ /**
+ * 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) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getConfirmedUser() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.confirmedUser is null"); //NOI18N
+ } else if (event.getConfirmedUser().getUserId() == null) {
+ // userId is null
+ throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
+ } else if (event.getConfirmedUser().getUserId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
+ }
+
+ // Add contact instance only once
+ this.uniqueAddContact(event.getConfirmedUser().getUserContact());
+ }
+
+ /**
+ * 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
+ final Contact registeredContact = event.getRegisteredUser().getUserContact();
+
+ // Add contact instance only once
+ this.uniqueAddContact(registeredContact);
+ }
+
+ @Override
+ public Contact findContactById (final Long contactId) throws ContactNotFoundException {
+ // Validate parameter
+ if (null == contactId) {
+ // Throw NPE
+ throw new NullPointerException("contactId is null"); //NOI18N
+ } else if (contactId < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException("contactId=" + contactId + " is invalid"); //NOI18N
+ } else if (!this.contactCache.containsKey(contactId)) {
+ // Not found
+ throw new ContactNotFoundException(contactId);
+ }
+
+ // Get it from cache
+ final Contact contact = this.contactCache.get(contactId);
+
+ // Return it
+ return contact;
+ }
+
+ /**
+ * Returns a text representation of given mobile number or null if not set.
+ * <p>
+ * @param mobileNumber Mobile number
+ * <p>
+ * @return Text representation or null
+ */
+ public String generateMobileNumber (final DialableMobileNumber mobileNumber) {
+ // Is it null?
+ if (null == mobileNumber) {
+ // Return null
+ return null;
+ }
+
+ // Get all data
+ final String number = String.format(
+ "%s%d%d", //NOI18N
+ mobileNumber.getMobileProvider().getProviderCountry().getCountryExternalDialPrefix(),
+ mobileNumber.getMobileProvider().getProviderDialPrefix(),
+ mobileNumber.getPhoneNumber()
+ );
+
+ // Return it
+ return number;
+ }
+
+ /**
+ * Returns a text representation of given land-line or fax number or null if
+ * not set.
+ * <p>
+ * @param phoneNumber Land-line or fax number
+ * <p>
+ * @return Text representation or null
+ */
+ public String generatePhoneNumber (final DialableNumber phoneNumber) {
+ // Is it null?
+ if (null == phoneNumber) {
+ // Return null
+ return null;
+ }
+
+ // Generate it
+ final String number = String.format(
+ "%s%d%d", //NOI18N
+ phoneNumber.getPhoneCountry().getCountryExternalDialPrefix(),
+ phoneNumber.getPhoneAreaCode(),
+ phoneNumber.getPhoneNumber()
+ );
+
+ // Return it
+ return number;
+ }
+
+ @Override
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<Contact> getAllContacts () {
+ return this.allContacts;
+ }
+
+ /**
+ * Getter for filtered contacts
+ * <p>
+ * @return
+ */
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<Contact> getFilteredContacts () {
+ return this.filteredContacts;
+ }
+
+ /**
+ * Setter for filtered contacts
+ * <p>
+ * @param filteredContacts Filtered contacts list
+ */
+ @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
+ public void setFilteredContacts (final List<Contact> filteredContacts) {
+ this.filteredContacts = filteredContacts;
+ }
+
+ /**
+ * Getter for selected contact
+ * <p>
+ * @return Selected Contact instance
+ */
+ public Contact getSelectedContact () {
+ return this.selectedContact;
+ }
+
+ /**
+ * Setter for selected contact
+ * <p>
+ * @param selectedContact
+ */
+ public void setSelectedContact (final Contact selectedContact) {
+ this.selectedContact = selectedContact;
+ }
+
+ /**
+ * Post-construction method
+ */
+ @PostConstruct
+ public void init () {
+ // Is cache there?
+ if (!this.contactCache.iterator().hasNext()) {
+ // Get whole list from EJB
+ final List<Contact> contacts = this.contactBean.allContacts();
+
+ // Add all
+ for (final Contact contact : contacts) {
+ // Add it to cache
+ this.contactCache.put(contact.getContactId(), contact);
+ }
+ }
+
+ // Is cache there and list is not full?
+ if ((this.getAllContacts().isEmpty()) && (this.contactCache.iterator().hasNext())) {
+ // Get iterator
+ final Iterator<Cache.Entry<Long, Contact>> iterator = this.contactCache.iterator();
+
+ // Build up list
+ while (iterator.hasNext()) {
+ // GEt next element
+ final Cache.Entry<Long, Contact> next = iterator.next();
+
+ // Add to list
+ this.getAllContacts().add(next.getValue());
+ }
+
+ // Sort list
+ this.getAllContacts().sort(new Comparator<Contact>() {
+ @Override
+ public int compare (final Contact o1, final Contact o2) {
+ return o1.getContactId() > o2.getContactId() ? 1 : o1.getContactId() < o2.getContactId() ? -1 : 0;
+ }
+ });
+
+ // Set full list
+ this.setFilteredContacts(this.getAllContacts());
+ }
+ }
+
+ @Override
+ public boolean isSameContactFound (final Contact contact) {
+ // Default is not found
+ boolean IsFound = false;
+
+ // Get iterator
+ final Iterator<Contact> iterator = this.getAllContacts().iterator();
+
+ // Loop through all
+ while (iterator.hasNext()) {
+ // Get next contact
+ final Contact next = iterator.next();
+
+ // Is the same?
+ if (Contacts.isSameContact(contact, next)) {
+ // Yes, then abort loop
+ IsFound = false;
+ break;
+ }
+ }
+
+ // Return status
+ return IsFound;
+ }
+
+ /**
+ * Removes given contact from all lists
+ * <p>
+ * @param contact Contact instance to remove
+ */
+ private void removeContact (final Contact contact) {
+ // Remove from general list
+ if (!this.contactCache.remove(contact.getContactId())) {
+ // Did not remove contact
+ throw new IllegalStateException(MessageFormat.format("contact {0} was not removed.", contact.getContactId())); //NOI18N
+ }
+ }
+
+ /**
+ * Adds unique instance to contact list. First any existing instance is
+ * being removed, then the new instance is added.
+ * <p>
+ * @param contact Contact instance to add uniquely
+ */
+ private void uniqueAddContact (final Contact contact) {
+ // Get iterator from list
+ final Iterator<Cache.Entry<Long, Contact>> iterator = this.contactCache.iterator();
+
+ // "Walk" through all entries
+ while (iterator.hasNext()) {
+ // Get next element
+ final Cache.Entry<Long, Contact> next = iterator.next();
+
+ // Is id number the same?
+ if (Objects.equals(contact.getContactId(), next.getKey())) {
+ // Found entry, so remove it and abort
+ this.removeContact(next.getValue());
+ break;
+ }
+ }
+
+ // Add contact to list
+ this.contactCache.put(contact.getContactId(), contact);
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2020 Free Software Foundation
+ *
+ * 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.jjobs.beans.contact.list;
+
+import java.io.Serializable;
+import java.util.List;
+import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
+import org.mxchange.jcontacts.model.contact.Contact;
+
+/**
+ * An administrative interface for user beans
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface JobsContactListWebViewController extends Serializable {
+
+ /**
+ * Returns a contact instance which has the given id number.
+ * <p>
+ * @param contactId Contact id
+ * <p>
+ * @return Contact instance
+ * <p>
+ * @throws ContactNotFoundException If the contact was not found
+ */
+ Contact findContactById (final Long contactId) throws ContactNotFoundException;
+
+ /**
+ * Checks whether the given contact is found
+ * <p>
+ * @param contact Contact instance
+ *
+ * @return Whether contact has been found
+ */
+ boolean isSameContactFound (final Contact contact);
+
+ /**
+ * Getter for all contacts
+ *
+ * @return All contact
+ */
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ List<Contact> getAllContacts ();
+
+}
import org.mxchange.jcontacts.events.mobile.unlinked.ObservableAdminUnlinkedMobileNumberEvent;
import org.mxchange.jcontacts.model.contact.Contact;
import org.mxchange.jjobs.beans.BaseJobsBean;
-import org.mxchange.jjobs.beans.contact.JobsContactWebRequestController;
+import org.mxchange.jjobs.beans.contact.list.JobsContactListWebViewController;
import org.mxchange.jphone.events.fax.created.ObservableCreatedFaxNumberEvent;
import org.mxchange.jphone.events.landline.created.ObservableCreatedLandLineNumberEvent;
import org.mxchange.jphone.events.mobile.created.ObservableCreatedMobileNumberEvent;
private static final long serialVersionUID = 542_145_347_916L;
/**
- * General contact controller
+ * An instance of a contact-list controller
*/
@Inject
- private JobsContactWebRequestController contactController;
+ private JobsContactListWebViewController contactListController;
/**
* "Cache" for contact's mobile, land-line and fax numbers. Currently one
* <p>
* @return List of all linked contacts
*/
- public List<Contact> allCurrentFaxNumberContacts () {
+ public List<Contact> getAllCurrentFaxNumberContacts () {
// Get id
final DialableFaxNumber number = this.getFaxNumber();
final List<Contact> list = new LinkedList<>();
// "Walk" through all contacts
- for (final Contact contact : this.contactController.allContacts()) {
+ for (final Contact contact : this.contactListController.getAllContacts()) {
// Is mobile instance the same?
if (Objects.equals(contact.getContactFaxNumber(), number)) {
// Found one
final List<Contact> list = new LinkedList<>();
// "Walk" through all contacts
- for (final Contact contact : this.contactController.allContacts()) {
+ for (final Contact contact : this.contactListController.getAllContacts()) {
// Is mobile instance the same?
if (Objects.equals(contact.getContactLandLineNumber(), number)) {
// Found one
final List<Contact> list = new LinkedList<>();
// "Walk" through all contacts
- for (final Contact contact : this.contactController.allContacts()) {
+ for (final Contact contact : this.contactListController.getAllContacts()) {
// Is mobile instance the same?
if (Objects.equals(contact.getContactMobileNumber(), number)) {
// Found one
import javax.faces.convert.FacesConverter;
import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
import org.mxchange.jcontacts.model.contact.Contact;
-import org.mxchange.jjobs.beans.contact.JobsContactWebRequestBean;
-import org.mxchange.jjobs.beans.contact.JobsContactWebRequestController;
+import org.mxchange.jjobs.beans.contact.list.JobsContactListWebViewBean;
+import org.mxchange.jjobs.beans.contact.list.JobsContactListWebViewController;
/**
* Converter for contact id <-> valid contact instance
/**
* User EJB
*/
- private static JobsContactWebRequestController CONTACT_CONTROLLER;
+ private static JobsContactListWebViewController CONTACT_LIST_CONTROLLER;
@Override
public Contact getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
// Is the instance there?
- if (null == CONTACT_CONTROLLER) {
+ if (null == CONTACT_LIST_CONTROLLER) {
// Get bean from CDI directly
- CONTACT_CONTROLLER = CDI.current().select(JobsContactWebRequestBean.class).get();
+ CONTACT_LIST_CONTROLLER = CDI.current().select(JobsContactListWebViewBean.class).get();
}
// Is the value null or empty?
final Long contactId = Long.valueOf(submittedValue);
// Try to get user instance from it
- contact = CONTACT_CONTROLLER.findContactById(contactId);
+ contact = CONTACT_LIST_CONTROLLER.findContactById(contactId);
} catch (final NumberFormatException ex) {
// Throw again
throw new ConverterException(ex);
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facelettaglibrary_2_2.xsd">
- <namespace>http://mxchange.org/jsf/jfinancials/links</namespace>
+ <namespace>http://mxchange.org/jsf/jjobs/links</namespace>
</facelet-taglib>
<div class="table-right">
<p:inputText type="secret" id="currentPassword" size="10" maxlength="255" value="#{userLoginController.userCurrentPassword}" required="true" validatorMessage="#{msg.ERROR_USER_CURRENT_PASSWORD_MISMATCHING}">
- <!-- <f:validator for="currentPassword" validatorId="FinancialsUserPasswordValidator" /> //-->
+ <!-- <f:validator for="currentPassword" validatorId="JobsUserPasswordValidator" /> //-->
</p:inputText>
</div>
</h:panelGroup>
<p:dataTable
id="contactList"
var="contact"
- value="#{contactController.allContacts()}"
+ value="#{contactListController.allContacts}"
paginator="true"
+ paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
+ filteredValue="#{contactListController.filteredContacts}"
rows="10"
+ rowKey="#{contact.contactId}"
+ reflow="true"
+ resizableColumns="true"
+ rowsPerPageTemplate="5,10,20,50,100"
+ sortMode="multiple"
summary="#{msg.TABLE_SUMMARY_ADMIN_LIST_CONTACT}"
emptyMessage="#{msg.ADMIN_EMPTY_LIST_CONTACT}"
widgetVar="contactList"
+ selectionMode="single"
+ selection="#{contactListController.selectedContact}"
+ skipChildren="true"
>
- <p:column>
- <f:facet name="header">
- <h:outputText value="#{msg.ADMIN_CONTACT_ID}" />
- </f:facet>
+ <f:facet name="header">
+ <p:panelGrid
+ columns="3"
+ layout="grid"
+ columnClasses="ui-grid-col-4,ui-grid-col-6,ui-grid-col-2"
+ >
+ <p:spacer />
+
+ <p:panelGrid
+ columns="2"
+ columnClasses="ui-grid-4,ui-grid-8"
+ layout="grid"
+ styleClass="ui-noborder"
+ >
+ <p:outputLabel for="globalFilter" value="#{msg.SEARCH_ALL_FIELDS}" style="float: right" />
+ <p:inputText id="globalFilter" onkeyup="PF('contactList').filter()" placeholder="#{msg.ENTER_KEYWORD}"/>
+ </p:panelGrid>
+
+ <p:outputPanel>
+ <p:spacer height="4" />
+
+ <p:commandButton
+ id="toggler"
+ type="button"
+ value="#{msg.SELECT_SHOWN_COLUMNS}"
+ styleClass="column-selector"
+ />
+
+ <p:columnToggler datasource="contactList" trigger="toggler" />
+ </p:outputPanel>
+ </p:panelGrid>
+ </f:facet>
+
+ <p:ajax
+ event="rowSelect"
+ update=":master:form-list-contacts:contact-details"
+ oncomplete="PF('contactDialog').show()"
+ />
+
+ <p:column
+ headerText="#{msg.ID_HEADER}"
+ sortBy="#{contact.contactId}"
+ filterable="false"
+ >
<p:link
outcome="admin_show_contact"
value="#{contact.contactId}"
</p:link>
</p:column>
- <p:column>
- <f:facet name="header">
- <h:outputText value="#{msg.ADMIN_CONTACT_PERSONAL_TITLE}" />
+ <p:column
+ headerText="#{msg.ADMIN_CONTACT_PERSONAL_TITLE}"
+ sortBy="#{contact.contactPersonalTitle}"
+ filterBy="#{contact.contactPersonalTitle}"
+ filterMatchMode="exact"
+ >
+ <f:facet name="filter">
+ <p:selectOneMenu onchange="PF('contactList').filter()">
+ <f:converter converterId="PersonalTitleConverter" />
+ <f:selectItem itemLabel="#{msg.CHOICE_ALL}" itemValue="#{null}" />
+ <f:selectItems
+ value="#{dataController.personalTitles}"
+ var="personalTitle"
+ itemValue="#{personalTitle}"
+ itemLabel="#{msg[personalTitle.messageKey]}"
+ />
+ </p:selectOneMenu>
</f:facet>
-
<h:outputText value="#{msg[contact.contactPersonalTitle.messageKey]}" />
</p:column>
- <p:column>
- <f:facet name="header">
- <h:outputText value="#{msg.ADMIN_CONTACT_FIRST_NAME}" />
- </f:facet>
-
+ <p:column
+ headerText="#{msg.ADMIN_CONTACT_FIRST_NAME}"
+ sortBy="#{contact.contactFirstName}"
+ filterBy="#{contact.contactFirstName}"
+ filterMatchMode="contains"
+ >
<h:outputText value="#{contact.contactFirstName}" />
</p:column>
- <p:column>
- <f:facet name="header">
- <h:outputText value="#{msg.ADMIN_CONTACT_FAMILY_NAME}" />
- </f:facet>
-
+ <p:column
+ headerText="#{msg.ADMIN_CONTACT_FAMILY_NAME}"
+ sortBy="#{contact.contactFamilyName}"
+ filterBy="#{contact.contactFamilyName}"
+ filterMatchMode="contains"
+ >
<h:outputText value="#{contact.contactFamilyName}" />
</p:column>
- <p:column>
- <f:facet name="header">
- <h:outputText value="#{msg.ADMIN_CONTACT_USAGE}" />
- </f:facet>
-
+ <p:column
+ headerText="#{msg.ADMIN_CONTACT_USAGE}"
+ sortable="false"
+ filterable="false"
+ >
<h:outputText value="#{msg[beanHelper.getContactUsageMessageKey(contact)]}" />
</p:column>
- <p:column>
- <f:facet name="header">
- <h:outputText value="#{msg.ENTRY_CREATED_HEADER}" />
- </f:facet>
-
+ <p:column
+ headerText="#{msg.ENTRY_CREATED_HEADER}"
+ sortBy="#{contact.contactCreated}"
+ filterBy="#{contact.contactCreated}"
+ filterMatchMode="contains"
+ >
<h:outputText id="contactCreated" value="#{contact.contactCreated}">
<f:convertDateTime type="both" timeStyle="short" dateStyle="short" />
</h:outputText>
</p:column>
- <p:column>
- <f:facet name="header">
- <h:outputText value="#{msg.ADMIN_ACTION_LINKS_HEADER}" />
- </f:facet>
-
+ <p:column
+ headerText="#{msg.ADMIN_ACTION_LINKS_HEADER}"
+ sortable="false"
+ filterable="false"
+ >
<links:outputContactAdminDropdownMenu contact="#{contact}" />
</p:column>
</p:dataTable>
+
+ <p:dialog
+ dynamic="true"
+ modal="true"
+ resizable="false"
+ header="#{msg.ADMIN_SINGLE_CONTACT_DETAILS_HEADER}"
+ hideEffect="fade"
+ showEffect="fade"
+ widgetVar="contactDialog"
+ position="top"
+ responsive="true"
+ closeOnEscape="true"
+ >
+ <p:outputPanel id="contact-details">
+ <p:panelGrid columns="2" rendered="#{not empty contactListController.selectedContact}">
+ <f:facet name="header">
+ <h:outputFormat value="#{msg.ADMIN_CONTACT_DETAILS_HEADER}">
+ <f:param value="#{contactListController.selectedContact.companyName}" />
+ <f:param value="#{contactListController.selectedContact.contactId}" />
+ </h:outputFormat>
+ </f:facet>
+
+ <p:outputLabel value="#{msg.ID_HEADER}" title="#{msg.CONTACT_ID_NUMBER_TITLE}" />
+ <h:outputText value="#{contactListController.selectedContact.contactId}" />
+ </p:panelGrid>
+ </p:outputPanel>
+ </p:dialog>
</h:form>
<h:form>
<p:dataTable
id="contact_fax_link"
var="contact"
- value="#{contactPhoneController.allCurrentFaxNumberContacts()}"
+ value="#{contactPhoneController.allCurrentFaxNumberContacts}"
summary="#{msg.TABLE_SUMMARY_ADMIN_SHOW_ADMINISTRATIVE_LINKS}"
>
<f:facet name="header">
<f:converter converterId="ContactConverter" />
<f:selectItems
- value="#{contactController.selectableContacts()}"
+ value="#{contactListController.allContacts}"
var="contact"
itemValue="#{contact}"
itemLabel="#{beanHelper.renderContact(contact)}"