X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2Fjava%2Forg%2Fmxchange%2Fjjobs%2Fbeans%2Fcontact%2FJobsContactWebSessionBean.java;h=2ead9fac4cee7c6653cced27a43abb4ffe217987;hb=452c9d8ae56b4f53323e34e77ef3a78ea91c61f2;hp=65af5406a5242630e76982c1962f677edeb6ad39;hpb=51b92002cda7d30d081bb5ad6bf9671ec2f18fb5;p=jjobs-war.git diff --git a/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java index 65af5406..2ead9fac 100644 --- a/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebSessionBean.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Roland Haeder + * Copyright (C) 2016 Roland Häder * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -17,8 +17,10 @@ package org.mxchange.jjobs.beans.contact; import java.text.MessageFormat; +import java.util.Collections; import java.util.Date; import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import java.util.Objects; import javax.annotation.PostConstruct; @@ -35,30 +37,40 @@ import org.mxchange.jcontacts.contact.ContactSessionBeanRemote; import org.mxchange.jcontacts.contact.UserContact; import org.mxchange.jcontacts.contact.gender.Gender; import org.mxchange.jcontacts.contact.utils.ContactUtils; -import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent; +import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent; +import org.mxchange.jcontacts.events.contact.deleted.ObservableAdminDeletedContactEvent; +import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent; +import org.mxchange.jcontacts.events.fax.unlinked.ObservableAdminUnlinkedFaxNumberEvent; +import org.mxchange.jcontacts.events.landline.unlinked.ObservableAdminUnlinkedLandLineNumberEvent; +import org.mxchange.jcontacts.events.mobile.unlinked.ObservableAdminUnlinkedMobileNumberEvent; import org.mxchange.jcontacts.exceptions.ContactNotFoundException; import org.mxchange.jcountry.data.Country; +import org.mxchange.jjobs.beans.BaseJobsController; import org.mxchange.jjobs.beans.login.JobsUserLoginWebSessionController; -import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber; -import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber; +import org.mxchange.jjobs.beans.user.JobsUserWebSessionController; +import org.mxchange.jphone.events.mobile.remove.AdminRemoveMobileNumberFromListEvent; import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; import org.mxchange.jphone.phonenumbers.fax.FaxNumber; import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; import org.mxchange.jphone.phonenumbers.landline.LandLineNumber; +import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; +import org.mxchange.jphone.phonenumbers.mobile.MobileNumber; import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider; -import org.mxchange.jusercore.events.login.UserLoggedInEvent; -import org.mxchange.jusercore.events.registration.UserRegisteredEvent; -import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent; -import org.mxchange.jusercore.exceptions.UserPasswordMismatchException; +import org.mxchange.jusercore.events.confirmation.ObservableUserConfirmedAccountEvent; +import org.mxchange.jusercore.events.login.ObservableUserLoggedInEvent; +import org.mxchange.jusercore.events.registration.ObservableUserRegisteredEvent; +import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent; +import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent; +import org.mxchange.jusercore.model.user.User; /** - * A general contact bean (controller) + * A general contact controller (bean) *

- * @author Roland Haeder + * @author Roland Häder */ @Named ("contactController") @SessionScoped -public class JobsContactWebSessionBean implements JobsContactWebSessionController { +public class JobsContactWebSessionBean extends BaseJobsController implements JobsContactWebSessionController { /** * Serial number @@ -70,16 +82,6 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle */ private Date birthday; - /** - * Cellphone number's carrier - */ - private MobileProvider cellphoneCarrier; - - /** - * Cellphone number - */ - private Long cellphoneNumber; - /** * City */ @@ -98,7 +100,7 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle /** * Contact list */ - private List contactList; + private final List contacts; /** * Country instance @@ -111,14 +113,14 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle private String emailAddress; /** - * Email address list + * Email address repeated */ - private List emailAddressList; + private String emailAddressRepeat; /** - * Email address repeated + * Email address list */ - private String emailAddressRepeat; + private final List emailAddresses; /** * Family name @@ -156,9 +158,9 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle private Short houseNumber; /** - * Whether a cellphone entry has been unlinked + * House number extension */ - private boolean isCellphoneUnlinked; + private String houseNumberExtension; /** * Whether a fax entry has been unlinked @@ -171,19 +173,39 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle private boolean isLandLineUnlinked; /** - * Phone number area code + * Whether a mobile entry has been unlinked + */ + private boolean isMobileUnlinked; + + /** + * Land-line number area code */ - private Integer phoneAreaCode; + private Integer landLineAreaCode; /** - * Country instance for phone number + * Country instance for land-line number */ - private Country phoneCountry; + private Country landLineCountry; /** - * Phone number + * Land-line number */ - private Long phoneNumber; + private Long landLineNumber; + + /** + * Mobile number + */ + private Long mobileNumber; + + /** + * Mobile provider + */ + private MobileProvider mobileProvider; + + /** + * A list of all selectable contacts + */ + private List selectableContacts; /** * Street @@ -191,7 +213,18 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle private String street; /** - * Login bean (controller) + * Title + */ + private String title; + + /** + * Regular user controller + */ + @Inject + private JobsUserWebSessionController userController; + + /** + * Login controller (bean) */ @Inject private JobsUserLoginWebSessionController userLoginController; @@ -211,15 +244,19 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle Context context = new InitialContext(); // Try to lookup - this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jratecalc-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N + this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jjobs-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N } catch (final NamingException e) { // Throw again throw new FaceletException(e); } + + // Init lists/maps + this.contacts = new LinkedList<>(); + this.emailAddresses = new LinkedList<>(); } @Override - public void afterAdminAddedContact (@Observes final AdminAddedContactEvent event) { + public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) { // The event must be valid if (null == event) { // Throw NPE @@ -229,24 +266,24 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle throw new NullPointerException("event.addedContact is null"); //NOI18N } else if (event.getAddedContact().getContactId() == null) { // ... and again - throw new NullPointerException("event.addedContact.customerId is null"); //NOI18N + throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N } else if (event.getAddedContact().getContactId() < 1) { // Not valid - throw new IllegalArgumentException(MessageFormat.format("event.addedContact.customerId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N + throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N } // Clear this bean this.clear(); // Call other method - this.contactList.add(event.getAddedContact()); + this.uniqueAddContact(event.getAddedContact()); + + // Add to selectable contacts + this.selectableContacts.add(event.getAddedContact()); } @Override - public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) { - // Trace message - //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterAdminAddedUserEvent: event={0} - CALLED!", event)); //NOI18N - + public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) { // event should not be null if (null == event) { // Throw NPE @@ -264,110 +301,189 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle // Clear all data this.clear(); - - // Trace message - //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterAdminAddedUserEvent: EXIT!"); //NOI18N } @Override - public void afterAdminUpdatedContactDataEvent (@Observes final AdminUpdatedContactEvent event) { - // Trace message - //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterAdminUpdatedContactDataEvent: event={0} - CALLED!", event)); //NOI18N - + public void afterAdminDeletedContactEvent (@Observes final ObservableAdminDeletedContactEvent event) { // event should not be null if (null == event) { // Throw NPE throw new NullPointerException("event is null"); //NOI18N - } else if (event.getUpdatedContact() == null) { + } else if (event.getDeletedContact() == null) { // Throw NPE again - throw new NullPointerException("event.updatedUser is null"); //NOI18N - } else if (event.getUpdatedContact().getContactId() == null) { + throw new NullPointerException("event.deletedContact is null"); //NOI18N + } else if (event.getDeletedContact().getContactId() == null) { // userId is null - throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N - } else if (event.getUpdatedContact().getContactId() < 1) { + throw new NullPointerException("event.deletedContact.contactId is null"); //NOI18N + } else if (event.getDeletedContact().getContactId() < 1) { // Not avalid id - throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getDeletedContact(), event.getDeletedContact().getContactId())); //NOI18N } - // Get iterator from list - Iterator iterator = this.contactList.iterator(); - - // "Walk" through all entries - while (iterator.hasNext()) { - // Get next element - Contact next = iterator.next(); + // Remove from both lists + this.contacts.remove(event.getDeletedContact()); + this.selectableContacts.remove(event.getDeletedContact()); - // Is id number the same? - if (Objects.equals(event.getUpdatedContact().getContactId(), next.getContactId())) { - // Found entry, so remove it and abort - this.contactList.remove(next); + // Clear all data + this.clear(); + } - // Remove also email from list - this.emailAddressList.remove(next.getContactEmailAddress()); - break; - } + @Override + public void afterAdminLinkedUserEvent (@Observes final ObservableAdminLinkedUserEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getLinkedUser() == null) { + // Throw NPE again + throw new NullPointerException("event.linkedUser is null"); //NOI18N + } else if (event.getLinkedUser().getUserContact() == null) { + // Throw NPE again + throw new NullPointerException("event.linkedUser.userContact is null"); //NOI18N + } else if (event.getLinkedUser().getUserContact().getContactId() == null) { + // userId is null + throw new NullPointerException("event.linkedUser.userContact.contactId is null"); //NOI18N + } else if (event.getLinkedUser().getUserContact().getContactId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserContact().getContactId())); //NOI18N } - // Add contact to list - this.contactList.add(event.getUpdatedContact()); + // Remove contact from list available contacts list + this.selectableContacts.remove(event.getLinkedUser().getUserContact()); - // Add email address to list - this.emailAddressList.add(event.getUpdatedContact().getContactEmailAddress()); + // Clear all data + this.clear(); } @Override - public void afterRegistrationEvent (@Observes final UserRegisteredEvent event) { - // Trace message - //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N + public void afterAdminUnlinkedFaxContactDataEvent (@Observes final ObservableAdminUnlinkedFaxNumberEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getUnlinkedFaxNumber() == null) { + // Throw NPE again + throw new NullPointerException("event.unlinkedFaxNumber is null"); //NOI18N + } else if (event.getUnlinkedFaxNumber().getPhoneId() == null) { + // userId is null + throw new NullPointerException("event.unlinkedFaxNumber.contactId is null"); //NOI18N + } else if (event.getUnlinkedFaxNumber().getPhoneId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedFaxNumber(), event.getUnlinkedFaxNumber().getPhoneId())); //NOI18N + } + + // Remove it from list + this.removeFromContacts(event.getUnlinkedFaxNumber()); + + // Clear all data + this.clear(); + } + @Override + public void afterAdminUnlinkedLandLineContactDataEvent (@Observes final ObservableAdminUnlinkedLandLineNumberEvent event) { // event should not be null if (null == event) { // Throw NPE throw new NullPointerException("event is null"); //NOI18N - } else if (event.getRegisteredUser() == null) { + } else if (event.getUnlinkedLandLineNumber() == null) { // Throw NPE again - throw new NullPointerException("event.user is null"); //NOI18N - } else if (event.getRegisteredUser().getUserId() == null) { + throw new NullPointerException("event.unlinkedLandLineNumber is null"); //NOI18N + } else if (event.getUnlinkedLandLineNumber().getPhoneId() == null) { // userId is null - throw new NullPointerException("event.user.userId is null"); //NOI18N - } else if (event.getRegisteredUser().getUserId() < 1) { + throw new NullPointerException("event.unlinkedLandLineNumber.contactId is null"); //NOI18N + } else if (event.getUnlinkedLandLineNumber().getPhoneId() < 1) { // Not avalid id - throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N + throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedLandLineNumber(), event.getUnlinkedLandLineNumber().getPhoneId())); //NOI18N } - // Get user instance - Contact registeredContact = event.getRegisteredUser().getUserContact(); + // Remove it from list + this.removeFromContacts(event.getUnlinkedLandLineNumber()); - // Debug message - //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: registeredContact={0}", registeredContact)); //NOI18N - // Copy all data from registered->user - this.copyContact(registeredContact); + // Clear all data + this.clear(); + } - // Add user name and email address - this.addUserNameEmailAddress(registeredContact); + @Override + public void afterAdminUnlinkedMobileContactDataEvent (@Observes final ObservableAdminUnlinkedMobileNumberEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getUnlinkedMobileNumber() == null) { + // Throw NPE again + throw new NullPointerException("event.unlinkedMobileNumber is null"); //NOI18N + } else if (event.getUnlinkedMobileNumber().getPhoneId() == null) { + // userId is null + throw new NullPointerException("event.unlinkedMobileNumber.contactId is null"); //NOI18N + } else if (event.getUnlinkedMobileNumber().getPhoneId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedMobileNumber(), event.getUnlinkedMobileNumber().getPhoneId())); //NOI18N + } + + // Remove it from list + this.removeFromContacts(event.getUnlinkedMobileNumber()); // Clear all data this.clear(); + } - // Trace message - //* NOISY-DEBUG: */ System.out.println("ContactWebBean:afterRegistration: EXIT!"); //NOI18N + @Override + public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getUpdatedContact() == null) { + // Throw NPE again + throw new NullPointerException("event.updatedContact is null"); //NOI18N + } else if (event.getUpdatedContact().getContactId() == null) { + // userId is null + throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N + } else if (event.getUpdatedContact().getContactId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N + } + + // Add contact instance only once + this.uniqueAddContact(event.getUpdatedContact()); + + // Add email address to list + this.emailAddresses.add(event.getUpdatedContact().getContactEmailAddress()); } @Override - public void afterUserLogin (@Observes final UserLoggedInEvent event) { - // Trace message - //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N + public void afterUserConfirmedAccountEventEvent (@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()); + } + + @Override + public void afterUserLoginEvent (@Observes final ObservableUserLoggedInEvent event) { // event should not be null if (null == event) { // Throw NPE throw new NullPointerException("event is null"); //NOI18N } else if (event.getLoggedInUser() == null) { // Throw NPE again - throw new NullPointerException("event.user is null"); //NOI18N + throw new NullPointerException("event.loggedInUser is null"); //NOI18N } else if (event.getLoggedInUser().getUserId() == null) { // userId is null - throw new NullPointerException("event.user.userId is null"); //NOI18N + throw new NullPointerException("event.loggedInUser.userId is null"); //NOI18N } else if (event.getLoggedInUser().getUserId() < 1) { // Not avalid id throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N @@ -375,15 +491,46 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle // Copy all data to this bean this.copyContact(event.getLoggedInUser().getUserContact()); + } - // Trace message - //* NOISY-DEBUG: */ System.out.println("ContactWebBean:afterUserLogin - EXIT!"); //NOI18N + @Override + 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 + Contact registeredContact = event.getRegisteredUser().getUserContact(); + + // Copy all data from registered->user + this.copyContact(registeredContact); + + // Add user name and email address + this.addUserNameEmailAddress(registeredContact); + + // Clear all data + this.clear(); } @Override @SuppressWarnings ("ReturnOfCollectionOrArrayField") public List allContacts () { - return this.contactList; + // Debug message + //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactController.allContacts: contactList.size()={0} - EXIT!", this.contactList.size())); + + // Return un-modified list + return this.contacts; } @Override @@ -397,21 +544,16 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle throw new FaceletException(new IllegalArgumentException("Not all personal data is set, but createContactInstance() is called.")); //NOI18N } - // Required personal data must be set - assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N - - // Create new contact instance - Contact localContact = new UserContact(); - // Generate phone number - DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber()); - DialableCellphoneNumber cellphone = new CellphoneNumber(this.getCellphoneCarrier(), this.getCellphoneNumber()); + DialableLandLineNumber phone = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber()); + DialableMobileNumber mobile = new MobileNumber(this.getMobileProvider(), this.getMobileNumber()); DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber()); // Create new contact Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName()); contact.setContactStreet(this.getStreet()); contact.setContactHouseNumber(this.getHouseNumber()); + contact.setContactHouseNumberExtension(this.getHouseNumberExtension()); contact.setContactZipCode(this.getZipCode()); contact.setContactCity(this.getCity()); contact.setContactCountry(this.getCountry()); @@ -422,7 +564,7 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle // Debug message //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: this.emailAddress={1}", this.getClass().getSimpleName(), this.getEmailAddress())); // Don't set null or wrong references - if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) { + if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) { // Now the number must be given if (phone.getPhoneAreaCode() == null) { // Is null @@ -464,25 +606,24 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle } // Is the provider set? - if ((cellphone instanceof DialableCellphoneNumber) && (this.getCellphoneCarrier() instanceof MobileProvider) && (this.getCellphoneNumber() != null) && (this.getCellphoneNumber() > 0)) { + if ((mobile instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) { // Is the number set? - if (cellphone.getPhoneNumber() == null) { + if (mobile.getPhoneNumber() == null) { // Is null - throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N - } else if (cellphone.getPhoneNumber() < 1) { + throw new NullPointerException("mobileNumber.phoneNumber is null"); //NOI18N + } else if (mobile.getPhoneNumber() < 1) { // Abort here - throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N + throw new IllegalArgumentException("mobileNumber.phoneNumber is zero or below."); //NOI18N } - // Set cellphone number - contact.setContactCellphoneNumber(cellphone); + // Set mobile number + contact.setContactMobileNumber(mobile); } // Trace message //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: contact={1} - EXIT!", this.getClass().getSimpleName(), contact)); - // Return it - return localContact; + return contact; } @Override @@ -496,7 +637,8 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle throw new FaceletException("Not all required fields are set."); //NOI18N } else if (!this.userLoginController.ifCurrentPasswordMatches()) { // Password not matching - throw new FaceletException(new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); + this.showFacesMessage("form_login_change_personal:currentPassword", "ERROR_USER_CURRENT_PASSWORD_MISMATCHING"); //NOI18N + return ""; //NOI18N } // Get contact instance @@ -513,24 +655,25 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle contact.setContactFamilyName(this.getFamilyName()); contact.setContactStreet(this.getStreet()); contact.setContactHouseNumber(this.getHouseNumber()); + contact.setContactHouseNumberExtension(this.getHouseNumberExtension()); contact.setContactZipCode(this.getZipCode()); contact.setContactCity(this.getCity()); contact.setContactCountry(this.getCountry()); - // Update contact's cellphone number - this.isCellphoneUnlinked = ContactUtils.updateCellPhoneNumber(contact, this.getCellphoneCarrier(), this.getCellphoneNumber()); + // Update contact's mobile number + this.isMobileUnlinked = ContactUtils.updateMobileNumber(contact, this.getMobileProvider(), this.getMobileNumber()); // Update contact's land-line number - this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber()); + this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber()); // Update contact's fax number this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber()); // Send it to the EJB - this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked); + this.contactBean.updateContactData(contact, this.isMobileUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked); // All fine - return "contact_data_saved"; //NOI18N + return "user_contact_data_saved"; //NOI18N } @Override @@ -545,26 +688,6 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle this.birthday = birthday; } - @Override - public MobileProvider getCellphoneCarrier () { - return this.cellphoneCarrier; - } - - @Override - public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) { - this.cellphoneCarrier = cellphoneCarrier; - } - - @Override - public Long getCellphoneNumber () { - return this.cellphoneNumber; - } - - @Override - public void setCellphoneNumber (Long cellphoneNumber) { - this.cellphoneNumber = cellphoneNumber; - } - @Override public String getCity () { return this.city; @@ -585,6 +708,17 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle this.comment = comment; } + @Override + public String getControllerType () { + return "general"; //NOI18N + } + + @Override + @Deprecated + public void setControllerType (final String controllerType) { + throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N + } + @Override public Country getCountry () { return this.country; @@ -686,33 +820,63 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle } @Override - public Integer getPhoneAreaCode () { - return this.phoneAreaCode; + public String getHouseNumberExtension () { + return this.houseNumberExtension; } @Override - public void setPhoneAreaCode (final Integer phoneAreaCode) { - this.phoneAreaCode = phoneAreaCode; + public void setHouseNumberExtension (final String houseNumberExtension) { + this.houseNumberExtension = houseNumberExtension; } @Override - public Country getPhoneCountry () { - return this.phoneCountry; + public Integer getLandLineAreaCode () { + return this.landLineAreaCode; } @Override - public void setPhoneCountry (final Country phoneCountry) { - this.phoneCountry = phoneCountry; + public void setLandLineAreaCode (final Integer landLineAreaCode) { + this.landLineAreaCode = landLineAreaCode; } @Override - public Long getPhoneNumber () { - return this.phoneNumber; + public Country getLandLineCountry () { + return this.landLineCountry; } @Override - public void setPhoneNumber (final Long phoneNumber) { - this.phoneNumber = phoneNumber; + public void setLandLineCountry (final Country landLineCountry) { + this.landLineCountry = landLineCountry; + } + + @Override + public Long getLandLineNumber () { + return this.landLineNumber; + } + + @Override + public void setLandLineNumber (final Long landLineNumber) { + this.landLineNumber = landLineNumber; + } + + @Override + public Long getMobileNumber () { + return this.mobileNumber; + } + + @Override + public void setMobileNumber (Long mobileNumber) { + this.mobileNumber = mobileNumber; + } + + @Override + public MobileProvider getMobileProvider () { + return this.mobileProvider; + } + + @Override + public void setMobileProvider (final MobileProvider mobileProvider) { + this.mobileProvider = mobileProvider; } @Override @@ -725,6 +889,16 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle this.street = street; } + @Override + public String getTitle () { + return this.title; + } + + @Override + public void setTitle (final String title) { + this.title = title; + } + @Override public Integer getZipCode () { return this.zipCode; @@ -735,26 +909,68 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle this.zipCode = zipCode; } - @Override - public boolean hasContacts () { - return (!this.allContacts().isEmpty()); - } - /** * Post-initialization of this class */ @PostConstruct public void init () { // Get full email address list for reducing EJB calls - this.emailAddressList = this.contactBean.getEmailAddressList(); + this.emailAddresses.addAll(this.contactBean.getEmailAddressList()); + + // Get all contacts + List allContacts = this.contactBean.getAllContacts(); // Get full contact list - this.contactList = this.contactBean.getAllContacts(); + this.contacts.addAll(allContacts); + + // Get all users + List allUsers = this.userController.allUsers(); + + // Get iterator + Iterator iterator = allContacts.iterator(); + + // Loop through it + while (iterator.hasNext()) { + // Get next element + Contact next = iterator.next(); + + // Get iterator + Iterator userIterator = allUsers.iterator(); + + // Loop through all users + while (userIterator.hasNext()) { + // Get user instance + User nextUser = userIterator.next(); + + // Is contact same? + if (Objects.equals(next, nextUser.getUserContact())) { + // Found same + iterator.remove(); + break; + } + } + } + + // Set contact list + this.selectableContacts = allContacts; } @Override public boolean isEmailAddressRegistered (final Contact contact) { - return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(contact.getContactEmailAddress()))); + // Cherck parameter + if (null == contact) { + // Throw NPE + throw new NullPointerException("contact is null"); //NOI18N + } else if (contact.getContactEmailAddress() == null) { + // Throw again + throw new NullPointerException("contact.contactEmailAddress is null"); //NOI18N + } else if (contact.getContactEmailAddress().isEmpty()) { + // Is empty + throw new IllegalArgumentException("contact.contactEmailAddress is empty."); //NOI18N + } + + // Determine it + return ((this.emailAddresses instanceof List) && (this.emailAddresses.contains(contact.getContactEmailAddress()))); } @Override @@ -795,7 +1011,7 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle this.clear(); // Try to lookup it in visible user list - for (final Iterator iterator = this.contactList.iterator(); iterator.hasNext();) { + for (final Iterator iterator = this.contacts.iterator(); iterator.hasNext();) { // Get next user Contact next = iterator.next(); @@ -820,6 +1036,35 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle return localContact; } + @Override + public void removeMobileNumberFromListEvent (@Observes final AdminRemoveMobileNumberFromListEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getMobileNumberList() == null) { + // Throw NPE again + throw new NullPointerException("event.mobileList is null"); //NOI18N + } else if (event.getMobileNumberList().isEmpty()) { + // List is empty, no need to check + return; + } + + // Check all entries + for (final Contact contact : this.contacts) { + // Is the mobile instance set and in list? + if ((contact.getContactMobileNumber() instanceof DialableMobileNumber) && (event.getMobileNumberList().contains(contact.getContactMobileNumber()))) { + // Found it, so remvoe it from list + event.getMobileNumberList().remove(contact.getContactMobileNumber()); + } + } + } + + @Override + public List selectableContacts () { + return Collections.unmodifiableList(this.selectableContacts); + } + @Override public void updateContactDataFromController (final Contact contact) { // Is the instance valid? @@ -845,13 +1090,13 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle */ private void addUserNameEmailAddress (final Contact contact) { // Make sure the entry is not added yet - if (this.emailAddressList.contains(contact.getContactEmailAddress())) { + if (this.emailAddresses.contains(contact.getContactEmailAddress())) { // Already added throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N } // Add email addres - this.emailAddressList.add(contact.getContactEmailAddress()); + this.emailAddresses.add(contact.getContactEmailAddress()); } /** @@ -860,11 +1105,13 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle private void clear () { // Clear all data // - personal data - this.setGender(Gender.UNKNOWN); + this.setGender(null); + this.setTitle(null); this.setFirstName(null); this.setFamilyName(null); this.setStreet(null); this.setHouseNumber(null); + this.setHouseNumberExtension(null); this.setZipCode(null); this.setCity(null); this.setCountry(null); @@ -872,9 +1119,14 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle // - contact data this.setEmailAddress(null); this.setEmailAddressRepeat(null); - this.setPhoneAreaCode(null); - this.setCellphoneCarrier(null); + this.setLandLineAreaCode(null); + this.setLandLineCountry(null); + this.setLandLineNumber(null); + this.setMobileProvider(null); + this.setMobileNumber(null); this.setFaxAreaCode(null); + this.setFaxCountry(null); + this.setFaxNumber(null); // - other data this.setBirthday(null); @@ -902,39 +1154,41 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle // Copy all fields: // - base data this.setGender(contact.getContactGender()); + this.setTitle(contact.getContactTitle()); this.setFirstName(contact.getContactFirstName()); this.setFamilyName(contact.getContactFamilyName()); this.setStreet(contact.getContactStreet()); this.setHouseNumber(contact.getContactHouseNumber()); + this.setHouseNumberExtension(contact.getContactHouseNumberExtension()); this.setZipCode(contact.getContactZipCode()); this.setCity(contact.getContactCity()); this.setCountry(contact.getContactCountry()); + this.setEmailAddress(contact.getContactEmailAddress()); + this.setBirthday(contact.getContactBirthday()); + this.setComment(contact.getContactComment()); - // Get cellphone, phone and fax instance - DialableCellphoneNumber cellphone = contact.getContactCellphoneNumber(); + // Get mobile, phone and fax instance + DialableMobileNumber mobile = contact.getContactMobileNumber(); DialableFaxNumber fax = contact.getContactFaxNumber(); DialableLandLineNumber phone = contact.getContactLandLineNumber(); // - contact data if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) { - this.setPhoneCountry(phone.getPhoneCountry()); - this.setPhoneAreaCode(phone.getPhoneAreaCode()); - this.setPhoneNumber(phone.getPhoneNumber()); + this.setLandLineCountry(phone.getPhoneCountry()); + this.setLandLineAreaCode(phone.getPhoneAreaCode()); + this.setLandLineNumber(phone.getPhoneNumber()); } - if ((cellphone instanceof DialableCellphoneNumber) && (cellphone.getCellphoneProvider() instanceof MobileProvider)) { - this.setCellphoneCarrier(cellphone.getCellphoneProvider()); - this.setCellphoneNumber(cellphone.getPhoneNumber()); + + if ((mobile instanceof DialableMobileNumber) && (mobile.getMobileProvider() instanceof MobileProvider)) { + this.setMobileProvider(mobile.getMobileProvider()); + this.setMobileNumber(mobile.getPhoneNumber()); } + if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) { this.setFaxCountry(fax.getPhoneCountry()); this.setFaxAreaCode(fax.getPhoneAreaCode()); this.setFaxNumber(fax.getPhoneNumber()); } - this.setEmailAddress(contact.getContactEmailAddress()); - - // -- other data - this.setBirthday(contact.getContactBirthday()); - this.setComment(contact.getContactComment()); } /** @@ -956,13 +1210,163 @@ public class JobsContactWebSessionBean implements JobsContactWebSessionControlle } // Remove from general list - if (!this.contactList.remove(contact)) { + if (!this.contacts.remove(contact)) { // Did not remove contact throw new IllegalStateException(MessageFormat.format("contact {0} was not removed.", contact.getContactId())); //NOI18N } // Remove from other lists - this.emailAddressList.remove(contact.getContactEmailAddress()); + this.emailAddresses.remove(contact.getContactEmailAddress()); + } + + /** + * Removes given fax number from all contacts + *

+ * @param faxNumber Fax number to remove + */ + private void removeFromContacts (final DialableFaxNumber faxNumber) { + // Log message + System.out.println(MessageFormat.format("{0}.removeFromContacts: faxNumber={1} - CALLED!", this.getClass().getSimpleName(), faxNumber)); //NOI18N + + // Is it valid? + if (null == faxNumber) { + // Throw NPE + throw new NullPointerException("faxNumber is null"); //NOI18N + } else if (faxNumber.getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N + } else if (faxNumber.getPhoneId() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("faxNumber.phoneId={0} is not valid", faxNumber.getPhoneId())); //NOI18N + } + + // Loop through all contacts + for (final Contact contact : this.contacts) { + // Log message + System.out.println(MessageFormat.format("{0}.removeFromContacts: contact={1},contact.contactFaxNumber={2}", this.getClass().getSimpleName(), contact, contact.getContactFaxNumber())); //NOI18N + + // Is the number set? + if (Objects.equals(contact.getContactFaxNumber(), faxNumber)) { + // Log message + System.out.println(MessageFormat.format("{0}.removeFromContacts: Unsetting faxNumber={1} ...", this.getClass().getSimpleName(), faxNumber)); //NOI18N + + // Found it + contact.setContactFaxNumber(null); + } + } + } + + /** + * Removes given land-line number from all contacts + *

+ * @param landLineNumber Land-line number to remove + */ + private void removeFromContacts (final DialableLandLineNumber landLineNumber) { + // Log message + System.out.println(MessageFormat.format("{0}.removeFromContacts: landLineNumber={1} - CALLED!", this.getClass().getSimpleName(), landLineNumber)); //NOI18N + + // Is it valid? + if (null == landLineNumber) { + // Throw NPE + throw new NullPointerException("landLineNumber is null"); //NOI18N + } else if (landLineNumber.getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N + } else if (landLineNumber.getPhoneId() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", landLineNumber.getPhoneId())); //NOI18N + } + + // Loop through all contacts + for (final Contact contact : this.contacts) { + // Log message + System.out.println(MessageFormat.format("{0}.removeFromContacts: contact={1},contact.contactLandLineNumber={2}", this.getClass().getSimpleName(), contact, contact.getContactLandLineNumber())); //NOI18N + + // Is the number set? + if (Objects.equals(contact.getContactLandLineNumber(), landLineNumber)) { + // Log message + System.out.println(MessageFormat.format("{0}.removeFromContacts: Unsetting landLineNumber={1} ...", this.getClass().getSimpleName(), landLineNumber)); //NOI18N + + // Found it + contact.setContactLandLineNumber(null); + } + } + } + + /** + * Removes given mobile number from all contacts + *

+ * @param mobileNumber Mobile number to remove + */ + private void removeFromContacts (final DialableMobileNumber mobileNumber) { + // Log message + System.out.println(MessageFormat.format("{0}.removeFromContacts: mobileNumber={1} - CALLED!", this.getClass().getSimpleName(), mobileNumber)); //NOI18N + + // Is it valid? + if (null == mobileNumber) { + // Throw NPE + throw new NullPointerException("mobileNumber is null"); //NOI18N + } else if (mobileNumber.getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N + } else if (mobileNumber.getPhoneId() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", mobileNumber.getPhoneId())); //NOI18N + } + + // Loop through all contacts + for (final Contact contact : this.contacts) { + // Log message + System.out.println(MessageFormat.format("{0}.removeFromContacts: contact={1},contact.contactMobileNumber={2}", this.getClass().getSimpleName(), contact, contact.getContactMobileNumber())); //NOI18N + + // Is the number set? + if (Objects.equals(contact.getContactMobileNumber(), mobileNumber)) { + // Log message + System.out.println(MessageFormat.format("{0}.removeFromContacts: Unsetting mobileNumber={1} ...", this.getClass().getSimpleName(), mobileNumber)); //NOI18N + + // Unset it + contact.setContactMobileNumber(null); + } + } + } + + /** + * Adds unique instance to contact list. First any existing instance is + * being removed, then the new instance is added. + *

+ * @param contact Contact instance to add uniquely + */ + private void uniqueAddContact (final Contact contact) { + // Is the instance valid? + if (null == contact) { + // Throw NPE + throw new NullPointerException("contact is null"); //NOI18N + } else if (contact.getContactId() == null) { + // Throw NPE + throw new NullPointerException("contact.contactId is null"); //NOI18N + } else if (contact.getContactId() < 1) { + // Not valid id number + throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N + } + + // Get iterator from list + Iterator iterator = this.contacts.iterator(); + + // "Walk" through all entries + while (iterator.hasNext()) { + // Get next element + Contact next = iterator.next(); + + // Is id number the same? + if (Objects.equals(contact.getContactId(), next.getContactId())) { + // Found entry, so remove it and abort + this.removeContact(next); + break; + } + } + + // Add contact to list + this.contacts.add(contact); } }